📄 halsurf.cpp
字号:
//
// 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 DEBUG_RectBuf 0
#ifdef ENABLE_DIRECT3D
extern void D3DGetPixelFormat(LPDDHAL_CREATESURFACEDATA pd);
extern DWORD D3DCreate3Dbuffer(LPDDHAL_CREATESURFACEDATA pd);
#endif // ENABLE_DIRECT3D
#ifdef DD_ENABLE
typedef struct {
LPDDRAWI_DDRAWSURFACE_LCL pSrcSurf;
DWORD dwID ; //0 if available
DWORD dwDstX1;
DWORD dwDstY1;
DWORD dwDstW ; //w and h in pixel
DWORD dwDstH ;
DWORD dwSrcW ; //w and h in pixel
DWORD dwSrcH ;
DWORD pSrcStart;
DWORD dwSrcPitch;
DWORD dwSurfBpp;
//Hardware-Used stuffs
WORD wVidEngNo;
WORD dwVideoFmt;
WORD wVideoCtrl;
WORD wVFIFO;
WORD wFetch;
} OVERLAYSURF,FAR *LPOVERLAYSURF;
OVERLAYSURF os;
// retrieve pFormat and pPixelFormat based on pDDPF
SCODE DetectPixelFormat(DDPIXELFORMAT *pDDPF,
EGPEFormat *pFormat,
EDDGPEPixelFormat *pPixelFormat)
{
if( pDDPF->dwFlags & DDPF_RGB )
{
if( !(pDDPF->dwFlags & DDPF_ALPHAPIXELS) )
{
pDDPF->dwRGBAlphaBitMask = 0;
}
/*
if( pDDPF->dwRGBBitCount == 4 )
{
*pPixelFormat = ddgpePixelFormat_4bpp;
}
else
*/
if( pDDPF->dwRGBBitCount == 8 )
{
*pPixelFormat = ddgpePixelFormat_8bpp;
}
else if( pDDPF->dwRGBBitCount == 16 )
{
if( pDDPF->dwRGBAlphaBitMask == 0x0000 &&
pDDPF->dwRBitMask == 0xF800 )
{
DEBUGMSG(1, (TEXT("565 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_565;
}
/*
else if( pDDPF->dwRGBAlphaBitMask == 0x8000 &&
pDDPF->dwRBitMask == 0x7C00 )
{
DEBUGMSG(1, (TEXT("1555 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_5551;
}
else if( pDDPF->dwRGBAlphaBitMask == 0xF000 &&
pDDPF->dwRBitMask == 0x0F00 )
{
DEBUGMSG(1, (TEXT("4444 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_4444;
}
else if( pDDPF->dwRGBAlphaBitMask == 0x0000 &&
pDDPF->dwRBitMask == 0x7C00 )
{
DEBUGMSG(1, (TEXT("0555 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_5550;
}
*/
else {
DEBUGMSG(1, (TEXT("DetectFormat: Unsupported 16-bit format\r\n") ));
return DDERR_UNSUPPORTEDFORMAT;
}
}
/*
else if( pDDPF->dwRGBBitCount == 24 )
{
if( pDDPF->dwRGBAlphaBitMask == 0x000000 &&
pDDPF->dwRBitMask == 0xFF0000 )
{
DEBUGMSG(1, (TEXT("8880 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_8880;
}
else
{
DEBUGMSG(1, (TEXT("DetectFormat: Unsupported 24-bit format\r\n") ));
return DDERR_UNSUPPORTEDFORMAT;
}
}
*/
else if( pDDPF->dwRGBBitCount == 32 )
{
if( pDDPF->dwRGBAlphaBitMask == 0x00000000 &&
pDDPF->dwRBitMask == 0x00FF0000 )
{
DEBUGMSG(1, (TEXT("8888 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_8888;
}
else
{
DEBUGMSG(1, (TEXT("DetectFormat: Unsupported 32-bit format\r\n") ));
return DDERR_UNSUPPORTEDFORMAT;
}
}
else
{
DEBUGMSG(1, (TEXT("DetectFormat: Unsupported bit-depth (%d)\r\n"), pDDPF->dwRGBBitCount));
return DDERR_UNSUPPORTEDFORMAT;
}
}
else if( pDDPF->dwFlags & DDPF_ZBUFFER )
{
#ifdef ENABLE_DIRECT3D
//Handle Z-buffer for D3D. WG. 6/15/02
DEBUGMSG(1, (TEXT("DetectFormat: Zbuffer surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_565;
#else
//*pPixelFormat = ddgpePixelFormat_raw;
return DDERR_UNSUPPORTEDFORMAT;
#endif //ENABLE_DIRECT3D
}
else if( pDDPF->dwFlags & DDPF_FOURCC )
{
if( pDDPF->dwFourCC == FOURCC_YUYV422 ) {
DEBUGMSG(1, (TEXT("DetectFormat: YUYV422 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_YUYV422;
}
else if( pDDPF->dwFourCC == FOURCC_YUY2422 ) {
DEBUGMSG(1, (TEXT("DetectFormat: YUY2422 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_YUY2422;
}
else if( pDDPF->dwFourCC == FOURCC_UYVY422 ) {
DEBUGMSG(1, (TEXT("DetectFormat: UYVY422 surface detected\r\n") ));
*pPixelFormat = ddgpePixelFormat_UYVY422;
}
else {
DEBUGMSG(1, (TEXT("DetectFormat: Unsupported FOURCC %08x\r\n"), pDDPF->dwFourCC ));
return DDERR_UNSUPPORTEDFORMAT;
}
}
else
{
DEBUGMSG(1, (TEXT("DetectFormat: Unsupported Non-RGB, Non-FOURCC surface.\r\n")));
return DDERR_UNSUPPORTEDFORMAT;
}
*pFormat = EDDGPEPixelFormatToEGPEFormat[*pPixelFormat];
DEBUGMSG(1, (TEXT("Detected surface pixelFormat, format = %d, %d\r\n"),
*pPixelFormat, *pFormat));
return DD_OK;
}
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;
}
DWORD WINAPI HalCreateSurface( LPDDHAL_CREATESURFACEDATA pd )
{
DEBUGENTER( HalCreateSurface );
/*
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
EGPEFormat format;
EDDGPEPixelFormat pixelFormat;
EDDGPEPixelFormat primaryPixelFormat;
DWORD dwFlags = pd->lpDDSurfaceDesc->dwFlags;
DWORD dwCaps = pd->lpDDSurfaceDesc->ddsCaps.dwCaps;
// get the pixel format for the primary surface
GPEMode modeInfo;
SCODE sc = ((SMI *)g_pGPE)->GetModeInfo(&modeInfo, 0);
if (FAILED(sc))
{
DEBUGMSG(1, (TEXT("Error: can't get mode info\r\n")));
pd->ddRVal = DDERR_GENERIC;
return DDHAL_DRIVER_HANDLED;
}
GPEModeEx modeInfoEx;
sc = ((SMI *)g_pGPE)->GetModeInfoEx(&modeInfoEx, 0);
if (FAILED(sc))
{
primaryPixelFormat = EGPEFormatToEDDGPEPixelFormat[modeInfo.format];
}
else
{
primaryPixelFormat = modeInfoEx.ePixelFormat;
}
// get the pixel format for the surface to be created
if (dwFlags & DDSD_PIXELFORMAT)
{
#ifdef ENABLE_DIRECT3D
D3DGetPixelFormat(pd);
#endif // ENABLE_DIRECT3D
pd->ddRVal = DetectPixelFormat(
&pd->lpDDSurfaceDesc->ddpfPixelFormat,
&format,
&pixelFormat);
if (FAILED(pd->ddRVal))
{
DEBUGMSG(1, (TEXT("HalCreateSurface: unsupported format\r\n")));
return DDHAL_DRIVER_HANDLED;
}
}
else
{
pixelFormat = primaryPixelFormat;
}
return DDGPECreateSurface(pd);
}
//////////////////////////// DDHAL_DDEXEBUFCALLBACKS ////////////////////////////
DWORD WINAPI HalCanCreateSurface( LPDDHAL_CANCREATESURFACEDATA pd )
{
DEBUGENTER( HalCanCreateSurface );
/*
typedef struct _DDHAL_CANCREATESURFACEDATA
{
LPDDRAWI_DIRECTDRAW_GBL lpDD; // driver struct
LPDDSURFACEDESC lpDDSurfaceDesc; // description of surface being created
DWORD bIsDifferentPixelFormat;
// pixel format differs from primary surface
HRESULT ddRVal; // return value
LPDDHAL_CANCREATESURFACE CanCreateSurface;
// PRIVATE: ptr to callback
} DDHAL_CANCREATESURFACEDATA;
*/
// Implementation
DDPIXELFORMAT *pddpf = &pd->lpDDSurfaceDesc->ddpfPixelFormat;
DWORD caps = pd->lpDDSurfaceDesc->ddsCaps.dwCaps;
// We do not allow system memory primaries.
//if ((caps & DDSCAPS_PRIMARYSURFACE) &&
// (caps & DDSCAPS_SYSTEMMEMORY)) {
// goto CannotCreate;
// }
if (pd->bIsDifferentPixelFormat) {
//if (caps & DDSCAPS_OVERLAY)
{
if (pddpf->dwFlags & DDPF_FOURCC) {
DEBUGMSG(1, (TEXT("HalCanCreateSurface FOURCC = %08x ('%c','%c','%c','%c')\r\n")
, pddpf->dwFourCC
, (pddpf->dwFourCC ) & 0xff
, (pddpf->dwFourCC >> 8) & 0xff
, (pddpf->dwFourCC >> 16) & 0xff
, (pddpf->dwFourCC >> 24) & 0xff
));
switch (pddpf->dwFourCC)
{
case FOURCC_UYVY422:
case FOURCC_YUY2422:
case FOURCC_YUYV422:
/* just in case App doesn't fill this */
pddpf->dwYUVBitCount=16;
goto CanCreate;
break;
default:
goto CannotCreate;
}
}
else if (pddpf->dwFlags & DDPF_RGB) {
DEBUGMSG(1, (TEXT("HalCanCreateSurface RGBBitCount = %d\r\n"), pddpf->dwRGBBitCount));
if (
(pddpf->dwRGBBitCount == 8)
||
(pddpf->dwRGBBitCount == 16 &&
pddpf->dwRBitMask == 0xF800 &&
pddpf->dwGBitMask == 0x07E0 &&
pddpf->dwBBitMask == 0x001F)
/* ||
(pddpf->dwRGBBitCount == 16 &&
pddpf->dwRBitMask == 0x7C00 &&
pddpf->dwGBitMask == 0x03E0 &&
pddpf->dwBBitMask == 0x001F)
*/
) {
goto CanCreate;
}
else {
goto CannotCreate;
}
}
}
}
CanCreate:
DEBUGMSG(1, (TEXT("HalCanCreateSurface: OK\r\n")));
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
CannotCreate:
DEBUGMSG(1, (TEXT("HalCanCreateSurface: Unsupported\r\n")));
pd->ddRVal = DDERR_UNSUPPORTEDFORMAT;
return DDHAL_DRIVER_HANDLED;
}
DWORD WINAPI HalCreateExecuteBuffer( LPDDHAL_CREATESURFACEDATA pd )
{
DEBUGENTER( HalCreateExecuteBuffer );
/*
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
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD WINAPI HalDestroyExecuteBuffer( LPDDHAL_DESTROYSURFACEDATA pd )
{
DEBUGENTER( HalDestroyExecutebuffer );
/*
typedef struct _DDHAL_DESTROYSURFACEDATA
{
LPDDRAWI_DIRECTDRAW_GBL lpDD; // driver struct
LPDDRAWI_DDRAWSURFACE_LCL lpDDSurface; // surface struct
HRESULT ddRVal; // return value
LPDDHALSURFCB_DESTROYSURFACE DestroySurface;// PRIVATE: ptr to callback
BOOL fDestroyGlobal;
} DDHAL_DESTROYSURFACEDATA;
*/
// Implementation
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD WINAPI HalLock( LPDDHAL_LOCKDATA pd )
{
//DEBUGENTER( HalLock );
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
// return ((SMI *)g_pGPE)->Lock(pd);
}
DWORD SMI::Lock( LPDDHAL_LOCKDATA pd )
{
//DEBUGENTER( HalLock );
/*
typedef struct _DDHAL_LOCKDATA
{
LPDDRAWI_DIRECTDRAW_GBL lpDD; // driver struct
LPDDRAWI_DDRAWSURFACE_LCL lpDDSurface; // surface struct
DWORD bHasRect; // rArea is valid
RECTL rArea; // area being locked
LPVOID lpSurfData; // pointer to screen memory (return value)
HRESULT ddRVal; // return value
LPDDHALSURFCB_LOCK Lock; // PRIVATE: ptr to callback
} DDHAL_LOCKDATA;
*/
// RETAILMSG(1,(TEXT("SMI:: +Lock()\r\n")));
DDGPESurf* pSurf = DDGPESurf::GetDDGPESurf(pd->lpDDSurface);
if (SurfaceBusyFlipping(pSurf))
{
pd->ddRVal = DDERR_WASSTILLDRAWING;
return DDHAL_DRIVER_HANDLED;
}
if (pd->dwFlags & DDLOCK_WAIT)
{
WaitForNotBusy();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -