📄 display.c
字号:
/**************************************************************************
* Name : display.c
* Title : DISP overlay control functions
* Author : Dave Bartlett
* Created : 23/04/02
*
* Copyright : 2003 by Imagination Technologies. 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 : PDP overlay control API (Marathon)
*
* Platform :
*
Version : $Revision: 1.20 $
Modifications :
$Log: display.c $
--- Revision Logs Removed ---
--- Revision Logs Removed ---
*/
/***************************************************** Configuration options */
//WARNING : M24VA_HW_VERIFICATION & M24VA_SW_SIMULATION must not both be defined
#ifdef DEBUG
#define DEBUG_MODE
#endif
//#define M24VA_SW_SIMULATION //Use software simulator
/*****************************************************************************/
#include <windows.h>
#include "drvescape.h"
#include "img_defs.h"
#include "services.h"
#include "drvescape.h"
#include "pdpal.h"
#pragma warning(disable: 4142)
#include "pvrapi.h"
#include "pvrvadd.h"
#include "decdisp.h"
#include "mbx12ddef.h"
#include "mbx13ddef.h"
/*****************************************************************************/
#define VDISP_NUM_ROT_SURFACES (4) /* This value should always be at least 2 (and it should always be a power of 2) */
#define ALLOCATION_ALIGNMENT (4096)
#define VDISP_QUEUE_SIZE (1024)
enum {eFLIP_INTERVAL = 1};
typedef struct _VDISP_STATE_
{
IMG_BOOL bHardwareInUse;
IMG_HANDLE hServices;
PVRSRV_DEV_DATA sDevData;
PVRSRV_DEV_DATA sDevDataPDP;
PVRSRV_PRIMARY_SURF* psPrimarySurf;
IMG_UINT32 ui32DisplayRotation;
IMG_UINT32 ui32SourceRotation;
IMG_UINT32 ui32NextRotatedBuffer;
IMG_BOOL bRotatedBuffersAllocated;
IMG_BOOL bCommandQueueCreated;
/* Hardware Info */
PVRSRV_HW_INFO sHWInfo;
/* rotated display buffers */
PVRSRV_MEM_INFO *apsDisplaySurfaces[VDISP_NUM_ROT_SURFACES];
IMG_UINT32 ui32RotatedDisplaySurfStride;
/* blit and flip queue */
PVRSRV_QUEUE_INFO *psCmdQueueInfo;
HDC hdcDriver;
} VDISP_STATE;
PVRSRV_SYNC_INFO *gpsLastSyncObject;
VDISP_STATE g_DISPState = { FALSE,0,NULL,0,0,0,FALSE };
/******************************************************** External functions */
/*****************************************************************************
FUNCTION : VDISP_Initialise
PURPOSE : Initialise PDP interface, acquire hardware
PARAMETERS : ui32Param - implemention specific parameter
RETURNS : VDISPError
Notes :
*****************************************************************************/
VDISPError PVRAPI VDISP_Initialise(IMG_PVOID pvParam)
{
PVRSRV_PRIMARY_SURF_INFO sPrimaryInfo;
if(g_DISPState.bHardwareInUse)
{
return(VDISPError_HardwareNotAvailable);
}
memset(&g_DISPState, 0, sizeof(g_DISPState));
gpsLastSyncObject = IMG_NULL;
g_DISPState.bHardwareInUse = TRUE;
g_DISPState.hdcDriver = GetWindowDC(NULL);
/* Connect to services acquire device */
PVRSRVConnect(NULL, &g_DISPState.hServices);
if(PVRSRVAcquireDeviceData(g_DISPState.hServices, 0, &g_DISPState.sDevData, PVRSRV_DEVICE_TYPE_MBX1_LITE) != PVRSRV_OK)
{
PVRSRVDisconnect(g_DISPState.hServices);
g_DISPState.hServices = NULL;
return(VDISPError_HardwareNotAvailable);
}
if(PVRSRVAcquireDeviceData(g_DISPState.hServices, 0, &g_DISPState.sDevDataPDP, PVRSRV_DEVICE_TYPE_PDP) != PVRSRV_OK)
{
PVRSRVDisconnect(g_DISPState.hServices);
g_DISPState.hServices = NULL;
return(VDISPError_HardwareNotAvailable);
}
/* Get surface width and height. */
if (PVRSRVQueryPrimary(&g_DISPState.sDevDataPDP, &sPrimaryInfo) != PVRSRV_OK)
{
ASSERT(0);
return VDISPError_GenericError;
}
if (PVRSRVAcquirePrimary(&g_DISPState.sDevDataPDP,
0,
sPrimaryInfo.ui32PixelWidth,
sPrimaryInfo.ui32PixelHeight,
PVRSRV_PIXEL_FORMAT_RGB565,
&g_DISPState.psPrimarySurf) != PVRSRV_OK)
{
ASSERT(0);
return VDISPError_GenericError;
}
g_DISPState.ui32NextRotatedBuffer = 0;
/* Obtain device HWinfo */
if(PVRSRVGetHWInfo(&g_DISPState.sDevData, &g_DISPState.sHWInfo))
{
PVRSRVDisconnect(g_DISPState.hServices);
g_DISPState.hServices = NULL;
return(VDISPError_GenericError);
}
return(VDISPError_OK);
}
/*****************************************************************************
FUNCTION : VDISP_Deinitialise
PURPOSE : Deinitialise PDP interface, release hardware
PARAMETERS :
RETURNS : VDISPError
Notes :
*****************************************************************************/
VDISPError PVRAPI VDISP_Deinitialise()
{
int i;
if(!g_DISPState.bHardwareInUse)
{
return(VDISPError_NotInitialised);
}
//#if !defined(M24VA_SW_SIMULATION)
{
PDP_OVERLAYATTRIBS sOverlay;
/* Ensure that overlay is turned off */
sOverlay.wValidFlags = PDP_OVERLAYATTRIB_VALID_VISIBILITY |
PDP_OVERLAYATTRIB_VALID_PIXFMT;
sOverlay.PixFormat = PDP_OVL_INVALID;
sOverlay.bOverlayOn = FALSE;
ExtEscape(g_DISPState.hdcDriver, DRVESC_OVERLAY_ATTRIBUTE,
sizeof(sOverlay), (LPSTR)&sOverlay,
sizeof(sOverlay), (LPSTR)&sOverlay);
if(g_DISPState.bRotatedBuffersAllocated == IMG_TRUE)
{
/* free the device memory we allocated for rotation */
for(i=0;i<VDISP_NUM_ROT_SURFACES;i++)
{
if(PVRSRVFreeDeviceMem(&g_DISPState.sDevData, g_DISPState.apsDisplaySurfaces[i]) != PVRSRV_OK)
{
return(VDISPError_GenericError);
}
g_DISPState.apsDisplaySurfaces[i] = NULL;
}
g_DISPState.bRotatedBuffersAllocated = IMG_FALSE;
}
if (g_DISPState.bCommandQueueCreated == IMG_TRUE)
{
/* Destroy the command queue */
PVRSRVDestroyCommandQueue(&g_DISPState.sDevData,g_DISPState.psCmdQueueInfo);
g_DISPState.bCommandQueueCreated = IMG_FALSE;
}
PVRSRVReleasePrimary(&g_DISPState.sDevDataPDP, g_DISPState.psPrimarySurf);
ReleaseDC(NULL, g_DISPState.hdcDriver);
#if defined(SUPPORT_3D_BLIT)
PVRSRVDeInitOverlayBltResources(&g_DISPState.sDevData);
#endif
PVRSRVReleaseDeviceData(&g_DISPState.sDevData);
PVRSRVReleaseDeviceData(&g_DISPState.sDevDataPDP);
PVRSRVDisconnect(g_DISPState.hServices);
g_DISPState.hServices = NULL;
g_DISPState.hdcDriver = NULL;
g_DISPState.bHardwareInUse = IMG_FALSE;
}
// #endif /* !defined(M24VA_SW_SIMULATION) */
return(VDISPError_OK);
}
/*****************************************************************************
FUNCTION : VDISP_GetRotationAngle
PURPOSE : Internal function to find physical screen rotation
PARAMETERS :
RETURNS : VDISPError
Notes :
*****************************************************************************/
static IMG_UINT32 VDISP_GetRotationAngle()
{
IMG_UINT32 ui32Angle=0;
/*
* This driver escape gives us a consistant interpretation of rotation angle
* Otherwise we get different angles for PocketPC and WinCE
*/
ExtEscape(g_DISPState.hdcDriver, DRVESC_GET_PHYS_ROTATION, 0,
NULL, sizeof(PDWORD), (LPSTR)&ui32Angle);
switch(ui32Angle)
{
case DMDO_0:
/* do nothing */
default:
break;
case DMDO_90:
ui32Angle=90;
break;
case DMDO_180:
ui32Angle=180;
break;
case DMDO_270:
ui32Angle=270;
break;
}
return(ui32Angle);
}
/*****************************************************************************
FUNCTION : VDISP_SetOverlayAttributes
PURPOSE :
PARAMETERS :
RETURNS : VDISPError
Notes :
*****************************************************************************/
VDISPError PVRAPI VDISP_OverlaySetAttributes(PVDISP_OVERLAYATTRIBS psOverlayAttributes,
SMSurface hSurface)
{
VDISPError eRtn = VDISPError_OK;
WORD wFlags =0;
IMG_UINT32 ui32Size;
IMG_UINT32 ui32BltRotateCmd;
PDP_OVERLAYATTRIBS sOverlay;
IMG_UINT32 ui32ScreenWidth, ui32ScreenHeight;
PINT_SM_HANDLE pSurface = (PINT_SM_HANDLE) hSurface;
int i;
/* Return error if application is using DirectDraw */
if (pSurface->bDirectDrawActive)
{
return VDISPError_IllegalFunctionCall;
}
if(!psOverlayAttributes || !hSurface)
{
return VDISPError_InvalidParameter;
}
switch(pSurface->eFormat)
{
case M24VA_SURF_FORMAT_420: sOverlay.PixFormat = PDP_OVL_IMC2; break;
case M24VA_SURF_FORMAT_422: sOverlay.PixFormat = PDP_OVL_YUY2; break;
default:
return(VDISPError_IncorrectSurfaceFormat);
break;
}
ui32ScreenWidth = GetDeviceCaps(g_DISPState.hdcDriver, HORZRES);
ui32ScreenHeight = GetDeviceCaps(g_DISPState.hdcDriver, VERTRES);
g_DISPState.ui32DisplayRotation = VDISP_GetRotationAngle();
/* if the screen is rotated and the Disable Rotation flag is not set then we need to
* make sure we have rotated display surfaces allocated and that we tell PDPAPI the
* rotated coordinates
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -