📄 fimgse2d.cpp
字号:
CheckFifo(1);
InterruptEnable();
m_pG2DReg->CMDR1 = G2D_NORMAL_BITBLT_BIT; // One Instruction
while(!WaitForFinish());
InterruptDisable();
}
// Resource Register Clear
SetRotationOrg(0,0);
m_pG2DReg->ROT_MODE = G2D_ROTATION_0_DEG_BIT;
SetRopEtype(ROP_SRC_ONLY);
// InterruptPendingClear();
}
#endif
void FIMGSE2D::BitBlt(GPEBltParms *pBltParms)
{
PRECTL prcSrc, prcDst;
prcSrc = pBltParms->prclSrc;
prcDst = pBltParms->prclDst;
#if 0
// check for negative x or y direction and correct values accordingly
if (!pBltParms->xPositive)
{
RETAILMSG (1, (TEXT("X Neg\r\n")));
}
if (!pBltParms->yPositive)
{
RETAILMSG (1, (TEXT("Y Neg\r\n")));
}
#endif
#if 1 // StretchBlt Spec out.
if((pBltParms->bltFlags & BLT_STRETCH) == BLT_STRETCH)
{
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::SetPatternOffsetX(BYTE ucPatOffsetX)
{
ucPatOffsetX &= 0x7; // ucPatOffsetX[2:0]
CheckFifo(17);
m_pG2DReg->PAT_OFF_X = ucPatOffsetX;
}
void FIMGSE2D::SetPatternOffsetY(BYTE ucPatOffsetY)
{
ucPatOffsetY &= 0x7; // ucPatOffsetY[2:0]
CheckFifo(17);
m_pG2DReg->PAT_OFF_Y = ucPatOffsetY;
}
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 bIsTransparent == 1, Transparent Mode and uBgColor isn't applied
// else if bIsTransparent ==0, Opaque Mode
void FIMGSE2D::SetFontColor(DWORD uFontColor, DWORD uBgColor, bool bIsTransparent)
{
DWORD uRopRegVal;
CheckFifo(17);
uRopRegVal = m_pG2DReg->ROP;
uRopRegVal =
(bIsTransparent == 1) ? (uRopRegVal | G2D_TRANSPARENT_BIT) : (uRopRegVal & ~(G2D_TRANSPARENT_BIT));
m_pG2DReg->ROP = uRopRegVal;
m_pG2DReg->FG_COLOR = uFontColor;
m_pG2DReg->BG_COLOR = uBgColor;
}
void FIMGSE2D::SetFontColor(G2D_COLOR eFontColor, G2D_COLOR eBgColor, bool bIsTransparent)
{
SetFontColor(m_uColorVal[eFontColor], m_uColorVal[eBgColor], bIsTransparent);
}
#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
InterruptEnable();
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);
InterruptDisable();
// InterruptPendingClear();
}
#endif
void FIMGSE2D::PutString(DWORD uPosX, DWORD uPosY, char* cStr)
{
BYTE* ucOneLetter;
DWORD uHostData = 0x0;
DWORD uTempData = 0x0;
unsigned int i, j, k;
DWORD uPosX2, uPosY2;
DWORD uFontOffset;
DWORD uAddressOffset;
// Only support 8X15 font size
// All font size will be implemented, but now only support 8X15 font size
if(m_bIsBitBlt==true) printf("Host to screen BitBLT!\n");
if(m_uFontWidth==8 && m_uFontHeight==8)
uFontOffset = 8;
else if(m_uFontWidth==8 && m_uFontHeight==15)
uFontOffset = 15;
else if(m_uFontWidth==8 && m_uFontHeight==16)
uFontOffset = 16;
uPosX2 = uPosX + m_uFontWidth - 1;
uPosY2 = uPosY + m_uFontHeight - 1;
CheckFifo(17);
for (i=0; i<strlen(cStr); i++)
{
if (m_bIsBitBlt == true)
{
m_pG2DReg->COORD2_X = uPosX; // COORD_0: LeftTop
m_pG2DReg->COORD2_Y = uPosY;
m_pG2DReg->COORD3_X = uPosX2; // COORD_1: RightBottom
m_pG2DReg->COORD3_Y = uPosY2;
//printf("HS BitBLT!\n");
}
if (m_bIsBitBlt == false)
{
m_pG2DReg->COORD0_X = uPosX; // COORD_0: LeftTop
m_pG2DReg->COORD0_Y = uPosY;
m_pG2DReg->COORD1_X = uPosX2; // COORD_1: RightBottom
m_pG2DReg->COORD1_Y = uPosY2;
}
ucOneLetter = m_upFontType + (cStr[i]-START_ASCII)*uFontOffset; // get start address of chosen letter in font8x15
uHostData = uTempData = 0;
for (j=0; j<4; j++) // Generate of first 1 word of data for a font (start)
{
uTempData = (DWORD)ucOneLetter[j];
uHostData |= (uTempData << (24 - 8*j));
}
if (m_bIsScr2Scr==1 && m_bIsBitBlt ==0) {
uAddressOffset=((m_uFontWidth/8*m_uFontHeight+3)/4)*4;
SetCMDR7(m_uFontAddr+(cStr[i]-START_ASCII)*uAddressOffset);
}
else if (m_bIsBitBlt) {
m_pG2DReg->CMDR2 = uHostData;
while(!bG2dDone);
bG2dDone=0;
}
else {
m_pG2DReg->CMDR4 = uHostData; // Set New font
while(!bG2dDone);
bG2dDone=0;
}
// for(k=0; k<3; k++) // Generate next 3 word of data for the font (continue)
for(k=0; k<((uFontOffset-4+3)/4); k++) // Generate next n word of data for the font (continue)
{
uHostData = uTempData = 0;
for (j=0+4*(k+1); j<4+4*(k+1); j++) // Upto font height(height: 15)
{
uTempData = (DWORD)ucOneLetter[j];
uHostData |= (uTempData<< (24 - 8*(j%4)));
}
if (m_bIsScr2Scr==1 && m_bIsBitBlt ==0) break;
else if (m_bIsBitBlt) {
m_pG2DReg->CMDR3 = uHostData;
while(!bG2dDone);
bG2dDone=0;
}
else {
m_pG2DReg->CMDR5 = uHostData;
while(!bG2dDone);
bG2dDone=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -