3 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4 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
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.
18 This file produces the graphics abstration of GOP. It is called by
19 WinNtGopDriver.c file which deals with the UEFI 2.0 driver model.
20 This file just does graphics.
27 EFI_WIN_NT_THUNK_PROTOCOL
*mWinNt
;
28 DWORD mTlsIndex
= TLS_OUT_OF_INDEXES
;
29 DWORD mTlsIndexUseCount
= 0; // lets us know when we can free mTlsIndex.
30 EFI_EVENT mGopScreenExitBootServicesEvent
;
31 GOP_MODE_DATA mGopModeData
[] = {
41 IN GOP_PRIVATE_DATA
*Private
,
42 IN UINT32 HorizontalResolution
,
43 IN UINT32 VerticalResolution
,
56 WinNtGopConvertParamToEfiKeyShiftState (
57 IN GOP_PRIVATE_DATA
*Private
,
64 // BUGBUG: Only GetAsyncKeyState() and GetKeyState() can distinguish
65 // left and right Ctrl, and Shift key.
66 // Neither of the two is defined in EFI_WIN_NT_THUNK_PROTOCOL.
67 // Therefor, we can not set the correct Shift state here.
70 Private
->LeftShift
= Flag
;
73 Private
->LeftCtrl
= Flag
;
76 Private
->LeftLogo
= Flag
;
79 Private
->RightLogo
= Flag
;
85 // BUGBUG: PrintScreen/SysRq can not trigger WM_KEYDOWN message,
86 // so SySReq shift state is not supported here.
89 Private
->SysReq
= Flag
;
95 WinNtGopConvertParamToEfiKey (
96 IN GOP_PRIVATE_DATA
*Private
,
102 case VK_HOME
: Key
->ScanCode
= SCAN_HOME
; break;
103 case VK_END
: Key
->ScanCode
= SCAN_END
; break;
104 case VK_LEFT
: Key
->ScanCode
= SCAN_LEFT
; break;
105 case VK_RIGHT
: Key
->ScanCode
= SCAN_RIGHT
; break;
106 case VK_UP
: Key
->ScanCode
= SCAN_UP
; break;
107 case VK_DOWN
: Key
->ScanCode
= SCAN_DOWN
; break;
108 case VK_DELETE
: Key
->ScanCode
= SCAN_DELETE
; break;
109 case VK_INSERT
: Key
->ScanCode
= SCAN_INSERT
; break;
110 case VK_PRIOR
: Key
->ScanCode
= SCAN_PAGE_UP
; break;
111 case VK_NEXT
: Key
->ScanCode
= SCAN_PAGE_DOWN
; break;
112 case VK_ESCAPE
: Key
->ScanCode
= SCAN_ESC
; break;
114 case VK_F1
: Key
->ScanCode
= SCAN_F1
; break;
115 case VK_F2
: Key
->ScanCode
= SCAN_F2
; break;
116 case VK_F3
: Key
->ScanCode
= SCAN_F3
; break;
117 case VK_F4
: Key
->ScanCode
= SCAN_F4
; break;
118 case VK_F5
: Key
->ScanCode
= SCAN_F5
; break;
119 case VK_F6
: Key
->ScanCode
= SCAN_F6
; break;
120 case VK_F7
: Key
->ScanCode
= SCAN_F7
; break;
121 case VK_F8
: Key
->ScanCode
= SCAN_F8
; break;
122 case VK_F9
: Key
->ScanCode
= SCAN_F9
; break;
123 case VK_F11
: Key
->ScanCode
= SCAN_F11
; break;
124 case VK_F12
: Key
->ScanCode
= SCAN_F12
; break;
126 case VK_F13
: Key
->ScanCode
= SCAN_F13
; break;
127 case VK_F14
: Key
->ScanCode
= SCAN_F14
; break;
128 case VK_F15
: Key
->ScanCode
= SCAN_F15
; break;
129 case VK_F16
: Key
->ScanCode
= SCAN_F16
; break;
130 case VK_F17
: Key
->ScanCode
= SCAN_F17
; break;
131 case VK_F18
: Key
->ScanCode
= SCAN_F18
; break;
132 case VK_F19
: Key
->ScanCode
= SCAN_F19
; break;
133 case VK_F20
: Key
->ScanCode
= SCAN_F20
; break;
134 case VK_F21
: Key
->ScanCode
= SCAN_F21
; break;
135 case VK_F22
: Key
->ScanCode
= SCAN_F22
; break;
136 case VK_F23
: Key
->ScanCode
= SCAN_F23
; break;
137 case VK_F24
: Key
->ScanCode
= SCAN_F24
; break;
138 case VK_PAUSE
: Key
->ScanCode
= SCAN_PAUSE
; break;
144 Private
->NumLock
= (BOOLEAN
)(!Private
->NumLock
);
147 Private
->ScrollLock
= (BOOLEAN
)(!Private
->ScrollLock
);
150 Private
->CapsLock
= (BOOLEAN
)(!Private
->CapsLock
);
154 WinNtGopConvertParamToEfiKeyShiftState (Private
, wParam
, TRUE
);
159 // GOP Protocol Member Functions
164 Graphics Output protocol interface to get video mode
166 @param This Protocol instance pointer.
167 @param ModeNumber The mode number to return information on.
168 @param Info Caller allocated buffer that returns information
170 @param SizeOfInfo A pointer to the size, in bytes, of the Info
173 @retval EFI_SUCCESS Mode information returned.
174 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
175 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
177 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
178 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
184 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
185 IN UINT32 ModeNumber
,
186 OUT UINTN
*SizeOfInfo
,
187 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
190 GOP_PRIVATE_DATA
*Private
;
192 Private
= GOP_PRIVATE_DATA_FROM_THIS (This
);
194 if (Info
== NULL
|| SizeOfInfo
== NULL
|| (UINTN
) ModeNumber
>= This
->Mode
->MaxMode
) {
195 return EFI_INVALID_PARAMETER
;
198 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
200 return EFI_OUT_OF_RESOURCES
;
203 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
205 (*Info
)->Version
= 0;
206 (*Info
)->HorizontalResolution
= Private
->ModeData
[ModeNumber
].HorizontalResolution
;
207 (*Info
)->VerticalResolution
= Private
->ModeData
[ModeNumber
].VerticalResolution
;
208 (*Info
)->PixelFormat
= PixelBltOnly
;
209 (*Info
)->PixelsPerScanLine
= (*Info
)->HorizontalResolution
;
216 Graphics Output protocol interface to set video mode
218 @param This Protocol instance pointer.
219 @param ModeNumber The mode number to be set.
221 @retval EFI_SUCCESS Graphics mode was changed.
222 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
224 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
230 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
235 GOP_PRIVATE_DATA
*Private
;
236 GOP_MODE_DATA
*ModeData
;
237 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Fill
;
238 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewFillLine
;
244 Private
= GOP_PRIVATE_DATA_FROM_THIS (This
);
246 if (ModeNumber
>= This
->Mode
->MaxMode
) {
247 return EFI_UNSUPPORTED
;
250 ModeData
= &Private
->ModeData
[ModeNumber
];
251 This
->Mode
->Mode
= ModeNumber
;
252 Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
= ModeData
->HorizontalResolution
;
253 Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
= ModeData
->VerticalResolution
;
254 Private
->GraphicsOutput
.Mode
->Info
->PixelsPerScanLine
= ModeData
->HorizontalResolution
;
256 if (Private
->HardwareNeedsStarting
) {
257 Status
= WinNtGopStartWindow (
259 ModeData
->HorizontalResolution
,
260 ModeData
->VerticalResolution
,
261 ModeData
->ColorDepth
,
262 ModeData
->RefreshRate
264 if (EFI_ERROR (Status
)) {
265 return EFI_DEVICE_ERROR
;
268 Private
->HardwareNeedsStarting
= FALSE
;
271 // Change the resolution and resize of the window
275 // Free the old buffer. We do not save the content of the old buffer since the
276 // screen is to be cleared anyway. Clearing the screen is required by the EFI spec.
277 // See UEFI spec -EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode()
279 Private
->WinNtThunk
->HeapFree (Private
->WinNtThunk
->GetProcessHeap (), 0, Private
->VirtualScreenInfo
);
282 // Allocate DIB frame buffer directly from NT for performance enhancement
283 // This buffer is the virtual screen/frame buffer. This buffer is not the
284 // same a a frame buffer. The first row of this buffer will be the bottom
285 // line of the image. This is an artifact of the way we draw to the screen.
287 Size
= ModeData
->HorizontalResolution
* ModeData
->VerticalResolution
* sizeof (RGBQUAD
) + sizeof (BITMAPV4HEADER
);
288 Private
->VirtualScreenInfo
= Private
->WinNtThunk
->HeapAlloc (
289 Private
->WinNtThunk
->GetProcessHeap (),
295 // Update the virtual screen info data structure
297 Private
->VirtualScreenInfo
->bV4Size
= sizeof (BITMAPV4HEADER
);
298 Private
->VirtualScreenInfo
->bV4Width
= ModeData
->HorizontalResolution
;
299 Private
->VirtualScreenInfo
->bV4Height
= ModeData
->VerticalResolution
;
300 Private
->VirtualScreenInfo
->bV4Planes
= 1;
301 Private
->VirtualScreenInfo
->bV4BitCount
= 32;
305 Private
->VirtualScreenInfo
->bV4V4Compression
= BI_RGB
;
308 // The rest of the allocated memory block is the virtual screen buffer
310 Private
->VirtualScreen
= (RGBQUAD
*) (Private
->VirtualScreenInfo
+ 1);
313 // Use the AdjuctWindowRect fuction to calculate the real width and height
314 // of the new window including the border and caption
318 Rect
.right
= ModeData
->HorizontalResolution
;
319 Rect
.bottom
= ModeData
->VerticalResolution
;
321 Private
->WinNtThunk
->AdjustWindowRect (&Rect
, WS_OVERLAPPEDWINDOW
, 0);
323 Width
= Rect
.right
- Rect
.left
;
324 Height
= Rect
.bottom
- Rect
.top
;
327 // Retrieve the original window position information
329 Private
->WinNtThunk
->GetWindowRect (Private
->WindowHandle
, &Rect
);
332 // Adjust the window size
334 Private
->WinNtThunk
->MoveWindow (Private
->WindowHandle
, Rect
.left
, Rect
.top
, Width
, Height
, TRUE
);
338 NewFillLine
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->HorizontalResolution
);
339 if (NewFillLine
== NULL
) {
340 return EFI_DEVICE_ERROR
;
343 if (Private
->FillLine
!= NULL
) {
344 FreePool (Private
->FillLine
);
347 Private
->FillLine
= NewFillLine
;
360 ModeData
->HorizontalResolution
,
361 ModeData
->VerticalResolution
,
362 ModeData
->HorizontalResolution
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
369 Blt pixels from the rectangle (Width X Height) formed by the BltBuffer
370 onto the graphics screen starting a location (X, Y). (0, 0) is defined as
371 the upper left hand side of the screen. (X, Y) can be outside of the
372 current screen geometry and the BltBuffer will be cliped when it is
373 displayed. X and Y can be negative or positive. If Width or Height is
374 bigger than the current video screen the image will be clipped.
376 @param This Protocol instance pointer.
377 @param X X location on graphics screen.
378 @param Y Y location on the graphics screen.
379 @param Width Width of BltBuffer.
380 @param Height Hight of BltBuffer
381 @param BltOperation Operation to perform on BltBuffer and video memory
382 @param BltBuffer Buffer containing data to blt into video buffer.
383 This buffer has a size of
384 Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
385 @param SourceX If the BltOperation is a EfiCopyBlt this is the
386 source of the copy. For other BLT operations this
387 argument is not used.
388 @param SourceX If the BltOperation is a EfiCopyBlt this is the
389 source of the copy. For other BLT operations this
390 argument is not used.
392 @retval EFI_SUCCESS The palette is updated with PaletteArray.
393 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
394 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video
398 // TODO: SourceY - add argument and description to function comment
399 // TODO: DestinationX - add argument and description to function comment
400 // TODO: DestinationY - add argument and description to function comment
401 // TODO: Delta - add argument and description to function comment
405 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
406 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
407 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
410 IN UINTN DestinationX
,
411 IN UINTN DestinationY
,
414 IN UINTN Delta OPTIONAL
417 GOP_PRIVATE_DATA
*Private
;
423 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
426 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*FillPixel
;
427 UINT32 VerticalResolution
;
428 UINT32 HorizontalResolution
;
430 Private
= GOP_PRIVATE_DATA_FROM_THIS (This
);
432 if ((BltOperation
< 0) || (BltOperation
>= EfiGraphicsOutputBltOperationMax
)) {
433 return EFI_INVALID_PARAMETER
;
436 if (Width
== 0 || Height
== 0) {
437 return EFI_INVALID_PARAMETER
;
440 // If Delta is zero, then the entire BltBuffer is being used, so Delta
441 // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
442 // the number of bytes in each row can be computed.
445 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
449 // We need to fill the Virtual Screen buffer with the blt data.
450 // The virtual screen is upside down, as the first row is the bootom row of
453 VerticalResolution
= This
->Mode
->Info
->VerticalResolution
;
454 HorizontalResolution
= This
->Mode
->Info
->HorizontalResolution
;
455 if (BltOperation
== EfiBltVideoToBltBuffer
) {
458 // Video to BltBuffer: Source is Video, destination is BltBuffer
460 if (SourceY
+ Height
> VerticalResolution
) {
461 return EFI_INVALID_PARAMETER
;
464 if (SourceX
+ Width
> HorizontalResolution
) {
465 return EFI_INVALID_PARAMETER
;
468 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
469 // We would not want a timer based event (Cursor, ...) to come in while we are
470 // doing this operation.
472 OriginalTPL
= gBS
->RaiseTPL (TPL_NOTIFY
);
474 for (SrcY
= SourceY
, DstY
= DestinationY
; DstY
< (Height
+ DestinationY
); SrcY
++, DstY
++) {
475 Blt
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) ((UINT8
*) BltBuffer
+ (DstY
* Delta
) + DestinationX
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
476 VScreen
= &Private
->VirtualScreen
[(VerticalResolution
- SrcY
- 1) * HorizontalResolution
+ SourceX
];
477 CopyMem (Blt
, VScreen
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * Width
);
481 // BltBuffer to Video: Source is BltBuffer, destination is Video
483 if (DestinationY
+ Height
> VerticalResolution
) {
484 return EFI_INVALID_PARAMETER
;
487 if (DestinationX
+ Width
> HorizontalResolution
) {
488 return EFI_INVALID_PARAMETER
;
492 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
493 // We would not want a timer based event (Cursor, ...) to come in while we are
494 // doing this operation.
496 OriginalTPL
= gBS
->RaiseTPL (TPL_NOTIFY
);
498 if (BltOperation
== EfiBltVideoFill
) {
499 FillPixel
= BltBuffer
;
500 for (Index
= 0; Index
< Width
; Index
++) {
501 Private
->FillLine
[Index
] = *FillPixel
;
505 for (Index
= 0; Index
< Height
; Index
++) {
506 if (DestinationY
<= SourceY
) {
507 SrcY
= SourceY
+ Index
;
508 DstY
= DestinationY
+ Index
;
510 SrcY
= SourceY
+ Height
- Index
- 1;
511 DstY
= DestinationY
+ Height
- Index
- 1;
514 VScreen
= &Private
->VirtualScreen
[(VerticalResolution
- DstY
- 1) * HorizontalResolution
+ DestinationX
];
515 switch (BltOperation
) {
516 case EfiBltBufferToVideo
:
517 Blt
= (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) ((UINT8
*) BltBuffer
+ (SrcY
* Delta
) + SourceX
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
518 CopyMem (VScreen
, Blt
, Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
521 case EfiBltVideoToVideo
:
522 VScreenSrc
= &Private
->VirtualScreen
[(VerticalResolution
- SrcY
- 1) * HorizontalResolution
+ SourceX
];
523 CopyMem (VScreen
, VScreenSrc
, Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
526 case EfiBltVideoFill
:
527 CopyMem (VScreen
, Private
->FillLine
, Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
533 if (BltOperation
!= EfiBltVideoToBltBuffer
) {
535 // Mark the area we just blted as Invalid so WM_PAINT will update.
537 Rect
.left
= DestinationX
;
538 Rect
.top
= DestinationY
;
539 Rect
.right
= DestinationX
+ Width
;
540 Rect
.bottom
= DestinationY
+ Height
;
541 Private
->WinNtThunk
->InvalidateRect (Private
->WindowHandle
, &Rect
, FALSE
);
544 // Send the WM_PAINT message to the thread that is drawing the window. We
545 // are in the main thread and the window drawing is in a child thread.
546 // There is a child thread per window. We have no CriticalSection or Mutex
547 // since we write the data and the other thread displays the data. While
548 // we may miss some data for a short period of time this is no different than
549 // a write combining on writes to a frame buffer.
552 Private
->WinNtThunk
->UpdateWindow (Private
->WindowHandle
);
555 gBS
->RestoreTPL (OriginalTPL
);
561 // Construction and Destruction functions
571 // TODO: WinNtIo - add argument and description to function comment
572 // TODO: EFI_UNSUPPORTED - add return value to function comment
573 // TODO: EFI_SUCCESS - add return value to function comment
576 IN EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
580 // Check to see if the IO abstraction represents a device type we support.
582 // This would be replaced a check of PCI subsystem ID, etc.
584 if (!CompareGuid (WinNtIo
->TypeGuid
, &gEfiWinNtGopGuid
)) {
585 return EFI_UNSUPPORTED
;
593 Win32 Windows event handler.
597 @return See Win32 Book
600 // TODO: hwnd - add argument and description to function comment
601 // TODO: iMsg - add argument and description to function comment
602 // TODO: wParam - add argument and description to function comment
603 // TODO: lParam - add argument and description to function comment
606 WinNtGopThreadWindowProc (
613 GOP_PRIVATE_DATA
*Private
;
616 PAINTSTRUCT PaintStruct
;
621 // BugBug - if there are two instances of this DLL in memory (such as is
622 // the case for ERM), the correct instance of this function may not be called.
623 // This also means that the address of the mTlsIndex value will be wrong, and
624 // the value may be wrong too.
629 // Use mTlsIndex global to get a Thread Local Storage version of Private.
630 // This works since each Gop protocol has a unique Private data instance and
633 Private
= mWinNt
->TlsGetValue (mTlsIndex
);
634 ASSERT (NULL
!= Private
);
638 Size
= Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
* Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
* sizeof (RGBQUAD
);
641 // Allocate DIB frame buffer directly from NT for performance enhancement
642 // This buffer is the virtual screen/frame buffer. This buffer is not the
643 // same a a frame buffer. The first fow of this buffer will be the bottom
644 // line of the image. This is an artifact of the way we draw to the screen.
646 Private
->VirtualScreenInfo
= Private
->WinNtThunk
->HeapAlloc (
647 Private
->WinNtThunk
->GetProcessHeap (),
652 Private
->VirtualScreenInfo
->bV4Size
= sizeof (BITMAPV4HEADER
);
653 Private
->VirtualScreenInfo
->bV4Width
= Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
;
654 Private
->VirtualScreenInfo
->bV4Height
= Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
;
655 Private
->VirtualScreenInfo
->bV4Planes
= 1;
656 Private
->VirtualScreenInfo
->bV4BitCount
= 32;
660 Private
->VirtualScreenInfo
->bV4V4Compression
= BI_RGB
;
661 Private
->VirtualScreen
= (RGBQUAD
*) (Private
->VirtualScreenInfo
+ 1);
666 // I have not found a way to convert hwnd into a Private context. So for
667 // now we use this API to convert hwnd to Private data.
670 Handle
= mWinNt
->BeginPaint (hwnd
, &PaintStruct
);
672 mWinNt
->SetDIBitsToDevice (
673 Handle
, // Destination Device Context
674 0, // Destination X - 0
675 0, // Destination Y - 0
676 Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
, // Width
677 Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
, // Height
680 0, // DIB Start Scan Line
681 Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
, // Number of scan lines
682 Private
->VirtualScreen
, // Address of array of DIB bits
683 (BITMAPINFO
*) Private
->VirtualScreenInfo
, // Address of structure with bitmap info
684 DIB_RGB_COLORS
// RGB or palette indexes
687 mWinNt
->EndPaint (hwnd
, &PaintStruct
);
691 // F10 and the ALT key do not create a WM_KEYDOWN message, thus this special case
692 // WM_SYSKEYDOWN is posted when F10 is pressed or
693 // holds down ALT key and then presses another key.
699 Key
.ScanCode
= SCAN_F10
;
701 GopPrivateAddKey (Private
, Key
);
705 if ((lParam
& GOP_ALT_KEY_PRESSED
) == GOP_ALT_KEY_PRESSED
) {
707 // ALT is pressed with another key pressed
709 WinNtGopConvertParamToEfiKey (Private
, &wParam
, &Key
);
711 if ((lParam
& GOP_EXTENDED_KEY
) == GOP_EXTENDED_KEY
) {
712 Private
->RightAlt
= TRUE
;
714 Private
->LeftAlt
= TRUE
;
717 if (Private
->RightAlt
&& Private
->LeftAlt
) {
718 Private
->LeftAlt
= FALSE
;
722 if (Key
.ScanCode
!= 0) {
724 GopPrivateAddKey (Private
, Key
);
730 if ((lParam
& GOP_ALT_KEY_PRESSED
) == GOP_ALT_KEY_PRESSED
) {
732 // ALT is pressed with another key released
734 WinNtGopConvertParamToEfiKeyShiftState (Private
, &wParam
, FALSE
);
736 // Actually ALT key is still held down here.
737 // Change the ALT key state when another key is released
738 // by user because we did not find a better solution to
739 // get a released ALT key.
741 Private
->RightAlt
= FALSE
;
742 Private
->LeftAlt
= FALSE
;
750 WinNtGopConvertParamToEfiKey (Private
, &wParam
, &Key
);
751 if (Key
.ScanCode
!= 0) {
753 GopPrivateAddKey (Private
, Key
);
759 WinNtGopConvertParamToEfiKeyShiftState (Private
, &wParam
, FALSE
);
764 // The ESC key also generate WM_CHAR.
766 if (wParam
== 0x1B) {
770 for (Index
= 0; Index
< (lParam
& 0xffff); Index
++) {
772 Key
.UnicodeChar
= (CHAR16
) wParam
;
774 GopPrivateAddKey (Private
, Key
);
782 // This close message is issued by user, core is not aware of this,
783 // so don't release the window display resource, just hide the window.
785 Private
->WinNtThunk
->ShowWindow (Private
->WindowHandle
, SW_HIDE
);
789 mWinNt
->DestroyWindow (hwnd
);
790 mWinNt
->PostQuitMessage (0);
792 mWinNt
->HeapFree (Private
->WinNtThunk
->GetProcessHeap (), 0, Private
->VirtualScreenInfo
);
794 mWinNt
->ExitThread (0);
801 return mWinNt
->DefWindowProc (hwnd
, iMsg
, wParam
, lParam
);
806 This thread simulates the end of WinMain () aplication. Each Winow nededs
807 to process it's events. The messages are dispatched to
808 WinNtGopThreadWindowProc ().
809 Be very careful sine WinNtGopThreadWinMain () and WinNtGopThreadWindowProc ()
810 are running in a seperate thread. We have to do this to process the events.
812 @param lpParameter Handle of window to manage.
814 @return if a WM_QUIT message is returned exit.
819 WinNtGopThreadWinMain (
824 GOP_PRIVATE_DATA
*Private
;
827 Private
= (GOP_PRIVATE_DATA
*) lpParameter
;
828 ASSERT (NULL
!= Private
);
831 // Since each thread has unique private data, save the private data in Thread
832 // Local Storage slot. Then the shared global mTlsIndex can be used to get
833 // thread specific context.
835 Private
->WinNtThunk
->TlsSetValue (mTlsIndex
, Private
);
837 Private
->ThreadId
= Private
->WinNtThunk
->GetCurrentThreadId ();
839 Private
->WindowsClass
.cbSize
= sizeof (WNDCLASSEX
);
840 Private
->WindowsClass
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_OWNDC
;
841 Private
->WindowsClass
.lpfnWndProc
= WinNtGopThreadWindowProc
;
842 Private
->WindowsClass
.cbClsExtra
= 0;
843 Private
->WindowsClass
.cbWndExtra
= 0;
844 Private
->WindowsClass
.hInstance
= NULL
;
845 Private
->WindowsClass
.hIcon
= Private
->WinNtThunk
->LoadIcon (NULL
, IDI_APPLICATION
);
846 Private
->WindowsClass
.hCursor
= Private
->WinNtThunk
->LoadCursor (NULL
, IDC_ARROW
);
847 Private
->WindowsClass
.hbrBackground
= (HBRUSH
) COLOR_WINDOW
;
848 Private
->WindowsClass
.lpszMenuName
= NULL
;
849 Private
->WindowsClass
.lpszClassName
= WIN_NT_GOP_CLASS_NAME
;
850 Private
->WindowsClass
.hIconSm
= Private
->WinNtThunk
->LoadIcon (NULL
, IDI_APPLICATION
);
853 // This call will fail after the first time, but thats O.K. since we only need
854 // WIN_NT_GOP_CLASS_NAME to exist to create the window.
856 // Note: Multiple instances of this DLL will use the same instance of this
857 // Class, including the callback function, unless the Class is unregistered and
858 // successfully registered again.
860 Private
->WinNtThunk
->RegisterClassEx (&Private
->WindowsClass
);
863 // Setting Rect values to allow for the AdjustWindowRect to provide
864 // us the correct sizes for the client area when doing the CreateWindowEx
867 Rect
.bottom
= Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
;
869 Rect
.right
= Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
;
871 Private
->WinNtThunk
->AdjustWindowRect (&Rect
, WS_OVERLAPPEDWINDOW
, 0);
873 Private
->WindowHandle
= Private
->WinNtThunk
->CreateWindowEx (
875 WIN_NT_GOP_CLASS_NAME
,
880 Rect
.right
- Rect
.left
,
881 Rect
.bottom
- Rect
.top
,
889 // The reset of this thread is the standard winows program. We need a sperate
890 // thread since we must process the message loop to make windows act like
894 Private
->WinNtThunk
->ShowWindow (Private
->WindowHandle
, SW_SHOW
);
895 Private
->WinNtThunk
->UpdateWindow (Private
->WindowHandle
);
898 // Let the main thread get some work done
900 Private
->WinNtThunk
->ReleaseSemaphore (Private
->ThreadInited
, 1, NULL
);
903 // This is the message loop that all Windows programs need.
905 while (Private
->WinNtThunk
->GetMessage (&Message
, Private
->WindowHandle
, 0, 0)) {
906 Private
->WinNtThunk
->TranslateMessage (&Message
);
907 Private
->WinNtThunk
->DispatchMessage (&Message
);
910 return Message
.wParam
;
915 TODO: Add function description
917 @param Private TODO: add argument description
918 @param HorizontalResolution TODO: add argument description
919 @param VerticalResolution TODO: add argument description
920 @param ColorDepth TODO: add argument description
921 @param RefreshRate TODO: add argument description
923 @return TODO: add return values
927 WinNtGopStartWindow (
928 IN GOP_PRIVATE_DATA
*Private
,
929 IN UINT32 HorizontalResolution
,
930 IN UINT32 VerticalResolution
,
931 IN UINT32 ColorDepth
,
932 IN UINT32 RefreshRate
938 mWinNt
= Private
->WinNtThunk
;
941 // Initialize a Thread Local Storge variable slot. We use TLS to get the
942 // correct Private data instance into the windows thread.
944 if (mTlsIndex
== TLS_OUT_OF_INDEXES
) {
945 ASSERT (0 == mTlsIndexUseCount
);
946 mTlsIndex
= Private
->WinNtThunk
->TlsAlloc ();
950 // always increase the use count!
955 // Register to be notified on exit boot services so we can destroy the window.
957 Status
= gBS
->CreateEventEx (
962 &gEfiEventExitBootServicesGuid
,
963 &mGopScreenExitBootServicesEvent
966 Private
->ThreadInited
= Private
->WinNtThunk
->CreateSemaphore (NULL
, 0, 1, NULL
);
967 Private
->ThreadHandle
= Private
->WinNtThunk
->CreateThread (
970 WinNtGopThreadWinMain
,
977 // The other thread has entered the windows message loop so we can
978 // continue our initialization.
980 Private
->WinNtThunk
->WaitForSingleObject (Private
->ThreadInited
, INFINITE
);
981 Private
->WinNtThunk
->CloseHandle (Private
->ThreadInited
);
993 // TODO: Private - add argument and description to function comment
994 // TODO: EFI_SUCCESS - add return value to function comment
996 WinNtGopConstructor (
997 GOP_PRIVATE_DATA
*Private
1000 Private
->ModeData
= mGopModeData
;
1002 Private
->GraphicsOutput
.QueryMode
= WinNtGopQuerytMode
;
1003 Private
->GraphicsOutput
.SetMode
= WinNtGopSetMode
;
1004 Private
->GraphicsOutput
.Blt
= WinNtGopBlt
;
1007 // Allocate buffer for Graphics Output Protocol mode information
1009 Private
->GraphicsOutput
.Mode
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
));
1010 if (Private
->GraphicsOutput
.Mode
== NULL
) {
1011 return EFI_OUT_OF_RESOURCES
;
1013 Private
->GraphicsOutput
.Mode
->Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
1014 if (Private
->GraphicsOutput
.Mode
->Info
== NULL
) {
1015 return EFI_OUT_OF_RESOURCES
;
1018 Private
->GraphicsOutput
.Mode
->MaxMode
= sizeof(mGopModeData
) / sizeof(GOP_MODE_DATA
);
1020 // Till now, we have no idea about the window size.
1022 Private
->GraphicsOutput
.Mode
->Mode
= GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER
;
1023 Private
->GraphicsOutput
.Mode
->Info
->Version
= 0;
1024 Private
->GraphicsOutput
.Mode
->Info
->HorizontalResolution
= 0;
1025 Private
->GraphicsOutput
.Mode
->Info
->VerticalResolution
= 0;
1026 Private
->GraphicsOutput
.Mode
->Info
->PixelFormat
= PixelBltOnly
;
1027 Private
->GraphicsOutput
.Mode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
1028 Private
->GraphicsOutput
.Mode
->FrameBufferBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) NULL
;
1029 Private
->GraphicsOutput
.Mode
->FrameBufferSize
= 0;
1031 Private
->HardwareNeedsStarting
= TRUE
;
1032 Private
->FillLine
= NULL
;
1034 WinNtGopInitializeSimpleTextInForWindow (Private
);
1046 // TODO: Private - add argument and description to function comment
1047 // TODO: EFI_SUCCESS - add return value to function comment
1049 WinNtGopDestructor (
1050 GOP_PRIVATE_DATA
*Private
1053 if (!Private
->HardwareNeedsStarting
) {
1055 // BugBug: Shutdown GOP Hardware and any child devices.
1057 Private
->WinNtThunk
->SendMessage (Private
->WindowHandle
, WM_DESTROY
, 0, 0);
1058 Private
->WinNtThunk
->CloseHandle (Private
->ThreadHandle
);
1060 mTlsIndexUseCount
--;
1063 // The callback function for another window could still be called,
1064 // so we need to make sure there are no more users of mTlsIndex.
1066 if (0 == mTlsIndexUseCount
) {
1067 ASSERT (TLS_OUT_OF_INDEXES
!= mTlsIndex
);
1069 Private
->WinNtThunk
->TlsFree (mTlsIndex
);
1070 mTlsIndex
= TLS_OUT_OF_INDEXES
;
1072 Private
->WinNtThunk
->UnregisterClass (
1073 Private
->WindowsClass
.lpszClassName
,
1074 Private
->WindowsClass
.hInstance
1078 WinNtGopDestroySimpleTextInForWindow (Private
);
1082 // Free graphics output protocol occupied resource
1084 if (Private
->GraphicsOutput
.Mode
!= NULL
) {
1085 if (Private
->GraphicsOutput
.Mode
->Info
!= NULL
) {
1086 FreePool (Private
->GraphicsOutput
.Mode
->Info
);
1088 FreePool (Private
->GraphicsOutput
.Mode
);
1096 This is the GOP screen's callback notification function for exit-boot-services.
1097 All we do here is call WinNtGopDestructor().
1099 @param Event not used
1100 @param Context pointer to the Private structure.
1112 WinNtGopDestructor (Context
);