📄 fimgse2d.cpp
字号:
{
StretchBlt((WORD)prcSrc->left,
(WORD)prcSrc->top,
(WORD)prcSrc->right,
(WORD)prcSrc->bottom,
(WORD)prcDst->left,
(WORD)prcDst->top,
(WORD)prcDst->right,
(WORD)prcDst->bottom);
}
else
{
#endif
BitBlt( (WORD)prcSrc->left,
(WORD)prcSrc->top,
(WORD)prcSrc->right,
(WORD)prcSrc->bottom,
(WORD)prcDst->left,
(WORD)prcDst->top,
(WORD)prcDst->right,
(WORD)prcDst->bottom);
#if 1
}
#endif
}
bool FIMGSE2D::WaitForFinish(void)
{
volatile unsigned uPendVal;
// static DWORD pending_count = 0;
uPendVal = m_pG2DReg->INTC_PEND;
/* pending_count ++;
if(pending_count >50)
{
RETAILMSG (1, (TEXT("uPendVal : %x\r\n"),uPendVal));
}
*/
if( (uPendVal>>8) & 0x7){
switch( (uPendVal>>8) & 0x7) {
case 1:
m_pG2DReg->INTC_PEND = ((1<<31)|(1<<8)); // Overflow
break;
case 2:
m_pG2DReg->INTC_PEND = ((1<<31)|(1<<9)); // Command All Finish, Engine IDLE
break;
case 4:
m_pG2DReg->INTC_PEND = ((1<<31)|(1<<10)); // Drawing Engine Finish
return false;
default:
m_pG2DReg->INTC_PEND = ((1<<31)|(0x7<<8)); // All Clear
break;
}
m_pG2DReg->INTC_PEND = (DWORD)(1<<31); // Victor gave us a guidance such this line to clear pending.
// pending_count = 0;
return true;
}
return false;
}
// Get Original Coordinate (X,Y) to rotate window
// usDestStX, usDesStY : Target Destination after rotation
// (usSrcX1, usSrcY1), (usSrcX2, usSrcY2) : Coordinate (X1,Y1), (X2, Y2) before rotation
// usRotDegree : support only 90/180/270 degrees
// usOrigX, usOrigY : Rotation Coordinate. the register value for rG2D_ROT_OC_X and rG2D_ROT_OC_Y
// formula to get usOrigX, usOrigY
// | usDestX - usOrigX | | cosA -sinA | | usSRCX - usOrigX |
// | | = | | | |
// | usDestY - usOrigY | | sinA cosA | | usSRCY - usOrigY |
//
//
//( if A == 90 degrees, usSRCX = usSrcX1 and usSRCY = usSrcY2
// else if A == 180 degrees, usSRCX = usSrcX2 and usSRCY = usSrcY2
// else if A == 270 degrees, usSRCX = usSrcX1 and usSRCY = usSrcY2 )
// cf. SRC window coordinate
//
// (usSrcX1, usSrcY1) (usSrcX2, usSrcY1)
// *---------------------------------*
// | |
// | |
// | Window |
// | |
// | |
// *---------------------------------*
// (usSrcX1, usSrcY2) (usSrcX2, usSrcY2)
void FIMGSE2D::GetRotationOrgXY(WORD usSrcX1, WORD usSrcY1, WORD usSrcX2, WORD usSrcY2, WORD usDestX1, WORD usDestY1,
ROT_DEG eRotDegree, WORD* usOrgX, WORD* usOrgY)
{
// CheckFifo(17);
switch(eRotDegree)
{
case ROT_0:
return;
case ROT_90:
*usOrgX = (usDestX1 - usDestY1 + usSrcX1 + usSrcY2)/2;
*usOrgY = (usDestX1 + usDestY1 - usSrcX1 + usSrcY2)/2;
break;
case ROT_180:
*usOrgX = (usDestX1 + usSrcX2)/2;
*usOrgY = (usDestY1 + usSrcY2)/2;
break;
case ROT_270:
*usOrgX = (usDestX1 + usDestY1 + usSrcX2 - usSrcY1)/2;
*usOrgY = (usDestY1 - usDestX1 + usSrcX2 + usSrcY1)/2;
break;
default:
Assert(0); // UnSupported Rotation Degree!
break;
}
}
void FIMGSE2D::RotateImage(
WORD usSrcX1, WORD usSrcY1, WORD usSrcX2, WORD usSrcY2,
WORD usDestX1, WORD usDestY1, ROT_DEG eRotDegree)
{
WORD usOrgX, usOrgY;
DWORD uRotDegree;
GetRotationOrgXY(usSrcX1, usSrcY1, usSrcX2, usSrcY2, usDestX1, usDestY1, eRotDegree, &usOrgX, &usOrgY);
// CheckFifo(17);
SetRotationOrg(usOrgX, usOrgY);
uRotDegree =
(eRotDegree == ROT_0) ? G2D_ROTATION_0_DEG_BIT :
(eRotDegree == ROT_90) ? G2D_ROTATION_90_DEG_BIT :
(eRotDegree == ROT_180) ? G2D_ROTATION_180_DEG_BIT : G2D_ROTATION_270_DEG_BIT;
m_pG2DReg->ROT_MODE = uRotDegree;
}
void FIMGSE2D::RotateWithBitBlt(
WORD usSrcX1, WORD usSrcY1, WORD usSrcX2, WORD usSrcY2,
WORD usDestX1, WORD usDestY1, ROT_DEG eRotDegree)
{
RotateImage(usSrcX1, usSrcY1, usSrcX2, usSrcY2, usDestX1, usDestY1, eRotDegree);
BitBlt(usSrcX1, usSrcY1, usSrcX2, usSrcY2, usSrcX1, usSrcY1, usSrcX2, usSrcY2);
}
// if ucTransMode is '1', Transparent Mode
// else '0', Opaque Mode
void FIMGSE2D::SetTransparentMode(bool bIsTransparent, DWORD uBsColor)
{
DWORD uRopRegVal;
// CheckFifo(17);
uRopRegVal = m_pG2DReg->ROP;
uRopRegVal =
(bIsTransparent == 1) ? (uRopRegVal | G2D_TRANSPARENT_BIT) : (uRopRegVal & ~(G2D_TRANSPARENT_BIT));
m_pG2DReg->ROP = uRopRegVal;
// register Blue Screen Color
m_pG2DReg->BS_COLOR = uBsColor;
}
void FIMGSE2D::SetTransparentMode(bool bIsTransparent, G2D_COLOR eBsColor)
{
SetTransparentMode(bIsTransparent, m_uColorVal[eBsColor]);
}
// if ucTransMode is '1', Transparent Mode
// else '0', Opaque Mode
void FIMGSE2D::SetColorKeyOn(DWORD uBsColor)
{
CheckFifo(17);
m_pG2DReg->ROP = m_pG2DReg->ROP | G2D_TRANSPARENT_BIT;
// register Blue Screen Color
m_pG2DReg->BS_COLOR = uBsColor;
}
void FIMGSE2D::SetColorKeyOn(G2D_COLOR eBsColor)
{
SetColorKeyOn(m_uColorVal[eBsColor]);
}
void FIMGSE2D::SetColorKeyOff(void)
{
CheckFifo(17);
// Blue screen off
m_pG2DReg->ROP = m_pG2DReg->ROP & ~(G2D_TRANSPARENT_BIT);
// color key off
m_pG2DReg->COLORKEY_CNTL = (m_pG2DReg->COLORKEY_CNTL & ~(0x1U<<31));
}
void FIMGSE2D::SetFgEcolor(G2D_COLOR eFgColor)
{
SetFgColor(m_uColorVal[eFgColor]);
}
void FIMGSE2D::SetFgColor(DWORD uFgColor)
{
uFgColor &= 0x00ffffff;
m_pG2DReg->FG_COLOR = uFgColor;
}
void FIMGSE2D::SetBgEcolor(G2D_COLOR eBgColor)
{
SetBgColor(m_uColorVal[eBgColor]);
}
void FIMGSE2D::SetBgColor(DWORD uBgColor)
{
uBgColor &= 0x00ffffff;
m_pG2DReg->BG_COLOR = uBgColor;
}
void FIMGSE2D::SetBsColor(DWORD uBsColor)
{
uBsColor &= 0x00ffffff;
m_pG2DReg->BS_COLOR = uBsColor;
}
#if 1
void FIMGSE2D::FillRect(DWORD uDstStX, DWORD uDstStY, DWORD uDstEndX, DWORD uDstEndY, DWORD uColor)
{
// printf("BitBlt using LineDraw\n");
DWORD y=0;
for(y=uDstStY; y < uDstEndY; y++)
{
PutLine(uDstStX, y, uDstEndX, y, uColor, false);
}
}
#endif
#if 0 // Not Good for S3C6400
void FIMGSE2D::FillRect(DWORD uDstStX, DWORD uDstStY, DWORD uDstEndX, DWORD uDstEndY, DWORD uColor)
{
// printf("BitBLT using Color Expansion\n");
DWORD FillSize = 0;
DWORD ResidueBitCount = 0;
DWORD FillCount = 0;
DWORD ResidueBit = 0;
DWORD i;
DWORD VerifyCounter = 0;
SetCoordinateSrcBlock(uDstStX, uDstStY, uDstEndX-1, uDstEndY-1); // For CMD4, CMD5
SetCoordinateDstBlock(uDstStX, uDstStY, uDstEndX-1, uDstEndY-1); // For CMD2, CMD3
FillSize = (uDstEndX - uDstStX ) * ( uDstEndY - uDstStY);
ResidueBitCount = FillSize % 32; // DWORD align;
FillCount = FillSize >> 5; // FillSize / 32
ResidueBit = FillBitResidue[ResidueBitCount];
SetTransparentMode(1, m_uBgColor);
Set3rdOperand(G2D_OPERAND3_FG);
SetFgColor(uColor);
#if 0
printf("(%d,%d)~(%d,%d) FillSize: %d, ResidueBitCount: %d, FillCount : %d, ResidueBit: %x, FgColor: %x, BgColor: %x\n",
uDstStX, uDstStY, uDstEndX, uDstEndY,
FillSize,
ResidueBitCount,
FillCount,
ResidueBit,
m_pG2DReg->FG_COLOR,
m_pG2DReg->BG_COLOR);
#endif
IntEnable();
CheckFifo(17);
#if 1
if(FillCount == 0){ //// FillSize : 0~31
m_pG2DReg->CMDR2 = ResidueBit;
while(!WaitForFinish());
VerifyCounter ++;
}
else // FillSize >= 32
{
m_pG2DReg->CMDR2 = 0xFFFFFFFF;
while(!WaitForFinish());
VerifyCounter ++;
for(i = 1; i<FillCount; i++)
{
if(!(i%17))
{
CheckFifo(17);
}
m_pG2DReg->CMDR3 = 0xFFFFFFFF;
while(!WaitForFinish());
VerifyCounter ++;
}
if(ResidueBitCount != 0)
{
m_pG2DReg->CMDR3 = ResidueBit;
while(!WaitForFinish());
VerifyCounter ++;
}
}
#endif
// printf("VRC : %d", VerifyCounter);
IntDisable();
// IntPendingClear();
}
#endif
void FIMGSE2D::InitColor(CSPACE eBpp)
{
switch(eBpp) {
case ARGB8: // 15-bpp, The name of ARGB8 should be changed to proper name.
m_uColorVal[G2D_BLACK] = 0x0;
m_uColorVal[G2D_RED] = (0x1f<<10);
m_uColorVal[G2D_GREEN] =(0x1f<<5);
m_uColorVal[G2D_BLUE] =(0x1f<<0);
m_uColorVal[G2D_WHITE] =0x7fff;
break;
case RGB16:
m_uColorVal[G2D_BLACK] = 0x0;
m_uColorVal[G2D_RED] = 0x1f<<11;
m_uColorVal[G2D_GREEN] = 0x3f<<5;
m_uColorVal[G2D_BLUE] = 0x1f<<0;
m_uColorVal[G2D_WHITE] = 0xffff;
break;
case RGB18:
m_uColorVal[G2D_BLACK] = 0x0;
m_uColorVal[G2D_RED] = 0x3f<<12;
m_uColorVal[G2D_GREEN] = 0x3f<<6;
m_uColorVal[G2D_BLUE] = 0x3f<<0;
m_uColorVal[G2D_WHITE] = 0xffff;
break;
case RGB24:
m_uColorVal[G2D_BLACK] = 0x0;
m_uColorVal[G2D_RED] = 0xff0000;
m_uColorVal[G2D_GREEN] = 0xff00;
m_uColorVal[G2D_BLUE] = 0xff;
m_uColorVal[G2D_WHITE] = 0xffffff;
break;
default:
m_uColorVal[G2D_BLACK] = 0x0;
m_uColorVal[G2D_RED] = 0x1f<<11;
m_uColorVal[G2D_GREEN] = 0x3f<<5;
m_uColorVal[G2D_BLUE] = 0x1f<<0;
m_uColorVal[G2D_WHITE] = 0xffff;
Assert(0);
break;
}
m_uColorVal[G2D_YELLOW] = (m_uColorVal[G2D_RED] | m_uColorVal[G2D_GREEN]);
m_uColorVal[G2D_CYAN] = (m_uColorVal[G2D_GREEN] | m_uColorVal[G2D_BLUE]);
m_uColorVal[G2D_MAGENTA] = (m_uColorVal[G2D_RED] | m_uColorVal[G2D_BLUE]);
}
void FIMGSE2D::SetHoriRes(DWORD horires)
{
m_uHoriRes = horires;
m_pG2DReg->HORI_RES = m_uHoriRes; //lcdX should be 4n
}
void FIMGSE2D::SetFbAddr(DWORD uFbAddr)
{
m_uFbStAddr = uFbAddr;
m_pG2DReg->FB_BA = m_uFbStAddr;
}
void FIMGSE2D::SetColorMode(CSPACE eBpp)
{
DWORD uBppMode;
uBppMode = (eBpp == ARGB8) ? G2D_COLOR_15BPP_BIT :
(eBpp == RGB16) ? G2D_COLOR_16BPP_BIT :
(eBpp == RGB18) ? G2D_COLOR_18BPP_BIT :
(eBpp == RGB24) ? G2D_COLOR_24BPP_BIT : G2D_COLOR_24BPP_BIT;
m_pG2DReg->COLOR_MODE = uBppMode;
}
// uFbStAddr = _DRAM_BaseAddress+0x04000000;
// eBpp = 泅犁 祸惑 depth
// uCwMaxHSz =LCD Width
// uCwMaxVSz = LCD Height
// uX1_Cw = 0
// uY1_Cw = 0
// uX2_Cw = Lcd Width
// uY2_Cw = LCD Height
void FIMGSE2D::InitSetting(DWORD uFbStAddr, CSPACE eBpp, DWORD uCwMaxHSz, DWORD uCwMaxVSz, DWORD uX1_Cw, DWORD uY1_Cw, DWORD uX2_Cw, DWORD uY2_Cw) // modification
{
#if HW_PROBE // For check HW consume time, insert GPIO LED triggering code.
// GPIO Virtual alloc
if(g_pGPIORegs == NULL)
{
g_pGPIORegs = (volatile S3C6400_GPIO_REG *)DrvLib_MapIoSpace(S3C6400_BASE_REG_PA_GPIO, sizeof(S3C6400_GPIO_REG), FALSE);
}
if (g_pGPIORegs == NULL)
{
RETAILMSG(1,(TEXT("[GPIO] g_pGPIORegs: VirtualAlloc failed!\r\n")));
DrvLib_UnmapIoSpace((PVOID)g_pGPIORegs);
g_pGPIORegs = NULL;
}
// g_pGPIORegs->GPNPUD &= ~(0xff<<24); // Pull Up/Down Disable
// g_pGPIORegs->GPNCON = (g_pGPIORegs->GPNCON & ~(0xff<<24)) | (0x55<<24); // GPN[15:14] set to output
#endif
Assert(uCwMaxHSz <= 2048); // Max horizontal size of clipping window should be 2048.
Assert(uCwMaxVSz <= 2048); // Max vertical size of clipping window should be 2048.
RETAILMSG (0, (TEXT("FIMGSE2D:: FbStAddr : %x, eBpp : %d, MaxH : %d, MaxV : %d, X1:%d, Y1:%d, X2:%d, Y2:%d\r\n"), uFbStAddr, eBpp, uCwMaxHSz, uCwMaxVSz, uX1_Cw, uY1_Cw, uX2_Cw, uY2_Cw));
// Initialize color
InitColor(eBpp);
SetFbAddr(uFbStAddr);
SetHoriRes(uCwMaxHSz);
SetMaxScreen(uCwMaxHSz - 1, uCwMaxVSz - 1);
SetClippingWindow(uX1_Cw, uY1_Cw, uX2_Cw -1, uY2_Cw -1);
m_uBytes = (eBpp == RGB16) ? 2 : 4;
/// Font Operation Related
// m_upFontType = (BYTE *)font8x15;
m_uFontWidth = 8;
m_uFontHeight = 15;
m_bIsBitBlt = true;
m_bIsScr2Scr = false;
m_uFontAddr = (uFbStAddr&0xff000000)+0x800000;
SetColorMode(eBpp);
DisableEffect(); // Disable per-pixel/per-plane alpha blending and fading
SetColorKeyOff();
m_pG2DReg->ALPHA = (FADING_OFFSET_DISABLE | ALPHA_VALUE_DISABLE);
SetFgEcolor(G2D_WHITE); // set color to both font and foreground color
SetBgEcolor(G2D_BLACK);
SetBsColor(m_uColorVal[G2D_BLUE]); // Set blue color to blue screen color
m_pG2DReg->ROP = (G2D_OPERAND3_FG_BIT | G2D_NO_ALPHA_BIT | OPAQUE_ENABLE | G2D_ROP_SRC_ONLY);
SetRotationOrg(0, 0);
m_pG2DReg->ROT_MODE = G2D_ROTATION_0_DEG_BIT;
m_pG2DReg->ALPHA = 0;
SetReadSize(0x0); // Read Burst Size
m_pG2DReg->ENDIAN_READSIZE |= (0x1 << 2); // HW read buffer size enable
}
void FIMGSE2D::PutPixelEcolor(DWORD uPosX, DWORD uPosY, G2D_COLOR eColor) //modification
{
PutPixel(uPosX, uPosY, m_uColorVal[eColor]);
}
void FIMGSE2D::PutPixel(DWORD uPosX, DWORD uPosY, DWORD uColor) //modification
{
m_pG2DReg->COORD0_X = uPosX;
m_pG2DReg->COORD0_Y = uPosY;
m_pG2DReg->FG_COLOR = uColor;
CheckFifo(1);
IntEnable();
m_pG2DReg->CMDR0 = G2D_REND_POINT_BIT;
while(!WaitForFinish());
IntDisable();
}
/**
* Draw Line
* (usPosX1, usPosY1) ~ (usPosX2, usPosY2)
* Do not draw last point
* 0 < usPosX, usPosY1, usPosX2, usPosY2 < 2048
*/
void FIMGSE2D::PutLine(DWORD usPosX1, DWORD usPosY1, DWORD usPosX2, DWORD usPosY2, DWORD uColor, bool bIsDrawLastPoint) //modification
{
int nMajorCoordX;
DWORD uHSz, uVSz;
int i;
int nIncr=0;
DWORD uCmdRegVal;
CheckFifo(1);
m_pG2DReg->COORD0_X = usPosX1;
m_pG2DReg->COORD0_Y = usPosY1;
m_pG2DReg->COORD2_X = usPosX2;
m_pG2DReg->COORD2_Y = usPosY2;
// printf("COORD0_X: %d, COORD0_Y:%d, COORD2_X:%d, COORD2_Y:%d\n",
// m_pG2DReg->COORD0 & (0x7ff),
// (m_pG2DReg->COORD0 & (0x7ff<<16)) >> 16,
// m_pG2DReg->COORD2 & (0x7ff),
// (m_pG2DReg->COORD2 & (0x7ff<<16)) >> 16);
uVSz = ABS((WORD)usPosY1 - (WORD)usPosY2);
uHSz = ABS((WORD)usPosX1 - (WORD)usPosX2);
nMajorCoordX = (uHSz>=uVSz);
if(nMajorCoordX)
{
for (i=0; i<12; i++)
{
uVSz <<= 1;
nIncr <<= 1;
if (uVSz >= uHSz)
{
nIncr = nIncr | 1;
uVSz -= uHSz;
}
}
nIncr = (nIncr + 1) >> 1;
if (usPosY1 > usPosY2)
{
nIncr = (~nIncr) + 1; // 2's complement
}
// printf("pre YINCR: %x ", nIncr );
}
else
{
for (i=0; i<12; i++)
{
uHSz <<= 1;
nIncr <<= 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -