3 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.
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.
19 This file produces the graphics abstration of UGA. It is called by
20 EmuGopDriver.c file which deals with the EFI 1.1 driver model.
21 This file just does graphics.
28 EFI_EVENT mGopScreenExitBootServicesEvent
;
30 GOP_MODE_DATA mGopModeData
[] = {
40 Returns information for an available graphics mode that the graphics device
41 and the set of active video output devices supports.
43 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
44 @param ModeNumber The mode number to return information on.
45 @param SizeOfInfo A pointer to the size, in bytes, of the Info buffer.
46 @param Info A pointer to callee allocated buffer that returns information about ModeNumber.
48 @retval EFI_SUCCESS Mode information returned.
49 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
50 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the video mode.
51 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
52 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
58 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
60 OUT UINTN
*SizeOfInfo
,
61 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
64 GOP_PRIVATE_DATA
*Private
;
66 Private
= GOP_PRIVATE_DATA_FROM_THIS (This
);
68 if (Info
== NULL
|| SizeOfInfo
== NULL
|| (UINTN
) ModeNumber
>= This
->Mode
->MaxMode
) {
69 return EFI_INVALID_PARAMETER
;
72 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
74 return EFI_OUT_OF_RESOURCES
;
77 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
80 (*Info
)->HorizontalResolution
= Private
->ModeData
[ModeNumber
].HorizontalResolution
;
81 (*Info
)->VerticalResolution
= Private
->ModeData
[ModeNumber
].VerticalResolution
;
82 (*Info
)->PixelFormat
= PixelBltOnly
;
83 (*Info
)->PixelsPerScanLine
= (*Info
)->HorizontalResolution
;
91 Set the video device into the specified mode and clears the visible portions of
92 the output display to black.
94 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
95 @param ModeNumber Abstraction that defines the current video mode.
97 @retval EFI_SUCCESS The graphics mode specified by ModeNumber was selected.
98 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
99 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
105 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
110 GOP_PRIVATE_DATA
*Private
;
111 GOP_MODE_DATA
*ModeData
;
112 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Fill
;
114 Private
= GOP_PRIVATE_DATA_FROM_THIS (This
);
116 if (ModeNumber
>= This
->Mode
->MaxMode
) {
117 return EFI_UNSUPPORTED
;
120 ModeData
= &Private
->ModeData
[ModeNumber
];
121 This
->Mode
->Mode
= ModeNumber
;
122 Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
= ModeData
->HorizontalResolution
;
123 Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
= ModeData
->VerticalResolution
;
124 Private
->GraphicsOutput
.Mode
->Info
->PixelsPerScanLine
= ModeData
->HorizontalResolution
;
126 if (Private
->HardwareNeedsStarting
) {
127 Status
= EmuGopStartWindow (
129 ModeData
->HorizontalResolution
,
130 ModeData
->VerticalResolution
,
131 ModeData
->ColorDepth
,
132 ModeData
->RefreshRate
134 if (EFI_ERROR (Status
)) {
135 return EFI_DEVICE_ERROR
;
138 Private
->HardwareNeedsStarting
= FALSE
;
142 Status
= Private
->EmuGraphicsWindow
->Size(
143 Private
->EmuGraphicsWindow
,
144 ModeData
->HorizontalResolution
,
145 ModeData
->VerticalResolution
160 ModeData
->HorizontalResolution
,
161 ModeData
->VerticalResolution
,
162 ModeData
->HorizontalResolution
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
170 Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer.
172 @param This Protocol instance pointer.
173 @param BltBuffer Buffer containing data to blit into video buffer. This
174 buffer has a size of Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
175 @param BltOperation Operation to perform on BlitBuffer and video memory
176 @param SourceX X coordinate of source for the BltBuffer.
177 @param SourceY Y coordinate of source for the BltBuffer.
178 @param DestinationX X coordinate of destination for the BltBuffer.
179 @param DestinationY Y coordinate of destination for the BltBuffer.
180 @param Width Width of rectangle in BltBuffer in pixels.
181 @param Height Hight of rectangle in BltBuffer in pixels.
182 @param Delta OPTIONAL
184 @retval EFI_SUCCESS The Blt operation completed.
185 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
186 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
192 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
193 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
194 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
197 IN UINTN DestinationX
,
198 IN UINTN DestinationY
,
201 IN UINTN Delta OPTIONAL
204 GOP_PRIVATE_DATA
*Private
;
207 EMU_GRAPHICS_WINDOWS__BLT_ARGS GopBltArgs
;
209 Private
= GOP_PRIVATE_DATA_FROM_THIS (This
);
211 if ((UINT32
)BltOperation
>= EfiGraphicsOutputBltOperationMax
) {
212 return EFI_INVALID_PARAMETER
;
215 if (Width
== 0 || Height
== 0) {
216 return EFI_INVALID_PARAMETER
;
219 // If Delta is zero, then the entire BltBuffer is being used, so Delta
220 // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
221 // the number of bytes in each row can be computed.
224 Delta
= Width
* sizeof (EFI_UGA_PIXEL
);
228 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
229 // We would not want a timer based event (Cursor, ...) to come in while we are
230 // doing this operation.
232 OriginalTPL
= gBS
->RaiseTPL (TPL_NOTIFY
);
235 // Pack UGA Draw protocol parameters to EMU_GRAPHICS_WINDOWS__BLT_ARGS structure to adapt to
236 // GopBlt() API of Unix UGA IO protocol.
238 GopBltArgs
.DestinationX
= DestinationX
;
239 GopBltArgs
.DestinationY
= DestinationY
;
240 GopBltArgs
.Height
= Height
;
241 GopBltArgs
.Width
= Width
;
242 GopBltArgs
.SourceX
= SourceX
;
243 GopBltArgs
.SourceY
= SourceY
;
244 GopBltArgs
.Delta
= Delta
;
245 Status
= Private
->EmuGraphicsWindow
->Blt (
246 Private
->EmuGraphicsWindow
,
247 (EFI_UGA_PIXEL
*)BltBuffer
,
248 (EFI_UGA_BLT_OPERATION
)BltOperation
,
252 gBS
->RestoreTPL (OriginalTPL
);
259 // Construction and Destruction functions
264 IN EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
268 // Check to see if the IO abstraction represents a device type we support.
270 // This would be replaced a check of PCI subsystem ID, etc.
272 if (!CompareGuid (EmuIoThunk
->Protocol
, &gEmuGraphicsWindowProtocolGuid
)) {
273 return EFI_UNSUPPORTED
;
282 IN GOP_PRIVATE_DATA
*Private
,
283 IN UINT32 HorizontalResolution
,
284 IN UINT32 VerticalResolution
,
285 IN UINT32 ColorDepth
,
286 IN UINT32 RefreshRate
292 // Register to be notified on exit boot services so we can destroy the window.
294 Status
= gBS
->CreateEvent (
295 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
299 &mGopScreenExitBootServicesEvent
302 Status
= Private
->EmuIoThunk
->Open (Private
->EmuIoThunk
);
303 if (!EFI_ERROR (Status
)) {
304 Private
->EmuGraphicsWindow
= Private
->EmuIoThunk
->Interface
;
306 // Register callback to support RegisterKeyNotify()
307 Status
= Private
->EmuGraphicsWindow
->RegisterKeyNotify (
308 Private
->EmuGraphicsWindow
,
309 GopPrivateMakeCallbackFunction
,
310 GopPrivateBreakCallbackFunction
,
313 ASSERT_EFI_ERROR (Status
);
320 GOP_PRIVATE_DATA
*Private
323 Private
->ModeData
= mGopModeData
;
325 Private
->GraphicsOutput
.QueryMode
= EmuGopQuerytMode
;
326 Private
->GraphicsOutput
.SetMode
= EmuGopSetMode
;
327 Private
->GraphicsOutput
.Blt
= EmuGopBlt
;
330 // Allocate buffer for Graphics Output Protocol mode information
332 Private
->GraphicsOutput
.Mode
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
));
333 if (Private
->GraphicsOutput
.Mode
== NULL
) {
334 return EFI_OUT_OF_RESOURCES
;
336 Private
->GraphicsOutput
.Mode
->Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
337 if (Private
->GraphicsOutput
.Mode
->Info
== NULL
) {
338 return EFI_OUT_OF_RESOURCES
;
341 Private
->GraphicsOutput
.Mode
->MaxMode
= sizeof(mGopModeData
) / sizeof(GOP_MODE_DATA
);
343 // Till now, we have no idea about the window size.
345 Private
->GraphicsOutput
.Mode
->Mode
= GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER
;
346 Private
->GraphicsOutput
.Mode
->Info
->Version
= 0;
347 Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
= 0;
348 Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
= 0;
349 Private
->GraphicsOutput
.Mode
->Info
->PixelFormat
= PixelBltOnly
;
350 Private
->GraphicsOutput
.Mode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
351 Private
->GraphicsOutput
.Mode
->FrameBufferBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) NULL
;
352 Private
->GraphicsOutput
.Mode
->FrameBufferSize
= 0;
354 Private
->HardwareNeedsStarting
= TRUE
;
355 Private
->EmuGraphicsWindow
= NULL
;
357 EmuGopInitializeSimpleTextInForWindow (Private
);
359 EmuGopInitializeSimplePointerForWindow (Private
);
368 GOP_PRIVATE_DATA
*Private
371 if (!Private
->HardwareNeedsStarting
) {
372 Private
->EmuIoThunk
->Close (Private
->EmuIoThunk
);
373 Private
->EmuGraphicsWindow
= NULL
;
377 // Free graphics output protocol occupied resource
379 if (Private
->GraphicsOutput
.Mode
!= NULL
) {
380 if (Private
->GraphicsOutput
.Mode
->Info
!= NULL
) {
381 FreePool (Private
->GraphicsOutput
.Mode
->Info
);
383 FreePool (Private
->GraphicsOutput
.Mode
);
400 This is the UGA screen's callback notification function for exit-boot-services.
401 All we do here is call EmuGopDestructor().
406 Context - pointer to the Private structure.
414 EmuGopDestructor (Context
);