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