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

« back to all changes in this revision

Viewing changes to commands/videotest.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <grub/term.h>
26
26
#include <grub/command.h>
27
27
#include <grub/i18n.h>
 
28
#include <grub/gfxmenu_view.h>
28
29
 
29
30
static grub_err_t
30
31
grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
38
39
  unsigned int width;
39
40
  unsigned int height;
40
41
  int i;
41
 
  grub_font_t sansbig;
42
 
  grub_font_t sans;
43
 
  grub_font_t sanssmall;
44
 
  grub_font_t fixed;
45
 
  struct grub_font_glyph *glyph;
46
42
  struct grub_video_render_target *text_layer;
47
43
  grub_video_color_t palette[16];
48
 
  const char *str;
49
 
  int texty;
50
44
 
51
45
  err = grub_video_set_mode ("auto", GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
52
46
  if (err)
54
48
 
55
49
  grub_video_get_viewport (&x, &y, &width, &height);
56
50
 
57
 
  grub_video_create_render_target (&text_layer, width, height,
58
 
                                   GRUB_VIDEO_MODE_TYPE_RGB
59
 
                                   | GRUB_VIDEO_MODE_TYPE_ALPHA);
60
 
 
61
 
  grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
62
 
 
63
 
  color = grub_video_map_rgb (0, 0, 0);
64
 
  grub_video_fill_rect (color, 0, 0, width, height);
65
 
 
66
 
  color = grub_video_map_rgb (255, 0, 0);
67
 
  grub_video_fill_rect (color, 0, 0, 100, 100);
68
 
 
69
 
  color = grub_video_map_rgb (0, 255, 255);
70
 
  grub_video_fill_rect (color, 100, 100, 100, 100);
71
 
 
72
 
  sansbig = grub_font_get ("Unknown Regular 16");
73
 
  sans = grub_font_get ("Unknown Regular 16");
74
 
  sanssmall = grub_font_get ("Unknown Regular 16");
75
 
  fixed = grub_font_get ("Fixed 20");
76
 
  if (! sansbig || ! sans || ! sanssmall || ! fixed)
77
 
    return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
78
 
 
79
 
  glyph = grub_font_get_glyph (fixed, '*');
80
 
  grub_font_draw_glyph (glyph, color, 200 ,0);
81
 
 
82
 
  grub_video_set_viewport (x + 150, y + 150,
83
 
                           width - 150 * 2, height - 150 * 2);
84
 
  color = grub_video_map_rgb (77, 33, 77);
85
 
  grub_video_fill_rect (color, 0, 0, width, height);
86
 
 
87
 
  grub_video_set_active_render_target (text_layer);
88
 
 
89
 
  color = grub_video_map_rgb (255, 255, 255);
90
 
 
91
 
  texty = 32;
92
 
  grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
93
 
                         sans, color, 16, texty);
94
 
  texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
95
 
 
96
 
  texty += grub_font_get_ascent (fixed);
97
 
  grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
98
 
                         fixed, color, 16, texty);
99
 
  texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
100
 
 
101
 
  /* To convert Unicode characters into UTF-8 for this test, the following
102
 
     command is useful:
 
51
  {
 
52
    const char *str;
 
53
    int texty;
 
54
    grub_font_t sansbig;
 
55
    grub_font_t sans;
 
56
    grub_font_t sanssmall;
 
57
    grub_font_t fixed;
 
58
    struct grub_font_glyph *glyph;
 
59
 
 
60
    grub_video_create_render_target (&text_layer, width, height,
 
61
                                     GRUB_VIDEO_MODE_TYPE_RGB
 
62
                                     | GRUB_VIDEO_MODE_TYPE_ALPHA);
 
63
 
 
64
    grub_video_set_active_render_target (text_layer);
 
65
 
 
66
    color = grub_video_map_rgb (0, 255, 255);
 
67
    sansbig = grub_font_get ("Unknown Regular 16");
 
68
    sans = grub_font_get ("Unknown Regular 16");
 
69
    sanssmall = grub_font_get ("Unknown Regular 16");
 
70
    fixed = grub_font_get ("Fixed 20");
 
71
    if (! sansbig || ! sans || ! sanssmall || ! fixed)
 
72
      return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
 
73
 
 
74
    glyph = grub_font_get_glyph (fixed, '*');
 
75
    grub_font_draw_glyph (glyph, color, 200 ,0);
 
76
 
 
77
    color = grub_video_map_rgb (255, 255, 255);
 
78
 
 
79
    texty = 32;
 
80
    grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
 
81
                           sans, color, 16, texty);
 
82
    texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
 
83
 
 
84
    texty += grub_font_get_ascent (fixed);
 
85
    grub_font_draw_string ("The quick brown fox jumped over the lazy dog.",
 
86
                           fixed, color, 16, texty);
 
87
    texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
 
88
 
 
89
    /* To convert Unicode characters into UTF-8 for this test, the following
 
90
       command is useful:
103
91
       echo -ne '\x00\x00\x26\x3A' | iconv -f UTF-32BE -t UTF-8 | od -t x1
104
 
     This converts the Unicode character U+263A to UTF-8.  */
