]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
Clean up to fix build break.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
CommitLineData
6dcf9abc 1/** @file\r
95276127 2 This is the main routine for initializing the Graphics Console support routines.\r
8541adab 3\r
6dcf9abc 4Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
8541adab 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
95276127 12\r
13**/\r
14\r
95276127 15#include "GraphicsConsole.h"\r
16\r
24248368 17/**\r
18 Gets Graphics Console devcie's foreground color and background color.\r
19\r
20 @param This Protocol instance pointer.\r
21 @param Foreground Returned text foreground color.\r
22 @param Background Returned text background color.\r
23\r
24 @retval EFI_SUCCESS It returned always.\r
25\r
26**/\r
95276127 27EFI_STATUS\r
28GetTextColors (\r
29 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
30 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,\r
31 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background\r
32 );\r
33\r
24248368 34/**\r
35 Draw Unicode string on the Graphice Console device's screen.\r
36\r
37 @param This Protocol instance pointer.\r
38 @param UnicodeWeight One Unicode string to be displayed.\r
39 @param Count The count of Unicode string.\r
40\r
41 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.\r
42 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw\r
43 protocol exist.\r
44 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.\r
45\r
46**/\r
95276127 47EFI_STATUS\r
48DrawUnicodeWeightAtCursorN (\r
49 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
50 IN CHAR16 *UnicodeWeight,\r
51 IN UINTN Count\r
52 );\r
53\r
24248368 54/**\r
55 Erase the cursor on the screen.\r
56\r
57 @param This Protocol instance pointer.\r
58\r
59 @retval EFI_SUCCESS The cursor is erased successfully.\r
60\r
61**/\r
95276127 62EFI_STATUS\r
63EraseCursor (\r
64 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
65 );\r
66\r
24248368 67/**\r
68 Check if the current specific mode supported the user defined resolution\r
69 for the Graphice Console devcie based on Graphics Output Protocol.\r
70\r
71 If yes, set the graphic devcice's current mode to this specific mode.\r
72 \r
73 @param GraphicsOutput Graphics Output Protocol instance pointer.\r
74 @param HorizontalResolution User defined horizontal resolution\r
75 @param VerticalResolution User defined vertical resolution.\r
76 @param CurrentModeNumber Current specific mode to be check.\r
77\r
8595bdaf 78 @retval EFI_SUCCESS The mode is supported.\r
24248368 79 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics \r
80 devcie supported.\r
81 @retval other The specific mode does not support user defined \r
82 resolution or failed to set the current mode to the \r
83 specific mode on graphics device.\r
84\r
85**/\r
3012ce5c 86EFI_STATUS\r
87CheckModeSupported (\r
88 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,\r
89 IN UINT32 HorizontalResolution,\r
90 IN UINT32 VerticalResolution,\r
91 OUT UINT32 *CurrentModeNumber\r
92 );\r
93\r
95276127 94//\r
8595bdaf 95// Graphics Console Devcie Private Data template\r
95276127 96//\r
fe1e36e5 97GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = {\r
95276127 98 GRAPHICS_CONSOLE_DEV_SIGNATURE,\r
99 (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL,\r
100 (EFI_UGA_DRAW_PROTOCOL *) NULL,\r
101 {\r
102 GraphicsConsoleConOutReset,\r
103 GraphicsConsoleConOutOutputString,\r
104 GraphicsConsoleConOutTestString,\r
105 GraphicsConsoleConOutQueryMode,\r
106 GraphicsConsoleConOutSetMode,\r
107 GraphicsConsoleConOutSetAttribute,\r
108 GraphicsConsoleConOutClearScreen,\r
109 GraphicsConsoleConOutSetCursorPosition,\r
110 GraphicsConsoleConOutEnableCursor,\r
111 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL\r
112 },\r
113 {\r
114 0,\r
115 0,\r
116 EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK),\r
117 0,\r
118 0,\r
119 TRUE\r
120 },\r
121 {\r
122 { 80, 25, 0, 0, 0, 0 }, // Mode 0\r
3012ce5c 123 { 80, 50, 0, 0, 0, 0 }, // Mode 1\r
124 { 100,31, 0, 0, 0, 0 }, // Mode 2\r
125 { 0, 0, 0, 0, 0, 0 } // Mode 3\r
95276127 126 },\r
127 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
93e3992d 128 (EFI_HII_HANDLE ) 0\r
95276127 129};\r
130\r
93e3992d 131EFI_HII_DATABASE_PROTOCOL *mHiiDatabase;\r
132EFI_HII_FONT_PROTOCOL *mHiiFont;\r
133BOOLEAN mFirstAccessFlag = TRUE;\r
134\r
555e76f8 135EFI_GUID mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};\r
93e3992d 136\r
fe1e36e5 137CHAR16 mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
95276127 138\r
fe1e36e5 139EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r
95276127 140 //\r
141 // B G R\r
142 //\r
143 {0x00, 0x00, 0x00, 0x00}, // BLACK\r
144 {0x98, 0x00, 0x00, 0x00}, // BLUE\r
145 {0x00, 0x98, 0x00, 0x00}, // GREEN\r
146 {0x98, 0x98, 0x00, 0x00}, // CYAN\r
147 {0x00, 0x00, 0x98, 0x00}, // RED\r
148 {0x98, 0x00, 0x98, 0x00}, // MAGENTA\r
149 {0x00, 0x98, 0x98, 0x00}, // BROWN\r
150 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY\r
151 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK\r
152 {0xff, 0x00, 0x00, 0x00}, // LIGHTBLUE - ?\r
153 {0x00, 0xff, 0x00, 0x00}, // LIGHTGREEN - ?\r
154 {0xff, 0xff, 0x00, 0x00}, // LIGHTCYAN\r
155 {0x00, 0x00, 0xff, 0x00}, // LIGHTRED\r
156 {0xff, 0x00, 0xff, 0x00}, // LIGHTMAGENTA\r
157 {0x00, 0xff, 0xff, 0x00}, // LIGHTBROWN\r
158 {0xff, 0xff, 0xff, 0x00} // WHITE\r
159};\r
160\r
fe1e36e5 161EFI_NARROW_GLYPH mCursorGlyph = {\r
95276127 162 0x0000,\r
163 0x00,\r
164 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }\r
165};\r
166\r
fe1e36e5 167CHAR16 SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
6dcf9abc 168\r
95276127 169EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {\r
170 GraphicsConsoleControllerDriverSupported,\r
171 GraphicsConsoleControllerDriverStart,\r
172 GraphicsConsoleControllerDriverStop,\r
173 0xa,\r
174 NULL,\r
175 NULL\r
176};\r
177\r
24248368 178\r
179/**\r
8595bdaf 180 Test to see if Graphics Console could be supported on the Controller.\r
24248368 181\r
182 Graphics Console could be supported if Graphics Output Protocol or UGA Draw\r
8595bdaf 183 Protocol exists on the Controller. (UGA Draw Protocol could be skipped\r
24248368 184 if PcdUgaConsumeSupport is set to FALSE.)\r
185\r
186 @param This Protocol instance pointer.\r
8595bdaf 187 @param Controller Handle of device to test.\r
24248368 188 @param RemainingDevicePath Optional parameter use to pick a specific child\r
189 device to start.\r
190\r
8595bdaf 191 @retval EFI_SUCCESS This driver supports this device.\r
192 @retval other This driver does not support this device.\r
24248368 193\r
194**/\r
95276127 195EFI_STATUS\r
196EFIAPI\r
197GraphicsConsoleControllerDriverSupported (\r
198 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
199 IN EFI_HANDLE Controller,\r
200 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
201 )\r
202{\r
8541adab 203 EFI_STATUS Status;\r
95276127 204 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
8541adab 205 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
206 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
95276127 207\r
8541adab 208 GraphicsOutput = NULL;\r
209 UgaDraw = NULL;\r
95276127 210 //\r
211 // Open the IO Abstraction(s) needed to perform the supported test\r
212 //\r
213 Status = gBS->OpenProtocol (\r
214 Controller,\r
215 &gEfiGraphicsOutputProtocolGuid,\r
216 (VOID **) &GraphicsOutput,\r
217 This->DriverBindingHandle,\r
218 Controller,\r
219 EFI_OPEN_PROTOCOL_BY_DRIVER\r
220 );\r
8541adab 221\r
222 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 223 //\r
224 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol\r
225 //\r
226 Status = gBS->OpenProtocol (\r
227 Controller,\r
228 &gEfiUgaDrawProtocolGuid,\r
229 (VOID **) &UgaDraw,\r
230 This->DriverBindingHandle,\r
231 Controller,\r
232 EFI_OPEN_PROTOCOL_BY_DRIVER\r
233 );\r
8541adab 234 }\r
235 if (EFI_ERROR (Status)) {\r
236 return Status;\r
95276127 237 }\r
238\r
239 //\r
240 // We need to ensure that we do not layer on top of a virtual handle.\r
241 // We need to ensure that the handles produced by the conspliter do not\r
242 // get used.\r
243 //\r
244 Status = gBS->OpenProtocol (\r
245 Controller,\r
246 &gEfiDevicePathProtocolGuid,\r
247 (VOID **) &DevicePath,\r
248 This->DriverBindingHandle,\r
249 Controller,\r
250 EFI_OPEN_PROTOCOL_BY_DRIVER\r
251 );\r
252 if (!EFI_ERROR (Status)) {\r
253 gBS->CloseProtocol (\r
254 Controller,\r
255 &gEfiDevicePathProtocolGuid,\r
256 This->DriverBindingHandle,\r
257 Controller\r
258 );\r
259 } else {\r
260 goto Error;\r
261 }\r
93e3992d 262\r
95276127 263 //\r
264 // Does Hii Exist? If not, we aren't ready to run\r
265 //\r
266 Status = EfiLocateHiiProtocol ();\r
267\r
268 //\r
269 // Close the I/O Abstraction(s) used to perform the supported test\r
270 //\r
271Error:\r
272 if (GraphicsOutput != NULL) {\r
273 gBS->CloseProtocol (\r
274 Controller,\r
275 &gEfiGraphicsOutputProtocolGuid,\r
276 This->DriverBindingHandle,\r
277 Controller\r
278 );\r
8541adab 279 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 280 gBS->CloseProtocol (\r
281 Controller,\r
282 &gEfiUgaDrawProtocolGuid,\r
283 This->DriverBindingHandle,\r
284 Controller\r
285 );\r
286 }\r
287 return Status;\r
288}\r
289\r
6dcf9abc 290\r
291/**\r
8595bdaf 292 Start this driver on Controller by opening Graphics Output protocol or \r
293 UGA Draw protocol, and installing Simple Text Out protocol on Controller.\r
24248368 294 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)\r
295 \r
296 @param This Protocol instance pointer.\r
8595bdaf 297 @param Controller Handle of device to bind driver to\r
24248368 298 @param RemainingDevicePath Optional parameter use to pick a specific child\r
299 device to start.\r
300\r
8595bdaf 301 @retval EFI_SUCCESS This driver is added to Controller.\r
302 @retval other This driver does not support this device.\r
6dcf9abc 303\r
304**/\r
95276127 305EFI_STATUS\r
306EFIAPI\r
307GraphicsConsoleControllerDriverStart (\r
308 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
309 IN EFI_HANDLE Controller,\r
310 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
311 )\r
95276127 312{\r
3012ce5c 313 EFI_STATUS Status;\r
314 GRAPHICS_CONSOLE_DEV *Private;\r
3012ce5c 315 UINTN NarrowFontSize;\r
316 UINT32 HorizontalResolution;\r
317 UINT32 VerticalResolution;\r
318 UINT32 ColorDepth;\r
319 UINT32 RefreshRate;\r
320 UINTN MaxMode;\r
321 UINTN Columns;\r
322 UINTN Rows;\r
95276127 323 UINT32 ModeNumber;\r
dca8c6d8 324 EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimplifiedFont;\r
325 UINTN PackageLength;\r
326 EFI_HII_PACKAGE_LIST_HEADER *PackageList;\r
327 UINT8 *Package;\r
328 UINT8 *Location;\r
93e3992d 329\r
95276127 330 ModeNumber = 0;\r
331\r
332 //\r
333 // Initialize the Graphics Console device instance\r
334 //\r
335 Private = AllocateCopyPool (\r
336 sizeof (GRAPHICS_CONSOLE_DEV),\r
337 &mGraphicsConsoleDevTemplate\r
338 );\r
339 if (Private == NULL) {\r
340 return EFI_OUT_OF_RESOURCES;\r
341 }\r
342\r
343 Private->SimpleTextOutput.Mode = &(Private->SimpleTextOutputMode);\r
344\r
345 Status = gBS->OpenProtocol (\r
346 Controller,\r
347 &gEfiGraphicsOutputProtocolGuid,\r
348 (VOID **) &Private->GraphicsOutput,\r
349 This->DriverBindingHandle,\r
350 Controller,\r
351 EFI_OPEN_PROTOCOL_BY_DRIVER\r
352 );\r
95276127 353\r
8541adab 354 if (EFI_ERROR(Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 355 Status = gBS->OpenProtocol (\r
356 Controller,\r
357 &gEfiUgaDrawProtocolGuid,\r
358 (VOID **) &Private->UgaDraw,\r
359 This->DriverBindingHandle,\r
360 Controller,\r
361 EFI_OPEN_PROTOCOL_BY_DRIVER\r
362 );\r
8541adab 363 }\r
364\r
365 if (EFI_ERROR (Status)) {\r
366 goto Error;\r
95276127 367 }\r
368\r
95276127 369 NarrowFontSize = ReturnNarrowFontSize ();\r
370\r
93e3992d 371 if (mFirstAccessFlag) {\r
dca8c6d8 372 //\r
373 // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.\r
374 // Looks ugly. Might be updated when font tool is ready.\r
375 //\r
376 PackageLength = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + NarrowFontSize + 4;\r
377 Package = AllocateZeroPool (PackageLength);\r
378 if (Package == NULL) {\r
379 return EFI_OUT_OF_RESOURCES;\r
380 }\r
381 CopyMem (Package, &PackageLength, 4);\r
382 SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR*) (Package + 4);\r
383 SimplifiedFont->Header.Length = (UINT32) (PackageLength - 4);\r
384 SimplifiedFont->Header.Type = EFI_HII_PACKAGE_SIMPLE_FONTS;\r
385 SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
8541adab 386\r
dca8c6d8 387 Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);\r
8595bdaf 388 CopyMem (Location, gUsStdNarrowGlyphData, NarrowFontSize);\r
8541adab 389\r
dca8c6d8 390 //\r
391 // Add this simplified font package to a package list then install it.\r
392 //\r
393 PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package);\r
394 Status = mHiiDatabase->NewPackageList (mHiiDatabase, PackageList, NULL, &(Private->HiiHandle));\r
395 ASSERT_EFI_ERROR (Status);\r
676df92c 396 FreePool (PackageList);\r
397 FreePool (Package);\r
dca8c6d8 398\r
93e3992d 399 mFirstAccessFlag = FALSE;\r
400 }\r
95276127 401 //\r
402 // If the current mode information can not be retrieved, then attemp to set the default mode\r
403 // of 800x600, 32 bit colot, 60 Hz refresh.\r
404 //\r
405 HorizontalResolution = 800;\r
406 VerticalResolution = 600;\r
407\r
408 if (Private->GraphicsOutput != NULL) {\r
409 //\r
8541adab 410 // The console is build on top of Graphics Output Protocol, find the mode number\r
3012ce5c 411 // for the user-defined mode; if there are multiple video devices,\r
412 // graphic console driver will set all the video devices to the same mode.\r
95276127 413 //\r
3012ce5c 414 Status = CheckModeSupported (\r
8541adab 415 Private->GraphicsOutput,\r
416 CURRENT_HORIZONTAL_RESOLUTION,\r
3012ce5c 417 CURRENT_VERTICAL_RESOLUTION,\r
418 &ModeNumber\r
419 );\r
420 if (!EFI_ERROR(Status)) {\r
421 //\r
422 // Update default mode to current mode\r
423 //\r
424 HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;\r
425 VerticalResolution = CURRENT_VERTICAL_RESOLUTION;\r
426 } else {\r
427 //\r
428 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec\r
429 //\r
430 Status = CheckModeSupported (\r
8541adab 431 Private->GraphicsOutput,\r
432 800,\r
433 600,\r
3012ce5c 434 &ModeNumber\r
435 );\r
95276127 436 }\r
437\r
438 if (EFI_ERROR (Status) || (ModeNumber == Private->GraphicsOutput->Mode->MaxMode)) {\r
439 //\r
440 // Set default mode failed or device don't support default mode, then get the current mode information\r
441 //\r
442 HorizontalResolution = Private->GraphicsOutput->Mode->Info->HorizontalResolution;\r
443 VerticalResolution = Private->GraphicsOutput->Mode->Info->VerticalResolution;\r
444 ModeNumber = Private->GraphicsOutput->Mode->Mode;\r
445 }\r
8541adab 446 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 447 //\r
3012ce5c 448 // At first try to set user-defined resolution\r
95276127 449 //\r
450 ColorDepth = 32;\r
451 RefreshRate = 60;\r
452 Status = Private->UgaDraw->SetMode (\r
453 Private->UgaDraw,\r
3012ce5c 454 CURRENT_HORIZONTAL_RESOLUTION,\r
455 CURRENT_VERTICAL_RESOLUTION,\r
95276127 456 ColorDepth,\r
457 RefreshRate\r
458 );\r
3012ce5c 459 if (!EFI_ERROR (Status)) {\r
460 HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;\r
461 VerticalResolution = CURRENT_VERTICAL_RESOLUTION;\r
8541adab 462 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 463 //\r
3012ce5c 464 // Try to set 800*600 which is required by UEFI/EFI spec\r
95276127 465 //\r
3012ce5c 466 Status = Private->UgaDraw->SetMode (\r
95276127 467 Private->UgaDraw,\r
3012ce5c 468 HorizontalResolution,\r
469 VerticalResolution,\r
470 ColorDepth,\r
471 RefreshRate\r
95276127 472 );\r
473 if (EFI_ERROR (Status)) {\r
3012ce5c 474 Status = Private->UgaDraw->GetMode (\r
475 Private->UgaDraw,\r
476 &HorizontalResolution,\r
477 &VerticalResolution,\r
478 &ColorDepth,\r
479 &RefreshRate\r
480 );\r
481 if (EFI_ERROR (Status)) {\r
482 goto Error;\r
483 }\r
95276127 484 }\r
695f7e98 485 } else {\r
486 Status = EFI_UNSUPPORTED;\r
487 goto Error;\r
95276127 488 }\r
489 }\r
490\r
491 //\r
492 // Compute the maximum number of text Rows and Columns that this current graphics mode can support\r
493 //\r
0898c57c 494 Columns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
495 Rows = VerticalResolution / EFI_GLYPH_HEIGHT;\r
95276127 496\r
497 //\r
498 // See if the mode is too small to support the required 80x25 text mode\r
499 //\r
500 if (Columns < 80 || Rows < 25) {\r
501 goto Error;\r
502 }\r
503 //\r
504 // Add Mode #0 that must be 80x25\r
505 //\r
506 MaxMode = 0;\r
8595bdaf 507 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;\r
508 Private->ModeData[MaxMode].GopHeight = VerticalResolution;\r
95276127 509 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
8595bdaf 510 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
511 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (25 * EFI_GLYPH_HEIGHT)) >> 1;\r
95276127 512 MaxMode++;\r
513\r
514 //\r
515 // If it is possible to support Mode #1 - 80x50, than add it as an active mode\r
516 //\r
517 if (Rows >= 50) {\r
8595bdaf 518 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;\r
519 Private->ModeData[MaxMode].GopHeight = VerticalResolution;\r
95276127 520 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
8595bdaf 521 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
522 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;\r
95276127 523 MaxMode++;\r
524 }\r
3012ce5c 525\r
95276127 526 //\r
3012ce5c 527 // If it is not to support Mode #1 - 80x50, then skip it\r
95276127 528 //\r
3012ce5c 529 if (MaxMode < 2) {\r
8595bdaf 530 Private->ModeData[MaxMode].Columns = 0;\r
531 Private->ModeData[MaxMode].Rows = 0;\r
532 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;\r
533 Private->ModeData[MaxMode].GopHeight = VerticalResolution;\r
3012ce5c 534 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
8595bdaf 535 Private->ModeData[MaxMode].DeltaX = 0;\r
536 Private->ModeData[MaxMode].DeltaY = 0;\r
3012ce5c 537 MaxMode++;\r
538 }\r
8541adab 539\r
3012ce5c 540 //\r
541 // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)\r
542 //\r
8541adab 543 if (Columns >= 100 && Rows >= 31) {\r
8595bdaf 544 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;\r
545 Private->ModeData[MaxMode].GopHeight = VerticalResolution;\r
3012ce5c 546 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
8595bdaf 547 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (100 * EFI_GLYPH_WIDTH)) >> 1;\r
548 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (31 * EFI_GLYPH_HEIGHT)) >> 1;\r
3012ce5c 549 MaxMode++;\r
550 }\r
95276127 551\r
3012ce5c 552 //\r
553 // Add Mode #3 that uses the entire display for user-defined mode\r
554 //\r
555 if (HorizontalResolution > 800 && VerticalResolution > 600) {\r
8595bdaf 556 Private->ModeData[MaxMode].Columns = HorizontalResolution/EFI_GLYPH_WIDTH;\r
557 Private->ModeData[MaxMode].Rows = VerticalResolution/EFI_GLYPH_HEIGHT;\r
558 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;\r
559 Private->ModeData[MaxMode].GopHeight = VerticalResolution;\r
95276127 560 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
8595bdaf 561 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;\r
562 Private->ModeData[MaxMode].DeltaY = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;\r
95276127 563 MaxMode++;\r
564 }\r
8541adab 565\r
95276127 566 //\r
567 // Update the maximum number of modes\r
568 //\r
569 Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;\r
570\r
571 //\r
572 // Determine the number of text modes that this protocol can support\r
573 //\r
574 Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);\r
575 if (EFI_ERROR (Status)) {\r
576 goto Error;\r
577 }\r
578\r
579 DEBUG_CODE_BEGIN ();\r
580 GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");\r
581 DEBUG_CODE_END ();\r
582\r
583 //\r
584 // Install protocol interfaces for the Graphics Console device.\r
585 //\r
586 Status = gBS->InstallMultipleProtocolInterfaces (\r
587 &Controller,\r
588 &gEfiSimpleTextOutProtocolGuid,\r
589 &Private->SimpleTextOutput,\r
590 NULL\r
591 );\r
592\r
593Error:\r
594 if (EFI_ERROR (Status)) {\r
595 //\r
8595bdaf 596 // Close the GOP and UGA Draw Protocol\r
95276127 597 //\r
598 if (Private->GraphicsOutput != NULL) {\r
599 gBS->CloseProtocol (\r
600 Controller,\r
601 &gEfiGraphicsOutputProtocolGuid,\r
602 This->DriverBindingHandle,\r
603 Controller\r
604 );\r
8541adab 605 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 606 gBS->CloseProtocol (\r
607 Controller,\r
608 &gEfiUgaDrawProtocolGuid,\r
609 This->DriverBindingHandle,\r
610 Controller\r
611 );\r
612 }\r
613\r
614 //\r
615 // Free private data\r
616 //\r
617 if (Private != NULL) {\r
618 if (Private->LineBuffer != NULL) {\r
619 FreePool (Private->LineBuffer);\r
620 }\r
621 FreePool (Private);\r
622 }\r
623 }\r
624\r
625 return Status;\r
626}\r
627\r
24248368 628/**\r
8595bdaf 629 Stop this driver on Controller by removing Simple Text Out protocol \r
630 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.\r
24248368 631 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)\r
632 \r
633\r
634 @param This Protocol instance pointer.\r
8595bdaf 635 @param Controller Handle of device to stop driver on\r
24248368 636 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
637 children is zero stop the entire bus driver.\r
638 @param ChildHandleBuffer List of Child Handles to Stop.\r
639\r
8595bdaf 640 @retval EFI_SUCCESS This driver is removed Controller.\r
24248368 641 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the \r
8595bdaf 642 Controller.\r
24248368 643 @retval other This driver was not removed from this device.\r
644\r
645**/\r
95276127 646EFI_STATUS\r
647EFIAPI\r
648GraphicsConsoleControllerDriverStop (\r
649 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
650 IN EFI_HANDLE Controller,\r
651 IN UINTN NumberOfChildren,\r
652 IN EFI_HANDLE *ChildHandleBuffer\r
653 )\r
654{\r
655 EFI_STATUS Status;\r
656 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOutput;\r
657 GRAPHICS_CONSOLE_DEV *Private;\r
658\r
659 Status = gBS->OpenProtocol (\r
660 Controller,\r
661 &gEfiSimpleTextOutProtocolGuid,\r
662 (VOID **) &SimpleTextOutput,\r
663 This->DriverBindingHandle,\r
664 Controller,\r
665 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
666 );\r
667 if (EFI_ERROR (Status)) {\r
668 return EFI_NOT_STARTED;\r
669 }\r
670\r
671 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput);\r
672\r
673 Status = gBS->UninstallProtocolInterface (\r
674 Controller,\r
675 &gEfiSimpleTextOutProtocolGuid,\r
676 &Private->SimpleTextOutput\r
677 );\r
678\r
679 if (!EFI_ERROR (Status)) {\r
680 //\r
681 // Close the GOP or UGA IO Protocol\r
682 //\r
683 if (Private->GraphicsOutput != NULL) {\r
684 gBS->CloseProtocol (\r
685 Controller,\r
686 &gEfiGraphicsOutputProtocolGuid,\r
687 This->DriverBindingHandle,\r
688 Controller\r
689 );\r
8541adab 690 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 691 gBS->CloseProtocol (\r
692 Controller,\r
693 &gEfiUgaDrawProtocolGuid,\r
694 This->DriverBindingHandle,\r
695 Controller\r
696 );\r
697 }\r
698\r
699 //\r
700 // Remove the font pack\r
701 //\r
38c0d70a 702 if (Private->HiiHandle != NULL) {\r
703 HiiLibRemovePackages (Private->HiiHandle);\r
704 mFirstAccessFlag = TRUE;\r
705 }\r
95276127 706\r
707 //\r
708 // Free our instance data\r
709 //\r
710 if (Private != NULL) {\r
711 FreePool (Private->LineBuffer);\r
712 FreePool (Private);\r
713 }\r
714 }\r
715\r
716 return Status;\r
717}\r
718\r
24248368 719/**\r
720 Check if the current specific mode supported the user defined resolution\r
721 for the Graphice Console devcie based on Graphics Output Protocol.\r
722\r
723 If yes, set the graphic devcice's current mode to this specific mode.\r
724 \r
725 @param GraphicsOutput Graphics Output Protocol instance pointer.\r
726 @param HorizontalResolution User defined horizontal resolution\r
727 @param VerticalResolution User defined vertical resolution.\r
728 @param CurrentModeNumber Current specific mode to be check.\r
729\r
8595bdaf 730 @retval EFI_SUCCESS The mode is supported.\r
24248368 731 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics \r
732 devcie supported.\r
733 @retval other The specific mode does not support user defined \r
734 resolution or failed to set the current mode to the \r
735 specific mode on graphics device.\r
736\r
737**/\r
3012ce5c 738EFI_STATUS\r
739CheckModeSupported (\r
740 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,\r
24248368 741 IN UINT32 HorizontalResolution,\r
742 IN UINT32 VerticalResolution,\r
743 OUT UINT32 *CurrentModeNumber\r
3012ce5c 744 )\r
745{\r
746 UINT32 ModeNumber;\r
747 EFI_STATUS Status;\r
8541adab 748 UINTN SizeOfInfo;\r
3012ce5c 749 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
8541adab 750\r
3012ce5c 751 Status = EFI_SUCCESS;\r
8541adab 752\r
3012ce5c 753 for (ModeNumber = 0; ModeNumber < GraphicsOutput->Mode->MaxMode; ModeNumber++) {\r
754 Status = GraphicsOutput->QueryMode (\r
755 GraphicsOutput,\r
756 ModeNumber,\r
757 &SizeOfInfo,\r
758 &Info\r
759 );\r
760 if (!EFI_ERROR (Status)) {\r
761 if ((Info->HorizontalResolution == HorizontalResolution) &&\r
762 (Info->VerticalResolution == VerticalResolution)) {\r
763 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
764 if (!EFI_ERROR (Status)) {\r
765 gBS->FreePool (Info);\r
766 break;\r
767 }\r
768 }\r
769 gBS->FreePool (Info);\r
770 }\r
771 }\r
8541adab 772\r
3012ce5c 773 if (ModeNumber == GraphicsOutput->Mode->MaxMode) {\r
774 Status = EFI_UNSUPPORTED;\r
775 }\r
8541adab 776\r
3012ce5c 777 *CurrentModeNumber = ModeNumber;\r
8541adab 778 return Status;\r
3012ce5c 779}\r
780\r
95276127 781\r
6dcf9abc 782/**\r
24248368 783 Locate HII Database protocol and HII Font protocol.\r
95276127 784\r
24248368 785 @retval EFI_SUCCESS HII Database protocol and HII Font protocol \r
786 are located successfully.\r
787 @return other Failed to locate HII Database protocol or \r
788 HII Font protocol.\r
95276127 789\r
6dcf9abc 790**/\r
791EFI_STATUS\r
792EfiLocateHiiProtocol (\r
793 VOID\r
794 )\r
95276127 795{\r
796 EFI_HANDLE Handle;\r
797 UINTN Size;\r
798 EFI_STATUS Status;\r
799\r
93e3992d 800 //\r
801 // There should only be one - so buffer size is this\r
802 //\r
803 Size = sizeof (EFI_HANDLE);\r
804\r
805 Status = gBS->LocateHandle (\r
806 ByProtocol,\r
807 &gEfiHiiDatabaseProtocolGuid,\r
808 NULL,\r
809 &Size,\r
810 (VOID **) &Handle\r
811 );\r
812\r
813 if (EFI_ERROR (Status)) {\r
814 return Status;\r
815 }\r
816\r
817 Status = gBS->HandleProtocol (\r
818 Handle,\r
819 &gEfiHiiDatabaseProtocolGuid,\r
820 (VOID **) &mHiiDatabase\r
821 );\r
822\r
823 if (EFI_ERROR (Status)) {\r
824 return Status;\r
825 }\r
826\r
827 Status = gBS->HandleProtocol (\r
828 Handle,\r
829 &gEfiHiiFontProtocolGuid,\r
830 (VOID **) &mHiiFont\r
831 );\r
832 return Status;\r
95276127 833}\r
93e3992d 834\r
95276127 835//\r
836// Body of the STO functions\r
837//\r
6dcf9abc 838\r
839/**\r
24248368 840 Reset the text output device hardware and optionaly run diagnostics.\r
841 \r
6dcf9abc 842 Implements SIMPLE_TEXT_OUTPUT.Reset().\r
843 If ExtendeVerification is TRUE, then perform dependent Graphics Console\r
844 device reset, and set display mode to mode 0.\r
845 If ExtendedVerification is FALSE, only set display mode to mode 0.\r
846\r
24248368 847 @param This Protocol instance pointer.\r
6dcf9abc 848 @param ExtendedVerification Indicates that the driver may perform a more\r
849 exhaustive verification operation of the device\r
850 during reset.\r
851\r
24248368 852 @retval EFI_SUCCESS The text output device was reset.\r
853 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and\r
854 could not be reset.\r
6dcf9abc 855\r
856**/\r
95276127 857EFI_STATUS\r
858EFIAPI\r
859GraphicsConsoleConOutReset (\r
860 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
861 IN BOOLEAN ExtendedVerification\r
862 )\r
95276127 863{\r
864 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
865 return This->SetMode (This, 0);\r
866}\r
867\r
6dcf9abc 868\r
869/**\r
24248368 870 Write a Unicode string to the output device.\r
871\r
872 Implements SIMPLE_TEXT_OUTPUT.OutputString(). \r
6dcf9abc 873 The Unicode string will be converted to Glyphs and will be\r
874 sent to the Graphics Console.\r
875\r
24248368 876 @param This Protocol instance pointer.\r
877 @param WString The NULL-terminated Unicode string to be displayed\r
878 on the output device(s). All output devices must\r
879 also support the Unicode drawing defined in this file.\r
6dcf9abc 880\r
24248368 881 @retval EFI_SUCCESS The string was output to the device.\r
882 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output\r
883 the text.\r
884 @retval EFI_UNSUPPORTED The output device's mode is not currently in a\r
885 defined text mode.\r
886 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the\r
887 characters in the Unicode string could not be\r
888 rendered and were skipped.\r
6dcf9abc 889\r
890**/\r
95276127 891EFI_STATUS\r
892EFIAPI\r
893GraphicsConsoleConOutOutputString (\r
894 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
895 IN CHAR16 *WString\r
896 )\r
95276127 897{\r
898 GRAPHICS_CONSOLE_DEV *Private;\r
899 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
900 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
901 INTN Mode;\r
902 UINTN MaxColumn;\r
903 UINTN MaxRow;\r
904 UINTN Width;\r
905 UINTN Height;\r
906 UINTN Delta;\r
907 EFI_STATUS Status;\r
908 BOOLEAN Warning;\r
909 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
910 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
911 UINTN DeltaX;\r
912 UINTN DeltaY;\r
913 UINTN Count;\r
914 UINTN Index;\r
915 INT32 OriginAttribute;\r
916 EFI_TPL OldTpl;\r
95276127 917\r
918 Status = EFI_SUCCESS;\r
919\r
920 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
921 //\r
922 // Current mode\r
923 //\r
924 Mode = This->Mode->Mode;\r
925 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
926 GraphicsOutput = Private->GraphicsOutput;\r
927 UgaDraw = Private->UgaDraw;\r
928\r
929 MaxColumn = Private->ModeData[Mode].Columns;\r
930 MaxRow = Private->ModeData[Mode].Rows;\r
931 DeltaX = Private->ModeData[Mode].DeltaX;\r
932 DeltaY = Private->ModeData[Mode].DeltaY;\r
0898c57c 933 Width = MaxColumn * EFI_GLYPH_WIDTH;\r
934 Height = (MaxRow - 1) * EFI_GLYPH_HEIGHT;\r
95276127 935 Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
936\r
937 //\r
938 // The Attributes won't change when during the time OutputString is called\r
939 //\r
940 GetTextColors (This, &Foreground, &Background);\r
941\r
942 EraseCursor (This);\r
943\r
944 Warning = FALSE;\r
945\r
946 //\r
947 // Backup attribute\r
948 //\r
949 OriginAttribute = This->Mode->Attribute;\r
950\r
6dcf9abc 951 while (*WString != L'\0') {\r
95276127 952\r
953 if (*WString == CHAR_BACKSPACE) {\r
954 //\r
955 // If the cursor is at the left edge of the display, then move the cursor\r
956 // one row up.\r
957 //\r
958 if (This->Mode->CursorColumn == 0 && This->Mode->CursorRow > 0) {\r
959 This->Mode->CursorRow--;\r
960 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
961 This->OutputString (This, SpaceStr);\r
962 EraseCursor (This);\r
963 This->Mode->CursorRow--;\r
964 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
965 } else if (This->Mode->CursorColumn > 0) {\r
966 //\r
967 // If the cursor is not at the left edge of the display, then move the cursor\r
968 // left one column.\r
969 //\r
970 This->Mode->CursorColumn--;\r
971 This->OutputString (This, SpaceStr);\r
972 EraseCursor (This);\r
973 This->Mode->CursorColumn--;\r
974 }\r
975\r
976 WString++;\r
977\r
978 } else if (*WString == CHAR_LINEFEED) {\r
979 //\r
980 // If the cursor is at the bottom of the display, then scroll the display one\r
981 // row, and do not update the cursor position. Otherwise, move the cursor\r
982 // down one row.\r
983 //\r
984 if (This->Mode->CursorRow == (INT32) (MaxRow - 1)) {\r
985 if (GraphicsOutput != NULL) {\r
986 //\r
987 // Scroll Screen Up One Row\r
988 //\r
989 GraphicsOutput->Blt (\r
990 GraphicsOutput,\r
991 NULL,\r
992 EfiBltVideoToVideo,\r
993 DeltaX,\r
0898c57c 994 DeltaY + EFI_GLYPH_HEIGHT,\r
95276127 995 DeltaX,\r
996 DeltaY,\r
997 Width,\r
998 Height,\r
999 Delta\r
1000 );\r
1001\r
1002 //\r
1003 // Print Blank Line at last line\r
1004 //\r
1005 GraphicsOutput->Blt (\r
1006 GraphicsOutput,\r
1007 &Background,\r
1008 EfiBltVideoFill,\r
1009 0,\r
1010 0,\r
1011 DeltaX,\r
1012 DeltaY + Height,\r
1013 Width,\r
0898c57c 1014 EFI_GLYPH_HEIGHT,\r
95276127 1015 Delta\r
1016 );\r
8541adab 1017 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1018 //\r
1019 // Scroll Screen Up One Row\r
1020 //\r
1021 UgaDraw->Blt (\r
1022 UgaDraw,\r
1023 NULL,\r
1024 EfiUgaVideoToVideo,\r
1025 DeltaX,\r
0898c57c 1026 DeltaY + EFI_GLYPH_HEIGHT,\r
95276127 1027 DeltaX,\r
1028 DeltaY,\r
1029 Width,\r
1030 Height,\r
1031 Delta\r
1032 );\r
1033\r
1034 //\r
1035 // Print Blank Line at last line\r
1036 //\r
1037 UgaDraw->Blt (\r
1038 UgaDraw,\r
1039 (EFI_UGA_PIXEL *) (UINTN) &Background,\r
1040 EfiUgaVideoFill,\r
1041 0,\r
1042 0,\r
1043 DeltaX,\r
1044 DeltaY + Height,\r
1045 Width,\r
0898c57c 1046 EFI_GLYPH_HEIGHT,\r
95276127 1047 Delta\r
1048 );\r
1049 }\r
1050 } else {\r
1051 This->Mode->CursorRow++;\r
1052 }\r
1053\r
1054 WString++;\r
1055\r
1056 } else if (*WString == CHAR_CARRIAGE_RETURN) {\r
1057 //\r
1058 // Move the cursor to the beginning of the current row.\r
1059 //\r
1060 This->Mode->CursorColumn = 0;\r
1061 WString++;\r
1062\r
1063 } else if (*WString == WIDE_CHAR) {\r
1064\r
1065 This->Mode->Attribute |= EFI_WIDE_ATTRIBUTE;\r
1066 WString++;\r
1067\r
1068 } else if (*WString == NARROW_CHAR) {\r
1069\r
1070 This->Mode->Attribute &= (~ (UINT32) EFI_WIDE_ATTRIBUTE);\r
1071 WString++;\r
1072\r
1073 } else {\r
1074 //\r
1075 // Print the character at the current cursor position and move the cursor\r
1076 // right one column. If this moves the cursor past the right edge of the\r
1077 // display, then the line should wrap to the beginning of the next line. This\r
1078 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the\r
1079 // bottom of the display, and the line wraps, then the display will be scrolled\r
1080 // one line.\r
1081 // If wide char is going to be displayed, need to display one character at a time\r
1082 // Or, need to know the display length of a certain string.\r
1083 //\r
1084 // Index is used to determine how many character width units (wide = 2, narrow = 1)\r
1085 // Count is used to determine how many characters are used regardless of their attributes\r
1086 //\r
1087 for (Count = 0, Index = 0; (This->Mode->CursorColumn + Index) < MaxColumn; Count++, Index++) {\r
1088 if (WString[Count] == CHAR_NULL) {\r
1089 break;\r
1090 }\r
1091\r
1092 if (WString[Count] == CHAR_BACKSPACE) {\r
1093 break;\r
1094 }\r
1095\r
1096 if (WString[Count] == CHAR_LINEFEED) {\r
1097 break;\r
1098 }\r
1099\r
1100 if (WString[Count] == CHAR_CARRIAGE_RETURN) {\r
1101 break;\r
1102 }\r
1103\r
1104 if (WString[Count] == WIDE_CHAR) {\r
1105 break;\r
1106 }\r
1107\r
1108 if (WString[Count] == NARROW_CHAR) {\r
1109 break;\r
1110 }\r
1111 //\r
1112 // Is the wide attribute on?\r
1113 //\r
1114 if (This->Mode->Attribute & EFI_WIDE_ATTRIBUTE) {\r
1115 //\r
1116 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop\r
1117 //\r
1118 Index++;\r
1119 //\r
1120 // This is the end-case where if we are at column 79 and about to print a wide character\r
1121 // We should prevent this from happening because we will wrap inappropriately. We should\r
1122 // not print this character until the next line.\r
1123 //\r
1124 if ((This->Mode->CursorColumn + Index + 1) > MaxColumn) {\r
1125 Index++;\r
1126 break;\r
1127 }\r
1128 }\r
1129 }\r
1130\r
1131 Status = DrawUnicodeWeightAtCursorN (This, WString, Count);\r
1132 if (EFI_ERROR (Status)) {\r
1133 Warning = TRUE;\r
1134 }\r
1135 //\r
1136 // At the end of line, output carriage return and line feed\r
1137 //\r
1138 WString += Count;\r
1139 This->Mode->CursorColumn += (INT32) Index;\r
1140 if (This->Mode->CursorColumn > (INT32) MaxColumn) {\r
1141 This->Mode->CursorColumn -= 2;\r
1142 This->OutputString (This, SpaceStr);\r
1143 }\r
1144\r
1145 if (This->Mode->CursorColumn >= (INT32) MaxColumn) {\r
1146 EraseCursor (This);\r
1147 This->OutputString (This, mCrLfString);\r
1148 EraseCursor (This);\r
1149 }\r
1150 }\r
1151 }\r
1152\r
1153 This->Mode->Attribute = OriginAttribute;\r
1154\r
1155 EraseCursor (This);\r
1156\r
1157 if (Warning) {\r
1158 Status = EFI_WARN_UNKNOWN_GLYPH;\r
1159 }\r
1160\r
1161 gBS->RestoreTPL (OldTpl);\r
1162 return Status;\r
1163\r
1164}\r
1165\r
6dcf9abc 1166/**\r
24248368 1167 Verifies that all characters in a Unicode string can be output to the \r
1168 target device.\r
6dcf9abc 1169\r
24248368 1170 Implements SIMPLE_TEXT_OUTPUT.QueryMode().\r
1171 If one of the characters in the *Wstring is neither valid valid Unicode\r
1172 drawing characters, not ASCII code, then this function will return\r
1173 EFI_UNSUPPORTED\r
1174\r
1175 @param This Protocol instance pointer.\r
1176 @param WString The NULL-terminated Unicode string to be examined for the output\r
1177 device(s).\r
6dcf9abc 1178\r
24248368 1179 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.\r
1180 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be\r
1181 rendered by one or more of the output devices mapped\r
1182 by the EFI handle.\r
6dcf9abc 1183\r
1184**/\r
95276127 1185EFI_STATUS\r
1186EFIAPI\r
1187GraphicsConsoleConOutTestString (\r
1188 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1189 IN CHAR16 *WString\r
1190 )\r
95276127 1191{\r
1192 EFI_STATUS Status;\r
95276127 1193 UINT16 Count;\r
95276127 1194\r
6dcf9abc 1195 EFI_IMAGE_OUTPUT *Blt;\r
93e3992d 1196\r
6dcf9abc 1197 Blt = NULL;\r
93e3992d 1198 Count = 0;\r
1199\r
1200 while (WString[Count] != 0) {\r
93e3992d 1201 Status = mHiiFont->GetGlyph (\r
1202 mHiiFont,\r
1203 WString[Count],\r
1204 NULL,\r
1205 &Blt,\r
1206 NULL\r
1207 );\r
676df92c 1208 if (Blt != NULL) {\r
1209 FreePool (Blt);\r
1210 Blt = NULL;\r
1211 }\r
93e3992d 1212 Count++;\r
d42d853e 1213\r
95276127 1214 if (EFI_ERROR (Status)) {\r
1215 return EFI_UNSUPPORTED;\r
1216 }\r
1217 }\r
1218\r
1219 return EFI_SUCCESS;\r
1220}\r
1221\r
6dcf9abc 1222\r
1223/**\r
24248368 1224 Returns information for an available text mode that the output device(s)\r
1225 supports\r
1226\r
6dcf9abc 1227 Implements SIMPLE_TEXT_OUTPUT.QueryMode().\r
24248368 1228 It returnes information for an available text mode that the Graphics Console supports.\r
1229 In this driver,we only support text mode 80x25, which is defined as mode 0.\r
6dcf9abc 1230\r
24248368 1231 @param This Protocol instance pointer.\r
6dcf9abc 1232 @param ModeNumber The mode number to return information on.\r
1233 @param Columns The returned columns of the requested mode.\r
1234 @param Rows The returned rows of the requested mode.\r
1235\r
24248368 1236 @retval EFI_SUCCESS The requested mode information is returned.\r
1237 @retval EFI_UNSUPPORTED The mode number is not valid.\r
6dcf9abc 1238\r
1239**/\r
95276127 1240EFI_STATUS\r
1241EFIAPI\r
1242GraphicsConsoleConOutQueryMode (\r
1243 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1244 IN UINTN ModeNumber,\r
1245 OUT UINTN *Columns,\r
1246 OUT UINTN *Rows\r
1247 )\r
95276127 1248{\r
1249 GRAPHICS_CONSOLE_DEV *Private;\r
1250 EFI_STATUS Status;\r
1251 EFI_TPL OldTpl;\r
8541adab 1252\r
95276127 1253 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
1254 return EFI_UNSUPPORTED;\r
1255 }\r
1256\r
1257 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1258 Status = EFI_SUCCESS;\r
8541adab 1259\r
95276127 1260 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1261\r
1262 *Columns = Private->ModeData[ModeNumber].Columns;\r
1263 *Rows = Private->ModeData[ModeNumber].Rows;\r
1264\r
1265 if (*Columns <= 0 && *Rows <= 0) {\r
1266 Status = EFI_UNSUPPORTED;\r
1267 goto Done;\r
1268\r
1269 }\r
1270\r
1271Done:\r
1272 gBS->RestoreTPL (OldTpl);\r
1273 return Status;\r
1274}\r
1275\r
6dcf9abc 1276\r
1277/**\r
24248368 1278 Sets the output device(s) to a specified mode.\r
1279 \r
6dcf9abc 1280 Implements SIMPLE_TEXT_OUTPUT.SetMode().\r
24248368 1281 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.\r
6dcf9abc 1282\r
24248368 1283 @param This Protocol instance pointer.\r
6dcf9abc 1284 @param ModeNumber The text mode to set.\r
1285\r
24248368 1286 @retval EFI_SUCCESS The requested text mode is set.\r
1287 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of \r
1288 Graphics Console device error.\r
1289 @retval EFI_UNSUPPORTED The text mode number is not valid.\r
6dcf9abc 1290\r
1291**/\r
95276127 1292EFI_STATUS\r
1293EFIAPI\r
1294GraphicsConsoleConOutSetMode (\r
1295 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1296 IN UINTN ModeNumber\r
1297 )\r
95276127 1298{\r
1299 EFI_STATUS Status;\r
1300 GRAPHICS_CONSOLE_DEV *Private;\r
1301 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
1302 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *NewLineBuffer;\r
1303 UINT32 HorizontalResolution;\r
1304 UINT32 VerticalResolution;\r
1305 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
1306 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1307 UINT32 ColorDepth;\r
1308 UINT32 RefreshRate;\r
1309 EFI_TPL OldTpl;\r
1310\r
1311 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1312\r
1313 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1314 GraphicsOutput = Private->GraphicsOutput;\r
1315 UgaDraw = Private->UgaDraw;\r
1316 ModeData = &(Private->ModeData[ModeNumber]);\r
1317\r
1318 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
1319 Status = EFI_UNSUPPORTED;\r
1320 goto Done;\r
1321 }\r
1322\r
1323 //\r
1324 // Make sure the requested mode number is supported\r
1325 //\r
1326 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
1327 Status = EFI_UNSUPPORTED;\r
1328 goto Done;\r
1329 }\r
1330\r
1331 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
1332 Status = EFI_UNSUPPORTED;\r
1333 goto Done;\r
1334 }\r
1335 //\r
1336 // Attempt to allocate a line buffer for the requested mode number\r
1337 //\r
0898c57c 1338 NewLineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT);\r
95276127 1339\r
1340 if (NewLineBuffer == NULL) {\r
1341 //\r
1342 // The new line buffer could not be allocated, so return an error.\r
1343 // No changes to the state of the current console have been made, so the current console is still valid\r
1344 //\r
1345 Status = EFI_OUT_OF_RESOURCES;\r
1346 goto Done;\r
1347 }\r
1348 //\r
1349 // If the mode has been set at least one other time, then LineBuffer will not be NULL\r
1350 //\r
1351 if (Private->LineBuffer != NULL) {\r
1352 //\r
1353 // Clear the current text window on the current graphics console\r
1354 //\r
1355 This->ClearScreen (This);\r
1356\r
1357 //\r
1358 // If the new mode is the same as the old mode, then just return EFI_SUCCESS\r
1359 //\r
1360 if ((INT32) ModeNumber == This->Mode->Mode) {\r
1361 FreePool (NewLineBuffer);\r
1362 Status = EFI_SUCCESS;\r
1363 goto Done;\r
1364 }\r
1365 //\r
7347d5d6 1366 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,\r
1367 // so erase the cursor, and free the LineBuffer for the current mode\r
95276127 1368 //\r
7347d5d6 1369 EraseCursor (This);\r
95276127 1370\r
1371 FreePool (Private->LineBuffer);\r
1372 }\r
1373 //\r
1374 // Assign the current line buffer to the newly allocated line buffer\r
1375 //\r
1376 Private->LineBuffer = NewLineBuffer;\r
1377\r
1378 if (GraphicsOutput != NULL) {\r
1379 if (ModeData->GopModeNumber != GraphicsOutput->Mode->Mode) {\r
1380 //\r
1381 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode\r
1382 //\r
1383 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeData->GopModeNumber);\r
1384 if (EFI_ERROR (Status)) {\r
1385 //\r
1386 // The mode set operation failed\r
1387 //\r
1388 goto Done;\r
1389 }\r
1390 } else {\r
1391 //\r
1392 // The current graphics mode is correct, so simply clear the entire display\r
1393 //\r
1394 Status = GraphicsOutput->Blt (\r
1395 GraphicsOutput,\r
1396 &mEfiColors[0],\r
1397 EfiBltVideoFill,\r
1398 0,\r
1399 0,\r
1400 0,\r
1401 0,\r
1402 ModeData->GopWidth,\r
1403 ModeData->GopHeight,\r
1404 0\r
1405 );\r
1406 }\r
8541adab 1407 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1408 //\r
1409 // Get the current UGA Draw mode information\r
1410 //\r
1411 Status = UgaDraw->GetMode (\r
1412 UgaDraw,\r
1413 &HorizontalResolution,\r
1414 &VerticalResolution,\r
1415 &ColorDepth,\r
1416 &RefreshRate\r
1417 );\r
1418 if (EFI_ERROR (Status) || HorizontalResolution != ModeData->GopWidth || VerticalResolution != ModeData->GopHeight) {\r
1419 //\r
1420 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode\r
1421 //\r
1422 Status = UgaDraw->SetMode (\r
1423 UgaDraw,\r
1424 ModeData->GopWidth,\r
1425 ModeData->GopHeight,\r
1426 32,\r
1427 60\r
1428 );\r
1429 if (EFI_ERROR (Status)) {\r
1430 //\r
1431 // The mode set operation failed\r
1432 //\r
1433 goto Done;\r
1434 }\r
1435 } else {\r
1436 //\r
1437 // The current graphics mode is correct, so simply clear the entire display\r
1438 //\r
1439 Status = UgaDraw->Blt (\r
1440 UgaDraw,\r
1441 (EFI_UGA_PIXEL *) (UINTN) &mEfiColors[0],\r
1442 EfiUgaVideoFill,\r
1443 0,\r
1444 0,\r
1445 0,\r
1446 0,\r
1447 ModeData->GopWidth,\r
1448 ModeData->GopHeight,\r
1449 0\r
1450 );\r
1451 }\r
1452 }\r
1453\r
1454 //\r
1455 // The new mode is valid, so commit the mode change\r
1456 //\r
1457 This->Mode->Mode = (INT32) ModeNumber;\r
1458\r
1459 //\r
1460 // Move the text cursor to the upper left hand corner of the displat and enable it\r
1461 //\r
1462 This->SetCursorPosition (This, 0, 0);\r
95276127 1463\r
1464 Status = EFI_SUCCESS;\r
1465\r
1466Done:\r
1467 gBS->RestoreTPL (OldTpl);\r
1468 return Status;\r
1469}\r
1470\r
6dcf9abc 1471\r
1472/**\r
24248368 1473 Sets the background and foreground colors for the OutputString () and\r
1474 ClearScreen () functions.\r
1475\r
6dcf9abc 1476 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().\r
1477\r
24248368 1478 @param This Protocol instance pointer.\r
1479 @param Attribute The attribute to set. Bits 0..3 are the foreground\r
1480 color, and bits 4..6 are the background color. \r
1481 All other bits are undefined and must be zero.\r
6dcf9abc 1482\r
24248368 1483 @retval EFI_SUCCESS The requested attribute is set.\r
1484 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.\r
1485 @retval EFI_UNSUPPORTED The attribute requested is not defined.\r
6dcf9abc 1486\r
1487**/\r
95276127 1488EFI_STATUS\r
1489EFIAPI\r
1490GraphicsConsoleConOutSetAttribute (\r
1491 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1492 IN UINTN Attribute\r
1493 )\r
95276127 1494{\r
1495 EFI_TPL OldTpl;\r
8541adab 1496\r
95276127 1497 if ((Attribute | 0xFF) != 0xFF) {\r
1498 return EFI_UNSUPPORTED;\r
1499 }\r
1500\r
1501 if ((INT32) Attribute == This->Mode->Attribute) {\r
1502 return EFI_SUCCESS;\r
1503 }\r
1504\r
1505 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1506\r
1507 EraseCursor (This);\r
1508\r
1509 This->Mode->Attribute = (INT32) Attribute;\r
1510\r
1511 EraseCursor (This);\r
1512\r
1513 gBS->RestoreTPL (OldTpl);\r
1514\r
1515 return EFI_SUCCESS;\r
1516}\r
1517\r
6dcf9abc 1518\r
1519/**\r
24248368 1520 Clears the output device(s) display to the currently selected background \r
1521 color.\r
1522\r
6dcf9abc 1523 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().\r
6dcf9abc 1524\r
24248368 1525 @param This Protocol instance pointer.\r
6dcf9abc 1526\r
24248368 1527 @retval EFI_SUCCESS The operation completed successfully.\r
1528 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
1529 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
6dcf9abc 1530\r
1531**/\r
95276127 1532EFI_STATUS\r
1533EFIAPI\r
1534GraphicsConsoleConOutClearScreen (\r
1535 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
1536 )\r
95276127 1537{\r
1538 EFI_STATUS Status;\r
1539 GRAPHICS_CONSOLE_DEV *Private;\r
1540 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
1541 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
1542 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1543 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
1544 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
1545 EFI_TPL OldTpl;\r
1546\r
1547 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1548\r
1549 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1550 GraphicsOutput = Private->GraphicsOutput;\r
1551 UgaDraw = Private->UgaDraw;\r
1552 ModeData = &(Private->ModeData[This->Mode->Mode]);\r
1553\r
1554 GetTextColors (This, &Foreground, &Background);\r
1555 if (GraphicsOutput != NULL) {\r
1556 Status = GraphicsOutput->Blt (\r
1557 GraphicsOutput,\r
1558 &Background,\r
1559 EfiBltVideoFill,\r
1560 0,\r
1561 0,\r
1562 0,\r
1563 0,\r
1564 ModeData->GopWidth,\r
1565 ModeData->GopHeight,\r
1566 0\r
1567 );\r
8541adab 1568 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1569 Status = UgaDraw->Blt (\r
1570 UgaDraw,\r
1571 (EFI_UGA_PIXEL *) (UINTN) &Background,\r
1572 EfiUgaVideoFill,\r
1573 0,\r
1574 0,\r
1575 0,\r
1576 0,\r
1577 ModeData->GopWidth,\r
1578 ModeData->GopHeight,\r
1579 0\r
1580 );\r
8541adab 1581 } else {\r
1582 Status = EFI_UNSUPPORTED;\r
95276127 1583 }\r
1584\r
1585 This->Mode->CursorColumn = 0;\r
1586 This->Mode->CursorRow = 0;\r
1587\r
1588 EraseCursor (This);\r
1589\r
1590 gBS->RestoreTPL (OldTpl);\r
1591\r
1592 return Status;\r
1593}\r
1594\r
6dcf9abc 1595\r
1596/**\r
24248368 1597 Sets the current coordinates of the cursor position.\r
1598\r
6dcf9abc 1599 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().\r
1600\r
24248368 1601 @param This Protocol instance pointer.\r
1602 @param Column The position to set the cursor to. Must be greater than or\r
1603 equal to zero and less than the number of columns and rows\r
1604 by QueryMode ().\r
1605 @param Row The position to set the cursor to. Must be greater than or\r
1606 equal to zero and less than the number of columns and rows\r
1607 by QueryMode ().\r
6dcf9abc 1608\r
24248368 1609 @retval EFI_SUCCESS The operation completed successfully.\r
1610 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
1611 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the\r
1612 cursor position is invalid for the current mode.\r
6dcf9abc 1613\r
1614**/\r
95276127 1615EFI_STATUS\r
1616EFIAPI\r
1617GraphicsConsoleConOutSetCursorPosition (\r
1618 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1619 IN UINTN Column,\r
1620 IN UINTN Row\r
1621 )\r
95276127 1622{\r
1623 GRAPHICS_CONSOLE_DEV *Private;\r
1624 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
1625 EFI_STATUS Status;\r
1626 EFI_TPL OldTpl;\r
1627\r
1628 Status = EFI_SUCCESS;\r
1629\r
1630 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1631\r
1632 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1633 ModeData = &(Private->ModeData[This->Mode->Mode]);\r
1634\r
1635 if ((Column >= ModeData->Columns) || (Row >= ModeData->Rows)) {\r
1636 Status = EFI_UNSUPPORTED;\r
1637 goto Done;\r
1638 }\r
1639\r
8595bdaf 1640 if ((This->Mode->CursorColumn == (INT32) Column) && (This->Mode->CursorRow == (INT32) Row)) {\r
95276127 1641 Status = EFI_SUCCESS;\r
1642 goto Done;\r
1643 }\r
1644\r
1645 EraseCursor (This);\r
1646\r
1647 This->Mode->CursorColumn = (INT32) Column;\r
1648 This->Mode->CursorRow = (INT32) Row;\r
1649\r
1650 EraseCursor (This);\r
1651\r
1652Done:\r
1653 gBS->RestoreTPL (OldTpl);\r
1654\r
1655 return Status;\r
1656}\r
1657\r
6dcf9abc 1658\r
1659/**\r
24248368 1660 Makes the cursor visible or invisible.\r
1661\r
6dcf9abc 1662 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().\r
6dcf9abc 1663\r
24248368 1664 @param This Protocol instance pointer.\r
6dcf9abc 1665 @param Visible If TRUE, the cursor is set to be visible, If FALSE,\r
1666 the cursor is set to be invisible.\r
1667\r
24248368 1668 @retval EFI_SUCCESS The operation completed successfully.\r
6dcf9abc 1669\r
1670**/\r
95276127 1671EFI_STATUS\r
1672EFIAPI\r
1673GraphicsConsoleConOutEnableCursor (\r
1674 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1675 IN BOOLEAN Visible\r
1676 )\r
95276127 1677{\r
1678 EFI_TPL OldTpl;\r
8541adab 1679\r
95276127 1680 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
8541adab 1681\r
95276127 1682 EraseCursor (This);\r
1683\r
1684 This->Mode->CursorVisible = Visible;\r
1685\r
1686 EraseCursor (This);\r
1687\r
1688 gBS->RestoreTPL (OldTpl);\r
1689 return EFI_SUCCESS;\r
1690}\r
1691\r
24248368 1692/**\r
1693 Gets Graphics Console devcie's foreground color and background color.\r
1694\r
1695 @param This Protocol instance pointer.\r
1696 @param Foreground Returned text foreground color.\r
1697 @param Background Returned text background color.\r
1698\r
1699 @retval EFI_SUCCESS It returned always.\r
1700\r
1701**/\r
95276127 1702EFI_STATUS\r
1703GetTextColors (\r
1704 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1705 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,\r
1706 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background\r
1707 )\r
1708{\r
1709 INTN Attribute;\r
1710\r
1711 Attribute = This->Mode->Attribute & 0x7F;\r
1712\r
1713 *Foreground = mEfiColors[Attribute & 0x0f];\r
1714 *Background = mEfiColors[Attribute >> 4];\r
1715\r
1716 return EFI_SUCCESS;\r
1717}\r
1718\r
24248368 1719/**\r
1720 Draw Unicode string on the Graphice Console device's screen.\r
1721\r
1722 @param This Protocol instance pointer.\r
1723 @param UnicodeWeight One Unicode string to be displayed.\r
1724 @param Count The count of Unicode string.\r
1725\r
1726 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.\r
1727 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw\r
1728 protocol exist.\r
1729 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.\r
1730\r
1731**/\r
93e3992d 1732EFI_STATUS\r
1733DrawUnicodeWeightAtCursorN (\r
1734 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
24248368 1735 IN CHAR16 *UnicodeWeight,\r
1736 IN UINTN Count\r
93e3992d 1737 )\r
1738{\r
1739 EFI_STATUS Status;\r
1740 GRAPHICS_CONSOLE_DEV *Private;\r
1741 EFI_IMAGE_OUTPUT *Blt;\r
1742 EFI_STRING String;\r
1743 EFI_FONT_DISPLAY_INFO *FontInfo;\r
d42d853e 1744 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1745 EFI_HII_ROW_INFO *RowInfoArray;\r
1746 UINTN RowInfoArraySize;\r
93e3992d 1747\r
1748 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
93e3992d 1749 Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
1750 if (Blt == NULL) {\r
1751 return EFI_OUT_OF_RESOURCES;\r
1752 }\r
1753\r
1754 Blt->Width = (UINT16) (Private->ModeData[This->Mode->Mode].GopWidth);\r
1755 Blt->Height = (UINT16) (Private->ModeData[This->Mode->Mode].GopHeight);\r
93e3992d 1756\r
1757 String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);\r
1758 if (String == NULL) {\r
676df92c 1759 FreePool (Blt);\r
93e3992d 1760 return EFI_OUT_OF_RESOURCES;\r
1761 }\r
8595bdaf 1762 //\r
1763 // Set the end character\r
1764 //\r
1765 *(String + Count) = L'\0';\r
93e3992d 1766\r
1767 FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
1768 if (FontInfo == NULL) {\r
676df92c 1769 FreePool (Blt);\r
1770 FreePool (String);\r
93e3992d 1771 return EFI_OUT_OF_RESOURCES;\r
1772 }\r
8595bdaf 1773 //\r
1774 // Get current foreground and background colors.\r
1775 //\r
93e3992d 1776 GetTextColors (This, &FontInfo->ForegroundColor, &FontInfo->BackgroundColor);\r
1777\r
d42d853e 1778 if (Private->GraphicsOutput != NULL) {\r
8595bdaf 1779 //\r
1780 // If Graphcis Output protocol exists, using HII Font protocol to draw. \r
1781 //\r
d42d853e 1782 Blt->Image.Screen = Private->GraphicsOutput;\r
95276127 1783\r
d42d853e 1784 Status = mHiiFont->StringToImage (\r
1785 mHiiFont,\r
1786 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,\r
1787 String,\r
1788 FontInfo,\r
1789 &Blt,\r
0898c57c 1790 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
1791 This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
d42d853e 1792 NULL,\r
1793 NULL,\r
1794 NULL\r
1795 );\r
95276127 1796\r
8541adab 1797 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
8595bdaf 1798 //\r
1799 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled, \r
1800 // using UGA Draw protocol to draw.\r
1801 //\r
d42d853e 1802 ASSERT (Private->UgaDraw!= NULL);\r
95276127 1803\r
d42d853e 1804 UgaDraw = Private->UgaDraw;\r
95276127 1805\r
d42d853e 1806 Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
1807 if (Blt->Image.Bitmap == NULL) {\r
676df92c 1808 FreePool (Blt);\r
1809 FreePool (String);\r
d42d853e 1810 return EFI_OUT_OF_RESOURCES;\r
95276127 1811 }\r
1812\r
d42d853e 1813 RowInfoArray = NULL;\r
1814 //\r
1815 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,\r
1816 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r
1817 //\r
1818 Status = mHiiFont->StringToImage (\r
1819 mHiiFont,\r
1820 EFI_HII_IGNORE_IF_NO_GLYPH,\r
1821 String,\r
1822 FontInfo,\r
1823 &Blt,\r
0898c57c 1824 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
1825 This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
d42d853e 1826 &RowInfoArray,\r
1827 &RowInfoArraySize,\r
1828 NULL\r
1829 );\r
95276127 1830\r
d42d853e 1831 if (!EFI_ERROR (Status)) {\r
95276127 1832 //\r
d42d853e 1833 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will\r
bd1d34ee 1834 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r
95276127 1835 //\r
bd1d34ee 1836 ASSERT (RowInfoArraySize <= 1);\r
8541adab 1837\r
d42d853e 1838 Status = UgaDraw->Blt (\r
1839 UgaDraw,\r
1840 (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
1841 EfiUgaBltBufferToVideo,\r
0898c57c 1842 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
1843 (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
1844 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
1845 (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
d42d853e 1846 RowInfoArray[0].LineWidth,\r
1847 RowInfoArray[0].LineHeight,\r
1848 Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
1849 );\r
1850 }\r
95276127 1851\r
676df92c 1852 FreePool (RowInfoArray);\r
1853 FreePool (Blt->Image.Bitmap);\r
8541adab 1854 } else {\r
1855 Status = EFI_UNSUPPORTED;\r
95276127 1856 }\r
1857\r
676df92c 1858 if (Blt != NULL) {\r
1859 FreePool (Blt);\r
1860 }\r
1861 if (String != NULL) {\r
1862 FreePool (String);\r
1863 }\r
1864 if (FontInfo != NULL) {\r
1865 FreePool (FontInfo);\r
1866 }\r
d42d853e 1867 return Status;\r
95276127 1868}\r
d42d853e 1869\r
24248368 1870/**\r
1871 Erase the cursor on the screen.\r
95276127 1872\r
24248368 1873 @param This Protocol instance pointer.\r
1874\r
1875 @retval EFI_SUCCESS The cursor is erased successfully.\r
1876\r
1877**/\r
95276127 1878EFI_STATUS\r
1879EraseCursor (\r
1880 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
1881 )\r
1882{\r
1883 GRAPHICS_CONSOLE_DEV *Private;\r
1884 EFI_SIMPLE_TEXT_OUTPUT_MODE *CurrentMode;\r
1885 INTN GlyphX;\r
1886 INTN GlyphY;\r
1887 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
1888 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1889 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground;\r
1890 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background;\r
0898c57c 1891 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[EFI_GLYPH_HEIGHT][EFI_GLYPH_WIDTH];\r
6dcf9abc 1892 UINTN PosX;\r
1893 UINTN PosY;\r
95276127 1894\r
1895 CurrentMode = This->Mode;\r
1896\r
1897 if (!CurrentMode->CursorVisible) {\r
1898 return EFI_SUCCESS;\r
1899 }\r
1900\r
1901 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1902 GraphicsOutput = Private->GraphicsOutput;\r
1903 UgaDraw = Private->UgaDraw;\r
1904\r
1905 //\r
24248368 1906 // In this driver, only narrow character was supported.\r
95276127 1907 //\r
1908 //\r
1909 // Blt a character to the screen\r
1910 //\r
0898c57c 1911 GlyphX = (CurrentMode->CursorColumn * EFI_GLYPH_WIDTH) + Private->ModeData[CurrentMode->Mode].DeltaX;\r
1912 GlyphY = (CurrentMode->CursorRow * EFI_GLYPH_HEIGHT) + Private->ModeData[CurrentMode->Mode].DeltaY;\r
95276127 1913 if (GraphicsOutput != NULL) {\r
1914 GraphicsOutput->Blt (\r
1915 GraphicsOutput,\r
1916 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
1917 EfiBltVideoToBltBuffer,\r
1918 GlyphX,\r
1919 GlyphY,\r
1920 0,\r
1921 0,\r
0898c57c 1922 EFI_GLYPH_WIDTH,\r
1923 EFI_GLYPH_HEIGHT,\r
1924 EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
95276127 1925 );\r
8541adab 1926 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1927 UgaDraw->Blt (\r
1928 UgaDraw,\r
1929 (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
1930 EfiUgaVideoToBltBuffer,\r
1931 GlyphX,\r
1932 GlyphY,\r
1933 0,\r
1934 0,\r
0898c57c 1935 EFI_GLYPH_WIDTH,\r
1936 EFI_GLYPH_HEIGHT,\r
1937 EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
95276127 1938 );\r
1939 }\r
1940\r
1941 GetTextColors (This, &Foreground.Pixel, &Background.Pixel);\r
1942\r
1943 //\r
1944 // Convert Monochrome bitmap of the Glyph to BltBuffer structure\r
1945 //\r
6dcf9abc 1946 for (PosY = 0; PosY < EFI_GLYPH_HEIGHT; PosY++) {\r
1947 for (PosX = 0; PosX < EFI_GLYPH_WIDTH; PosX++) {\r
1948 if ((mCursorGlyph.GlyphCol1[PosY] & (1 << PosX)) != 0) {\r
1949 BltChar[PosY][EFI_GLYPH_WIDTH - PosX - 1].Raw ^= Foreground.Raw;\r
95276127 1950 }\r
1951 }\r
1952 }\r
1953\r
1954 if (GraphicsOutput != NULL) {\r
1955 GraphicsOutput->Blt (\r
1956 GraphicsOutput,\r
1957 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
1958 EfiBltBufferToVideo,\r
1959 0,\r
1960 0,\r
1961 GlyphX,\r
1962 GlyphY,\r
0898c57c 1963 EFI_GLYPH_WIDTH,\r
1964 EFI_GLYPH_HEIGHT,\r
1965 EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
95276127 1966 );\r
8541adab 1967 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1968 UgaDraw->Blt (\r
1969 UgaDraw,\r
1970 (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
1971 EfiUgaBltBufferToVideo,\r
1972 0,\r
1973 0,\r
1974 GlyphX,\r
1975 GlyphY,\r
0898c57c 1976 EFI_GLYPH_WIDTH,\r
1977 EFI_GLYPH_HEIGHT,\r
1978 EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
95276127 1979 );\r
1980 }\r
1981\r
1982 return EFI_SUCCESS;\r
1983}\r
97a079ed
A
1984\r
1985/**\r
1986 The user Entry Point for module GraphicsConsole. The user code starts with this function.\r
1987\r
8541adab 1988 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
97a079ed 1989 @param[in] SystemTable A pointer to the EFI System Table.\r
8541adab 1990\r
97a079ed
A
1991 @retval EFI_SUCCESS The entry point is executed successfully.\r
1992 @retval other Some error occurs when executing this entry point.\r
1993\r
1994**/\r
1995EFI_STATUS\r
1996EFIAPI\r
1997InitializeGraphicsConsole (\r
1998 IN EFI_HANDLE ImageHandle,\r
1999 IN EFI_SYSTEM_TABLE *SystemTable\r
2000 )\r
2001{\r
2002 EFI_STATUS Status;\r
2003\r
2004 //\r
2005 // Install driver model protocol(s).\r
2006 //\r
5bca971e 2007 Status = EfiLibInstallDriverBindingComponentName2 (\r
97a079ed
A
2008 ImageHandle,\r
2009 SystemTable,\r
2010 &gGraphicsConsoleDriverBinding,\r
2011 ImageHandle,\r
2012 &gGraphicsConsoleComponentName,\r
5bca971e 2013 &gGraphicsConsoleComponentName2\r
97a079ed
A
2014 );\r
2015 ASSERT_EFI_ERROR (Status);\r
2016\r
2017\r
2018 return Status;\r
2019}\r
2020\r
d42d853e 2021\r