Implemented IDirect3D9::CheckDeviceType()

svn path=/trunk/; revision=32496
This commit is contained in:
Gregor Brunmar 2008-02-26 21:33:04 +00:00
parent ec108a7c35
commit 314611d68d
7 changed files with 329 additions and 31 deletions

View file

@ -12,6 +12,7 @@
#include <ddraw.h>
#include <strsafe.h>
#include <debug.h>
#include <d3dhal.h>
#include "d3d9_private.h"
#include "adapter.h"
@ -217,7 +218,7 @@ static void CopyDriverCaps(const D3DCAPS9* pSrcCaps, D3DCAPS9* pDstCaps)
if (pSrcCaps->Caps2 & D3DCAPS2_PRESENT_INTERVAL_IMMEDIATE)
pDstCaps->PresentationIntervals |= D3DPRESENT_INTERVAL_IMMEDIATE;
pDstCaps->PrimitiveMiscCaps = pSrcCaps->PrimitiveMiscCaps & ~D3DPMISCCAPS_SEPERATEFVFFOG;
pDstCaps->PrimitiveMiscCaps = pSrcCaps->PrimitiveMiscCaps & ~D3DPMISCCAPS_FOGINFVF;
if (pSrcCaps->VertexProcessingCaps & D3DVTXPCAPS_FOGVERTEX)
{
@ -232,14 +233,14 @@ static void CopyDriverCaps(const D3DCAPS9* pSrcCaps, D3DCAPS9* pDstCaps)
HRESULT GetAdapterCaps(const LPDIRECT3D9_DISPLAYADAPTER_INT pDisplayAdapter, D3DDEVTYPE DeviceType, D3DCAPS9* pDstCaps)
{
HRESULT hResult = D3DERR_INVALIDDEVICE;
LPD3D9_DRIVERCAPS pDriverCaps = NULL;
D3DCAPS9* pDriverCaps = NULL;
ZeroMemory(pDstCaps, sizeof(D3DCAPS9));
switch (DeviceType)
{
case D3DDEVTYPE_HAL:
pDriverCaps = &pDisplayAdapter->DriverCaps;
pDriverCaps = &pDisplayAdapter->DriverCaps.DriverCaps9;
hResult = D3D_OK;
break;
@ -257,7 +258,7 @@ HRESULT GetAdapterCaps(const LPDIRECT3D9_DISPLAYADAPTER_INT pDisplayAdapter, D3D
if (pDriverCaps != NULL)
{
CopyDriverCaps(&pDriverCaps->DriverCaps, pDstCaps);
CopyDriverCaps(pDriverCaps, pDstCaps);
}
if (SUCCEEDED(hResult))

View file

@ -11,11 +11,13 @@
<library>dxguid</library>
<library>strsafe</library>
<library>version</library>
<library>d3d8thk</library>
<file>d3d9.c</file>
<file>d3d9_helpers.c</file>
<file>d3d9_impl.c</file>
<file>d3d9_create.c</file>
<file>adapter.c</file>
<file>format.c</file>
<file>d3d9.rc</file>
</module>

View file

@ -45,18 +45,51 @@ static VOID SetAdapterInfo(IN OUT LPDIRECT3D9_DISPLAYADAPTER_INT pDisplayAdapter
pDisplayAdapter->bInUseFlag = TRUE;
}
static BOOL IsGDIDriver(HDC hDC)
{
COLORREF NearestBlack = GetNearestColor(hDC, RGB(0, 0, 0));
COLORREF NearestWhite = GetNearestColor(hDC, RGB(255, 255, 255));
if (NearestBlack != RGB(0, 0, 0) || NearestWhite != RGB(255, 255, 255))
return TRUE;
return FALSE;
}
static BOOL GetDirect3DAdapterInfo(IN OUT LPDIRECT3D9_DISPLAYADAPTER_INT pDisplayAdapter)
{
HDC hDC;
/* Check if minimum DirectDraw is supported */
if (IsDirectDrawSupported() == FALSE)
return FALSE;
LPD3D9_DEVICEDATA pDeviceData;
/* Test DC creation for the display device */
if (NULL == (hDC = CreateDCA(NULL, pDisplayAdapter->szDeviceName, NULL, NULL)))
return FALSE;
pDeviceData = LocalAlloc(LMEM_ZEROINIT, sizeof(D3D9_DEVICEDATA));
if (NULL == pDeviceData)
{
DPRINT1("Out of memory, could not initialize Direct3D adapter");
DeleteDC(hDC);
return FALSE;
}
pDeviceData->hDC = hDC;
pDeviceData->DisplayGuid = pDisplayAdapter->DisplayGuid;
pDeviceData->DeviceType = D3DDEVTYPE_HAL;
lstrcpynA(pDeviceData->szDeviceName, pDisplayAdapter->szDeviceName, CCHDEVICENAME);
pDeviceData->szDeviceName[CCHDEVICENAME-1] = '\0';
if (pDisplayAdapter->bInUseFlag)
{
pDeviceData->_UnknownA8h.DeviceType = D3DDEVTYPE_HAL;
}
else if (IsGDIDriver(hDC))
{
pDeviceData->_UnknownA8h.DeviceType = D3DDEVTYPE_REF;
}
//GetDeviceData(pDeviceData);
DeleteDC(hDC);
return TRUE;
}
@ -105,6 +138,10 @@ static BOOL GetDisplayDeviceInfo(IN OUT LPDIRECT3D9_INT pDirect3D9)
++AdapterIndex;
}
/* Check if minimum DirectDraw is supported */
if (IsDirectDrawSupported() == FALSE)
return FALSE;
for (AdapterIndex = 0; AdapterIndex < pDirect3D9->NumDisplayAdapters; AdapterIndex++)
{
GetDirect3DAdapterInfo(&pDirect3D9->DisplayAdapters[AdapterIndex]);

View file

@ -11,6 +11,7 @@
#include <debug.h>
#include "d3d9_helpers.h"
#include "adapter.h"
#include "format.h"
/* IDirect3D9: IUnknown implementation */
static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface, REFIID riid, LPVOID* ppvObject)
@ -340,12 +341,95 @@ static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9 iface, UI
return D3D_OK;
}
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE CheckType,
/*++
* @name IDirect3D9::CheckDeviceType
* @implemented
*
* The function IDirect3D9Impl_CheckDeviceType checks if a specific D3DFORMAT is hardware accelerated
* on the specified display adapter.
*
* @param LPDIRECT3D iface
* Pointer to the IDirect3D object returned from Direct3DCreate9()
*
* @param UINT Adapter
* Adapter index to get information about. D3DADAPTER_DEFAULT is the primary display.
* The maximum value for this is the value returned by IDirect3D::GetAdapterCount().
*
* @param D3DDEVTYPE DeviceType
* One of the D3DDEVTYPE enum members.
*
* @param D3DFORMAT DisplayFormat
* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display adapter mode to be checked.
*
* @param D3DFORMAT BackBufferFormat
* One of the D3DFORMAT enum membersfor the render target mode to be checked. D3DFMT_UNKNOWN is only allowed in windowed mode.
*
* @param BOOL Windowed
* If this value is TRUE, the D3DFORMAT check will be done for windowed mode and FALSE equals fullscreen mode.
*
* @return HRESULT
* If the format is hardware accelerated, the method returns D3D_OK.
* If the format isn't hardware accelerated or unsupported - the return value will be D3DERR_NOTAVAILABLE.
* If Adapter is out of range, DeviceType is invalid,
* DisplayFormat or BackBufferFormat is invalid - the return value will be D3DERR_INVALIDCALL.
*
*/
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType,
D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
{
UNIMPLEMENTED
HRESULT hResult;
return D3D_OK;
LPDIRECT3D9_INT This = impl_from_IDirect3D9(iface);
LOCK_D3D9();
if (Adapter >= This->NumDisplayAdapters)
{
DPRINT1("Invalid Adapter number specified");
UNLOCK_D3D9();
return D3DERR_INVALIDCALL;
}
if (DeviceType != D3DDEVTYPE_HAL &&
DeviceType != D3DDEVTYPE_REF &&
DeviceType != D3DDEVTYPE_SW)
{
DPRINT1("Invalid DeviceType specified");
UNLOCK_D3D9();
return D3DERR_INVALIDCALL;
}
if (BackBufferFormat == D3DFMT_UNKNOWN &&
Windowed == TRUE)
{
BackBufferFormat = DisplayFormat;
}
if (DisplayFormat == D3DFMT_UNKNOWN && BackBufferFormat == D3DFMT_UNKNOWN)
{
DPRINT1("Invalid D3DFORMAT specified");
UNLOCK_D3D9();
return D3DERR_INVALIDCALL;
}
if (FALSE == IsBackBufferFormat(BackBufferFormat))
{
DPRINT1("Invalid D3DFORMAT specified");
UNLOCK_D3D9();
return D3DERR_NOTAVAILABLE;
}
if (TRUE == Windowed && TRUE == IsExtendedFormat(DisplayFormat))
{
DPRINT1("Extended diplay modes can only be used in fullscreen mode");
UNLOCK_D3D9();
return D3DERR_NOTAVAILABLE;
}
hResult = CheckDeviceFormat(&This->DisplayAdapters[Adapter].DriverCaps, DisplayFormat, BackBufferFormat, Windowed);
UNLOCK_D3D9();
return hResult;
}
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType,

View file

@ -9,13 +9,91 @@
#define _D3D9_PRIVATE_H_
#include <windows.h>
#include <ddraw.h>
#define DX_D3D9_MAX_NUM_ADAPTERS 12
typedef struct _tagD3D9_DRIVERCAPS
{
D3DCAPS9 DriverCaps;
} D3D9_DRIVERCAPS, FAR* LPD3D9_DRIVERCAPS;
/* 0x0000 */ D3DCAPS9 DriverCaps9;
/* 0x0130 */ DWORD dwDisplayWidth;
/* 0x0134 */ DWORD dwDisplayHeight;
/* 0x0138 */ D3DFORMAT RawDisplayFormat;
/* 0x013c */ D3DFORMAT DisplayFormat;
/* 0x0140 */ DWORD dwRefreshRate;
/* 0x0144 */ DWORD unknown0081;
/* 0x0148 */ DWORD dwSVBCaps;
/* 0x014c */ DWORD dwVSBCaps;
/* 0x0150 */ DWORD dwSVBCaps2;
/* 0x0154 */ DWORD unknown0085;
/* 0x0158 */ DWORD NumSupportedFormatOps;
/* 0x015c */ LPDDSURFACEDESC pSupportedFormatOps;
/* 0x0160 */ DWORD unknown0088;
/* 0x0164 */ DWORD NumSupportedExtendedModes;
/* 0x0168 */ D3DDISPLAYMODE* pSupportedExtendedModes;
/* 0x016c */ ULONG_PTR ulUniqueAdapterGroupId;
/* 0x0170 */ DWORD NumSupportedQueries;
/* 0x0174 */ D3DQUERYTYPE* pSupportedQueriesList;
} D3D9_DRIVERCAPS, FAR *LPD3D9_DRIVERCAPS;
typedef struct _tagUnknownA8h
{
/* 0x0000 */ DWORD DdCreateSurface;
/* 0x0004 */ DWORD DdDestroySurface;
/* 0x0008 */ DWORD DdLock;
/* 0x000c */ DWORD DdUnlock;
/* 0x0010 */ DWORD D3dContextCreate;
/* 0x0014 */ DWORD D3dContextDestroy;
/* 0x0018 */ DWORD unknown0100;
/* 0x001c */ DWORD unknown0101;
/* 0x0020 */ DWORD unknown0102;
/* 0x0024 */ DWORD D3dDrawPrimitives2;
/* 0x0028 */ DWORD DdGetDriverState;
/* 0x002c */ DWORD D3dValidateTextureStageState;
/* 0x0030 */ DWORD unknown0106;
/* 0x0034 */ DWORD unknown0107;
/* 0x0038 */ DWORD DdBlt;
/* 0x003c */ DWORD DdGetScanLine;
/* 0x0040 */ DWORD DdWaitForVerticalBlank;
/* 0x0044 */ DWORD DdFlip;
/* 0x0048 */ DWORD DdGetBltStatus;
/* 0x004c */ DWORD DdGetFlipStatus;
/* 0x0050 */ DWORD DdGetAvailDriverMemory;
/* 0x0054 */ DWORD unknown0115;
/* 0x0058 */ DWORD DdSetMode;
/* 0x005c */ DWORD DdSetExclusiveMode;
/* 0x0060 */ DWORD DdFlipToGDISurface;
/* 0x0064 */ DWORD unknown0119;
/* 0x0068 */ DWORD unknown0120;
/* 0x006c */ DWORD unknown0121;
/* 0x0070 */ DWORD unknown0122;
/* 0x0074 */ DWORD unknown0123;
/* 0x0078 */ DWORD unknown0124;
/* 0x007c */ DWORD DXVAGetGuids;
/* 0x0080 */ DWORD DXVAGetCompressedBufferInfo;
/* 0x0084 */ DWORD DXVAGetUncompressedFormats;
/* 0x0088 */ DWORD DXVAGetInternalInfo;
/* 0x008c */ DWORD DXVACreate;
/* 0x0090 */ DWORD DXVADestroy;
/* 0x0094 */ DWORD DXVABeginFrame;
/* 0x0098 */ DWORD DXVAEndFrame;
/* 0x009c */ DWORD DXVAExecute;
/* 0x00a0 */ DWORD DXVAQueryStatus;
/* 0x00a4 */ D3DDEVTYPE DeviceType;
} D3D9_UnknownA8h_INT;
typedef struct _tagD3D9_DEVICEDATA
{
/* 0x0000 */ D3D9_DRIVERCAPS DriverCaps;
/* 0x0178 */ D3D9_UnknownA8h_INT _UnknownA8h;
/* 0x0220 */ CHAR szDeviceName[CCHDEVICENAME];
/* 0x0240 */ HDC hDC;
/* 0x0244 */ GUID DisplayGuid;
/* 0x0254 */ LPDWORD pUnknown0254; //D3D9_Unknown6BC_INT* pUnknown6BC; // hDirectDrawLocal
/* 0x0258 */ D3DDEVTYPE DeviceType;
/* 0x025c */ HMODULE hD3DRefDll;
/* 0x0260 */ DWORD unknown0152;
} D3D9_DEVICEDATA, FAR *LPD3D9_DEVICEDATA;
typedef struct _tagDIRECT3D9DisplayAdapterInfo_
{
@ -32,24 +110,6 @@ typedef struct _tagDIRECT3D9DisplayAdapterInfo_
/* 0x0134 */ D3DDISPLAYMODE* pSupportedD3DExtendedFormats;
/* 0x0138 */ DWORD unknown000009;
/* 0x013c */ D3D9_DRIVERCAPS DriverCaps;
/* 0x026c */ DWORD dwDisplayWidth; /* Current display res */
/* 0x0270 */ DWORD dwDisplayHeight; /* Current display res */
/* 0x0274 */ DWORD unknown000088; /* Current D3DFORMAT */
/* 0x0278 */ DWORD unknown000089; /* Current D3DFORMAT - duplicate? */
/* 0x027c */ DWORD MonitorFrequency; /* Current monitor frequency */
/* 0x0280 */ DWORD unknown000091;
/* 0x0284 */ DWORD unknown000092;
/* 0x0288 */ DWORD unknown000093;
/* 0x028c */ DWORD unknown000094;
/* 0x0290 */ DWORD unknown000095;
/* 0x0294 */ DWORD unknown000096;
/* 0x0298 */ DWORD unknown000097;
/* 0x029c */ DWORD unknown000098;
/* 0x02a0 */ DWORD unknown000099;
/* 0x02a4 */ DWORD unknown000100;
/* 0x02a8 */ DWORD unknown000101; /*? 0xf7627000 */
/* 0x02ac */ DWORD unknown000102; /*? 0x00000002 */
/* 0x02b0 */ LPDWORD unknown000103; /*? 0x001552A0 */
/* 0x02b4 */ DWORD unknown000104;
/* 0x02b8 */ DWORD unknown000105;
} Direct3D9DisplayAdapterInfo_INT, FAR* LPDIRECT3D9_DISPLAYADAPTER_INT;

View file

@ -0,0 +1,91 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS ReactX
* FILE: dll/directx/d3d9/format.c
* PURPOSE: d3d9.dll D3DFORMAT helper functions
* PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
*/
#include "format.h"
#include <ddrawi.h>
BOOL IsBackBufferFormat(D3DFORMAT Format)
{
return ((Format >= D3DFMT_A8R8G8B8) && (Format < D3DFMT_A1R5G5B5)) ||
(IsExtendedFormat(Format));
}
BOOL IsExtendedFormat(D3DFORMAT Format)
{
return (Format == D3DFMT_A2R10G10B10);
}
BOOL IsSupportedFormatOp(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayFormat, DWORD FormatOp)
{
const DWORD NumFormatOps = pDriverCaps->NumSupportedFormatOps;
DWORD FormatOpIndex;
for (FormatOpIndex = 0; FormatOpIndex < NumFormatOps; FormatOpIndex++)
{
const LPDDSURFACEDESC pSurfaceDesc = &pDriverCaps->pSupportedFormatOps[FormatOpIndex];
if (pSurfaceDesc->ddpfPixelFormat.dwFourCC == DisplayFormat &&
(pSurfaceDesc->ddpfPixelFormat.dwOperations & FormatOp) == FormatOp)
{
return TRUE;
}
}
return FALSE;
}
HRESULT CheckDeviceFormat(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
{
if (FALSE == IsSupportedFormatOp(pDriverCaps, DisplayFormat, D3DFORMAT_OP_DISPLAYMODE | D3DFORMAT_OP_3DACCELERATION))
{
return D3DERR_NOTAVAILABLE;
}
if (DisplayFormat != BackBufferFormat)
{
D3DFORMAT AdjustedDisplayFormat = DisplayFormat;
if (DisplayFormat == D3DFMT_X8R8G8B8)
{
DisplayFormat = D3DFMT_A8R8G8B8;
}
else if (DisplayFormat == D3DFMT_X1R5G5B5)
{
DisplayFormat = D3DFMT_A1R5G5B5;
}
if (AdjustedDisplayFormat == BackBufferFormat)
{
if (FALSE == IsSupportedFormatOp(pDriverCaps, AdjustedDisplayFormat, D3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET))
{
return D3DERR_NOTAVAILABLE;
}
return D3D_OK;
}
else if (FALSE == Windowed)
{
return D3DERR_NOTAVAILABLE;
}
if (FALSE == IsSupportedFormatOp(pDriverCaps, BackBufferFormat, D3DFORMAT_OP_OFFSCREEN_RENDERTARGET) ||
FALSE == IsSupportedFormatOp(pDriverCaps, BackBufferFormat, D3DFORMAT_OP_CONVERT_TO_ARGB) ||
FALSE == IsSupportedFormatOp(pDriverCaps, BackBufferFormat, D3DFORMAT_MEMBEROFGROUP_ARGB))
{
return D3DERR_NOTAVAILABLE;
}
}
else
{
if (FALSE == IsSupportedFormatOp(pDriverCaps, DisplayFormat, D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET))
{
return D3DERR_NOTAVAILABLE;
}
}
return D3D_OK;
}

View file

@ -0,0 +1,23 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS ReactX
* FILE: dll/directx/d3d9/format.h
* PURPOSE: d3d9.dll D3DFORMAT helper functions
* PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
*/
#ifndef _FORMAT_H_
#define _FORMAT_H_
#include <d3d9.h>
#include "d3d9_private.h"
BOOL IsBackBufferFormat(D3DFORMAT Format);
BOOL IsExtendedFormat(D3DFORMAT Format);
BOOL IsSupportedFormatOp(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayFormat, DWORD FormatOp);
HRESULT CheckDeviceFormat(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed);
#endif // _FORMAT_H_