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

📄 halsurf.cpp

📁 s3c2443的display driver.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// -----------------------------------------------------------------------------
//
//  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.
//
// -----------------------------------------------------------------------------

#include "precomp.h"

#define HAL_ZONE_ERROR 0
#define HAL_ZONE_INFO 0
#define HAL_ZONE_WARNING 0

#define GDI_SCREEN_WIDTH	(g_pGPE->ScreenWidth())
#define GDI_SCREEN_HEIGHT	(g_pGPE->ScreenHeight())

#define DDRAW_SCREEN_WIDTH	( (g_pDDrawPrimarySurface != NULL) \
								? (g_pDDrawPrimarySurface->Width()) \
								: GDI_SCREEN_WIDTH )
#define DDRAW_SCREEN_HEIGHT	( (g_pDDrawPrimarySurface != NULL) \
								? (g_pDDrawPrimarySurface->Height()) \
								: GDI_SCREEN_HEIGHT )

bool UpdateHALInit(
	LPDDRAWI_DIRECTDRAW_GBL lpDD,           // driver struct
	DWORD modeidx )
{
    DDHALINFO   ddhalinfo;

	DEBUGENTER(UpdateHALInit);

	memset(&ddhalinfo, 0, sizeof(ddhalinfo));
	ddhalinfo.dwSize = sizeof(ddhalinfo);

	buildDDHALInfo(&ddhalinfo, modeidx);

	lpDD->vmiData = ddhalinfo.vmiData;
	lpDD->dwMonitorFrequency = ddhalinfo.dwMonitorFrequency;
	lpDD->ddCaps = ddhalinfo.ddCaps;
	
	DEBUGLEAVE(UpdateHALInit);
	return TRUE;
}


BOOL HalGDIHasSplitFromDDraw(void)
{
	BOOL	bDifferentPrimaries = FALSE;

	DEBUGENTER(HalGDIHasSplitFromDDraw);
	
	bDifferentPrimaries = g_pGPE->PrimarySurface() != g_pDDrawPrimarySurface;

	DEBUGLEAVE(HalGDIHasSplitFromDDraw);

	return bDifferentPrimaries;
}


DWORD WINAPI HalFlipToGDISurface( LPDDHAL_FLIPTOGDISURFACEDATA pd )
{
    DEBUGENTER( HalFlipToGDISurface );
    /*
    typedef struct _DDHAL_FLIPTOGDISURFACEDATA
    {
        LPDDRAWI_DIRECTDRAW_GBL    lpDD;             // driver struct
        DWORD                      dwToGDI;          // TRUE if flipping to the GDI surface, FALSE if flipping away
        DWORD                      dwReserved;       // reserved for future use
        HRESULT                    ddRVal;           // return value
        LPDDHAL_FLIPTOGDISURFACE   FlipToGDISurface; // PRIVATE: ptr to callback
    } DDHAL_FLIPTOGDISURFACEDATA;
    */

    // Implementation
    pd->ddRVal = DD_OK;

    return DDHAL_DRIVER_HANDLED;
}

SCODE HalGetPixelFormatFromSurfaceDesc(
					LPDDSURFACEDESC			lpDDSurfaceDesc,
					EDDGPEPixelFormat*		pPixelFormat,
					EGPEFormat*				pFormat
					)
{
	SCODE ddRVal = S_OK;

	DEBUGENTER(HalGetPixelFormatFromSurfaceDesc);

	if ((lpDDSurfaceDesc == NULL) || (pPixelFormat == NULL) || (pFormat == NULL))
	{
		DEBUGMSG(HAL_ZONE_ERROR, (TEXT("DDGPEGetPixelFormatFromSurfaceDesc ERROR - Invalid Parameters\r\n") ));
		return DDERR_INVALIDPARAMS;
	}

	if ( (lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) )
	{
		ddRVal = g_pGPE->DetectPixelFormat(
						lpDDSurfaceDesc->ddsCaps.dwCaps,
						&lpDDSurfaceDesc->ddpfPixelFormat,
						pFormat,
						pPixelFormat
						);

		DEBUGMSG(HAL_ZONE_INFO, (TEXT("got pixelFormat %d\r\n"), *pPixelFormat));

		if( FAILED(ddRVal) )
		{
			DEBUGMSG(HAL_ZONE_WARNING,(TEXT("DDGPEGetPixelFormatFromSurfaceDesc returned DDERR_UNSUPPORTEDFORMAT\r\n")));
			ddRVal = DDERR_UNSUPPORTEDFORMAT;
		}
	}
	else
	{
		// just use primary surface info
		
		if (g_pDDrawPrimarySurface != NULL)
		{
			*pPixelFormat	= g_pDDrawPrimarySurface->PixelFormat();
			*pFormat		= g_pDDrawPrimarySurface->Format();
		}
		else
		{
			// it should never come in here, but this code works...

			SCODE		sc;
			GPEMode		modeInfo;
			DDGPESurf*	pDDGPESurf = NULL;

			sc = g_pGPE->GetModeInfo(&modeInfo, g_pGPE->GetPhysicalModeId());
			if (FAILED(sc))
			{
				ddRVal = DDERR_UNSUPPORTEDFORMAT;
			}
			else
			{
				*pFormat = modeInfo.format;

				GPEModeEx	modeInfoEx; // restrict the scope of this, since we can't rely on it being valid for all drivers
				sc = g_pGPE->GetModeInfoEx(&modeInfoEx, g_pGPE->GetPhysicalModeId());
				if (FAILED(sc))
				{
					// function probably wasn't supported by the driver
					*pPixelFormat = EGPEFormatToEDDGPEPixelFormat[modeInfo.format];
					ddRVal = S_OK;
				}
				else
				{
					*pPixelFormat = modeInfoEx.ePixelFormat;
				}
			}
		}

	}

	DEBUGLEAVE(HalGetPixelFormatFromSurfaceDesc);
	return ddRVal;
}


