~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to loader/i386/pc/xnu.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 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
 
#include <grub/env.h>
20
 
#include <grub/misc.h>
21
 
#include <grub/xnu.h>
22
 
#include <grub/mm.h>
23
 
#include <grub/cpu/xnu.h>
24
 
#include <grub/video_fb.h>
25
 
#include <grub/bitmap_scale.h>
26
 
 
27
 
#define min(a,b) (((a) < (b)) ? (a) : (b))
28
 
#define max(a,b) (((a) > (b)) ? (a) : (b))
29
 
 
30
 
#define DEFAULT_VIDEO_MODE "auto"
31
 
 
32
 
/* Setup video for xnu. */
33
 
grub_err_t
34
 
grub_xnu_set_video (struct grub_xnu_boot_params *params)
35
 
{
36
 
  struct grub_video_mode_info mode_info;
37
 
  int ret;
38
 
  char *tmp;
39
 
  const char *modevar;
40
 
  void *framebuffer;
41
 
  grub_err_t err;
42
 
  struct grub_video_bitmap *bitmap = NULL;
43
 
 
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);
51
 
  else
52
 
    {
53
 
      tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
54
 
      if (! tmp)
55
 
        return grub_errno;
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);
60
 
      grub_free (tmp);
61
 
    }
62
 
 
63
 
  if (err)
64
 
    return err;
65
 
 
66
 
  ret = grub_video_get_info (&mode_info);
67
 
  if (ret)
68
 
    return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
69
 
 
70
 
  if (grub_xnu_bitmap)
71
 
    {
72
 
      if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH)
73
 
        err = grub_video_bitmap_create_scaled (&bitmap,
74
 
                                               mode_info.width,
75
 
                                               mode_info.height,
76
 
                                               grub_xnu_bitmap,
77
 
                                               GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST);
78
 
      else
79
 
        bitmap = grub_xnu_bitmap;
80
 
    }
81
 
 
82
 
  if (bitmap)
83
 
    {
84
 
      int x, y;
85
 
 
86
 
      x = mode_info.width - bitmap->mode_info.width;
87
 
      x /= 2;
88
 
      y = mode_info.height - bitmap->mode_info.height;
89
 
      y /= 2;
90
 
      err = grub_video_blit_bitmap (bitmap,
91
 
                                    GRUB_VIDEO_BLIT_REPLACE,
92
 
                                    x > 0 ? x : 0,
93
 
                                    y > 0 ? y : 0,
94
 
                                    x < 0 ? -x : 0,
95
 
                                    y < 0 ? -y : 0,
96
 
                                    min (bitmap->mode_info.width,
97
 
                                         mode_info.width),
98
 
                                    min (bitmap->mode_info.height,
99
 
                                         mode_info.height));
100
 
    }
101
 
  if (err)
102
 
    {
103
 
      grub_print_error ();
104
 
      grub_errno = GRUB_ERR_NONE;
105
 
      bitmap = 0;
106
 
    }
107
 
 
108
 
  ret = grub_video_get_info_and_fini (&mode_info, &framebuffer);
109
 
  if (ret)
110
 
    return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters");
111
 
 
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;
116
 
 
117
 
  params->lfb_base = PTR_TO_UINT32 (framebuffer);
118
 
  params->lfb_mode = bitmap ? GRUB_XNU_VIDEO_SPLASH 
119
 
    : GRUB_XNU_VIDEO_TEXT_IN_VIDEO;
120
 
 
121
 
  return GRUB_ERR_NONE;
122
 
}
123