⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fimgse2d.cpp

📁 SMDK2416_BSP
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		uXYIncr = CalculateXYIncrFormat(usSrcWidth - 1, usDstHeight - 1);	
		SetYIncr(uXYIncr);
	}
	else
	{
		if(usSrcWidth == usDstWidth && usSrcHeight == usDstHeight)
		{
			RETAILMSG(TRUE, (TEXT("This is not stretch or shrink BLT, redirect to BitBlt, R:%d\n"), m_iRotate));
			BitBlt(prclSrc, prclDst, m_iRotate);
			return;
		}
	
		uXYIncr = CalculateXYIncrFormat(usSrcWidth - 1, usDstWidth - 1);	
		SetXIncr(uXYIncr);
	}
	
	printf("\nXIncr : %d.%x", (uXYIncr&0x003ff800)>>11, (uXYIncr & 0x000007ff));

	if((m_iRotate == ROT_90) ||(m_iRotate == ROT_270) )
	{
		uXYIncr = CalculateXYIncrFormat(usSrcHeight - 1, usDstWidth - 1);
		SetXIncr(uXYIncr);
	}
	else
	{
		uXYIncr = CalculateXYIncrFormat(usSrcHeight - 1, usDstHeight - 1);
		SetYIncr(uXYIncr);
	}
	printf("\nYIncr : %d.%x", (uXYIncr&0x003ff800)>>11, (uXYIncr & 0x000007ff));	
	
	SetCoordinateSrcBlock(prclSrc->left, prclSrc->top, prclSrc->right - 1, prclSrc->bottom - 1);	

	if(m_iRotate == ROT_180)		//< origin set to (x2,y2)
	{
		rectDst.left = prclDst->right - 1;						//< x2
		rectDst.top = prclDst->bottom - 1;						//< y2
		rectDst.right = 2 * (prclDst->right - 1) - prclDst->left ;		//< x2 + (x2 - x1)
		rectDst.bottom = 2 * (prclDst->bottom -1) - prclDst->top;	//< y2 + (y2 - y1)
	}
	else	 if(m_iRotate == ROT_90)		//<In this time, Height and Width are swapped.	
	{
		rectDst.left = prclDst->right - 1;						//< x2
		rectDst.right = prclDst->right - 1 + prclDst->bottom - 1 - prclDst->top;	//< x2 + (y2 - y1)
		rectDst.top = prclDst->top;										//< y1
		rectDst.bottom = prclDst->top + prclDst->right - 1 - prclDst->left;		//< y1 + (x2 - x1)
	}
	else	 if(m_iRotate == ROT_270)		//<In this time, Height and Width are swapped.	
	{
		rectDst.left = prclDst->left;							//< x1
		rectDst.right = prclDst->left + prclDst->bottom - 1- prclDst->top;		//< x1 + (y2 - y1)
		rectDst.top = prclDst->bottom - 1;									//< y2
		rectDst.bottom = prclDst->bottom - 1 + prclDst->right - 1- prclDst->left;	//< y2 + (x2 - x1)
	}	
	else		//< ROT_0
	{
		rectDst.left = prclDst->left;
		rectDst.top = prclDst->top;		
		rectDst.right = prclDst->right - 1;
		rectDst.bottom = prclDst->bottom - 1;
	}
	
	/// Set Destination's Rotation mode
	SetRotationMode(m_iRotate);		
	SetRotationOrg((WORD)rectDst.left, (WORD)rectDst.top);	
	SetCoordinateDstBlock(rectDst.left, rectDst.top, rectDst.right, rectDst.bottom);			

//	if(m_iRotate!=ROT_0)
//	{
		RETAILMSG(ZONE_CHECK(ZONE_STRETCHBLT),(TEXT("ROT:%d, Src:(%d,%d)~(%d,%d), Dst:(%d,%d)~(%d,%d), OC:(%d,%d)\r\n"), 
			m_iRotate, prclSrc->left, prclSrc->top, prclSrc->right, prclSrc->bottom, 
			rectDst.left, rectDst.top, rectDst.right, rectDst.bottom, rectDst.left, rectDst.top));
//	}

	uCmdRegVal = G2D_STRETCH_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_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);	//< exclude Destination Right, Bottom line

	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.
	//Reset();

	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;
}


/**
*	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 S3C2450_IOPORT_REG *)VirtualAlloc(0, sizeof(S3C2450_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
	}
	if (g_pGPIORegs == NULL)
	{
		RETAILMSG(1,(TEXT("[GPIO] g_pGPIORegs: VirtualAlloc failed!\r\n")));
		g_pGPIORegs = NULL;
	}
	else
	if (!VirtualCopy((PVOID)g_pGPIORegs, (PVOID)(S3C2450_BASE_REG_PA_IOPORT>>8), sizeof(S3C2450_IOPORT_REG), PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL ))
	{
		RETAILMSG(1, (TEXT("[GPIO] g_pGPIORegs: VirtualCopy failed!\r\n")));
		VirtualFree((PVOID)g_pGPIORegs, 0, MEM_RELEASE);
	}
//	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();	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -