From f4ee84bae1d56b60916025aac6bc465e0e4e91d4 Mon Sep 17 00:00:00 2001 From: Gregor Brunmar Date: Sun, 13 Jan 2008 11:45:31 +0000 Subject: [PATCH] Refactored d3d9 a bit svn path=/trunk/; revision=31754 --- reactos/dll/directx/d3d9/d3d9.c | 6 +- reactos/dll/directx/d3d9/d3d9.rbuild | 1 + reactos/dll/directx/d3d9/d3d9_common.h | 19 ++++ reactos/dll/directx/d3d9/d3d9_create.c | 128 ++++++++++++++++++++++++ reactos/dll/directx/d3d9/d3d9_create.h | 16 +++ reactos/dll/directx/d3d9/d3d9_helpers.c | 109 +------------------- reactos/dll/directx/d3d9/d3d9_helpers.h | 4 +- reactos/dll/directx/d3d9/d3d9_impl.c | 4 +- reactos/dll/directx/d3d9/d3d9_private.h | 15 +-- 9 files changed, 176 insertions(+), 126 deletions(-) create mode 100644 reactos/dll/directx/d3d9/d3d9_common.h create mode 100644 reactos/dll/directx/d3d9/d3d9_create.c create mode 100644 reactos/dll/directx/d3d9/d3d9_create.h diff --git a/reactos/dll/directx/d3d9/d3d9.c b/reactos/dll/directx/d3d9/d3d9.c index c30db67ff7c..5d3eab11902 100644 --- a/reactos/dll/directx/d3d9/d3d9.c +++ b/reactos/dll/directx/d3d9/d3d9.c @@ -7,14 +7,16 @@ * Gregor Brunmar */ -#include -#include "d3d9_private.h" +#include #include "d3d9_helpers.h" +#include "d3d9_create.h" #include #define DEBUG_MESSAGE_BUFFER_SIZE 512 +typedef IDirect3D9* (WINAPI *LPDIRECT3DCREATE9)(UINT); + static LPCSTR D3dError_WrongSdkVersion = "D3D ERROR: D3D header version mismatch.\n" "The application was compiled against and will only work with " diff --git a/reactos/dll/directx/d3d9/d3d9.rbuild b/reactos/dll/directx/d3d9/d3d9.rbuild index aff4e62f115..1fe8bd52bb6 100644 --- a/reactos/dll/directx/d3d9/d3d9.rbuild +++ b/reactos/dll/directx/d3d9/d3d9.rbuild @@ -13,5 +13,6 @@ d3d9.c d3d9_helpers.c d3d9_impl.c + d3d9_create.c d3d9.rc diff --git a/reactos/dll/directx/d3d9/d3d9_common.h b/reactos/dll/directx/d3d9/d3d9_common.h new file mode 100644 index 00000000000..0d6d0042c63 --- /dev/null +++ b/reactos/dll/directx/d3d9/d3d9_common.h @@ -0,0 +1,19 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS ReactX + * FILE: dll/directx/d3d9/d3d9_common.h + * PURPOSE: d3d9.dll common functions, defines and macros + * PROGRAMERS: Gregor Brunmar + */ +#ifndef _D3D9_COMMON_H_ +#define _D3D9_COMMON_H_ + +#define COBJMACROS +#include + +#define DLLAPI __declspec(dllexport) +#define DX_D3D9_DEBUG 0x80000000 + +extern const struct IDirect3D9Vtbl Direct3D9_Vtbl; + +#endif // _D3D9_COMMON_H_ diff --git a/reactos/dll/directx/d3d9/d3d9_create.c b/reactos/dll/directx/d3d9/d3d9_create.c new file mode 100644 index 00000000000..63e70a61672 --- /dev/null +++ b/reactos/dll/directx/d3d9/d3d9_create.c @@ -0,0 +1,128 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS ReactX + * FILE: dll/directx/d3d9/d3d9_create.c + * PURPOSE: d3d9.dll internal create functions and data + * PROGRAMERS: Gregor Brunmar + */ + +typedef struct IDirect3D9 *LPDIRECT3D9; + +#include "d3d9_create.h" +#include "d3d9_helpers.h" +#include +#include + +static const GUID DISPLAY_GUID = { 0x67685559, 0x3106, 0x11D0, { 0xB9, 0x71, 0x00, 0xAA, 0x00, 0x34, 0x2F, 0x9F } }; + +static CHAR D3D9_PrimaryDeviceName[CCHDEVICENAME]; + +static BOOL GetDisplayDeviceInfo(IN OUT LPDIRECT3D9_INT pDirect3D9) +{ + DISPLAY_DEVICEA DisplayDevice; + DWORD AdapterIndex; + DWORD Planes; + DWORD Bpp; + HDC hDC; + + memset(&DisplayDevice, 0, sizeof(DISPLAY_DEVICEA)); + DisplayDevice.cb = sizeof(DISPLAY_DEVICEA); + + pDirect3D9->dwNumDisplayAdapters = 0; + D3D9_PrimaryDeviceName[0] = '\0'; + + AdapterIndex = 0; + while (EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) == TRUE) + { + if ((DisplayDevice.StateFlags & (DISPLAY_DEVICE_DISCONNECT | DISPLAY_DEVICE_MIRRORING_DRIVER)) == 0 && + (DisplayDevice.StateFlags & (DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) != 0) + { + memcpy(&pDirect3D9->DisplayAdapters[0].DisplayGuid, &DISPLAY_GUID, sizeof(GUID)); + + lstrcpynA(pDirect3D9->DisplayAdapters[0].szDeviceName, DisplayDevice.DeviceName, MAX_PATH); + + if (pDirect3D9->dwNumDisplayAdapters == 0) + lstrcpynA(D3D9_PrimaryDeviceName, DisplayDevice.DeviceName, sizeof(D3D9_PrimaryDeviceName)); + + pDirect3D9->DisplayAdapters[0].dwStateFlags = DisplayDevice.StateFlags; + pDirect3D9->DisplayAdapters[0].bInUseFlag = TRUE; + + ++pDirect3D9->dwNumDisplayAdapters; + break; + } + } + + AdapterIndex = 0; + while (EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) == TRUE) + { + if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0 && + (DisplayDevice.StateFlags & (DISPLAY_DEVICE_MIRRORING_DRIVER | DISPLAY_DEVICE_PRIMARY_DEVICE)) == 0) + { + memcpy(&pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].DisplayGuid, &DISPLAY_GUID, sizeof(GUID)); + + lstrcpynA(pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].szDeviceName, DisplayDevice.DeviceName, MAX_PATH); + + pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].dwStateFlags = DisplayDevice.StateFlags; + pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].bInUseFlag = TRUE; + + ++pDirect3D9->dwNumDisplayAdapters; + } + } + + hDC = GetDC(NULL); + Planes = GetDeviceCaps(hDC, PLANES); + Bpp = GetDeviceCaps(hDC, BITSPIXEL); + ReleaseDC(NULL, hDC); + + if (Planes * Bpp < 8) + return FALSE; + + hDC = CreateDCA(NULL, D3D9_PrimaryDeviceName, NULL, NULL); + + if (hDC == NULL) + return FALSE; + + return TRUE; +} + +HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9) +{ + LPDIRECT3D9_INT pDirect3D9; + + if (ppDirect3D9 == 0) + return DDERR_INVALIDPARAMS; + + if (AlignedAlloc((LPVOID *)&pDirect3D9, sizeof(DIRECT3D9_INT)) != S_OK) + return DDERR_OUTOFMEMORY; + + if (pDirect3D9 == 0) + return DDERR_OUTOFMEMORY; + + pDirect3D9->unknown000007 = 0; + pDirect3D9->lpInt = 0; + + pDirect3D9->lpVtbl = &Direct3D9_Vtbl; + //pDirect3D9->dwProcessId = GetCurrentThreadId(); + pDirect3D9->dwRefCnt = 1; + + pDirect3D9->unknown004576 = 0; + pDirect3D9->unknown004578 = 0; + pDirect3D9->unknown004579 = 0; + pDirect3D9->unknown004580 = 0; + pDirect3D9->unknown004581 = 0; + pDirect3D9->unknown004582 = 0; + pDirect3D9->unknown004583 = 0; + pDirect3D9->unknown004589 = 0x20; + + pDirect3D9->lpInt = pDirect3D9; + pDirect3D9->unknown000007 = 1; + + //InitializeCriticalSection(&pDirect3D9->d3d9_cs); + + //memset(pDirect3D9->DisplayAdapters, 0, sizeof(pDirect3D9->DisplayAdapters)); + GetDisplayDeviceInfo(pDirect3D9); + + *ppDirect3D9 = (LPDIRECT3D9)&pDirect3D9->lpVtbl; + + return ERROR_SUCCESS; +} diff --git a/reactos/dll/directx/d3d9/d3d9_create.h b/reactos/dll/directx/d3d9/d3d9_create.h new file mode 100644 index 00000000000..74aeedf4267 --- /dev/null +++ b/reactos/dll/directx/d3d9/d3d9_create.h @@ -0,0 +1,16 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS ReactX + * FILE: dll/directx/d3d9/d3d9_create.h + * PURPOSE: d3d9.dll internal create functions and data + * PROGRAMERS: Gregor Brunmar + */ +#ifndef _D3D9_CREATE_H_ +#define _D3D9_CREATE_H_ + +#include "d3d9_private.h" + +/* Creates a Direct3D9 object */ +HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9); + +#endif // _D3D9_CREATE_H_ diff --git a/reactos/dll/directx/d3d9/d3d9_helpers.c b/reactos/dll/directx/d3d9/d3d9_helpers.c index b74d200299f..ef9c022104d 100644 --- a/reactos/dll/directx/d3d9/d3d9_helpers.c +++ b/reactos/dll/directx/d3d9/d3d9_helpers.c @@ -6,6 +6,7 @@ * PROGRAMERS: Gregor Brunmar */ +#include #include "d3d9_helpers.h" #include #include @@ -15,10 +16,6 @@ static LPCSTR D3D9_DebugRegPath = "Software\\Microsoft\\Direct3D"; -static const GUID DISPLAY_GUID = { 0x67685559, 0x3106, 0x11D0, { 0xB9, 0x71, 0x00, 0xAA, 0x00, 0x34, 0x2F, 0x9F } }; - -static CHAR D3D9_PrimaryDeviceName[32]; - LPDIRECT3D9_INT impl_from_IDirect3D9(LPDIRECT3D9 iface) { return (LPDIRECT3D9_INT)((ULONG_PTR)iface - FIELD_OFFSET(DIRECT3D9_INT, lpVtbl)); @@ -65,110 +62,6 @@ HRESULT FormatDebugString(IN OUT LPSTR Buffer, IN LONG BufferSize, IN LPCSTR For return 0; } -static BOOL GetDisplayDeviceInfo(IN OUT LPDIRECT3D9_INT pDirect3D9) -{ - DISPLAY_DEVICEA DisplayDevice; - DWORD AdapterIndex; - DWORD Planes; - DWORD Bpp; - HDC hDC; - - memset(&DisplayDevice, 0, sizeof(DISPLAY_DEVICEA)); - DisplayDevice.cb = sizeof(DISPLAY_DEVICEA); - - pDirect3D9->dwNumDisplayAdapters = 0; - D3D9_PrimaryDeviceName[0] = '\0'; - - AdapterIndex = 0; - while (EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) == TRUE) - { - if ((DisplayDevice.StateFlags & (DISPLAY_DEVICE_DISCONNECT | DISPLAY_DEVICE_MIRRORING_DRIVER)) == 0 && - (DisplayDevice.StateFlags & (DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) != 0) - { - memcpy(&pDirect3D9->DisplayAdapters[0].DisplayGuid, &DISPLAY_GUID, sizeof(GUID)); - - lstrcpynA(pDirect3D9->DisplayAdapters[0].szDeviceName, DisplayDevice.DeviceName, MAX_PATH); - - if (pDirect3D9->dwNumDisplayAdapters == 0) - lstrcpynA(D3D9_PrimaryDeviceName, DisplayDevice.DeviceName, sizeof(D3D9_PrimaryDeviceName)); - - pDirect3D9->DisplayAdapters[0].dwStateFlags = DisplayDevice.StateFlags; - pDirect3D9->DisplayAdapters[0].bInUseFlag = TRUE; - - ++pDirect3D9->dwNumDisplayAdapters; - } - } - - AdapterIndex = 0; - while (EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) == TRUE) - { - if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0 && - (DisplayDevice.StateFlags & (DISPLAY_DEVICE_MIRRORING_DRIVER | DISPLAY_DEVICE_PRIMARY_DEVICE)) == 0) - { - memcpy(&pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].DisplayGuid, &DISPLAY_GUID, sizeof(GUID)); - - lstrcpynA(pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].szDeviceName, DisplayDevice.DeviceName, MAX_PATH); - - pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].dwStateFlags = DisplayDevice.StateFlags; - pDirect3D9->DisplayAdapters[pDirect3D9->dwNumDisplayAdapters].bInUseFlag = TRUE; - - ++pDirect3D9->dwNumDisplayAdapters; - } - } - - hDC = GetDC(NULL); - Planes = GetDeviceCaps(hDC, PLANES); - Bpp = GetDeviceCaps(hDC, BITSPIXEL); - ReleaseDC(NULL, hDC); - - if (Planes * Bpp < 8) - return FALSE; - - return TRUE; -} - -HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9) -{ - LPDIRECT3D9_INT pDirect3D9; - - if (ppDirect3D9 == 0) - return DDERR_INVALIDPARAMS; - - if (AlignedAlloc((LPVOID *)&pDirect3D9, sizeof(DIRECT3D9_INT)) != S_OK) - return DDERR_OUTOFMEMORY; - - if (pDirect3D9 == 0) - return DDERR_OUTOFMEMORY; - - pDirect3D9->unknown000007 = 0; - pDirect3D9->lpInt = 0; - - pDirect3D9->lpVtbl = &Direct3D9_Vtbl; - //pDirect3D9->dwProcessId = GetCurrentThreadId(); - pDirect3D9->dwRefCnt = 1; - - pDirect3D9->unknown004576 = 0; - pDirect3D9->unknown004578 = 0; - pDirect3D9->unknown004579 = 0; - pDirect3D9->unknown004580 = 0; - pDirect3D9->unknown004581 = 0; - pDirect3D9->unknown004582 = 0; - pDirect3D9->unknown004583 = 0; - pDirect3D9->unknown004589 = 0x20; - - pDirect3D9->lpInt = pDirect3D9; - pDirect3D9->unknown000007 = 1; - - //InitializeCriticalSection(&pDirect3D9->d3d9_cs); - - //memset(pDirect3D9->DisplayAdapters, 0, sizeof(pDirect3D9->DisplayAdapters)); - GetDisplayDeviceInfo(pDirect3D9); - - *ppDirect3D9 = (LPDIRECT3D9)&pDirect3D9->lpVtbl; - - return ERROR_SUCCESS; -} - HRESULT AlignedAlloc(IN OUT LPVOID *ppObject, IN SIZE_T dwSize) { ULONG AddressOffset; diff --git a/reactos/dll/directx/d3d9/d3d9_helpers.h b/reactos/dll/directx/d3d9/d3d9_helpers.h index 1647da73efb..96bf1378ff2 100644 --- a/reactos/dll/directx/d3d9/d3d9_helpers.h +++ b/reactos/dll/directx/d3d9/d3d9_helpers.h @@ -8,6 +8,7 @@ #ifndef _D3D9_HELPERS_H_ #define _D3D9_HELPERS_H_ +#include "d3d9_common.h" #include "d3d9_private.h" /* Convert a IDirect3D9 pointer safely to the internal implementation struct */ @@ -19,9 +20,6 @@ BOOL ReadRegistryValue(IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataB /* Formats debug strings */ HRESULT FormatDebugString(IN OUT LPSTR Buffer, IN LONG BufferSize, IN LPCSTR FormatString, ... ); -/* Creates a Direct3D9 object */ -HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9); - /* Allocates memory and returns an aligned pointer */ HRESULT AlignedAlloc(IN OUT LPVOID *ppObject, IN SIZE_T dwSize); diff --git a/reactos/dll/directx/d3d9/d3d9_impl.c b/reactos/dll/directx/d3d9/d3d9_impl.c index afed7c42341..4e66516d43b 100644 --- a/reactos/dll/directx/d3d9/d3d9_impl.c +++ b/reactos/dll/directx/d3d9/d3d9_impl.c @@ -5,8 +5,10 @@ * PURPOSE: IDirect3D9 implementation * PROGRAMERS: Gregor Brunmar */ -#include "d3d9_helpers.h" +#include "d3d9_common.h" +#include +#include "d3d9_helpers.h" #include /* IDirect3D9: IUnknown implementation */ diff --git a/reactos/dll/directx/d3d9/d3d9_private.h b/reactos/dll/directx/d3d9/d3d9_private.h index 2ae86a8ced3..e44adf5543b 100644 --- a/reactos/dll/directx/d3d9/d3d9_private.h +++ b/reactos/dll/directx/d3d9/d3d9_private.h @@ -1,23 +1,14 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS ReactX - * FILE: dll/directx/d3d9/d3d9_helpers.c - * PURPOSE: d3d9.dll helper functions + * FILE: dll/directx/d3d9/d3d9_private.h + * PURPOSE: d3d9.dll internal structures * PROGRAMERS: Gregor Brunmar */ #ifndef _D3D9_PRIVATE_H_ #define _D3D9_PRIVATE_H_ -#define COBJMACROS #include -#include - -#define DLLAPI __declspec(dllexport) -#define DX_D3D9_DEBUG 0x80000000 - -typedef IDirect3D9* (WINAPI *LPDIRECT3DCREATE9)(UINT); - -extern const IDirect3D9Vtbl Direct3D9_Vtbl; typedef struct _tagDIRECT3D9DisplayAdapterInfo_ { @@ -133,7 +124,7 @@ typedef struct _tagDIRECT3D9DisplayAdapterInfo_ typedef struct _tagDIRECT3D9_INT_ { -/* 0x0000 */ const IDirect3D9Vtbl *lpVtbl; /* LPDIRECTD3D9 functoions table */ +/* 0x0000 */ const struct IDirect3D9Vtbl *lpVtbl; /* LPDIRECTD3D9 functoions table */ /* 0x0004 */ CRITICAL_SECTION d3d9_cs; /* 0x001c */ DWORD unknown000007; /* 0x00000001 */ /* 0x0020 */ DWORD dwProcessId;