ReactOS  0.4.13-dev-247-g0f29b3f
d3d9_swapchain.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/d3d9_swapchain.c
5  * PURPOSE: Direct3D9's swap chain object
6  * PROGRAMERS: Gregor Gullwi <gbrunmar (dot) ros (at) gmail (dot) com>
7  */
8 #include "d3d9_swapchain.h"
9 
10 #include <debug.h>
11 #include <ddraw.h>
12 
13 #include "d3d9_helpers.h"
14 #include "d3d9_device.h"
15 #include "d3d9_cursor.h"
16 
17 #define LOCK_D3DDEVICE9() D3D9BaseObject_LockDevice(&This->BaseObject)
18 #define UNLOCK_D3DDEVICE9() D3D9BaseObject_UnlockDevice(&This->BaseObject)
19 
20 /* Convert a IDirect3DSwapChain9 pointer safely to the internal implementation struct */
22 {
23  if (NULL == iface)
24  return NULL;
25 
27 }
28 
29 /* IDirect3DSwapChain9: IUnknown implementation */
31 {
33 
34  if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDirect3DSwapChain9))
35  {
36  IUnknown_AddRef(iface);
37  *ppvObject = &This->lpVtbl;
38  return S_OK;
39  }
40 
41  *ppvObject = NULL;
42  return E_NOINTERFACE;
43 }
44 
46 {
48  return D3D9BaseObject_AddRef((D3D9BaseObject*) &This->BaseObject.lpVtbl);
49 }
50 
52 {
54  return D3D9BaseObject_Release((D3D9BaseObject*) &This->BaseObject.lpVtbl);
55 }
56 
57 /* IDirect3DSwapChain9 interface */
58 static HRESULT WINAPI Direct3DSwapChain9_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion,DWORD dwFlags)
59 {
61  return D3D_OK;
62 }
63 
64 static HRESULT WINAPI Direct3DSwapChain9_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface)
65 {
67  return D3D_OK;
68 }
69 
70 static HRESULT WINAPI Direct3DSwapChain9_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer)
71 {
73  return D3D_OK;
74 }
75 
77 {
79  return D3D_OK;
80 }
81 
83 {
85  return D3D_OK;
86 }
87 
88 /*++
89 * @name IDirect3DSwapChain9::GetDevice
90 * @implemented
91 *
92 * The function Direct3DSwapChain9_GetDevice sets the ppDevice argument
93 * to the device connected to create the swap chain.
94 *
95 * @param LPDIRECT3DSWAPCHAIN9 iface
96 * Pointer to a IDirect3DSwapChain9 object returned from IDirect3D9Device::GetSwapChain()
97 *
98 * @param IDirect3DDevice9** ppDevice
99 * Pointer to a IDirect3DDevice9* structure to be set to the device object.
100 *
101 * @return HRESULT
102 * If the method successfully sets the ppDevice value, the return value is D3D_OK.
103 * If ppDevice is a bad pointer the return value will be D3DERR_INVALIDCALL.
104 * If the swap chain didn't contain any device, the return value will be D3DERR_INVALIDDEVICE.
105 *
106 */
107 static HRESULT WINAPI Direct3DSwapChain9_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice)
108 {
110  LOCK_D3DDEVICE9();
111 
112  if (NULL == ppDevice)
113  {
114  DPRINT1("Invalid ppDevice parameter specified");
116  return D3DERR_INVALIDCALL;
117  }
118 
119  if (FAILED(D3D9BaseObject_GetDevice(&This->BaseObject, ppDevice)))
120  {
121  DPRINT1("Invalid This parameter specified");
123  return D3DERR_INVALIDDEVICE;
124  }
125 
127  return D3D_OK;
128 }
129 
130 /*++
131 * @name IDirect3DSwapChain9::GetPresentParameters
132 * @implemented
133 *
134 * The function Direct3DSwapChain9_GetPresentParameters fills the pPresentationParameters
135 * argument with the D3DPRESENT_PARAMETERS parameters that was used to create the swap chain.
136 *
137 * @param LPDIRECT3DSWAPCHAIN9 iface
138 * Pointer to a IDirect3DSwapChain9 object returned from IDirect3D9Device::GetSwapChain()
139 *
140 * @param D3DPRESENT_PARAMETERS* pPresentationParameters
141 * Pointer to a D3DPRESENT_PARAMETERS structure to be filled with the creation parameters.
142 *
143 * @return HRESULT
144 * If the method successfully fills the pPresentationParameters structure, the return value is D3D_OK.
145 * If pPresentationParameters is a bad pointer the return value will be D3DERR_INVALIDCALL.
146 *
147 */
149 {
151  LOCK_D3DDEVICE9();
152 
153  if (NULL == pPresentationParameters)
154  {
155  DPRINT1("Invalid pPresentationParameters parameter specified");
157  return D3DERR_INVALIDCALL;
158  }
159 
160  *pPresentationParameters = This->PresentParameters;
161 
163  return D3D_OK;
164 }
165 
166 static IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
167 {
168  /* IUnknown */
172 
173  /* IDirect3DSwapChain9 */
181 };
182 
184 {
185  Direct3DSwapChain9_INT* pThisSwapChain;
186  if (FAILED(AlignedAlloc((LPVOID*)&pThisSwapChain, sizeof(Direct3DSwapChain9_INT))))
187  {
188  DPRINT1("Could not create Direct3DSwapChain9_INT");
189  return NULL;
190  }
191 
192  InitD3D9BaseObject((D3D9BaseObject*) &pThisSwapChain->BaseObject.lpVtbl, RefType, (IUnknown*) &pBaseDevice->lpVtbl);
193 
194  pThisSwapChain->lpVtbl = &Direct3DSwapChain9_Vtbl;
195 
196  pThisSwapChain->ChainIndex = ChainIndex;
197  pThisSwapChain->AdapterGroupIndex = ChainIndex;
198  pThisSwapChain->pUnknown6BC = pBaseDevice->DeviceData[ChainIndex].pUnknown6BC;
199  pThisSwapChain->pUnknown015c = (LPVOID)0xD3D9D3D9;
200 
201  return pThisSwapChain;
202 }
203 
205 {
206  pThisSwapChain->dwWidth = pPresentationParameters->BackBufferWidth;
207  pThisSwapChain->dwHeight = pPresentationParameters->BackBufferHeight;
208 }
209 
211 {
212  int i;
213  DIRECT3DDEVICE9_INT* pDevice;
214 
215  for (i = 0; i < 256; i++)
216  {
217  pThisSwapChain->GammaRamp.red[i] =
218  pThisSwapChain->GammaRamp.green[i] =
219  pThisSwapChain->GammaRamp.blue[i] = i;
220  }
221 
222  pThisSwapChain->PresentParameters = pPresentationParameters[pThisSwapChain->ChainIndex];
223  pThisSwapChain->SwapEffect = pPresentationParameters->SwapEffect;
224  Direct3DSwapChain9_SetDisplayMode(pThisSwapChain, &pThisSwapChain->PresentParameters);
225 
226  if (FAILED(D3D9BaseObject_GetDeviceInt(&pThisSwapChain->BaseObject, &pDevice)))
227  {
228  DPRINT1("Could not get the swapchain device");
229  return DDERR_GENERIC;
230  }
231 
232  pThisSwapChain->pCursor = CreateD3D9Cursor(pDevice, pThisSwapChain);
233  if (NULL == pThisSwapChain->pCursor)
234  {
235  DPRINT1("Could not allocate D3D9Cursor");
236  return DDERR_OUTOFMEMORY;
237  }
238 
239  return Direct3DSwapChain9_Reset(pThisSwapChain, pPresentationParameters);
240 }
241 
243 {
244  // TODO: Do all the dirty work...
245  return D3D_OK;
246 }
247 
249 {
250  memcpy(pRamp, &pThisSwapChain->GammaRamp, sizeof(D3DGAMMARAMP));
251 }
252 
254 {
256 }
static HRESULT WINAPI Direct3DSwapChain9_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags)
ULONG D3D9BaseObject_AddRef(D3D9BaseObject *pBaseObject)
HRESULT Direct3DSwapChain9_Init(Direct3DSwapChain9_INT *pThisSwapChain, D3DPRESENT_PARAMETERS *pPresentationParameters)
#define REFIID
Definition: guiddef.h:113
D3D9Cursor * CreateD3D9Cursor(struct _Direct3DDevice9_INT *pBaseDevice, struct _Direct3DSwapChain9_INT *pSwapChain)
Definition: d3d9_cursor.c:18
#define E_NOINTERFACE
Definition: winerror.h:2364
Type
Definition: Type.h:6
WORD red[256]
Definition: d3d8types.h:1046
LPDIRECT3DSWAPCHAIN9_INT IDirect3DSwapChain9ToImpl(LPDIRECT3DSWAPCHAIN9 iface)
#define LOCK_D3DDEVICE9()
REFIID riid
Definition: precomp.h:44
struct _IDirect3DDevice9Vtbl_INT * lpVtbl
Definition: d3d9_device.h:88
static HRESULT WINAPI Direct3DSwapChain9_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9 *pDestSurface)
#define D3DERR_INVALIDCALL
WORD blue[256]
Definition: d3d8types.h:1048
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
HRESULT D3D9BaseObject_GetDeviceInt(D3D9BaseObject *pBaseObject, DIRECT3DDEVICE9_INT **ppDevice)
ULONG D3D9BaseObject_Release(D3D9BaseObject *pBaseObject)
#define D3DERR_INVALIDDEVICE
Definition: d3d8.h:86
HRESULT Direct3DSwapChain9_Reset(Direct3DSwapChain9_INT *pThisSwapChain, D3DPRESENT_PARAMETERS *pPresentationParameters)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
VOID Direct3DSwapChain9_SetDisplayMode(Direct3DSwapChain9_INT *pThisSwapChain, D3DPRESENT_PARAMETERS *pPresentationParameters)
struct _D3D9Cursor * pCursor
HRESULT D3D9BaseObject_GetDevice(D3D9BaseObject *pBaseObject, IDirect3DDevice9 **ppDevice)
D3D9BaseObject BaseObject
smooth NULL
Definition: ftsmooth.c:416
HRESULT AlignedAlloc(IN OUT LPVOID *ppObject, IN SIZE_T dwSize)
Definition: d3d9_helpers.c:95
#define DDERR_GENERIC
Definition: ddraw.h:72
D3DPRESENT_PARAMETERS PresentParameters
LONG HRESULT
Definition: typedefs.h:77
D3DSWAPEFFECT SwapEffect
const GUID IID_IUnknown
struct IDirect3DSwapChain9 * LPDIRECT3DSWAPCHAIN9
Definition: d3d9.h:145
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
static IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl
#define LPVOID
Definition: nt_native.h:45
static HRESULT WINAPI Direct3DSwapChain9_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, void **ppvObject)
REF_TYPE
#define UNLOCK_D3DDEVICE9()
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static HRESULT WINAPI Direct3DSwapChain9_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS *pRasterStatus)
REFIID LPVOID * ppvObject
Definition: precomp.h:44
VOID Direct3DSwapChain9_GetGammaRamp(Direct3DSwapChain9_INT *pThisSwapChain, D3DGAMMARAMP *pRamp)
WORD green[256]
Definition: d3d8types.h:1047
D3D9_DEVICEDATA DeviceData[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_device.h:121
static HRESULT WINAPI Direct3DSwapChain9_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE *pMode)
static ULONG WINAPI Direct3DSwapChain9_Release(LPDIRECT3DSWAPCHAIN9 iface)
#define S_OK
Definition: intsafe.h:59
#define D3D_OK
Definition: d3d.h:106
static ULONG WINAPI Direct3DSwapChain9_AddRef(LPDIRECT3DSWAPCHAIN9 iface)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
VOID Direct3DSwapChain9_SetGammaRamp(Direct3DSwapChain9_INT *pThisSwapChain, DWORD Flags, CONST D3DGAMMARAMP *pRamp)
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
#define DPRINT1
Definition: precomp.h:8
Direct3DSwapChain9_INT * CreateDirect3DSwapChain9(enum REF_TYPE RefType, struct _Direct3DDevice9_INT *pBaseDevice, DWORD ChainIndex)
static HRESULT WINAPI Direct3DSwapChain9_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9 **ppDevice)
VOID InitD3D9BaseObject(D3D9BaseObject *pBaseObject, enum REF_TYPE RefType, IUnknown *pUnknown)
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
static HRESULT WINAPI Direct3DSwapChain9_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
#define ULONG_PTR
Definition: config.h:101
enum _D3DBACKBUFFER_TYPE D3DBACKBUFFER_TYPE
#define CONST
Definition: pedump.c:81
struct _D3D9_Unknown6BC * pUnknown6BC
Definition: d3d9_private.h:142
D3DSWAPEFFECT SwapEffect
Definition: d3d8types.h:1128
static HRESULT WINAPI Direct3DSwapChain9_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS *pPresentationParameters)