📄 sa2video.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
*/
#include <windows.h>
#include <types.h>
#include <nkintr.h>
#include <syspal.h>
#include <ceddk.h>
#include "memdefs.h"
#include "precomp.h"
#include "cursor.h"
#include "xllp_lcd.h"
#include "xllp_gpio.h"
#include "strsafe.h"
extern "C" PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);
extern "C" void DispDrvrSetPalette(const PALETTEENTRY *,USHORT,USHORT);
extern "C" void *gFrameBuffer;
extern "C" volatile LCD_PALETTE *v_pPaletteBuffer;
extern "C" BOOL bDoRotation;
extern "C" void ScrollBuffer(int direction);
extern "C" void DispDrvrDirtyRectDump2(LPCRECT prc,DWORD color);
extern "C" void DispDrvrDirtyRectDump_rectfill(LPCRECT prc,DWORD color);
extern "C" BOOL gDrawCursorFlag;
extern "C" XLLP_LCD_T XllpLCD;
extern "C" volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh2_YCbCr_Y;
extern "C" volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh3_YCbCr_Cb;
extern "C" volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh4_YCbCr_Cr;
extern "C" volatile unsigned int *pOSCR;
extern "C" void ApplicationImageProcessingHandler(void);
extern "C" HANDLE hIntEventKnown;
extern "C" HANDLE hIntEvent;
extern "C" BOOL g_fDisableRotation; //Enable/disable screen rotation
volatile LCDRegs * v_pLcdRegs = NULL;
volatile XLLP_GPIO_T * v_pGPIORegs = NULL;
BOOL bSuspended = FALSE;
extern HMODULE g_hmodDisplayDll;
#define NUM_FRAME_BUFFERS 2
POWER_CAPABILITIES DisplayDrvPowerCaps =
{
// DeviceDx: Supported power states
DX_MASK(D0) | DX_MASK(D2) | DX_MASK(D3) | DX_MASK(D4),
// WakeFromDx
0,
// InrushDx: No inrush of power
0,
// Power: Maximum milliwatts in each state
{
0x00000000, // D0
0x00000000, // D1
0x00000000, // D2
0x00000000, // D3
0x00000000 // D4
},
// Latency
{
0x00000000, // D0
0x00000000, // D1
0x00000000, // D2
0x00000000, // D3
0x00000000 // D4
},
// Flags: None
0
};
DDGPE * pGPE = NULL;
// These masks are used to extract the color component for a 16 bit pixel value. 5 bits red, 6 bits green, 5 bits blue.
ulong BitMasks[] = {0xF800, 0x07E0, 0x001F};
#ifdef DEBUG
#define ZONE_PM DEBUGZONE(14)
#endif
INSTANTIATE_GPE_ZONES(0x4003,"GDI Driver","Power Management","unused2") /* Start with Errors, warnings, and pm */
BOOL APIENTRY
GPEEnableDriver(
ULONG iEngineVersion,
ULONG cj,
DRVENABLEDATA *pded,
PENGCALLBACKS pEngCallbacks
);
BOOL APIENTRY
DrvEnableDriver(
ULONG iEngineVersion,
ULONG cj,
DRVENABLEDATA *data,
PENGCALLBACKS pEngineCallbacks
)
{
return GPEEnableDriver(iEngineVersion,cj,data,pEngineCallbacks);
}
#define DMA_CHANNEL_0 _T("DMA_CHANNEL_0")
////////////////////////////////////////////////////////////////////////////////////////////
// Main entry point for a GPE-compliant driver
GPE *
GetGPE()
{
if (!pGPE)
{
pGPE = new SA2Video();
}
return pGPE;
}
VOID
SA2Video::PowerHandler(
BOOL bOff
)
{
// turn off the display if it is not already turned off
// (turning on is controlled by SA2Video::SetPmPowerState)
if (bOff && !bSuspended) {
DEBUGMSG(ZONE_PM, (TEXT("SA2Video::PowerHandler: TurnOff Display\r\n")));
DispDrvrPowerHandler(TRUE);
bSuspended = TRUE;
}
}
SA2Video::SA2Video()
{
DEBUGMSG(GPE_ZONE_INIT,(TEXT("SA2Video::SA2Video\r\n")));
m_InDDraw = FALSE;
// Determine the display type
// Setup the LCD controller for that display
// Power up and enable the display
DispDrvrInitialize();
// Advertise the power management interface for this driver.
AdvertisePowerInterface();
m_ModeInfo.modeId = 0;
m_ModeInfo.width = m_nScreenWidth = DispDrvr_cxScreen;
m_ModeInfo.height = m_nScreenHeight = DispDrvr_cyScreen;
m_ModeInfo.Bpp = bpp;
m_ModeInfo.frequency = 60;
m_ModeInfo.format = bpp == 8 ? gpe8Bpp : gpe16Bpp;
m_pMode = &m_ModeInfo;
m_pModeEx.modeInfo.modeId = 0;
m_pModeEx.modeInfo.width = m_nScreenWidth = DispDrvr_cxScreen;
m_pModeEx.modeInfo.height = m_nScreenHeight = DispDrvr_cyScreen;
m_pModeEx.modeInfo.Bpp = bpp;
m_pModeEx.modeInfo.frequency = 60;
m_pModeEx.modeInfo.format = bpp == 8 ? gpe8Bpp : gpe16Bpp;
if (!g_fDisableRotation)
{
m_iRotate = GetRotateModeFromReg();
}
else
{
m_iRotate = DMDO_0;
}
SetRotateParams();
m_pVirtualFrameBuffer = gFrameBuffer;
m_pPrimarySurface = new DDGPESurf(m_nScreenWidth,m_nScreenHeight,m_pVirtualFrameBuffer,
DispDrvr_cdwStride,m_ModeInfo.format);
m_VirtualFrameBuffer = (ULONG)FRAME_BUFFER_0_BASE_VIRTUAL;
if (m_pPrimarySurface)
{
((GPESurf *)m_pPrimarySurface)->SetRotation(m_nScreenWidth, m_nScreenHeight, m_iRotate);
}
// Set up the software cursor state.
m_CursorVisible = FALSE;
m_CursorDisabled = TRUE;
m_CursorForcedOff = FALSE;
}
SCODE
SA2Video::SetMode(
int modeId,
HPALETTE * pPalette)
{
SCODE Result = E_INVALIDARG;
// Here, we use EngCreatePalette to create a palette that that MGDI will use as a
// stock palette
if(pPalette && 0 == modeId)
{
switch (bpp)
{
case 8:
*pPalette = EngCreatePalette(PAL_INDEXED, PALETTE_SIZE, (ULONG*)_rgbIdentity, 0, 0, 0);
Result = S_OK;
break;
case 16:
*pPalette = EngCreatePalette(PAL_BITFIELDS, 0, NULL, BitMasks[0], BitMasks[1], BitMasks[2]);
Result = S_OK;
break;
default:
*pPalette = NULL;
break;
}
}
return Result;
}
SCODE
SA2Video::GetModeInfo(
GPEMode * pMode,
int modeNumber
)
{
if(modeNumber != 0)
{
return E_INVALIDARG;
}
*pMode = m_ModeInfo;
return S_OK;
}
int
SA2Video::NumModes()
{
return 1;
}
SCODE
SA2Video::SetPointerShape(
GPESurf * pMask,
GPESurf * pColorSurf,
int xHot,
int yHot,
int cX,
int cY
)
{
int row;
int colByte;
BYTE * pAND;
BYTE * pXOR;
BYTE bitMask;
unsigned i;
if (!bDoRotation)
{
CursorOff();
}
if (!pMask)
{ // Turn off the cursor.
memset((BYTE *)gCursorMask,0xFF,sizeof(gCursorMask));
memset((BYTE *)gCursorData,0x00,sizeof(gCursorData));
m_CursorDisabled = TRUE;
}
else
{
i = 0;
for (row = 0; row < cY; row++)
{
for (colByte = 0; colByte < (cX / 8); colByte++)
{
pAND = (unsigned char *)pMask->Buffer()+(row*pMask->Stride())+colByte;
pXOR = pAND+(cY*pMask->Stride());
for (bitMask = 0x0080; bitMask; bitMask >>= 1)
{
gCursorMask[i] = (*pAND & bitMask) ? 0xFFFF : 0x0000;
gCursorData[i] = (*pXOR & bitMask) ? 0xFFFF : 0x0000;
i++;
}
}
}
m_CursorDisabled = FALSE;
m_CursorSize.x = cX;
m_CursorSize.y = cY;
gxHot = xHot;
gyHot = yHot;
}
return S_OK;
}
SCODE
SA2Video::MovePointer(
int xPosition,
int yPosition
)
{
if (!bDoRotation)
{
CursorOff();
}
if(xPosition != -1 || yPosition != -1)
{
// enable cursor
DispDrvrMoveCursor(xPosition, yPosition);
m_CursorRect.left = xPosition - gxHot;
m_CursorRect.right = m_CursorRect.left + m_CursorSize.x;
m_CursorRect.top = yPosition - gyHot;
m_CursorRect.bottom = m_CursorRect.top + m_CursorSize.y;
if (!bDoRotation)
{
CursorOn();
}
}
else
{
// disable cursor
DispDrvrMoveCursor(DispDrvr_cxScreen, DispDrvr_cyScreen);
}
return S_OK;
}
void
SA2Video::WaitForNotBusy()
{
return;
}
int
SA2Video::IsBusy()
{
return 0; // Never busy as there is no acceleration
}
void
SA2Video::GetPhysicalVideoMemory(
unsigned long * pPhysicalMemoryBase,
unsigned long * pVideoMemorySize
)
{
*pPhysicalMemoryBase = (ULONG)FRAME_BUFFER_0_BASE_VIRTUAL;
*pVideoMemorySize = DispDrvr_cdwStride * DispDrvr_cyScreen;
}
void
SA2Video::GetVirtualVideoMemory(
unsigned long * pVirtualMemoryBase,
unsigned long * pVideoMemorySize
)
{
*pVirtualMemoryBase = (unsigned)(m_pPrimarySurface->Buffer());
*pVideoMemorySize = DispDrvr_cdwStride * DispDrvr_cyScreen;
}
SCODE
SA2Video::AllocSurface(
DDGPESurf ** ppSurf,
int width,
int height,
EGPEFormat format,
EDDGPEPixelFormat pixelFormat,
int surfaceFlags
)
{
if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
{
*ppSurf = NULL;
return E_OUTOFMEMORY;
}
DWORD SurfBpp = EGPEFormatToBpp[format];
DWORD stride = ((SurfBpp * width + 31) >> 5) << 2;
DWORD nSurfaceBytes = stride * height;
*ppSurf = new DDGPESurf(width, height, stride, format, pixelFormat);
if (NULL != *ppSurf)
{
if (((*ppSurf)->Buffer()) == NULL)
{
delete *ppSurf;
*ppSurf = NULL;
}
else
{
return S_OK;
}
}
return E_OUTOFMEMORY;
}
SCODE
SA2Video::AllocSurface(
GPESurf ** surface,
int width,
int height,
EGPEFormat format,
int surfaceFlags
)
{
if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
{
// Can't allocate video-memory surfaces in the SA2Video environment
return E_OUTOFMEMORY;
}
// Allocate from system memory
*surface = new GPESurf(width,height,format);
if (*surface != NULL)
{
// Check that the bits were allocated succesfully
if (((*surface)->Buffer()) == NULL)
{
delete *surface;
}
else
{
return S_OK;
}
}
return E_OUTOFMEMORY;
}
SCODE
SA2Video::WrappedEmulatedLine(
GPELineParms *pParms
)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -