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

📄 s3c6400_line.cpp

📁 Samsung公司S3C6400芯片的BSP源码包
💻 CPP
字号:
//
// Copyright (c) Samsung Electornics.  All rights reserved.
//
//
// Use of this bsp source code is subject to the terms of the Samsung
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE BSP SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:	s3c6400_line.cpp

Abstract:		draws accelerated lines

Functions:


Notes:			not all lines are accelerated.

--*/

//#include <assert.h>
#include "precomp.h"
#include "dispperf.h"

SCODE
S3C6400Disp::WrappedEmulatedLine(GPELineParms *pLineParms)
{
	SCODE retval;
	RECT  bounds;
	int   N_plus_1;                // Minor length of bounding rect + 1

	// calculate the bounding-rect to determine overlap with cursor
	if (pLineParms->dN)            // The line has a diagonal component (we'll refresh the bounding rect)
	{
		N_plus_1 = 2 + ((pLineParms->cPels * pLineParms->dN) / pLineParms->dM);
	}
	else
	{
		N_plus_1 = 1;
	}

	switch(pLineParms->iDir)
	{
	case 0:
		bounds.left = pLineParms->xStart;
		bounds.top = pLineParms->yStart;
		bounds.right = pLineParms->xStart + pLineParms->cPels + 1;
		bounds.bottom = bounds.top + N_plus_1;
		break;

	case 1:
		bounds.left = pLineParms->xStart;
		bounds.top = pLineParms->yStart;
		bounds.bottom = pLineParms->yStart + pLineParms->cPels + 1;
		bounds.right = bounds.left + N_plus_1;
		break;

	case 2:
		bounds.right = pLineParms->xStart + 1;
		bounds.top = pLineParms->yStart;
		bounds.bottom = pLineParms->yStart + pLineParms->cPels + 1;
		bounds.left = bounds.right - N_plus_1;
		break;

	case 3:
		bounds.right = pLineParms->xStart + 1;
		bounds.top = pLineParms->yStart;
		bounds.left = pLineParms->xStart - pLineParms->cPels;
		bounds.bottom = bounds.top + N_plus_1;
		break;

	case 4:
		bounds.right = pLineParms->xStart + 1;
		bounds.bottom = pLineParms->yStart + 1;
		bounds.left = pLineParms->xStart - pLineParms->cPels;
		bounds.top = bounds.bottom - N_plus_1;
		break;

	case 5:
		bounds.right = pLineParms->xStart + 1;
		bounds.bottom = pLineParms->yStart + 1;
		bounds.top = pLineParms->yStart - pLineParms->cPels;
		bounds.left = bounds.right - N_plus_1;
		break;

	case 6:
		bounds.left = pLineParms->xStart;
		bounds.bottom = pLineParms->yStart + 1;
		bounds.top = pLineParms->yStart - pLineParms->cPels;
		bounds.right = bounds.left + N_plus_1;
		break;

	case 7:
		bounds.left = pLineParms->xStart;
		bounds.bottom = pLineParms->yStart + 1;
		bounds.right = pLineParms->xStart + pLineParms->cPels + 1;
		bounds.top = bounds.bottom - N_plus_1;
		break;

	default:
		DISPDRV_ERR((_T("[DISPDRV:ERR] WrappedEmulatedLine() : Invalid Direction %d\n\r"), pLineParms->iDir));
		return E_INVALIDARG;
	}
	// check for line overlap with cursor and turn off cursor if overlaps
	if (m_CursorVisible && !m_CursorDisabled)
	{
		RotateRectl(&m_CursorRect);
		if (m_CursorRect.top < bounds.bottom && m_CursorRect.bottom > bounds.top &&
			m_CursorRect.left < bounds.right && m_CursorRect.right > bounds.left)
		{
			RotateRectlBack(&m_CursorRect);
			CursorOff();
			m_CursorForcedOff = TRUE;
		}
		else
			RotateRectlBack(&m_CursorRect);
	}

#if G2D_ACCELERATE
	if(	(m_VideoPowerState != VideoPowerOff) &&	// to avoid hanging while bring up display H/W
		(!m_iRotate) &&
			((S3C6400Surf *)(pLineParms->pDst))->InVideoMemory() &&
		 	(pLineParms->mix == 0x0d0d) &&
		 	(pLineParms->style == 0) 
#define SIMPLE_LINEACCEL
#ifdef SIMPLE_LINEACCEL
			&& (pLineParms->dN == 0) &&
			(pLineParms->dM == pLineParms->cPels*16) 
#endif
	 	)
	{
#ifdef DO_DISPPERF
		DispPerfType(DISPPERF_ACCEL_HARDWARE);
#endif
		retval = AcceleratedSolidLine(pLineParms);
	}
	else
	{
#ifdef DO_DISPPERF
		DispPerfType(DISPPERF_ACCEL_EMUL);
#endif
		retval = EmulatedLine (pLineParms);
	}
#else
	// do emulated line
		retval = EmulatedLine (pLineParms);
#endif

	// se if cursor was forced off because of overlap with line bouneds and turn back on
		if (m_CursorForcedOff)
	{
		m_CursorForcedOff = FALSE;
		CursorOn();
	}

	return retval;
}


SCODE
S3C6400Disp::AcceleratedSolidLine(GPELineParms *pLineParms)
{
	SCODE retval;

	retval = S_OK;

	int nMajorLength = pLineParms->dM / 16;
	int nMinorLength = pLineParms->dN / 16;
	int xStart = pLineParms->xStart;
	int yStart = pLineParms->yStart;
	int xEnd = 1;
	int yEnd = 1;	
	int minorlength = 0;						// default 0
	if (pLineParms->dN)            // The line has a diagonal component (we'll refresh the bounding rect)
	{
		minorlength = ((pLineParms->cPels * pLineParms->dN) / pLineParms->dM);
	}

//	printf("G ");
#if G2D_PROFILE
	RopProfiler *ropProfiler;
	ropProfiler = RopProfiler::Instance();	
#endif	

	m_oG2D->SetTransparentMode(0, G2D_BLACK);

	m_oG2D->InitSetting(
	 	m_VideoMemoryPhysicalBase + (( S3C6400Surf *)(pLineParms->pDst))->OffsetInVideoMemory(),
		RGB16,			// Need to change
		m_nScreenWidth,	m_nScreenHeight,
						pLineParms->prclClip->left,
						pLineParms->prclClip->top,
						pLineParms->prclClip->right,
						pLineParms->prclClip->bottom
		);	

	// Line is vertical or horizontal
	// Use fill-blt to draw a line starting at
	// pLineParms->xStart, pLineParms->yStart
	// in the direction specified by pLineParms->iDir
	// for a total of pLineParms->cPels pixels
	//           -y
	//            ^
	//			⒇	5 |	6  ⒅ 
	//				⒇	|	 ⒅
	//			4		⒇|⒅   7
	// -x <-------+-------> +x
	//			3		⒆|①		0
	//				⒆	|	 ①	
	//			⒆	2	|	1	 ①
	//			      +y

	switch (pLineParms->iDir & 0x07)
	{
		// major axis is X-axis, dM = X-axis, dN = Y-axis
		case	0:				// +x +1/2y
			yEnd = yStart + nMinorLength;
			xEnd = xStart + nMajorLength;
			break;
		case	1:				// +1/2x + y
			yEnd = yStart + nMajorLength;
			xEnd = xStart + nMinorLength;
			break;
		case	2:				// -1/2x + y
			yEnd = yStart + nMajorLength;
			xEnd = xStart - nMinorLength;
			break;
		case	3:				// -x + 1/2y
			yEnd = yStart + nMinorLength;
			xEnd = xStart - nMajorLength;
			break;			
		case	4:				// -x - 1/2y
			yEnd = yStart - nMinorLength;
			xEnd = xStart - nMajorLength;
			break;
		case	5:				// -1/2x - y
			yEnd = yStart - nMajorLength;
			xEnd = xStart - nMinorLength;
			break;
		case	6:				// +1/2x - y
			yEnd = yStart - nMajorLength;
			xEnd = xStart + nMinorLength;
			break;
		case	7:				// +x -1/2y
			yEnd = yStart - nMinorLength;
			xEnd = xStart + nMajorLength;
			break;
	}	

#if G2D_PROFILE
			ropProfiler->Log(true, G2D_LINE_PROFCODE);			
#endif	

	if(pLineParms->cPels == 1)
	{
		m_oG2D->PutPixel(xStart, yStart, pLineParms->solidColor);
	}
	else
	{
#ifdef SIMPLE_LINEACCEL
		bool IsLastDraw = false;
		if(xEnd < 0) xEnd = 0;		// Cut negative coordinate
		if(yEnd < 0) yEnd = 0;		// negative coordinate is not supported on H/W IP
		m_oG2D->PutLine(xStart, yStart, xEnd, yEnd, pLineParms->solidColor, IsLastDraw);
#else
		bool IsLastDraw = false;
		int y_intercept = 0;
		int x_intercept = 0;
		int x1 = xStart * 16;		// interpolation
		int x2 = xEnd * 16;
		int y1 = yStart * 16;
		int y2 = yEnd * 16;

		ASSERT(xStart >=0);
		ASSERT(yStart >=0);
		// y=(y2-y1)/(x2-x1)x + b
		// b = (y1x2-x1y2)/(x2-x1)		
		// 1. line is out over y-axis
		// y value when x=0 is y=b=(y1x2-x1y2)/(x2-x1)
		if(x2 < 0)
		{
			if(x2 == x1)	// do not draw. it is clipped.
			{
				return retval; 
			}
			if(y2 == y1)	// Horizontal Line.
			{
				if(yEnd < 0) yEnd = 0;
		RETAILMSG(TRUE,(_T("ACCDRAW1 : LT(%d,%d)~RB(%d,%d)\n "), xStart, yStart, xEnd, yEnd));				
				m_oG2D->PutLine(xStart, yStart, 0, yEnd, pLineParms->solidColor, IsLastDraw);
				return retval;
			}

			y_intercept = ((y1*x2)-(x1*y2))/(x2-x1);

			if(y_intercept < 0 )	// Recalc for x
			{
				x_intercept = ((x1*y2)-(y1*x2))/(y2-y1);
				if(x_intercept < 0)
				{
					RETAILMSG(TRUE,(_T("Line Draw error\n")));
				}
				else	// (xStart, yStart) ~ (x_intercept/16, 0)
				{
		RETAILMSG(TRUE,(_T("ACCDRAW2 : LT(%d,%d)~RB(%d,%d)\n "), xStart, yStart, xEnd, yEnd));									
					m_oG2D->PutLine(xStart, yStart, x_intercept/16, 0, pLineParms->solidColor, IsLastDraw);
					return retval;
				}
			}
			else	// (xStart, yStart) ~ (0, y_intercept/16)
			{
		RETAILMSG(TRUE,(_T("ACCDRAW3 : LT(%d,%d)~RB(%d,%d)\n "), xStart, yStart, xEnd, yEnd));								
					m_oG2D->PutLine(xStart, yStart, 0, y_intercept/16, pLineParms->solidColor, IsLastDraw);
					return retval;
			}
		}
		else if(y2 < 0)
		{
			if(y1 == y2)		// do not draw. it is clipped
			{
				return retval;		
			}
			if(x1 == x2)	// Vertical Line
			{
				if(xEnd < 0) xEnd = 0;
		RETAILMSG(TRUE,(_T("ACCDRAW4 : LT(%d,%d)~RB(%d,%d)\n "), xStart, yStart, xEnd, yEnd));								
				m_oG2D->PutLine(xStart, yStart, xEnd, 0, pLineParms->solidColor, IsLastDraw);
				return retval;			
			}				
			x_intercept = ((x1*y2)-(y1*x2))/(y2-y1);			
			if(x_intercept < 0)	// Recalc for y
			{
				y_intercept = ((y1*x2)-(x1*y2))/(x2-x1);
				if(y_intercept < 0)
				{
					RETAILMSG(TRUE,(_T("Line Draw error\n")));
				}
				else	// (xStart, yStart) ~ (0, y_intercept)
				{
		RETAILMSG(TRUE,(_T("ACCDRAW5 : LT(%d,%d)~RB(%d,%d)\n "), xStart, yStart, xEnd, yEnd));									
					m_oG2D->PutLine(xStart, yStart, 0, y_intercept/16, pLineParms->solidColor, IsLastDraw);
					return retval;
				}
			}
			else	// (xStart, yStart) ~ (x_intercept, 0)
			{
		RETAILMSG(TRUE,(_T("ACCDRAW6 : LT(%d,%d)~RB(%d,%d)\n "), xStart, yStart, xEnd, yEnd));								
					m_oG2D->PutLine(xStart, yStart, x_intercept/16, 0, pLineParms->solidColor, IsLastDraw);				
					return retval;
			}
		}
		else
		{
		RETAILMSG(TRUE,(_T("ACCDRAW7 : LT(%d,%d)~RB(%d,%d)\n "), xStart, yStart, xEnd, yEnd));											
			m_oG2D->PutLine(xStart, yStart, xEnd, yEnd, pLineParms->solidColor, IsLastDraw);
			return retval;
		}
#endif
	}


	return retval;
}

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

	if (phase == gpeSingle || phase == gpePrepare)
	{
#ifdef DO_DISPPERF
		DispPerfStart(ROP_LINE);
#endif
		if ((pLineParms->pDst != m_pPrimarySurface))
		{
			pLineParms->pLine = &GPE::EmulatedLine;
		}
		else
		{
				pLineParms->pLine = (SCODE (GPE::*)(struct GPELineParms *))&S3C6400Disp::WrappedEmulatedLine;
		}
	}
	else if (phase == gpeComplete)
	{
#ifdef DO_DISPPERF
		DispPerfEnd(0);
#endif

	}

	return S_OK;
}

⌨️ 快捷键说明

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