~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, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

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
}