winntugascreen.c
来自「Next BIOS Source code : Extensible Firmw」· C语言 代码 · 共 895 行 · 第 1/2 页
C
895 行
/*++
Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
Module Name:
WinNtUgaScreen.c
Abstract:
This file produces the graphics abstration of UGA. It is called by
WinNtUgaDriver.c file which deals with the EFI 1.1 driver model.
This file just does graphics.
--*/
#include "WinNtUga.h"
EFI_WIN_NT_THUNK_PROTOCOL *mWinNt;
DWORD mTlsIndex = TLS_OUT_OF_INDEXES;
DWORD mTlsIndexUseCount = 0; // lets us know when we can free mTlsIndex.
static EFI_EVENT mUgaScreenExitBootServicesEvent;
EFI_STATUS
WinNtUgaStartWindow (
IN UGA_PRIVATE_DATA *Private,
IN UINT32 HorizontalResolution,
IN UINT32 VerticalResolution,
IN UINT32 ColorDepth,
IN UINT32 RefreshRate
);
static
VOID
EFIAPI
KillNtUgaThread (
IN EFI_EVENT Event,
IN VOID *Context
);
//
// UGA Protocol Member Functions
//
EFI_STATUS
EFIAPI
WinNtUgaGetMode (
EFI_UGA_DRAW_PROTOCOL *This,
UINT32 *HorizontalResolution,
UINT32 *VerticalResolution,
UINT32 *ColorDepth,
UINT32 *RefreshRate
)
/*++
Routine Description:
Return the current video mode information.
Arguments:
This - Protocol instance pointer.
HorizontalResolution - Current video horizontal resolution in pixels
VerticalResolution - Current video Vertical resolution in pixels
ColorDepth - Current video color depth in bits per pixel
RefreshRate - Current video refresh rate in Hz.
Returns:
EFI_SUCCES - Mode information returned.
EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
EFI_INVALID_PARAMETER - One of the input args was NULL.
--*/
{
UGA_PRIVATE_DATA *Private;
//
// Check parameters
//
if( This == NULL
|| HorizontalResolution == NULL
|| VerticalResolution == NULL
|| ColorDepth == NULL
|| RefreshRate == NULL )
{
return EFI_INVALID_PARAMETER;
}
Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
if (Private->HardwareNeedsStarting) {
return EFI_NOT_STARTED;
}
*HorizontalResolution = Private->HorizontalResolution;
*VerticalResolution = Private->VerticalResolution;
*ColorDepth = Private->ColorDepth;
*RefreshRate = Private->RefreshRate;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
WinNtUgaSetMode (
EFI_UGA_DRAW_PROTOCOL *This,
UINT32 HorizontalResolution,
UINT32 VerticalResolution,
UINT32 ColorDepth,
UINT32 RefreshRate
)
/*++
Routine Description:
Return the current video mode information.
Arguments:
This - Protocol instance pointer.
HorizontalResolution - Current video horizontal resolution in pixels
VerticalResolution - Current video Vertical resolution in pixels
ColorDepth - Current video color depth in bits per pixel
RefreshRate - Current video refresh rate in Hz.
Returns:
EFI_SUCCES - Mode information returned.
EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
EFI_INVALID_PARAMETER - One of the input args was NULL.
--*/
{
EFI_STATUS Status;
UGA_PRIVATE_DATA *Private;
EFI_UGA_PIXEL Fill;
EFI_UGA_PIXEL *NewFillLine;
Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
if (Private->HardwareNeedsStarting) {
Status = WinNtUgaStartWindow (
Private,
HorizontalResolution, VerticalResolution, ColorDepth, RefreshRate
);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
Private->HardwareNeedsStarting = FALSE;
} else if (HorizontalResolution > Private->HorizontalResolution ||
VerticalResolution > Private->VerticalResolution) {
//
// BugBug: We currently do not support growing the window
//
return EFI_INVALID_PARAMETER;
}
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (EFI_UGA_PIXEL) * HorizontalResolution,
&NewFillLine
);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
if (Private->FillLine != NULL) {
gBS->FreePool (Private->FillLine);
}
Private->FillLine = NewFillLine;
Private->HorizontalResolution = HorizontalResolution;
Private->VerticalResolution = VerticalResolution;
Private->ColorDepth = ColorDepth;
Private->RefreshRate = RefreshRate;
Fill.Red = 0x00;
Fill.Green = 0x00;
Fill.Blue = 0x00;
This->Blt (
This,
&Fill, EfiUgaVideoFill,
0, 0, 0, 0,
HorizontalResolution, VerticalResolution,
HorizontalResolution * sizeof (EFI_UGA_PIXEL)
);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
WinNtUgaBlt (
IN EFI_UGA_DRAW_PROTOCOL *This,
IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
IN EFI_UGA_BLT_OPERATION BltOperation,
IN UINTN SourceX,
IN UINTN SourceY,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height,
IN UINTN Delta OPTIONAL
)
/*++
Routine Description:
Blt pixels from the rectangle (Width X Height) formed by the BltBuffer
onto the graphics screen starting a location (X, Y). (0, 0) is defined as
the upper left hand side of the screen. (X, Y) can be outside of the
current screen geometry and the BltBuffer will be cliped when it is
displayed. X and Y can be negative or positive. If Width or Height is
bigger than the current video screen the image will be clipped.
Arguments:
This - Protocol instance pointer.
X - X location on graphics screen.
Y - Y location on the graphics screen.
Width - Width of BltBuffer.
Height - Hight of BltBuffer
BltOperation - Operation to perform on BltBuffer and video memory
BltBuffer - Buffer containing data to blt into video buffer. This
buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
SourceX - If the BltOperation is a EfiCopyBlt this is the source
of the copy. For other BLT operations this argument is not
used.
SourceX - If the BltOperation is a EfiCopyBlt this is the source
of the copy. For other BLT operations this argument is not
used.
Returns:
EFI_SUCCESS - The palette is updated with PaletteArray.
EFI_INVALID_PARAMETER - BltOperation is not valid.
EFI_DEVICE_ERROR - A hardware error occured writting to the video
buffer.
--*/
{
UGA_PRIVATE_DATA *Private;
EFI_TPL OriginalTPL;
UINTN DstY, SrcY;
RGBQUAD *VScreen, *VScreenSrc;
EFI_UGA_PIXEL *Blt;
UINTN Index;
RECT Rect;
EFI_UGA_PIXEL *FillPixel;
Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
if( ( BltOperation >= EfiUgaBltMax ) || ( BltOperation < 0 ) ) {
return EFI_INVALID_PARAMETER;
}
if (Width == 0 || Height == 0) {
return EFI_INVALID_PARAMETER;
}
//
// If Delta is zero, then the entire BltBuffer is being used, so Delta
// is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
// the number of bytes in each row can be computed.
//
if (Delta == 0) {
Delta = Width * sizeof (EFI_UGA_PIXEL);
}
//
// We need to fill the Virtual Screen buffer with the blt data.
// The virtual screen is upside down, as the first row is the bootom row of
// the image.
//
if (BltOperation == EfiUgaVideoToBltBuffer) {
//
// Video to BltBuffer: Source is Video, destination is BltBuffer
//
if (SourceY + Height > Private->VerticalResolution) {
return EFI_INVALID_PARAMETER;
}
if (SourceX + Width > Private->HorizontalResolution) {
return EFI_INVALID_PARAMETER;
}
//
// We have to raise to TPL Notify, so we make an atomic write the frame buffer.
// We would not want a timer based event (Cursor, ...) to come in while we are
// doing this operation.
//
OriginalTPL = gBS->RaiseTPL (EFI_TPL_NOTIFY);
for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {
Blt = (EFI_UGA_PIXEL *)((UINT8 *)BltBuffer + (DstY * Delta) + DestinationX * sizeof (EFI_UGA_PIXEL));
VScreen = &Private->VirtualScreen[(Private->VerticalResolution - SrcY - 1)*Private->HorizontalResolution + SourceX];
EfiCopyMem (Blt, VScreen, sizeof (EFI_UGA_PIXEL) * Width);
}
} else {
//
// BltBuffer to Video: Source is BltBuffer, destination is Video
//
if (DestinationY + Height > Private->VerticalResolution) {
return EFI_INVALID_PARAMETER;
}
if (DestinationX + Width > Private->HorizontalResolution) {
return EFI_INVALID_PARAMETER;
}
//
// We have to raise to TPL Notify, so we make an atomic write the frame buffer.
// We would not want a timer based event (Cursor, ...) to come in while we are
// doing this operation.
//
OriginalTPL = gBS->RaiseTPL (EFI_TPL_NOTIFY);
if (BltOperation == EfiUgaVideoFill) {
FillPixel = (EFI_UGA_PIXEL *)((UINT8 *)BltBuffer + (SourceY * Delta) + SourceX * sizeof (EFI_UGA_PIXEL));
for (Index = 0; Index < Width; Index++) {
Private->FillLine[Index] = *FillPixel;
}
}
for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {
VScreen = &Private->VirtualScreen[(Private->VerticalResolution - DstY - 1)*Private->HorizontalResolution + DestinationX];
switch (BltOperation) {
case EfiUgaBltBufferToVideo:
Blt = (EFI_UGA_PIXEL *)((UINT8 *)BltBuffer + (SrcY * Delta) + SourceX * sizeof (EFI_UGA_PIXEL));
EfiCopyMem (VScreen, Blt, Width * sizeof (EFI_UGA_PIXEL));
break;
case EfiUgaVideoToVideo:
VScreenSrc = &Private->VirtualScreen[(Private->VerticalResolution - SrcY - 1)*Private->HorizontalResolution + SourceX];
EfiCopyMem (VScreen, VScreenSrc, Width * sizeof (EFI_UGA_PIXEL));
break;
case EfiUgaVideoFill:
EfiCopyMem (VScreen, Private->FillLine, Width * sizeof (EFI_UGA_PIXEL));
break;
}
}
}
if (BltOperation != EfiUgaVideoToBltBuffer) {
//
// Mark the area we just blted as Invalid so WM_PAINT will update.
//
Rect.left = DestinationX;
Rect.top = DestinationY;
Rect.right = DestinationX + Width;
Rect.bottom = DestinationY + Height;
Private->WinNtThunk->InvalidateRect (Private->WindowHandle, &Rect, FALSE);
//
// Send the WM_PAINT message to the thread that is drawing the window. We
// are in the main thread and the window drawing is in a child thread.
// There is a child thread per window. We have no CriticalSection or Mutex
// since we write the data and the other thread displays the data. While
// we may miss some data for a short period of time this is no different than
// a write combining on writes to a frame buffer.
//
Private->WinNtThunk->UpdateWindow (Private->WindowHandle);
}
gBS->RestoreTPL (OriginalTPL);
return EFI_SUCCESS;
}
EFI_STATUS
WinNtUgaDispatchService (
IN PUGA_DEVICE pDevice,
IN PUGA_IO_REQUEST pIoRequest
)
/*++
Routine Description:
Send an IO operation to the root video graphics device or one of it's
children. You can use the root device pDevice == NULL to discover
all child devices.
Arguments:
pDevice - Device to send pIoRequest to. Null is the root device.
pIoRequest - IO operation requested.
Returns:
Varies depending on pIoRequest.
--*/
{
return EFI_NOT_FOUND;
}
//
// Construction and Destruction functions
//
EFI_STATUS
WinNtUgaSupported (
IN EFI_WIN_NT_IO_PROTOCOL *WinNtIo
)
/*++
Routine Description:
Arguments:
Returns:
None
--*/
{
//
// Check to see if the IO abstraction represents a device type we support.
//
// This would be replaced a check of PCI subsystem ID, etc.
//
if (!EfiCompareGuid (WinNtIo->TypeGuid, &gEfiWinNtUgaGuid)) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
LRESULT
CALLBACK
WinNtUgaThreadWindowProc (
IN HWND hwnd,
IN UINT iMsg,
IN WPARAM wParam,
IN LPARAM lParam
)
/*++
Routine Description:
Win32 Windows event handler.
Arguments:
See Win32 Book
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?