2009-05-02 23:19:20 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2009 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/env.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/xnu.h>
|
2009-06-04 18:22:45 +00:00
|
|
|
#include <grub/mm.h>
|
2009-05-02 23:19:20 +00:00
|
|
|
#include <grub/cpu/xnu.h>
|
2009-08-14 12:41:58 +00:00
|
|
|
#include <grub/video_fb.h>
|
2009-11-20 09:46:30 +00:00
|
|
|
#include <grub/bitmap_scale.h>
|
2009-05-02 23:19:20 +00:00
|
|
|
|
|
|
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
|
2009-11-14 15:25:50 +00:00
|
|
|
#define DEFAULT_VIDEO_MODE "auto"
|
2009-06-04 18:22:45 +00:00
|
|
|
|
2009-05-02 23:19:20 +00:00
|
|
|
/* Setup video for xnu. */
|
|
|
|
grub_err_t
|
|
|
|
grub_xnu_set_video (struct grub_xnu_boot_params *params)
|
|
|
|
{
|
|
|
|
struct grub_video_mode_info mode_info;
|
|
|
|
int ret;
|
2010-02-06 15:32:45 +00:00
|
|
|
char *tmp;
|
|
|
|
const char *modevar;
|
2009-08-14 12:41:58 +00:00
|
|
|
void *framebuffer;
|
2009-05-02 23:19:20 +00:00
|
|
|
grub_err_t err;
|
2009-11-20 09:46:30 +00:00
|
|
|
struct grub_video_bitmap *bitmap = NULL;
|
2009-05-02 23:19:20 +00:00
|
|
|
|
2009-06-04 18:22:45 +00:00
|
|
|
modevar = grub_env_get ("gfxpayload");
|
2009-11-14 15:25:50 +00:00
|
|
|
/* Consider only graphical 32-bit deep modes. */
|
2009-06-04 18:22:45 +00:00
|
|
|
if (! modevar || *modevar == 0)
|
2009-11-14 15:25:50 +00:00
|
|
|
err = grub_video_set_mode (DEFAULT_VIDEO_MODE,
|
|
|
|
GRUB_VIDEO_MODE_TYPE_PURE_TEXT
|
|
|
|
| GRUB_VIDEO_MODE_TYPE_DEPTH_MASK,
|
|
|
|
32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS);
|
2009-06-04 18:22:45 +00:00
|
|
|
else
|
|
|
|
{
|
2010-01-20 08:12:47 +00:00
|
|
|
tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
|
2009-06-04 18:22:45 +00:00
|
|
|
if (! tmp)
|
2010-02-06 15:32:45 +00:00
|
|
|
return grub_errno;
|
2009-11-14 15:25:50 +00:00
|
|
|
err = grub_video_set_mode (tmp,
|
|
|
|
GRUB_VIDEO_MODE_TYPE_PURE_TEXT
|
|
|
|
| GRUB_VIDEO_MODE_TYPE_DEPTH_MASK,
|
|
|
|
32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS);
|
2009-06-04 18:22:45 +00:00
|
|
|
grub_free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2009-11-20 09:46:30 +00:00
|
|
|
ret = grub_video_get_info (&mode_info);
|
|
|
|
if (ret)
|
|
|
|
return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
|
|
|
|
|
2009-10-15 12:40:13 +00:00
|
|
|
if (grub_xnu_bitmap)
|
2009-11-20 09:46:30 +00:00
|
|
|
{
|
|
|
|
if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH)
|
|
|
|
err = grub_video_bitmap_create_scaled (&bitmap,
|
|
|
|
mode_info.width,
|
|
|
|
mode_info.height,
|
|
|
|
grub_xnu_bitmap,
|
|
|
|
GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
|
|
|
|
else
|
|
|
|
bitmap = grub_xnu_bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitmap)
|
2009-10-15 12:40:13 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
2009-11-20 09:46:30 +00:00
|
|
|
x = mode_info.width - bitmap->mode_info.width;
|
2009-10-15 12:40:13 +00:00
|
|
|
x /= 2;
|
2009-11-20 09:46:30 +00:00
|
|
|
y = mode_info.height - bitmap->mode_info.height;
|
2009-10-15 12:40:13 +00:00
|
|
|
y /= 2;
|
2009-11-20 09:46:30 +00:00
|
|
|
err = grub_video_blit_bitmap (bitmap,
|
2009-10-15 12:40:13 +00:00
|
|
|
GRUB_VIDEO_BLIT_REPLACE,
|
|
|
|
x > 0 ? x : 0,
|
|
|
|
y > 0 ? y : 0,
|
|
|
|
x < 0 ? -x : 0,
|
|
|
|
y < 0 ? -y : 0,
|
2009-11-20 09:46:30 +00:00
|
|
|
min (bitmap->mode_info.width,
|
2009-10-15 12:40:13 +00:00
|
|
|
mode_info.width),
|
2009-11-20 09:46:30 +00:00
|
|
|
min (bitmap->mode_info.height,
|
2009-10-15 12:40:13 +00:00
|
|
|
mode_info.height));
|
2009-11-20 09:46:30 +00:00
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
bitmap = 0;
|
2009-10-15 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2009-08-14 12:41:58 +00:00
|
|
|
ret = grub_video_get_info_and_fini (&mode_info, &framebuffer);
|
2009-05-02 23:19:20 +00:00
|
|
|
if (ret)
|
|
|
|
return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
|
|
|
|
|
|
|
|
params->lfb_width = mode_info.width;
|
|
|
|
params->lfb_height = mode_info.height;
|
|
|
|
params->lfb_depth = mode_info.bpp;
|
|
|
|
params->lfb_line_len = mode_info.pitch;
|
|
|
|
|
2009-08-14 12:41:58 +00:00
|
|
|
params->lfb_base = PTR_TO_UINT32 (framebuffer);
|
2009-11-20 09:46:30 +00:00
|
|
|
params->lfb_mode = bitmap ? GRUB_XNU_VIDEO_SPLASH
|
|
|
|
: GRUB_XNU_VIDEO_TEXT_IN_VIDEO;
|
2009-05-02 23:19:20 +00:00
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|