]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c
1. Fixed bugs in DxeNetLib to meet consistence with network module DriverBinding...
[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 INT32 CurrentMode;
1354 UINTN Row;
1355 UINTN Column;
1356 TEXT_OUT_SPLITTER_QUERY_DATA *Mode;
1357
1358 //
1359 // No extra check for ModeNumber here, as it has been checked in
1360 // ConSplitterTextOutSetMode. And mode 0 should always be supported.
1361 // Row and Column should be fetched from intersection map.
1362 //
1363 if (Private->TextOutModeMap != NULL) {
1364 CurrentMode = *(Private->TextOutModeMap + Private->TextOutListCount * ModeNumber);
1365 } else {
1366 CurrentMode = (INT32)(ModeNumber);
1367 }
1368 Mode = &(Private->TextOutQueryData[CurrentMode]);
1369 Row = Mode->Rows;
1370 Column = Mode->Columns;
1371
1372 if (Row <= 0 && Column <= 0) {
1373 return EFI_UNSUPPORTED;
1374 }
1375
1376 if (Private->DevNullColumns != Column || Private->DevNullRows != Row) {
1377
1378 Private->TextOutMode.Mode = (INT32) ModeNumber;
1379 Private->DevNullColumns = Column;
1380 Private->DevNullRows = Row;
1381
1382 if (Private->DevNullScreen != NULL) {
1383 FreePool (Private->DevNullScreen);
1384 }
1385
1386 Size = (Row * (Column + 1)) * sizeof (CHAR16);
1387 Private->DevNullScreen = AllocateZeroPool (Size);
1388 if (Private->DevNullScreen == NULL) {
1389 return EFI_OUT_OF_RESOURCES;
1390 }
1391
1392 if (Private->DevNullAttributes != NULL) {
1393 FreePool (Private->DevNullAttributes);
1394 }
1395
1396 Size = Row * Column * sizeof (INT32);
1397 Private->DevNullAttributes = AllocateZeroPool (Size);
1398 if (Private->DevNullAttributes == NULL) {
1399 return EFI_OUT_OF_RESOURCES;
1400 }
1401 }
1402
1403 DevNullTextOutClearScreen (Private);
1404
1405 return EFI_SUCCESS;
1406 }
1407
1408 EFI_STATUS
1409 DevNullTextOutClearScreen (
1410 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
1411 )
1412 /*++
1413
1414 Routine Description:
1415 Clears the output device(s) display to the currently selected background
1416 color.
1417
1418 Arguments:
1419 Private - Protocol instance pointer.
1420
1421 Returns:
1422 EFI_SUCCESS - The operation completed successfully.
1423 EFI_DEVICE_ERROR - The device had an error and
1424 could not complete the request.
1425 EFI_UNSUPPORTED - The output device is not in a valid text mode.
1426
1427 --*/
1428 {
1429 UINTN Row;
1430 UINTN Column;
1431 CHAR16 *Screen;
1432 INT32 *Attributes;
1433 INT32 CurrentAttribute;
1434
1435 //
1436 // Clear the DevNull Text Out Buffers.
1437 // The screen is filled with spaces.
1438 // The attributes are all synced with the current Simple Text Out Attribute
1439 //
1440 Screen = Private->DevNullScreen;
1441 Attributes = Private->DevNullAttributes;
1442 CurrentAttribute = Private->TextOutMode.Attribute;
1443
1444 for (Row = 0; Row < Private->DevNullRows; Row++) {
1445 for (Column = 0; Column < Private->DevNullColumns; Column++, Screen++, Attributes++) {
1446 *Screen = ' ';
1447 *Attributes = CurrentAttribute;
1448 }
1449 //
1450 // Each line of the screen has a NULL on the end so we must skip over it
1451 //
1452 Screen++;
1453 }
1454
1455 DevNullTextOutSetCursorPosition (Private, 0, 0);
1456
1457 return DevNullTextOutEnableCursor (Private, TRUE);
1458 }
1459
1460 EFI_STATUS
1461 DevNullTextOutSetCursorPosition (
1462 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1463 IN UINTN Column,
1464 IN UINTN Row
1465 )
1466 /*++
1467
1468 Routine Description:
1469 Sets the current coordinates of the cursor position
1470
1471 Arguments:
1472 Private - Protocol instance pointer.
1473 Column, Row - the position to set the cursor to. Must be greater than or
1474 equal to zero and less than the number of columns and rows
1475 by QueryMode ().
1476
1477 Returns:
1478 EFI_SUCCESS - The operation completed successfully.
1479 EFI_DEVICE_ERROR - The device had an error and
1480 could not complete the request.
1481 EFI_UNSUPPORTED - The output device is not in a valid text mode, or the
1482 cursor position is invalid for the current mode.
1483
1484 --*/
1485 {
1486 //
1487 // No need to do extra check here as whether (Column, Row) is valid has
1488 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
1489 // always be supported.
1490 //
1491 Private->TextOutMode.CursorColumn = (INT32) Column;
1492 Private->TextOutMode.CursorRow = (INT32) Row;
1493
1494 return EFI_SUCCESS;
1495 }
1496
1497 EFI_STATUS
1498 DevNullTextOutEnableCursor (
1499 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1500 IN BOOLEAN Visible
1501 )
1502 /*++
1503 Routine Description:
1504
1505 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1506 In this driver, the cursor cannot be hidden.
1507
1508 Arguments:
1509
1510 Private - Indicates the calling context.
1511
1512 Visible - If TRUE, the cursor is set to be visible, If FALSE, the cursor
1513 is set to be invisible.
1514
1515 Returns:
1516
1517 EFI_SUCCESS - The request is valid.
1518
1519
1520 --*/
1521 {
1522 Private->TextOutMode.CursorVisible = Visible;
1523
1524 return EFI_SUCCESS;
1525 }
1526
1527 EFI_STATUS
1528 DevNullSyncStdOut (
1529 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
1530 )
1531 /*++
1532 Routine Description:
1533 Take the DevNull TextOut device and update the Simple Text Out on every
1534 UGA device.
1535
1536 Arguments:
1537 Private - Indicates the calling context.
1538
1539 Returns:
1540 EFI_SUCCESS - The request is valid.
1541 other - Return status of TextOut->OutputString ()
1542
1543 --*/
1544 {
1545 EFI_STATUS Status;
1546 EFI_STATUS ReturnStatus;
1547 UINTN Row;
1548 UINTN Column;
1549 UINTN List;
1550 UINTN MaxColumn;
1551 UINTN CurrentColumn;
1552 UINTN StartRow;
1553 UINTN StartColumn;
1554 INT32 StartAttribute;
1555 BOOLEAN StartCursorState;
1556 CHAR16 *Screen;
1557 CHAR16 *Str;
1558 CHAR16 *Buffer;
1559 CHAR16 *BufferTail;
1560 CHAR16 *ScreenStart;
1561 INT32 CurrentAttribute;
1562 INT32 *Attributes;
1563 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
1564
1565 //
1566 // Save the devices Attributes, Cursor enable state and location
1567 //
1568 StartColumn = Private->TextOutMode.CursorColumn;
1569 StartRow = Private->TextOutMode.CursorRow;
1570 StartAttribute = Private->TextOutMode.Attribute;
1571 StartCursorState = Private->TextOutMode.CursorVisible;
1572
1573 for (List = 0; List < Private->CurrentNumberOfConsoles; List++) {
1574
1575 Sto = Private->TextOutList[List].TextOut;
1576
1577 //
1578 // Skip non GOP/UGA devices
1579 //
1580 if ((Private->TextOutList[List].GraphicsOutput != NULL) || (Private->TextOutList[List].UgaDraw != NULL)) {
1581 Sto->EnableCursor (Sto, FALSE);
1582 Sto->ClearScreen (Sto);
1583 }
1584 }
1585
1586 ReturnStatus = EFI_SUCCESS;
1587 Screen = Private->DevNullScreen;
1588 Attributes = Private->DevNullAttributes;
1589 MaxColumn = Private->DevNullColumns;
1590
1591 Buffer = AllocateZeroPool ((MaxColumn + 1) * sizeof (CHAR16));
1592 if (Buffer == NULL) {
1593 return ReturnStatus;
1594 }
1595
1596 for (Row = 0; Row < Private->DevNullRows; Row++, Screen += (MaxColumn + 1), Attributes += MaxColumn) {
1597
1598 if (Row == (Private->DevNullRows - 1)) {
1599 //
1600 // Don't ever sync the last character as it will scroll the screen
1601 //
1602 Screen[MaxColumn - 1] = 0x00;
1603 }
1604
1605 Column = 0;
1606 while (Column < MaxColumn) {
1607 if (Screen[Column]) {
1608 CurrentAttribute = Attributes[Column];
1609 CurrentColumn = Column;
1610 ScreenStart = &Screen[Column];
1611
1612 //
1613 // the line end is alway 0x0. So Column should be less than MaxColumn
1614 // It should be still in the same row
1615 //
1616 for (Str = ScreenStart, BufferTail = Buffer; *Str != 0; Str++, Column++) {
1617
1618 if (Attributes[Column] != CurrentAttribute) {
1619 Column--;
1620 break;
1621 }
1622
1623 *BufferTail = *Str;
1624 BufferTail++;
1625 if (Attributes[Column] & EFI_WIDE_ATTRIBUTE) {
1626 Str++;
1627 Column++;
1628 }
1629 }
1630
1631 *BufferTail = 0;
1632
1633 for (List = 0; List < Private->CurrentNumberOfConsoles; List++) {
1634
1635 Sto = Private->TextOutList[List].TextOut;
1636
1637 //
1638 // Skip non GOP/UGA devices
1639 //
1640 if ((Private->TextOutList[List].GraphicsOutput != NULL) || (Private->TextOutList[List].UgaDraw != NULL)) {
1641 Sto->SetAttribute (Sto, CurrentAttribute);
1642 Sto->SetCursorPosition (Sto, CurrentColumn, Row);
1643 Status = Sto->OutputString (Sto, Buffer);
1644 if (EFI_ERROR (Status)) {
1645 ReturnStatus = Status;
1646 }
1647 }
1648 }
1649
1650 }
1651
1652 Column++;
1653 }
1654 }
1655 //
1656 // Restore the devices Attributes, Cursor enable state and location
1657 //
1658 for (List = 0; List < Private->CurrentNumberOfConsoles; List++) {
1659 Sto = Private->TextOutList[List].TextOut;
1660
1661 //
1662 // Skip non GOP/UGA devices
1663 //
1664 if ((Private->TextOutList[List].GraphicsOutput != NULL) || (Private->TextOutList[List].UgaDraw != NULL)) {
1665 Sto->SetAttribute (Sto, StartAttribute);
1666 Sto->SetCursorPosition (Sto, StartColumn, StartRow);
1667 Status = Sto->EnableCursor (Sto, StartCursorState);
1668 if (EFI_ERROR (Status)) {
1669 ReturnStatus = Status;
1670 }
1671 }
1672 }
1673
1674 FreePool (Buffer);
1675
1676 return ReturnStatus;
1677 }