dispdrvr.c
来自「PXA255 WINCE 4.2 BSP ,该BSP是商用的。」· C语言 代码 · 共 1,785 行 · 第 1/4 页
C
1,785 行
}
// Free all the global memory resources
void Cleanup(void)
{
if (v_pLcdRegs)
{
VirtualFree((PVOID)v_pLcdRegs,0,MEM_RELEASE);
v_pLcdRegs = NULL;
}
if (v_pClkRegs)
{
VirtualFree((PVOID)v_pClkRegs,0,MEM_RELEASE);
v_pLcdRegs = NULL;
}
if (v_pGPIORegs)
{
VirtualFree((PVOID)v_pGPIORegs,0,MEM_RELEASE);
v_pGPIORegs = NULL;
}
if (frameDescriptorCh0fd1)
{
VirtualFree((PVOID)frameDescriptorCh0fd1,0,MEM_RELEASE);
frameDescriptorCh0fd1 = NULL;
}
if (frameDescriptorCh0fd2)
{
VirtualFree((PVOID)frameDescriptorCh0fd2,0,MEM_RELEASE);
frameDescriptorCh0fd2 = NULL;
}
if (frameDescriptorCh1)
{
VirtualFree((PVOID)frameDescriptorCh1,0,MEM_RELEASE);
frameDescriptorCh1 = NULL;
}
if (frameDescriptorPalette)
{
VirtualFree((PVOID)frameDescriptorPalette,0,MEM_RELEASE);
frameDescriptorPalette = NULL;
}
if (v_pPaletteBuffer)
{
VirtualFree((PVOID)v_pPaletteBuffer,0,MEM_RELEASE);
v_pPaletteBuffer = NULL;
}
// If using the section descriptor, there's no memory to free, so don't do the VirtualFree.
if ((gFrameBuffer) && (gFrameBuffer != (PBYTE)FRAME_BUFFER_0_BASE_VIRTUAL))
{
VirtualFree((PVOID)gFrameBuffer,0,MEM_RELEASE);
gFrameBuffer = NULL;
}
#ifdef PLAT_LUBBOCK
if (v_pBoardLevelRegister)
{
VirtualFree((PVOID)v_pBoardLevelRegister,0,MEM_RELEASE);
v_pBoardLevelRegister = NULL;
}
#endif
#ifdef PLAT_SANDGATE
if (v_pPWMRegs)
{
VirtualFree((PVOID)v_pPWMRegs,0,MEM_RELEASE);
v_pPWMRegs = NULL;
}
#endif
}
void DispDrvrPowerHandler(BOOL bOff)
{
if(bOff)
{
DisableLCDController();
}
else
{
// Copy the original frame buffer back in.
CopyFrameBuffer(FALSE);
// Initialize the GPIO registers for proper LCD Controller operation
LcdSetupGPIOs();
// Initialize the LCD Controller and Board Control Register
InitLCDController();
// Clear LCD Controller status register
LCDClearStatusReg();
// Enable the LCD controller
EnableLCDController();
}
}
void CopyFrameBuffer(BOOL gDirection)
{
DWORD i;
unsigned *cfbp;
unsigned *fbp;
cfbp=(unsigned *)gBlankFrameBuffer;
fbp=(unsigned *)gFrameBuffer+(activeFrameBuffer*frameBufferSize);
for(i=0;i<(DispDrvr_cxScreen*DispDrvr_cyScreen*(bpp/8)/4);i++)
{
if (gDirection)
*cfbp++ = *fbp++;
else
*fbp++ = *cfbp++;
}
}
void ClearFrameBuffer(BOOL color)
{
DWORD i;
unsigned *fbp;
fbp=(unsigned *)gFrameBuffer+(activeFrameBuffer*frameBufferSize);
for(i=0;i<(DispDrvr_cxScreen*DispDrvr_cyScreen*(bpp/8)/4);i++)
{
if (color)
*fbp++ = 0xFFFFFFFF; // Ones turn it white
else
*fbp++ = 0x000000000; // Zeros turn it black
}
}
//**********************************************************************
//
//DispDrvrContrastControl:
//
// Modify the contrast according to the Cmd parameter.
// Not supported
//
BOOL DispDrvrContrastControl(int Cmd,DWORD *pValue)
{
// currently does not support changing contrast in software.
return TRUE;
}
void DirtyRectDumpPortraitLoop_C(BYTE *pDstBuf, BYTE *pSrcBuf, DWORD yTop, DWORD yBottom,
DWORD srcWidthB, DWORD bytesPerRow, DWORD bytesPerPixel,
DWORD srcMarginWidth, DWORD dstMarginWidth)
{
DWORD row,i,j;
if ( bytesPerPixel != 2 ) {
//not 16-bit
for (i=0;i<srcWidthB/bytesPerPixel;i++) {
for (row=yTop;row < yBottom;row++) {
for (j=0;j<bytesPerPixel;j++) {
*pDstBuf++=*(pSrcBuf+j);
}
pSrcBuf-=bytesPerRow;
}
pDstBuf+=dstMarginWidth;
pSrcBuf+=srcMarginWidth+2;
}
}else {
WORD *pwDst, *pwSrc;
int rowLen;
//16-bit
srcWidthB >>= 1;
pwDst = (WORD *)pDstBuf;
pwSrc = (WORD *)pSrcBuf;
//first row for pwSrc, then column for pwDst
rowLen = yBottom - yTop;
#ifndef _OPT_ASM
bytesPerRow >>=1;
dstMarginWidth >>=1;
srcMarginWidth >>=1;
for (i=0;i<srcWidthB;i++) {
for (row=0;row < (rowLen >>2);row++) {
*pwDst ++ = *pwSrc;
pwSrc-=bytesPerRow;
*pwDst ++ = *pwSrc;
pwSrc-=bytesPerRow;
*pwDst ++ = *pwSrc;
pwSrc-=bytesPerRow;
*pwDst ++ = *pwSrc;
pwSrc-=bytesPerRow;
}
for (row=0;row < (rowLen & 0x3);row++) {
*pwDst ++ = *pwSrc;
pwSrc-=bytesPerRow;
}
pwDst +=dstMarginWidth;
pwSrc +=srcMarginWidth+1;
}
#else
dirtyRectDump_core_ASM(pwSrc, pwDst, rowLen, srcWidthB, bytesPerRow, srcMarginWidth, dstMarginWidth);
#endif
}
}
void DispDrvrDirtyRectDump(LPCRECT prc)
{
BYTE *pDstBuf,*pSrcBuf,*pSrcMask;
DWORD xLeft,yTop,xRight,yBottom;
DWORD bytesPerRow,bytesPerPixel,srcBytesPerRow;
DWORD row,i,j;
DWORD srcWidthB,srcMarginWidth,clipWidthB,dstMarginWidth,cursorWidthB;
DWORD srcStartRow,dstStartRow;
if (bAllowOSFrameBufferUpdates)
{
bytesPerPixel=bpp/8;
xLeft = prc->left < 0 ? 0 : prc->left;
yTop = prc->top < 0 ? 0 : prc->top;
xRight = prc->right > gDibBufferWidth ? gDibBufferWidth : prc->right;
yBottom = prc->bottom > gDibBufferHeight ? gDibBufferHeight : prc->bottom;
if ((LONG)xLeft >= (LONG)xRight || (LONG)yTop >= (LONG)yBottom) return;
xLeft*=bytesPerPixel;
xRight*=bytesPerPixel;
bytesPerRow=DispDrvr_cxScreen*bytesPerPixel;
srcBytesPerRow=gDibBufferWidth*bytesPerPixel;
srcWidthB = xRight -xLeft;
if (bLandscapeDisplay) {
srcStartRow = yTop * srcBytesPerRow;
srcMarginWidth = srcBytesPerRow-srcWidthB;
dstStartRow = yTop * bytesPerRow;
dstMarginWidth = bytesPerRow-srcWidthB;
pDstBuf = gFrameBuffer + dstStartRow + xLeft;
} else {
srcStartRow = (yBottom-1) * srcBytesPerRow;
srcMarginWidth = (yBottom-yTop) * srcBytesPerRow;
dstStartRow = xLeft * DispDrvr_cyScreen;
dstMarginWidth = (DispDrvr_cyScreen-(yBottom-yTop))*bytesPerPixel;
pDstBuf = gFrameBuffer + dstStartRow + (DispDrvr_cyScreen -yBottom)*bytesPerPixel;
}
pSrcBuf = gDibBuffer +srcStartRow +xLeft;
EnterCriticalSection(&displayMutex);
if (bLandscapeDisplay) {
for (row = yTop;row < yBottom;row++) {
i=srcWidthB;
#if 0
while(i > 0)
{
if (i<4 || ((unsigned)pDstBuf & 0x3) || ((unsigned)pSrcBuf & 0x3))
{
*pDstBuf++ = *pSrcBuf;
pSrcBuf++;
i-=1;
} else
{
*(unsigned *)pDstBuf = *(unsigned *)pSrcBuf;
pDstBuf+=4;
pSrcBuf+=4;
i-=4;
}
}
pSrcBuf += srcMarginWidth;
pDstBuf += dstMarginWidth;
#else // !0
memcpy(pDstBuf, pSrcBuf, i);
pDstBuf += i + dstMarginWidth;
pSrcBuf += i + srcMarginWidth;
#endif // 0
}
} else {
DirtyRectDumpPortraitLoop_C(pDstBuf, pSrcBuf, yTop, yBottom, srcWidthB, bytesPerRow,
bytesPerPixel, srcMarginWidth, dstMarginWidth);
}
// Cursor update request?.
if (gDrawCursorFlag &&
gCursorRect.left*bytesPerPixel < xRight && gCursorRect.right*bytesPerPixel > xLeft &&
(DWORD)gCursorRect.top < yBottom && (DWORD)gCursorRect.bottom > yTop) {
DWORD srcRowMarginB;
DWORD cursorSizeXB;
yTop=gCursorRect.top;
// Clip off cursor if past bottom of screen
yBottom = gCursorRect.bottom > gDibBufferHeight ? gDibBufferHeight : gCursorRect.bottom;
// Now clip off cursor if past right side of screen
clipWidthB=gCursorRect.right > gDibBufferWidth ? gCursorRect.right -gDibBufferWidth: 0;
clipWidthB*=bytesPerPixel;
xLeft=gCursorRect.left*bytesPerPixel;
cursorWidthB=CURSOR_XSIZE*bytesPerPixel;
cursorSizeXB=(gCursorRect.right - gCursorRect.left)*bytesPerPixel;
srcWidthB=cursorSizeXB - clipWidthB;
srcRowMarginB = cursorWidthB - cursorSizeXB;
if (bLandscapeDisplay) {
srcStartRow = 0;
srcMarginWidth = 0;
dstStartRow = yTop * bytesPerRow;
dstMarginWidth = bytesPerRow-srcWidthB;
pDstBuf = gFrameBuffer + dstStartRow + xLeft;
} else {
srcStartRow = (yBottom-yTop-1) * cursorWidthB;
srcMarginWidth = (yBottom-yTop) * cursorWidthB;
dstStartRow = xLeft * DispDrvr_cyScreen;
dstMarginWidth = (DispDrvr_cyScreen-(yBottom-yTop))*bytesPerPixel;
pDstBuf = gFrameBuffer + dstStartRow + (DispDrvr_cyScreen -yBottom)*bytesPerPixel;
}
pSrcBuf =(BYTE *)gCursorData + srcStartRow;
pSrcMask =(BYTE *)gCursorMask + srcStartRow;
if (bLandscapeDisplay) {
for (row=yTop;row<yBottom;row++)
{
i=srcWidthB;
pSrcBuf += srcRowMarginB;
pSrcMask += srcRowMarginB;
while (i > 0)
{
if (i<4 || ((unsigned)pDstBuf & 0x3) || ((unsigned)pSrcBuf & 0x3))
{
*pDstBuf &= *pSrcMask;
*pDstBuf++ ^= *pSrcBuf;
pSrcMask++;
pSrcBuf++;
i-=1;
} else
{
*(unsigned *)pDstBuf &= *(unsigned *)pSrcMask;
*(unsigned *)pDstBuf ^= *(unsigned *)pSrcBuf;
pDstBuf+=4;
pSrcMask+=4;
pSrcBuf+=4;
i-=4;
}
}
pSrcMask += clipWidthB;
pSrcBuf += clipWidthB;
pDstBuf += dstMarginWidth;
}
} else {
pSrcBuf += srcRowMarginB;
pSrcMask += srcRowMarginB;
for (i=0;i<srcWidthB/bytesPerPixel;i++) {
for (row=yTop;row<yBottom;row++) {
for (j=0;j<bytesPerPixel;j++) {
*pDstBuf &= *(pSrcMask+j);
*pDstBuf++ ^= *(pSrcBuf+j);
}
pSrcBuf-=cursorWidthB;
pSrcMask-=cursorWidthB;
}
pSrcBuf +=srcMarginWidth+2;
pSrcMask +=srcMarginWidth+2;
pDstBuf +=dstMarginWidth;
}
}
}
LeaveCriticalSection(&displayMutex);
}
}
void DirtyRectDumpPortraitLoop_C_rectfill(BYTE *pDstBuf, WORD srcColor,DWORD yTop,DWORD yBottom,
DWORD srcWidthB, DWORD bytesPerRow, DWORD bytesPerPixel, DWORD srcMarginWidth, DWORD dstMarginWidth)
{
DWORD row,i;
WORD *pwDst;
WORD rowLen;
//16-bit
srcWidthB >>= 1;
pwDst = (WORD *)pDstBuf;
//first row for pwSrc, then column for pwDst
rowLen = (WORD)(yBottom - yTop);
bytesPerRow >>=1;
dstMarginWidth >>=1;
srcMarginWidth >>=1;
for (i=0;i<srcWidthB;i++) {
for (row=0;row < (DWORD)(rowLen >>2);row++) {
*pwDst ++ = srcColor;
*pwDst ++ = srcColor;
*pwDst ++ = srcColor;
*pwDst ++ = srcColor;
}
for (row=0;row < (DWORD)(rowLen & 0x3);row++) {
*pwDst ++ = srcColor;
}
pwDst +=dstMarginWidth;
}
}
void DispDrvrDirtyRectDump_rectfill(LPCRECT prc, DWORD color)
{
BYTE *pDstBuf,*pSrcBuf,*pSrcMask;
WORD srcColor = (WORD)color;
DWORD xLeft,yTop,xRight,yBottom;
DWORD bytesPerRow,bytesPerPixel,srcBytesPerRow;
DWORD row,i,j;
DWORD srcWidthB,srcMarginWidth,clipWidthB,dstMarginWidth,cursorWidthB;
DWORD srcStartRow,dstStartRow;
DWORD srcMarginWidth2;
DWORD dstMarginWidth2;
DWORD dstStep;
if (bAllowOSFrameBufferUpdates)
{
bytesPerPixel=bpp/8;
xLeft = prc->left < 0 ? 0 : prc->left;
yTop = prc->top < 0 ? 0 : prc->top;
xRight = prc->right > gDibBufferWidth ? gDibBufferWidth : prc->right;
yBottom = prc->bottom > gDibBufferHeight ? gDibBufferHeight : prc->bottom;
if ((LONG)xLeft >= (LONG)xRight || (LONG)yTop >= (LONG)yBottom) return;
xLeft*=bytesPerPixel;
xRight*=bytesPerPixel;
bytesPerRow=DispDrvr_cxScreen*bytesPerPixel;
srcBytesPerRow=gDibBufferWidth*bytesPerPixel;
srcWidthB = xRight -xLeft;
if (bLandscapeDisplay) {
srcStartRow = yTop * srcBytesPerRow;
srcMarginWidth = srcBytesPerRow-srcWidthB;
dstStartRow = yTop * bytesPerRow;
dstMarginWidth = bytesPerRow-srcWidthB;
pDstBuf = gFrameBuffer + dstStartRow + xLeft;
} else {
srcStartRow = (yBottom-1) * srcBytesPerRow;
srcMarginWidth = (yBottom-yTop) * srcBytesPerRow;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?