aboutsummaryrefslogtreecommitdiffstats
path: root/UefiMonitorTest/Graphics.h
blob: 44c72aa429fc86e8d10d08d01ce11d9bbdb3b9c5 (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
#ifndef UMT_GRAPHICS_H
#define UMT_GRAPHICS_H

#include <Uefi.h>

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

#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;

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

VOID
ForgetGraphicsInfo (
  IN GRAPHICS_CONTEXT *Graphics
  );

/**
  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
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
  );

/**
  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,
  ...
  );

#endif /* UMT_GRAPHICS_H */