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

📄 hwverify.cpp

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			}
		}
		
		/* Inc HwVer failure */
		m_ulHwVerifyFailureCo++;

	}

	return (TRUE);
}


/***********************************************************************************
 Function Name	: PrintSurfaceDetails
 Inputs			: 
 Outputs		: 
 Returns		: 
 Globals Used	: 
 Description	: 
************************************************************************************/
void CHWVerify::PrintSurfaceDetails(PTCHAR ptszSurfName, GPESurf *psSurface, PRECT psRect, BOOL bGenBmp, EGPEFormat eDstFmt, PULONG pulPalette)
{
	TCHAR	tszBuf[128];
	LONG lRotationAngle=0;

	if (psSurface == NULL)
	{
		MessageAndPDumpComment(("BitBlt : No %ls surface", ptszSurfName));
		return;
	}

	if (psSurface->InVideoMemory())
	{
		MessageAndPDumpComment(("BitBlt : %ls surface in Video Memory", ptszSurfName));

		// It's one of ours, so we can assume MBXSurf class.
		lRotationAngle = ((MBXSurf*)(psSurface))->m_lRotationAngle;
	}
	else
	{
		MessageAndPDumpComment(("BitBlt : %ls surface in System Memory", ptszSurfName));
	}
	
	RECT sSaveRect = *psRect;
	ULONG	ulWidth  = psSurface->Width();
	ULONG	ulHeight = psSurface->Height();//Logical
	ULONG	ulStride = psSurface->Stride();
	ULONG	ulBpp    = EGPEFormatToBpp[psSurface->Format()];
	PVOID	pvPtr    = psSurface->Buffer();

	if (ulWidth == 0 || ulHeight == 0)
	{
		ulWidth = RectWidth(psRect);
		ulHeight = RectHeight(psRect);
	}

	MessageAndPDumpComment(("BitBlt : %ls surface (%ld, %ld) in size %ld BPP with stride of 0x%lx @ 0x%lx", ptszSurfName, ulWidth, ulHeight, ulBpp, ulStride, pvPtr));
	MessageAndPDumpComment(("BitBlt : %ls surface rect is (%ld, %ld) to (%ld, %ld)", ptszSurfName, psRect->left, psRect->top, psRect->right, psRect->bottom));
	
	if (lRotationAngle)
	{
		if (lRotationAngle == 270 || lRotationAngle == 90)
		{
			// In memory the physical width is the rotated logical height for 90 and 270 degrees.
			ulWidth = psSurface->Height();
			ulHeight = psSurface->Width();
		}

		// Warning, this overwrites the blt params, so we must restore at the end.
		RotateRegion (psRect, ulHeight, ulWidth);
	}
	
	if (bGenBmp == TRUE)
	{
		RGBQUAD *pPal;
		
		if (pulPalette)
		{
			pPal = m_psPalInfo->prgbqSrcPalette;
		}
		else if (ulBpp == 4)
		{
			pPal = (RGBQUAD *)&gAlphaPalette;
		}
		else if (ulBpp == 1)
		{
			pPal = (RGBQUAD *)&gMaskPalette;
		}
		else
		{
			pPal = NULL;
		}

		MessageAndPDumpComment (("BitBlt : Generating %ls.bmp", ptszSurfName));
		wcscpy(tszBuf, m_tszHWVerPath);
		wcscat(tszBuf, L"\\");
		wcscat(tszBuf, ptszSurfName);
		wcscat(tszBuf, L".bmp");
		CreateBmp (tszBuf, pvPtr, ulWidth, ulHeight, ulStride, ulBpp, eDstFmt, pPal);
	}

	*psRect = sSaveRect;

}


