2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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/>.
20
#include <grub/misc.h>
23
#include <grub/cpu/xnu.h>
24
#include <grub/video_fb.h>
25
#include <grub/bitmap_scale.h>
27
#define min(a,b) (((a) < (b)) ? (a) : (b))
28
#define max(a,b) (((a) > (b)) ? (a) : (b))
30
#define DEFAULT_VIDEO_MODE "auto"
32
/* Setup video for xnu. */
34
grub_xnu_set_video (struct grub_xnu_boot_params *params)
36
struct grub_video_mode_info mode_info;
42
struct grub_video_bitmap *bitmap = NULL;
44
modevar = grub_env_get ("gfxpayload");
45
/* Consider only graphical 32-bit deep modes. */
46
if (! modevar || *modevar == 0)
47
err = grub_video_set_mode (DEFAULT_VIDEO_MODE,
48
GRUB_VIDEO_MODE_TYPE_PURE_TEXT
49
| GRUB_VIDEO_MODE_TYPE_DEPTH_MASK,
50
32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS);
53
tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
56
err = grub_video_set_mode (tmp,
57
GRUB_VIDEO_MODE_TYPE_PURE_TEXT
58
| GRUB_VIDEO_MODE_TYPE_DEPTH_MASK,
59
32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS);
66
ret = grub_video_get_info (&mode_info);
68
return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
72
if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH)
73
err = grub_video_bitmap_create_scaled (&bitmap,
77
GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
79
bitmap = grub_xnu_bitmap;
86
x = mode_info.width - bitmap->mode_info.width;
88
y = mode_info.height - bitmap->mode_info.height;
90
err = grub_video_blit_bitmap (bitmap,
91
GRUB_VIDEO_BLIT_REPLACE,
96
min (bitmap->mode_info.width,
98
min (bitmap->mode_info.height,
104
grub_errno = GRUB_ERR_NONE;
108
ret = grub_video_get_info_and_fini (&mode_info, &framebuffer);
110
return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
112
params->lfb_width = mode_info.width;
113
params->lfb_height = mode_info.height;
114
params->lfb_depth = mode_info.bpp;
115
params->lfb_line_len = mode_info.pitch;
117
params->lfb_base = PTR_TO_UINT32 (framebuffer);
118
params->lfb_mode = bitmap ? GRUB_XNU_VIDEO_SPLASH
119
: GRUB_XNU_VIDEO_TEXT_IN_VIDEO;
121
return GRUB_ERR_NONE;