GRUB-1.98 changes
[grub2/jjazz.git] / include / grub / video.h
blob57f2b37f25dac80487462539a5a9389963e605df
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007,2008,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/>.
19 #ifndef GRUB_VIDEO_HEADER
20 #define GRUB_VIDEO_HEADER 1
22 #include <grub/err.h>
23 #include <grub/types.h>
25 /* Video color in hardware dependent format. Users should not assume any
26 specific coding format. */
27 typedef grub_uint32_t grub_video_color_t;
29 /* This structure is driver specific and should not be accessed directly by
30 outside code. */
31 struct grub_video_render_target;
33 /* Forward declarations for used data structures. */
34 struct grub_video_bitmap;
36 /* Defines used to describe video mode or rendering target. */
37 /* If following is set render target contains currenly displayed image
38 after swapping buffers (otherwise it contains previously displayed image).
40 #define GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP 0x00000080
41 #define GRUB_VIDEO_MODE_TYPE_PURE_TEXT 0x00000040
42 #define GRUB_VIDEO_MODE_TYPE_ALPHA 0x00000020
43 #define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED 0x00000010
44 #define GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP 0x00000004
45 #define GRUB_VIDEO_MODE_TYPE_INDEX_COLOR 0x00000002
46 #define GRUB_VIDEO_MODE_TYPE_RGB 0x00000001
48 /* Defines used to mask flags. */
49 #define GRUB_VIDEO_MODE_TYPE_COLOR_MASK 0x0000000F
51 /* Defines used to specify requested bit depth. */
52 #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK 0x0000ff00
53 #define GRUB_VIDEO_MODE_TYPE_DEPTH_POS 8
55 /* The basic render target representing the whole display. This always
56 renders to the back buffer when double-buffering is in use. */
57 #define GRUB_VIDEO_RENDER_TARGET_DISPLAY \
58 ((struct grub_video_render_target *) 0)
60 /* Defined blitting formats. */
61 enum grub_video_blit_format
63 /* Generic RGBA, use fields & masks. */
64 GRUB_VIDEO_BLIT_FORMAT_RGBA,
66 /* Optimized RGBA's. */
67 GRUB_VIDEO_BLIT_FORMAT_RGBA_8888,
68 GRUB_VIDEO_BLIT_FORMAT_BGRA_8888,
70 /* Generic RGB, use fields & masks. */
71 GRUB_VIDEO_BLIT_FORMAT_RGB,
73 /* Optimized RGB's. */
74 GRUB_VIDEO_BLIT_FORMAT_RGB_888,
75 GRUB_VIDEO_BLIT_FORMAT_BGR_888,
76 GRUB_VIDEO_BLIT_FORMAT_RGB_565,
77 GRUB_VIDEO_BLIT_FORMAT_BGR_565,
79 /* When needed, decode color or just use value as is. */
80 GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
82 /* Two color bitmap; bits packed: rows are not padded to byte boundary. */
83 GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
86 /* Define blitting operators. */
87 enum grub_video_blit_operators
89 /* Replace target bitmap data with source. */
90 GRUB_VIDEO_BLIT_REPLACE,
91 /* Blend target and source based on source's alpha value. */
92 GRUB_VIDEO_BLIT_BLEND
95 struct grub_video_mode_info
97 /* Width of the screen. */
98 unsigned int width;
100 /* Height of the screen. */
101 unsigned int height;
103 /* Mode type bitmask. Contains information like is it Index color or
104 RGB mode. */
105 unsigned int mode_type;
107 /* Bits per pixel. */
108 unsigned int bpp;
110 /* Bytes per pixel. */
111 unsigned int bytes_per_pixel;
113 /* Pitch of one scanline. How many bytes there are for scanline. */
114 unsigned int pitch;
116 /* In index color mode, number of colors. In RGB mode this is 256. */
117 unsigned int number_of_colors;
119 /* Optimization hint how binary data is coded. */
120 enum grub_video_blit_format blit_format;
122 /* How many bits are reserved for red color. */
123 unsigned int red_mask_size;
125 /* What is location of red color bits. In Index Color mode, this is 0. */
126 unsigned int red_field_pos;
128 /* How many bits are reserved for green color. */
129 unsigned int green_mask_size;
131 /* What is location of green color bits. In Index Color mode, this is 0. */
132 unsigned int green_field_pos;
134 /* How many bits are reserved for blue color. */
135 unsigned int blue_mask_size;
137 /* What is location of blue color bits. In Index Color mode, this is 0. */
138 unsigned int blue_field_pos;
140 /* How many bits are reserved in color. */
141 unsigned int reserved_mask_size;
143 /* What is location of reserved color bits. In Index Color mode,
144 this is 0. */
145 unsigned int reserved_field_pos;
147 /* For 1-bit bitmaps, the background color. Used for bits = 0. */
148 grub_uint8_t bg_red;
149 grub_uint8_t bg_green;
150 grub_uint8_t bg_blue;
151 grub_uint8_t bg_alpha;
153 /* For 1-bit bitmaps, the foreground color. Used for bits = 1. */
154 grub_uint8_t fg_red;
155 grub_uint8_t fg_green;
156 grub_uint8_t fg_blue;
157 grub_uint8_t fg_alpha;
160 /* A 2D rectangle type. */
161 struct grub_video_rect
163 unsigned x;
164 unsigned y;
165 unsigned width;
166 unsigned height;
168 typedef struct grub_video_rect grub_video_rect_t;
170 struct grub_video_palette_data
172 grub_uint8_t r; /* Red color value (0-255). */
173 grub_uint8_t g; /* Green color value (0-255). */
174 grub_uint8_t b; /* Blue color value (0-255). */
175 grub_uint8_t a; /* Reserved bits value (0-255). */
178 typedef enum grub_video_driver_id
180 GRUB_VIDEO_DRIVER_NONE,
181 GRUB_VIDEO_DRIVER_VBE,
182 GRUB_VIDEO_DRIVER_EFI_UGA,
183 GRUB_VIDEO_DRIVER_EFI_GOP
184 } grub_video_driver_id_t;
186 struct grub_video_adapter
188 /* The video adapter name. */
189 const char *name;
190 grub_video_driver_id_t id;
192 /* Initialize the video adapter. */
193 grub_err_t (*init) (void);
195 /* Clean up the video adapter. */
196 grub_err_t (*fini) (void);
198 grub_err_t (*setup) (unsigned int width, unsigned int height,
199 unsigned int mode_type, unsigned int mode_mask);
201 grub_err_t (*get_info) (struct grub_video_mode_info *mode_info);
203 grub_err_t (*get_info_and_fini) (struct grub_video_mode_info *mode_info,
204 void **framebuffer);
206 grub_err_t (*set_palette) (unsigned int start, unsigned int count,
207 struct grub_video_palette_data *palette_data);
209 grub_err_t (*get_palette) (unsigned int start, unsigned int count,
210 struct grub_video_palette_data *palette_data);
212 grub_err_t (*set_viewport) (unsigned int x, unsigned int y,
213 unsigned int width, unsigned int height);
215 grub_err_t (*get_viewport) (unsigned int *x, unsigned int *y,
216 unsigned int *width, unsigned int *height);
218 grub_video_color_t (*map_color) (grub_uint32_t color_name);
220 grub_video_color_t (*map_rgb) (grub_uint8_t red, grub_uint8_t green,
221 grub_uint8_t blue);
223 grub_video_color_t (*map_rgba) (grub_uint8_t red, grub_uint8_t green,
224 grub_uint8_t blue, grub_uint8_t alpha);
226 grub_err_t (*unmap_color) (grub_video_color_t color,
227 grub_uint8_t *red, grub_uint8_t *green,
228 grub_uint8_t *blue, grub_uint8_t *alpha);
230 grub_err_t (*fill_rect) (grub_video_color_t color, int x, int y,
231 unsigned int width, unsigned int height);
233 grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,
234 enum grub_video_blit_operators oper,
235 int x, int y, int offset_x, int offset_y,
236 unsigned int width, unsigned int height);
238 grub_err_t (*blit_render_target) (struct grub_video_render_target *source,
239 enum grub_video_blit_operators oper,
240 int x, int y, int offset_x, int offset_y,
241 unsigned int width, unsigned int height);
243 grub_err_t (*scroll) (grub_video_color_t color, int dx, int dy);
245 grub_err_t (*swap_buffers) (void);
247 grub_err_t (*create_render_target) (struct grub_video_render_target **result,
248 unsigned int width, unsigned int height,
249 unsigned int mode_type);
251 grub_err_t (*delete_render_target) (struct grub_video_render_target *target);
253 grub_err_t (*set_active_render_target) (struct grub_video_render_target *target);
255 grub_err_t (*get_active_render_target) (struct grub_video_render_target **target);
257 /* The next video adapter. */
258 struct grub_video_adapter *next;
260 typedef struct grub_video_adapter *grub_video_adapter_t;
262 void EXPORT_FUNC (grub_video_register) (grub_video_adapter_t adapter);
263 void grub_video_unregister (grub_video_adapter_t adapter);
264 void grub_video_iterate (int (*hook) (grub_video_adapter_t adapter));
266 grub_err_t EXPORT_FUNC (grub_video_restore) (void);
268 grub_err_t EXPORT_FUNC (grub_video_get_info) (struct grub_video_mode_info *mode_info);
270 /* Framebuffer address may change as a part of normal operation
271 (e.g. double buffering). That's why you need to stop video subsystem to be
272 sure that framebuffer address doesn't change. To ensure this abstraction
273 grub_video_get_info_and_fini is the only function supplying framebuffer
274 address. */
275 grub_err_t grub_video_get_info_and_fini (struct grub_video_mode_info *mode_info,
276 void **framebuffer);
278 enum grub_video_blit_format grub_video_get_blit_format (struct grub_video_mode_info *mode_info);
280 grub_err_t grub_video_set_palette (unsigned int start, unsigned int count,
281 struct grub_video_palette_data *palette_data);
283 grub_err_t grub_video_get_palette (unsigned int start, unsigned int count,
284 struct grub_video_palette_data *palette_data);
286 grub_err_t EXPORT_FUNC (grub_video_set_viewport) (unsigned int x,
287 unsigned int y,
288 unsigned int width,
289 unsigned int height);
291 grub_err_t EXPORT_FUNC (grub_video_get_viewport) (unsigned int *x,
292 unsigned int *y,
293 unsigned int *width,
294 unsigned int *height);
296 grub_video_color_t EXPORT_FUNC (grub_video_map_color) (grub_uint32_t color_name);
298 grub_video_color_t EXPORT_FUNC (grub_video_map_rgb) (grub_uint8_t red,
299 grub_uint8_t green,
300 grub_uint8_t blue);
302 grub_video_color_t EXPORT_FUNC (grub_video_map_rgba) (grub_uint8_t red,
303 grub_uint8_t green,
304 grub_uint8_t blue,
305 grub_uint8_t alpha);
307 grub_err_t EXPORT_FUNC (grub_video_unmap_color) (grub_video_color_t color,
308 grub_uint8_t *red,
309 grub_uint8_t *green,
310 grub_uint8_t *blue,
311 grub_uint8_t *alpha);
313 grub_err_t EXPORT_FUNC (grub_video_fill_rect) (grub_video_color_t color,
314 int x, int y,
315 unsigned int width,
316 unsigned int height);
318 grub_err_t EXPORT_FUNC (grub_video_blit_bitmap) (struct grub_video_bitmap *bitmap,
319 enum grub_video_blit_operators oper,
320 int x, int y,
321 int offset_x, int offset_y,
322 unsigned int width,
323 unsigned int height);
325 grub_err_t EXPORT_FUNC (grub_video_blit_render_target) (struct grub_video_render_target *source,
326 enum grub_video_blit_operators oper,
327 int x, int y,
328 int offset_x,
329 int offset_y,
330 unsigned int width,
331 unsigned int height);
333 grub_err_t grub_video_scroll (grub_video_color_t color, int dx, int dy);
335 grub_err_t EXPORT_FUNC (grub_video_swap_buffers) (void);
337 grub_err_t EXPORT_FUNC (grub_video_create_render_target) (struct grub_video_render_target **result,
338 unsigned int width,
339 unsigned int height,
340 unsigned int mode_type);
342 grub_err_t EXPORT_FUNC (grub_video_delete_render_target) (struct grub_video_render_target *target);
344 grub_err_t EXPORT_FUNC (grub_video_set_active_render_target) (struct grub_video_render_target *target);
346 grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target);
348 grub_err_t EXPORT_FUNC (grub_video_set_mode) (const char *modestring,
349 unsigned int modemask,
350 unsigned int modevalue);
352 static inline int
353 grub_video_check_mode_flag (unsigned int flags, unsigned int mask,
354 unsigned int flag, int def)
356 return (flag & mask) ? !! (flags & flag) : def;
359 grub_video_driver_id_t
360 grub_video_get_driver_id (void);
362 #endif /* ! GRUB_VIDEO_HEADER */