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

📄 ddgpe.cpp

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "precomp.h"
INSTANTIATE_DDGPE

//////////////////////////////////////////////////////////////////////////////////////////////
// DDGPE
//////////////////////////////////////////////////////////////////////////////////////////////

static HINSTANCE hDDStub = NULL;

//#define SURF_TO_PDATA(pSurf) ((BYTE *)(((LPDDRAWI_DDRAWSURFACE_INT)(pSurf))->lpLcl->lpGbl->fpVidMem))



DDGPE::DDGPE() : m_pModeEx(NULL), m_dwPhysicalModeID(0L)
{
    // load ddraw support
    hDDStub = LoadLibrary(TEXT("ddstub.dll"));
    m_pDriverData = NULL;
}



DDGPE::~DDGPE()
{
    if (hDDStub)
    {
        FreeLibrary(hDDStub);
		hDDStub = NULL;
    }
}

SCODE DDGPE::AllocSurface
				(DDGPESurf *		*ppSurf,
				int					width,
				int					height,
				EGPEFormat			format,
				EDDGPEPixelFormat	pixelFormat,
				int					surfaceFlags 
				)
{
	DEBUGMSG(GPE_ZONE_WARNING, (TEXT("AllocSurface(EDDGPEPixelFormat) Not Implemented by DDI\r\n") ));

	return AllocSurface((GPESurf**)ppSurf, width, height, format, surfaceFlags);
}


SCODE DDGPE::AllocSurface
				(DDGPESurf *			*ppSurf,
				DDGPEAllocSurfaceData*	pddgpeAllocSurfaceData
				)
{
	DEBUGMSG(GPE_ZONE_CREATE, (TEXT("AllocSurface(DDGPEAllocSurfaceData) Not Implemented by DDI\r\n") ));

	if (pddgpeAllocSurfaceData == NULL)
	{
		return DDERR_INVALIDPARAMS;
	}

	return AllocSurface(
				ppSurf, 
				pddgpeAllocSurfaceData->nWidth, 
				pddgpeAllocSurfaceData->nHeight, 
				pddgpeAllocSurfaceData->gpeFormat, 
				pddgpeAllocSurfaceData->ddgpePixelFormat,
				pddgpeAllocSurfaceData->nSurfaceFlags
				);
}


SCODE DDGPE::AllocVideoSurface
				(DDGPESurf*			*ppSurf,
				int					width,
				int					height,
				EGPEFormat			format,
				EDDGPEPixelFormat	pixelFormat,
				unsigned long *	pOffsetInVideoMemory 
				)
{
	SCODE		rc = S_OK;
	DDGPESurf*	pSurf;

	//DEBUGMSG(1, (TEXT("Allocating video surface from DDGPE\r\n") ));
	rc = AllocSurface( &pSurf, width, height, format, pixelFormat, GPE_REQUIRE_VIDEO_MEMORY );

	if( SUCCEEDED(rc) )
	{
		pSurf->lpDDSurface = NULL;
	
		*pOffsetInVideoMemory = pSurf->OffsetInVideoMemory();
		DEBUGMSG(GPE_ZONE_CREATE,(TEXT("GPE_AllocVideoSurface: offset in video memory: %08x\r\n"),
											pSurf->OffsetInVideoMemory() ));
		*ppSurf = pSurf;
	}

	return rc;
}


SCODE DDGPE::AllocVideoSurface
				(LPDDRAWI_DDRAWSURFACE_GBL lpDDSurface,
				int					width,
				int					height,
				EGPEFormat			format,
				EDDGPEPixelFormat	pixelFormat,
				unsigned long *		pOffsetInVideoMemory 
				)
{
	SCODE		rc = S_OK;
	DDGPESurf*	pDDGPESurf = NULL;
	
	rc = AllocVideoSurface	(
								&pDDGPESurf,
								width,
								height,
								format,
								pixelFormat,
								pOffsetInVideoMemory
							);

	if (SUCCEEDED(rc))
	{
		if (lpDDSurface != NULL)
		{
			lpDDSurface->dwReserved1 = (ULONG_PTR)pDDGPESurf;
			lpDDSurface->fpVidMem = (FLATPTR)pDDGPESurf->Buffer();
			lpDDSurface->lPitch = pDDGPESurf->Stride();
		}

		// associate the dd surface with this gpe surface
		pDDGPESurf->lpDDSurface = lpDDSurface;

		/*
		lpDDSurface->dwReserved1 = (DWORD)pGPESurf;

		// associate the dd surface with this gpe surface
		pGPESurf->lpDDSurface = lpDDSurface;*/
	}

	return rc;
}

