2 Support for Graphics output spliter.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "ConSplitter.h"
19 CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
22 Returns information for an available graphics mode that the graphics device
23 and the set of active video output devices supports.
25 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
26 @param ModeNumber The mode number to return information on.
27 @param SizeOfInfo A pointer to the size, in bytes, of the Info buffer.
28 @param Info A pointer to callee allocated buffer that returns information about ModeNumber.
30 @retval EFI_SUCCESS Mode information returned.
31 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
32 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the video mode.
33 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
34 @retval EFI_OUT_OF_RESOURCES No resource available.
39 ConSplitterGraphicsOutputQueryMode (
40 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
42 OUT UINTN
*SizeOfInfo
,
43 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
46 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
48 if (This
== NULL
|| Info
== NULL
|| SizeOfInfo
== NULL
|| ModeNumber
>= This
->Mode
->MaxMode
) {
49 return EFI_INVALID_PARAMETER
;
53 // retrieve private data
55 Private
= GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
57 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
59 return EFI_OUT_OF_RESOURCES
;
62 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
64 CopyMem (*Info
, &Private
->GraphicsOutputModeBuffer
[ModeNumber
], *SizeOfInfo
);
71 Set the video device into the specified mode and clears the visible portions of
72 the output display to black.
74 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
75 @param ModeNumber Abstraction that defines the current video mode.
77 @retval EFI_SUCCESS The graphics mode specified by ModeNumber was selected.
78 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
79 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
80 @retval EFI_OUT_OF_RESOURCES No resource available.
85 ConSplitterGraphicsOutputSetMode (
86 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
91 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
93 EFI_STATUS ReturnStatus
;
94 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Mode
;
95 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
98 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
99 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
101 if (ModeNumber
>= This
->Mode
->MaxMode
) {
102 return EFI_UNSUPPORTED
;
105 Private
= GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
106 Mode
= &Private
->GraphicsOutputModeBuffer
[ModeNumber
];
108 ReturnStatus
= EFI_SUCCESS
;
110 // return the worst status met
112 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
113 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
114 if (GraphicsOutput
!= NULL
) {
116 // Find corresponding ModeNumber of this GraphicsOutput instance
118 for (NumberIndex
= 0; NumberIndex
< GraphicsOutput
->Mode
->MaxMode
; NumberIndex
++) {
119 Status
= GraphicsOutput
->QueryMode (GraphicsOutput
, (UINT32
) NumberIndex
, &SizeOfInfo
, &Info
);
120 if (EFI_ERROR (Status
)) {
123 if ((Info
->HorizontalResolution
== Mode
->HorizontalResolution
) && (Info
->VerticalResolution
== Mode
->VerticalResolution
)) {
130 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, (UINT32
) NumberIndex
);
131 if (EFI_ERROR (Status
)) {
132 ReturnStatus
= Status
;
134 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
135 UgaDraw
= Private
->TextOutList
[Index
].UgaDraw
;
136 if (UgaDraw
!= NULL
) {
137 Status
= UgaDraw
->SetMode (
139 Mode
->HorizontalResolution
,
140 Mode
->VerticalResolution
,
144 if (EFI_ERROR (Status
)) {
145 ReturnStatus
= Status
;
151 This
->Mode
->Mode
= ModeNumber
;
153 CopyMem (This
->Mode
->Info
, &Private
->GraphicsOutputModeBuffer
[ModeNumber
], This
->Mode
->SizeOfInfo
);
156 // Information is not enough here, so the following items remain unchanged:
157 // GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat
158 // GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
159 // These items will be initialized/updated when a new GOP device is added into ConsoleSplitter.
168 The following table defines actions for BltOperations.
170 EfiBltVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY)
171 directly to every pixel of the video display rectangle
172 (DestinationX, DestinationY)
173 (DestinationX + Width, DestinationY + Height).
174 Only one pixel will be used from the BltBuffer. Delta is NOT used.
175 EfiBltVideoToBltBuffer - Read data from the video display rectangle
176 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
177 the BltBuffer rectangle (DestinationX, DestinationY )
178 (DestinationX + Width, DestinationY + Height). If DestinationX or
179 DestinationY is not zero then Delta must be set to the length in bytes
180 of a row in the BltBuffer.
181 EfiBltBufferToVideo - Write data from the BltBuffer rectangle
182 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
183 video display rectangle (DestinationX, DestinationY)
184 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
185 not zero then Delta must be set to the length in bytes of a row in the
187 EfiBltVideoToVideo - Copy from the video display rectangle
188 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
189 to the video display rectangle (DestinationX, DestinationY)
190 (DestinationX + Width, DestinationY + Height).
191 The BltBuffer and Delta are not used in this mode.
193 @param This Protocol instance pointer.
194 @param BltBuffer Buffer containing data to blit into video buffer.
195 This buffer has a size of
196 Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
197 @param BltOperation Operation to perform on BlitBuffer and video
199 @param SourceX X coordinate of source for the BltBuffer.
200 @param SourceY Y coordinate of source for the BltBuffer.
201 @param DestinationX X coordinate of destination for the BltBuffer.
202 @param DestinationY Y coordinate of destination for the BltBuffer.
203 @param Width Width of rectangle in BltBuffer in pixels.
204 @param Height Hight of rectangle in BltBuffer in pixels.
205 @param Delta OPTIONAL.
207 @retval EFI_SUCCESS The Blt operation completed.
208 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
209 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video
215 ConSplitterGraphicsOutputBlt (
216 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
217 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
218 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
221 IN UINTN DestinationX
,
222 IN UINTN DestinationY
,
225 IN UINTN Delta OPTIONAL
229 EFI_STATUS ReturnStatus
;
230 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
232 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
233 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
235 if (This
== NULL
|| ((UINTN
) BltOperation
) >= EfiGraphicsOutputBltOperationMax
) {
236 return EFI_INVALID_PARAMETER
;
239 Private
= GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
241 ReturnStatus
= EFI_SUCCESS
;
244 // return the worst status met
246 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
247 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
248 if (GraphicsOutput
!= NULL
) {
249 Status
= GraphicsOutput
->Blt (
261 if (EFI_ERROR (Status
)) {
262 ReturnStatus
= Status
;
263 } else if (BltOperation
== EfiBltVideoToBltBuffer
) {
265 // Only need to read the data into buffer one time
271 UgaDraw
= Private
->TextOutList
[Index
].UgaDraw
;
272 if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
273 Status
= UgaDraw
->Blt (
275 (EFI_UGA_PIXEL
*) BltBuffer
,
276 (EFI_UGA_BLT_OPERATION
) BltOperation
,
285 if (EFI_ERROR (Status
)) {
286 ReturnStatus
= Status
;
287 } else if (BltOperation
== EfiBltVideoToBltBuffer
) {
289 // Only need to read the data into buffer one time
300 Return the current video mode information.
302 @param This The EFI_UGA_DRAW_PROTOCOL instance.
303 @param HorizontalResolution The size of video screen in pixels in the X dimension.
304 @param VerticalResolution The size of video screen in pixels in the Y dimension.
305 @param ColorDepth Number of bits per pixel, currently defined to be 32.
306 @param RefreshRate The refresh rate of the monitor in Hertz.
308 @retval EFI_SUCCESS Mode information returned.
309 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
310 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
315 ConSplitterUgaDrawGetMode (
316 IN EFI_UGA_DRAW_PROTOCOL
*This
,
317 OUT UINT32
*HorizontalResolution
,
318 OUT UINT32
*VerticalResolution
,
319 OUT UINT32
*ColorDepth
,
320 OUT UINT32
*RefreshRate
323 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
325 if ((HorizontalResolution
== NULL
) ||
326 (VerticalResolution
== NULL
) ||
327 (RefreshRate
== NULL
) ||
328 (ColorDepth
== NULL
)) {
329 return EFI_INVALID_PARAMETER
;
332 // retrieve private data
334 Private
= UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
336 *HorizontalResolution
= Private
->UgaHorizontalResolution
;
337 *VerticalResolution
= Private
->UgaVerticalResolution
;
338 *ColorDepth
= Private
->UgaColorDepth
;
339 *RefreshRate
= Private
->UgaRefreshRate
;
346 Set the current video mode information.
348 @param This The EFI_UGA_DRAW_PROTOCOL instance.
349 @param HorizontalResolution The size of video screen in pixels in the X dimension.
350 @param VerticalResolution The size of video screen in pixels in the Y dimension.
351 @param ColorDepth Number of bits per pixel, currently defined to be 32.
352 @param RefreshRate The refresh rate of the monitor in Hertz.
354 @retval EFI_SUCCESS Mode information returned.
355 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
356 @retval EFI_OUT_OF_RESOURCES Out of resources.
361 ConSplitterUgaDrawSetMode (
362 IN EFI_UGA_DRAW_PROTOCOL
*This
,
363 IN UINT32 HorizontalResolution
,
364 IN UINT32 VerticalResolution
,
365 IN UINT32 ColorDepth
,
366 IN UINT32 RefreshRate
370 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
372 EFI_STATUS ReturnStatus
;
373 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
376 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
377 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
379 Private
= UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
381 ReturnStatus
= EFI_SUCCESS
;
384 // Update the Mode data
386 Private
->UgaHorizontalResolution
= HorizontalResolution
;
387 Private
->UgaVerticalResolution
= VerticalResolution
;
388 Private
->UgaColorDepth
= ColorDepth
;
389 Private
->UgaRefreshRate
= RefreshRate
;
392 // return the worst status met
394 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
396 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
397 if (GraphicsOutput
!= NULL
) {
399 // Find corresponding ModeNumber of this GraphicsOutput instance
401 for (NumberIndex
= 0; NumberIndex
< GraphicsOutput
->Mode
->MaxMode
; NumberIndex
++) {
402 Status
= GraphicsOutput
->QueryMode (GraphicsOutput
, (UINT32
) NumberIndex
, &SizeOfInfo
, &Info
);
403 if (EFI_ERROR (Status
)) {
406 if ((Info
->HorizontalResolution
== HorizontalResolution
) && (Info
->VerticalResolution
== VerticalResolution
)) {
413 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, (UINT32
) NumberIndex
);
414 if (EFI_ERROR (Status
)) {
415 ReturnStatus
= Status
;
417 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)){
418 UgaDraw
= Private
->TextOutList
[Index
].UgaDraw
;
419 if (UgaDraw
!= NULL
) {
420 Status
= UgaDraw
->SetMode (
422 HorizontalResolution
,
427 if (EFI_ERROR (Status
)) {
428 ReturnStatus
= Status
;
439 Blt a rectangle of pixels on the graphics screen.
441 The following table defines actions for BltOperations.
444 Write data from the BltBuffer pixel (SourceX, SourceY)
445 directly to every pixel of the video display rectangle
446 (DestinationX, DestinationY)
447 (DestinationX + Width, DestinationY + Height).
448 Only one pixel will be used from the BltBuffer. Delta is NOT used.
449 EfiUgaVideoToBltBuffer:
450 Read data from the video display rectangle
451 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
452 the BltBuffer rectangle (DestinationX, DestinationY )
453 (DestinationX + Width, DestinationY + Height). If DestinationX or
454 DestinationY is not zero then Delta must be set to the length in bytes
455 of a row in the BltBuffer.
456 EfiUgaBltBufferToVideo:
457 Write data from the BltBuffer rectangle
458 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
459 video display rectangle (DestinationX, DestinationY)
460 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
461 not zero then Delta must be set to the length in bytes of a row in the
464 Copy from the video display rectangle
465 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
466 to the video display rectangle (DestinationX, DestinationY)
467 (DestinationX + Width, DestinationY + Height).
468 The BltBuffer and Delta are not used in this mode.
470 @param This Protocol instance pointer.
471 @param BltBuffer Buffer containing data to blit into video buffer. This
472 buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
473 @param BltOperation Operation to perform on BlitBuffer and video memory
474 @param SourceX X coordinate of source for the BltBuffer.
475 @param SourceY Y coordinate of source for the BltBuffer.
476 @param DestinationX X coordinate of destination for the BltBuffer.
477 @param DestinationY Y coordinate of destination for the BltBuffer.
478 @param Width Width of rectangle in BltBuffer in pixels.
479 @param Height Hight of rectangle in BltBuffer in pixels.
480 @param Delta OPTIONAL
482 @retval EFI_SUCCESS The Blt operation completed.
483 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
484 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
489 ConSplitterUgaDrawBlt (
490 IN EFI_UGA_DRAW_PROTOCOL
*This
,
491 IN EFI_UGA_PIXEL
*BltBuffer
, OPTIONAL
492 IN EFI_UGA_BLT_OPERATION BltOperation
,
495 IN UINTN DestinationX
,
496 IN UINTN DestinationY
,
499 IN UINTN Delta OPTIONAL
503 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
505 EFI_STATUS ReturnStatus
;
506 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
508 Private
= UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
510 ReturnStatus
= EFI_SUCCESS
;
512 // return the worst status met
514 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
515 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
516 if (GraphicsOutput
!= NULL
) {
517 Status
= GraphicsOutput
->Blt (
519 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltBuffer
,
520 (EFI_GRAPHICS_OUTPUT_BLT_OPERATION
) BltOperation
,
529 if (EFI_ERROR (Status
)) {
530 ReturnStatus
= Status
;
531 } else if (BltOperation
== EfiUgaVideoToBltBuffer
) {
533 // Only need to read the data into buffer one time
539 if (Private
->TextOutList
[Index
].UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
540 Status
= Private
->TextOutList
[Index
].UgaDraw
->Blt (
541 Private
->TextOutList
[Index
].UgaDraw
,
552 if (EFI_ERROR (Status
)) {
553 ReturnStatus
= Status
;
554 } else if (BltOperation
== EfiUgaVideoToBltBuffer
) {
556 // Only need to read the data into buffer one time
567 Sets the output device(s) to a specified mode.
569 @param Private Text Out Splitter pointer.
570 @param ModeNumber The mode number to set.
575 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
,
580 // No need to do extra check here as whether (Column, Row) is valid has
581 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
582 // always be supported.
584 Private
->TextOutMode
.Mode
= (INT32
) ModeNumber
;
585 Private
->TextOutMode
.CursorColumn
= 0;
586 Private
->TextOutMode
.CursorRow
= 0;
587 Private
->TextOutMode
.CursorVisible
= TRUE
;