]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c
4ffffdbb54889a60f2d49d0436c69c7aea2af597
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitterGraphics.c
1 /** @file
2 Support for ConsoleControl protocol. Support for Graphics output spliter.
3 Support for DevNull Console Out. This console uses memory buffers
4 to represnt the console. It allows a console to start very early and
5 when a new console is added it is synced up with the current console.
6
7 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16
17 **/
18
19 #include "ConSplitter.h"
20
21
22 CHAR16 mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };
23
24
25 /**
26 Return the current video mode information. Also returns info about existence
27 of Graphics Output devices or UGA Draw devices in system, and whether the Std
28 In device is locked. GopUgaExists and StdInLocked parameters are optional, and
29 only returned if a non NULL pointer is passed in.
30
31 @param This Protocol instance pointer.
32 @param Mode Current video mode.
33 @param GopUgaExists TRUE if GOP Spliter has found a GOP/UGA device
34 @param StdInLocked TRUE if StdIn device is keyboard locked
35
36 @retval EFI_SUCCESS Video mode information is returned.
37 @retval EFI_INVALID_PARAMETER Invalid parameters if Mode == NULL.
38
39 **/
40 EFI_STATUS
41 EFIAPI
42 ConSpliterConsoleControlGetMode (
43 IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
44 OUT EFI_CONSOLE_CONTROL_SCREEN_MODE *Mode,
45 OUT BOOLEAN *GopUgaExists,
46 OUT BOOLEAN *StdInLocked
47 )
48 {
49 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
50 UINTN Index;
51
52 Private = CONSOLE_CONTROL_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
53
54 if (Mode == NULL) {
55 return EFI_INVALID_PARAMETER;
56 }
57
58 *Mode = Private->ConsoleOutputMode;
59
60 if (GopUgaExists != NULL) {
61 *GopUgaExists = FALSE;
62 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
63 if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {
64 *GopUgaExists = TRUE;
65 break;
66 }
67 }
68 }
69
70 if (StdInLocked != NULL) {
71 *StdInLocked = ConSpliterConssoleControlStdInLocked ();
72 }
73
74 return EFI_SUCCESS;
75 }
76
77
78 /**
79 Set the current video mode to either text or graphics. Graphics is
80 for Quiet Boot.
81
82 @param This Console Control Protocol instance pointer.
83 @param Mode Video mode is to be set.
84
85 @retval EFI_SUCCESS Mode is set successfully.
86 @retval EFI_INVALID_PARAMETER Mode is not the valid mode value.
87 @retval EFI_UNSUPPORTED Mode is unsupported by console device.
88
89 **/
90 EFI_STATUS
91 EFIAPI
92 ConSpliterConsoleControlSetMode (
93 IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
94 IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode
95 )
96 {
97 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
98 UINTN Index;
99 TEXT_OUT_AND_GOP_DATA *TextAndGop;
100 BOOLEAN Supported;
101
102 Private = CONSOLE_CONTROL_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
103
104 if (Mode >= EfiConsoleControlScreenMaxValue) {
105 return EFI_INVALID_PARAMETER;
106 }
107
108 //
109 // Judge current mode with wanted mode at first.
110 //
111 if (Private->ConsoleOutputMode == Mode) {
112 return EFI_SUCCESS;
113 }
114
115 Supported = FALSE;
116 TextAndGop = &Private->TextOutList[0];
117 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++, TextAndGop++) {
118 if ((TextAndGop->GraphicsOutput != NULL) || (TextAndGop->UgaDraw != NULL)) {
119 Supported = TRUE;
120 break;
121 }
122 }
123
124 if ((!Supported) && (Mode == EfiConsoleControlScreenGraphics)) {
125 return EFI_UNSUPPORTED;
126 }
127
128 Private->ConsoleOutputMode = Mode;
129
130 TextAndGop = &Private->TextOutList[0];
131 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++, TextAndGop++) {
132
133 TextAndGop->TextOutEnabled = TRUE;
134 //
135 // If we are going into Graphics mode disable ConOut to any UGA device
136 //
137 if ((Mode == EfiConsoleControlScreenGraphics) &&((TextAndGop->GraphicsOutput != NULL) || (TextAndGop->UgaDraw != NULL))) {
138 TextAndGop->TextOutEnabled = FALSE;
139 if (FeaturePcdGet (PcdConOutGopSupport)) {
140 DevNullGopSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);
141 } else if (FeaturePcdGet (PcdConOutUgaSupport)) {
142 DevNullUgaSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);
143 }
144 }
145 }
146 if (Mode == EfiConsoleControlScreenText) {
147 DevNullSyncStdOut (Private);
148 }
149 return EFI_SUCCESS;
150 }
151
152
153 /**
154 Returns information for an available graphics mode that the graphics device
155 and the set of active video output devices supports.
156
157 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
158 @param ModeNumber The mode number to return information on.
159 @param SizeOfInfo A pointer to the size, in bytes, of the Info buffer.
160 @param Info A pointer to callee allocated buffer that returns information about ModeNumber.
161
162 @retval EFI_SUCCESS Mode information returned.
163 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
164 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the video mode.
165 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
166 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
167 @retval EFI_OUT_OF_RESOURCES No resource available.
168
169 **/
170 EFI_STATUS
171 EFIAPI
172 ConSpliterGraphicsOutputQueryMode (
173 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
174 IN UINT32 ModeNumber,
175 OUT UINTN *SizeOfInfo,
176 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
177 )
178 {
179 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
180
181 if (This == NULL || Info == NULL || SizeOfInfo == NULL || ModeNumber >= This->Mode->MaxMode) {
182 return EFI_INVALID_PARAMETER;
183 }
184
185 //
186 // retrieve private data
187 //
188 Private = GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
189
190 if (Private->HardwareNeedsStarting) {
191 return EFI_NOT_STARTED;
192 }
193
194 *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
195 if (*Info == NULL) {
196 return EFI_OUT_OF_RESOURCES;
197 }
198
199 *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
200
201 CopyMem (*Info, &Private->GraphicsOutputModeBuffer[ModeNumber], *SizeOfInfo);
202
203 return EFI_SUCCESS;
204 }
205
206
207 /**
208 Set the video device into the specified mode and clears the visible portions of
209 the output display to black.
210
211 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
212 @param ModeNumber Abstraction that defines the current video mode.
213
214 @retval EFI_SUCCESS The graphics mode specified by ModeNumber was selected.
215 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
216 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
217 @retval EFI_OUT_OF_RESOURCES No resource available.
218
219 **/
220 EFI_STATUS
221 EFIAPI
222 ConSpliterGraphicsOutputSetMode (
223 IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This,
224 IN UINT32 ModeNumber
225 )
226 {
227 EFI_STATUS Status;
228 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
229 UINTN Index;
230 EFI_STATUS ReturnStatus;
231 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;
232 UINTN Size;
233 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
234 UINTN NumberIndex;
235 UINTN SizeOfInfo;
236 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
237 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
238
239 if (ModeNumber >= This->Mode->MaxMode) {
240 return EFI_UNSUPPORTED;
241 }
242
243 if (ModeNumber == This->Mode->Mode) {
244 return EFI_SUCCESS;
245 }
246
247 Private = GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
248
249 ReturnStatus = EFI_SUCCESS;
250
251 //
252 // Free the old version
253 //
254 if (Private->GraphicsOutputBlt != NULL) {
255 FreePool (Private->GraphicsOutputBlt);
256 }
257
258 //
259 // Allocate the virtual Blt buffer
260 //
261 Mode = &Private->GraphicsOutputModeBuffer[ModeNumber];
262 Size = Mode->HorizontalResolution * Mode->VerticalResolution * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
263 Private->GraphicsOutputBlt = AllocateZeroPool (Size);
264
265 if (Private->GraphicsOutputBlt == NULL) {
266 return EFI_OUT_OF_RESOURCES;
267 }
268
269 //
270 // return the worst status met
271 //
272 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
273 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
274 if (GraphicsOutput != NULL) {
275 //
276 // Find corresponding ModeNumber of this GraphicsOutput instance
277 //
278 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex ++) {
279 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
280 if (EFI_ERROR (Status)) {
281 return Status;
282 }
283 if ((Info->HorizontalResolution == Mode->HorizontalResolution) && (Info->VerticalResolution == Mode->VerticalResolution)) {
284 FreePool (Info);
285 break;
286 }
287 FreePool (Info);
288 }
289
290 Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);
291 if (EFI_ERROR (Status)) {
292 ReturnStatus = Status;
293 }
294 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
295 UgaDraw = Private->TextOutList[Index].UgaDraw;
296 if (UgaDraw != NULL) {
297 Status = UgaDraw->SetMode (
298 UgaDraw,
299 Mode->HorizontalResolution,
300 Mode->VerticalResolution,
301 32,
302 60
303 );
304 if (EFI_ERROR (Status)) {
305 ReturnStatus = Status;
306 }
307 }
308 }
309 }
310
311 This->Mode->Mode = ModeNumber;
312
313 CopyMem (This->Mode->Info, &Private->GraphicsOutputModeBuffer[ModeNumber], This->Mode->SizeOfInfo);
314
315 //
316 // Information is not enough here, so the following items remain unchanged:
317 // GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat
318 // GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
319 // These items will be initialized/updated when a new GOP device is added into ConsoleSplitter.
320 //
321
322 Private->HardwareNeedsStarting = FALSE;
323
324 return ReturnStatus;
325 }
326
327 /**
328 The following table defines actions for BltOperations.
329
330 EfiBltVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY)
331 directly to every pixel of the video display rectangle
332 (DestinationX, DestinationY)
333 (DestinationX + Width, DestinationY + Height).
334 Only one pixel will be used from the BltBuffer. Delta is NOT used.
335 EfiBltVideoToBltBuffer - Read data from the video display rectangle
336 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
337 the BltBuffer rectangle (DestinationX, DestinationY )
338 (DestinationX + Width, DestinationY + Height). If DestinationX or
339 DestinationY is not zero then Delta must be set to the length in bytes
340 of a row in the BltBuffer.
341 EfiBltBufferToVideo - Write data from the BltBuffer rectangle
342 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
343 video display rectangle (DestinationX, DestinationY)
344 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
345 not zero then Delta must be set to the length in bytes of a row in the
346 BltBuffer.
347 EfiBltVideoToVideo - Copy from the video display rectangle
348 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
349 to the video display rectangle (DestinationX, DestinationY)
350 (DestinationX + Width, DestinationY + Height).
351 The BltBuffer and Delta are not used in this mode.
352
353 @param Private Protocol instance pointer.
354 @param BltBuffer Buffer containing data to blit into video buffer.
355 This buffer has a size of
356 Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
357 @param BltOperation Operation to perform on BlitBuffer and video
358 memory
359 @param SourceX X coordinate of source for the BltBuffer.
360 @param SourceY Y coordinate of source for the BltBuffer.
361 @param DestinationX X coordinate of destination for the BltBuffer.
362 @param DestinationY Y coordinate of destination for the BltBuffer.
363 @param Width Width of rectangle in BltBuffer in pixels.
364 @param Height Hight of rectangle in BltBuffer in pixels.
365 @param Delta OPTIONAL.
366
367 @retval EFI_SUCCESS The Blt operation completed.
368 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
369 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video
370 buffer.
371
372 **/
373 EFI_STATUS
374 DevNullGraphicsOutputBlt (
375 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
376 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
377 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
378 IN UINTN SourceX,
379 IN UINTN SourceY,
380 IN UINTN DestinationX,
381 IN UINTN DestinationY,
382 IN UINTN Width,
383 IN UINTN Height,
384 IN UINTN Delta OPTIONAL
385 )
386 {
387 UINTN SrcY;
388 BOOLEAN Forward;
389 UINTN Index;
390 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltPtr;
391 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ScreenPtr;
392 UINTN HorizontalResolution;
393 UINTN VerticalResolution;
394
395 if ((BltOperation < EfiBltVideoFill) || (BltOperation >= EfiGraphicsOutputBltOperationMax)) {
396 return EFI_INVALID_PARAMETER;
397 }
398
399 if (Width == 0 || Height == 0) {
400 return EFI_INVALID_PARAMETER;
401 }
402
403 if (Delta == 0) {
404 Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
405 }
406
407 HorizontalResolution = Private->GraphicsOutput.Mode->Info->HorizontalResolution;
408 VerticalResolution = Private->GraphicsOutput.Mode->Info->VerticalResolution;
409
410 //
411 // We need to fill the Virtual Screen buffer with the blt data.
412 //
413 if (BltOperation == EfiBltVideoToBltBuffer) {
414 //
415 // Video to BltBuffer: Source is Video, destination is BltBuffer
416 //
417 if ((SourceY + Height) > VerticalResolution) {
418 return EFI_INVALID_PARAMETER;
419 }
420
421 if ((SourceX + Width) > HorizontalResolution) {
422 return EFI_INVALID_PARAMETER;
423 }
424
425 BltPtr = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + DestinationY * Delta + DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
426 ScreenPtr = &Private->GraphicsOutputBlt[SourceY * HorizontalResolution + SourceX];
427 while (Height > 0) {
428 CopyMem (BltPtr, ScreenPtr, Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
429 BltPtr = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltPtr + Delta);
430 ScreenPtr += HorizontalResolution;
431 Height--;
432 }
433 } else {
434 //
435 // BltBuffer to Video: Source is BltBuffer, destination is Video
436 //
437 if (DestinationY + Height > VerticalResolution) {
438 return EFI_INVALID_PARAMETER;
439 }
440
441 if (DestinationX + Width > HorizontalResolution) {
442 return EFI_INVALID_PARAMETER;
443 }
444
445 if ((BltOperation == EfiBltVideoToVideo) && (DestinationY > SourceY)) {
446 //
447 // Copy backwards, only care the Video to Video Blt
448 //
449 ScreenPtr = &Private->GraphicsOutputBlt[(DestinationY + Height - 1) * HorizontalResolution + DestinationX];
450 SrcY = SourceY + Height - 1;
451 Forward = FALSE;
452 } else {
453 //
454 // Copy forwards, for other cases
455 //
456 ScreenPtr = &Private->GraphicsOutputBlt[DestinationY * HorizontalResolution + DestinationX];
457 SrcY = SourceY;
458 Forward = TRUE;
459 }
460
461 while (Height != 0) {
462 if (BltOperation == EfiBltVideoFill) {
463 for (Index = 0; Index < Width; Index++) {
464 ScreenPtr[Index] = *BltBuffer;
465 }
466 } else {
467 if (BltOperation == EfiBltBufferToVideo) {
468 BltPtr = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + SrcY * Delta + SourceX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
469 } else {
470 BltPtr = &Private->GraphicsOutputBlt[SrcY * HorizontalResolution + SourceX];
471 }
472
473 CopyMem (ScreenPtr, BltPtr, Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
474 }
475
476 if (Forward) {
477 ScreenPtr += HorizontalResolution;
478 SrcY ++;
479 } else {
480 ScreenPtr -= HorizontalResolution;
481 SrcY --;
482 }
483 Height--;
484 }
485 }
486
487 return EFI_SUCCESS;
488 }
489
490
491 /**
492 The following table defines actions for BltOperations.
493
494 EfiBltVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY)
495 directly to every pixel of the video display rectangle
496 (DestinationX, DestinationY)
497 (DestinationX + Width, DestinationY + Height).
498 Only one pixel will be used from the BltBuffer. Delta is NOT used.
499 EfiBltVideoToBltBuffer - Read data from the video display rectangle
500 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
501 the BltBuffer rectangle (DestinationX, DestinationY )
502 (DestinationX + Width, DestinationY + Height). If DestinationX or
503 DestinationY is not zero then Delta must be set to the length in bytes
504 of a row in the BltBuffer.
505 EfiBltBufferToVideo - Write data from the BltBuffer rectangle
506 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
507 video display rectangle (DestinationX, DestinationY)
508 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
509 not zero then Delta must be set to the length in bytes of a row in the
510 BltBuffer.
511 EfiBltVideoToVideo - Copy from the video display rectangle
512 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
513 to the video display rectangle (DestinationX, DestinationY)
514 (DestinationX + Width, DestinationY + Height).
515 The BltBuffer and Delta are not used in this mode.
516
517 @param This Protocol instance pointer.
518 @param BltBuffer Buffer containing data to blit into video buffer.
519 This buffer has a size of
520 Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
521 @param BltOperation Operation to perform on BlitBuffer and video
522 memory
523 @param SourceX X coordinate of source for the BltBuffer.
524 @param SourceY Y coordinate of source for the BltBuffer.
525 @param DestinationX X coordinate of destination for the BltBuffer.
526 @param DestinationY Y coordinate of destination for the BltBuffer.
527 @param Width Width of rectangle in BltBuffer in pixels.
528 @param Height Hight of rectangle in BltBuffer in pixels.
529 @param Delta OPTIONAL.
530
531 @retval EFI_SUCCESS The Blt operation completed.
532 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
533 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video
534 buffer.
535
536 **/
537 EFI_STATUS
538 EFIAPI
539 ConSpliterGraphicsOutputBlt (
540 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
541 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
542 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
543 IN UINTN SourceX,
544 IN UINTN SourceY,
545 IN UINTN DestinationX,
546 IN UINTN DestinationY,
547 IN UINTN Width,
548 IN UINTN Height,
549 IN UINTN Delta OPTIONAL
550 )
551 {
552 EFI_STATUS Status;
553 EFI_STATUS ReturnStatus;
554 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
555 UINTN Index;
556 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
557 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
558
559 Private = GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
560
561 ReturnStatus = EFI_SUCCESS;
562 //
563 // return the worst status met
564 //
565 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
566 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
567 if (GraphicsOutput != NULL) {
568 Status = GraphicsOutput->Blt (
569 GraphicsOutput,
570 BltBuffer,
571 BltOperation,
572 SourceX,
573 SourceY,
574 DestinationX,
575 DestinationY,
576 Width,
577 Height,
578 Delta
579 );
580 if (EFI_ERROR (Status)) {
581 ReturnStatus = Status;
582 } else if (BltOperation == EfiBltVideoToBltBuffer) {
583 //
584 // Only need to read the data into buffer one time
585 //
586 return EFI_SUCCESS;
587 }
588 }
589
590 UgaDraw = Private->TextOutList[Index].UgaDraw;
591 if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
592 Status = UgaDraw->Blt (
593 UgaDraw,
594 (EFI_UGA_PIXEL *) BltBuffer,
595 (EFI_UGA_BLT_OPERATION) BltOperation,
596 SourceX,
597 SourceY,
598 DestinationX,
599 DestinationY,
600 Width,
601 Height,
602 Delta
603 );
604 if (EFI_ERROR (Status)) {
605 ReturnStatus = Status;
606 } else if (BltOperation == EfiBltVideoToBltBuffer) {
607 //
608 // Only need to read the data into buffer one time
609 //
610 return EFI_SUCCESS;
611 }
612 }
613 }
614
615 return ReturnStatus;
616 }
617
618 /**
619 Write data from the buffer to video display based on Graphics Output setting.
620
621 @param Private Consplitter Text Out pointer.
622 @param GraphicsOutput Graphics Output protocol pointer.
623 @param UgaDraw UGA Draw protocol pointer.
624
625 @retval EFI_UNSUPPORTED No graphics devcie available .
626 @retval EFI_SUCCESS The Blt operation completed.
627 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
628 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
629
630
631 **/
632 EFI_STATUS
633 DevNullGopSync (
634 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
635 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
636 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
637 )
638 {
639 if (GraphicsOutput != NULL) {
640 return GraphicsOutput->Blt (
641 GraphicsOutput,
642 Private->GraphicsOutputBlt,
643 EfiBltBufferToVideo,
644 0,
645 0,
646 0,
647 0,
648 Private->GraphicsOutput.Mode->Info->HorizontalResolution,
649 Private->GraphicsOutput.Mode->Info->VerticalResolution,
650 0
651 );
652 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
653 return UgaDraw->Blt (
654 UgaDraw,
655 (EFI_UGA_PIXEL *) Private->GraphicsOutputBlt,
656 EfiUgaBltBufferToVideo,
657 0,
658 0,
659 0,
660 0,
661 Private->GraphicsOutput.Mode->Info->HorizontalResolution,
662 Private->GraphicsOutput.Mode->Info->VerticalResolution,
663 0
664 );
665 } else {
666 return EFI_UNSUPPORTED;
667 }
668 }
669
670 /**
671 Return the current video mode information.
672
673 @param This The EFI_UGA_DRAW_PROTOCOL instance.
674 @param HorizontalResolution The size of video screen in pixels in the X dimension.
675 @param VerticalResolution The size of video screen in pixels in the Y dimension.
676 @param ColorDepth Number of bits per pixel, currently defined to be 32.
677 @param RefreshRate The refresh rate of the monitor in Hertz.
678
679 @retval EFI_SUCCESS Mode information returned.
680 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
681 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
682
683 **/
684 EFI_STATUS
685 EFIAPI
686 ConSpliterUgaDrawGetMode (
687 IN EFI_UGA_DRAW_PROTOCOL *This,
688 OUT UINT32 *HorizontalResolution,
689 OUT UINT32 *VerticalResolution,
690 OUT UINT32 *ColorDepth,
691 OUT UINT32 *RefreshRate
692 )
693 {
694 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
695
696 if ((HorizontalResolution == NULL) ||
697 (VerticalResolution == NULL) ||
698 (RefreshRate == NULL) ||
699 (ColorDepth == NULL)) {
700 return EFI_INVALID_PARAMETER;
701 }
702 //
703 // retrieve private data
704 //
705 Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
706
707 *HorizontalResolution = Private->UgaHorizontalResolution;
708 *VerticalResolution = Private->UgaVerticalResolution;
709 *ColorDepth = Private->UgaColorDepth;
710 *RefreshRate = Private->UgaRefreshRate;
711
712 return EFI_SUCCESS;
713 }
714
715
716 /**
717 Set the current video mode information.
718
719 @param This The EFI_UGA_DRAW_PROTOCOL instance.
720 @param HorizontalResolution The size of video screen in pixels in the X dimension.
721 @param VerticalResolution The size of video screen in pixels in the Y dimension.
722 @param ColorDepth Number of bits per pixel, currently defined to be 32.
723 @param RefreshRate The refresh rate of the monitor in Hertz.
724
725 @retval EFI_SUCCESS Mode information returned.
726 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
727 @retval EFI_OUT_OF_RESOURCES Out of resources.
728
729 **/
730 EFI_STATUS
731 EFIAPI
732 ConSpliterUgaDrawSetMode (
733 IN EFI_UGA_DRAW_PROTOCOL *This,
734 IN UINT32 HorizontalResolution,
735 IN UINT32 VerticalResolution,
736 IN UINT32 ColorDepth,
737 IN UINT32 RefreshRate
738 )
739 {
740 EFI_STATUS Status;
741 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
742 UINTN Index;
743 EFI_STATUS ReturnStatus;
744 UINTN Size;
745 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
746 UINTN NumberIndex;
747 UINTN SizeOfInfo;
748 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
749 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
750
751 Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
752
753 //
754 // UgaDevNullSetMode ()
755 //
756 ReturnStatus = EFI_SUCCESS;
757
758 //
759 // Free the old version
760 //
761 if (Private->UgaBlt != NULL) {
762 FreePool (Private->UgaBlt);
763 }
764
765 //
766 // Allocate the virtual Blt buffer
767 //
768 Size = HorizontalResolution * VerticalResolution * sizeof (EFI_UGA_PIXEL);
769 Private->UgaBlt = AllocateZeroPool (Size);
770 if (Private->UgaBlt == NULL) {
771 return EFI_OUT_OF_RESOURCES;
772 }
773
774 //
775 // Update the Mode data
776 //
777 Private->UgaHorizontalResolution = HorizontalResolution;
778 Private->UgaVerticalResolution = VerticalResolution;
779 Private->UgaColorDepth = ColorDepth;
780 Private->UgaRefreshRate = RefreshRate;
781
782 if (Private->ConsoleOutputMode != EfiConsoleControlScreenGraphics) {
783 return ReturnStatus;
784 }
785 //
786 // return the worst status met
787 //
788 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
789
790 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
791 if (GraphicsOutput != NULL) {
792 //
793 // Find corresponding ModeNumber of this GraphicsOutput instance
794 //
795 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex ++) {
796 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
797 if (EFI_ERROR (Status)) {
798 return Status;
799 }
800 if ((Info->HorizontalResolution == HorizontalResolution) && (Info->VerticalResolution == VerticalResolution)) {
801 FreePool (Info);
802 break;
803 }
804 FreePool (Info);
805 }
806
807 Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);
808 if (EFI_ERROR (Status)) {
809 ReturnStatus = Status;
810 }
811 } else if (FeaturePcdGet (PcdUgaConsumeSupport)){
812 UgaDraw = Private->TextOutList[Index].UgaDraw;
813 if (UgaDraw != NULL) {
814 Status = UgaDraw->SetMode (
815 UgaDraw,
816 HorizontalResolution,
817 VerticalResolution,
818 ColorDepth,
819 RefreshRate
820 );
821 if (EFI_ERROR (Status)) {
822 ReturnStatus = Status;
823 }
824 }
825 }
826 }
827
828 return ReturnStatus;
829 }
830
831 /**
832 Blt a rectangle of pixels on the graphics screen.
833
834 The following table defines actions for BltOperations.
835
836 EfiUgaVideoFill:
837 Write data from the BltBuffer pixel (SourceX, SourceY)
838 directly to every pixel of the video display rectangle
839 (DestinationX, DestinationY)
840 (DestinationX + Width, DestinationY + Height).
841 Only one pixel will be used from the BltBuffer. Delta is NOT used.
842 EfiUgaVideoToBltBuffer:
843 Read data from the video display rectangle
844 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
845 the BltBuffer rectangle (DestinationX, DestinationY )
846 (DestinationX + Width, DestinationY + Height). If DestinationX or
847 DestinationY is not zero then Delta must be set to the length in bytes
848 of a row in the BltBuffer.
849 EfiUgaBltBufferToVideo:
850 Write data from the BltBuffer rectangle
851 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
852 video display rectangle (DestinationX, DestinationY)
853 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
854 not zero then Delta must be set to the length in bytes of a row in the
855 BltBuffer.
856 EfiUgaVideoToVideo:
857 Copy from the video display rectangle
858 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
859 to the video display rectangle (DestinationX, DestinationY)
860 (DestinationX + Width, DestinationY + Height).
861 The BltBuffer and Delta are not used in this mode.
862
863 @param Private Text Out Splitter pointer.
864 @param BltBuffer Buffer containing data to blit into video buffer.
865 This buffer has a size of
866 Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
867 @param BltOperation Operation to perform on BlitBuffer and video
868 memory
869 @param SourceX X coordinate of source for the BltBuffer.
870 @param SourceY Y coordinate of source for the BltBuffer.
871 @param DestinationX X coordinate of destination for the BltBuffer.
872 @param DestinationY Y coordinate of destination for the BltBuffer.
873 @param Width Width of rectangle in BltBuffer in pixels.
874 @param Height Hight of rectangle in BltBuffer in pixels.
875 @param Delta OPTIONAL.
876
877 @retval EFI_SUCCESS The Blt operation completed.
878 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
879 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video
880 buffer.
881
882 **/
883 EFI_STATUS
884 DevNullUgaBlt (
885 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
886 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
887 IN EFI_UGA_BLT_OPERATION BltOperation,
888 IN UINTN SourceX,
889 IN UINTN SourceY,
890 IN UINTN DestinationX,
891 IN UINTN DestinationY,
892 IN UINTN Width,
893 IN UINTN Height,
894 IN UINTN Delta OPTIONAL
895 )
896 {
897 UINTN SrcY;
898 BOOLEAN Forward;
899 UINTN Index;
900 EFI_UGA_PIXEL *BltPtr;
901 EFI_UGA_PIXEL *ScreenPtr;
902 UINT32 HorizontalResolution;
903 UINT32 VerticalResolution;
904
905 if ((BltOperation < 0) || (BltOperation >= EfiUgaBltMax)) {
906 return EFI_INVALID_PARAMETER;
907 }
908
909 if (Width == 0 || Height == 0) {
910 return EFI_INVALID_PARAMETER;
911 }
912
913 if (Delta == 0) {
914 Delta = Width * sizeof (EFI_UGA_PIXEL);
915 }
916
917 HorizontalResolution = Private->UgaHorizontalResolution;
918 VerticalResolution = Private->UgaVerticalResolution;
919
920 //
921 // We need to fill the Virtual Screen buffer with the blt data.
922 //
923 if (BltOperation == EfiUgaVideoToBltBuffer) {
924 //
925 // Video to BltBuffer: Source is Video, destination is BltBuffer
926 //
927 if ((SourceY + Height) > VerticalResolution) {
928 return EFI_INVALID_PARAMETER;
929 }
930
931 if ((SourceX + Width) > HorizontalResolution) {
932 return EFI_INVALID_PARAMETER;
933 }
934
935 BltPtr = (EFI_UGA_PIXEL *) ((UINT8 *) BltBuffer + DestinationY * Delta + DestinationX * sizeof (EFI_UGA_PIXEL));
936 ScreenPtr = &Private->UgaBlt[SourceY * HorizontalResolution + SourceX];
937 while (Height > 0) {
938 CopyMem (BltPtr, ScreenPtr, Width * sizeof (EFI_UGA_PIXEL));
939 BltPtr = (EFI_UGA_PIXEL *) ((UINT8 *) BltPtr + Delta);
940 ScreenPtr += HorizontalResolution;
941 Height--;
942 }
943 } else {
944 //
945 // BltBuffer to Video: Source is BltBuffer, destination is Video
946 //
947 if (DestinationY + Height > VerticalResolution) {
948 return EFI_INVALID_PARAMETER;
949 }
950
951 if (DestinationX + Width > HorizontalResolution) {
952 return EFI_INVALID_PARAMETER;
953 }
954
955 if ((BltOperation == EfiUgaVideoToVideo) && (DestinationY > SourceY)) {
956 //
957 // Copy backwards, only care the Video to Video Blt
958 //
959 ScreenPtr = &Private->UgaBlt[(DestinationY + Height - 1) * HorizontalResolution + DestinationX];
960 SrcY = SourceY + Height - 1;
961 Forward = FALSE;
962 } else {
963 //
964 // Copy forwards, for other cases
965 //
966 ScreenPtr = &Private->UgaBlt[DestinationY * HorizontalResolution + DestinationX];
967 SrcY = SourceY;
968 Forward = TRUE;
969 }
970
971 while (Height != 0) {
972 if (BltOperation == EfiUgaVideoFill) {
973 for (Index = 0; Index < Width; Index++) {
974 ScreenPtr[Index] = *BltBuffer;
975 }
976 } else {
977 if (BltOperation == EfiUgaBltBufferToVideo) {
978 BltPtr = (EFI_UGA_PIXEL *) ((UINT8 *) BltBuffer + SrcY * Delta + SourceX * sizeof (EFI_UGA_PIXEL));
979 } else {
980 BltPtr = &Private->UgaBlt[SrcY * HorizontalResolution + SourceX];
981 }
982
983 CopyMem (ScreenPtr, BltPtr, Width * sizeof (EFI_UGA_PIXEL));
984 }
985
986 if (Forward) {
987 ScreenPtr += HorizontalResolution;
988 SrcY ++;
989 } else {
990 ScreenPtr -= HorizontalResolution;
991 SrcY --;
992 }
993 Height--;
994 }
995 }
996
997 return EFI_SUCCESS;
998 }
999
1000 /**
1001 Blt a rectangle of pixels on the graphics screen.
1002
1003 The following table defines actions for BltOperations.
1004
1005 EfiUgaVideoFill:
1006 Write data from the BltBuffer pixel (SourceX, SourceY)
1007 directly to every pixel of the video display rectangle
1008 (DestinationX, DestinationY)
1009 (DestinationX + Width, DestinationY + Height).
1010 Only one pixel will be used from the BltBuffer. Delta is NOT used.
1011 EfiUgaVideoToBltBuffer:
1012 Read data from the video display rectangle
1013 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
1014 the BltBuffer rectangle (DestinationX, DestinationY )
1015 (DestinationX + Width, DestinationY + Height). If DestinationX or
1016 DestinationY is not zero then Delta must be set to the length in bytes
1017 of a row in the BltBuffer.
1018 EfiUgaBltBufferToVideo:
1019 Write data from the BltBuffer rectangle
1020 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
1021 video display rectangle (DestinationX, DestinationY)
1022 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
1023 not zero then Delta must be set to the length in bytes of a row in the
1024 BltBuffer.
1025 EfiUgaVideoToVideo:
1026 Copy from the video display rectangle
1027 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
1028 to the video display rectangle (DestinationX, DestinationY)
1029 (DestinationX + Width, DestinationY + Height).
1030 The BltBuffer and Delta are not used in this mode.
1031
1032 @param This Protocol instance pointer.
1033 @param BltBuffer Buffer containing data to blit into video buffer. This
1034 buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
1035 @param BltOperation Operation to perform on BlitBuffer and video memory
1036 @param SourceX X coordinate of source for the BltBuffer.
1037 @param SourceY Y coordinate of source for the BltBuffer.
1038 @param DestinationX X coordinate of destination for the BltBuffer.
1039 @param DestinationY Y coordinate of destination for the BltBuffer.
1040 @param Width Width of rectangle in BltBuffer in pixels.
1041 @param Height Hight of rectangle in BltBuffer in pixels.
1042 @param Delta OPTIONAL
1043
1044 @retval EFI_SUCCESS The Blt operation completed.
1045 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
1046 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
1047
1048 **/
1049 EFI_STATUS
1050 EFIAPI
1051 ConSpliterUgaDrawBlt (
1052 IN EFI_UGA_DRAW_PROTOCOL *This,
1053 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
1054 IN EFI_UGA_BLT_OPERATION BltOperation,
1055 IN UINTN SourceX,
1056 IN UINTN SourceY,
1057 IN UINTN DestinationX,
1058 IN UINTN DestinationY,
1059 IN UINTN Width,
1060 IN UINTN Height,
1061 IN UINTN Delta OPTIONAL
1062 )
1063 {
1064 EFI_STATUS Status;
1065 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
1066 UINTN Index;
1067 EFI_STATUS ReturnStatus;
1068 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1069
1070 Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
1071
1072 //
1073 // Sync up DevNull UGA device
1074 //
1075 ReturnStatus = DevNullUgaBlt (
1076 Private,
1077 BltBuffer,
1078 BltOperation,
1079 SourceX,
1080 SourceY,
1081 DestinationX,
1082 DestinationY,
1083 Width,
1084 Height,
1085 Delta
1086 );
1087 if (Private->ConsoleOutputMode != EfiConsoleControlScreenGraphics) {
1088 return ReturnStatus;
1089 }
1090 //
1091 // return the worst status met
1092 //
1093 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
1094 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
1095 if (GraphicsOutput != NULL) {
1096 Status = GraphicsOutput->Blt (
1097 GraphicsOutput,
1098 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltBuffer,
1099 (EFI_GRAPHICS_OUTPUT_BLT_OPERATION) BltOperation,
1100 SourceX,
1101 SourceY,
1102 DestinationX,
1103 DestinationY,
1104 Width,
1105 Height,
1106 Delta
1107 );
1108 if (EFI_ERROR (Status)) {
1109 ReturnStatus = Status;
1110 } else if (BltOperation == EfiBltVideoToBltBuffer) {
1111 //
1112 // Only need to read the data into buffer one time
1113 //
1114 return EFI_SUCCESS;
1115 }
1116 }
1117
1118 if (Private->TextOutList[Index].UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
1119 Status = Private->TextOutList[Index].UgaDraw->Blt (
1120 Private->TextOutList[Index].UgaDraw,
1121 BltBuffer,
1122 BltOperation,
1123 SourceX,
1124 SourceY,
1125 DestinationX,
1126 DestinationY,
1127 Width,
1128 Height,
1129 Delta
1130 );
1131 if (EFI_ERROR (Status)) {
1132 ReturnStatus = Status;
1133 } else if (BltOperation == EfiUgaVideoToBltBuffer) {
1134 //
1135 // Only need to read the data into buffer one time
1136 //
1137 return EFI_SUCCESS;
1138 }
1139 }
1140 }
1141
1142 return ReturnStatus;
1143 }
1144
1145 /**
1146 Write data from the buffer to video display based on UGA Draw setting.
1147
1148 @param Private Consplitter Text Out pointer.
1149 @param GraphicsOutput Graphics Output protocol pointer.
1150 @param UgaDraw UGA Draw protocol pointer.
1151
1152 @retval EFI_UNSUPPORTED No graphics devcie available .
1153 @retval EFI_SUCCESS The Blt operation completed.
1154 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
1155 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
1156
1157 **/
1158 EFI_STATUS
1159 DevNullUgaSync (
1160 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1161 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
1162 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
1163 )
1164 {
1165 if (GraphicsOutput != NULL) {
1166 return GraphicsOutput->Blt (
1167 GraphicsOutput,
1168 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) Private->UgaBlt,
1169 EfiBltBufferToVideo,
1170 0,
1171 0,
1172 0,
1173 0,
1174 Private->UgaHorizontalResolution,
1175 Private->UgaVerticalResolution,
1176 0
1177 );
1178 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
1179 return UgaDraw->Blt (
1180 UgaDraw,
1181 Private->UgaBlt,
1182 EfiUgaBltBufferToVideo,
1183 0,
1184 0,
1185 0,
1186 0,
1187 Private->UgaHorizontalResolution,
1188 Private->UgaVerticalResolution,
1189 Private->UgaHorizontalResolution * sizeof (EFI_UGA_PIXEL)
1190 );
1191 } else {
1192 return EFI_UNSUPPORTED;
1193 }
1194 }
1195
1196
1197 /**
1198 Write a Unicode string to the output device.
1199
1200 @param Private Pointer to the console output splitter's private
1201 data. It indicates the calling context.
1202 @param WString The NULL-terminated Unicode string to be
1203 displayed on the output device(s). All output
1204 devices must also support the Unicode drawing
1205 defined in this file.
1206
1207 @retval EFI_SUCCESS The string was output to the device.
1208 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
1209 output the text.
1210 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
1211 defined text mode.
1212 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
1213 characters in the Unicode string could not be
1214 rendered and were skipped.
1215
1216 **/
1217 EFI_STATUS
1218 DevNullTextOutOutputString (
1219 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1220 IN CHAR16 *WString
1221 )
1222 {
1223 UINTN SizeScreen;
1224 UINTN SizeAttribute;
1225 UINTN Index;
1226 EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
1227 CHAR16 *Screen;
1228 CHAR16 *NullScreen;
1229 CHAR16 InsertChar;
1230 CHAR16 TempChar;
1231 CHAR16 *PStr;
1232 INT32 *Attribute;
1233 INT32 *NullAttributes;
1234 INT32 CurrentWidth;
1235 UINTN LastRow;
1236 UINTN MaxColumn;
1237
1238 Mode = &Private->TextOutMode;
1239 NullScreen = Private->DevNullScreen;
1240 NullAttributes = Private->DevNullAttributes;
1241 LastRow = Private->DevNullRows - 1;
1242 MaxColumn = Private->DevNullColumns;
1243
1244 if ((Mode->Attribute & EFI_WIDE_ATTRIBUTE) != 0) {
1245 CurrentWidth = 2;
1246 } else {
1247 CurrentWidth = 1;
1248 }
1249
1250 while (*WString != L'\0') {
1251
1252 if (*WString == CHAR_BACKSPACE) {
1253 //
1254 // If the cursor is at the left edge of the display, then move the cursor
1255 // one row up.
1256 //
1257 if (Mode->CursorColumn == 0 && Mode->CursorRow > 0) {
1258 Mode->CursorRow--;
1259 Mode->CursorColumn = (INT32) MaxColumn;
1260 }
1261
1262 //
1263 // If the cursor is not at the left edge of the display,
1264 // then move the cursor left one column.
1265 //
1266 if (Mode->CursorColumn > 0) {
1267 Mode->CursorColumn--;
1268 if (Mode->CursorColumn > 0 &&
1269 NullAttributes[Mode->CursorRow * MaxColumn + Mode->CursorColumn - 1] & EFI_WIDE_ATTRIBUTE
1270 ) {
1271 Mode->CursorColumn--;
1272
1273 //
1274 // Insert an extra backspace
1275 //
1276 InsertChar = CHAR_BACKSPACE;
1277 PStr = WString + 1;
1278 while (*PStr != L'\0') {
1279 TempChar = *PStr;
1280 *PStr = InsertChar;
1281 InsertChar = TempChar;
1282 PStr++;
1283 }
1284
1285 *PStr = InsertChar;
1286 *(++PStr) = 0;
1287
1288 WString++;
1289 }
1290 }
1291
1292 WString++;
1293
1294 } else if (*WString == CHAR_LINEFEED) {
1295 //
1296 // If the cursor is at the bottom of the display,
1297 // then scroll the display one row, and do not update
1298 // the cursor position. Otherwise, move the cursor down one row.
1299 //
1300 if (Mode->CursorRow == (INT32) (LastRow)) {
1301 //
1302 // Scroll Screen Up One Row
1303 //
1304 SizeAttribute = LastRow * MaxColumn;
1305 CopyMem (
1306 NullAttributes,
1307 NullAttributes + MaxColumn,
1308 SizeAttribute * sizeof (INT32)
1309 );
1310
1311 //
1312 // Each row has an ending CHAR_NULL. So one more character each line
1313 // for DevNullScreen than DevNullAttributes
1314 //
1315 SizeScreen = SizeAttribute + LastRow;
1316 CopyMem (
1317 NullScreen,
1318 NullScreen + (MaxColumn + 1),
1319 SizeScreen * sizeof (CHAR16)
1320 );
1321
1322 //
1323 // Print Blank Line at last line
1324 //
1325 Screen = NullScreen + SizeScreen;
1326 Attribute = NullAttributes + SizeAttribute;
1327
1328 for (Index = 0; Index < MaxColumn; Index++, Screen++, Attribute++) {
1329 *Screen = L' ';
1330 *Attribute = Mode->Attribute;
1331 }
1332 } else {
1333 Mode->CursorRow++;
1334 }
1335
1336 WString++;
1337 } else if (*WString == CHAR_CARRIAGE_RETURN) {
1338 //
1339 // Move the cursor to the beginning of the current row.
1340 //
1341 Mode->CursorColumn = 0;
1342 WString++;
1343 } else {
1344 //
1345 // Print the character at the current cursor position and
1346 // move the cursor right one column. If this moves the cursor
1347 // past the right edge of the display, then the line should wrap to
1348 // the beginning of the next line. This is equivalent to inserting
1349 // a CR and an LF. Note that if the cursor is at the bottom of the
1350 // display, and the line wraps, then the display will be scrolled
1351 // one line.
1352 //
1353 Index = Mode->CursorRow * MaxColumn + Mode->CursorColumn;
1354
1355 while (Mode->CursorColumn < (INT32) MaxColumn) {
1356 if (*WString == CHAR_NULL) {
1357 break;
1358 }
1359
1360 if (*WString == CHAR_BACKSPACE) {
1361 break;
1362 }
1363
1364 if (*WString == CHAR_LINEFEED) {
1365 break;
1366 }
1367
1368 if (*WString == CHAR_CARRIAGE_RETURN) {
1369 break;
1370 }
1371
1372 if (*WString == UNICODE_WIDE_CHAR || *WString == UNICODE_NARROW_CHAR) {
1373 CurrentWidth = (*WString == UNICODE_WIDE_CHAR) ? 2 : 1;
1374 WString++;
1375 continue;
1376 }
1377
1378 if (Mode->CursorColumn + CurrentWidth > (INT32) MaxColumn) {
1379 //
1380 // If a wide char is at the rightmost column, then move the char
1381 // to the beginning of the next row
1382 //
1383 NullScreen[Index + Mode->CursorRow] = L' ';
1384 NullAttributes[Index] = Mode->Attribute | (UINT32) EFI_WIDE_ATTRIBUTE;
1385 Index++;
1386 Mode->CursorColumn++;
1387 } else {
1388 NullScreen[Index + Mode->CursorRow] = *WString;
1389 NullAttributes[Index] = Mode->Attribute;
1390 if (CurrentWidth == 1) {
1391 NullAttributes[Index] &= (~ (UINT32) EFI_WIDE_ATTRIBUTE);
1392 } else {
1393 NullAttributes[Index] |= (UINT32) EFI_WIDE_ATTRIBUTE;
1394 NullAttributes[Index + 1] &= (~ (UINT32) EFI_WIDE_ATTRIBUTE);
1395 }
1396
1397 Index += CurrentWidth;
1398 WString++;
1399 Mode->CursorColumn += CurrentWidth;
1400 }
1401 }
1402 //
1403 // At the end of line, output carriage return and line feed
1404 //
1405 if (Mode->CursorColumn >= (INT32) MaxColumn) {
1406 DevNullTextOutOutputString (Private, mCrLfString);
1407 }
1408 }
1409 }
1410
1411 return EFI_SUCCESS;
1412 }
1413
1414
1415 /**
1416 Sets the output device(s) to a specified mode.
1417
1418 @param Private Text Out Splitter pointer.
1419 @param ModeNumber The mode number to set.
1420
1421 @retval EFI_SUCCESS The requested text mode was set.
1422 @retval EFI_DEVICE_ERROR The device had an error and could not complete
1423 the request.
1424 @retval EFI_UNSUPPORTED The mode number was not valid.
1425 @retval EFI_OUT_OF_RESOURCES Out of resources.
1426
1427 **/
1428 EFI_STATUS
1429 DevNullTextOutSetMode (
1430 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1431 IN UINTN ModeNumber
1432 )
1433 {
1434 UINTN Size;
1435 INT32 CurrentMode;
1436 UINTN Row;
1437 UINTN Column;
1438 TEXT_OUT_SPLITTER_QUERY_DATA *Mode;
1439
1440 //
1441 // No extra check for ModeNumber here, as it has been checked in
1442 // ConSplitterTextOutSetMode. And mode 0 should always be supported.
1443 // Row and Column should be fetched from intersection map.
1444 //
1445 if (Private->TextOutModeMap != NULL) {
1446 CurrentMode = *(Private->TextOutModeMap + Private->TextOutListCount * ModeNumber);
1447 } else {
1448 CurrentMode = (INT32) (ModeNumber);
1449 }
1450 Mode = &(Private->TextOutQueryData[CurrentMode]);
1451 Row = Mode->Rows;
1452 Column = Mode->Columns;
1453
1454 if (Row == 0 || Column == 0) {
1455 return EFI_UNSUPPORTED;
1456 }
1457
1458 if (Private->TextOutMode.Mode != (INT32) ModeNumber) {
1459
1460 Private->TextOutMode.Mode = (INT32) ModeNumber;
1461 Private->DevNullColumns = Column;
1462 Private->DevNullRows = Row;
1463
1464 if (Private->DevNullScreen != NULL) {
1465 FreePool (Private->DevNullScreen);
1466 }
1467
1468 Size = (Row * (Column + 1)) * sizeof (CHAR16);
1469 Private->DevNullScreen = AllocateZeroPool (Size);
1470 if (Private->DevNullScreen == NULL) {
1471 return EFI_OUT_OF_RESOURCES;
1472 }
1473
1474 if (Private->DevNullAttributes != NULL) {
1475 FreePool (Private->DevNullAttributes);
1476 }
1477
1478 Size = Row * Column * sizeof (INT32);
1479 Private->DevNullAttributes = AllocateZeroPool (Size);
1480 if (Private->DevNullAttributes == NULL) {
1481 return EFI_OUT_OF_RESOURCES;
1482 }
1483 }
1484
1485 DevNullTextOutClearScreen (Private);
1486
1487 return EFI_SUCCESS;
1488 }
1489
1490
1491 /**
1492 Clears the output device(s) display to the currently selected background
1493 color.
1494
1495 @param Private Text Out Splitter pointer.
1496
1497 @retval EFI_SUCCESS The operation completed successfully.
1498 @retval EFI_DEVICE_ERROR The device had an error and could not complete
1499 the request.
1500 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1501
1502 **/
1503 EFI_STATUS
1504 DevNullTextOutClearScreen (
1505 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
1506 )
1507 {
1508 UINTN Row;
1509 UINTN Column;
1510 CHAR16 *Screen;
1511 INT32 *Attributes;
1512 INT32 CurrentAttribute;
1513
1514 //
1515 // Clear the DevNull Text Out Buffers.
1516 // The screen is filled with spaces.
1517 // The attributes are all synced with the current Simple Text Out Attribute
1518 //
1519 Screen = Private->DevNullScreen;
1520 Attributes = Private->DevNullAttributes;
1521 CurrentAttribute = Private->TextOutMode.Attribute;
1522
1523 for (Row = 0; Row < Private->DevNullRows; Row++) {
1524 for (Column = 0; Column < Private->DevNullColumns; Column++, Screen++, Attributes++) {
1525 *Screen = L' ';
1526 *Attributes = CurrentAttribute;
1527 }
1528 //
1529 // Each line of the screen has a NULL on the end so we must skip over it
1530 //
1531 Screen++;
1532 }
1533
1534 DevNullTextOutSetCursorPosition (Private, 0, 0);
1535
1536 return DevNullTextOutEnableCursor (Private, TRUE);
1537 }
1538
1539
1540 /**
1541 Sets the current coordinates of the cursor position on NULL device.
1542
1543 @param Private Text Out Splitter pointer.
1544 @param Column The column position to set the cursor to. Must be
1545 greater than or equal to zero and less than the
1546 number of columns by QueryMode ().
1547 @param Row The row position to set the cursor to. Must be
1548 greater than or equal to zero and less than the
1549 number of rows by QueryMode ().
1550
1551 @retval EFI_SUCCESS Always returned.
1552
1553 **/
1554 EFI_STATUS
1555 DevNullTextOutSetCursorPosition (
1556 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1557 IN UINTN Column,
1558 IN UINTN Row
1559 )
1560 {
1561 //
1562 // No need to do extra check here as whether (Column, Row) is valid has
1563 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
1564 // always be supported.
1565 //
1566 Private->TextOutMode.CursorColumn = (INT32) Column;
1567 Private->TextOutMode.CursorRow = (INT32) Row;
1568
1569 return EFI_SUCCESS;
1570 }
1571
1572
1573 /**
1574 Set cursor visibility property on NULL device.
1575
1576 @param Private Text Out Splitter pointer.
1577 @param Visible If TRUE, the cursor is set to be visible, If
1578 FALSE, the cursor is set to be invisible.
1579
1580 @retval EFI_SUCCESS Always returned.
1581
1582 **/
1583 EFI_STATUS
1584 DevNullTextOutEnableCursor (
1585 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1586 IN BOOLEAN Visible
1587 )
1588 {
1589 Private->TextOutMode.CursorVisible = Visible;
1590
1591 return EFI_SUCCESS;
1592 }
1593
1594
1595 /**
1596 Take the DevNull TextOut device and update the Simple Text Out on every
1597 UGA device.
1598
1599 @param Private Text Out Splitter pointer.
1600
1601 @retval EFI_SUCCESS The request is valid.
1602 @retval other Return status of TextOut->OutputString ()
1603
1604 **/
1605 EFI_STATUS
1606 DevNullSyncStdOut (
1607 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
1608 )
1609 {
1610 EFI_STATUS Status;
1611 EFI_STATUS ReturnStatus;
1612 UINTN Row;
1613 UINTN Column;
1614 UINTN List;
1615 UINTN MaxColumn;
1616 UINTN CurrentColumn;
1617 UINTN StartRow;
1618 UINTN StartColumn;
1619 INT32 StartAttribute;
1620 BOOLEAN StartCursorState;
1621 CHAR16 *Screen;
1622 CHAR16 *Str;
1623 CHAR16 *Buffer;
1624 CHAR16 *BufferTail;
1625 CHAR16 *ScreenStart;
1626 INT32 CurrentAttribute;
1627 INT32 *Attributes;
1628 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
1629
1630 //
1631 // Save the devices Attributes, Cursor enable state and location
1632 //
1633 StartColumn = Private->TextOutMode.CursorColumn;
1634 StartRow = Private->TextOutMode.CursorRow;
1635 StartAttribute = Private->TextOutMode.Attribute;
1636 StartCursorState = Private->TextOutMode.CursorVisible;
1637
1638 for (List = 0; List < Private->CurrentNumberOfConsoles; List++) {
1639
1640 Sto = Private->TextOutList[List].TextOut;
1641
1642 //
1643 // Skip non GOP/UGA devices
1644 //
1645 if ((Private->TextOutList[List].GraphicsOutput != NULL) || (Private->TextOutList[List].UgaDraw != NULL)) {
1646 Sto->EnableCursor (Sto, FALSE);
1647 Sto->ClearScreen (Sto);
1648 }
1649 }
1650
1651 ReturnStatus = EFI_SUCCESS;
1652 Screen = Private->DevNullScreen;
1653 Attributes = Private->DevNullAttributes;
1654 MaxColumn = Private->DevNullColumns;
1655
1656 Buffer = AllocateZeroPool ((MaxColumn + 1) * sizeof (CHAR16));
1657 if (Buffer == NULL) {
1658 return ReturnStatus;
1659 }
1660
1661 for (Row = 0; Row < Private->DevNullRows; Row++, Screen += (MaxColumn + 1), Attributes += MaxColumn) {
1662
1663 if (Row == (Private->DevNullRows - 1)) {
1664 //
1665 // Don't ever sync the last character as it will scroll the screen
1666 //
1667 Screen[MaxColumn - 1] = 0x00;
1668 }
1669
1670 Column = 0;
1671 while (Column < MaxColumn) {
1672 if (Screen[Column] > 0) {
1673 CurrentAttribute = Attributes[Column];
1674 CurrentColumn = Column;
1675 ScreenStart = &Screen[Column];
1676
1677 //
1678 // the line end is alway 0x0. So Column should be less than MaxColumn
1679 // It should be still in the same row
1680 //
1681 for (Str = ScreenStart, BufferTail = Buffer; *Str != 0; Str++, Column++) {
1682
1683 if (Attributes[Column] != CurrentAttribute) {
1684 Column--;
1685 break;
1686 }
1687
1688 *BufferTail = *Str;
1689 BufferTail++;
1690 if ((Attributes[Column] & EFI_WIDE_ATTRIBUTE) != 0) {
1691 Str++;
1692 Column++;
1693 }
1694 }
1695
1696 *BufferTail = 0;
1697
1698 for (List = 0; List < Private->CurrentNumberOfConsoles; List++) {
1699
1700 Sto = Private->TextOutList[List].TextOut;
1701
1702 //
1703 // Skip non GOP/UGA devices
1704 //
1705 if ((Private->TextOutList[List].GraphicsOutput != NULL) || (Private->TextOutList[List].UgaDraw != NULL)) {
1706 Sto->SetAttribute (Sto, CurrentAttribute);
1707 Sto->SetCursorPosition (Sto, CurrentColumn, Row);
1708 Status = Sto->OutputString (Sto, Buffer);
1709 if (EFI_ERROR (Status)) {
1710 ReturnStatus = Status;
1711 }
1712 }
1713 }
1714
1715 }
1716
1717 Column++;
1718 }
1719 }
1720 //
1721 // Restore the devices Attributes, Cursor enable state and location
1722 //
1723 for (List = 0; List < Private->CurrentNumberOfConsoles; List++) {
1724 Sto = Private->TextOutList[List].TextOut;
1725
1726 //
1727 // Skip non GOP/UGA devices
1728 //
1729 if ((Private->TextOutList[List].GraphicsOutput != NULL) || (Private->TextOutList[List].UgaDraw != NULL)) {
1730 Sto->SetAttribute (Sto, StartAttribute);
1731 Sto->SetCursorPosition (Sto, StartColumn, StartRow);
1732 Status = Sto->EnableCursor (Sto, StartCursorState);
1733 if (EFI_ERROR (Status)) {
1734 ReturnStatus = Status;
1735 }
1736 }
1737 }
1738
1739 FreePool (Buffer);
1740
1741 return ReturnStatus;
1742 }