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

📄 line.cpp

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 CPP
字号:
/*
 * $Workfile: LINE.CPP $
 * $Revision: 6 $
 * $Date: 4/07/00 8:51a $
 * $Modtime: 4/07/00 8:36a $
 * $Author: Sarma $
 *
 * Copyright (c) 1998 National Semiconductor Corporation.
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of National 
 * Semiconductor Corporation. ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into
 * with National Semiconductor Corporation.
 * This code is supplied as is.
 *
 */

/*
 *$Log: /CE/Platform/Nsc/Drivers/Video/gxvideo/base/LINE.CPP $
 * 
 * 6     4/07/00 8:51a Sarma
 * Removed Cyrix Corporation from the legal/confidentail information.
 * 
 * 5     4/06/00 4:09p Sarma
 * Removed personal messages.
 * 
 * 4     3/29/00 9:10a Sarma
 * Added durango interface for rendering.
 * 
 * 3     12/02/98 1:48p Sarma
 * combined statements as 32 bit writes instead of 16 bit.
 * 
 * 2     11/12/98 3:30p Sarma
 * Added Confidential copyright to files with VSS keywords for
 * log/history.
 *$History: LINE.CPP $
 * 
 * *****************  Version 6  *****************
 * User: Sarma        Date: 4/07/00    Time: 8:51a
 * Updated in $/CE/Platform/Nsc/Drivers/Video/gxvideo/base
 * Removed Cyrix Corporation from the legal/confidentail information.
 * 
 * *****************  Version 5  *****************
 * User: Sarma        Date: 4/06/00    Time: 4:09p
 * Updated in $/CE/Platform/Nsc/Drivers/Video/gxvideo/base
 * Removed personal messages.
 * 
 * *****************  Version 4  *****************
 * User: Sarma        Date: 3/29/00    Time: 9:10a
 * Updated in $/CE/Platform/Nsc/Drivers/Video/gxvideo/base
 * Added durango interface for rendering.
 * 
 * *****************  Version 3  *****************
 * User: Sarma        Date: 12/02/98   Time: 1:48p
 * Updated in $/wince/v2.1/gxvideo
 * combined statements as 32 bit writes instead of 16 bit.
 * 
 * *****************  Version 2  *****************
 * User: Sarma        Date: 11/12/98   Time: 3:30p
 * Updated in $/wince/v2.1/gxvideo
 * Added Confidential copyright to files with VSS keywords for
 * log/history.
*/

#include "precomp.h"

#ifdef DURANGO
#include "gfx_rtns.h"
#endif


//////////////////////////////////////////////////////////////////////////////////////

SCODE GxVideo::Line(
	GPELineParms *pLineParms,
	EGPEPhase phase )
{
	DEBUGMSG(GPE_ZONE_LINE,(TEXT("GxVideo::Line\r\n")));

	pLineParms->pLine = EmulatedLine;

#ifdef ENABLE_ACCELERATION

	// WHAT IS PHASE? SINGLE PIXEL?

	if( phase == gpeSingle || phase == gpePrepare )
	{
		// CHECK IF DESTINATION IS VIDEO MEMORY AND NOT DOTTED

		if(pLineParms->pDst->InVideoMemory())
		{
			SelectSolidColor(pLineParms->solidColor);
			pLineParms->pLine = (SCODE (GPE::*)(struct GPELineParms *))AcceleratedSolidLine;
		}
	}

#endif // ENABLE_ACCELERATION

	return S_OK;
}

unsigned short vector_mode_table[] =
{
	VM_MAJOR_INC | VM_MINOR_INC | VM_X_MAJOR,
	VM_MAJOR_INC | VM_MINOR_INC | VM_Y_MAJOR,
	VM_MAJOR_INC | VM_Y_MAJOR,
	VM_MINOR_INC | VM_X_MAJOR,
	VM_X_MAJOR,
	VM_Y_MAJOR,
	VM_MINOR_INC | VM_Y_MAJOR,
	VM_MAJOR_INC | VM_X_MAJOR,
};

unsigned short init_error_adjust[] =
{
	-1, -1, -1, -1, 0, 0, 0, 0
};

