mirror of
https://github.com/reactos/reactos.git
synced 2024-12-31 19:42:51 +00:00
Refactored d3d9 a bit
svn path=/trunk/; revision=31754
This commit is contained in:
parent
e23f06ce53
commit
f4ee84bae1
9 changed files with 176 additions and 126 deletions
|
@ -7,14 +7,16 @@
|
|||
* Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include "d3d9_private.h"
|
||||
#include <d3d9.h>
|
||||
#include "d3d9_helpers.h"
|
||||
#include "d3d9_create.h"
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
#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 "
|
||||
|
|
|
@ -13,5 +13,6 @@
|
|||
<file>d3d9.c</file>
|
||||
<file>d3d9_helpers.c</file>
|
||||
<file>d3d9_impl.c</file>
|
||||
<file>d3d9_create.c</file>
|
||||
<file>d3d9.rc</file>
|
||||
</module>
|
||||
|
|
19
reactos/dll/directx/d3d9/d3d9_common.h
Normal file
19
reactos/dll/directx/d3d9/d3d9_common.h
Normal file
|
@ -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 <gregor (dot) brunmar (at) home (dot) se>
|
||||
*/
|
||||
#ifndef _D3D9_COMMON_H_
|
||||
#define _D3D9_COMMON_H_
|
||||
|
||||
#define COBJMACROS
|
||||
#include <windows.h>
|
||||
|
||||
#define DLLAPI __declspec(dllexport)
|
||||
#define DX_D3D9_DEBUG 0x80000000
|
||||
|
||||
extern const struct IDirect3D9Vtbl Direct3D9_Vtbl;
|
||||
|
||||
#endif // _D3D9_COMMON_H_
|
128
reactos/dll/directx/d3d9/d3d9_create.c
Normal file
128
reactos/dll/directx/d3d9/d3d9_create.c
Normal file
|
@ -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 <gregor (dot) brunmar (at) home (dot) se>
|
||||
*/
|
||||
|
||||
typedef struct IDirect3D9 *LPDIRECT3D9;
|
||||
|
||||
#include "d3d9_create.h"
|
||||
#include "d3d9_helpers.h"
|
||||
#include <debug.h>
|
||||
#include <ddrawi.h>
|
||||
|
||||
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;
|
||||
}
|
16
reactos/dll/directx/d3d9/d3d9_create.h
Normal file
16
reactos/dll/directx/d3d9/d3d9_create.h
Normal file
|
@ -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 <gregor (dot) brunmar (at) home (dot) se>
|
||||
*/
|
||||
#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_
|
|
@ -6,6 +6,7 @@
|
|||
* PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
|
||||
*/
|
||||
|
||||
#include <d3d9.h>
|
||||
#include "d3d9_helpers.h"
|
||||
#include <stdio.h>
|
||||
#include <ddraw.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
* PURPOSE: IDirect3D9 implementation
|
||||
* PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
|
||||
*/
|
||||
#include "d3d9_helpers.h"
|
||||
|
||||
#include "d3d9_common.h"
|
||||
#include <d3d9.h>
|
||||
#include "d3d9_helpers.h"
|
||||
#include <debug.h>
|
||||
|
||||
/* IDirect3D9: IUnknown implementation */
|
||||
|
|
|
@ -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 <gregor (dot) brunmar (at) home (dot) se>
|
||||
*/
|
||||
#ifndef _D3D9_PRIVATE_H_
|
||||
#define _D3D9_PRIVATE_H_
|
||||
|
||||
#define COBJMACROS
|
||||
#include <windows.h>
|
||||
#include <d3d9.h>
|
||||
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue