* kern/i386/loader.S (grub_multiboot_backward_relocator): Improve
[grub2/phcoder/solaris.git] / commands / videotest.c
blob477727bbcaeabfdc43662d8477dee27c4f12bfb1
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007 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 #include <grub/machine/memory.h>
20 #include <grub/video.h>
21 #include <grub/types.h>
22 #include <grub/dl.h>
23 #include <grub/misc.h>
24 #include <grub/normal.h>
25 #include <grub/arg.h>
26 #include <grub/mm.h>
27 #include <grub/font.h>
28 #include <grub/term.h>
30 static grub_err_t
31 grub_cmd_videotest (struct grub_arg_list *state __attribute__ ((unused)),
32 int argc __attribute__ ((unused)),
33 char **args __attribute__ ((unused)))
35 if (grub_video_setup (1024, 768,
36 GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != GRUB_ERR_NONE)
37 return grub_errno;
39 grub_getkey ();
41 grub_video_color_t color;
42 unsigned int x;
43 unsigned int y;
44 unsigned int width;
45 unsigned int height;
46 int i;
47 struct grub_font_glyph glyph;
48 struct grub_video_render_target *text_layer;
49 grub_video_color_t palette[16];
51 grub_video_get_viewport (&x, &y, &width, &height);
53 grub_video_create_render_target (&text_layer, width, height,
54 GRUB_VIDEO_MODE_TYPE_RGB
55 | GRUB_VIDEO_MODE_TYPE_ALPHA);
57 grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
59 color = grub_video_map_rgb (0, 0, 0);
60 grub_video_fill_rect (color, 0, 0, width, height);
62 color = grub_video_map_rgb (255, 0, 0);
63 grub_video_fill_rect (color, 0, 0, 100, 100);
65 color = grub_video_map_rgb (0, 255, 255);
66 grub_video_fill_rect (color, 100, 100, 100, 100);
68 grub_font_get_glyph ('*', &glyph);
69 grub_video_blit_glyph (&glyph, color, 200 ,0);
71 grub_video_set_viewport (x + 150, y + 150,
72 width - 150 * 2, height - 150 * 2);
73 color = grub_video_map_rgb (77, 33, 77);
74 grub_video_fill_rect (color, 0, 0, width, height);
76 grub_video_set_active_render_target (text_layer);
78 color = grub_video_map_rgb (255, 255, 255);
80 grub_font_get_glyph ('A', &glyph);
81 grub_video_blit_glyph (&glyph, color, 16, 16);
82 grub_font_get_glyph ('B', &glyph);
83 grub_video_blit_glyph (&glyph, color, 16 * 2, 16);
85 grub_font_get_glyph ('*', &glyph);
87 for (i = 0; i < 16; i++)
89 color = grub_video_map_color (i);
90 palette[i] = color;
91 grub_video_blit_glyph (&glyph, color, 16 + i * 16, 32);
94 grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
96 for (i = 0; i < 255; i++)
98 color = grub_video_map_rgb (i, 33, 77);
99 grub_video_fill_rect (color, 0, 0, width, height);
100 grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, 0, 0,
101 0, 0, width, height);
104 grub_getkey ();
106 grub_video_delete_render_target (text_layer);
108 grub_video_restore ();
110 for (i = 0; i < 16; i++)
111 grub_printf("color %d: %08x\n", i, palette[i]);
113 grub_errno = GRUB_ERR_NONE;
114 return grub_errno;
117 GRUB_MOD_INIT(videotest)
119 grub_register_command ("videotest",
120 grub_cmd_videotest,
121 GRUB_COMMAND_FLAG_BOTH,
122 "videotest",
123 "Test video subsystem",
127 GRUB_MOD_FINI(videotest)
129 grub_unregister_command ("videotest");