/**************************************************************************
 * Function Name  : CompareSurfaces
 * Inputs         : pbySrc - ptr to source surface
 *				  : ulSrcDx - X size of source surface
 *				  : ulSrcDy - Y size of source surface
 *				  : ulSrcStride - Stride of source surface
 *                : pbyDst - ptr to destination surface
 *				  : ulDstStride - Stride of destination surface
 *				  : ulBPP - Bits per pixel 
 * Outputs        : None
 * Returns        : NULL on success, else ptr to first diff
 * Description    : Copy src suface to dst surface
**************************************************************************/
static PVOID CompareSurfaces(PBYTE pbySrc, ULONG ulSrcDx, ULONG ulSrcDy, ULONG ulSrcStride, PBYTE pbyDst, ULONG ulDstStride, ULONG ulBPP)
{
	PBYTE	pbyCurDst=pbyDst;
	PBYTE	pbyCurSrc=pbySrc;
	ULONG	ulScanLines;
	ULONG	ulLineLength=(ulSrcDx * ulBPP) / 8;
	PVOID	pvFail;

	/* Assumes surface to copy is at 0,0 in source surface */
	if (ulLineLength == ulDstStride && ulDstStride == ulSrcStride)
	{
		if ((pvFail=(PVOID)memcmp(pbyCurSrc, pbyCurDst, ulLineLength * ulSrcDy)) != NULL)
		{
			return FindMemCmpFail(pbyCurSrc, pbyCurDst, ulLineLength * ulSrcDy);
		}
	}
	else
	{
		for (ulScanLines = 0; ulScanLines < ulSrcDy; ulScanLines++)
		{
			if ((pvFail=(PVOID)memcmp(pbyCurSrc, pbyCurDst, ulLineLength)) != NULL)
			{
				return FindMemCmpFail(pbyCurSrc, pbyCurDst, ulLineLength);
			}
			pbyCurDst += ulDstStride;
			pbyCurSrc += ulSrcStride;
		}
	}

	return (NULL);
}


/**************************************************************************
 * Function Name  : Compare32BppSurfacesWithoutAlpha
 * Inputs         : pbySrc - ptr to source surface
 *				  : ulSrcDx - X size of source surface
 *				  : ulSrcDy - Y size of source surface
 *				  : ulSrcStride - Stride of source surface
 *                : pbyDst - ptr to destination surface
 *				  : ulDstStride - Stride of destination surface
 *				  : ulBPP - Bits per pixel 
 * Outputs        : None
 * Returns        : NULL on success, else ptr to first diff
 * Description    : Copy src suface to dst surface
**************************************************************************/
static PVOID Compare32BppSurfacesWithoutAlpha(PBYTE pbySrc, ULONG ulSrcDx, ULONG ulSrcDy, ULONG ulSrcStride, PBYTE pbyDst, ULONG ulDstStride, ULONG ulBPP)
{
	PBYTE	pbyCurDst = pbyDst;
	PBYTE	pbyCurSrc = pbySrc;
	ULONG	ulScanLines;
	ULONG	ulLineLength=(ulSrcDx * ulBPP) / 8;
//	PVOID	pvFail;

	for (ulScanLines = 0; ulScanLines < ulSrcDy; ulScanLines++)
	{
		PDWORD pdwSrc = (PDWORD)pbyCurSrc;
		PDWORD pdwDst = (PDWORD)pbyCurDst;
		ULONG ulPixels = ulSrcDx;

		while (ulPixels--)
		{
			if (((*pdwSrc - *pdwDst) & 0x00FFFFFF) != 0)
			{
				return (PVOID)(pdwSrc);
			}

			pdwSrc++;
			pdwDst++;
		}


		pbyCurDst += ulDstStride;
		pbyCurSrc += ulSrcStride;
	}

	return (NULL);
}


/***********************************************************************************
 Function Name	: FindMemCmpFail
 Inputs			: 
 Outputs		: 
 Returns		: 
 Globals Used	: 
 Description	: 
************************************************************************************/
static PVOID FindMemCmpFail(PVOID pv1, PVOID pv2, ULONG ulSize)
{
	PBYTE	pby1=(PBYTE)pv1;
	PBYTE	pby2=(PBYTE)pv2;
	ULONG	ulIdx;
	
	for (ulIdx=0; ulIdx < ulSize; ulIdx++)
	{
		if (*pby1 != *pby2)
		{
			return (PVOID)(pby1);
		}
		pby1++;
		pby2++;
	}
	return (NULL);
}


/***********************************************************************************
 Function Name	: FindIntersection
 Inputs			: 
 Outputs		: 
 Returns		: 
 Globals Used	: 
 Description	: 
************************************************************************************/
static BOOL FindIntersection(PRECT psRect1, PRECT psRect2, PRECT psIntersect)
{
	if (psRect1->top > psRect2->top)
	{
		psIntersect->top=psRect1->top;
	}
	else
	{
		psIntersect->top=psRect2->top;
	}
	if (psRect1->bottom > psRect2->bottom)
	{
		psIntersect->bottom=psRect2->bottom;
	}
	else
	{
		psIntersect->bottom=psRect1->bottom;
	}
	if (psRect1->left > psRect2->left)
	{
		psIntersect->left=psRect1->left;
	}
	else
	{
		psIntersect->left=psRect2->left;
	}
	if (psRect1->right > psRect2->right)
	{
		psIntersect->right=psRect2->right;
	}
	else
	{
		psIntersect->right=psRect1->right;
	}

	if (psIntersect->top > psIntersect->bottom || psIntersect->left > psIntersect->right)
	{
		return (FALSE);
	}

	return (TRUE);
}


/***********************************************************************************
 Function Name	: MessageAnsi
 Inputs			: 
 Outputs		: 
 Returns		: 
 Globals Used	: 
 Description	: 
************************************************************************************/
static void MessageAnsi(PSTR pszFormat, ...)
{
	TCHAR	ptszScript[128];
	TCHAR	ptszFormat[128];
	va_list params;

	va_start(params, pszFormat);
	wsprintf(ptszFormat, TEXT("%hs"), pszFormat);
	wvsprintf(ptszScript, ptszFormat, params);
	va_end(params);

	DPFINFO((ptszScript));
}


/***********************************************************************************
 Function Name	: CreateBmp
 Inputs			: 
 Outputs		: 
 Returns		: 
 Globals Used	: 
 Description	: 
************************************************************************************/
static BOOL CreateBmp(LPCTSTR pwszFileName,
					  PVOID pvData,
					  ULONG ulX,
					  ULONG ulY,
					  ULONG ulStride,
					  ULONG ulBpp,
					  EGPEFormat eDstFmt,
					  RGBQUAD *prgbqPalette)
{
	HANDLE		hFile;
	BMP_HEADER	sBmpHeader;
	ULONG		ulBytesWritten;
	ULONG		ulXIdx;
	LONG		lYIdx;	
	RGBTRIPLE *	psLineStore;
	ULONG		ulNumEntries = 0;
	ULONG		ulPaletteSize = 0;
	ULONG		ulImageSize = 0;
	ULONG		ulLineSize = abs(ulStride);
	
	/* First alloc enough room for one line */
	if ((psLineStore = (RGBTRIPLE *)AllocSharedMem((ulX * sizeof(RGBTRIPLE) + sizeof(ULONG)))) == NULL)
	{
		DPFERROR((L"CreateBmp : Alloc line store"));
		return (FALSE);
	}

	/* Open file */
	hFile = CreateFile(pwszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 0);
	if (hFile == INVALID_HANDLE_VALUE)
	{
		DPFERROR((L"CreateBmp : Failed to create file %s", pwszFileName));
		FreeSharedMem(psLineStore);
		return FALSE;
	}

	/* Write BMP header */	
	if (sizeof(BMP_HEADER) != 54)
	{
		sBmpHeader.bmfHeader.bfType = sizeof(BMP_HEADER);
		DebugBreak();
	}

	if (ulBpp <= 8)
	{
		ulNumEntries = 1<<ulBpp;
		ulPaletteSize = ulNumEntries * sizeof(RGBQUAD);
		ulImageSize = ulLineSize * ulY;
	}
	else
	{
		ulImageSize = (ulX * ulY * sizeof(RGBTRIPLE));
	}	

	/* File Header */
	sBmpHeader.bmfHeader.bfType      = 0x4D42;		/* "BM" */
	sBmpHeader.bmfHeader.bfSize      = sizeof(BMP_HEADER) + ulImageSize + ulPaletteSize;
	sBmpHeader.bmfHeader.bfReserved1 = 0;
	sBmpHeader.bmfHeader.bfReserved2 = 0;
	sBmpHeader.bmfHeader.bfOffBits   = sizeof(BMP_HEADER) + ulPaletteSize;

	/* Info Header */
	sBmpHeader.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
	sBmpHeader.bmiHeader.biWidth         = ulX; 
	sBmpHeader.bmiHeader.biHeight        = ulY; 
	sBmpHeader.bmiHeader.biPlanes        = 1; 
	sBmpHeader.bmiHeader.biBitCount      = (BYTE)((ulBpp <= 8) ? ulBpp : 24);
	sBmpHeader.bmiHeader.biCompression   = BI_RGB;
	sBmpHeader.bmiHeader.biSizeImage     = ulImageSize; 
	sBmpHeader.bmiHeader.biXPelsPerMeter = 0; 
	sBmpHeader.bmiHeader.biYPelsPerMeter = 0; 
	sBmpHeader.bmiHeader.biClrUsed       = 0; 
	sBmpHeader.bmiHeader.biClrImportant  = 0;
	
	if (ulBpp == 2)
	{
		/* dump as 4Bpp as there is not bmp format for 2Bpp */
		ULONG ulNewImgSize = ulImageSize * 2;
		ULONG ulNewPalSize = 16 * sizeof(RGBQUAD);

		sBmpHeader.bmfHeader.bfSize      = sizeof(BMP_HEADER) + ulNewImgSize + ulNewPalSize;
		sBmpHeader.bmfHeader.bfOffBits   = sizeof(BMP_HEADER) + ulNewPalSize;
		sBmpHeader.bmiHeader.biBitCount  = 4;
		sBmpHeader.bmiHeader.biSizeImage = ulNewImgSize; 
	}

	if (WriteFile(hFile, &sBmpHeader, sizeof(BMP_HEADER), &ulBytesWritten, NULL) == FALSE)
	{
		DPFERROR((L"CreateBmp : Failed to write BMP header"));
		FreeSharedMem(psLineStore);
		CloseHandle(hFile);
		return (FALSE);
	}

	if (ulNumEntries)
	{
		ASSERT (prgbqPalette != NULL);

		if (WriteFile(hFile, prgbqPalette, ulPaletteSize, &ulBytesWritten, NULL) == FALSE)
		{
			DPFERROR((L"CreateBmp : Failed to write palette"));
			FreeSharedMem(psLineStore);
			CloseHandle(hFile);
			return (FALSE);
		}

		/* move to last line in bitmap */
		PBYTE pbyData = (PBYTE)pvData + ((ulY - 1) * ulStride);

		ULONG ulNewLineSize = ((((ulX + 1) >> 1) + 3) & 0xFFFFFFFC);

		/* special case 2Bpp as there is no bmp format available */
		if (ulBpp == 2)
		{
			int nCnt;
			ULONG ulBlack = 0;

			/* pad out palette entries to 16 */
			for (nCnt = 0; nCnt < 12; nCnt++)
			{
				if (WriteFile(hFile, &ulBlack, sizeof(RGBQUAD), &ulBytesWritten, NULL) == FALSE)
				{
					DPFERROR((L"CreateBmp : Failed to write palette"));
					FreeSharedMem(psLineStore);
					CloseHandle(hFile);
					return (FALSE);
				}
			}

			while (ulY--)
			{
				PBYTE pbyPtr = pbyData;
				WORD *pwWritePix = (WORD *)psLineStore;

				for (nCnt = 0; nCnt < (int)ulNewLineSize; nCnt += 2)
				{
					BYTE byTemp = *pbyPtr++;

					/* 0xE4 -> 0x2301 - appears to be right */
					*pwWritePix++ = ((byTemp & 0x03) << 8) |
									((byTemp & 0x0C) << 10) |
									((byTemp & 0x30) >> 4) |
									((byTemp & 0xC0) >> 2);
			  	}

				if (WriteFile(hFile, psLineStore, ulNewLineSize, &ulBytesWritten, NULL) == FALSE)
				{
					DPFERROR((L"CreateBmp : Failed to write bitmap bits"));
					FreeSharedMem(psLineStore);
					CloseHandle(hFile);
					return (FALSE);
				}

				pbyData -= ulStride;
			}
		}
		else
		{
			/* write bimap bits unprocessed */
			while (ulY--)
			{
				memset (psLineStore, 0, ulNewLineSize);
				memcpy (psLineStore, pbyData, ulLineSize);

				if (WriteFile(hFile, psLineStore, ulNewLineSize, &ulBytesWritten, NULL) == FALSE)
				{
					DPFERROR((L"CreateBmp : Failed to write bitmap bits"));
					FreeSharedMem(psLineStore);
					CloseHandle(hFile);
					return (FALSE);
				}

				pbyData -= ulStride;

⌨️ 快捷键说明

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