~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to video/emu/sdl.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) 2005,2006,2007,2008,2009  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
 
#define grub_video_render_target grub_video_fbrender_target
20
 
 
21
 
#include <grub/err.h>
22
 
#include <grub/types.h>
23
 
#include <grub/dl.h>
24
 
#include <grub/misc.h>
25
 
#include <grub/mm.h>
26
 
#include <grub/video.h>
27
 
#include <grub/video_fb.h>
28
 
#include <SDL/SDL.h>
29
 
 
30
 
static SDL_Surface *window = 0;
31
 
static struct grub_video_render_target *sdl_render_target;
32
 
static struct grub_video_mode_info mode_info;
33
 
 
34
 
static grub_err_t
35
 
grub_video_sdl_set_palette (unsigned int start, unsigned int count,
36
 
                            struct grub_video_palette_data *palette_data);
37
 
 
38
 
static grub_err_t
39
 
grub_video_sdl_init (void)
40
 
{
41
 
  window = 0;
42
 
 
43
 
  if (SDL_Init (SDL_INIT_VIDEO) < 0)
44
 
    return grub_error (GRUB_ERR_BAD_DEVICE, "Couldn't init SDL: %s",
45
 
                       SDL_GetError ());
46
 
 
47
 
  grub_memset (&mode_info, 0, sizeof (mode_info));
48
 
 
49
 
  return grub_video_fb_init ();
50
 
}
51
 
 
52
 
static grub_err_t
53
 
grub_video_sdl_fini (void)
54
 
{
55
 
  SDL_Quit ();
56
 
  window = 0;
57
 
 
58
 
  grub_memset (&mode_info, 0, sizeof (mode_info));
59
 
 
60
 
  return grub_video_fb_fini ();
61
 
}
62
 
 
63
 
static inline unsigned int
64
 
get_mask_size (grub_uint32_t mask)
65
 
{
66
 
  unsigned i;
67
 
  for (i = 0; mask > 1U << i; i++);
68
 
  return i;
69
 
}
70
 
 
71
 
static grub_err_t
72
 
grub_video_sdl_setup (unsigned int width, unsigned int height,
73
 
                      unsigned int mode_type, unsigned int mode_mask)
74
 
{
75
 
  int depth;
76
 
  int flags = 0;
77
 
  grub_err_t err;
78
 
 
79
 
  /* Decode depth from mode_type.  If it is zero, then autodetect.  */
80
 
  depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
81
 
          >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;
82
 
 
83
 
  if (depth == 0)
84
 
    depth = 32;
85
 
 
86
 
  if (width == 0 && height == 0)
87
 
    {
88
 
      width = 800;
89
 
      height = 600;
90
 
    }
91
 
 
92
 
  if ((mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)
93
 
      || !(mode_mask & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED))
94
 
    flags |= SDL_DOUBLEBUF;
95
 
 
96
 
  window = SDL_SetVideoMode (width, height, depth, flags | SDL_HWSURFACE);
97
 
  if (! window)
98
 
    window = SDL_SetVideoMode (width, height, depth, flags | SDL_SWSURFACE);
99
 
  if (! window)
100
 
    return grub_error (GRUB_ERR_BAD_DEVICE, "Couldn't open window: %s",
101
 
                       SDL_GetError ());
102
 
 
103
 
  grub_memset (&sdl_render_target, 0, sizeof (sdl_render_target));
104
 
 
105
 
  mode_info.width = window->w;
106
 
  mode_info.height = window->h;
107
 
  mode_info.mode_type = 0;
108
 
  if (window->flags & SDL_DOUBLEBUF)
109
 
    mode_info.mode_type
110
 
      |= GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED;
111
 
  if (window->format->palette)
112
 
    mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
113
 
  else
114
 
    mode_info.mode_type |= GRUB_VIDEO_MODE_TYPE_RGB;
115
 
 
116
 
  mode_info.bpp = window->format->BitsPerPixel;
117
 
  mode_info.bytes_per_pixel = window->format->BytesPerPixel;
118
 
  mode_info.pitch = window->pitch;
119
 
 
120
 
  /* In index color mode, number of colors.  In RGB mode this is 256.  */
121
 
  if (window->format->palette)
122
 
    mode_info.number_of_colors
123
 
      = 1 << window->format->BitsPerPixel;
124
 
  else
125
 
    mode_info.number_of_colors = 256;
126
 
 
127
 
  if (! window->format->palette)
128
 
    {
129
 
      mode_info.red_mask_size
130
 
        = get_mask_size (window->format->Rmask >> window->format->Rshift);
131
 
      mode_info.red_field_pos = window->format->Rshift;
132
 
      mode_info.green_mask_size
133
 
        = get_mask_size (window->format->Gmask >> window->format->Gshift);
134
 
      mode_info.green_field_pos = window->format->Gshift;
135
 
      mode_info.blue_mask_size
136
 
        = get_mask_size (window->format->Bmask >> window->format->Bshift);
137
 
      mode_info.blue_field_pos = window->format->Bshift;
138
 
      mode_info.reserved_mask_size
139
 
        = get_mask_size (window->format->Amask >> window->format->Ashift);
140
 
      mode_info.reserved_field_pos = window->format->Ashift;
141
 
      mode_info.blit_format
142
 
        = grub_video_get_blit_format (&mode_info);
143
 
    }
144
 
 
145
 
  err = grub_video_fb_create_render_target_from_pointer (&sdl_render_target,
146
 
                                                         &mode_info,
147
 
                                                         window->pixels);
148
 
  if (err)
149
 
    return err;
150
 
 
151
 
  /* Copy default palette to initialize emulated palette.  */
152
 
  grub_video_sdl_set_palette (0, (sizeof (grub_video_fbstd_colors)
153
 
                                  / sizeof (grub_video_fbstd_colors[0])),
154
 
                              grub_video_fbstd_colors);
155
 
 
156
 
  /* Reset render target to SDL one.  */
157
 
  return grub_video_fb_set_active_render_target (sdl_render_target);
158
 
}
159
 
 
160
 
