2 Support for Graphics output spliter.
4 Copyright (c) 2006 - 2010, Intel Corporation. <BR>
5 All rights reserved. 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_NOT_STARTED Video display is not initialized. Call SetMode ()
34 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
35 @retval EFI_OUT_OF_RESOURCES No resource available.
40 ConSplitterGraphicsOutputQueryMode (
41 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
43 OUT UINTN
*SizeOfInfo
,
44 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
47 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
49 if (This
== NULL
|| Info
== NULL
|| SizeOfInfo
== NULL
|| ModeNumber
>= This
->Mode
->MaxMode
) {
50 return EFI_INVALID_PARAMETER
;
54 // retrieve private data
56 Private
= GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
58 if (Private
->HardwareNeedsStarting
) {
59 return EFI_NOT_STARTED
;
62 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
64 return EFI_OUT_OF_RESOURCES
;
67 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
69 CopyMem (*Info
, &Private
->GraphicsOutputModeBuffer
[ModeNumber
], *SizeOfInfo
);
76 Set the video device into the specified mode and clears the visible portions of
77 the output display to black.
79 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
80 @param ModeNumber Abstraction that defines the current video mode.
82 @retval EFI_SUCCESS The graphics mode specified by ModeNumber was selected.
83 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
84 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
85 @retval EFI_OUT_OF_RESOURCES No resource available.
90 ConSplitterGraphicsOutputSetMode (
91 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
96 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
98 EFI_STATUS ReturnStatus
;
99 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Mode
;
100 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
103 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
104 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
106 if (ModeNumber
>= This
->Mode
->MaxMode
) {
107 return EFI_UNSUPPORTED
;
110 Private
= GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
111 Mode
= &Private
->GraphicsOutputModeBuffer
[ModeNumber
];
113 ReturnStatus
= EFI_SUCCESS
;
115 // return the worst status met
117 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
118 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
119 if (GraphicsOutput
!= NULL
) {
121 // Find corresponding ModeNumber of this GraphicsOutput instance
123 for (NumberIndex
= 0; NumberIndex
< GraphicsOutput
->Mode
->MaxMode
; NumberIndex
++) {
124 Status
= GraphicsOutput
->QueryMode (GraphicsOutput
, (UINT32
) NumberIndex
, &SizeOfInfo
, &Info
);
125 if (EFI_ERROR (Status
)) {
128 if ((Info
->HorizontalResolution
== Mode
->HorizontalResolution
) && (Info
->VerticalResolution
== Mode
->VerticalResolution
)) {
135 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, (UINT32
) NumberIndex
);
136 if (EFI_ERROR (Status
)) {
137 ReturnStatus
= Status
;
139 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
140 UgaDraw
= Private
->TextOutList
[Index
].UgaDraw
;
141 if (UgaDraw
!= NULL
) {
142 Status
= UgaDraw
->SetMode (
144 Mode
->HorizontalResolution
,
145 Mode
->VerticalResolution
,
149 if (EFI_ERROR (Status
)) {
150 ReturnStatus
= Status
;
156 This
->Mode
->Mode
= ModeNumber
;
158 CopyMem (This
->Mode
->Info
, &Private
->GraphicsOutputModeBuffer
[ModeNumber
], This
->Mode
->SizeOfInfo
);
161 // Information is not enough here, so the following items remain unchanged:
162 // GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat
163 // GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
164 // These items will be initialized/updated when a new GOP device is added into ConsoleSplitter.
167 Private
->HardwareNeedsStarting
= FALSE
;
175 The following table defines actions for BltOperations.
177 EfiBltVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY)
178 directly to every pixel of the video display rectangle
179 (DestinationX, DestinationY)
180 (DestinationX + Width, DestinationY + Height).
181 Only one pixel will be used from the BltBuffer. Delta is NOT used.
182 EfiBltVideoToBltBuffer - Read data from the video display rectangle
183 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
184 the BltBuffer rectangle (DestinationX, DestinationY )
185 (DestinationX + Width, DestinationY + Height). If DestinationX or
186 DestinationY is not zero then Delta must be set to the length in bytes
187 of a row in the BltBuffer.
188 EfiBltBufferToVideo - Write data from the BltBuffer rectangle
189 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
190 video display rectangle (DestinationX, DestinationY)
191 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
192 not zero then Delta must be set to the length in bytes of a row in the
194 EfiBltVideoToVideo - Copy from the video display rectangle
195 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
196 to the video display rectangle (DestinationX, DestinationY)
197 (DestinationX + Width, DestinationY + Height).
198 The BltBuffer and Delta are not used in this mode.
200 @param This Protocol instance pointer.
201 @param BltBuffer Buffer containing data to blit into video buffer.
202 This buffer has a size of
203 Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
204 @param BltOperation Operation to perform on BlitBuffer and video
206 @param SourceX X coordinate of source for the BltBuffer.
207 @param SourceY Y coordinate of source for the BltBuffer.
208 @param DestinationX X coordinate of destination for the BltBuffer.
209 @param DestinationY Y coordinate of destination for the BltBuffer.
210 @param Width Width of rectangle in BltBuffer in pixels.
211 @param Height Hight of rectangle in BltBuffer in pixels.
212 @param Delta OPTIONAL.
214 @retval EFI_SUCCESS The Blt operation completed.
215 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
216 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video
222 ConSplitterGraphicsOutputBlt (
223 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
224 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
225 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
228 IN UINTN DestinationX
,
229 IN UINTN DestinationY
,
232 IN UINTN Delta OPTIONAL
236 EFI_STATUS ReturnStatus
;
237 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
239 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
240 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
242 if (This
== NULL
|| ((UINTN
) BltOperation
) >= EfiGraphicsOutputBltOperationMax
) {
243 return EFI_INVALID_PARAMETER
;
246 Private
= GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
248 ReturnStatus
= EFI_SUCCESS
;
251 // return the worst status met
253 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
254 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
255 if (GraphicsOutput
!= NULL
) {
256 Status
= GraphicsOutput
->Blt (
268 if (EFI_ERROR (Status
)) {
269 ReturnStatus
= Status
;
270 } else if (BltOperation
== EfiBltVideoToBltBuffer
) {
272 // Only need to read the data into buffer one time
278 UgaDraw
= Private
->TextOutList
[Index
].UgaDraw
;
279 if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
280 Status
= UgaDraw
->Blt (
282 (EFI_UGA_PIXEL
*) BltBuffer
,
283 (EFI_UGA_BLT_OPERATION
) BltOperation
,
292 if (EFI_ERROR (Status
)) {
293 ReturnStatus
= Status
;
294 } else if (BltOperation
== EfiBltVideoToBltBuffer
) {
296 // Only need to read the data into buffer one time
307 Return the current video mode information.
309 @param This The EFI_UGA_DRAW_PROTOCOL instance.
310 @param HorizontalResolution The size of video screen in pixels in the X dimension.
311 @param VerticalResolution The size of video screen in pixels in the Y dimension.
312 @param ColorDepth Number of bits per pixel, currently defined to be 32.
313 @param RefreshRate The refresh rate of the monitor in Hertz.
315 @retval EFI_SUCCESS Mode information returned.
316 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
317 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
322 ConSplitterUgaDrawGetMode (
323 IN EFI_UGA_DRAW_PROTOCOL
*This
,
324 OUT UINT32
*HorizontalResolution
,
325 OUT UINT32
*VerticalResolution
,
326 OUT UINT32
*ColorDepth
,
327 OUT UINT32
*RefreshRate
330 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
332 if ((HorizontalResolution
== NULL
) ||
333 (VerticalResolution
== NULL
) ||
334 (RefreshRate
== NULL
) ||
335 (ColorDepth
== NULL
)) {
336 return EFI_INVALID_PARAMETER
;
339 // retrieve private data
341 Private
= UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
343 *HorizontalResolution
= Private
->UgaHorizontalResolution
;
344 *VerticalResolution
= Private
->UgaVerticalResolution
;
345 *ColorDepth
= Private
->UgaColorDepth
;
346 *RefreshRate
= Private
->UgaRefreshRate
;
353 Set the current video mode information.
355 @param This The EFI_UGA_DRAW_PROTOCOL instance.
356 @param HorizontalResolution The size of video screen in pixels in the X dimension.
357 @param VerticalResolution The size of video screen in pixels in the Y dimension.
358 @param ColorDepth Number of bits per pixel, currently defined to be 32.
359 @param RefreshRate The refresh rate of the monitor in Hertz.
361 @retval EFI_SUCCESS Mode information returned.
362 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
363 @retval EFI_OUT_OF_RESOURCES Out of resources.
368 ConSplitterUgaDrawSetMode (
369 IN EFI_UGA_DRAW_PROTOCOL
*This
,
370 IN UINT32 HorizontalResolution
,
371 IN UINT32 VerticalResolution
,
372 IN UINT32 ColorDepth
,
373 IN UINT32 RefreshRate
377 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
379 EFI_STATUS ReturnStatus
;
380 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
383 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
384 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
386 Private
= UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
388 ReturnStatus
= EFI_SUCCESS
;
391 // Update the Mode data
393 Private
->UgaHorizontalResolution
= HorizontalResolution
;
394 Private
->UgaVerticalResolution
= VerticalResolution
;
395 Private
->UgaColorDepth
= ColorDepth
;
396 Private
->UgaRefreshRate
= RefreshRate
;
399 // return the worst status met
401 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
403 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
404 if (GraphicsOutput
!= NULL
) {
406 // Find corresponding ModeNumber of this GraphicsOutput instance
408 for (NumberIndex
= 0; NumberIndex
< GraphicsOutput
->Mode
->MaxMode
; NumberIndex
++) {
409 Status
= GraphicsOutput
->QueryMode (GraphicsOutput
, (UINT32
) NumberIndex
, &SizeOfInfo
, &Info
);
410 if (EFI_ERROR (Status
)) {
413 if ((Info
->HorizontalResolution
== HorizontalResolution
) && (Info
->VerticalResolution
== VerticalResolution
)) {
420 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, (UINT32
) NumberIndex
);
421 if (EFI_ERROR (Status
)) {
422 ReturnStatus
= Status
;
424 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)){
425 UgaDraw
= Private
->TextOutList
[Index
].UgaDraw
;
426 if (UgaDraw
!= NULL
) {
427 Status
= UgaDraw
->SetMode (
429 HorizontalResolution
,
434 if (EFI_ERROR (Status
)) {
435 ReturnStatus
= Status
;
446 Blt a rectangle of pixels on the graphics screen.
448 The following table defines actions for BltOperations.
451 Write data from the BltBuffer pixel (SourceX, SourceY)
452 directly to every pixel of the video display rectangle
453 (DestinationX, DestinationY)
454 (DestinationX + Width, DestinationY + Height).
455 Only one pixel will be used from the BltBuffer. Delta is NOT used.
456 EfiUgaVideoToBltBuffer:
457 Read data from the video display rectangle
458 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
459 the BltBuffer rectangle (DestinationX, DestinationY )
460 (DestinationX + Width, DestinationY + Height). If DestinationX or
461 DestinationY is not zero then Delta must be set to the length in bytes
462 of a row in the BltBuffer.
463 EfiUgaBltBufferToVideo:
464 Write data from the BltBuffer rectangle
465 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
466 video display rectangle (DestinationX, DestinationY)
467 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
468 not zero then Delta must be set to the length in bytes of a row in the
471 Copy from the video display rectangle
472 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
473 to the video display rectangle (DestinationX, DestinationY)
474 (DestinationX + Width, DestinationY + Height).
475 The BltBuffer and Delta are not used in this mode.
477 @param This Protocol instance pointer.
478 @param BltBuffer Buffer containing data to blit into video buffer. This
479 buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
480 @param BltOperation Operation to perform on BlitBuffer and video memory
481 @param SourceX X coordinate of source for the BltBuffer.
482 @param SourceY Y coordinate of source for the BltBuffer.
483 @param DestinationX X coordinate of destination for the BltBuffer.
484 @param DestinationY Y coordinate of destination for the BltBuffer.
485 @param Width Width of rectangle in BltBuffer in pixels.
486 @param Height Hight of rectangle in BltBuffer in pixels.
487 @param Delta OPTIONAL
489 @retval EFI_SUCCESS The Blt operation completed.
490 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
491 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
496 ConSplitterUgaDrawBlt (
497 IN EFI_UGA_DRAW_PROTOCOL
*This
,
498 IN EFI_UGA_PIXEL
*BltBuffer
, OPTIONAL
499 IN EFI_UGA_BLT_OPERATION BltOperation
,
502 IN UINTN DestinationX
,
503 IN UINTN DestinationY
,
506 IN UINTN Delta OPTIONAL
510 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
512 EFI_STATUS ReturnStatus
;
513 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
515 Private
= UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
517 ReturnStatus
= EFI_SUCCESS
;
519 // return the worst status met
521 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
522 GraphicsOutput
= Private
->TextOutList
[Index
].GraphicsOutput
;
523 if (GraphicsOutput
!= NULL
) {
524 Status
= GraphicsOutput
->Blt (
526 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltBuffer
,
527 (EFI_GRAPHICS_OUTPUT_BLT_OPERATION
) BltOperation
,
536 if (EFI_ERROR (Status
)) {
537 ReturnStatus
= Status
;
538 } else if (BltOperation
== EfiBltVideoToBltBuffer
) {
540 // Only need to read the data into buffer one time
546 if (Private
->TextOutList
[Index
].UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
547 Status
= Private
->TextOutList
[Index
].UgaDraw
->Blt (
548 Private
->TextOutList
[Index
].UgaDraw
,
559 if (EFI_ERROR (Status
)) {
560 ReturnStatus
= Status
;
561 } else if (BltOperation
== EfiUgaVideoToBltBuffer
) {
563 // Only need to read the data into buffer one time
574 Sets the output device(s) to a specified mode.
576 @param Private Text Out Splitter pointer.
577 @param ModeNumber The mode number to set.
582 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
,
587 // No need to do extra check here as whether (Column, Row) is valid has
588 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
589 // always be supported.
591 Private
->TextOutMode
.Mode
= (INT32
) ModeNumber
;
592 Private
->TextOutMode
.CursorColumn
= 0;
593 Private
->TextOutMode
.CursorRow
= 0;
594 Private
->TextOutMode
.CursorVisible
= TRUE
;