📄 haldd.c
字号:
/******************************************************************************
<module>
* Name : haldd.c
* Title : DDraw calback fucntionality
* Author(s) : Imagination Technologies
* Created : 26 May 2004
*
* Copyright : 2004 by Imagination Technologies Limited.
* All rights reserved. No part of this software, either
* material or conceptual may be copied or distributed,
* transmitted, transcribed, stored in a retrieval system
* or translated into any human or computer language in any
* form by any means, electronic, mechanical, manual or
* other-wise, or disclosed to third parties without the
* express written permission of Imagination Technologies
* Limited, Unit 8, HomePark Industrial Estate,
* King's Langley, Hertfordshire, WD4 8LZ, U.K.
*
* Description : ddraw primary callback functionality
*
* Platform : Windows CE
*
$Log: haldd.c $
********************************************************************************/
#include "ddraw_headers.h"
/*
This is used as our faux mode table. We simply fill it out with the current
mode's information and return it to DirectDraw
*/
static DDHALMODEINFO l_sModeInfo;
/*****************************************************************************
<function>
FUNCTION : HALInit
PURPOSE : This function is called by DirectDraw as part of DirectDrawCreate to fill
out it's internal arrays of driver function pointers and caps bits. This
function assumes that the device has been initialized as part of the GWES
and GDI startup.
PARAMETERS : LPDDHALINFO structure to be filled in
RETURNS : BOOL - true if successful
<function/>
*****************************************************************************/
EXTERN_C BOOL
PVRHALInit ( LPDDHALINFO psHALInfo, BOOL bReset, ULONG ulModeIndex )
{
PVR_DISPLAYINFO sDisplayInfo;
DWORD dwNumDevices;
DWORD dwIndex;
PVRSRV_DEVICE_IDENTIFIER asDevId[PVRSRV_MAX_DEVICES];
PVRSRV_PRIMARY_SURF_INFO sPrimSurfData;
/* Reset and ModeIndex are currently not used */
ASSERTMSG ((L"HALInit failure"), (bReset == FALSE));
ASSERTMSG ((L"HALInit failure"), (ulModeIndex == 0));
// !TODO! Check HALInfo.
DPFENTER ((L"->HALInit"));
/* Fail if GDI is rotated */
if (GetRotationAngle() != 0)
{
return (FALSE);
}
/* Fill out the massive DDHALINFO structure to the best of our ability */
memset(psHALInfo, 0, sizeof(DDHALINFO));
psHALInfo->dwSize = sizeof(DDHALINFO);
/* Allocate memory for our driver data */
gpsDriverData = (PDXHALDATA)AllocSharedMem(sizeof(DXHALDATA));
if (!gpsDriverData)
{
DPFERROR ((L"!!!ERROR!!! - Failed to allocated driver data structure !"));
return (FALSE);
}
memset(gpsDriverData, 0, sizeof(DXHALDATA));
/* Initialise PDUMP context */
PDUMPINIT(&gpsDriverData->psPDContext);
/* Connect to resource manager */
PVRHALConnectResMan(TRUE, TRUE);
/* Enumerate PVRSRV devices */
if(PVRSRVEnumerateDevices(NULL, &dwNumDevices, asDevId) != PVRSRV_OK)
{
DPFERROR ((L"!!!ERROR!!! - Failed to allocated enumerate available devices!"));
goto HALInitErrorExit;
}
/* Obtain display class device Identifier index */
for(dwIndex = 0; dwIndex < dwNumDevices; dwIndex++)
{
/* Get class of current device */
PVRSRV_DEVICE_CLASS eDevClass = asDevId[dwIndex].eDeviceClass;
if(eDevClass == PVRSRV_DEVICE_CLASS_DISPLAY)
{
/*
Get and store dev data for the Display device. We will need this
to obtain a Primary surface structure later.
*/
if(PVRSRVAcquireDeviceData(NULL,
dwIndex,
&gpsDriverData->sDisplayDevData,
PVRSRV_DEVICE_TYPE_UNKNOWN) != PVRSRV_OK)
{
DPFERROR ((L"!!!ERROR!!! - Failed to acquire device data!"));
goto HALInitErrorExit;
}
}
else if(eDevClass == PVRSRV_DEVICE_CLASS_3D)
{
/*
Get and store dev data for the Display device. We will need this
to obtain a Primary surface structure later.
*/
if(PVRSRVAcquireDeviceData(NULL,
dwIndex,
&gpsDriverData->sDevData,
PVRSRV_DEVICE_TYPE_UNKNOWN) != PVRSRV_OK)
{
DPFERROR ((L"!!!ERROR!!! - Failed to acquire device data!"));
goto HALInitErrorExit;
}
}
}
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryEnable(gpsDriverData->sDisplayDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
/* Create DD HAL Command queue */
if(PVRSRVCreateCommandQueue(&gpsDriverData->sDisplayDevData, HAL_COMMANDQUEUE_SIZE, &gpsDriverData->psDDQueueInfo) != PVRSRV_OK)
{
DPFERROR ((L"!!!ERROR!!! - Failed to create command queue!"));
goto HALInitErrorExit;
}
/* Query for primary surface data */
if(PVRSRVQueryPrimary(&gpsDriverData->sDisplayDevData, &sPrimSurfData) != PVRSRV_OK)
{
DPFERROR ((L"!!!ERROR!!! - Failed Query Primary surface data!"));
goto HALInitErrorExit;
}
/* Obtain the primary surface object and populate our surface structure */
if(PVRSRVAcquirePrimary(&gpsDriverData->sDisplayDevData,
0,
sPrimSurfData.ui32PixelWidth,
sPrimSurfData.ui32PixelHeight,
sPrimSurfData.ePixelFormat,
&gpsDriverData->psPrimSurfData))
{
DPFERROR ((L"!!!ERROR!!! - Failed Get Primary surface data!"));
goto HALInitErrorExit;
}
/* Set up hardware info struct */
PVRSRVGetHWInfo(&gpsDriverData->sDevData, &gpsDriverData->sHWInfo);
/* Setup stuff in our driver data */
gpsDriverData->psDDHALInfo = psHALInfo;
gpsDriverData->dwDevCookie = 1;
/*
Default device name to empty string and fill it in when we
know we've got a valid string - this way we should create
DC's for the correct device every time
*/
gpsDriverData->pszDriverName[0] = '\0';
/* return our HINSTANCE */
psHALInfo->lpPDevice = (LPVOID)0; // physical device ptr
psHALInfo->hInstance = (DWORD)0; // instance handle of driver
/* Time to insert callbacks */
psHALInfo->dwFlags |= DDHALINFO_GETDRIVERINFOSET
| DDHALINFO_GETDRIVERINFO2
| DDHALINFO_ISPRIMARYDISPLAY
| DDHALINFO_MODEXILLEGAL;
psHALInfo->GetDriverInfo = (LPDDHAL_GETDRIVERINFO)HALGetDriverInfo;
psHALInfo->lpDDCallbacks = (LPDDHAL_DDCALLBACKS) /*MapLS*/((ULONG) &sHALDDCallbacks);
psHALInfo->lpDDSurfaceCallbacks = (LPDDHAL_DDSURFACECALLBACKS) /*MapLS*/((ULONG) &sHALDDSurfaceCallbacks);
psHALInfo->lpDDPaletteCallbacks = (LPDDHAL_DDPALETTECALLBACKS) /*MapLS*/((ULONG) &sHALDDPaletteCallbacks);
sHALDDCoreCaps.dwCaps |= DDCAPS_PALETTE;
/*
Reset the caps in case we set them last time.
*/
sHALDDCoreCaps.dwCaps |= DDCAPS_BLTDEPTHFILL;
sHALDDCoreCaps.dwCaps |= DDCAPS_ZBLTS;
/*
Copy our caps in.
*/
psHALInfo->lpdwFourCC = (PULONG) /*MapLS*/((ULONG) pdwHALFourCCs);
psHALInfo->ddCaps = sHALDDCoreCaps;
// Display mode and memory data.
memset(&sDisplayInfo, 0, sizeof(sDisplayInfo));
GetDisplayInfo(&sDisplayInfo);
psHALInfo->vmiData.ddpfDisplay.dwSize = sizeof(DDPIXELFORMAT);
psHALInfo->vmiData.fpPrimary = (ULONG)sDisplayInfo.pvFBLinBaseAddr;
psHALInfo->vmiData.dwDisplayWidth = sDisplayInfo.ulDisplayWidth;
psHALInfo->vmiData.dwDisplayHeight = sDisplayInfo.ulDisplayHeight;
psHALInfo->vmiData.lDisplayPitch = sDisplayInfo.ulDisplayPitch;
psHALInfo->dwMonitorFrequency = sDisplayInfo.ulMonitorFrequency;
psHALInfo->vmiData.ddpfDisplay.dwRGBBitCount = sDisplayInfo.ulBpp;
psHALInfo->vmiData.ddpfDisplay.dwRBitMask = sDisplayInfo.ulRedBitMask;
psHALInfo->vmiData.ddpfDisplay.dwGBitMask = sDisplayInfo.ulGreenBitMask;
psHALInfo->vmiData.ddpfDisplay.dwBBitMask = sDisplayInfo.ulBlueBitMask;
psHALInfo->vmiData.ddpfDisplay.dwRGBAlphaBitMask = sDisplayInfo.ulAlphaBitMask;
if(psHALInfo->vmiData.ddpfDisplay.dwRGBAlphaBitMask != 0)
{
psHALInfo->vmiData.ddpfDisplay.dwFlags = DDPF_RGB |
DDPF_ALPHAPIXELS |
DDPF_ALPHAPREMULT;
}
else
{
psHALInfo->vmiData.ddpfDisplay.dwFlags = DDPF_RGB;
}
/* Copy the data to our faux mode table */
l_sModeInfo.dwWidth = psHALInfo->vmiData.dwDisplayWidth;
l_sModeInfo.dwHeight = psHALInfo->vmiData.dwDisplayHeight;
l_sModeInfo.lPitch = psHALInfo->vmiData.lDisplayPitch;
l_sModeInfo.dwBPP = psHALInfo->vmiData.ddpfDisplay.dwRGBBitCount;
l_sModeInfo.wFlags = 0;
l_sModeInfo.wRefreshRate = (WORD)psHALInfo->dwMonitorFrequency;
l_sModeInfo.dwRBitMask = psHALInfo->vmiData.ddpfDisplay.dwRBitMask;
l_sModeInfo.dwGBitMask = psHALInfo->vmiData.ddpfDisplay.dwGBitMask;
l_sModeInfo.dwBBitMask = psHALInfo->vmiData.ddpfDisplay.dwBBitMask;
l_sModeInfo.dwAlphaBitMask = psHALInfo->vmiData.ddpfDisplay.dwRGBAlphaBitMask;
// We do our own memory management.
psHALInfo->vmiData.dwFlags = 0;
psHALInfo->vmiData.dwNumHeaps = 0;
psHALInfo->vmiData.pvmList = NULL;
/* Memory alignments */
psHALInfo->vmiData.dwZBufferAlign = ZBUF_ALIGN;
psHALInfo->vmiData.dwTextureAlign = TEXTURE_ALIGN;
psHALInfo->vmiData.dwOffscreenAlign = OFFSCREEN_ALIGN;
psHALInfo->vmiData.dwOverlayAlign = OVERLAY_ALIGN;
/* Fake DirectDraw into thinking we only have the display mode we are running in */
psHALInfo->dwModeIndex = 0;
psHALInfo->dwNumModes = 1;
psHALInfo->lpModeInfo = &l_sModeInfo;
DPFEXIT ((L"<-HALInit"));
return (TRUE);
HALInitErrorExit:
DPFEXIT ((L"<-HALInit"));
/* Clean up and Exit */
if(gpsDriverData->psPrimSurfData)
{
PVRSRVReleasePrimary(&gpsDriverData->sDisplayDevData, gpsDriverData->psPrimSurfData);
}
if(gpsDriverData->psDDQueueInfo)
{
PVRSRVDestroyCommandQueue(&gpsDriverData->sDisplayDevData, gpsDriverData->psDDQueueInfo);
}
if(gpsDriverData->sDisplayDevData.psDevInfoKM != NULL)
{
PVRSRVReleaseDeviceData(&gpsDriverData->sDisplayDevData);
}
if(gpsDriverData->sDevData.psDevInfoKM != NULL)
{
PVRSRVReleaseDeviceData(&gpsDriverData->sDevData);
}
PVRHALConnectResMan(TRUE, FALSE);
FreeSharedMem(gpsDriverData);
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(gpsDriverData->sDisplayDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
return (FALSE);
}
/*****************************************************************************
<function>
FUNCTION : HALDestroyDriver
PARAMETERS : LPDDHAL_DESTROYDRIVERDATA data structure
RETURNS : DDHAL return code
<function/>
*****************************************************************************/
DWORD WINAPI HALDestroyDriver(LPDDHAL_DESTROYDRIVERDATA psDestroyData )
{
DPFL2("DestroyDriver");
psDestroyData->ddRVal = DD_OK;
DPFL4("MBXDestroyDriver() - Destroying HAL");
/* This won't actually destroy the primary, just decrement the reference count */
PVRSRVReleasePrimary(&gpsDriverData->sDisplayDevData, gpsDriverData->psPrimSurfData);
/* Clean up the command queue */
PVRSRVDestroyCommandQueue(&gpsDriverData->sDisplayDevData, gpsDriverData->psDDQueueInfo);
/* Destroy the display device data */
PVRSRVReleaseDeviceData(&gpsDriverData->sDisplayDevData);
/* Destroy the 3d device data */
PVRSRVReleaseDeviceData(&gpsDriverData->sDevData);
/* De-initialise PDUMP Context */
PDUMPCLOSE(gpsDriverData->psPDContext);
/* Disconnect from resource manager */
PVRHALConnectResMan(TRUE, FALSE);
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(gpsDriverData->sDisplayDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
/* We need to free up driver data mem */
FreeSharedMem(gpsDriverData);
gpsDriverData = NULL;
return DDHAL_DRIVER_HANDLED;
}
/*****************************************************************************
<function>
FUNCTION : HALWaitForVerticalBlank
PARAMETERS : LPDDHAL_WAITFORVERTICALBLANKDATA data structure
RETURNS : DDHAL return code
<function/>
*****************************************************************************/
DWORD WINAPI HALWaitForVerticalBlank( LPDDHAL_WAITFORVERTICALBLANKDATA pd )
{
/* FIXME - TODO - Implement this function */
// FIXME We need to return OK for this or test kit fails for d3dm pd->ddRVal = DDERR_UNSUPPORTED;
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
/*****************************************************************************
<function>
FUNCTION : HALGetScanLine
PARAMETERS : LPDDHAL_GETSCANLINEDATA data structure
RETURNS : DDHAL return code
<function/>
*****************************************************************************/
DWORD WINAPI HALGetScanLine( LPDDHAL_GETSCANLINEDATA pd )
{
/* FIXME - Does This Work?
if(PDP_GetLineCount(g_PDPHandle,&psGetScanLine->dwScanLine) == PDP_ERROR_OK)
{
psGetScanLine->ddRVal = DD_OK;
}
else
{
psGetScanLine->ddRVal = DDERR_VERTICALBLANKINPROGRESS;
}
*/
pd->ddRVal = DDERR_UNSUPPORTED;
return DDHAL_DRIVER_HANDLED;
}
/*****************************************************************************
<function>
FUNCTION : HALSetExclusiveMode
PARAMETERS : LPDDHAL_SETEXCLUSIVEMODEDATA data structure
RETURNS : DDHAL return code
<function/>
*****************************************************************************/
DWORD WINAPI HALSetExclusiveMode( LPDDHAL_SETEXCLUSIVEMODEDATA pd )
{
/* FIXME - Called wen we leave or enter exclusive mode. Do we need to do anything here? */
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
/*****************************************************************************
End of file (haldd.c)
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -