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