2009-07-20 Joe Auricchio <jauricchio@gmail.com>
[grub2/phcoder.git] / include / grub / video.h
blobc98731ddf6e0a9cdddc563acbade23609f5036ed
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 #define GRUB_VIDEO_MODE_TYPE_PURE_TEXT 0x00000040
38 #define GRUB_VIDEO_MODE_TYPE_ALPHA 0x00000020
39 #define GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED 0x00000010
40 #define GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP 0x00000004
41 #define GRUB_VIDEO_MODE_TYPE_INDEX_COLOR 0x00000002
42 #define GRUB_VIDEO_MODE_TYPE_RGB 0x00000001
44 /* Defines used to mask flags. */
45 #define GRUB_VIDEO_MODE_TYPE_COLOR_MASK 0x0000000F
47 /* Defines used to specify requested bit depth. */
48 #define GRUB_VIDEO_MODE_TYPE_DEPTH_MASK 0x0000ff00
49 #define GRUB_VIDEO_MODE_TYPE_DEPTH_POS 8
51 /* Defined predefined render targets. */
52 #define GRUB_VIDEO_RENDER_TARGET_DISPLAY ((struct grub_video_render_target *) 0)
53 #define GRUB_VIDEO_RENDER_TARGET_FRONT_BUFFER ((struct grub_video_render_target *) 0)
54 #define GRUB_VIDEO_RENDER_TARGET_BACK_BUFFER ((struct grub_video_render_target *) 1)
56 /* Defined blitting formats. */
57 enum grub_video_blit_format
59 /* Generic RGBA, use fields & masks. */
60 GRUB_VIDEO_BLIT_FORMAT_RGBA,
62 /* Optimized RGBA's. */
63 GRUB_VIDEO_BLIT_FORMAT_RGBA_8888,
64 GRUB_VIDEO_BLIT_FORMAT_BGRA_8888,
66 /* Generic RGB, use fields & masks. */
67 GRUB_VIDEO_BLIT_FORMAT_RGB,
69 /* Optimized RGB's. */
70 GRUB_VIDEO_BLIT_FORMAT_RGB_888,
71 GRUB_VIDEO_BLIT_FORMAT_BGR_888,
72 GRUB_VIDEO_BLIT_FORMAT_RGB_565,
73 GRUB_VIDEO_BLIT_FORMAT_BGR_565,
75 /* When needed, decode color or just use value as is. */
76 GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
78 /* Two color bitmap; bits packed: rows are not padded to byte boundary. */
79 GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
82 /* Define blitting operators. */
83 enum grub_video_blit_operators
85 /* Replace target bitmap data with source. */
86 GRUB_VIDEO_BLIT_REPLACE,
87 /* Blend target and source based on source's alpha value. */
88 GRUB_VIDEO_BLIT_BLEND
91 struct grub_video_mode_info
93 /* Width of the screen. */
94 unsigned int width;
96 /* Height of the screen. */
97 unsigned int height;
99 /* Mode type bitmask. Contains information like is it Index color or
100 RGB mode. */
101 unsigned int mode_type;
103 /* Bits per pixel. */
104 unsigned int bpp;
106 /* Bytes per pixel. */
107 unsigned int bytes_per_pixel;
109 /* Pitch of one scanline. How many bytes there are for scanline. */
110 unsigned int pitch;
112 /* In index color mode, number of colors. In RGB mode this is 256. */
113 unsigned int number_of_colors;
115 /* Optimization hint how binary data is coded. */
116 enum grub_video_blit_format blit_format;
118 /* How many bits are reserved for red color. */
119 unsigned int red_mask_size;
121 /* What is location of red color bits. In Index Color mode, this is 0. */
122 unsigned int red_field_pos;
124 /* How many bits are reserved for green color. */
125 unsigned int green_mask_size;
127 /* What is location of green color bits. In Index Color mode, this is 0. */
128 unsigned int green_field_pos;
130 /* How many bits are reserved for blue color. */
131 unsigned int blue_mask_size;
133 /* What is location of blue color bits. In Index Color mode, this is 0. */
134 unsigned int blue_field_pos;
136 /* How many bits are reserved in color. */
137 unsigned int reserved_mask_size;
139 /* What is location of reserved color bits. In Index Color mode,
140 this is 0. */
141 unsigned int reserved_field_pos;
143 /* For 1-bit bitmaps, the background color. Used for bits = 0. */
144 grub_uint8_t bg_red;
145 grub_uint8_t bg_green;
146 grub_uint8_t bg_blue;
147 grub_uint8_t bg_alpha;
149 /* For 1-bit bitmaps, the foreground color. Used for bits = 1. */
150 grub_uint8_t fg_red;
151 grub_uint8_t fg_green;
152 grub_uint8_t fg_blue;
153 grub_uint8_t fg_alpha;
156 struct grub_video_palette_data
158 grub_uint8_t r; /* Red color value (0-255). */
159 grub_uint8_t g; /* Green color value (0-255). */
160 grub_uint8_t b; /* Blue color value (0-255). */
161 grub_uint8_t a; /* Reserved bits value (0-255). */
164 struct grub_video_adapter
166 /* The video adapter name. */
167 const char *name;
169 /* Initialize the video adapter. */
170 grub_err_t (*init) (void);
172 /* Clean up the video adapter. */
173 grub_err_t (*fini) (void);
175 grub_err_t (*setup) (unsigned int width, unsigned int height,
176 unsigned int mode_type);
178 grub_err_t (*get_info) (struct grub_video_mode_info *mode_info);
180 grub_err_t (*set_palette) (unsigned int start, unsigned int count,
181 struct grub_video_palette_data *palette_data);
183 grub_err_t (*get_palette) (unsigned int start, unsigned int count,
184 struct grub_video_palette_data *palette_data);
186 grub_err_t (*set_viewport) (unsigned int x, unsigned int y,
187 unsigned int width, unsigned int height);
189 grub_err_t (*get_viewport) (unsigned int *x, unsigned int *y,
190 unsigned int *width, unsigned int *height);
192 grub_video_color_t (*map_color) (grub_uint32_t color_name);
194 grub_video_color_t (*map_rgb) (grub_uint8_t red, grub_uint8_t green,
195 grub_uint8_t blue);
197 grub_video_color_t (*map_rgba) (grub_uint8_t red, grub_uint8_t green,
198 grub_uint8_t blue, grub_uint8_t alpha);
200 grub_err_t (*unmap_color) (grub_video_color_t color,
201 grub_uint8_t *red, grub_uint8_t *green,
202 grub_uint8_t *blue, grub_uint8_t *alpha);
204 grub_err_t (*fill_rect) (grub_video_color_t color, int x, int y,
205 unsigned int width, unsigned int height);
207 grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap,
208 enum grub_video_blit_operators oper,
209 int x, int y, int offset_x, int offset_y,
210 unsigned int width, unsigned int height);
212 grub_err_t (*blit_render_target) (struct grub_video_render_target *source,
213 enum grub_video_blit_operators oper,
214 int x, int y, int offset_x, int offset_y,
215 unsigned int width, unsigned int height);
217 grub_err_t (*scroll) (grub_video_color_t color, int dx, int dy);
219 grub_err_t (*swap_buffers) (void);
221 grub_err_t (*create_render_target) (struct grub_video_render_target **result,
222 unsigned int width, unsigned int height,
223 unsigned int mode_type);
225 grub_err_t (*delete_render_target) (struct grub_video_render_target *target);
227 grub_err_t (*set_active_render_target) (struct grub_video_render_target *target);
229 grub_err_t (*get_active_render_target) (struct grub_video_render_target **target);
231 /* The next video adapter. */
232 struct grub_video_adapter *next;
234 typedef struct grub_video_adapter *grub_video_adapter_t;
236 void grub_video_register (grub_video_adapter_t adapter);
237 void grub_video_unregister (grub_video_adapter_t adapter);
238 void grub_video_iterate (int (*hook) (grub_video_adapter_t adapter));
240 grub_err_t grub_video_restore (void);
242 grub_err_t grub_video_get_info (struct grub_video_mode_info *mode_info);
244 enum grub_video_blit_format grub_video_get_blit_format (struct grub_video_mode_info *mode_info);
246 grub_err_t grub_video_set_palette (unsigned int start, unsigned int count,
247 struct grub_video_palette_data *palette_data);
249 grub_err_t grub_video_get_palette (unsigned int start, unsigned int count,
250 struct grub_video_palette_data *palette_data);
252 grub_err_t grub_video_set_viewport (unsigned int x, unsigned int y,
253 unsigned int width, unsigned int height);
255 grub_err_t grub_video_get_viewport (unsigned int *x, unsigned int *y,
256 unsigned int *width, unsigned int *height);
258 grub_video_color_t grub_video_map_color (grub_uint32_t color_name);
260 grub_video_color_t grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green,
261 grub_uint8_t blue);
263 grub_video_color_t grub_video_map_rgba (grub_uint8_t red, grub_uint8_t green,
264 grub_uint8_t blue, grub_uint8_t alpha);
266 grub_err_t grub_video_unmap_color (grub_video_color_t color,
267 grub_uint8_t *red, grub_uint8_t *green,
268 grub_uint8_t *blue, grub_uint8_t *alpha);
270 grub_err_t grub_video_fill_rect (grub_video_color_t color, int x, int y,
271 unsigned int width, unsigned int height);
273 grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap,
274 enum grub_video_blit_operators oper,
275 int x, int y, int offset_x, int offset_y,
276 unsigned int width, unsigned int height);
278 grub_err_t grub_video_blit_render_target (struct grub_video_render_target *source,
279 enum grub_video_blit_operators oper,
280 int x, int y,
281 int offset_x, int offset_y,
282 unsigned int width,
283 unsigned int height);
285 grub_err_t grub_video_scroll (grub_video_color_t color, int dx, int dy);
287 grub_err_t grub_video_swap_buffers (void);
289 grub_err_t grub_video_create_render_target (struct grub_video_render_target **result,
290 unsigned int width,
291 unsigned int height,
292 unsigned int mode_type);
294 grub_err_t grub_video_delete_render_target (struct grub_video_render_target *target);
296 grub_err_t grub_video_set_active_render_target (struct grub_video_render_target *target);
298 grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target);
300 grub_err_t grub_video_set_mode (char *modestring,
301 int NESTED_FUNC_ATTR (*hook) (grub_video_adapter_t p,
302 struct grub_video_mode_info *mode_info));
304 #endif /* ! GRUB_VIDEO_HEADER */