RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Screen.c
Go to the documentation of this file.
1 
12 #include "EfiScannerHeaders.h"
13 #include "Screen.h"
14 #include "efiGraphicsOutput.h"
15 #include "efiUgaDraw.h"
16 #include "ConsoleControl.h"
17 
18 #include "logo.h"
19 
20 
21 
22 #define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \
23  { 0xf42f7782, 0x12e, 0x4c12, {0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21} }
24 
27 
30 
33 
34 
35 
38 
39 
40 BOOLEAN GraphicsAvailable = FALSE;
41 
42 
48 {
49  EFI_STATUS Status;
50  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextProt;
51  UINTN TestMode, Columns, Rows;
52 
53 
54  Status = gBS->LocateProtocol(&gEfiSimpleTextOutProtocolGuid, NULL, (VOID **) &SimpleTextProt);
55  if (EFI_ERROR(Status))
56  {
57  LogFullAscii("PickBestTextMode: error unable to locate SimpleTextProtocol\r\n");
58  return Status;
59  }
60 
61 
62  // lets enumerate all possible modes
63  // appending to the UEFI documentation the Text Output Protocol
64  // should at least provide the 0-Mode (80x25 text mode)
65  // we assume everything beyond that is better
66  // not used because even if there is a higher resolution mode
67  // it is provided typically as 0-Mode as well
68  // (so there is no 80x25 mode it is exchanged with higher
69  // resolution, but still there is only one mode available)
70 
71  TestMode = 0;
72  do
73  {
74  Status = SimpleTextProt->QueryMode(SimpleTextProt, TestMode, &Columns, &Rows);
75 
76  LogFullAscii("ScreenEnableGraphicsMode: Mode=%d Columns=%d Rows=%d\r\n",
77  TestMode,
78  Columns,
79  Rows);
80  TestMode++;
81  } while (Status == EFI_SUCCESS);
82 
83 
84  return EFI_SUCCESS;
85 }
86 
91 {
92 
93  EFI_CONSOLE_CONTROL_SCREEN_MODE NewMode, CurrentMode;
94 
96 
97  if (gConsoleControlProt != NULL)
98  {
99 
100  gConsoleControlProt->GetMode(gConsoleControlProt, &CurrentMode, NULL, NULL);
101 
102  if (CurrentMode != NewMode)
103  gConsoleControlProt->SetMode(gConsoleControlProt, NewMode);
104  }
105 
106  return EFI_SUCCESS;
107 }
108 
115 {
116  EFI_STATUS Status;
117  UINT32 UGAWidth, UGAHeight, UGADepth, UGARefreshRate;
118 
119  GraphicsAvailable = FALSE;
120 
121 
122  if (gGraphicsOutputProt != NULL)
123  {
124 
125  ScreenHeightProbed = gGraphicsOutputProt->Mode->Info->VerticalResolution;
126  ScreenWidthProbed = gGraphicsOutputProt->Mode->Info->HorizontalResolution;
127  GraphicsAvailable = TRUE;
128  return EFI_SUCCESS;
129  }
130 
131  if (gUgaDrawProt != NULL)
132  {
133  Status = gUgaDrawProt->GetMode(gUgaDrawProt,
134  &UGAWidth,
135  &UGAHeight,
136  &UGADepth,
137  &UGARefreshRate);
138 
139  if (EFI_ERROR(Status))
140  {
141  LogFullAscii("ScreenGetResolution: calling gUgaDrawProt->GetMode failed!\r\n");
142 
143  gUgaDrawProt = NULL;
144  return Status;
145  }
146 
147  // all good
148  ScreenHeightProbed = UGAHeight;
149  ScreenWidthProbed = UGAWidth;
150  GraphicsAvailable = TRUE;
151  return EFI_SUCCESS;
152  }
153 
154  return EFI_NOT_FOUND;
155 }
156 
157 
169 {
170  EFI_STATUS Status;
171 
172  gConsoleControlProt = NULL;
173  gUgaDrawProt = NULL;
174  gGraphicsOutputProt = NULL;
175 
176  // get protocols
177  Status = gBS->LocateProtocol(&ggConsoleControlProtocolGuid,
178  NULL,
179  (VOID**)&gConsoleControlProt);
180 
181  if (EFI_ERROR(Status))
182  LogFullAscii("ScreenInit: error unable to locate gConsoleControlProtocol\r\n");
183 
184  Status = gBS->LocateProtocol(&ggUgaDrawProtocolGuid,
185  NULL,
186  (VOID**)&gUgaDrawProt);
187 
188  if (EFI_ERROR(Status))
189  LogFullAscii("ScreenInit: error unable to locate gUgaDrawProtocol\r\n");
190 
191  Status = gBS->LocateProtocol(&ggGraphicsOutputProtocolGuid,
192  NULL,
193  (VOID**)&gGraphicsOutputProt);
194 
195  if (EFI_ERROR(Status))
196  LogFullAscii("ScreenInit: error unable to locate gGraphicsOutputProtocol");
197 
198  return ScreenGetResolution();
199 }
200 
201 
208 {
209 
210  if (!GraphicsAvailable)
211  return EFI_NOT_FOUND;
212 
213  if (gGraphicsOutputProt != NULL)
214  {
215  gGraphicsOutputProt->Blt(gGraphicsOutputProt,
218  0, 0, 0, 0,
221  0);
222  return EFI_SUCCESS;
223  }
224 
225  if (gUgaDrawProt != NULL)
226  {
227  gUgaDrawProt->Blt(gUgaDrawProt,
228  (EFI_UGA_PIXEL*)&Color,
230  0, 0, 0, 0,
233  0);
234  return EFI_SUCCESS;
235  }
236 
237  return EFI_NOT_FOUND;
238 }
239 
240 
247  UINTN ScreenPosX,
248  UINTN ScreenPosY)
249 {
250  if (!GraphicsAvailable || !Image)
251  return EFI_NOT_FOUND;
252 
253 
254  if (gGraphicsOutputProt != NULL)
255  {
256 
257  gGraphicsOutputProt->Blt(gGraphicsOutputProt,
260  0, 0,
261  ScreenPosX,
262  ScreenPosY,
263  Image->Width,
264  Image->Height,
265  0);
266  return EFI_SUCCESS;
267 
268  }
269 
270  if (gUgaDrawProt != NULL)
271  {
272  gUgaDrawProt->Blt( gUgaDrawProt,
273  (EFI_UGA_PIXEL *)Image->Data,
275  0, 0,
276  ScreenPosX,
277  ScreenPosY,
278  Image->Width,
279  Image->Height, 0);
280  return EFI_SUCCESS;
281  }
282 
283  return EFI_NOT_FOUND;
284 }
285 
286 
287 
288 
296 {
297  EFI_STATUS Status;
298  GIMAGE *Image;
299  UINTN x, y;
300 
301 
302  Status = ScreenInit();
303  if (EFI_ERROR(Status))
304  {
305  LogFullAscii("ScreenShowSplashLogo: unable to initialize screen!\r\n");
306  return EFI_NOT_FOUND;
307  }
308 
310 
311  Image = ImageLoadBMPFromMem((UINT8*)&logo, sizeof(logo));
312  if (!Image)
313  {
314  LogFullAscii("ScreenShowSplashLogo: unable to load splash image!\r\n");
315  return EFI_NOT_FOUND;
316  }
317 
318 
319  // clear screen to the color of first pixel
320  ScreenClearToColor(&Image->Data[0]);
321 
322  // draw it
323  x = (ScreenWidthProbed/2) - (Image->Width/2);
324  y = (ScreenHeightProbed/2) - (Image->Height/2);
325 
326  ScreenDrawImage(Image, x, y);
327 
328  // sleep for 5 sec (5000000 us)
329  gBS->Stall(500*TICKS_PER_MS);
330 
331  // switch back to console mode
333 
334  return EFI_SUCCESS;
335 }