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

📄 blit.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
				case 90:
				{
					dwRotationAngle  = 270;
					break;
				}
				case 270:
				{
					dwRotationAngle  = 90;
					break;
				}
			}

			/* Try Hardware 2D blit */
			if(!Hardware2DBlit(psSourceSurface,
							   (RECT*)sNewRects,
							   psDestSurface,
							   &sDest,
							   D3DMTEXF_NONE,
							   0,
							   NULL,
							   0,
							   dwRotationAngle))
			{

				/* Try 3D hardware blit */
				if(!Hardware3DBlit(psSourceSurface,
								   (RECT*)sNewRects,
								   psDestSurface,
								   &sDest,
								   D3DMTEXF_NONE,
								   0,
								   NULL,
								   0,
								   dwRotationAngle))
				{
					/* Can't do it with 3d - punt to software */
					if(!SoftwareBlit(psSourceSurface,
									 (RECT*)sNewRects,
									 psDestSurface,
									 &sDest,
									 D3DMTEXF_NONE,
									 0,
									 NULL,
									 0,
									 dwRotationAngle))
					{
						psSourceSurface->psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;
						D3DM_DPF((DPF_ERROR, "CopyRectangle:Unsupported Blit. Failing"));
						return;
					}
				}
			}

			return;
		}
		else
		{
			/* Dest is rotated */
			RotateRects(psContext, 
						&sNewRects[1], 
						(LPD3DMRECT)&sDest, 
						1, 
						psDestSurface->dwWidth,
						psDestSurface->dwHeight);

			/* Try 3D hardware blit */
			if(!Hardware3DBlit(psSourceSurface,
							   &pcrd->SourceRect,
							   psDestSurface,
							   (RECT*)&sNewRects[1],
							   D3DMTEXF_NONE,
							   0,
							   NULL,
							   0,
							   psContext->dwRotationAngle))
			{
				/* Can't do it with 3d - punt to software */
				if(!SoftwareBlit(psSourceSurface,
								 &pcrd->SourceRect,
								 psDestSurface,
								 (RECT*)&sNewRects[1],
								 D3DMTEXF_NONE,
								 0,
								 NULL,
								 0,
								 psContext->dwRotationAngle))
				{
					psSourceSurface->psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;
					D3DM_DPF((DPF_ERROR, "CopyRectangle:Unsupported Blit. Failing"));
					return;
				}
			}

			return;
		}
	}
	else
	{
		psSourceRect = &pcrd->SourceRect;
		psDestRect   = &sDest;
	}


	/* Try Twiddling */
	if(!Twiddle(psSourceSurface,
				psDestSurface,
				psSourceRect,
				psDestRect))
	{
		/* Try 2D hardware blit */
		if(!Hardware2DBlit(psSourceSurface,
						   psSourceRect,
						   psDestSurface,
						   psDestRect,
						   D3DMTEXF_NONE,
						   0,
						   NULL,
						   0,
						   0))
		{
			/* Try 3D hardware blit */
			if(!Hardware3DBlit(psSourceSurface,
							   psSourceRect,
							   psDestSurface,
							   psDestRect,
							   D3DMTEXF_NONE,
							   0,
							   NULL,
							   0,
							   0))
			{
				/* Hardware can't do it so try a software blit */
				if(!SoftwareBlit(psSourceSurface,
								 psSourceRect,
								 psDestSurface,
								 psDestRect,
								 D3DMTEXF_NONE,
								 0,
								 NULL,
								 0,
								 0))
				{
					psSourceSurface->psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;
					D3DM_DPF((DPF_ERROR, "CopyRectangle:Unsupported Blit. Failing"));
					return;
				}
			}
		}
	}
}
/*----------------------------------------------------------------------------
<function>
	FUNCTION:   StretchRect

	PURPOSE:    Stretches a rectangle from one surface to another

	PARAMETERS:	In:  psrd - stretch rect data
				
	RETURNS:	
</function>
------------------------------------------------------------------------------*/
VOID StretchRect(LPD3DM_STRETCHRECT psrd)
{
	LPD3DM_SURFACE psSourceSurface;
	LPD3DM_SURFACE psDestSurface;
	LPD3DM_CONTEXT psContext;
	D3DMRECT	   sNewRects[2];
	RECT		   *psSourceRect, *psDestRect;

	psSourceSurface = (LPD3DM_SURFACE) psrd->SourceId;
	psDestSurface	= (LPD3DM_SURFACE) psrd->DestId;
	psContext		= psSourceSurface->psContext;

	/* Flush any outstanding gemoetry */
	FlushGeometryOnSurface(psDestSurface);

	/* Scale rects as required */
	ScaleRectAndClamp(&psrd->SourceRect, psSourceSurface);
	ScaleRectAndClamp(&psrd->DestRect, psDestSurface);

	/* Check rotation status */
	if(psContext->dwRotationAngle != 0						  &&
	  (psSourceSurface->eSurfaceType == D3DMRTYPE_BACKBUFFER  ||
	   psSourceSurface->eSurfaceType == D3DMRTYPE_FRONTBUFFER ||
	   psDestSurface->eSurfaceType   == D3DMRTYPE_BACKBUFFER  ||
	   psDestSurface->eSurfaceType   == D3DMRTYPE_FRONTBUFFER))
    {
		if((psSourceSurface->eSurfaceType == D3DMRTYPE_BACKBUFFER  ||
		    psSourceSurface->eSurfaceType == D3DMRTYPE_FRONTBUFFER) &&
		   (psDestSurface->eSurfaceType   == D3DMRTYPE_BACKBUFFER  ||
			psDestSurface->eSurfaceType   == D3DMRTYPE_FRONTBUFFER))
		{
			/* Source and dest buffers are rotated so just rotate the rects and the blit will work */
			RotateRects(psContext, 
						sNewRects, 
						(LPD3DMRECT)&psrd->SourceRect, 
						1, 
						psSourceSurface->dwWidth,
						psSourceSurface->dwHeight);

			RotateRects(psContext, 
						&sNewRects[1], 
						(LPD3DMRECT)&psrd->DestRect, 
						1, 
						psDestSurface->dwWidth,
						psDestSurface->dwHeight);

			psSourceRect = (RECT*)sNewRects;
			psDestRect   = (RECT*)&sNewRects[1];
		}
		else if(psSourceSurface->eSurfaceType == D3DMRTYPE_BACKBUFFER  ||
		        psSourceSurface->eSurfaceType == D3DMRTYPE_FRONTBUFFER)
		{
			DWORD dwRotationAngle;

			/* Source is rotated */
			RotateRects(psContext, 
						sNewRects, 
						(LPD3DMRECT)&psrd->SourceRect, 
						1, 
						psSourceSurface->dwWidth,
						psSourceSurface->dwHeight);

			switch(psContext->dwRotationAngle)
			{
				case 180:
				{
					dwRotationAngle  = 180;
					break;
				}
				case 90:
				{
					dwRotationAngle  = 270;
					break;
				}
				case 270:
				{
					dwRotationAngle  = 90;
					break;
				}
			}

			/* Try 3D hardware blit */
			if(!Hardware3DBlit(psSourceSurface,
							   (RECT*)sNewRects,
							   psDestSurface,
							   &psrd->DestRect,
							   psrd->Filter,
							   0,
							   NULL,
							   0,
							   dwRotationAngle))
			{
				/* Can't do it with 3d - punt to software */
				if(!SoftwareBlit(psSourceSurface,
								 (RECT*)sNewRects,
								 psDestSurface,
								 &psrd->DestRect,
								 psrd->Filter,
								 0,
								 NULL,
								 0,
								 dwRotationAngle))
				{
					psSourceSurface->psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;
					D3DM_DPF((DPF_ERROR, "CopyRectangle:Unsupported Blit. Failing"));
					return;
				}
			}


			return;
		}
		else
		{
			/* Dest is rotated */
			RotateRects(psContext, 
						&sNewRects[1], 
						(LPD3DMRECT)&psrd->DestRect, 
						1, 
						psDestSurface->dwWidth,
						psDestSurface->dwHeight);

			/* Try 3D hardware blit */
			if(!Hardware3DBlit(psSourceSurface,
							   &psrd->SourceRect,
							   psDestSurface,
							   (RECT*)&sNewRects[1],
							   psrd->Filter,
							   0,
							   NULL,
							   0,
							   psContext->dwRotationAngle))
			{
				/* Can't do it with 3d - punt to software */
				if(!SoftwareBlit(psSourceSurface,
								 &psrd->SourceRect,
								 psDestSurface,
								 (RECT*)&sNewRects[1],
								 psrd->Filter,
								 0,
								 NULL,
								 0,
								 psContext->dwRotationAngle))
				{
					psSourceSurface->psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;
					D3DM_DPF((DPF_ERROR, "CopyRectangle:Unsupported Blit. Failing"));
					return;
				}
			}

			return;
		}
	}
	else
	{
		psSourceRect = &psrd->SourceRect;
		psDestRect   = &psrd->DestRect;
	}

	/* Try Hardware 3D blit */
	if(!Hardware3DBlit(psSourceSurface,
					   psSourceRect,
					   psDestSurface,
					   psDestRect,
					   psrd->Filter,
					   0,
					   NULL,
					   0,
					   0))
	{
		/* Try Hardware 2D blit */
		if(!Hardware2DBlit(psSourceSurface,
						   psSourceRect,
						   psDestSurface,
						   psDestRect,
						   psrd->Filter,
						   0,
						   NULL,
						   0,
						   0))
		{
			/* Hardware can't do it so try a software blit */
			if(!SoftwareBlit(psSourceSurface,
							 psSourceRect,
							 psDestSurface,
							 psDestRect,
							 psrd->Filter,
							 0,
							 NULL,
							 0,
							 0))
			{
				psSourceSurface->psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;
				D3DM_DPF((DPF_ERROR, "StretchRect:Unsupported Blit. Failing"));
				return;
			}
		}
	}
}
/*----------------------------------------------------------------------------
<function>
	FUNCTION:   ColourFill

	PURPOSE:    Performs a colourfill blit to the given surface

	PARAMETERS:	In:  pcf - Colour fill command data
						
	RETURNS:	
</function>
------------------------------------------------------------------------------*/
VOID ColourFill(LPD3DM_COLORFILL pcfd)
{
	LPD3DM_SURFACE psDestSurface;
	LPD3DM_CONTEXT psContext;
	D3DMRECT	   sNewRect;
	RECT		   *psDestRect;
	
	psDestSurface	= (LPD3DM_SURFACE) pcfd->SurfaceId;
	psContext		= psDestSurface->psContext;

	/* Flush any outstanding geometry */
	FlushGeometryOnSurface(psDestSurface);

	/* Scale rects as required */
	ScaleRectAndClamp(&pcfd->Rect, psDestSurface);

	if(psContext->dwRotationAngle != 0						  &&
	   psDestSurface->eSurfaceType   == D3DMRTYPE_BACKBUFFER  ||
	   psDestSurface->eSurfaceType   == D3DMRTYPE_FRONTBUFFER)
	{
		RotateRects(psContext, 
					&sNewRect, 
					(LPD3DMRECT)&pcfd->Rect, 
					1, 
					psDestSurface->dwWidth,
					psDestSurface->dwHeight);

		psDestRect   = (RECT*)&sNewRect;
	}
	else
	{
		psDestRect = &pcfd->Rect;
	}

	/* Try the blit with 2D HW*/
	if(!Hardware2DBlit(NULL,
					   NULL,
					   psDestSurface,
					   psDestRect,
					   D3DMTEXF_NONE,
					   pcfd->Color,
					   NULL,
					   0,
					   0))
	{
		/* Hardware can't do it so try a software blit */
		if(!SoftwareBlit(NULL,
						 NULL,
						 psDestSurface,
						 psDestRect,
						 D3DMTEXF_NONE,
						 pcfd->Color,
						 NULL,
						 0,
						 0))
		{
			psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;
			D3DM_DPF((DPF_ERROR, "ColourFill:Unsupported Blit. Failing"));
			return;
		}
	}
}
/*****************************************************************************
 End of file (Blit.c)
*****************************************************************************/

⌨️ 快捷键说明

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