~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/video/bitmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
 
4
 *
 
5
 *  GRUB is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <grub/video.h>
 
20
#include <grub/bitmap.h>
 
21
#include <grub/types.h>
 
22
#include <grub/dl.h>
 
23
#include <grub/mm.h>
 
24
#include <grub/misc.h>
 
25
 
 
26
/* List of bitmap readers registered to system.  */
 
27
static grub_video_bitmap_reader_t bitmap_readers_list;
 
28
 
 
29
/* Register bitmap reader.  */
 
30
void
 
31
grub_video_bitmap_reader_register (grub_video_bitmap_reader_t reader)
 
32
{
 
33
  reader->next = bitmap_readers_list;
 
34
  bitmap_readers_list = reader;
 
35
}
 
36
 
 
37
/* Unregister bitmap reader.  */
 
38
void
 
39
grub_video_bitmap_reader_unregister (grub_video_bitmap_reader_t reader)
 
40
{
 
41
  grub_video_bitmap_reader_t *p, q;
 
42
 
 
43
  for (p = &bitmap_readers_list, q = *p; q; p = &(q->next), q = q->next)
 
44
    if (q == reader)
 
45
      {
 
46
        *p = q->next;
 
47
        break;
 
48
      }
 
49
}
 
50
 
 
51
/* Creates new bitmap, saves created bitmap on success to *bitmap.  */
 
52
grub_err_t
 
53
grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
 
54
                          unsigned int width, unsigned int height,
 
55
                          enum grub_video_blit_format blit_format)
 
56
{
 
57
  struct grub_video_mode_info *mode_info;
 
58
  unsigned int size;
 
59
 
 
60
  if (!bitmap)
 
61
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
 
62
 
 
63
  *bitmap = 0;
 
64
 
 
65
  if (width == 0 || height == 0)
 
66
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
 
67
 
 
68
  *bitmap = (struct grub_video_bitmap *)grub_malloc (sizeof (struct grub_video_bitmap));
 
69
  if (! *bitmap)
 
70
    return grub_errno;
 
71
 
 
72
  mode_info = &((*bitmap)->mode_info);
 
73
 
 
74
  /* Populate mode_info.  */
 
75
  mode_info->width = width;
 
76
  mode_info->height = height;
 
77
  mode_info->blit_format = blit_format;
 
78
 
 
79
  switch (blit_format)
 
80
    {
 
81
      case GRUB_VIDEO_BLIT_FORMAT_RGBA_8888:
 
82
        mode_info->mode_type = GRUB_VIDEO_MODE_TYPE_RGB
 
83
                               | GRUB_VIDEO_MODE_TYPE_ALPHA;
 
84
        mode_info->bpp = 32;
 
85
        mode_info->bytes_per_pixel = 4;
 
86
        mode_info->number_of_colors = 256;
 
87
        mode_info->red_mask_size = 8;
 
88
        mode_info->red_field_pos = 0;
 
89
        mode_info->green_mask_size = 8;
 
90
        mode_info->green_field_pos = 8;
 
91
        mode_info->blue_mask_size = 8;
 
92
        mode_info->blue_field_pos = 16;
 
93
        mode_info->reserved_mask_size = 8;
 
94
        mode_info->reserved_field_pos = 24;
 
95
        break;
 
96
 
 
97
      case GRUB_VIDEO_BLIT_FORMAT_RGB_888:
 
98
        mode_info->mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
 
99
        mode_info->bpp = 24;
 
100
        mode_info->bytes_per_pixel = 3;
 
101
        mode_info->number_of_colors = 256;
 
102
        mode_info->red_mask_size = 8;
 
103
        mode_info->red_field_pos = 0;
 
104
        mode_info->green_mask_size = 8;
 
105
        mode_info->green_field_pos = 8;
 
106
        mode_info->blue_mask_size = 8;
 
107
        mode_info->blue_field_pos = 16;
 
108
        mode_info->reserved_mask_size = 0;
 
109
        mode_info->reserved_field_pos = 0;
 
110
        break;
 
111
 
 
112
      case GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR:
 
113
        mode_info->mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
 
114
        mode_info->bpp = 8;
 
115
        mode_info->bytes_per_pixel = 1;
 
116
        mode_info->number_of_colors = 256;
 
117
        mode_info->red_mask_size = 0;
 
118
        mode_info->red_field_pos = 0;
 
119
        mode_info->green_mask_size = 0;
 
120
        mode_info->green_field_pos = 0;
 
121
        mode_info->blue_mask_size = 0;
 
122
        mode_info->blue_field_pos = 0;
 
123
        mode_info->reserved_mask_size = 0;
 
124
        mode_info->reserved_field_pos = 0;
 
125
        break;
 
126
 
 
127
      default:
 
128
        grub_free (*bitmap);
 
129
        *bitmap = 0;
 
130
 
 
131
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
 
132
                           "unsupported bitmap format");
 
133
    }
 
134
 
 
135
  mode_info->pitch = width * mode_info->bytes_per_pixel;
 
136
 
 
137
  /* Calculate size needed for the data.  */
 
138
  size = (width * mode_info->bytes_per_pixel) * height;
 
139
 
 
140
  (*bitmap)->data = grub_zalloc (size);
 
141
  if (! (*bitmap)->data)
 
142
    {
 
143
      grub_free (*bitmap);
 
144
      *bitmap = 0;
 
145
 
 
146
      return grub_errno;
 
147
    }
 
148
 
 
149
  return GRUB_ERR_NONE;
 
150
}
 
151
 
 
152
/* Frees all resources allocated by bitmap.  */
 
153
grub_err_t
 
154
grub_video_bitmap_destroy (struct grub_video_bitmap *bitmap)
 
155
{
 
156
  if (! bitmap)
 
157
    return GRUB_ERR_NONE;
 
158
 
 
159
  grub_free (bitmap->data);
 
160
  grub_free (bitmap);
 
161
 
 
162
  return GRUB_ERR_NONE;
 
163
}
 
164
 
 
165
/* Match extension to filename.  */
 
166
static int
 
167
match_extension (const char *filename, const char *ext)
 
168
{
 
169
  int pos;
 
170
  int ext_len;
 
171
 
 
172
  pos = grub_strlen (filename);
 
173
  ext_len = grub_strlen (ext);
 
174
 
 
175
  if (! pos || ! ext_len || ext_len > pos)
 
176
    return 0;
 
177
 
 
178
  pos -= ext_len;
 
179
 
 
180
  return grub_strcmp (filename + pos, ext) == 0;
 
181
}
 
182
 
 
183
/* Loads bitmap using registered bitmap readers.  */
 
184
grub_err_t
 
185
grub_video_bitmap_load (struct grub_video_bitmap **bitmap,
 
186
                        const char *filename)
 
187
{
 
188
  grub_video_bitmap_reader_t reader = bitmap_readers_list;
 
189
 
 
190
  if (!bitmap)
 
191
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
 
192
 
 
193
  *bitmap = 0;
 
194
 
 
195
  while (reader)
 
196
    {
 
197
      if (match_extension (filename, reader->extension))
 
198
        return reader->reader (bitmap, filename);
 
199
 
 
200
      reader = reader->next;
 
201
    }
 
202
 
 
203
  return grub_error(GRUB_ERR_BAD_FILE_TYPE, "unsupported bitmap format");
 
204
}
 
205
 
 
206
/* Return bitmap width.  */
 
207
unsigned int
 
208
grub_video_bitmap_get_width (struct grub_video_bitmap *bitmap)
 
209
{
 
210
  if (!bitmap)
 
211
    return 0;
 
212
 
 
213
  return bitmap->mode_info.width;
 
214
}
 
215
 
 
216
/* Return bitmap height.  */
 
217
unsigned int
 
218
grub_video_bitmap_get_height (struct grub_video_bitmap *bitmap)
 
219
{
 
220
  if (!bitmap)
 
221
    return 0;
 
222
 
 
223
  return bitmap->mode_info.height;
 
224
}
 
225
 
 
226
/* Return mode info for bitmap.  */
 
227
void grub_video_bitmap_get_mode_info (struct grub_video_bitmap *bitmap,
 
228
                                      struct grub_video_mode_info *mode_info)
 
229
{
 
230
  if (!bitmap)
 
231
    return;
 
232
 
 
233
  *mode_info = bitmap->mode_info;
 
234
}
 
235
 
 
236
/* Return pointer to bitmap's raw data.  */
 
237
void *grub_video_bitmap_get_data (struct grub_video_bitmap *bitmap)
 
238
{
 
239
  if (!bitmap)
 
240
    return 0;
 
241
 
 
242
  return bitmap->data;
 
243
}
 
244
 
 
245
/* Initialize bitmap module.  */
 
246
GRUB_MOD_INIT(bitmap)
 
247
{
 
248
}
 
249
 
 
250
/* Finalize bitmap module.  */
 
251
GRUB_MOD_FINI(bitmap)
 
252
{
 
253
}