]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Console/GraphicsConsole/Dxe/GraphicsConsole.c
40e89a91702617b81286e1fc9d675e3e96ed6d31
[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 ((Info->PixelFormat == PixelRedGreenBlueReserved8BitPerColor) ||
383 (Info->PixelFormat == PixelBlueGreenRedReserved8BitPerColor))) {
384 Status = Private->GraphicsOutput->SetMode (Private->GraphicsOutput, ModeNumber);
385 if (!EFI_ERROR (Status)) {
386 gBS->FreePool (Info);
387 break;
388 }
389 }
390 gBS->FreePool (Info);
391 }
392 }
393
394 if (EFI_ERROR (Status) || (ModeNumber == Private->GraphicsOutput->Mode->MaxMode)) {
395 //
396 // Set default mode failed or device don't support default mode, then get the current mode information
397 //
398 HorizontalResolution = Private->GraphicsOutput->Mode->Info->HorizontalResolution;
399 VerticalResolution = Private->GraphicsOutput->Mode->Info->VerticalResolution;
400 ModeNumber = Private->GraphicsOutput->Mode->Mode;
401 }
402 } else {
403 //
404 // The console is build on top of UGA Draw Protocol
405 //
406 ColorDepth = 32;
407 RefreshRate = 60;
408 Status = Private->UgaDraw->SetMode (
409 Private->UgaDraw,
410 HorizontalResolution,
411 VerticalResolution,
412 ColorDepth,
413 RefreshRate
414 );
415 if (EFI_ERROR (Status)) {
416 //
417 // Get the current mode information from the UGA Draw Protocol
418 //
419 Status = Private->UgaDraw->GetMode (
420 Private->UgaDraw,
421 &HorizontalResolution,
422 &VerticalResolution,
423 &ColorDepth,
424 &RefreshRate
425 );
426 if (EFI_ERROR (Status)) {
427 goto Error;
428 }
429 }
430 }
431
432 //
433 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
434 //
435 Columns = HorizontalResolution / GLYPH_WIDTH;
436 Rows = VerticalResolution / GLYPH_HEIGHT;
437
438 //
439 // See if the mode is too small to support the required 80x25 text mode
440 //
441 if (Columns < 80 || Rows < 25) {
442 goto Error;
443 }
444 //
445 // Add Mode #0 that must be 80x25
446 //
447 MaxMode = 0;
448 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
449 Private->ModeData[MaxMode].GopHeight = VerticalResolution;
450 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
451 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * GLYPH_WIDTH)) >> 1;
452 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (25 * GLYPH_HEIGHT)) >> 1;
453 MaxMode++;
454
455 //
456 // If it is possible to support Mode #1 - 80x50, than add it as an active mode
457 //
458 if (Rows >= 50) {
459 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
460 Private->ModeData[MaxMode].GopHeight = VerticalResolution;
461 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
462 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * GLYPH_WIDTH)) >> 1;
463 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (50 * GLYPH_HEIGHT)) >> 1;
464 MaxMode++;
465 }
466 //
467 // If the graphics mode is 800x600, than add a text mode that uses the entire display
468 //
469 if (HorizontalResolution == 800 && VerticalResolution == 600) {
470
471 if (MaxMode < 2) {
472 Private->ModeData[MaxMode].Columns = 0;
473 Private->ModeData[MaxMode].Rows = 0;
474 Private->ModeData[MaxMode].GopWidth = 800;
475 Private->ModeData[MaxMode].GopHeight = 600;
476 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
477 Private->ModeData[MaxMode].DeltaX = 0;
478 Private->ModeData[MaxMode].DeltaY = 0;
479 MaxMode++;
480 }
481
482 Private->ModeData[MaxMode].Columns = 800 / GLYPH_WIDTH;
483 Private->ModeData[MaxMode].Rows = 600 / GLYPH_HEIGHT;
484 Private->ModeData[MaxMode].GopWidth = 800;
485 Private->ModeData[MaxMode].GopHeight = 600;
486 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
487 Private->ModeData[MaxMode].DeltaX = (800 % GLYPH_WIDTH) >> 1;
488 Private->ModeData[MaxMode].DeltaY = (600 % GLYPH_HEIGHT) >> 1;
489 MaxMode++;
490 }
491 //
492 // Update the maximum number of modes
493 //
494 Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;
495
496 //
497 // Determine the number of text modes that this protocol can support
498 //
499 Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);
500 if (EFI_ERROR (Status)) {
501 goto Error;
502 }
503
504 DEBUG_CODE_BEGIN ();
505 GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");
506 DEBUG_CODE_END ();
507
508 //
509 // Install protocol interfaces for the Graphics Console device.
510 //
511 Status = gBS->InstallMultipleProtocolInterfaces (
512 &Controller,
513 &gEfiSimpleTextOutProtocolGuid,
514 &Private->SimpleTextOutput,
515 NULL
516 );
517
518 Error:
519 if (EFI_ERROR (Status)) {
520 //
521 // Close the GOP or UGA IO Protocol
522 //
523 if (Private->GraphicsOutput != NULL) {
524 gBS->CloseProtocol (
525 Controller,
526 &gEfiGraphicsOutputProtocolGuid,
527 This->DriverBindingHandle,
528 Controller
529 );
530 } else {
531 gBS->CloseProtocol (
532 Controller,
533 &gEfiUgaDrawProtocolGuid,
534 This->DriverBindingHandle,
535 Controller
536 );
537 }
538
539 //
540 // Free private data
541 //
542 if (Private != NULL) {
543 gBS->FreePool (Private->LineBuffer);
544 gBS->FreePool (Private);
545 }
546 }
547
548 return Status;
549 }
550
551 EFI_STATUS
552 EFIAPI
553 GraphicsConsoleControllerDriverStop (
554 IN EFI_DRIVER_BINDING_PROTOCOL *This,
555 IN EFI_HANDLE Controller,
556 IN UINTN NumberOfChildren,
557 IN EFI_HANDLE *ChildHandleBuffer
558 )
559 {
560 EFI_STATUS Status;
561 EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOutput;
562 GRAPHICS_CONSOLE_DEV *Private;
563
564 Status = gBS->OpenProtocol (
565 Controller,
566 &gEfiSimpleTextOutProtocolGuid,
567 (VOID **) &SimpleTextOutput,
568 This->DriverBindingHandle,
569 Controller,
570 EFI_OPEN_PROTOCOL_GET_PROTOCOL
571 );
572 if (EFI_ERROR (Status)) {
573 return EFI_NOT_STARTED;
574 }
575
576 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput);
577
578 Status = gBS->UninstallProtocolInterface (
579 Controller,
580 &gEfiSimpleTextOutProtocolGuid,
581 &Private->SimpleTextOutput
582 );
583
584 if (!EFI_ERROR (Status)) {
585 //
586 // Close the GOP or UGA IO Protocol
587 //
588 if (Private->GraphicsOutput != NULL) {
589 gBS->CloseProtocol (
590 Controller,
591 &gEfiGraphicsOutputProtocolGuid,
592 This->DriverBindingHandle,
593 Controller
594 );
595 } else {
596 gBS->CloseProtocol (
597 Controller,
598 &gEfiUgaDrawProtocolGuid,
599 This->DriverBindingHandle,
600 Controller
601 );
602 }
603
604 //
605 // Remove the font pack
606 //
607 mHii->RemovePack (mHii, Private->HiiHandle);
608
609 //
610 // Free our instance data
611 //
612 if (Private != NULL) {
613 gBS->FreePool (Private->LineBuffer);
614 gBS->FreePool (Private);
615 }
616 }
617
618 return Status;
619 }
620
621 EFI_STATUS
622 EfiLocateHiiProtocol (
623 VOID
624 )
625 /*++
626
627 Routine Description:
628 Find if the HII protocol is available. If yes, locate the HII protocol
629
630 Arguments:
631
632 Returns:
633
634 --*/
635 {
636 EFI_HANDLE Handle;
637 UINTN Size;
638 EFI_STATUS Status;
639
640 //
641 // There should only be one - so buffer size is this
642 //
643 Size = sizeof (EFI_HANDLE);
644
645 Status = gBS->LocateHandle (
646 ByProtocol,
647 &gEfiHiiProtocolGuid,
648 NULL,
649 &Size,
650 &Handle
651 );
652
653 if (EFI_ERROR (Status)) {
654 return Status;
655 }
656
657 Status = gBS->HandleProtocol (
658 Handle,
659 &gEfiHiiProtocolGuid,
660 (VOID **)&mHii
661 );
662
663 return Status;
664 }
665 //
666 // Body of the STO functions
667 //
668 EFI_STATUS
669 EFIAPI
670 GraphicsConsoleConOutReset (
671 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
672 IN BOOLEAN ExtendedVerification
673 )
674 /*++
675 Routine Description:
676
677 Implements SIMPLE_TEXT_OUTPUT.Reset().
678 If ExtendeVerification is TRUE, then perform dependent Graphics Console
679 device reset, and set display mode to mode 0.
680 If ExtendedVerification is FALSE, only set display mode to mode 0.
681
682 Arguments:
683
684 This - Indicates the calling context.
685
686 ExtendedVerification - Indicates that the driver may perform a more exhaustive
687 verification operation of the device during reset.
688
689 Returns:
690
691 EFI_SUCCESS
692 The reset operation succeeds.
693
694 EFI_DEVICE_ERROR
695 The Graphics Console is not functioning correctly
696
697 --*/
698 {
699 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
700 return This->SetMode (This, 0);
701 }
702
703 EFI_STATUS
704 EFIAPI
705 GraphicsConsoleConOutOutputString (
706 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
707 IN CHAR16 *WString
708 )
709 /*++
710 Routine Description:
711
712 Implements SIMPLE_TEXT_OUTPUT.OutputString().
713 The Unicode string will be converted to Glyphs and will be
714 sent to the Graphics Console.
715
716
717 Arguments:
718
719 This - Indicates the calling context.
720
721 WString - The Null-terminated Unicode string to be displayed on
722 the Graphics Console.
723
724 Returns:
725
726 EFI_SUCCESS
727 The string is output successfully.
728
729 EFI_DEVICE_ERROR
730 The Graphics Console failed to send the string out.
731
732 EFI_WARN_UNKNOWN_GLYPH
733 Indicates that some of the characters in the Unicode string could not
734 be rendered and are skipped.
735
736 --*/
737 {
738 GRAPHICS_CONSOLE_DEV *Private;
739 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
740 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
741 INTN Mode;
742 UINTN MaxColumn;
743 UINTN MaxRow;
744 UINTN Width;
745 UINTN Height;
746 UINTN Delta;
747 EFI_STATUS Status;
748 BOOLEAN Warning;
749 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
750 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
751 UINTN DeltaX;
752 UINTN DeltaY;
753 UINTN Count;
754 UINTN Index;
755 INT32 OriginAttribute;
756 CHAR16 SpaceStr[] = { NARROW_CHAR, ' ', 0 };
757
758 //
759 // Current mode
760 //
761 Mode = This->Mode->Mode;
762 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
763 GraphicsOutput = Private->GraphicsOutput;
764 UgaDraw = Private->UgaDraw;
765
766 MaxColumn = Private->ModeData[Mode].Columns;
767 MaxRow = Private->ModeData[Mode].Rows;
768 DeltaX = Private->ModeData[Mode].DeltaX;
769 DeltaY = Private->ModeData[Mode].DeltaY;
770 Width = MaxColumn * GLYPH_WIDTH;
771 Height = (MaxRow - 1) * GLYPH_HEIGHT;
772 Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
773
774 //
775 // The Attributes won't change when during the time OutputString is called
776 //
777 GetTextColors (This, &Foreground, &Background);
778
779 EraseCursor (This);
780
781 Warning = FALSE;
782
783 //
784 // Backup attribute
785 //
786 OriginAttribute = This->Mode->Attribute;
787
788 while (*WString) {
789
790 if (*WString == CHAR_BACKSPACE) {
791 //
792 // If the cursor is at the left edge of the display, then move the cursor
793 // one row up.
794 //
795 if (This->Mode->CursorColumn == 0 && This->Mode->CursorRow > 0) {
796 This->Mode->CursorRow--;
797 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);
798 This->OutputString (This, SpaceStr);
799 EraseCursor (This);
800 This->Mode->CursorRow--;
801 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);
802 } else if (This->Mode->CursorColumn > 0) {
803 //
804 // If the cursor is not at the left edge of the display, then move the cursor
805 // left one column.
806 //
807 This->Mode->CursorColumn--;
808 This->OutputString (This, SpaceStr);
809 EraseCursor (This);
810 This->Mode->CursorColumn--;
811 }
812
813 WString++;
814
815 } else if (*WString == CHAR_LINEFEED) {
816 //
817 // If the cursor is at the bottom of the display, then scroll the display one
818 // row, and do not update the cursor position. Otherwise, move the cursor
819 // down one row.
820 //
821 if (This->Mode->CursorRow == (INT32) (MaxRow - 1)) {
822 if (GraphicsOutput != NULL) {
823 //
824 // Scroll Screen Up One Row
825 //
826 GraphicsOutput->Blt (
827 GraphicsOutput,
828 NULL,
829 EfiBltVideoToVideo,
830 DeltaX,
831 DeltaY + GLYPH_HEIGHT,
832 DeltaX,
833 DeltaY,
834 Width,
835 Height,
836 Delta
837 );
838
839 //
840 // Print Blank Line at last line
841 //
842 GraphicsOutput->Blt (
843 GraphicsOutput,
844 &Background,
845 EfiBltVideoFill,
846 0,
847 0,
848 DeltaX,
849 DeltaY + Height,
850 Width,
851 GLYPH_HEIGHT,
852 Delta
853 );
854 } else {
855 //
856 // Scroll Screen Up One Row
857 //
858 UgaDraw->Blt (
859 UgaDraw,
860 NULL,
861 EfiUgaVideoToVideo,
862 DeltaX,
863 DeltaY + GLYPH_HEIGHT,
864 DeltaX,
865 DeltaY,
866 Width,
867 Height,
868 Delta
869 );
870
871 //
872 // Print Blank Line at last line
873 //
874 UgaDraw->Blt (
875 UgaDraw,
876 (EFI_UGA_PIXEL *) (UINTN) &Background,
877 EfiUgaVideoFill,
878 0,
879 0,
880 DeltaX,
881 DeltaY + Height,
882 Width,
883 GLYPH_HEIGHT,
884 Delta
885 );
886 }
887 } else {
888 This->Mode->CursorRow++;
889 }
890
891 WString++;
892
893 } else if (*WString == CHAR_CARRIAGE_RETURN) {
894 //
895 // Move the cursor to the beginning of the current row.
896 //
897 This->Mode->CursorColumn = 0;
898 WString++;
899
900 } else if (*WString == WIDE_CHAR) {
901
902 This->Mode->Attribute |= EFI_WIDE_ATTRIBUTE;
903 WString++;
904
905 } else if (*WString == NARROW_CHAR) {
906
907 This->Mode->Attribute &= (~ (UINT32) EFI_WIDE_ATTRIBUTE);
908 WString++;
909
910 } else {
911 //
912 // Print the character at the current cursor position and move the cursor
913 // right one column. If this moves the cursor past the right edge of the
914 // display, then the line should wrap to the beginning of the next line. This
915 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
916 // bottom of the display, and the line wraps, then the display will be scrolled
917 // one line.
918 // If wide char is going to be displayed, need to display one character at a time
919 // Or, need to know the display length of a certain string.
920 //
921 // Index is used to determine how many character width units (wide = 2, narrow = 1)
922 // Count is used to determine how many characters are used regardless of their attributes
923 //
924 for (Count = 0, Index = 0; (This->Mode->CursorColumn + Index) < MaxColumn; Count++, Index++) {
925 if (WString[Count] == CHAR_NULL) {
926 break;
927 }
928
929 if (WString[Count] == CHAR_BACKSPACE) {
930 break;
931 }
932
933 if (WString[Count] == CHAR_LINEFEED) {
934 break;
935 }
936
937 if (WString[Count] == CHAR_CARRIAGE_RETURN) {
938 break;
939 }
940
941 if (WString[Count] == WIDE_CHAR) {
942 break;
943 }
944
945 if (WString[Count] == NARROW_CHAR) {
946 break;
947 }
948 //
949 // Is the wide attribute on?
950 //
951 if (This->Mode->Attribute & EFI_WIDE_ATTRIBUTE) {
952 //
953 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
954 //
955 Index++;
956 //
957 // This is the end-case where if we are at column 79 and about to print a wide character
958 // We should prevent this from happening because we will wrap inappropriately. We should
959 // not print this character until the next line.
960 //
961 if ((This->Mode->CursorColumn + Index + 1) > MaxColumn) {
962 Index++;
963 break;
964 }
965 }
966 }
967
968 Status = DrawUnicodeWeightAtCursorN (This, WString, Count);
969 if (EFI_ERROR (Status)) {
970 Warning = TRUE;
971 }
972 //
973 // At the end of line, output carriage return and line feed
974 //
975 WString += Count;
976 This->Mode->CursorColumn += (INT32) Index;
977 if (This->Mode->CursorColumn > (INT32) MaxColumn) {
978 This->Mode->CursorColumn -= 2;
979 This->OutputString (This, SpaceStr);
980 }
981
982 if (This->Mode->CursorColumn >= (INT32) MaxColumn) {
983 EraseCursor (This);
984 This->OutputString (This, mCrLfString);
985 EraseCursor (This);
986 }
987 }
988 }
989
990 This->Mode->Attribute = OriginAttribute;
991
992 EraseCursor (This);
993
994 if (Warning) {
995 return EFI_WARN_UNKNOWN_GLYPH;
996 }
997
998 return EFI_SUCCESS;
999 }
1000
1001 EFI_STATUS
1002 EFIAPI
1003 GraphicsConsoleConOutTestString (
1004 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1005 IN CHAR16 *WString
1006 )
1007 /*++
1008 Routine Description:
1009
1010 Implements SIMPLE_TEXT_OUTPUT.TestString().
1011 If one of the characters in the *Wstring is
1012 neither valid valid Unicode drawing characters,
1013 not ASCII code, then this function will return
1014 EFI_UNSUPPORTED.
1015
1016
1017 Arguments:
1018
1019 This - Indicates the calling context.
1020
1021 WString - The Null-terminated Unicode string to be tested.
1022
1023 Returns:
1024
1025 EFI_SUCCESS
1026 The Graphics Console is capable of rendering the output string.
1027
1028 EFI_UNSUPPORTED
1029 Some of the characters in the Unicode string cannot be rendered.
1030
1031 --*/
1032 {
1033 EFI_STATUS Status;
1034 UINT16 GlyphWidth;
1035 UINT32 GlyphStatus;
1036 UINT16 Count;
1037 GRAPHICS_CONSOLE_DEV *Private;
1038 GLYPH_UNION *Glyph;
1039
1040 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1041 GlyphStatus = 0;
1042 Count = 0;
1043
1044 while (WString[Count]) {
1045 Status = mHii->GetGlyph (
1046 mHii,
1047 WString,
1048 &Count,
1049 (UINT8 **) &Glyph,
1050 &GlyphWidth,
1051 &GlyphStatus
1052 );
1053
1054 if (EFI_ERROR (Status)) {
1055 return EFI_UNSUPPORTED;
1056 }
1057 }
1058
1059 return EFI_SUCCESS;
1060 }
1061
1062 EFI_STATUS
1063 EFIAPI
1064 GraphicsConsoleConOutQueryMode (
1065 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1066 IN UINTN ModeNumber,
1067 OUT UINTN *Columns,
1068 OUT UINTN *Rows
1069 )
1070 /*++
1071 Routine Description:
1072
1073 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1074 It returnes information for an available text mode
1075 that the Graphics Console supports.
1076 In this driver,we only support text mode 80x25, which is
1077 defined as mode 0.
1078
1079
1080 Arguments:
1081
1082 This - Indicates the calling context.
1083
1084 ModeNumber - The mode number to return information on.
1085
1086 Columns - The returned columns of the requested mode.
1087
1088 Rows - The returned rows of the requested mode.
1089
1090 Returns:
1091
1092 EFI_SUCCESS
1093 The requested mode information is returned.
1094
1095 EFI_UNSUPPORTED
1096 The mode number is not valid.
1097
1098 --*/
1099 {
1100 GRAPHICS_CONSOLE_DEV *Private;
1101
1102 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {
1103 return EFI_UNSUPPORTED;
1104 }
1105
1106 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1107
1108 *Columns = Private->ModeData[ModeNumber].Columns;
1109 *Rows = Private->ModeData[ModeNumber].Rows;
1110
1111 if (*Columns <= 0 && *Rows <= 0) {
1112 return EFI_UNSUPPORTED;
1113
1114 }
1115
1116 return EFI_SUCCESS;
1117 }
1118
1119 EFI_STATUS
1120 EFIAPI
1121 GraphicsConsoleConOutSetMode (
1122 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1123 IN UINTN ModeNumber
1124 )
1125 /*++
1126 Routine Description:
1127
1128 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1129 Set the Graphics Console to a specified mode.
1130 In this driver, we only support mode 0.
1131
1132 Arguments:
1133
1134 This - Indicates the calling context.
1135
1136 ModeNumber - The text mode to set.
1137
1138 Returns:
1139
1140 EFI_SUCCESS
1141 The requested text mode is set.
1142
1143 EFI_DEVICE_ERROR
1144 The requested text mode cannot be set because of Graphics Console device error.
1145
1146 EFI_UNSUPPORTED
1147 The text mode number is not valid.
1148
1149 --*/
1150 {
1151 EFI_STATUS Status;
1152 GRAPHICS_CONSOLE_DEV *Private;
1153 GRAPHICS_CONSOLE_MODE_DATA *ModeData;
1154 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *NewLineBuffer;
1155 UINT32 HorizontalResolution;
1156 UINT32 VerticalResolution;
1157 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1158 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1159 UINT32 ColorDepth;
1160 UINT32 RefreshRate;
1161
1162 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1163 GraphicsOutput = Private->GraphicsOutput;
1164 UgaDraw = Private->UgaDraw;
1165 ModeData = &(Private->ModeData[ModeNumber]);
1166
1167 //
1168 // Make sure the requested mode number is supported
1169 //
1170 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {
1171 return EFI_UNSUPPORTED;
1172 }
1173
1174 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {
1175 return EFI_UNSUPPORTED;
1176 }
1177 //
1178 // Attempt to allocate a line buffer for the requested mode number
1179 //
1180 Status = gBS->AllocatePool (
1181 EfiBootServicesData,
1182 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * GLYPH_WIDTH * GLYPH_HEIGHT,
1183 (VOID **) &NewLineBuffer
1184 );
1185 if (EFI_ERROR (Status)) {
1186 //
1187 // The new line buffer could not be allocated, so return an error.
1188 // No changes to the state of the current console have been made, so the current console is still valid
1189 //
1190 return Status;
1191 }
1192 //
1193 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1194 //
1195 if (Private->LineBuffer != NULL) {
1196 //
1197 // Clear the current text window on the current graphics console
1198 //
1199 This->ClearScreen (This);
1200
1201 //
1202 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1203 //
1204 if ((INT32) ModeNumber == This->Mode->Mode) {
1205 gBS->FreePool (NewLineBuffer);
1206 return EFI_SUCCESS;
1207 }
1208 //
1209 // Otherwise, the size of the text console and/or the UGA mode will be changed,
1210 // so turn off the cursor, and free the LineBuffer for the current mode
1211 //
1212 This->EnableCursor (This, FALSE);
1213
1214 gBS->FreePool (Private->LineBuffer);
1215 }
1216 //
1217 // Assign the current line buffer to the newly allocated line buffer
1218 //
1219 Private->LineBuffer = NewLineBuffer;
1220
1221 if (GraphicsOutput != NULL) {
1222 if (ModeData->GopModeNumber != GraphicsOutput->Mode->Mode) {
1223 //
1224 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode
1225 //
1226 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeData->GopModeNumber);
1227 if (EFI_ERROR (Status)) {
1228 //
1229 // The mode set operation failed
1230 //
1231 return Status;
1232 }
1233 } else {
1234 //
1235 // The current graphics mode is correct, so simply clear the entire display
1236 //
1237 Status = GraphicsOutput->Blt (
1238 GraphicsOutput,
1239 &mEfiColors[0],
1240 EfiBltVideoFill,
1241 0,
1242 0,
1243 0,
1244 0,
1245 ModeData->GopWidth,
1246 ModeData->GopHeight,
1247 0
1248 );
1249 }
1250 } else {
1251 //
1252 // Get the current UGA Draw mode information
1253 //
1254 Status = UgaDraw->GetMode (
1255 UgaDraw,
1256 &HorizontalResolution,
1257 &VerticalResolution,
1258 &ColorDepth,
1259 &RefreshRate
1260 );
1261 if (EFI_ERROR (Status) || HorizontalResolution != ModeData->GopWidth || VerticalResolution != ModeData->GopHeight) {
1262 //
1263 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode
1264 //
1265 Status = UgaDraw->SetMode (
1266 UgaDraw,
1267 ModeData->GopWidth,
1268 ModeData->GopHeight,
1269 32,
1270 60
1271 );
1272 if (EFI_ERROR (Status)) {
1273 //
1274 // The mode set operation failed
1275 //
1276 return Status;
1277 }
1278 } else {
1279 //
1280 // The current graphics mode is correct, so simply clear the entire display
1281 //
1282 Status = UgaDraw->Blt (
1283 UgaDraw,
1284 (EFI_UGA_PIXEL *) (UINTN) &mEfiColors[0],
1285 EfiUgaVideoFill,
1286 0,
1287 0,
1288 0,
1289 0,
1290 ModeData->GopWidth,
1291 ModeData->GopHeight,
1292 0
1293 );
1294 }
1295 }
1296
1297 //
1298 // The new mode is valid, so commit the mode change
1299 //
1300 This->Mode->Mode = (INT32) ModeNumber;
1301
1302 //
1303 // Move the text cursor to the upper left hand corner of the displat and enable it
1304 //
1305 This->SetCursorPosition (This, 0, 0);
1306 This->EnableCursor (This, TRUE);
1307
1308 return EFI_SUCCESS;
1309 }
1310
1311 EFI_STATUS
1312 EFIAPI
1313 GraphicsConsoleConOutSetAttribute (
1314 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1315 IN UINTN Attribute
1316 )
1317 /*++
1318 Routine Description:
1319
1320 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1321
1322 Arguments:
1323
1324 This - Indicates the calling context.
1325
1326 Attrubute - The attribute to set. Only bit0..6 are valid, all other bits
1327 are undefined and must be zero.
1328
1329 Returns:
1330
1331 EFI_SUCCESS
1332 The requested attribute is set.
1333
1334 EFI_DEVICE_ERROR
1335 The requested attribute cannot be set due to Graphics Console port error.
1336
1337 EFI_UNSUPPORTED
1338 The attribute requested is not defined by EFI spec.
1339
1340 --*/
1341 {
1342 if ((Attribute | 0xFF) != 0xFF) {
1343 return EFI_UNSUPPORTED;
1344 }
1345
1346 if ((INT32) Attribute == This->Mode->Attribute) {
1347 return EFI_SUCCESS;
1348 }
1349
1350 EraseCursor (This);
1351
1352 This->Mode->Attribute = (INT32) Attribute;
1353
1354 EraseCursor (This);
1355
1356 return EFI_SUCCESS;
1357 }
1358
1359 EFI_STATUS
1360 EFIAPI
1361 GraphicsConsoleConOutClearScreen (
1362 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This
1363 )
1364 /*++
1365 Routine Description:
1366
1367 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1368 It clears the Graphics Console's display to the
1369 currently selected background color.
1370
1371
1372 Arguments:
1373
1374 This - Indicates the calling context.
1375
1376 Returns:
1377
1378 EFI_SUCCESS
1379 The operation completed successfully.
1380
1381 EFI_DEVICE_ERROR
1382 The Graphics Console cannot be cleared due to Graphics Console device error.
1383
1384 EFI_UNSUPPORTED
1385 The Graphics Console is not in a valid text mode.
1386
1387 --*/
1388 {
1389 EFI_STATUS Status;
1390 GRAPHICS_CONSOLE_DEV *Private;
1391 GRAPHICS_CONSOLE_MODE_DATA *ModeData;
1392 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1393 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1394 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
1395 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
1396
1397 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1398 GraphicsOutput = Private->GraphicsOutput;
1399 UgaDraw = Private->UgaDraw;
1400 ModeData = &(Private->ModeData[This->Mode->Mode]);
1401
1402 GetTextColors (This, &Foreground, &Background);
1403 if (GraphicsOutput != NULL) {
1404 Status = GraphicsOutput->Blt (
1405 GraphicsOutput,
1406 &Background,
1407 EfiBltVideoFill,
1408 0,
1409 0,
1410 0,
1411 0,
1412 ModeData->GopWidth,
1413 ModeData->GopHeight,
1414 0
1415 );
1416 } else {
1417 Status = UgaDraw->Blt (
1418 UgaDraw,
1419 (EFI_UGA_PIXEL *) (UINTN) &Background,
1420 EfiUgaVideoFill,
1421 0,
1422 0,
1423 0,
1424 0,
1425 ModeData->GopWidth,
1426 ModeData->GopHeight,
1427 0
1428 );
1429 }
1430
1431 This->Mode->CursorColumn = 0;
1432 This->Mode->CursorRow = 0;
1433
1434 EraseCursor (This);
1435
1436 return Status;
1437 }
1438
1439 EFI_STATUS
1440 EFIAPI
1441 GraphicsConsoleConOutSetCursorPosition (
1442 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1443 IN UINTN Column,
1444 IN UINTN Row
1445 )
1446 /*++
1447 Routine Description:
1448
1449 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1450
1451 Arguments:
1452
1453 This - Indicates the calling context.
1454
1455 Column - The row to set cursor to.
1456
1457 Row - The column to set cursor to.
1458
1459 Returns:
1460
1461 EFI_SUCCESS
1462 The operation completed successfully.
1463
1464 EFI_DEVICE_ERROR
1465 The request fails due to Graphics Console device error.
1466
1467 EFI_UNSUPPORTED
1468 The Graphics Console is not in a valid text mode, or the cursor position
1469 is invalid for current mode.
1470
1471 --*/
1472 {
1473 GRAPHICS_CONSOLE_DEV *Private;
1474 GRAPHICS_CONSOLE_MODE_DATA *ModeData;
1475
1476 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1477 ModeData = &(Private->ModeData[This->Mode->Mode]);
1478
1479 if ((Column >= ModeData->Columns) || (Row >= ModeData->Rows)) {
1480 return EFI_UNSUPPORTED;
1481 }
1482
1483 if (((INT32) Column == This->Mode->CursorColumn) && ((INT32) Row == This->Mode->CursorRow)) {
1484 return EFI_SUCCESS;
1485 }
1486
1487 EraseCursor (This);
1488
1489 This->Mode->CursorColumn = (INT32) Column;
1490 This->Mode->CursorRow = (INT32) Row;
1491
1492 EraseCursor (This);
1493
1494 return EFI_SUCCESS;
1495 }
1496
1497 EFI_STATUS
1498 EFIAPI
1499 GraphicsConsoleConOutEnableCursor (
1500 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1501 IN BOOLEAN Visible
1502 )
1503 /*++
1504 Routine Description:
1505
1506 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1507 In this driver, the cursor cannot be hidden.
1508
1509 Arguments:
1510
1511 This - Indicates the calling context.
1512
1513 Visible - If TRUE, the cursor is set to be visible,
1514 If FALSE, the cursor is set to be invisible.
1515
1516 Returns:
1517
1518 EFI_SUCCESS
1519 The request is valid.
1520
1521 EFI_UNSUPPORTED
1522 The Graphics Console does not support a hidden cursor.
1523
1524 --*/
1525 {
1526 EraseCursor (This);
1527
1528 This->Mode->CursorVisible = Visible;
1529
1530 EraseCursor (This);
1531
1532 return EFI_SUCCESS;
1533 }
1534
1535 EFI_STATUS
1536 GetTextColors (
1537 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1538 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
1539 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background
1540 )
1541 {
1542 INTN Attribute;
1543
1544 Attribute = This->Mode->Attribute & 0x7F;
1545
1546 *Foreground = mEfiColors[Attribute & 0x0f];
1547 *Background = mEfiColors[Attribute >> 4];
1548
1549 return EFI_SUCCESS;
1550 }
1551
1552 EFI_STATUS
1553 DrawUnicodeWeightAtCursorN (
1554 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
1555 IN CHAR16 *UnicodeWeight,
1556 IN UINTN Count
1557 )
1558 {
1559 GRAPHICS_CONSOLE_DEV *Private;
1560 EFI_STATUS Status;
1561 EFI_STATUS ReturnStatus;
1562 GLYPH_UNION *Glyph;
1563 GLYPH_UNION GlyphData;
1564 INTN GlyphX;
1565 INTN GlyphY;
1566 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1567 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1568 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
1569 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
1570 UINTN Index;
1571 UINTN ArrayIndex;
1572 UINTN Counts;
1573 UINT16 GlyphWidth;
1574 UINT32 GlyphStatus;
1575
1576 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1577
1578 ReturnStatus = EFI_SUCCESS;
1579 GlyphStatus = 0;
1580 GlyphWidth = 0x08;
1581
1582 GetTextColors (This, &Foreground, &Background);
1583
1584 Index = 0;
1585 ArrayIndex = 0;
1586 while (Index < Count) {
1587 if (This->Mode->Attribute & EFI_WIDE_ATTRIBUTE) {
1588 GlyphStatus = WIDE_CHAR;
1589 } else {
1590 GlyphStatus = NARROW_CHAR;
1591 }
1592
1593 Status = mHii->GetGlyph (
1594 mHii,
1595 UnicodeWeight,
1596 (UINT16 *) &Index,
1597 (UINT8 **) &Glyph,
1598 &GlyphWidth,
1599 &GlyphStatus
1600 );
1601 if (EFI_ERROR (Status)) {
1602 ReturnStatus = Status;
1603 }
1604
1605 Counts = 0;
1606
1607 CopyMem (&GlyphData, Glyph, sizeof (GLYPH_UNION));
1608
1609 do {
1610 //
1611 // We are creating the second half of the wide character's BLT buffer
1612 //
1613 if (GlyphWidth == 0x10 && Counts == 1) {
1614 CopyMem (&GlyphData.NarrowGlyph.GlyphCol1, &Glyph->WideGlyph.GlyphCol2, sizeof (Glyph->WideGlyph.GlyphCol2));
1615 }
1616
1617 Counts++;
1618
1619 if (GlyphWidth == 0x10) {
1620 mHii->GlyphToBlt (
1621 mHii,
1622 (UINT8 *) &GlyphData,
1623 Foreground,
1624 Background,
1625 Count * 2,
1626 GLYPH_WIDTH,
1627 GLYPH_HEIGHT,
1628 &Private->LineBuffer[ArrayIndex * GLYPH_WIDTH]
1629 );
1630 } else {
1631 mHii->GlyphToBlt (
1632 mHii,
1633 (UINT8 *) &GlyphData,
1634 Foreground,
1635 Background,
1636 Count,
1637 GLYPH_WIDTH,
1638 GLYPH_HEIGHT,
1639 &Private->LineBuffer[ArrayIndex * GLYPH_WIDTH]
1640 );
1641 }
1642
1643 ArrayIndex++;
1644
1645 } while (Counts < 2 && GlyphWidth == 0x10);
1646
1647 }
1648 //
1649 // If we are printing Wide characters, treat the BLT as if it is twice as many characters
1650 //
1651 if (GlyphWidth == 0x10) {
1652 Count = Count * 2;
1653 }
1654 //
1655 // Blt a character to the screen
1656 //
1657 GlyphX = This->Mode->CursorColumn * GLYPH_WIDTH;
1658 GlyphY = This->Mode->CursorRow * GLYPH_HEIGHT;
1659 GraphicsOutput = Private->GraphicsOutput;
1660 UgaDraw = Private->UgaDraw;
1661 if (GraphicsOutput != NULL) {
1662 GraphicsOutput->Blt (
1663 GraphicsOutput,
1664 Private->LineBuffer,
1665 EfiBltBufferToVideo,
1666 0,
1667 0,
1668 GlyphX + Private->ModeData[This->Mode->Mode].DeltaX,
1669 GlyphY + Private->ModeData[This->Mode->Mode].DeltaY,
1670 GLYPH_WIDTH * Count,
1671 GLYPH_HEIGHT,
1672 GLYPH_WIDTH * Count * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1673 );
1674 } else {
1675 UgaDraw->Blt (
1676 UgaDraw,
1677 (EFI_UGA_PIXEL *) (UINTN) Private->LineBuffer,
1678 EfiUgaBltBufferToVideo,
1679 0,
1680 0,
1681 GlyphX + Private->ModeData[This->Mode->Mode].DeltaX,
1682 GlyphY + Private->ModeData[This->Mode->Mode].DeltaY,
1683 GLYPH_WIDTH * Count,
1684 GLYPH_HEIGHT,
1685 GLYPH_WIDTH * Count * sizeof (EFI_UGA_PIXEL)
1686 );
1687 }
1688
1689 return ReturnStatus;
1690 }
1691
1692 EFI_STATUS
1693 EraseCursor (
1694 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This
1695 )
1696 {
1697 GRAPHICS_CONSOLE_DEV *Private;
1698 EFI_SIMPLE_TEXT_OUTPUT_MODE *CurrentMode;
1699 INTN GlyphX;
1700 INTN GlyphY;
1701 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1702 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1703 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground;
1704 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background;
1705 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[GLYPH_HEIGHT][GLYPH_WIDTH];
1706 UINTN X;
1707 UINTN Y;
1708
1709 CurrentMode = This->Mode;
1710
1711 if (!CurrentMode->CursorVisible) {
1712 return EFI_SUCCESS;
1713 }
1714
1715 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1716 GraphicsOutput = Private->GraphicsOutput;
1717 UgaDraw = Private->UgaDraw;
1718
1719 //
1720 // BUGBUG - we need to think about what to do with wide and narrow character deletions.
1721 //
1722 //
1723 // Blt a character to the screen
1724 //
1725 GlyphX = (CurrentMode->CursorColumn * GLYPH_WIDTH) + Private->ModeData[CurrentMode->Mode].DeltaX;
1726 GlyphY = (CurrentMode->CursorRow * GLYPH_HEIGHT) + Private->ModeData[CurrentMode->Mode].DeltaY;
1727 if (GraphicsOutput != NULL) {
1728 GraphicsOutput->Blt (
1729 GraphicsOutput,
1730 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,
1731 EfiBltVideoToBltBuffer,
1732 GlyphX,
1733 GlyphY,
1734 0,
1735 0,
1736 GLYPH_WIDTH,
1737 GLYPH_HEIGHT,
1738 GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1739 );
1740 } else {
1741 UgaDraw->Blt (
1742 UgaDraw,
1743 (EFI_UGA_PIXEL *) (UINTN) BltChar,
1744 EfiUgaVideoToBltBuffer,
1745 GlyphX,
1746 GlyphY,
1747 0,
1748 0,
1749 GLYPH_WIDTH,
1750 GLYPH_HEIGHT,
1751 GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)
1752 );
1753 }
1754
1755 GetTextColors (This, &Foreground.Pixel, &Background.Pixel);
1756
1757 //
1758 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1759 //
1760 for (Y = 0; Y < GLYPH_HEIGHT; Y++) {
1761 for (X = 0; X < GLYPH_WIDTH; X++) {
1762 if ((mCursorGlyph.GlyphCol1[Y] & (1 << X)) != 0) {
1763 BltChar[Y][GLYPH_WIDTH - X - 1].Raw ^= Foreground.Raw;
1764 }
1765 }
1766 }
1767
1768 if (GraphicsOutput != NULL) {
1769 GraphicsOutput->Blt (
1770 GraphicsOutput,
1771 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,
1772 EfiBltBufferToVideo,
1773 0,
1774 0,
1775 GlyphX,
1776 GlyphY,
1777 GLYPH_WIDTH,
1778 GLYPH_HEIGHT,
1779 GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1780 );
1781 } else {
1782 UgaDraw->Blt (
1783 UgaDraw,
1784 (EFI_UGA_PIXEL *) (UINTN) BltChar,
1785 EfiUgaBltBufferToVideo,
1786 0,
1787 0,
1788 GlyphX,
1789 GlyphY,
1790 GLYPH_WIDTH,
1791 GLYPH_HEIGHT,
1792 GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)
1793 );
1794 }
1795
1796 return EFI_SUCCESS;
1797 }