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