SCODE GxVideo::AcceleratedSolidLine(GPELineParms *pLineParms)
{
	GxVideoSurf *gxsurf = (GxVideoSurf *)(pLineParms->pDst);
	int left = gxsurf->Left();
	int top = gxsurf->Top();
	int x1 = pLineParms->xStart + left;
	int y1 = pLineParms->yStart + top;
	// Clip Rectangle is also w.r.t to the destination 
	int ClipRectLeft = pLineParms->prclClip->left + left;
	int ClipRectTop = pLineParms->prclClip->top + top;
	int ClipRectRight = pLineParms->prclClip->right + left;
	int ClipRectBottom = pLineParms->prclClip->bottom + top;
	unsigned short blit_mode, raster_mode, vector_mode;

	// DETERMINE VECTOR MODE

	vector_mode = vector_mode_table[pLineParms->iDir & 7];

	// CHECK IF PATCOPY

	if (pLineParms->mix == 0x0D0D)
	{
		blit_mode = 0;
		raster_mode = 0x00F0;
	}

	// CHECK IF XOR

	else if (pLineParms->mix == 0x0707)
	{
		blit_mode = BM_READ_DST_FB0;
		raster_mode = 0x005A;
		vector_mode |= VM_READ_DST_FB;
	}

//		if( pLineParms->mix == 0x0B07 )	   .. dotted line

	// OTHERWISE UNSUPPORTED ROP
	// Could support more ROPs by providing a table to translate from
	// the "mix" value to the proper ROP value.  16 ROPs are supported
	// in GX for vectors.

	else
	{
		return EmulatedLine( pLineParms );
	}

	// SPECIAL CASE HORIZONTAL AND VERTICAL LINES

	if (!(pLineParms->dN))															   
	{
		int width, height;

		switch(pLineParms->iDir)
		{
		case 3:
		case 4:
			x1 -= pLineParms->cPels;
		case 0:
		case 7:
			// Since we are plotting horizontal line by BitBlt which doesnot
			// include the last pixel. To force the BitBlt to draw this Increment 
			// width by width+1.
			width = pLineParms->cPels +1;
			height = 1;
			break;
		case 5:
		case 6:
			y1 -= pLineParms->cPels;
		case 1:
		case 2:
			// Since we are plotting Vertical line by BitBlt which doesnot
			// include the last pixel. To force the BitBlt to draw this Increment 
			// height by height+1.
			height = pLineParms->cPels+1;
			width = 1;
			break;

		}

		// ADJUST RECTANGLE BASED IN CLIPPING RECTANGLE

		if (pLineParms->prclClip)
		{
			// CLIP IN THE X DIRECTION

			if ((x1 < ClipRectLeft))
			{
				width -= (ClipRectLeft - x1);
				if (width <= 0) return S_OK;
				x1 = ClipRectLeft;
			}
			if ((x1+width > ClipRectRight))
			{
				width = (ClipRectRight - x1);
				if (width <= 0) return S_OK;
			}

			// CLIP IN THE Y DIRECTION

			if ((y1 < ClipRectTop))
			{
				height -= (ClipRectTop - y1);
				if (height <= 0) return S_OK;
				y1 = ClipRectTop;
			}
			if ((y1+height > ClipRectBottom))
			{
				height = (ClipRectBottom - y1);
				if (height <= 0) return S_OK;
			}
		}

		// DRAW HORIZONTAL OR VERTICAL LINE

#ifdef DURANGO
		RETAILMSG( 0, ( TEXT(" Special Bresenham Line \n") ) );
		unsigned long color = (pLineParms->solidColor);
		gfx_set_solid_pattern(color);
		gfx_set_raster_operation((unsigned char) raster_mode); //pBltParms->rop4);
		gfx_pattern_fill(x1,y1,width,height);
#else
		WAIT_PENDING(GXregisters);
		WRITE_REG32(GXregisters, GP_DST_XCOOR, (y1 << 16) | x1);
		WRITE_REG16(GXregisters, GP_RASTER_MODE, raster_mode);
		WRITE_REG32(GXregisters, GP_WIDTH, (height << 16) | width);
		WRITE_REG16(GXregisters, GP_BLIT_MODE, blit_mode);
#endif
	}
	else
	{
		int axial, init, diag;
		// WARNING!!!
		// This code does not take into account the clipping rectangle.
		// The "Polygons" program still works fine, so it may be that 
		// WindowsCE clips the lines. 

		// DETERMINE BRESENHAM PARAMETERS

		axial = ((int) pLineParms->dN << 1);
		init = axial - (int) pLineParms->dM;
		diag = init - (int) pLineParms->dM;

		// ADJUST INITIAL ERROR
		// Adjust by -1 for certain directions so that the vector 
		// hits the same pixels when drawn in either direction.
		// The Gamma value is assumed to account for the initial 
		// error adjustment for clipped lines.

		init += init_error_adjust[pLineParms->iDir & 7];
		init += (int) pLineParms->llGamma;

		// DRAW THE VECTOR

#ifdef DURANGO
		RETAILMSG( 0, ( TEXT(" Bresenham Line \n") ) );
		unsigned long color = (pLineParms->solidColor);
		gfx_set_solid_pattern(color);
		unsigned short length = ((init << 16) | pLineParms->cPels);	
		gfx_set_raster_operation((unsigned char) raster_mode); //pBltParms->rop4);
		gfx_bresenham_line(x1, y1,length,init,axial,diag,vector_mode);  

#else 			
		WAIT_PENDING(GXregisters);
		WRITE_REG32(GXregisters, GP_DST_XCOOR, (y1 << 16) | x1);
		WRITE_REG16(GXregisters, GP_AXIAL_ERROR, axial);
		WRITE_REG16(GXregisters, GP_DIAG_ERROR, diag);
		WRITE_REG32(GXregisters, GP_VECTOR_LENGTH, (init << 16) | pLineParms->cPels);
		WRITE_REG16(GXregisters, GP_RASTER_MODE, raster_mode);
		WRITE_REG16(GXregisters, GP_VECTOR_MODE, vector_mode);
#endif	
	}
	return S_OK;
}



⌨️ 快捷键说明

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