ReactOS 0.4.16-dev-197-g92996da
swapchain.c
Go to the documentation of this file.
1/*
2 * IDirect3DSwapChain8 implementation
3 *
4 * Copyright 2005 Oliver Stieber
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "config.h"
22#include "d3d8_private.h"
23
25
26static inline struct d3d8_swapchain *impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
27{
29}
30
31static HRESULT WINAPI d3d8_swapchain_QueryInterface(IDirect3DSwapChain8 *iface, REFIID riid, void **out)
32{
33 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
34
35 if (IsEqualGUID(riid, &IID_IDirect3DSwapChain8)
37 {
39 *out = iface;
40 return S_OK;
41 }
42
43 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
44
45 *out = NULL;
46 return E_NOINTERFACE;
47}
48
49static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface)
50{
51 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
53
54 TRACE("%p increasing refcount to %u.\n", iface, ref);
55
56 if (ref == 1)
57 {
58 if (swapchain->parent_device)
63 }
64
65 return ref;
66}
67
68static ULONG WINAPI d3d8_swapchain_Release(IDirect3DSwapChain8 *iface)
69{
70 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
72
73 TRACE("%p decreasing refcount to %u.\n", iface, ref);
74
75 if (!ref)
76 {
77 IDirect3DDevice8 *parent_device = swapchain->parent_device;
78
82
83 if (parent_device)
85 }
86 return ref;
87}
88
89static HRESULT WINAPI DECLSPEC_HOTPATCH d3d8_swapchain_Present(IDirect3DSwapChain8 *iface,
90 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
91 const RGNDATA *dirty_region)
92{
93 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
95 HRESULT hr;
96
97 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
98 iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), dst_window_override, dirty_region);
99
100 if (device->device_state != D3D8_DEVICE_STATE_OK)
101 return D3DERR_DEVICELOST;
102
103 if (dirty_region)
104 FIXME("Ignoring dirty_region %p.\n", dirty_region);
105
108 src_rect, dst_rect, dst_window_override, 0, 0);
110
111 return hr;
112}
113
114static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface,
115 UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
116{
117 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
119 struct d3d8_surface *surface_impl;
120 HRESULT hr = D3D_OK;
121
122 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
123 iface, backbuffer_idx, backbuffer_type, backbuffer);
124
125 /* backbuffer_type is ignored by native. */
126
127 if (!backbuffer)
128 {
129 WARN("The output pointer is NULL, returning D3DERR_INVALIDCALL.\n");
130 return D3DERR_INVALIDCALL;
131 }
132
134 if ((wined3d_texture = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain, backbuffer_idx)))
135 {
137 *backbuffer = &surface_impl->IDirect3DSurface8_iface;
138 IDirect3DSurface8_AddRef(*backbuffer);
139 }
140 else
141 {
142 /* Do not set *backbuffer = NULL, see tests/device.c, test_swapchain(). */
144 }
146
147 return hr;
148}
149
150static const IDirect3DSwapChain8Vtbl d3d8_swapchain_vtbl =
151{
157};
158
160{
162}
163
165{
167};
168
169static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device,
171{
172 HRESULT hr;
173
174 swapchain->refcount = 1;
176
178 hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
181
182 if (FAILED(hr))
183 {
184 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
185 return hr;
186 }
187
188 swapchain->parent_device = &device->IDirect3DDevice8_iface;
190
191 return D3D_OK;
192}
193
195 struct d3d8_swapchain **swapchain)
196{
197 struct d3d8_swapchain *object;
198 HRESULT hr;
199
200 if (!(object = heap_alloc_zero(sizeof(*object))))
201 return E_OUTOFMEMORY;
202
203 if (FAILED(hr = swapchain_init(object, device, desc)))
204 {
205 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
206 heap_free(object);
207 return hr;
208 }
209
210 TRACE("Created swapchain %p.\n", object);
211 *swapchain = object;
212
213 return D3D_OK;
214}
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:240
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
static HRESULT WINAPI d3d8_swapchain_QueryInterface(IDirect3DSwapChain8 *iface, REFIID riid, void **out)
Definition: swapchain.c:31
static void STDMETHODCALLTYPE d3d8_swapchain_wined3d_object_released(void *parent)
Definition: swapchain.c:159
HRESULT d3d8_swapchain_create(struct d3d8_device *device, struct wined3d_swapchain_desc *desc, struct d3d8_swapchain **swapchain)
Definition: swapchain.c:194
static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device, struct wined3d_swapchain_desc *desc)
Definition: swapchain.c:169
static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops
Definition: swapchain.c:164
static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface)
Definition: swapchain.c:49
static ULONG WINAPI d3d8_swapchain_Release(IDirect3DSwapChain8 *iface)
Definition: swapchain.c:68
static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface, UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
Definition: swapchain.c:114
static HRESULT WINAPI DECLSPEC_HOTPATCH d3d8_swapchain_Present(IDirect3DSwapChain8 *iface, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region)
Definition: swapchain.c:89
static struct d3d8_swapchain * impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
Definition: swapchain.c:26
static const IDirect3DSwapChain8Vtbl d3d8_swapchain_vtbl
Definition: swapchain.c:150
@ D3D8_DEVICE_STATE_OK
Definition: d3d8_private.h:93
static struct d3d8_device * impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
Definition: d3d8_private.h:132
enum _D3DBACKBUFFER_TYPE D3DBACKBUFFER_TYPE
#define D3D_OK
Definition: d3d.h:106
#define D3DERR_INVALIDCALL
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
void *CDECL wined3d_texture_get_sub_resource_parent(struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: texture.c:3449
r parent
Definition: btrfs.c:3010
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
static const WCHAR desc[]
Definition: protectdata.c:36
unsigned int UINT
Definition: ndis.h:50
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
static FILE * out
Definition: regtests2xml.c:44
#define IDirect3DSwapChain8_AddRef(p)
Definition: d3d8.h:269
#define IDirect3DSurface8_AddRef(p)
Definition: d3d8.h:309
#define D3DERR_DEVICELOST
Definition: d3d8.h:82
#define IDirect3DDevice8_AddRef(p)
Definition: d3d8.h:947
#define IDirect3DDevice8_Release(p)
Definition: d3d8.h:948
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
IDirect3DSurface8 IDirect3DSurface8_iface
Definition: d3d8_private.h:176
IDirect3DSwapChain8 IDirect3DSwapChain8_iface
Definition: d3d8_private.h:165
struct wined3d_swapchain * wined3d_swapchain
Definition: d3d8_private.h:167
IDirect3DDevice8 * parent_device
Definition: d3d8_private.h:168
Definition: devices.h:37
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
struct wined3d_texture *CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain, UINT back_buffer_idx)
Definition: swapchain.c:215
HRESULT CDECL wined3d_swapchain_present(struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, DWORD swap_interval, DWORD flags)
Definition: swapchain.c:152
ULONG CDECL wined3d_swapchain_decref(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:113
ULONG CDECL wined3d_swapchain_incref(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:104
HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device, struct wined3d_swapchain_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain)
Definition: swapchain.c:1023
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:373
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:368
#define E_NOINTERFACE
Definition: winerror.h:2364