SCODE DDGPE::AllocVideoSurface(
						DDGPESurf*					*ppSurf,
						DDGPEAllocSurfaceData*		pddgpeAllocSurfaceData,
						unsigned long *				pOffsetInVideoMemory
						)
{
	SCODE		rc = S_OK;
	DDGPESurf*	pSurf;

	if ((ppSurf == NULL) || (pddgpeAllocSurfaceData == NULL))
	{
		return E_INVALIDARG;
	}

	//DEBUGMSG(1, (TEXT("Allocating video surface from DDGPE\r\n") ));

	pddgpeAllocSurfaceData->nSurfaceFlags |= GPE_REQUIRE_VIDEO_MEMORY;

	rc = AllocSurface( &pSurf, pddgpeAllocSurfaceData );

	if( SUCCEEDED(rc) )
	{
		pSurf->lpDDSurface = NULL;
	
		if (pOffsetInVideoMemory != NULL)
		{
			*pOffsetInVideoMemory = pSurf->OffsetInVideoMemory();
		}
		
		DEBUGMSG(GPE_ZONE_CREATE,(TEXT("GPE_AllocVideoSurface: offset in video memory: %08x\r\n"),
								pSurf->OffsetInVideoMemory() ));

		*ppSurf = pSurf;
	}

	return rc;
}

SCODE DDGPE::AllocVideoSurface(
						LPDDRAWI_DDRAWSURFACE_GBL	lpDDSurface,
						DDGPEAllocSurfaceData*		pddgpeAllocSurfaceData,
						unsigned long *				pOffsetInVideoMemory
						)
{
	SCODE		rc = S_OK;
	DDGPESurf*	pDDGPESurf = NULL;
	
	rc = AllocVideoSurface	(
								&pDDGPESurf,
								pddgpeAllocSurfaceData,
								pOffsetInVideoMemory
							);

	if (SUCCEEDED(rc))
	{
		if (lpDDSurface != NULL)
		{
			lpDDSurface->dwReserved1 = (ULONG_PTR)pDDGPESurf;
			lpDDSurface->fpVidMem = (FLATPTR)pDDGPESurf->Buffer();
			lpDDSurface->lPitch = pDDGPESurf->Stride();
		}

		// associate the dd surface with this gpe surface
		pDDGPESurf->lpDDSurface = lpDDSurface;

		/*
		lpDDSurface->dwReserved1 = (DWORD)pGPESurf;

		// associate the dd surface with this gpe surface
		pGPESurf->lpDDSurface = lpDDSurface;*/
	}

	return rc;
}


SCODE DDGPE::WrapSurface
				(LPDDRAWI_DDRAWSURFACE_GBL	lpDDSurface,
				int							width,
				int							height,
				EGPEFormat					format,
				EDDGPEPixelFormat			pixelFormat,
				int							stride,
				int							surfaceFlags
				)
{
	SCODE		rc = S_OK;
	DDGPESurf*	pDDGPESurf;

	//DEBUGMSG(1, (TEXT("Allocating video surface from DDGPE\r\n") ));
	rc = AllocSurface( &pDDGPESurf, width, height, format, pixelFormat, surfaceFlags );

	if (SUCCEEDED(rc) && (pDDGPESurf == NULL))
	{
		rc = E_UNEXPECTED;
	}
	if( SUCCEEDED(rc) )
	{
		if (lpDDSurface != NULL)
		{
			lpDDSurface->dwReserved1 = (ULONG_PTR)pDDGPESurf;
			lpDDSurface->fpVidMem = (FLATPTR)pDDGPESurf->Buffer();
			lpDDSurface->lPitch = pDDGPESurf->Stride();
		}

		// associate the dd surface with this gpe surface
		pDDGPESurf->lpDDSurface = lpDDSurface;
	}

	return rc;
}


SCODE DDGPE::WrapSurface
				(DDGPESurf*			*ppSurf,
				int					width,
				int					height,
				EGPEFormat			format,
				EDDGPEPixelFormat	pixelFormat,
				unsigned char *		pBits,
				int					stride 
				)
{
	DDGPESurf* pDDGPESurf = new DDGPESurf( width, height, pBits, stride, format, pixelFormat );
	if( !pDDGPESurf )
	{
		DEBUGMSG(GPE_ZONE_CREATE | GPE_ZONE_ERROR, (TEXT("DDGPE: Out of memory when creating system surface\r\n") ));
		return E_OUTOFMEMORY;
	}

	*ppSurf = pDDGPESurf;

	return S_OK;
}

SCODE DDGPE::WrapSurface
				(LPDDRAWI_DDRAWSURFACE_GBL	lpDDSurface,
				int					width,
				int					height,
				EGPEFormat			format,
				EDDGPEPixelFormat	pixelFormat,
				unsigned char *		pBits,
				int					stride 
				)
{
	DDGPESurf* pDDGPESurf = NULL;
	SCODE	sc = S_OK;
	
	sc = WrapSurface	(
							&pDDGPESurf,
							width,
							height,
							format,
							pixelFormat,
							pBits,
							stride
						);

	if (SUCCEEDED(sc))
	{
		if (lpDDSurface != NULL)
		{
			lpDDSurface->dwReserved1 = (ULONG_PTR)pDDGPESurf;
			lpDDSurface->fpVidMem = (FLATPTR)pDDGPESurf->Buffer();
			lpDDSurface->lPitch = pDDGPESurf->Stride();
		}

		// associate the dd surface with this gpe surface
		pDDGPESurf->lpDDSurface = lpDDSurface;

		/*
		// This is what _was_ being done, but I think it was not enough...
		lpDDSurface->dwReserved1 = (DWORD)pDDGPESurf;

		// associate the dd surface with this gpe surface
		pDDGPESurf->lpDDSurface = lpDDSurface;*/
	}

	return sc;
}


SCODE DDGPE::WrapSurface(
					DDGPESurf*					*ppSurf,
					DDGPEAllocSurfaceData*		pddgpeAllocSurfaceData 
					)
{
	SCODE	hr = S_OK;

	if (pddgpeAllocSurfaceData->pBits != NULL)
	{
		DDGPESurf* pDDGPESurf = new DDGPESurf(
										pddgpeAllocSurfaceData->nWidth, 
										pddgpeAllocSurfaceData->nHeight, 
										pddgpeAllocSurfaceData->pBits, 
										pddgpeAllocSurfaceData->nStride, 
										pddgpeAllocSurfaceData->gpeFormat, 
										pddgpeAllocSurfaceData->ddgpePixelFormat 
										);
		if( !pDDGPESurf )
		{
			DEBUGMSG(GPE_ZONE_CREATE | GPE_ZONE_ERROR, (TEXT("DDGPE: Out of memory when creating system surface\r\n") ));
			return E_OUTOFMEMORY;
		}

		*ppSurf = pDDGPESurf;

		hr = S_OK;
	}
	else
	{
	}

	return hr;
}

SCODE DDGPE::WrapSurface(
					LPDDRAWI_DDRAWSURFACE_GBL	lpDDSurface,
					DDGPEAllocSurfaceData*		pddgpeAllocSurfaceData 
					)
{
	DDGPESurf*	pDDGPESurf = NULL;
	SCODE		sc = S_OK;
	
	sc = WrapSurface	(
							&pDDGPESurf,
							pddgpeAllocSurfaceData
						);

	if (SUCCEEDED(sc))
	{
		if (lpDDSurface != NULL)
		{
			lpDDSurface->dwReserved1 = (ULONG_PTR)pDDGPESurf;
			lpDDSurface->fpVidMem  = (FLATPTR)pDDGPESurf->Buffer();
			lpDDSurface->lPitch = pDDGPESurf->Stride();
		}

		// associate the dd surface with this gpe surface
		pDDGPESurf->lpDDSurface = lpDDSurface;

		/*
		lpDDSurface->dwReserved1 = (DWORD)pDDGPESurf;

		// associate the dd surface with this gpe surface
		pDDGPESurf->lpDDSurface = lpDDSurface;
		*/
	}

	return sc;
}

SCODE DDGPE::BltPrepare(
					DDGPEBltParms*		pddgpeBltParms
					)
{
	//DEBUGMSG(HAL_ZONE_WARNING, (TEXT("BltPrepare(DDGPEBltParms) Not Implemented by DDI\r\n") ));

	if (pddgpeBltParms == NULL)
	{
		return E_INVALIDARG;
	}

        // DDGPE cannot do color conversion blits. Fail 'em.

        if (pddgpeBltParms->gpeBltParms.pSrc != NULL &&
            pddgpeBltParms->gpeBltParms.pDst != NULL) {

#ifdef _CPPRTTI

          DDGPESurf * pSrc = dynamic_cast<DDGPESurf *>(pddgpeBltParms->gpeBltParms.pSrc);
          DDGPESurf * pDst = dynamic_cast<DDGPESurf *>(pddgpeBltParms->gpeBltParms.pDst);

          // If either dynamic_cast failed, it means the surfaces are not
          // ddgpe surface, in which case, what the hell are we doing here?

          if (pSrc == NULL || pDst == NULL) {
            return DDERR_GENERIC;
          }

#else

          // No RTTI? Do it the barbaric way.

          DDGPESurf * pSrc = (DDGPESurf *)(pddgpeBltParms->gpeBltParms.pSrc);
          DDGPESurf * pDst = (DDGPESurf *)(pddgpeBltParms->gpeBltParms.pDst);

#endif

          if (pSrc->PixelFormat() != pDst->PixelFormat()) {
            return DDERR_UNSUPPORTED;
          }

        }

⌨️ 快捷键说明

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