105
 
 
106
 
  /* Characters used:
107
 
     Code point  Description                    UTF-8 encoding
108
 
     ----------- ------------------------------ --------------
109
 
     U+263A      unfilled smiley face           E2 98 BA
110
 
     U+00A1      inverted exclamation point     C2 A1
111
 
     U+00A3      British pound currency symbol  C2 A3
112
 
     U+03C4      Greek tau                      CF 84
113
 
     U+00E4      lowercase letter a with umlaut C3 A4
114
 
     U+2124      set 'Z' symbol (integers)      E2 84 A4
115
 
     U+2287      subset symbol                  E2 8A 87
116
 
     U+211D      set 'R' symbol (real numbers)  E2 84 9D  */
117
 
 
118
 
  str =
119
 
    "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
120
 
    " \xC2\xA1\xCF\x84\xC3\xA4u! "
121
 
    " \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D";
122
 
  color = grub_video_map_rgb (128, 128, 255);
123
 
 
124
 
  /* All characters in the string exist in the 'Fixed 20' (10x20) font.  */
125
 
  texty += grub_font_get_ascent(fixed);
126
 
  grub_font_draw_string (str, fixed, color, 16, texty);
127
 
  texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
128
 
 
129
 
  texty += grub_font_get_ascent(sansbig);
130
 
  grub_font_draw_string (str, sansbig, color, 16, texty);
131
 
  texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);
132
 
 
133
 
  texty += grub_font_get_ascent(sans);
134
 
  grub_font_draw_string (str, sans, color, 16, texty);
135
 
  texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
136
 
 
137
 
  texty += grub_font_get_ascent(sanssmall);
138
 
  grub_font_draw_string (str, sanssmall, color, 16, texty);
139
 
  texty += (grub_font_get_descent (sanssmall)
140
 
            + grub_font_get_leading (sanssmall));
141
 
 
142
 
  glyph = grub_font_get_glyph (fixed, '*');
143
 
 
144
 
  for (i = 0; i < 16; i++)
 
92
       This converts the Unicode character U+263A to UTF-8.  */
 
93
 
 
94
    /* Characters used:
 
95
       Code point  Description                    UTF-8 encoding
 
96
       ----------- ------------------------------ --------------
 
97
       U+263A      unfilled smiley face           E2 98 BA
 
98
       U+00A1      inverted exclamation point     C2 A1
 
99
       U+00A3      British pound currency symbol  C2 A3
 
100
       U+03C4      Greek tau                      CF 84
 
101
       U+00E4      lowercase letter a with umlaut C3 A4
 
102
       U+2124      set 'Z' symbol (integers)      E2 84 A4
 
103
       U+2287      subset symbol                  E2 8A 87
 
104
       U+211D      set 'R' symbol (real numbers)  E2 84 9D  */
 
105
 
 
106
    str =
 
107
      "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
 
108
      " \xC2\xA1\xCF\x84\xC3\xA4u! "
 
109
      " \xE2\x84\xA4\xE2\x8A\x87\xE2\x84\x9D";
 
110
    color = grub_video_map_rgb (128, 128, 255);
 
111
 
 
112
    /* All characters in the string exist in the 'Fixed 20' (10x20) font.  */
 
113
    texty += grub_font_get_ascent(fixed);
 
114
    grub_font_draw_string (str, fixed, color, 16, texty);
 
115
    texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
 
116
 
 
117
    texty += grub_font_get_ascent(sansbig);
 
118
    grub_font_draw_string (str, sansbig, color, 16, texty);
 
119
    texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);
 
120
 
 
121
    texty += grub_font_get_ascent(sans);
 
122
    grub_font_draw_string (str, sans, color, 16, texty);
 
123
    texty += grub_font_get_descent (sans) + grub_font_get_leading (sans);
 
124
 
 
125
    texty += grub_font_get_ascent(sanssmall);
 
126
    grub_font_draw_string (str, sanssmall, color, 16, texty);
 
127
    texty += (grub_font_get_descent (sanssmall)
 
128
              + grub_font_get_leading (sanssmall));
 
129
 
 
130
    glyph = grub_font_get_glyph (fixed, '*');
 
131
 
 
132
    for (i = 0; i < 16; i++)
 
133
      {
 
134
        color = grub_video_map_color (i);
 
135
        palette[i] = color;
 
136
        grub_font_draw_glyph (glyph, color, 16 + i * 16, 220);
 
137
      }
 
138
  }
 
139
 
 
140
  grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
 
141
 
 
142
  for (i = 0; i < 2; i++)
145
143
    {
146
 
      color = grub_video_map_color (i);
147
 
      palette[i] = color;
148
 
      grub_font_draw_glyph (glyph, color, 16 + i * 16, 220);
 
144
      color = grub_video_map_rgb (0, 0, 0);
 
145
      grub_video_fill_rect (color, 0, 0, width, height);
 
146
 
 
147
      color = grub_video_map_rgb (255, 0, 0);
 
148
      grub_video_fill_rect (color, 0, 0, 100, 100);
 
149
 
 
150
      color = grub_video_map_rgb (0, 255, 255);
 
151
      grub_video_fill_rect (color, 100, 100, 100, 100);
 
152
 
 
153
      grub_video_set_viewport (x + 150, y + 150,
 
154
                               width - 150 * 2, height - 150 * 2);
 
155
      color = grub_video_map_rgb (77, 33, 77);
 
156
      grub_video_fill_rect (color, 0, 0, width, height);
 
157
      grub_video_swap_buffers ();
149
158
    }
150
159
 
151
 
  grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY);
152
 
 
153
160
  for (i = 0; i < 5; i++)
154
161
    {
155
162
      color = grub_video_map_rgb (i, 33, 77);