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

📄 line.cpp

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 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:	s3c6410_line.cpp

Abstract:		draws accelerated lines

Functions:


Notes:			not all lines are accelerated.

--*/

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

#define SIMPLE_LINEACCEL

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

	DEBUGMSG(GPE_ZONE_LINE, (TEXT("++S3C6410DISP::WrappedEmulatedLine\r\n")));
	// 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_oG2D->WaitForIdle();	//< Wait for Fully Empty Command Fifo for all BitBlt request
	}
#endif

#if G2D_ACCELERATE
	if(	(m_VideoPowerState != VideoPowerOff) &&	// to avoid hanging while bring up display H/W
		(!m_iRotate) &&
			((S3C6410Surf *)(pLineParms->pDst))->InVideoMemory() &&
		 	(pLineParms->mix == 0x0d0d) &&
		 	(pLineParms->style == 0) 
#ifdef SIMPLE_LINEACCEL
			&& (pLineParms->dN == 0) &&
			(pLineParms->dM == pLineParms->cPels*16) 
#endif
	 	)
	{
#ifdef DO_DISPPERF
		DispPerfType(DISPPERF_ACCEL_HARDWARE);
#endif
	//	m_oG2D->WaitForIdle();	//< Wait for Fully Empty Command Fifo for all HW Line Drawing Request	
		RETAILMSG(FALSE, (TEXT("ALine:(%d,%d) + m(%d), n(%d), cPels(%d), dir(%d)\n"), pLineParms->xStart, pLineParms->yStart, pLineParms->dM, pLineParms->dN, pLineParms->cPels, pLineParms->iDir));
		retval = AcceleratedSolidLine(pLineParms);
	}
	else
	{
		RETAILMSG(FALSE, (TEXT("ELine:(%d,%d) + m(%d), n(%d), cPels(%d), dir(%d)\n"), pLineParms->xStart, pLineParms->yStart, pLineParms->dM, pLineParms->dN, pLineParms->cPels, pLineParms->iDir));	
		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();
	}

	DEBUGMSG(GPE_ZONE_LINE, (TEXT("--S3C6410DISP::WrappedEmulatedLine\r\n")));

	return retval;
}

/**
*	@fn	SCODE S3C6410DISP::AcceleratedSolidLine(GPELineParms *pLineParms)
*	@brief Draw Solid line with 1 width.
*	@param	pLineParms	Line Drawing Information Structure
*	@	
*/

SCODE S3C6410Disp::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 G2D_PROFILE
	RopProfiler *ropProfiler;
	ropProfiler = RopProfiler::Instance();	
#endif	

#if (CPU_NAME==S3C6410)
	/**
	*	Prepare DestinationSurface Information
	*
	*/
	SURFACE_DESCRIPTOR descDstSurface;

	descDstSurface.dwBaseaddr = (m_VideoMemoryPhysicalBase + (( S3C6410Surf *)(pLineParms->pDst))->OffsetInVideoMemory());
	descDstSurface.dwColorMode = pLineParms->pDst->Format();
	descDstSurface.dwHoriRes = pLineParms->pDst->Width();
	descDstSurface.dwVertRes = pLineParms->pDst->Height();	
	
	m_oG2D->SetDstSurface(&descDstSurface);
	m_oG2D->SetClipWindow(pLineParms->prclClip);
	m_oG2D->SetTransparentMode(0, 0x00000000L);	
#elif (CPU_NAME==S3C6400)
	m_oG2D->SetTransparentMode(0, G2D_BLACK);

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

	if(pLineParms->cPels == 1)
	{
		RETAILMSG(1,(_T("PI\r\n")));	
		EnterCriticalSection(&m_cs2D);	
		m_oG2D->PutPixel(xStart, yStart, pLineParms->solidColor);
		LeaveCriticalSection(&m_cs2D);		
		RETAILMSG(1,(_T("PO\r\n")));
	}
	else
	{
#ifdef SIMPLE_LINEACCEL
		int xEnd = 1;
		int yEnd = 1;	

		// 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 ;
				xEnd = xStart + pLineParms->cPels;
				break;
			case	1:				// +1/2x + y
				yEnd = yStart + pLineParms->cPels;
				xEnd = xStart;
				break;
			case	2:				// -1/2x + y
				yEnd = yStart + pLineParms->cPels;
				xEnd = xStart;
				break;
			case	3:				// -x + 1/2y
				yEnd = yStart;
				xEnd = xStart - pLineParms->cPels;
				break;			
			case	4:				// -x - 1/2y
				yEnd = yStart;
				xEnd = xStart - pLineParms->cPels;
				break;
			case	5:				// -1/2x - y
				yEnd = yStart - pLineParms->cPels;
				xEnd = xStart;
				break;
			case	6:				// +1/2x - y
				yEnd = yStart - pLineParms->cPels;
				xEnd = xStart;
				break;
			case	7:				// +x -1/2y
				yEnd = yStart;
				xEnd = xStart + pLineParms->cPels;
				break;
		}	


		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
		EnterCriticalSection(&m_cs2D);
		m_oG2D->PutLine(xStart, yStart, xEnd, yEnd, pLineParms->solidColor, IsLastDraw);
		LeaveCriticalSection(&m_cs2D);		
#else
		int nMajorLength = pLineParms->dM / 16;
		int nMinorLength = pLineParms->dN / 16;
		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);
		}

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


		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(0,(_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(0,(_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(0,(_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(0,(_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(0,(_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(0,(_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(0,(_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
S3C6410Disp::Line(GPELineParms *pLineParms, EGPEPhase phase)
{
	DEBUGMSG (GPE_ZONE_INIT, (TEXT("++S3C6410Disp::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 *))&S3C6410Disp::WrappedEmulatedLine;
		}
	}
	else if (phase == gpeComplete)
	{
#ifdef DO_DISPPERF
		DispPerfEnd(0);
#endif

	}
	DEBUGMSG(GPE_ZONE_INIT, (TEXT("--S3C6410DISP::Line\r\n")));

	return S_OK;
}

⌨️ 快捷键说明

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