static grub_err_t
161
 
grub_video_sdl_set_palette (unsigned int start, unsigned int count,
162
 
                            struct grub_video_palette_data *palette_data)
163
 
{
164
 
  unsigned i;
165
 
  if (window->format->palette)
166
 
    {
167
 
      SDL_Color *tmp = grub_malloc (count * sizeof (tmp[0]));
168
 
      for (i = 0; i < count; i++)
169
 
        {
170
 
          tmp[i].r = palette_data[i].r;
171
 
          tmp[i].g = palette_data[i].g;
172
 
          tmp[i].b = palette_data[i].b;
173
 
          tmp[i].unused = palette_data[i].a;
174
 
        }
175
 
      SDL_SetColors (window, tmp, start, count);
176
 
      grub_free (tmp);
177
 
    }
178
 
 
179
 
  return grub_video_fb_set_palette (start, count, palette_data);
180
 
}
181
 
 
182
 
static grub_err_t
183
 
grub_video_sdl_swap_buffers (void)
184
 
{
185
 
  if (SDL_Flip (window) < 0)
186
 
    return grub_error (GRUB_ERR_BAD_DEVICE, "couldn't swap buffers: %s",
187
 
                       SDL_GetError ());
188
 
  return GRUB_ERR_NONE;
189
 
}
190
 
 
191
 
static grub_err_t
192
 
grub_video_sdl_set_active_render_target (struct grub_video_render_target *target)
193
 
{
194
 
  if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
195
 
    return grub_video_fb_set_active_render_target (sdl_render_target);
196
 
 
197
 
  return grub_video_fb_set_active_render_target (target);
198
 
}
199
 
 
200
 
static struct grub_video_adapter grub_video_sdl_adapter =
201
 
  {
202
 
    .name = "SDL Video Driver",
203
 
    .id = GRUB_VIDEO_DRIVER_SDL,
204
 
 
205
 
    .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE,
206
 
 
207
 
    .init = grub_video_sdl_init,
208
 
    .fini = grub_video_sdl_fini,
209
 
    .setup = grub_video_sdl_setup,
210
 
    .get_info = grub_video_fb_get_info,
211
 
    .set_palette = grub_video_sdl_set_palette,
212
 
    .get_palette = grub_video_fb_get_palette,
213
 
    .set_viewport = grub_video_fb_set_viewport,
214
 
    .get_viewport = grub_video_fb_get_viewport,
215
 
    .map_color = grub_video_fb_map_color,
216
 
    .map_rgb = grub_video_fb_map_rgb,
217
 
    .map_rgba = grub_video_fb_map_rgba,
218
 
    .unmap_color = grub_video_fb_unmap_color,
219
 
    .fill_rect = grub_video_fb_fill_rect,
220
 
    .blit_bitmap = grub_video_fb_blit_bitmap,
221
 
    .blit_render_target = grub_video_fb_blit_render_target,
222
 
    .scroll = grub_video_fb_scroll,
223
 
    .swap_buffers = grub_video_sdl_swap_buffers,
224
 
    .create_render_target = grub_video_fb_create_render_target,
225
 
    .delete_render_target = grub_video_fb_delete_render_target,
226
 
    .set_active_render_target = grub_video_sdl_set_active_render_target,
227
 
    .get_active_render_target = grub_video_fb_get_active_render_target,
228
 
 
229
 
    .next = 0
230
 
  };
231
 
 
232
 
GRUB_MOD_INIT(sdl)
233
 
{
234
 
  grub_video_register (&grub_video_sdl_adapter);
235
 
}
236
 
 
237
 
GRUB_MOD_FINI(sdl)
238
 
{
239
 
  grub_video_unregister (&grub_video_sdl_adapter);
240
 
}