📄 fimgse2d.cpp
字号:
#elif (G2D_CMDPROCESSING==G2D_INTERRUPT)
CheckFifo(1);
IntEnable();
m_pG2DReg->CMDR1 = uCmdRegVal; // Process Only One Instruction per bitblt request
WaitForSingleObject(m_hInterrupt2D, INFINITE);
IntDisable();
IntPendingClear();
InterruptDone(m_dwSysIntr2D);
#elif (G2D_CMDPROCESSING==G2D_BUSYWAITING)
CheckFifo(1);
IntEnable();
while(!WaitForFinish()); // Polling Style
m_pG2DReg->CMDR1 = uCmdRegVal; // Process Only One Instruction per bitblt request
IntDisable();
#else
RETAILMSG(TRUE,(TEXT("CMDPROCESSING TYPE is invalid, Please Check Header Definition\n")));
return FALSE;
#endif
RETAILMSG(ZONE_CHECK(ZONE_STRETCHBLT),(TEXT("[2DHW] StretchBlt Exit\r\n")));
/// TODO: Resource Register clearing can be needed.
}
/**
* @fn FIMGSE2D::FlipBlt(PRECTL prclSrc, PRECTL prclDst, ROT_TYPE m_iRotate)
* @param prclSrc Source Rectangle
* @param prclDst Destination Rectangle
* @param m_iRotate Flip Setting. See also ROT_TYPE type
* @note This funciton performs ONLY FLIP Bit blit using 2D HW. this function cannot handle rotation case.
* There's predefine macro type for presenting rotation register's setting value
* This function requires Scratch Memory for Destination.
* This function don't support X&Y flipping
* @sa ROT_TYPE
**/
BOOL FIMGSE2D::FlipBlt(PRECTL prclSrc, PRECTL prclDst, ROT_TYPE m_iRotate)
{
DWORD uCmdRegVal=0;
RECTL rectDst; //< If rotation case this value must be corrected.
RETAILMSG(ZONE_CHECK(ZONE_FLIPBLT),(TEXT("[2DHW] FlipBlt Entry\r\n")));
/// Always LeftTop Coordinate is less than RightBottom for Source and Destination Region
Assert( (prclSrc->left < prclSrc->right) && (prclSrc->top < prclSrc->bottom) );
Assert( (prclDst->left < prclDst->right) && (prclDst->top < prclDst->bottom) );
/// Check Flip Option, we only do care about only flip, don't care about rotation option although it set.
if(HASBIT_COND(m_iRotate, FLIP_X))
{
SetRotationMode(FLIP_X);
/// Set rotation origin on destination's bottom line.
rectDst.left = prclDst->left; //< x1
rectDst.right = prclDst->right - 1; //< x2
rectDst.top = prclDst->bottom - 1; //< y2
rectDst.bottom = prclDst->bottom - 1 + prclDst->bottom - 1 - prclDst->top; //< y2 + (y2-y1)
}
else if(HASBIT_COND(m_iRotate, FLIP_Y))
{
SetRotationMode(FLIP_Y);
/// Set rotation origin on destination's right line.
rectDst.left = prclDst->right - 1; //< x2
rectDst.right = prclDst->right - 1 + prclDst->right - 1 - prclDst->left; //< x2 + (x2 - x1)
rectDst.top = prclDst->top; //< y1
rectDst.bottom = prclDst->bottom - 1; //< y2
}
else
{
/// Do not need to do Flip operation.
return FALSE;
}
SetCoordinateSrcBlock(prclSrc->left, prclSrc->top, prclSrc->right - 1, prclSrc->bottom - 1);
SetRotationOrg((WORD)rectDst.left, (WORD)rectDst.top);
SetCoordinateDstBlock(rectDst.left, rectDst.top, rectDst.right, rectDst.bottom);
uCmdRegVal = G2D_NORMAL_BITBLT_BIT;
#if (G2D_CMDPROCESSING==G2D_FASTRETURN)
WaitForEmptyFifo(); //< This is check fully empty command fifo.
m_pG2DReg->CMDR1 = uCmdRegVal; // Process Only One Instruction per bitblt request
#elif (G2D_CMDPROCESSING==G2D_INTERRUPT)
CheckFifo(1);
IntEnable();
m_pG2DReg->CMDR1 = uCmdRegVal; // Process Only One Instruction per bitblt request
WaitForSingleObject(m_hInterrupt2D, INFINITE);
IntDisable();
IntPendingClear();
InterruptDone(m_dwSysIntr2D);
#elif (G2D_CMDPROCESSING==G2D_BUSYWAITING)
CheckFifo(1);
IntEnable();
while(!WaitForFinish()); // Polling Style
m_pG2DReg->CMDR1 = uCmdRegVal; // Process Only One Instruction per bitblt request
IntDisable();
#else
RETAILMSG(TRUE,(TEXT("CMDPROCESSING TYPE is invalid, Please Check Header Definition\n")));
return FALSE;
#endif
RETAILMSG(ZONE_CHECK(ZONE_FLIPBLT),(TEXT("[2DHW] FlipBlt Exit\r\n")));
/// TODO: Resource Register clearing can be needed.
return TRUE;
}
// if ucTransMode is '1', Transparent Mode
// else '0', Opaque Mode
void FIMGSE2D::SetTransparentMode(bool bIsTransparent, COLOR uBsColor)
{
DWORD uRopRegVal;
CheckFifo(2);
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;
}
// if ucTransMode is '1', Transparent Mode
// else '0', Opaque Mode
void FIMGSE2D::SetColorKeyOn(DWORD uBsColor)
{
CheckFifo(2);
m_pG2DReg->ROP = m_pG2DReg->ROP | G2D_TRANSPARENT_BIT;
// register Blue Screen Color
m_pG2DReg->BS_COLOR = uBsColor;
}
void FIMGSE2D::SetColorKeyOff(void)
{
CheckFifo(2);
// 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::SetFgColor(DWORD uFgColor)
{
CheckFifo(1);
uFgColor &= 0x00ffffff; //< Remove Alpha value
m_pG2DReg->FG_COLOR = uFgColor;
}
void FIMGSE2D::SetBgColor(DWORD uBgColor)
{
CheckFifo(1);
uBgColor &= 0x00ffffff; //< Remove Alpha value
m_pG2DReg->BG_COLOR = uBgColor;
}
void FIMGSE2D::SetBsColor(DWORD uBsColor)
{
CheckFifo(1);
uBsColor &= 0x00ffffff; //< Remove Alpha value
m_pG2DReg->BS_COLOR = uBsColor;
}
/**
* @fn void FIMGSE2D::FillRect(PRECT prtDst, DWORD uColor)
* @param prtDst Destination Rectangle
* @param uColor Filled Color
* @attention prtDst must have positive value.
* @brief prclDst must be rotated when screen is rotated.
*/
void FIMGSE2D::FillRect(PRECTL prclDst, COLOR uColor)
{
RETAILMSG(0,(TEXT("C:0x%x, prclDst:%d,%d,%d,%d\n"),
uColor, prclDst->left, prclDst->top, prclDst->right, prclDst->bottom
));
SetFgColor(uColor);
Set3rdOperand(G2D_OPERAND3_FG);
SetRopEtype(ROP_PAT_ONLY);
BitBlt(prclDst, prclDst, ROT_0); // Fill Rect doesn't care about screen rotation,
}
/*
* @fn void FIMGSE2D::SetSrcSurface(PSURFACE_DESCRIPTOR desc_surface)
* @brief Set Source Surface Information to FIMG2D HW Register
* @param desc_surface Surface Information : Base Address, Horizontal&Vertical Resolution, Color mode
*/
void FIMGSE2D::SetSrcSurface(PSURFACE_DESCRIPTOR desc_surface)
{
CheckFifo(4);
RETAILMSG(0,(TEXT("SRCaddr: 0x%x, Source Surface Base: 0x%x, Color:%d, Hori:%d, Vert:%d\r\n"),
&(m_pG2DReg->SRC_BASE_ADDR),
desc_surface->dwBaseaddr, desc_surface->dwColorMode, desc_surface->dwHoriRes, desc_surface->dwVertRes));
m_pG2DReg->SRC_BASE_ADDR = desc_surface->dwBaseaddr;
m_pG2DReg->SRC_COLOR_MODE = m_iColorModeMapper[desc_surface->dwColorMode];
m_pG2DReg->SRC_HORI_RES = desc_surface->dwHoriRes;
m_pG2DReg->SRC_VERT_RES = desc_surface->dwVertRes;
}
/*
* @fn void FIMGSE2D::SetDstSurface(PSURFACE_DESCRIPTOR desc_surface)
* @brief Set Destination Surface Information to FIMG2D HW Register
* @param desc_surface Surface Information : Base Address, Horizontal&Vertical Resolution, Color mode
*/
void FIMGSE2D::SetDstSurface(PSURFACE_DESCRIPTOR desc_surface)
{
CheckFifo(4);
RETAILMSG(0,(TEXT("DSTaddr: 0x%x, Destination Surface Base: 0x%x, Color:%d, Hori:%d, Vert:%d\r\n"),
&(m_pG2DReg->DST_BASE_ADDR),
desc_surface->dwBaseaddr, desc_surface->dwColorMode, desc_surface->dwHoriRes, desc_surface->dwVertRes));
m_pG2DReg->DST_BASE_ADDR = desc_surface->dwBaseaddr;
m_pG2DReg->DST_COLOR_MODE = m_iColorModeMapper[desc_surface->dwColorMode];
m_pG2DReg->SC_HORI_RES = desc_surface->dwHoriRes;
m_pG2DReg->SC_VERT_RES = desc_surface->dwVertRes;
}
/*
* @fn void FIMGSE2D::TranslateCoordinateToZero(PSURFACE_DESCRIPTOR pdesc_surface, LPRECT prclDst)
* @brief Adjust Coordinate from (x1,y1)~(x2,y2) to (0,0)~(x2-x1,y2-y1)
* Recalculate BaseAddress
* @param desc_surface Surface Information : Base Address, Horizontal&Vertical Resolution, Color mode
* prclDst Surface Target Region coordinate
* prclCLip Surface Clipping region coordinate
*/
void FIMGSE2D::TranslateCoordinateToZero(PSURFACE_DESCRIPTOR pdesc_surface, PRECTL prclDst, PRECTL prclClip)
{
RECTL rtNew;
RECTL rtNewClip;
/// NewAddress = OriginalAddress + (Y1 * Hori.Res + X1) * BPP
/// NewRect : NewRect.Left & top = (0,0), Right & bottom = (X2-X1, Y2-Y1)
switch(pdesc_surface->dwColorMode)
{
case gpe16Bpp:
/// 2Bytes per pixel
pdesc_surface->dwBaseaddr = pdesc_surface->dwBaseaddr + (prclDst->top * pdesc_surface->dwHoriRes + prclDst->left) * 2;
break;
case gpe24Bpp:
/// 3Bytes per pixel
pdesc_surface->dwBaseaddr = pdesc_surface->dwBaseaddr + (prclDst->top * pdesc_surface->dwHoriRes + prclDst->left) * 3;
break;
case gpe32Bpp:
/// 4Bytes per pixel
pdesc_surface->dwBaseaddr = pdesc_surface->dwBaseaddr + (prclDst->top * pdesc_surface->dwHoriRes + prclDst->left) * 4;
break;
default:
RETAILMSG(TRUE,(TEXT("[TCTZ] Unsupported Color Format\r\n")));
break;
}
rtNew.left = 0;
rtNew.top = 0;
rtNew.right = prclDst->right - prclDst->left;
rtNew.bottom = prclDst->bottom - prclDst->top;
if(prclClip)
{
rtNewClip.left = 0;
rtNewClip.top = 0;
rtNewClip.right = prclClip->right - prclDst->left;
rtNewClip.bottom = prclClip->bottom - prclDst->top;
CopyRect((LPRECT)prclClip, (LPRECT) &rtNewClip);
}
CopyRect((LPRECT)prclDst, (LPRECT)&rtNew);
pdesc_surface->dwVertRes -= prclDst->bottom - prclDst->top;
}
/**
* Initialize 2D HW
*/
void FIMGSE2D::Init()
{
CheckFifo(4);
#if HW_PROBE // For check HW consume time, insert GPIO LED triggering code.
// GPIO Virtual alloc
if(g_pGPIORegs == NULL)
{
g_pGPIORegs = (volatile S3C6410_GPIO_REG *)DrvLib_MapIoSpace(S3C6410_BASE_REG_PA_GPIO, sizeof(S3C6410_GPIO_REG), FALSE);
}
if (g_pGPIORegs == NULL)
{
RETAILMSG(0,(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
/// Font Operation Related
m_bIsBitBlt = true;
m_bIsScr2Scr = false;
DisableEffect(); // Disable per-pixel/per-plane alpha blending and fading
SetColorKeyOff();
m_pG2DReg->ALPHA = (FADING_OFFSET_DISABLE | ALPHA_VALUE_DISABLE);
m_pG2DReg->ROP = (G2D_OPERAND3_FG_BIT | G2D_NO_ALPHA_BIT | OPAQUE_ENABLE | G2D_ROP_SRC_ONLY);
SetRotationOrg(0, 0);
m_pG2DReg->ROT_MODE = ROT_0;
m_pG2DReg->ALPHA = 0;
}
void FIMGSE2D::PutPixel(DWORD uPosX, DWORD uPosY, DWORD uColor) //modification
{
CheckFifo(4);
m_pG2DReg->COORD0_X = uPosX;
m_pG2DReg->COORD0_Y = uPosY;
m_pG2DReg->FG_COLOR = uColor;
#if (G2D_CMDPROCESSING==G2D_FASTRETURN)
WaitForEmptyFifo(); //< This is check fully empty command fifo.
m_pG2DReg->CMDR0 = G2D_REND_POINT_BIT;
#elif (G2D_CMDPROCESSING==G2D_INTERRUPT)
CheckFifo(1);
IntEnable();
m_pG2DReg->CMDR0 = G2D_REND_POINT_BIT;
WaitForSingleObject(m_hInterrupt2D, INFINITE);
IntDisable();
IntPendingClear();
InterruptDone(m_dwSysIntr2D);
#elif (G2D_CMDPROCESSING==G2D_BUSYWAITING)
CheckFifo(1);
IntEnable();
while(!WaitForFinish()); // Polling Style
m_pG2DReg->CMDR0 = G2D_REND_POINT_BIT;
IntDisable();
#else
RETAILMSG(TRUE,(TEXT("CMDPROCESSING TYPE is invalid, Please Check Header Definition\n")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -