ReactOS 0.4.15-dev-7918-g2a2556c
device.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS ReactX
4 * FILE: dll/directx/d3d9/device.c
5 * PURPOSE: Direct3D9's device creation
6 * PROGRAMERS: Gregor Gullwi <gbrunmar (dot) ros (at) gmail (dot) com>
7 */
8
9#include "device.h"
10#include <debug.h>
11#include "d3d9_helpers.h"
12#include "d3d9_create.h"
13
14static HRESULT InitD3D9ResourceManager(D3D9ResourceManager* pThisResourceManager, LPDIRECT3DDEVICE9_INT pDirect3DDevice9)
15{
16 DWORD MaxSimultaneousTextures;
17
18 MaxSimultaneousTextures = max(1, pDirect3DDevice9->DeviceData[0].DriverCaps.DriverCaps9.MaxSimultaneousTextures);
19
20 if (FAILED(AlignedAlloc((LPVOID *)&pThisResourceManager->pTextureHeap, sizeof(DWORD) + MaxSimultaneousTextures * sizeof(int) * 3)))
21 {
22 DPRINT1("Could not allocate texture heap");
23 return DDERR_OUTOFMEMORY;
24 }
25
26 // TODO: Init texture heap
27
28 pThisResourceManager->MaxSimultaneousTextures = MaxSimultaneousTextures;
29 pThisResourceManager->pBaseDevice = pDirect3DDevice9;
30
31 return D3D_OK;
32}
33
35 UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviourFlags,
36 D3DPRESENT_PARAMETERS* pPresentationParameters, DWORD NumAdaptersToCreate)
37{
38 D3D9ResourceManager* pResourceManager;
39 DWORD i;
40
41 // Insert Reset/Ctor here
42
43 if (FAILED(AlignedAlloc((LPVOID *)&pResourceManager, sizeof(D3D9ResourceManager))) ||
44 FAILED(InitD3D9ResourceManager(pResourceManager, pThisBaseDevice)))
45 {
46 DPRINT1("Could not create resource manager");
47 return DDERR_OUTOFMEMORY;
48 }
49
50 pThisBaseDevice->pResourceManager = pResourceManager;
51
52 pThisBaseDevice->lpVtbl = &Direct3DDevice9HAL_Vtbl;
53 pThisBaseDevice->lRefCnt = 1;
54 pThisBaseDevice->dwProcessId = GetCurrentThreadId();
55 pThisBaseDevice->pUnknown = (IUnknown*) &pThisBaseDevice->lpVtbl;
57
58 pThisBaseDevice->pDirect3D9 = pDirect3D9;
59 pThisBaseDevice->DeviceType = DeviceType;
60 pThisBaseDevice->hWnd = hFocusWindow;
61 pThisBaseDevice->AdjustedBehaviourFlags = BehaviourFlags;
62 pThisBaseDevice->BehaviourFlags = BehaviourFlags;
63 pThisBaseDevice->NumAdaptersInDevice = NumAdaptersToCreate;
64
65 // TODO: Query driver for correct DX version
66 pThisBaseDevice->dwDXVersion = 9;
67
68 for (i = 0; i < NumAdaptersToCreate; i++)
69 {
70 if (FALSE == CreateD3D9DeviceData(&pDirect3D9->DisplayAdapters[i], &pThisBaseDevice->DeviceData[i]))
71 {
72 DPRINT1("Failed to get device data for adapter: %d", i);
73 return DDERR_GENERIC;
74 }
75
76 pThisBaseDevice->AdapterIndexInGroup[i] = i;
77 pThisBaseDevice->CurrentDisplayMode[i].Width = pDirect3D9->DisplayAdapters[i].DriverCaps.dwDisplayWidth;
78 pThisBaseDevice->CurrentDisplayMode[i].Height = pDirect3D9->DisplayAdapters[i].DriverCaps.dwDisplayHeight;
81
82 pThisBaseDevice->pSwapChains[i] = CreateDirect3DSwapChain9(RT_BUILTIN, pThisBaseDevice, i);
83 pThisBaseDevice->pSwapChains2[i] = pThisBaseDevice->pSwapChains[i];
84
85 if (FAILED(Direct3DSwapChain9_Init(pThisBaseDevice->pSwapChains[i], pPresentationParameters)))
86 {
87 DPRINT1("Failed to init swap chain: %d", i);
88 return DDERR_GENERIC;
89 }
90 }
91
92 return D3D_OK;
93}
94
96 HWND hFocusWindow, DWORD BehaviourFlags,
97 D3DPRESENT_PARAMETERS* pPresentationParameters,
98 DWORD NumAdaptersToCreate,
99 struct IDirect3DDevice9** ppReturnedDeviceInterface)
100{
101 HRESULT Ret;
102
103 if (FAILED(AlignedAlloc((LPVOID *)ppReturnedDeviceInterface, sizeof(D3D9HALDEVICE))))
104 {
105 DPRINT1("Not enough memory to create HAL device");
106 return DDERR_OUTOFMEMORY;
107 }
108
109 Ret = InitD3D9BaseDevice((LPDIRECT3DDEVICE9_INT)*ppReturnedDeviceInterface, pDirect3D9, Adapter,
110 D3DDEVTYPE_HAL, hFocusWindow, BehaviourFlags,
111 pPresentationParameters, NumAdaptersToCreate);
112
113 if (FAILED(Ret))
114 {
115 AlignedFree((LPVOID)*ppReturnedDeviceInterface);
116 return Ret;
117 }
118
119 return D3D_OK;
120}
#define DPRINT1
Definition: precomp.h:8
enum _D3DDEVTYPE D3DDEVTYPE
@ D3DDEVTYPE_HAL
Definition: d3d8types.h:576
@ RT_BUILTIN
BOOL CreateD3D9DeviceData(IN LPDIRECT3D9_DISPLAYADAPTER pDisplayAdapter, IN LPD3D9_DEVICEDATA pDeviceData)
Definition: d3d9_create.c:115
IDirect3DDevice9Vtbl_INT Direct3DDevice9HAL_Vtbl
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
Direct3DSwapChain9_INT * CreateDirect3DSwapChain9(enum REF_TYPE RefType, struct _Direct3DDevice9_INT *pBaseDevice, DWORD ChainIndex)
HRESULT Direct3DSwapChain9_Init(Direct3DSwapChain9_INT *pThisSwapChain, D3DPRESENT_PARAMETERS *pPresentationParameters)
#define D3D_OK
Definition: d3d.h:106
#define FALSE
Definition: types.h:117
static HRESULT InitD3D9ResourceManager(D3D9ResourceManager *pThisResourceManager, LPDIRECT3DDEVICE9_INT pDirect3DDevice9)
Definition: device.c:14
HRESULT CreateD3D9HalDevice(LPDIRECT3D9_INT pDirect3D9, UINT Adapter, HWND hFocusWindow, DWORD BehaviourFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, DWORD NumAdaptersToCreate, struct IDirect3DDevice9 **ppReturnedDeviceInterface)
Definition: device.c:95
HRESULT InitD3D9BaseDevice(LPDIRECT3DDEVICE9_INT pThisBaseDevice, LPDIRECT3D9_INT pDirect3D9, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviourFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, DWORD NumAdaptersToCreate)
Definition: device.c:34
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FAILED(hr)
Definition: intsafe.h:51
DeviceType
Definition: mmdrv.h:42
unsigned int UINT
Definition: ndis.h:50
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DDERR_GENERIC
Definition: ddraw.h:72
DWORD MaxSimultaneousTextures
Definition: d3d9_device.h:81
struct _Direct3DDevice9_INT * pBaseDevice
Definition: d3d9_device.h:78
D3D9HeapTexture * pTextureHeap
Definition: d3d9_device.h:83
D3D9_DRIVERCAPS DriverCaps
Definition: d3d9_private.h:137
D3DFORMAT RawDisplayFormat
Definition: d3d9_private.h:71
D3DCAPS9 DriverCaps9
Definition: d3d9_private.h:68
DWORD MaxSimultaneousTextures
Definition: d3d9caps.h:302
D3DFORMAT Format
Definition: d3d8types.h:1042
Direct3D9DisplayAdapterInfo DisplayAdapters[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_private.h:176
LPDIRECT3D9_INT pDirect3D9
Definition: d3d9_device.h:130
D3DDISPLAYMODE CurrentDisplayMode[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_device.h:119
LPDIRECT3DSWAPCHAIN9_INT pSwapChains[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_device.h:122
LPDIRECT3DSWAPCHAIN9_INT pSwapChains2[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_device.h:123
DWORD AdapterIndexInGroup[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_device.h:120
D3D9_DEVICEDATA DeviceData[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_device.h:121
CRITICAL_SECTION CriticalSection
Definition: d3d9_device.h:89
D3D9ResourceManager * pResourceManager
Definition: d3d9_device.h:113
struct _IDirect3DDevice9Vtbl_INT * lpVtbl
Definition: d3d9_device.h:88
D3DDEVTYPE DeviceType
Definition: d3d9_device.h:129
#define max(a, b)
Definition: svc.c:63
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459