ReactOS 0.4.15-dev-8219-ge8b88cf
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 */
58static 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
64static HRESULT WINAPI Direct3DSwapChain9_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface)
65{
67 return D3D_OK;
68}
69
70static 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*/
107static HRESULT WINAPI Direct3DSwapChain9_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice)
108{
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");
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{
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
166static 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;
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}
Type
Definition: Type.h:7
#define DPRINT1
Definition: precomp.h:8
const GUID IID_IUnknown
#define UNIMPLEMENTED
Definition: debug.h:118
enum _D3DBACKBUFFER_TYPE D3DBACKBUFFER_TYPE
struct IDirect3DSwapChain9 * LPDIRECT3DSWAPCHAIN9
Definition: d3d9.h:145
HRESULT D3D9BaseObject_GetDevice(D3D9BaseObject *pBaseObject, IDirect3DDevice9 **ppDevice)
ULONG D3D9BaseObject_Release(D3D9BaseObject *pBaseObject)
ULONG D3D9BaseObject_AddRef(D3D9BaseObject *pBaseObject)
VOID InitD3D9BaseObject(D3D9BaseObject *pBaseObject, enum REF_TYPE RefType, IUnknown *pUnknown)
HRESULT D3D9BaseObject_GetDeviceInt(D3D9BaseObject *pBaseObject, DIRECT3DDEVICE9_INT **ppDevice)
REF_TYPE
D3D9Cursor * CreateD3D9Cursor(struct _Direct3DDevice9_INT *pBaseDevice, struct _Direct3DSwapChain9_INT *pSwapChain)
Definition: d3d9_cursor.c:18
HRESULT AlignedAlloc(IN OUT LPVOID *ppObject, IN SIZE_T dwSize)
Definition: d3d9_helpers.c:95
static ULONG WINAPI Direct3DSwapChain9_AddRef(LPDIRECT3DSWAPCHAIN9 iface)
static HRESULT WINAPI Direct3DSwapChain9_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS *pRasterStatus)
static HRESULT WINAPI Direct3DSwapChain9_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9 *pDestSurface)
static HRESULT WINAPI Direct3DSwapChain9_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS *pPresentationParameters)
static HRESULT WINAPI Direct3DSwapChain9_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE *pMode)
VOID Direct3DSwapChain9_SetDisplayMode(Direct3DSwapChain9_INT *pThisSwapChain, D3DPRESENT_PARAMETERS *pPresentationParameters)
#define UNLOCK_D3DDEVICE9()
HRESULT Direct3DSwapChain9_Reset(Direct3DSwapChain9_INT *pThisSwapChain, D3DPRESENT_PARAMETERS *pPresentationParameters)
VOID Direct3DSwapChain9_SetGammaRamp(Direct3DSwapChain9_INT *pThisSwapChain, DWORD Flags, CONST D3DGAMMARAMP *pRamp)
#define LOCK_D3DDEVICE9()
static ULONG WINAPI Direct3DSwapChain9_Release(LPDIRECT3DSWAPCHAIN9 iface)
static HRESULT WINAPI Direct3DSwapChain9_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9 **ppBackBuffer)
static HRESULT WINAPI Direct3DSwapChain9_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, void **ppvObject)
static HRESULT WINAPI Direct3DSwapChain9_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9 **ppDevice)
static HRESULT WINAPI Direct3DSwapChain9_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags)
LPDIRECT3DSWAPCHAIN9_INT IDirect3DSwapChain9ToImpl(LPDIRECT3DSWAPCHAIN9 iface)
static IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl
Direct3DSwapChain9_INT * CreateDirect3DSwapChain9(enum REF_TYPE RefType, struct _Direct3DDevice9_INT *pBaseDevice, DWORD ChainIndex)
HRESULT Direct3DSwapChain9_Init(Direct3DSwapChain9_INT *pThisSwapChain, D3DPRESENT_PARAMETERS *pPresentationParameters)
VOID Direct3DSwapChain9_GetGammaRamp(Direct3DSwapChain9_INT *pThisSwapChain, D3DGAMMARAMP *pRamp)
#define D3D_OK
Definition: d3d.h:106
#define D3DERR_INVALIDCALL
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
unsigned long DWORD
Definition: ntddk_ex.h:95
FxDevice * pDevice
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
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int UINT
Definition: ndis.h:50
#define LPVOID
Definition: nt_native.h:45
#define CONST
Definition: pedump.c:81
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define D3DERR_INVALIDDEVICE
Definition: d3d8.h:86
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DDERR_GENERIC
Definition: ddraw.h:72
ID3D9BaseObjectVtbl * lpVtbl
struct _D3D9_Unknown6BC * pUnknown6BC
Definition: d3d9_private.h:142
WORD blue[256]
Definition: d3d8types.h:1048
WORD green[256]
Definition: d3d8types.h:1047
WORD red[256]
Definition: d3d8types.h:1046
D3DSWAPEFFECT SwapEffect
Definition: d3d8types.h:1128
D3D9_DEVICEDATA DeviceData[D3D9_INT_MAX_NUM_ADAPTERS]
Definition: d3d9_device.h:121
struct _IDirect3DDevice9Vtbl_INT * lpVtbl
Definition: d3d9_device.h:88
struct _D3D9_Unknown6BC * pUnknown6BC
D3DPRESENT_PARAMETERS PresentParameters
struct IDirect3DSwapChain9Vtbl * lpVtbl
struct _D3D9Cursor * pCursor
D3DSWAPEFFECT SwapEffect
D3D9BaseObject BaseObject
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG
Definition: typedefs.h:59
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170