]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[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
fe1e36e5 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
396 SafeFreePool (PackageList);\r
8541adab 397 SafeFreePool (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
1208 SafeFreePool (Blt);\r
1209 Blt = NULL;\r
1210 Count++;\r
d42d853e 1211\r
95276127 1212 if (EFI_ERROR (Status)) {\r
1213 return EFI_UNSUPPORTED;\r
1214 }\r
1215 }\r
1216\r
1217 return EFI_SUCCESS;\r
1218}\r
1219\r
6dcf9abc 1220\r
1221/**\r
24248368 1222 Returns information for an available text mode that the output device(s)\r
1223 supports\r
1224\r
6dcf9abc 1225 Implements SIMPLE_TEXT_OUTPUT.QueryMode().\r
24248368 1226 It returnes information for an available text mode that the Graphics Console supports.\r
1227 In this driver,we only support text mode 80x25, which is defined as mode 0.\r
6dcf9abc 1228\r
24248368 1229 @param This Protocol instance pointer.\r
6dcf9abc 1230 @param ModeNumber The mode number to return information on.\r
1231 @param Columns The returned columns of the requested mode.\r
1232 @param Rows The returned rows of the requested mode.\r
1233\r
24248368 1234 @retval EFI_SUCCESS The requested mode information is returned.\r
1235 @retval EFI_UNSUPPORTED The mode number is not valid.\r
6dcf9abc 1236\r
1237**/\r
95276127 1238EFI_STATUS\r
1239EFIAPI\r
1240GraphicsConsoleConOutQueryMode (\r
1241 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1242 IN UINTN ModeNumber,\r
1243 OUT UINTN *Columns,\r
1244 OUT UINTN *Rows\r
1245 )\r
95276127 1246{\r
1247 GRAPHICS_CONSOLE_DEV *Private;\r
1248 EFI_STATUS Status;\r
1249 EFI_TPL OldTpl;\r
8541adab 1250\r
95276127 1251 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
1252 return EFI_UNSUPPORTED;\r
1253 }\r
1254\r
1255 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1256 Status = EFI_SUCCESS;\r
8541adab 1257\r
95276127 1258 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1259\r
1260 *Columns = Private->ModeData[ModeNumber].Columns;\r
1261 *Rows = Private->ModeData[ModeNumber].Rows;\r
1262\r
1263 if (*Columns <= 0 && *Rows <= 0) {\r
1264 Status = EFI_UNSUPPORTED;\r
1265 goto Done;\r
1266\r
1267 }\r
1268\r
1269Done:\r
1270 gBS->RestoreTPL (OldTpl);\r
1271 return Status;\r
1272}\r
1273\r
6dcf9abc 1274\r
1275/**\r
24248368 1276 Sets the output device(s) to a specified mode.\r
1277 \r
6dcf9abc 1278 Implements SIMPLE_TEXT_OUTPUT.SetMode().\r
24248368 1279 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.\r
6dcf9abc 1280\r
24248368 1281 @param This Protocol instance pointer.\r
6dcf9abc 1282 @param ModeNumber The text mode to set.\r
1283\r
24248368 1284 @retval EFI_SUCCESS The requested text mode is set.\r
1285 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of \r
1286 Graphics Console device error.\r
1287 @retval EFI_UNSUPPORTED The text mode number is not valid.\r
6dcf9abc 1288\r
1289**/\r
95276127 1290EFI_STATUS\r
1291EFIAPI\r
1292GraphicsConsoleConOutSetMode (\r
1293 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1294 IN UINTN ModeNumber\r
1295 )\r
95276127 1296{\r
1297 EFI_STATUS Status;\r
1298 GRAPHICS_CONSOLE_DEV *Private;\r
1299 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
1300 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *NewLineBuffer;\r
1301 UINT32 HorizontalResolution;\r
1302 UINT32 VerticalResolution;\r
1303 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
1304 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1305 UINT32 ColorDepth;\r
1306 UINT32 RefreshRate;\r
1307 EFI_TPL OldTpl;\r
1308\r
1309 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1310\r
1311 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1312 GraphicsOutput = Private->GraphicsOutput;\r
1313 UgaDraw = Private->UgaDraw;\r
1314 ModeData = &(Private->ModeData[ModeNumber]);\r
1315\r
1316 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
1317 Status = EFI_UNSUPPORTED;\r
1318 goto Done;\r
1319 }\r
1320\r
1321 //\r
1322 // Make sure the requested mode number is supported\r
1323 //\r
1324 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
1325 Status = EFI_UNSUPPORTED;\r
1326 goto Done;\r
1327 }\r
1328\r
1329 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
1330 Status = EFI_UNSUPPORTED;\r
1331 goto Done;\r
1332 }\r
1333 //\r
1334 // Attempt to allocate a line buffer for the requested mode number\r
1335 //\r
0898c57c 1336 NewLineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT);\r
95276127 1337\r
1338 if (NewLineBuffer == NULL) {\r
1339 //\r
1340 // The new line buffer could not be allocated, so return an error.\r
1341 // No changes to the state of the current console have been made, so the current console is still valid\r
1342 //\r
1343 Status = EFI_OUT_OF_RESOURCES;\r
1344 goto Done;\r
1345 }\r
1346 //\r
1347 // If the mode has been set at least one other time, then LineBuffer will not be NULL\r
1348 //\r
1349 if (Private->LineBuffer != NULL) {\r
1350 //\r
1351 // Clear the current text window on the current graphics console\r
1352 //\r
1353 This->ClearScreen (This);\r
1354\r
1355 //\r
1356 // If the new mode is the same as the old mode, then just return EFI_SUCCESS\r
1357 //\r
1358 if ((INT32) ModeNumber == This->Mode->Mode) {\r
1359 FreePool (NewLineBuffer);\r
1360 Status = EFI_SUCCESS;\r
1361 goto Done;\r
1362 }\r
1363 //\r
7347d5d6 1364 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,\r
1365 // so erase the cursor, and free the LineBuffer for the current mode\r
95276127 1366 //\r
7347d5d6 1367 EraseCursor (This);\r
95276127 1368\r
1369 FreePool (Private->LineBuffer);\r
1370 }\r
1371 //\r
1372 // Assign the current line buffer to the newly allocated line buffer\r
1373 //\r
1374 Private->LineBuffer = NewLineBuffer;\r
1375\r
1376 if (GraphicsOutput != NULL) {\r
1377 if (ModeData->GopModeNumber != GraphicsOutput->Mode->Mode) {\r
1378 //\r
1379 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode\r
1380 //\r
1381 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeData->GopModeNumber);\r
1382 if (EFI_ERROR (Status)) {\r
1383 //\r
1384 // The mode set operation failed\r
1385 //\r
1386 goto Done;\r
1387 }\r
1388 } else {\r
1389 //\r
1390 // The current graphics mode is correct, so simply clear the entire display\r
1391 //\r
1392 Status = GraphicsOutput->Blt (\r
1393 GraphicsOutput,\r
1394 &mEfiColors[0],\r
1395 EfiBltVideoFill,\r
1396 0,\r
1397 0,\r
1398 0,\r
1399 0,\r
1400 ModeData->GopWidth,\r
1401 ModeData->GopHeight,\r
1402 0\r
1403 );\r
1404 }\r
8541adab 1405 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1406 //\r
1407 // Get the current UGA Draw mode information\r
1408 //\r
1409 Status = UgaDraw->GetMode (\r
1410 UgaDraw,\r
1411 &HorizontalResolution,\r
1412 &VerticalResolution,\r
1413 &ColorDepth,\r
1414 &RefreshRate\r
1415 );\r
1416 if (EFI_ERROR (Status) || HorizontalResolution != ModeData->GopWidth || VerticalResolution != ModeData->GopHeight) {\r
1417 //\r
1418 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode\r
1419 //\r
1420 Status = UgaDraw->SetMode (\r
1421 UgaDraw,\r
1422 ModeData->GopWidth,\r
1423 ModeData->GopHeight,\r
1424 32,\r
1425 60\r
1426 );\r
1427 if (EFI_ERROR (Status)) {\r
1428 //\r
1429 // The mode set operation failed\r
1430 //\r
1431 goto Done;\r
1432 }\r
1433 } else {\r
1434 //\r
1435 // The current graphics mode is correct, so simply clear the entire display\r
1436 //\r
1437 Status = UgaDraw->Blt (\r
1438 UgaDraw,\r
1439 (EFI_UGA_PIXEL *) (UINTN) &mEfiColors[0],\r
1440 EfiUgaVideoFill,\r
1441 0,\r
1442 0,\r
1443 0,\r
1444 0,\r
1445 ModeData->GopWidth,\r
1446 ModeData->GopHeight,\r
1447 0\r
1448 );\r
1449 }\r
1450 }\r
1451\r
1452 //\r
1453 // The new mode is valid, so commit the mode change\r
1454 //\r
1455 This->Mode->Mode = (INT32) ModeNumber;\r
1456\r
1457 //\r
1458 // Move the text cursor to the upper left hand corner of the displat and enable it\r
1459 //\r
1460 This->SetCursorPosition (This, 0, 0);\r
95276127 1461\r
1462 Status = EFI_SUCCESS;\r
1463\r
1464Done:\r
1465 gBS->RestoreTPL (OldTpl);\r
1466 return Status;\r
1467}\r
1468\r
6dcf9abc 1469\r
1470/**\r
24248368 1471 Sets the background and foreground colors for the OutputString () and\r
1472 ClearScreen () functions.\r
1473\r
6dcf9abc 1474 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().\r
1475\r
24248368 1476 @param This Protocol instance pointer.\r
1477 @param Attribute The attribute to set. Bits 0..3 are the foreground\r
1478 color, and bits 4..6 are the background color. \r
1479 All other bits are undefined and must be zero.\r
6dcf9abc 1480\r
24248368 1481 @retval EFI_SUCCESS The requested attribute is set.\r
1482 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.\r
1483 @retval EFI_UNSUPPORTED The attribute requested is not defined.\r
6dcf9abc 1484\r
1485**/\r
95276127 1486EFI_STATUS\r
1487EFIAPI\r
1488GraphicsConsoleConOutSetAttribute (\r
1489 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1490 IN UINTN Attribute\r
1491 )\r
95276127 1492{\r
1493 EFI_TPL OldTpl;\r
8541adab 1494\r
95276127 1495 if ((Attribute | 0xFF) != 0xFF) {\r
1496 return EFI_UNSUPPORTED;\r
1497 }\r
1498\r
1499 if ((INT32) Attribute == This->Mode->Attribute) {\r
1500 return EFI_SUCCESS;\r
1501 }\r
1502\r
1503 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1504\r
1505 EraseCursor (This);\r
1506\r
1507 This->Mode->Attribute = (INT32) Attribute;\r
1508\r
1509 EraseCursor (This);\r
1510\r
1511 gBS->RestoreTPL (OldTpl);\r
1512\r
1513 return EFI_SUCCESS;\r
1514}\r
1515\r
6dcf9abc 1516\r
1517/**\r
24248368 1518 Clears the output device(s) display to the currently selected background \r
1519 color.\r
1520\r
6dcf9abc 1521 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().\r
6dcf9abc 1522\r
24248368 1523 @param This Protocol instance pointer.\r
6dcf9abc 1524\r
24248368 1525 @retval EFI_SUCCESS The operation completed successfully.\r
1526 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
1527 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
6dcf9abc 1528\r
1529**/\r
95276127 1530EFI_STATUS\r
1531EFIAPI\r
1532GraphicsConsoleConOutClearScreen (\r
1533 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
1534 )\r
95276127 1535{\r
1536 EFI_STATUS Status;\r
1537 GRAPHICS_CONSOLE_DEV *Private;\r
1538 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
1539 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
1540 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1541 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
1542 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
1543 EFI_TPL OldTpl;\r
1544\r
1545 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1546\r
1547 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1548 GraphicsOutput = Private->GraphicsOutput;\r
1549 UgaDraw = Private->UgaDraw;\r
1550 ModeData = &(Private->ModeData[This->Mode->Mode]);\r
1551\r
1552 GetTextColors (This, &Foreground, &Background);\r
1553 if (GraphicsOutput != NULL) {\r
1554 Status = GraphicsOutput->Blt (\r
1555 GraphicsOutput,\r
1556 &Background,\r
1557 EfiBltVideoFill,\r
1558 0,\r
1559 0,\r
1560 0,\r
1561 0,\r
1562 ModeData->GopWidth,\r
1563 ModeData->GopHeight,\r
1564 0\r
1565 );\r
8541adab 1566 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1567 Status = UgaDraw->Blt (\r
1568 UgaDraw,\r
1569 (EFI_UGA_PIXEL *) (UINTN) &Background,\r
1570 EfiUgaVideoFill,\r
1571 0,\r
1572 0,\r
1573 0,\r
1574 0,\r
1575 ModeData->GopWidth,\r
1576 ModeData->GopHeight,\r
1577 0\r
1578 );\r
8541adab 1579 } else {\r
1580 Status = EFI_UNSUPPORTED;\r
95276127 1581 }\r
1582\r
1583 This->Mode->CursorColumn = 0;\r
1584 This->Mode->CursorRow = 0;\r
1585\r
1586 EraseCursor (This);\r
1587\r
1588 gBS->RestoreTPL (OldTpl);\r
1589\r
1590 return Status;\r
1591}\r
1592\r
6dcf9abc 1593\r
1594/**\r
24248368 1595 Sets the current coordinates of the cursor position.\r
1596\r
6dcf9abc 1597 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().\r
1598\r
24248368 1599 @param This Protocol instance pointer.\r
1600 @param Column The position to set the cursor to. Must be greater than or\r
1601 equal to zero and less than the number of columns and rows\r
1602 by QueryMode ().\r
1603 @param Row The position to set the cursor to. Must be greater than or\r
1604 equal to zero and less than the number of columns and rows\r
1605 by QueryMode ().\r
6dcf9abc 1606\r
24248368 1607 @retval EFI_SUCCESS The operation completed successfully.\r
1608 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
1609 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the\r
1610 cursor position is invalid for the current mode.\r
6dcf9abc 1611\r
1612**/\r
95276127 1613EFI_STATUS\r
1614EFIAPI\r
1615GraphicsConsoleConOutSetCursorPosition (\r
1616 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1617 IN UINTN Column,\r
1618 IN UINTN Row\r
1619 )\r
95276127 1620{\r
1621 GRAPHICS_CONSOLE_DEV *Private;\r
1622 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
1623 EFI_STATUS Status;\r
1624 EFI_TPL OldTpl;\r
1625\r
1626 Status = EFI_SUCCESS;\r
1627\r
1628 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
1629\r
1630 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1631 ModeData = &(Private->ModeData[This->Mode->Mode]);\r
1632\r
1633 if ((Column >= ModeData->Columns) || (Row >= ModeData->Rows)) {\r
1634 Status = EFI_UNSUPPORTED;\r
1635 goto Done;\r
1636 }\r
1637\r
8595bdaf 1638 if ((This->Mode->CursorColumn == (INT32) Column) && (This->Mode->CursorRow == (INT32) Row)) {\r
95276127 1639 Status = EFI_SUCCESS;\r
1640 goto Done;\r
1641 }\r
1642\r
1643 EraseCursor (This);\r
1644\r
1645 This->Mode->CursorColumn = (INT32) Column;\r
1646 This->Mode->CursorRow = (INT32) Row;\r
1647\r
1648 EraseCursor (This);\r
1649\r
1650Done:\r
1651 gBS->RestoreTPL (OldTpl);\r
1652\r
1653 return Status;\r
1654}\r
1655\r
6dcf9abc 1656\r
1657/**\r
24248368 1658 Makes the cursor visible or invisible.\r
1659\r
6dcf9abc 1660 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().\r
6dcf9abc 1661\r
24248368 1662 @param This Protocol instance pointer.\r
6dcf9abc 1663 @param Visible If TRUE, the cursor is set to be visible, If FALSE,\r
1664 the cursor is set to be invisible.\r
1665\r
24248368 1666 @retval EFI_SUCCESS The operation completed successfully.\r
6dcf9abc 1667\r
1668**/\r
95276127 1669EFI_STATUS\r
1670EFIAPI\r
1671GraphicsConsoleConOutEnableCursor (\r
1672 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1673 IN BOOLEAN Visible\r
1674 )\r
95276127 1675{\r
1676 EFI_TPL OldTpl;\r
8541adab 1677\r
95276127 1678 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
8541adab 1679\r
95276127 1680 EraseCursor (This);\r
1681\r
1682 This->Mode->CursorVisible = Visible;\r
1683\r
1684 EraseCursor (This);\r
1685\r
1686 gBS->RestoreTPL (OldTpl);\r
1687 return EFI_SUCCESS;\r
1688}\r
1689\r
24248368 1690/**\r
1691 Gets Graphics Console devcie's foreground color and background color.\r
1692\r
1693 @param This Protocol instance pointer.\r
1694 @param Foreground Returned text foreground color.\r
1695 @param Background Returned text background color.\r
1696\r
1697 @retval EFI_SUCCESS It returned always.\r
1698\r
1699**/\r
95276127 1700EFI_STATUS\r
1701GetTextColors (\r
1702 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1703 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,\r
1704 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background\r
1705 )\r
1706{\r
1707 INTN Attribute;\r
1708\r
1709 Attribute = This->Mode->Attribute & 0x7F;\r
1710\r
1711 *Foreground = mEfiColors[Attribute & 0x0f];\r
1712 *Background = mEfiColors[Attribute >> 4];\r
1713\r
1714 return EFI_SUCCESS;\r
1715}\r
1716\r
24248368 1717/**\r
1718 Draw Unicode string on the Graphice Console device's screen.\r
1719\r
1720 @param This Protocol instance pointer.\r
1721 @param UnicodeWeight One Unicode string to be displayed.\r
1722 @param Count The count of Unicode string.\r
1723\r
1724 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.\r
1725 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw\r
1726 protocol exist.\r
1727 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.\r
1728\r
1729**/\r
93e3992d 1730EFI_STATUS\r
1731DrawUnicodeWeightAtCursorN (\r
1732 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
24248368 1733 IN CHAR16 *UnicodeWeight,\r
1734 IN UINTN Count\r
93e3992d 1735 )\r
1736{\r
1737 EFI_STATUS Status;\r
1738 GRAPHICS_CONSOLE_DEV *Private;\r
1739 EFI_IMAGE_OUTPUT *Blt;\r
1740 EFI_STRING String;\r
1741 EFI_FONT_DISPLAY_INFO *FontInfo;\r
d42d853e 1742 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1743 EFI_HII_ROW_INFO *RowInfoArray;\r
1744 UINTN RowInfoArraySize;\r
93e3992d 1745\r
1746 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
93e3992d 1747 Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
1748 if (Blt == NULL) {\r
1749 return EFI_OUT_OF_RESOURCES;\r
1750 }\r
1751\r
1752 Blt->Width = (UINT16) (Private->ModeData[This->Mode->Mode].GopWidth);\r
1753 Blt->Height = (UINT16) (Private->ModeData[This->Mode->Mode].GopHeight);\r
93e3992d 1754\r
1755 String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);\r
1756 if (String == NULL) {\r
1757 SafeFreePool (Blt);\r
1758 return EFI_OUT_OF_RESOURCES;\r
1759 }\r
8595bdaf 1760 //\r
1761 // Set the end character\r
1762 //\r
1763 *(String + Count) = L'\0';\r
93e3992d 1764\r
1765 FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
1766 if (FontInfo == NULL) {\r
1767 SafeFreePool (Blt);\r
1768 SafeFreePool (String);\r
1769 return EFI_OUT_OF_RESOURCES;\r
1770 }\r
8595bdaf 1771 //\r
1772 // Get current foreground and background colors.\r
1773 //\r
93e3992d 1774 GetTextColors (This, &FontInfo->ForegroundColor, &FontInfo->BackgroundColor);\r
1775\r
d42d853e 1776 if (Private->GraphicsOutput != NULL) {\r
8595bdaf 1777 //\r
1778 // If Graphcis Output protocol exists, using HII Font protocol to draw. \r
1779 //\r
d42d853e 1780 Blt->Image.Screen = Private->GraphicsOutput;\r
95276127 1781\r
d42d853e 1782 Status = mHiiFont->StringToImage (\r
1783 mHiiFont,\r
1784 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,\r
1785 String,\r
1786 FontInfo,\r
1787 &Blt,\r
0898c57c 1788 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
1789 This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
d42d853e 1790 NULL,\r
1791 NULL,\r
1792 NULL\r
1793 );\r
95276127 1794\r
8541adab 1795 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
8595bdaf 1796 //\r
1797 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled, \r
1798 // using UGA Draw protocol to draw.\r
1799 //\r
d42d853e 1800 ASSERT (Private->UgaDraw!= NULL);\r
95276127 1801\r
d42d853e 1802 UgaDraw = Private->UgaDraw;\r
95276127 1803\r
d42d853e 1804 Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
1805 if (Blt->Image.Bitmap == NULL) {\r
1806 SafeFreePool (Blt);\r
1807 SafeFreePool (String);\r
1808 return EFI_OUT_OF_RESOURCES;\r
95276127 1809 }\r
1810\r
d42d853e 1811 RowInfoArray = NULL;\r
1812 //\r
1813 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,\r
1814 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r
1815 //\r
1816 Status = mHiiFont->StringToImage (\r
1817 mHiiFont,\r
1818 EFI_HII_IGNORE_IF_NO_GLYPH,\r
1819 String,\r
1820 FontInfo,\r
1821 &Blt,\r
0898c57c 1822 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
1823 This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
d42d853e 1824 &RowInfoArray,\r
1825 &RowInfoArraySize,\r
1826 NULL\r
1827 );\r
95276127 1828\r
d42d853e 1829 if (!EFI_ERROR (Status)) {\r
95276127 1830 //\r
d42d853e 1831 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will\r
bd1d34ee 1832 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r
95276127 1833 //\r
bd1d34ee 1834 ASSERT (RowInfoArraySize <= 1);\r
8541adab 1835\r
d42d853e 1836 Status = UgaDraw->Blt (\r
1837 UgaDraw,\r
1838 (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
1839 EfiUgaBltBufferToVideo,\r
0898c57c 1840 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
1841 (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
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
d42d853e 1844 RowInfoArray[0].LineWidth,\r
1845 RowInfoArray[0].LineHeight,\r
1846 Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
1847 );\r
1848 }\r
95276127 1849\r
d42d853e 1850 SafeFreePool (RowInfoArray);\r
1851 SafeFreePool (Blt->Image.Bitmap);\r
8541adab 1852 } else {\r
1853 Status = EFI_UNSUPPORTED;\r
95276127 1854 }\r
1855\r
d42d853e 1856 SafeFreePool (Blt);\r
1857 SafeFreePool (String);\r
1858 SafeFreePool (FontInfo);\r
1859 return Status;\r
95276127 1860}\r
d42d853e 1861\r
24248368 1862/**\r
1863 Erase the cursor on the screen.\r
95276127 1864\r
24248368 1865 @param This Protocol instance pointer.\r
1866\r
1867 @retval EFI_SUCCESS The cursor is erased successfully.\r
1868\r
1869**/\r
95276127 1870EFI_STATUS\r
1871EraseCursor (\r
1872 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
1873 )\r
1874{\r
1875 GRAPHICS_CONSOLE_DEV *Private;\r
1876 EFI_SIMPLE_TEXT_OUTPUT_MODE *CurrentMode;\r
1877 INTN GlyphX;\r
1878 INTN GlyphY;\r
1879 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
1880 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1881 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground;\r
1882 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background;\r
0898c57c 1883 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[EFI_GLYPH_HEIGHT][EFI_GLYPH_WIDTH];\r
6dcf9abc 1884 UINTN PosX;\r
1885 UINTN PosY;\r
95276127 1886\r
1887 CurrentMode = This->Mode;\r
1888\r
1889 if (!CurrentMode->CursorVisible) {\r
1890 return EFI_SUCCESS;\r
1891 }\r
1892\r
1893 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1894 GraphicsOutput = Private->GraphicsOutput;\r
1895 UgaDraw = Private->UgaDraw;\r
1896\r
1897 //\r
24248368 1898 // In this driver, only narrow character was supported.\r
95276127 1899 //\r
1900 //\r
1901 // Blt a character to the screen\r
1902 //\r
0898c57c 1903 GlyphX = (CurrentMode->CursorColumn * EFI_GLYPH_WIDTH) + Private->ModeData[CurrentMode->Mode].DeltaX;\r
1904 GlyphY = (CurrentMode->CursorRow * EFI_GLYPH_HEIGHT) + Private->ModeData[CurrentMode->Mode].DeltaY;\r
95276127 1905 if (GraphicsOutput != NULL) {\r
1906 GraphicsOutput->Blt (\r
1907 GraphicsOutput,\r
1908 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
1909 EfiBltVideoToBltBuffer,\r
1910 GlyphX,\r
1911 GlyphY,\r
1912 0,\r
1913 0,\r
0898c57c 1914 EFI_GLYPH_WIDTH,\r
1915 EFI_GLYPH_HEIGHT,\r
1916 EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
95276127 1917 );\r
8541adab 1918 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1919 UgaDraw->Blt (\r
1920 UgaDraw,\r
1921 (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
1922 EfiUgaVideoToBltBuffer,\r
1923 GlyphX,\r
1924 GlyphY,\r
1925 0,\r
1926 0,\r
0898c57c 1927 EFI_GLYPH_WIDTH,\r
1928 EFI_GLYPH_HEIGHT,\r
1929 EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
95276127 1930 );\r
1931 }\r
1932\r
1933 GetTextColors (This, &Foreground.Pixel, &Background.Pixel);\r
1934\r
1935 //\r
1936 // Convert Monochrome bitmap of the Glyph to BltBuffer structure\r
1937 //\r
6dcf9abc 1938 for (PosY = 0; PosY < EFI_GLYPH_HEIGHT; PosY++) {\r
1939 for (PosX = 0; PosX < EFI_GLYPH_WIDTH; PosX++) {\r
1940 if ((mCursorGlyph.GlyphCol1[PosY] & (1 << PosX)) != 0) {\r
1941 BltChar[PosY][EFI_GLYPH_WIDTH - PosX - 1].Raw ^= Foreground.Raw;\r
95276127 1942 }\r
1943 }\r
1944 }\r
1945\r
1946 if (GraphicsOutput != NULL) {\r
1947 GraphicsOutput->Blt (\r
1948 GraphicsOutput,\r
1949 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
1950 EfiBltBufferToVideo,\r
1951 0,\r
1952 0,\r
1953 GlyphX,\r
1954 GlyphY,\r
0898c57c 1955 EFI_GLYPH_WIDTH,\r
1956 EFI_GLYPH_HEIGHT,\r
1957 EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
95276127 1958 );\r
8541adab 1959 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
95276127 1960 UgaDraw->Blt (\r
1961 UgaDraw,\r
1962 (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
1963 EfiUgaBltBufferToVideo,\r
1964 0,\r
1965 0,\r
1966 GlyphX,\r
1967 GlyphY,\r
0898c57c 1968 EFI_GLYPH_WIDTH,\r
1969 EFI_GLYPH_HEIGHT,\r
1970 EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
95276127 1971 );\r
1972 }\r
1973\r
1974 return EFI_SUCCESS;\r
1975}\r
97a079ed
A
1976\r
1977/**\r
1978 The user Entry Point for module GraphicsConsole. The user code starts with this function.\r
1979\r
8541adab 1980 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
97a079ed 1981 @param[in] SystemTable A pointer to the EFI System Table.\r
8541adab 1982\r
97a079ed
A
1983 @retval EFI_SUCCESS The entry point is executed successfully.\r
1984 @retval other Some error occurs when executing this entry point.\r
1985\r
1986**/\r
1987EFI_STATUS\r
1988EFIAPI\r
1989InitializeGraphicsConsole (\r
1990 IN EFI_HANDLE ImageHandle,\r
1991 IN EFI_SYSTEM_TABLE *SystemTable\r
1992 )\r
1993{\r
1994 EFI_STATUS Status;\r
1995\r
1996 //\r
1997 // Install driver model protocol(s).\r
1998 //\r
5bca971e 1999 Status = EfiLibInstallDriverBindingComponentName2 (\r
97a079ed
A
2000 ImageHandle,\r
2001 SystemTable,\r
2002 &gGraphicsConsoleDriverBinding,\r
2003 ImageHandle,\r
2004 &gGraphicsConsoleComponentName,\r
5bca971e 2005 &gGraphicsConsoleComponentName2\r
97a079ed
A
2006 );\r
2007 ASSERT_EFI_ERROR (Status);\r
2008\r
2009\r
2010 return Status;\r
2011}\r
2012\r
d42d853e 2013\r