aboutsummaryrefslogtreecommitdiffstats
path: root/UefiMonitorTest/Graphics.h
blob: bfa24cdfa4cc6798e24ba56ab4594c637c1a42aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#ifndef UMT_GRAPHICS_H
#define UMT_GRAPHICS_H

#include <Uefi.h>

#include <Protocol/GraphicsOutput.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/SimplePointer.h>

#define GET_UCOLOR(Color) (*(UINT32 *)Color)

#define PUT_PUXEL(Graphics, X, Y, Icolor) \
    Graphics->BackBuffer[X + (Y * Graphics->Pitch)] = Icolor

typedef struct {
  UINT8 Blue;
  UINT8 Green;
  UINT8 Red;
  UINT8 Reserved;
} GRAPHICS_PIXEL_COLOR;

typedef struct {
  ///
  /// The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
  ///
  EFI_GRAPHICS_OUTPUT_PROTOCOL            *Gop;
  ///
  /// Base address of graphics linear frame buffer.
  /// Starts from the upper left pixel.
  ///
  UINT32                                  *FrontBuffer;
  ///
  /// Pointer to allocated memory. Secondary linear buffer.
  ///
  UINT32                                  *BackBuffer;
  ///
  /// Amount of frame buffer needed to support the active mode in bytes.
  ///
  UINTN                                   BufferSize;
  ///
  /// The size of video screen in pixels in the X dimension.
  ///
  UINT32                                  Width;
  ///
  /// The size of video screen in pixels in the Y dimension.
  ///
  UINT32                                  Height;
  ///
  /// Bit-mask defines what bits are used for different colors.
  ///
  EFI_PIXEL_BITMASK                       PixelMasks;
  ///
  /// Amount of bits to shift left.
  /// R-G-B-Rsvd
  ///
  INT8                                    PixelShl[4];
  ///
  /// Amount of bits to shift right.
  /// R-G-B-Rsvd
  ///
  INT8                                    PixelShr[4];
  ///
  /// The size of pixel color in bytes.
  ///
  UINT32                                  PixelWidth;
  ///
  /// Amount of bytes you should skip to go one pixel down.
  ///
  UINT32                                  Pitch;
  //
  // The EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
  //
  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL       *TextInputEx;
  //
  // A mouse support.
  //
  BOOLEAN                                 MouseSupported;
  //
  // The MouseInterface instance.
  //
  EFI_SIMPLE_POINTER_PROTOCOL             *MouseInterface;
} GRAPHICS_CONTEXT;

enum UMT_COLORS {
  UMT_COLOR_BLACK = 0,
  UMT_COLOR_WHITE,
  UMT_COLOR_RED,
  UMT_COLOR_LIME,
  UMT_COLOR_BLUE,
  UMT_COLOR_YELLOW,
  UMT_COLOR_AQUA,
  UMT_COLOR_MAGENTA,
  UMT_COLOR_SILVER,
  UMT_COLOR_GRAY,
  UMT_COLOR_MAROON,
  UMT_COLOR_OLIVE,
  UMT_COLOR_GREEN,
  UMT_COLOR_PURPLE,
  UMT_COLOR_TEAL,
  UMT_COLOR_NAVY,
  UMT_COLOR_END
};

typedef struct {
  EFI_STRING_ID         StringId;
  GRAPHICS_PIXEL_COLOR  Color;
} UMT_COLORS;

extern CONST UMT_COLORS gUmtColors[];

EFI_STATUS
PrepareGraphicsInfo (
  IN GRAPHICS_CONTEXT             *Graphics,
  IN EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop
  );

VOID
ForgetGraphicsInfo (
  IN GRAPHICS_CONTEXT *Graphics
  );

/**
  Get a color that doesn't depend on pixel format, i.e.
  independent color.

  @param[in] Graphics               A graphics context.
  @param[in] Ucolor                 A GRAPHICS_PIXEL_COLOR, which is
                                    represented as unsigned 32-bit.

  @retval  UINT32                   A color in independent format.
**/
UINT32
GetIcolor (
  IN  GRAPHICS_CONTEXT  *Graphics,
  IN  UINT32            Ucolor
  );

/**
  Draw a line using Bresenham's algorithm

  @retval  VOID
**/
VOID
DrawLine (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X0,
  IN UINTN                      Y0,
  IN UINTN                      X1,
  IN UINTN                      Y1,
  IN CONST GRAPHICS_PIXEL_COLOR *Color
  );

VOID
PutRect (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X0,
  IN UINTN                      Y0,
  IN UINTN                      X1,
  IN UINTN                      Y1,
  IN CONST GRAPHICS_PIXEL_COLOR *Color
  );

VOID
DrawRectWithBorder (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X0,
  IN UINTN                      Y0,
  IN UINTN                      X1,
  IN UINTN                      Y1,
  IN UINTN                      BorderSize,
  IN CONST GRAPHICS_PIXEL_COLOR *MainColor,
  IN CONST GRAPHICS_PIXEL_COLOR *BorderColor
  );

VOID
DrawRoundedRect (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X0,
  IN UINTN                      Y0,
  IN UINTN                      X1,
  IN UINTN                      Y1,
  IN UINTN                      CornerRadius,
  IN CONST GRAPHICS_PIXEL_COLOR *Color
  );

VOID
DrawCircle (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X0,
  IN UINTN                      Y0,
  IN UINTN                      R,
  IN CONST GRAPHICS_PIXEL_COLOR *Color
  );

/**
  Draws a character to the screen

  @retval  VOID
**/
VOID
DrawChar (
  IN GRAPHICS_CONTEXT *Graphics,
  IN UINTN            X,
  IN UINTN            Y,
  IN UINT32           Icolor,
  IN CHAR16           Char
  );

EFI_STATUS
GetFontParameters (
  IN  GRAPHICS_CONTEXT *Graphics,
  OUT UINTN           *FontWidth,
  OUT UINTN           *FontHeight
  );

/**
  Draws output based on a null-terminated Unicode format string
  and a arguments list to the screen

  @retval The number of Unicode characters drawn
**/
UINTN
EFIAPI
DrawStringVF (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X,
  IN UINTN                      Y,
  IN CONST GRAPHICS_PIXEL_COLOR *Color,
  IN CONST CHAR16               *FormatString,
  IN VA_LIST                    Marker
  );

UINTN
EFIAPI
DrawStringF (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X,
  IN UINTN                      Y,
  IN CONST GRAPHICS_PIXEL_COLOR *Color,
  IN CONST CHAR16               *FormatString,
  ...
  );

UINTN
EFIAPI
DrawHiiStringF (
  IN GRAPHICS_CONTEXT           *Graphics,
  IN UINTN                      X,
  IN UINTN                      Y,
  IN CONST GRAPHICS_PIXEL_COLOR *Color,
  IN CONST EFI_STRING_ID        HiiFormatStringId,
  IN CONST EFI_HII_HANDLE       HiiFormatHandle,
  ...
  );

#endif /* UMT_GRAPHICS_H */