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