fimgse2d.cpp
来自「6410BSP3」· C++ 代码 · 共 1,270 行 · 第 1/4 页
CPP
1,270 行
**/
BOOL FIMGSE2D::FlipBlt(PRECTL prclSrc, PRECTL prclDst, ROT_TYPE m_iRotate)
{
DWORD uCmdRegVal=0;
BOOL bRetVal = FALSE;
RECTL rectDst; //< If rotation case this value must be corrected.
RETAILMSG(DISP_ZONE_ENTER,(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;
bRetVal = DoCmd(&(m_pG2DReg->CMDR1), uCmdRegVal, G2D_INTERRUPT);
RETAILMSG(DISP_ZONE_ENTER,(TEXT("[2DHW] FlipBlt Exit\r\n")));
/// TODO: Resource Register clearing can be needed.
return bRetVal;
}
// if ucTransMode is '1', Transparent Mode
// else '0', Opaque Mode
void FIMGSE2D::SetTransparentMode(bool bIsTransparent, COLOR uBsColor)
{
DWORD uRopRegVal;
RequestEmptyFifo(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)
{
RequestEmptyFifo(2);
m_pG2DReg->ROP = m_pG2DReg->ROP | G2D_TRANSPARENT_BIT;
// register Blue Screen Color
m_pG2DReg->BS_COLOR = uBsColor;
}
void FIMGSE2D::SetColorKeyOff(void)
{
RequestEmptyFifo(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)
{
RequestEmptyFifo(1);
uFgColor &= 0x00ffffff; //< Remove Alpha value
m_pG2DReg->FG_COLOR = uFgColor;
}
void FIMGSE2D::SetBgColor(DWORD uBgColor)
{
RequestEmptyFifo(1);
uBgColor &= 0x00ffffff; //< Remove Alpha value
m_pG2DReg->BG_COLOR = uBgColor;
}
void FIMGSE2D::SetBsColor(DWORD uBsColor)
{
RequestEmptyFifo(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)
{
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)
{
RequestEmptyFifo(4);
m_pG2DReg->SRC_BASE_ADDR = desc_surface->dwBaseaddr;
m_pG2DReg->SRC_COLOR_MODE = 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)
{
RequestEmptyFifo(4);
m_pG2DReg->DST_BASE_ADDR = desc_surface->dwBaseaddr;
m_pG2DReg->DST_COLOR_MODE = 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 G2D_COLOR_RGB_565:
case G2D_COLOR_RGBA_5551:
case G2D_COLOR_ARGB_1555:
/// 2Bytes per pixel
pdesc_surface->dwBaseaddr = pdesc_surface->dwBaseaddr + (prclDst->top * pdesc_surface->dwHoriRes + prclDst->left) * 2;
break;
case G2D_COLOR_RGBA_8888:
case G2D_COLOR_ARGB_8888:
case G2D_COLOR_XRGB_8888:
case G2D_COLOR_RGBX_8888:
/// 4Bytes per pixel
pdesc_surface->dwBaseaddr = pdesc_surface->dwBaseaddr + (prclDst->top * pdesc_surface->dwHoriRes + prclDst->left) * 4;
break;
default:
RETAILMSG(DISP_ZONE_ERROR,(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()
{
RequestEmptyFifo(4);
/// 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_MODE | 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
{
SetRotationMode(ROT_0);
RequestEmptyFifo(4);
m_pG2DReg->COORD0_X = uPosX;
m_pG2DReg->COORD0_Y = uPosY;
m_pG2DReg->FG_COLOR = uColor;
DoCmd(&(m_pG2DReg->CMDR0), G2D_REND_POINT_BIT, G2D_FASTRETURN);
}
/**
* Draw Line
* (usPosX1, usPosY1) ~ (usPosX2, usPosY2)
* Do not draw last point
* 0 < usPosX, usPosY1, usPosX2, usPosY2 < 2040
* X-INCR is calculated by (End_X - Start_X)/ ABS(End_Y - Start Y), when Y-axis is the major axis(Y length>X length)
* Y-INCR is calculated by (End_Y - Start_Y)/ ABS(End_X - Start X), When X-axis is the major axis
*/
#define INCR_INTEGER_PART_LENGTH (11)
#define INCR_FRACTION_PART_LENGTH (11)
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;
SetRotationMode(ROT_0);
RequestEmptyFifo(7);
RETAILMSG(DISP_ZONE_LINE,(TEXT("(%d,%d)~(%d,%d):Color:0x%x, LasT:%d\n"),
usPosX1, usPosY1, usPosX2, usPosY2, uColor, bIsDrawLastPoint));
m_pG2DReg->COORD0_X = usPosX1;
m_pG2DReg->COORD0_Y = usPosY1;
m_pG2DReg->COORD2_X = usPosX2;
m_pG2DReg->COORD2_Y = usPosY2;
/// Vertical Length
uVSz = ABS((WORD)usPosY1 - (WORD)usPosY2);
/// Horizontal Length
uHSz = ABS((WORD)usPosX1 - (WORD)usPosX2);
nMajorCoordX = (uHSz>=uVSz);
if(nMajorCoordX)
{
// X length is longer than Y length
// YINCR = (EY-SY)/ABS(EX-SX)
for (i=0; i<INCR_FRACTION_PART_LENGTH+1; 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
}
RETAILMSG(DISP_ZONE_LINE, (TEXT("YINCR: %x "), nIncr ));
}
else
{
// Y length is longer than Y length
// XINCR = (EX-SX)/ABS(EY-SY)
for (i=0; i<INCR_FRACTION_PART_LENGTH+1; i++)
{
uHSz <<= 1;
nIncr <<= 1;
if (uHSz >= uVSz)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?