📄 s3c2450disp.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
#include "precomp.h"
#include <nkintr.h>
#include <gxinfo.h>
#include "dispperf.h"
#define DISPPERF_DECLARE
#define jj 0
INSTANTIATE_GPE_ZONES(0x3,"MGDI Driver","unused1","unused2") // Start with errors and warnings
DDGPE * gGPE = (DDGPE *)NULL;
// This prototype avoids problems exporting from .lib
BOOL
APIENTRY
GPEEnableDriver(
ULONG engineVersion,
ULONG cj,
DRVENABLEDATA * data,
PENGCALLBACKS engineCallbacks
);
BOOL
APIENTRY
DrvEnableDriver(
ULONG engineVersion,
ULONG cj,
DRVENABLEDATA * data,
PENGCALLBACKS engineCallbacks
)
{
return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}
// this routine converts a string into a GUID and returns TRUE if the
// conversion was successful.
BOOL
ConvertStringToGuid (LPCTSTR pszGuid, GUID *pGuid)
{
UINT Data4[8];
int Count;
BOOL fOk = FALSE;
TCHAR *pszGuidFormat = _T("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");
DEBUGCHK(pGuid != NULL && pszGuid != NULL);
__try
{
if (_stscanf(pszGuid, pszGuidFormat, &pGuid->Data1, &pGuid->Data2, &pGuid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3], &Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
{
for(Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
{
pGuid->Data4[Count] = (UCHAR) Data4[Count];
}
}
fOk = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{ }
return fOk;
}
// This routine notifies the OS that we support the Power Manager IOCTLs (through ExtEscape(), which calls DrvEscape()).
BOOL
AdvertisePowerInterface(HMODULE hInst)
{
BOOL fOk = FALSE;
HKEY hk;
DWORD dwStatus;
TCHAR szTemp[MAX_PATH];
GUID gClass;
// assume we are advertising the default class
fOk = ConvertStringToGuid(PMCLASS_DISPLAY, &gClass);
DEBUGCHK(fOk);
// check for an override in the registry
dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\GDI\\Drivers"), 0, 0, &hk);
if(dwStatus == ERROR_SUCCESS)
{
DWORD dwType, dwSize;
dwSize = sizeof(szTemp);
dwStatus = RegQueryValueEx(hk, _T("DisplayPowerClass"), NULL, &dwType, (LPBYTE) szTemp, &dwSize);
szTemp[MAX_PATH-1] = 0;
if(dwStatus == ERROR_SUCCESS && dwType == REG_SZ)
{
// got a guid string, convert it to a guid
GUID gTemp;
fOk = ConvertStringToGuid(szTemp, &gTemp);
DEBUGCHK(fOk);
if(fOk)
{
gClass = gTemp;
}
}
// release the registry key
RegCloseKey(hk);
}
// figure out what device name to advertise
if(fOk)
{
fOk = GetModuleFileName(hInst, szTemp, sizeof(szTemp) / sizeof(szTemp[0]));
DEBUGCHK(fOk);
}
// now advertise the interface
if(fOk)
{
fOk = AdvertiseInterface(&gClass, szTemp, TRUE);
DEBUGCHK(fOk);
}
return fOk;
}
//
// Main entry point for a GPE-compliant driver
GPE *
GetGPE( )
{
if (!gGPE)
{
gGPE = new S3C2450DISP( );
}
return gGPE;
}
ULONG gBitMasks[ ] = { 0xf800,0x07e0,0x001f}; //< This is for RGB565 Format Bitmask.
S3C2450DISP::S3C2450DISP( )
{
DWORD oldMode;
ULONG fbSize;
ULONG fbOffset;
ULONG offsetX;
ULONG offsetY;
m_InDDraw = FALSE;
m_pIntrReg = (S3C2450_INTR_REG *)VirtualAlloc(0, sizeof(S3C2450_INTR_REG), MEM_RESERVE, PAGE_NOACCESS);
if (m_pIntrReg == NULL)
{
return;
}
if (!VirtualCopy((PVOID)m_pIntrReg, (PVOID)(S3C2450_BASE_REG_PA_INTR >> 8), sizeof(S3C2450_INTR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE)) {
return;
}
m_pLCDReg = (S3C2450_LCD_REG *)VirtualAlloc(0, sizeof(S3C2450_LCD_REG), MEM_RESERVE, PAGE_NOACCESS);
if (m_pLCDReg == NULL)
{
return;
}
if (!VirtualCopy((PVOID)m_pLCDReg, (PVOID)(S3C2450_BASE_REG_PA_LCD >> 8), sizeof(S3C2450_LCD_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE)) {
return;
}
// regist LCD Interrupt
m_dwVSYNCIrq = IRQ_LCD_VSYNC;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &m_dwVSYNCIrq, sizeof(DWORD), &m_dwVSYNCSysIntr, sizeof(DWORD), NULL))
{
m_dwVSYNCSysIntr = SYSINTR_UNDEFINED;
return;
}
m_hVSYNCInterruptEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(NULL == m_hVSYNCInterruptEvent)
{
return;
}
if (!(InterruptInitialize(m_dwVSYNCSysIntr, m_hVSYNCInterruptEvent, 0, 0)))
{
return;
}
m_pLCDReg->VIDINTCON &= ~((0x3)<<15 | (0x3)<<13 | (0x1) <<12 | (0x1) ); // FRAMESEL0, INTFRMEN Bit clear
m_pLCDReg->VIDINTCON |= ((0x3)<<15 /*| (0x0)<<13 | (0x1)<<12*/ ); /// Video Frame Disalbe
fpVisibleOverlay = 0;
fpOverlayFlipFrom = 0;
InitializeCriticalSection(&m_CS);
InitializeCriticalSection(&m_cs2D);
oldMode = SetKMode(TRUE);
m_RedMaskSize = 5;
m_RedMaskPosition = 11;
m_GreenMaskSize = 6;
m_GreenMaskPosition = 5;
m_BlueMaskSize = 5;
m_BlueMaskPosition = 0;
gBitMasks[0] =((1<<m_RedMaskSize) -1) << m_RedMaskPosition;
gBitMasks[1] =((1<<m_GreenMaskSize)-1) << m_GreenMaskPosition;
gBitMasks[2] =((1<<m_BlueMaskSize) -1) << m_BlueMaskPosition;
m_VesaMode = 0;
m_nScreenWidth = LCD_XSIZE_TFT;
m_nScreenHeight = LCD_YSIZE_TFT;
m_colorDepth = 16;
m_cxPhysicalScreen = LCD_XSIZE_TFT;
m_cyPhysicalScreen = LCD_YSIZE_TFT;
m_pvFlatFrameBuffer = IMAGE_FRAMEBUFFER_DMA_BASE;
m_cbScanLineLength = m_nScreenWidth * 2;
m_FrameBufferSize = m_nScreenHeight * m_cbScanLineLength;
m_VideoPowerState = VideoPowerOn;
m_iRotate = GetRotateModeFromReg();
SetRotateParams();
SetKMode(oldMode);
//< Initialize Display Mode
InitializeDisplayMode();
// compute frame buffer displayable area offset
offsetX = (m_cxPhysicalScreen - m_nScreenWidthSave) / 2;
offsetY = (m_cyPhysicalScreen - m_nScreenHeightSave) / 2;
fbOffset = (offsetY * m_cbScanLineLength) + offsetX;
// compute physical frame buffer size
fbSize = m_cyPhysicalScreen * m_cbScanLineLength;
// for DDraw enabled, make sure we also have some off-screen video memory available for surface allocations
fbSize = IMAGE_FRAMEBUFFER_SIZE;
// Use CreateFileMapping/MapViewOfFile to guarantee the VirtualFrameBuffer
// pointer is allocated in shared memory.
m_hVFBMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, fbSize, NULL);
if (m_hVFBMapping != NULL)
{
m_VirtualFrameBuffer = (DWORD)MapViewOfFile(m_hVFBMapping, FILE_MAP_WRITE, 0, 0, 0);
}
else
{
m_VirtualFrameBuffer = NULL;
}
if (VirtualCopy((void *)m_VirtualFrameBuffer, (void *)(m_pvFlatFrameBuffer >> 8), fbSize, PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL))
{
if (VirtualSetAttributes((void *)m_VirtualFrameBuffer, fbSize, 0x4, 0xc, NULL) != TRUE)
{
RETAILMSG (jj, (_T("Couldn't change framebuffer's page attributes as NCB.")));
RETAILMSG (jj, (_T("VirtualSetAttributes failed.")));
}
}
PREFAST_ASSERT(m_VirtualFrameBuffer);
memset ((void*)m_VirtualFrameBuffer, 0x0, fbSize); //< Screen Clear
m_VirtualFrameBuffer += fbOffset;
fbSize -= fbOffset;
m_pVideoMemoryHeap = new SurfaceHeap(fbSize, m_VirtualFrameBuffer, NULL, NULL);
if(!m_pVideoMemoryHeap)
{
RETAILMSG (jj, (L"Failed to create surface heap on internal SRAM memory\n"));
return;
}
m_CursorVisible = FALSE;
m_CursorDisabled = TRUE;
m_CursorForcedOff = FALSE;
memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
BOOL bResult;
m_oG2D = new FIMGSE2D;
if(m_oG2D == NULL)
{
RETAILMSG(jj, (TEXT("--S3C2450DISP() 2D Accelerator Initialization Fail\r\n")));
}
else
{
m_oG2D->Init();
RETAILMSG(jj, (TEXT("--S3C2450DISP() 2D Accelerator Initialization Succeed\r\n")));
}
if(m_oG2D)
{
bResult = m_oG2D->InitializeInterrupt();
if(bResult==FALSE)
{
RETAILMSG(jj, (TEXT("--S3C2450DISP() 2D Acclerator Interrupt Initialization Failed.\r\n")));
}
else
{
RETAILMSG(jj, (TEXT("--S3C2450DISP() 2D Acclerator Interrupt Initialization Succeed.\r\n")));
}
}
else
{
RETAILMSG(jj, (TEXT("--S3C2450DISP() 2D Acclerator Object was not created.\r\n")));
}
AdvertisePowerInterface(g_hmodDisplayDll);
}
S3C2450DISP::~S3C2450DISP( )
{
if (m_VirtualFrameBuffer != NULL)
{
UnmapViewOfFile((LPVOID)m_VirtualFrameBuffer);
}
if (m_hVFBMapping != NULL)
{
CloseHandle(m_hVFBMapping);
}
if (m_pLCDReg)
{
VirtualFree((PVOID)m_pLCDReg, 0, MEM_RELEASE);
m_pLCDReg = NULL;
}
if (m_pIntrReg)
{
VirtualFree((PVOID)m_pIntrReg, 0, MEM_RELEASE);
m_pIntrReg = NULL;
}
if (m_oG2D)
{
m_oG2D->DeinitInterrupt( );
delete m_oG2D;
}
}
void S3C2450DISP::CursorOn (void)
{
UCHAR *ptrScreen = (UCHAR*)m_pPrimarySurface->Buffer();
UCHAR *ptrLine;
UCHAR *cbsLine;
int x, y;
if (!m_CursorForcedOff && !m_CursorDisabled && !m_CursorVisible)
{
RECTL cursorRectSave = m_CursorRect;
int iRotate;
RotateRectl(&m_CursorRect);
for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
{
if (y < 0)
{continue;}
if (y >= m_nScreenHeightSave)
{break;}
ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];
for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
{
if (x < 0)
{continue;}
if (x >= m_nScreenWidthSave)
{break;}
switch (m_iRotate)
{
case DMDO_0:
iRotate = (y - m_CursorRect.top)*m_CursorSize.x + x - m_CursorRect.left;
break;
case DMDO_90:
iRotate = (x - m_CursorRect.left)*m_CursorSize.x + m_CursorSize.y - 1 - (y - m_CursorRect.top);
break;
case DMDO_180:
iRotate = (m_CursorSize.y - 1 - (y - m_CursorRect.top))*m_CursorSize.x + m_CursorSize.x - 1 - (x - m_CursorRect.left);
break;
case DMDO_270:
iRotate = (m_CursorSize.x -1 - (x - m_CursorRect.left))*m_CursorSize.x + y - m_CursorRect.top;
break;
default:
iRotate = (y - m_CursorRect.top)*m_CursorSize.x + x - m_CursorRect.left;
break;
}
cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3)] = ptrLine[x * (m_colorDepth >> 3)];
ptrLine[x * (m_colorDepth >> 3)] &= m_CursorAndShape[iRotate];
ptrLine[x * (m_colorDepth >> 3)] ^= m_CursorXorShape[iRotate];
if (m_colorDepth > 8)
{
cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 1] = ptrLine[x * (m_colorDepth >> 3) + 1];
ptrLine[x * (m_colorDepth >> 3) + 1] &= m_CursorAndShape[iRotate];
ptrLine[x * (m_colorDepth >> 3) + 1] ^= m_CursorXorShape[iRotate];
if (m_colorDepth > 16)
{
cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 2] = ptrLine[x * (m_colorDepth >> 3) + 2];
ptrLine[x * (m_colorDepth >> 3) + 2] &= m_CursorAndShape[iRotate];
ptrLine[x * (m_colorDepth >> 3) + 2] ^= m_CursorXorShape[iRotate];
}
}
}
}
m_CursorRect = cursorRectSave;
m_CursorVisible = TRUE;
}
}
void S3C2450DISP::CursorOff (void)
{
UCHAR *ptrScreen = (UCHAR*)m_pPrimarySurface->Buffer();
UCHAR *ptrLine;
UCHAR *cbsLine;
int x, y;
if (!m_CursorForcedOff && !m_CursorDisabled && m_CursorVisible)
{
RECTL rSave = m_CursorRect;
RotateRectl(&m_CursorRect);
for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
{
// clip to displayable screen area (top/bottom)
if (y < 0)
{continue;}
if (y >= m_nScreenHeightSave)
{break;}
ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];
for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
{
// clip to displayable screen area (left/right)
if (x < 0)
{continue;}
if (x >= m_nScreenWidthSave)
{break;}
ptrLine[x * (m_colorDepth >> 3)] = cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3)];
if (m_colorDepth > 8)
{
ptrLine[x * (m_colorDepth >> 3) + 1] = cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 1];
if (m_colorDepth > 16)
{
ptrLine[x * (m_colorDepth >> 3) + 2] = cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 2];
}
}
}
}
m_CursorRect = rSave;
m_CursorVisible = FALSE;
}
}
SCODE S3C2450DISP::SetPointerShape(GPESurf *pMask, GPESurf *pColorSurf, INT xHot, INT yHot, INT cX, INT cY)
{
UCHAR *andPtr; // input pointer
UCHAR *xorPtr; // input pointer
UCHAR *andLine; // output pointer
UCHAR *xorLine; // output pointer
char bAnd;
char bXor;
int row;
int col;
int i;
int bitMask;
// turn current cursor off
CursorOff( );
// release memory associated with old cursor
if (!pMask) // do we have a new cursor shape
{
m_CursorDisabled = TRUE; // no, so tag as disabled
}
else
{
m_CursorDisabled = FALSE; // yes, so tag as not disabled
// store size and hotspot for new cursor
m_CursorSize.x = cX;
m_CursorSize.y = cY;
m_CursorHotspot.x = xHot;
m_CursorHotspot.y = yHot;
andPtr = (UCHAR*)pMask->Buffer();
xorPtr = (UCHAR*)pMask->Buffer() + (cY * pMask->Stride());
// store OR and AND mask for new cursor
for (row = 0; row < cY; row++)
{
andLine = &m_CursorAndShape[cX * row];
xorLine = &m_CursorXorShape[cX * row];
for (col = 0; col < cX / 8; col++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -