ReactOS 0.4.16-dev-125-g798ea90
d3d9_create.c File Reference
#include <d3d9.h>
#include "d3d9_create.h"
#include "d3d9_helpers.h"
#include "d3d9_caps.h"
#include <debug.h>
#include <ddrawi.h>
#include <ddrawgdi.h>
Include dependency graph for d3d9_create.c:

Go to the source code of this file.

Functions

static BOOL IsDirectDrawSupported ()
 
static VOID SetAdapterInfo (IN OUT LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapter, IN LPDISPLAY_DEVICEA pDisplayDevice)
 
static BOOL IsGDIDriver (HDC hDC)
 
void GetDisplayAdapterFromDevice (IN OUT LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapters, IN DWORD AdapterIndex, IN LPD3D9_DEVICEDATA pDeviceData)
 
BOOL CreateD3D9DeviceData (IN LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapter, IN LPD3D9_DEVICEDATA pDeviceData)
 
VOID DestroyD3D9DeviceData (IN LPD3D9_DEVICEDATA pDeviceData)
 
static BOOL GetDirect3D9AdapterInfo (IN OUT LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapters, IN DWORD AdapterIndex)
 
static BOOL GetDisplayDeviceInfo (IN OUT LPDIRECT3D9_INT pDirect3D9)
 
HRESULT CreateD3D9 (OUT LPDIRECT3D9 *ppDirect3D9, UINT SDKVersion)
 

Variables

static const GUID DISPLAY_GUID = { 0x67685559, 0x3106, 0x11D0, { 0xB9, 0x71, 0x00, 0xAA, 0x00, 0x34, 0x2F, 0x9F } }
 
static CHAR D3D9_PrimaryDeviceName [CCHDEVICENAME]
 

Function Documentation

◆ CreateD3D9()

HRESULT CreateD3D9 ( OUT LPDIRECT3D9 ppDirect3D9,
UINT  SDKVersion 
)

Definition at line 237 of file d3d9_create.c.

238{
239 LPDIRECT3D9_INT pDirect3D9;
240
241 if (ppDirect3D9 == 0)
242 return DDERR_INVALIDPARAMS;
243
244 if (AlignedAlloc((LPVOID *)&pDirect3D9, sizeof(DIRECT3D9_INT)) != S_OK)
245 return DDERR_OUTOFMEMORY;
246
247 if (pDirect3D9 == 0)
248 return DDERR_OUTOFMEMORY;
249
250 pDirect3D9->lpVtbl = &Direct3D9_Vtbl;
251 pDirect3D9->dwProcessId = GetCurrentThreadId();
252 pDirect3D9->lRefCnt = 1;
253
254 pDirect3D9->SDKVersion = SDKVersion;
255
256 pDirect3D9->lpInt = pDirect3D9;
257 pDirect3D9->unknown000007 = 1;
258
259 InitializeCriticalSection(&pDirect3D9->d3d9_cs);
260
261 if (FALSE == GetDisplayDeviceInfo(pDirect3D9))
262 {
263 DPRINT1("Could not create Direct3D9 object");
264 AlignedFree(pDirect3D9);
265 return DDERR_GENERIC;
266 }
267
268 *ppDirect3D9 = (LPDIRECT3D9)&pDirect3D9->lpVtbl;
269
270 return D3D_OK;
271}
#define DPRINT1
Definition: precomp.h:8
struct IDirect3D9 * LPDIRECT3D9
Definition: d3d9.h:124
struct IDirect3D9Vtbl Direct3D9_Vtbl
Definition: d3d9_impl.c:1028
static BOOL GetDisplayDeviceInfo(IN OUT LPDIRECT3D9_INT pDirect3D9)
Definition: d3d9_create.c:181
VOID AlignedFree(IN OUT LPVOID pObject)
Definition: d3d9_helpers.c:130
HRESULT AlignedAlloc(IN OUT LPVOID *ppObject, IN SIZE_T dwSize)
Definition: d3d9_helpers.c:95
#define D3D_OK
Definition: d3d.h:106
#define FALSE
Definition: types.h:117
#define S_OK
Definition: intsafe.h:52
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DDERR_GENERIC
Definition: ddraw.h:72
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459

Referenced by Direct3DCreate9().

◆ CreateD3D9DeviceData()

BOOL CreateD3D9DeviceData ( IN LPDIRECT3D9_DISPLAYADAPTER  pDisplayAdapter,
IN LPD3D9_DEVICEDATA  pDeviceData 
)

Definition at line 115 of file d3d9_create.c.

116{
117 HDC hDC;
118
119 /* Test DC creation for the display device */
120 if (NULL == (hDC = CreateDCA(NULL, pDisplayAdapter->szDeviceName, NULL, NULL)))
121 {
122 DPRINT1("Could not create dc for display adapter: %s", pDisplayAdapter->szDeviceName);
123 return FALSE;
124 }
125
126 pDeviceData->hDC = hDC;
127 pDeviceData->DisplayGuid = pDisplayAdapter->DisplayGuid;
128 pDeviceData->DeviceType = D3DDEVTYPE_HAL;
129 lstrcpynA(pDeviceData->szDeviceName, pDisplayAdapter->szDeviceName, CCHDEVICENAME);
130 pDeviceData->szDeviceName[CCHDEVICENAME-1] = '\0';
131
132 if (pDisplayAdapter->bInUseFlag)
133 {
134 pDeviceData->D3D9Callbacks.DeviceType = D3DDEVTYPE_HAL;
135 }
136 else if (IsGDIDriver(hDC))
137 {
138 pDeviceData->D3D9Callbacks.DeviceType = D3DDEVTYPE_REF;
139 }
140
141 if (FALSE == GetDeviceData(pDeviceData))
142 {
143 DPRINT1("Could not get device data for display adapter: %s", pDisplayAdapter->szDeviceName);
144 return FALSE;
145 }
146
147 return TRUE;
148}
static HDC hDC
Definition: 3dtext.c:33
@ D3DDEVTYPE_HAL
Definition: d3d8types.h:576
@ D3DDEVTYPE_REF
Definition: d3d8types.h:577
BOOL GetDeviceData(LPD3D9_DEVICEDATA pDeviceData)
Definition: d3d9_caps.c:126
static BOOL IsGDIDriver(HDC hDC)
Definition: d3d9_create.c:48
#define CCHDEVICENAME
Definition: ddrawi.h:63
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define lstrcpynA
Definition: compat.h:751
static HDC
Definition: imagelist.c:88
HDC WINAPI CreateDCA(_In_opt_ LPCSTR pszDriver, _In_opt_ LPCSTR pszDevice, _In_opt_ LPCSTR pszOutput, _In_opt_ const DEVMODEA *pdmInit)

Referenced by GetDirect3D9AdapterInfo(), and InitD3D9BaseDevice().

◆ DestroyD3D9DeviceData()

VOID DestroyD3D9DeviceData ( IN LPD3D9_DEVICEDATA  pDeviceData)

Definition at line 150 of file d3d9_create.c.

151{
152 DeleteDC(pDeviceData->hDC);
153 HeapFree(GetProcessHeap(), 0, pDeviceData->pUnknown6BC);
154}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI DeleteDC(_In_ HDC)

Referenced by GetDirect3D9AdapterInfo(), and IDirect3DDevice9Base_Release().

◆ GetDirect3D9AdapterInfo()

static BOOL GetDirect3D9AdapterInfo ( IN OUT LPDIRECT3D9_DISPLAYADAPTER  pDisplayAdapters,
IN DWORD  AdapterIndex 
)
static

Definition at line 156 of file d3d9_create.c.

157{
158 LPD3D9_DEVICEDATA pDeviceData;
159
160 pDeviceData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3D9_DEVICEDATA));
161 if (NULL == pDeviceData)
162 {
163 DPRINT1("Out of memory, could not initialize Direct3D adapter");
164 return FALSE;
165 }
166
167 if (FALSE == CreateD3D9DeviceData(&pDisplayAdapters[AdapterIndex], pDeviceData))
168 {
169 DPRINT1("Could not create device data for adapter: %d", AdapterIndex);
170 return FALSE;
171 }
172
173 GetDisplayAdapterFromDevice(pDisplayAdapters, AdapterIndex, pDeviceData);
174
175 DestroyD3D9DeviceData(pDeviceData);
176 HeapFree(GetProcessHeap(), 0, pDeviceData);
177
178 return TRUE;
179}
BOOL CreateD3D9DeviceData(IN LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapter, IN LPD3D9_DEVICEDATA pDeviceData)
Definition: d3d9_create.c:115
void GetDisplayAdapterFromDevice(IN OUT LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapters, IN DWORD AdapterIndex, IN LPD3D9_DEVICEDATA pDeviceData)
Definition: d3d9_create.c:59
VOID DestroyD3D9DeviceData(IN LPD3D9_DEVICEDATA pDeviceData)
Definition: d3d9_create.c:150
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134

Referenced by GetDisplayDeviceInfo().

◆ GetDisplayAdapterFromDevice()

void GetDisplayAdapterFromDevice ( IN OUT LPDIRECT3D9_DISPLAYADAPTER  pDisplayAdapters,
IN DWORD  AdapterIndex,
IN LPD3D9_DEVICEDATA  pDeviceData 
)

Definition at line 59 of file d3d9_create.c.

60{
61 LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapter = &pDisplayAdapters[AdapterIndex];
62 DWORD FormatOpIndex;
63 DWORD AdapterGroupId;
64 DWORD NumAdaptersInGroup;
66
67 memcpy(&pDisplayAdapter->DriverCaps, &pDeviceData->DriverCaps, sizeof(D3D9_DRIVERCAPS));
68
69 for (FormatOpIndex = 0; FormatOpIndex < pDeviceData->DriverCaps.NumSupportedFormatOps; FormatOpIndex++)
70 {
71 LPDDSURFACEDESC pSurfaceDesc = &pDeviceData->DriverCaps.pSupportedFormatOps[FormatOpIndex];
72 D3DFORMAT Format = pSurfaceDesc->ddpfPixelFormat.dwFourCC;
73
74 if ((pSurfaceDesc->ddpfPixelFormat.dwOperations & D3DFORMAT_OP_DISPLAYMODE) != 0 &&
76 {
77 pDisplayAdapter->Supported16bitFormat = Format;
78 break;
79 }
80 }
81
82 NumAdaptersInGroup = 0;
83 AdapterGroupId = pDeviceData->DriverCaps.ulUniqueAdapterGroupId;
84 for (Index = 0; Index < AdapterIndex; Index++)
85 {
86 if (AdapterGroupId == pDisplayAdapters[Index].DriverCaps.ulUniqueAdapterGroupId)
87 ++NumAdaptersInGroup;
88 }
89 pDisplayAdapter->MasterAdapterIndex = AdapterIndex;
90 pDisplayAdapter->NumAdaptersInGroup = NumAdaptersInGroup + 1; /* Add self */
91 pDisplayAdapter->AdapterIndexInGroup = NumAdaptersInGroup;
92
94 pDisplayAdapter->szDeviceName,
95 NULL,
96 &pDisplayAdapter->NumSupportedD3DFormats,
97 pDisplayAdapter->Supported16bitFormat,
98 pDeviceData->pUnknown6BC
99 );
100
101 if (pDisplayAdapter->NumSupportedD3DFormats > 0)
102 {
103 pDisplayAdapter->pSupportedD3DFormats = HeapAlloc(GetProcessHeap(), 0, pDisplayAdapter->NumSupportedD3DFormats * sizeof(D3DDISPLAYMODE));
104
106 pDisplayAdapter->szDeviceName,
107 pDisplayAdapter->pSupportedD3DFormats,
108 &pDisplayAdapter->NumSupportedD3DFormats,
109 pDisplayAdapter->Supported16bitFormat,
110 pDeviceData->pUnknown6BC
111 );
112 }
113}
@ D3DFMT_X1R5G5B5
Definition: d3d8types.h:607
@ D3DFMT_R5G6B5
Definition: d3d8types.h:606
enum _D3DFORMAT D3DFORMAT
void CreateDisplayModeList(LPCSTR lpszDeviceName, D3DDISPLAYMODE *pDisplayModes, DWORD *pNumDisplayModes, D3DFORMAT Default16BitFormat, D3D9_Unknown6BC *pUnknown6BC)
Definition: d3d9_caps.c:17
#define D3DFORMAT_OP_DISPLAYMODE
Definition: ddrawi.h:1584
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
D3DDISPLAYMODE * pSupportedD3DFormats
Definition: d3d9_private.h:159
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by GetDirect3D9AdapterInfo().

◆ GetDisplayDeviceInfo()

static BOOL GetDisplayDeviceInfo ( IN OUT LPDIRECT3D9_INT  pDirect3D9)
static

Definition at line 181 of file d3d9_create.c.

182{
183 DISPLAY_DEVICEA DisplayDevice;
184 DWORD AdapterIndex;
185
186 memset(&DisplayDevice, 0, sizeof(DISPLAY_DEVICEA));
187 DisplayDevice.cb = sizeof(DISPLAY_DEVICEA);
188
189 pDirect3D9->NumDisplayAdapters = 0;
190 D3D9_PrimaryDeviceName[0] = '\0';
191
192 AdapterIndex = 0;
193 while ((EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) != FALSE) &&
194 pDirect3D9->NumDisplayAdapters < D3D9_INT_MAX_NUM_ADAPTERS)
195 {
198 {
199 SetAdapterInfo(&pDirect3D9->DisplayAdapters[pDirect3D9->NumDisplayAdapters], &DisplayDevice);
200
201 if (pDirect3D9->NumDisplayAdapters == 0)
203
204 ++pDirect3D9->NumDisplayAdapters;
205 break;
206 }
207
208 ++AdapterIndex;
209 }
210
211 AdapterIndex = 0;
212 while ((EnumDisplayDevicesA(NULL, AdapterIndex, &DisplayDevice, 0) != FALSE) &&
213 pDirect3D9->NumDisplayAdapters < D3D9_INT_MAX_NUM_ADAPTERS)
214 {
215 if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0 &&
217 {
218 SetAdapterInfo(&pDirect3D9->DisplayAdapters[pDirect3D9->NumDisplayAdapters], &DisplayDevice);
219 ++pDirect3D9->NumDisplayAdapters;
220 }
221
222 ++AdapterIndex;
223 }
224
225 /* Check if minimum DirectDraw is supported */
227 return FALSE;
228
229 for (AdapterIndex = 0; AdapterIndex < pDirect3D9->NumDisplayAdapters; AdapterIndex++)
230 {
231 GetDirect3D9AdapterInfo(pDirect3D9->DisplayAdapters, AdapterIndex);
232 }
233
234 return TRUE;
235}
#define D3D9_INT_MAX_NUM_ADAPTERS
Definition: d3d9_private.h:15
static CHAR D3D9_PrimaryDeviceName[CCHDEVICENAME]
Definition: d3d9_create.c:19
static BOOL IsDirectDrawSupported()
Definition: d3d9_create.c:21
static VOID SetAdapterInfo(IN OUT LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapter, IN LPDISPLAY_DEVICEA pDisplayDevice)
Definition: d3d9_create.c:38
static BOOL GetDirect3D9AdapterInfo(IN OUT LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapters, IN DWORD AdapterIndex)
Definition: d3d9_create.c:156
#define memset(x, y, z)
Definition: compat.h:39
DWORD StateFlags
Definition: wingdi.h:2812
CHAR DeviceName[32]
Definition: wingdi.h:2810
BOOL WINAPI EnumDisplayDevicesA(LPCSTR lpDevice, DWORD iDevNum, PDISPLAY_DEVICEA lpDisplayDevice, DWORD dwFlags)
Definition: display.c:23
#define DISPLAY_DEVICE_MIRRORING_DRIVER
Definition: wingdi.h:1399
#define DISPLAY_DEVICE_PRIMARY_DEVICE
Definition: wingdi.h:1398
#define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
Definition: wingdi.h:1396
struct _DISPLAY_DEVICEA DISPLAY_DEVICEA
#define DISPLAY_DEVICE_DISCONNECT
Definition: wingdi.h:1402

Referenced by CreateD3D9().

◆ IsDirectDrawSupported()

static BOOL IsDirectDrawSupported ( )
static

Definition at line 21 of file d3d9_create.c.

22{
23 HDC hDC;
24 DWORD Planes;
25 DWORD Bpp;
26
27 hDC = GetDC(NULL);
28 Planes = GetDeviceCaps(hDC, PLANES);
31
32 if (Planes * Bpp < 8)
33 return FALSE;
34
35 return TRUE;
36}
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define PLANES
Definition: wingdi.h:721
#define BITSPIXEL
Definition: wingdi.h:720
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by GetDisplayDeviceInfo().

◆ IsGDIDriver()

static BOOL IsGDIDriver ( HDC  hDC)
static

Definition at line 48 of file d3d9_create.c.

49{
50 COLORREF NearestBlack = GetNearestColor(hDC, RGB(0, 0, 0));
51 COLORREF NearestWhite = GetNearestColor(hDC, RGB(255, 255, 255));
52
53 if (NearestBlack != RGB(0, 0, 0) || NearestWhite != RGB(255, 255, 255))
54 return TRUE;
55
56 return FALSE;
57}
#define RGB(r, g, b)
Definition: precomp.h:71
DWORD COLORREF
Definition: windef.h:300
COLORREF WINAPI GetNearestColor(_In_ HDC, _In_ COLORREF)

Referenced by CreateD3D9DeviceData().

◆ SetAdapterInfo()

static VOID SetAdapterInfo ( IN OUT LPDIRECT3D9_DISPLAYADAPTER  pDisplayAdapter,
IN LPDISPLAY_DEVICEA  pDisplayDevice 
)
static

Definition at line 38 of file d3d9_create.c.

39{
40 memcpy(&pDisplayAdapter->DisplayGuid, &DISPLAY_GUID, sizeof(GUID));
41
42 lstrcpynA(pDisplayAdapter->szDeviceName, pDisplayDevice->DeviceName, MAX_PATH);
43
44 pDisplayAdapter->dwStateFlags = pDisplayDevice->StateFlags;
45 pDisplayAdapter->bInUseFlag = TRUE;
46}
static const GUID DISPLAY_GUID
Definition: d3d9_create.c:17
#define MAX_PATH
Definition: compat.h:34

Referenced by GetDisplayDeviceInfo().

Variable Documentation

◆ D3D9_PrimaryDeviceName

CHAR D3D9_PrimaryDeviceName[CCHDEVICENAME]
static

Definition at line 19 of file d3d9_create.c.

Referenced by GetDisplayDeviceInfo().

◆ DISPLAY_GUID

const GUID DISPLAY_GUID = { 0x67685559, 0x3106, 0x11D0, { 0xB9, 0x71, 0x00, 0xAA, 0x00, 0x34, 0x2F, 0x9F } }
static

Definition at line 17 of file d3d9_create.c.

Referenced by SetAdapterInfo().