DWORD WINAPI HalCreateSurface( LPDDHAL_CREATESURFACEDATA pd )
{
    /*
    typedef struct _DDHAL_CREATESURFACEDATA
    {
        LPDDRAWI_DIRECTDRAW_GBL     lpDD;           // driver struct
        LPDDSURFACEDESC             lpDDSurfaceDesc;// description of surface being created
        LPDDRAWI_DDRAWSURFACE_LCL   FAR *lplpSList; // list of created surface objects
        DWORD                       dwSCnt;         // number of surfaces in SList
        HRESULT                     ddRVal;         // return value
        LPDDHAL_CREATESURFACE       CreateSurface;  // PRIVATE: ptr to callback
    } DDHAL_CREATESURFACEDATA;
    */

    // Implementation
	SCODE				sc = S_OK;
	unsigned int		iSurf;		// Surface index
	//unsigned int		nBPP;		// Bits-per-pixel on surface
	unsigned int		nWidth;		// Width of surface in pixels
	//unsigned int		nPitch;		// Width of surface in bytes
	unsigned int		nHeight;	// Height of surface in pixels
	LPDDRAWI_DDRAWSURFACE_LCL
						pSurf;		// Pointer to surface data
	EDDGPEPixelFormat	pixelFormat;
	EGPEFormat			format;		// Pixel format of surface(s) being created
	DWORD 				dwFlags = pd->lpDDSurfaceDesc->dwFlags;
	DWORD 				dwCaps = pd->lpDDSurfaceDesc->ddsCaps.dwCaps;

	DEBUGENTER( HalCreateSurface );

	//DebugBreak();

	/*
	typedef struct _DDHAL_CREATESURFACEDATA
	{
	    LPDDRAWI_DIRECTDRAW_GBL     lpDD;           // driver struct
	    LPDDSURFACEDESC             lpDDSurfaceDesc;// description of surface being created
	    LPDDRAWI_DDRAWSURFACE_LCL   FAR *lplpSList; // list of created surface objects
	    DWORD                       dwSCnt;         // number of surfaces in SList
	    HRESULT                     ddRVal;         // return value
	    LPDDHAL_CREATESURFACE       CreateSurface;  // PRIVATE: ptr to callback
	} DDHAL_CREATESURFACEDATA;
	*/


	sc = HalGetPixelFormatFromSurfaceDesc(
				pd->lpDDSurfaceDesc,
				&pixelFormat,
				&format
				);

	if (FAILED(sc))
	{
		RETAILMSG(1,(TEXT("DDGPECreateSurface ERROR - DDERR_UNSUPPORTEDFORMAT (0x%08x)\r\n"),
											sc ));
		pd->ddRVal = DDERR_UNSUPPORTEDFORMAT;
		DEBUGLEAVE(HalCreateSurface);
		return DDHAL_DRIVER_HANDLED;
	}

	// Use pd->lpDDSurfaceDesc->dwFlags to determine which fields are valid and use them
/*	nBPP = (pd->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) ?
		((USHORT)(pd->lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount)) :
		g_pDDrawPrimarySurface->Bpp();*/
/*#ifdef FB16BPP
		16;		// REVIEW!
#else
		8;	// REVIEW!
#endif*/


	nWidth = (pd->lpDDSurfaceDesc->dwFlags & DDSD_WIDTH) ?
		( pd->lpDDSurfaceDesc->dwWidth ) : DDRAW_SCREEN_WIDTH;		// resolves to a call to
																	//  g_pDDrawPrimarySurface or a GPE query

	nHeight = (pd->lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) ?
		( pd->lpDDSurfaceDesc->dwHeight ) : DDRAW_SCREEN_HEIGHT;	// resolves to a call to
																	//  g_pDDrawPrimarySurface or a GPE query
	RETAILMSG(1,(TEXT("nWidth=%d  nHeight=%d\n"),nWidth,nHeight));
	//RETAILMSG(GPE_ZONE_CREATE,(TEXT("nBPP: %d\r\n"), nBPP ));

	/*switch(nBPP)
	{
	case 8:
		format = gpe8Bpp;
		break;
	case 16:
		format = gpe16Bpp;
		break;
	case 24:
//		if( pd->lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS )
//			format = pfmt_24a;
//		else
//			format = pfmt_24;
//		nBPP = 32;
//		break;
		RETAILMSG(GPE_ZONE_WARNING,(TEXT("HalCreateSurface rejecting %d BPP surface\r\n"), nBPP));
		pd->ddRVal = DDERR_UNSUPPORTEDFORMAT;
		return DDHAL_DRIVER_HANDLED;
	case 32:
		format = gpe32Bpp;
		break;
	}*/

	//nPitch = ( nWidth * nBPP ) >>3;
	//nPitch = ( nPitch + 3 ) & ~3;


#if DEBUG
	RETAILMSG(1,(TEXT("Number of surfaces to create: %d\r\n"), pd->dwSCnt ));
	RETAILMSG(1,(TEXT("Create Surface flags: ")));
//	DumpDDSCAPS(pd->lpDDSurfaceDesc->ddsCaps);
#endif

	for( iSurf=0; iSurf<pd->dwSCnt; iSurf++ )
	{
		pSurf = pd->lplpSList[iSurf];

//#if DEBUG
#if 0
		RETAILMSG(1,(TEXT("Surface #%d: LCL:%08x FLAGS:"), iSurf, pSurf ));
		DumpDDSCAPS( pSurf->ddsCaps );
		if( dwCaps & DDSCAPS_MIPMAP )
		{
			RETAILMSG(1,(TEXT("MipMap count: %d\r\n"), pSurf->lpSurfMore->dwMipMapCount ));
		}
		RETAILMSG(1,(TEXT("\r\nAddr of GBL: 0x%08x, Addr of LCL: 0x%08x\r\n"),
			pSurf->lpGbl, pSurf ));
#endif

        if ( pSurf->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE )
        {
			RETAILMSG(1, (TEXT("dwCaps4 = 0x%x\r\n"), pSurf->lpSurfMore->ddsCapsEx.dwCaps4));
			if ( (pSurf->lpSurfMore->ddsCapsEx.dwCaps4 & DDSCAPS4_NONGDIPRIMARY) )
			{
				DWORD	dwModeID = -1L;

				RETAILMSG(1, (TEXT("SPLITTING THE DDRAW SURFACE\r\n") ));

				// g_pDrawPrimarySurface is originally set to the GDI primary surface, but this isn't what we want
				// for our model. We want a ddraw primary surface that is separate from the GDI primary surface.
				// (and that could have a different pixel depth, stride, format, etc.)

				RETAILMSG(1, (TEXT("still have pixelFormat %d\r\n"), pixelFormat));

				if ( (pd->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) )
				{
					RETAILMSG(1, (TEXT("Using pixel format to find split mode\r\n") ));
					sc = g_pGPE->DetectMode(&dwModeID, nWidth, nHeight, format, pixelFormat, &pd->lpDDSurfaceDesc->ddpfPixelFormat);
				}
				else
				{
					RETAILMSG(1, (TEXT("NOT using pixel format to find split mode\r\n") ));
					sc = g_pGPE->DetectMode(&dwModeID, nWidth, nHeight, format, pixelFormat);
				}

				GPEMode		modeInfo;
				DDGPESurf*	pDDGPESurf = NULL;

				if (FAILED(sc))
				{

					RETAILMSG(1, (TEXT("Could not find requested primary surface mode 0x%08x\r\n"), sc));

					// try to just split off a surface of the same type as the current primary surface (GDI surface)
					sc = S_OK;
					dwModeID = g_pGPE->GetModeId(); // can only split off GDI surface
				}
				else
				{
					RETAILMSG(1, (TEXT("Found requested primary surface mode: ID = %d\r\n"), dwModeID));
				}

⌨️ 快捷键说明

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