ReactOS 0.4.17-dev-966-gf06eace
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 "d3d8_private.h"
22
24
25static inline struct d3d8_swapchain *impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
26{
28}
29
30static HRESULT WINAPI d3d8_swapchain_QueryInterface(IDirect3DSwapChain8 *iface, REFIID riid, void **out)
31{
32 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
33
34 if (IsEqualGUID(riid, &IID_IDirect3DSwapChain8)
36 {
38 *out = iface;
39 return S_OK;
40 }
41
42 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
43
44 *out = NULL;
45 return E_NOINTERFACE;
46}
47
48static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface)
49{
50 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
52
53 TRACE("%p increasing refcount to %lu.\n", iface, ref);
54
55 if (ref == 1)
56 {
57 if (swapchain->parent_device)
60 }
61
62 return ref;
63}
64
65static ULONG WINAPI d3d8_swapchain_Release(IDirect3DSwapChain8 *iface)
66{
67 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
69
70 TRACE("%p decreasing refcount to %lu.\n", iface, ref);
71
72 if (!ref)
73 {
74 IDirect3DDevice8 *parent_device = swapchain->parent_device;
75
77
78 if (parent_device)
80 }
81 return ref;
82}
83
84static HRESULT WINAPI DECLSPEC_HOTPATCH d3d8_swapchain_Present(IDirect3DSwapChain8 *iface,
85 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
86 const RGNDATA *dirty_region)
87{
88 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
90
91 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
92 iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), dst_window_override, dirty_region);
93
94 if (device->device_state != D3D8_DEVICE_STATE_OK)
95 return D3DERR_DEVICELOST;
96
97 if (dirty_region)
98 FIXME("Ignoring dirty_region %p.\n", dirty_region);
99
101 src_rect, dst_rect, dst_window_override, swapchain->swap_interval, 0);
102}
103
104static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface,
105 UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
106{
107 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
109 struct d3d8_surface *surface_impl;
110 HRESULT hr = D3D_OK;
111
112 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
113 iface, backbuffer_idx, backbuffer_type, backbuffer);
114
115 /* backbuffer_type is ignored by native. */
116
117 if (!backbuffer)
118 {
119 WARN("The output pointer is NULL, returning D3DERR_INVALIDCALL.\n");
120 return D3DERR_INVALIDCALL;
121 }
122
124 if ((wined3d_texture = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain, backbuffer_idx)))
125 {
127 *backbuffer = &surface_impl->IDirect3DSurface8_iface;
128 IDirect3DSurface8_AddRef(*backbuffer);
129 }
130 else
131 {
132 /* Do not set *backbuffer = NULL, see tests/device.c, test_swapchain(). */
134 }
136
137 return hr;
138}
139
140static const IDirect3DSwapChain8Vtbl d3d8_swapchain_vtbl =
141{
147};
148
150{
151 free(parent);
152}
153
155{
157};
158
160 BOOL windowed)
161{
162 TRACE("parent %p, windowed %d.\n", parent, windowed);
163}
164
166{
168};
169
170static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device,
171 struct wined3d_swapchain_desc *desc, unsigned int swap_interval)
172{
173 HRESULT hr;
174
175 swapchain->refcount = 1;
178 swapchain->swap_interval = swap_interval;
179
180 if (FAILED(hr = wined3d_swapchain_create(device->wined3d_device, desc, &swapchain->state_parent,
181 swapchain, &d3d8_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain)))
182 {
183 WARN("Failed to create wined3d swapchain, hr %#lx.\n", hr);
184 return hr;
185 }
186
187 swapchain->parent_device = &device->IDirect3DDevice8_iface;
189
190 return D3D_OK;
191}
192
194 unsigned int swap_interval, struct d3d8_swapchain **swapchain)
195{
196 struct wined3d_rendertarget_view *wined3d_dsv;
197 struct d3d8_swapchain *object;
198 struct d3d8_surface *surface;
199 unsigned int i;
200 HRESULT hr;
201
202 if (!(object = calloc(1, sizeof(*object))))
203 return E_OUTOFMEMORY;
204
205 if (FAILED(hr = swapchain_init(object, device, desc, swap_interval)))
206 {
207 WARN("Failed to initialize swapchain, hr %#lx.\n", hr);
208 free(object);
209 return hr;
210 }
211
212 for (i = 0; i < desc->backbuffer_count; ++i)
213 {
214 if (!(surface = d3d8_surface_create(wined3d_swapchain_get_back_buffer(object->wined3d_swapchain, i), 0,
215 (IUnknown *)&device->IDirect3DDevice8_iface)))
216 {
217 IDirect3DSwapChain8_Release(&object->IDirect3DSwapChain8_iface);
218 return E_OUTOFMEMORY;
219 }
220 surface->parent_device = &device->IDirect3DDevice8_iface;
221 }
222
223 if ((desc->flags & WINED3D_SWAPCHAIN_IMPLICIT)
224 && (wined3d_dsv = wined3d_device_context_get_depth_stencil_view(device->immediate_context)))
225 {
227
229 (IUnknown *)&device->IDirect3DDevice8_iface)))
230 {
231 IDirect3DSwapChain8_Release(&object->IDirect3DSwapChain8_iface);
232 return E_OUTOFMEMORY;
233 }
234 surface->parent_device = &device->IDirect3DDevice8_iface;
235 }
236
237 TRACE("Created swapchain %p.\n", object);
238 *swapchain = object;
239
240 return D3D_OK;
241}
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:240
#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
#define D3DERR_INVALIDCALL
Definition: d3d10_private.h:42
static HRESULT WINAPI d3d8_swapchain_QueryInterface(IDirect3DSwapChain8 *iface, REFIID riid, void **out)
Definition: swapchain.c:30
static const struct wined3d_swapchain_state_parent_ops d3d8_swapchain_state_parent_ops
Definition: swapchain.c:165
static void STDMETHODCALLTYPE d3d8_swapchain_wined3d_object_released(void *parent)
Definition: swapchain.c:149
static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops
Definition: swapchain.c:154
static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface)
Definition: swapchain.c:48
static ULONG WINAPI d3d8_swapchain_Release(IDirect3DSwapChain8 *iface)
Definition: swapchain.c:65
static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface, UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
Definition: swapchain.c:104
static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device, struct wined3d_swapchain_desc *desc, unsigned int swap_interval)
Definition: swapchain.c:170
static void CDECL d3d8_swapchain_windowed_state_changed(struct wined3d_swapchain_state_parent *parent, BOOL windowed)
Definition: swapchain.c:159
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:84
static struct d3d8_swapchain * impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
Definition: swapchain.c:25
static const IDirect3DSwapChain8Vtbl d3d8_swapchain_vtbl
Definition: swapchain.c:140
HRESULT d3d8_swapchain_create(struct d3d8_device *device, struct wined3d_swapchain_desc *desc, unsigned int swap_interval, struct d3d8_swapchain **swapchain)
Definition: swapchain.c:193
@ D3D8_DEVICE_STATE_OK
Definition: d3d8_private.h:102
struct d3d8_surface * d3d8_surface_create(struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, IUnknown *container)
Definition: surface.c:318
static struct d3d8_device * impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
Definition: d3d8_private.h:144
enum _D3DBACKBUFFER_TYPE D3DBACKBUFFER_TYPE
#define D3D_OK
Definition: d3d.h:106
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define free
Definition: debug_ros.c:5
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
struct wined3d_rendertarget_view *CDECL wined3d_device_context_get_depth_stencil_view(const struct wined3d_device_context *context)
Definition: device.c:4676
struct wined3d_texture *__cdecl wined3d_texture_from_resource(struct wined3d_resource *resource)
Definition: texture.c:3343
void *CDECL wined3d_texture_get_sub_resource_parent(struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: texture.c:4033
struct wined3d_resource *CDECL wined3d_rendertarget_view_get_resource(const struct wined3d_rendertarget_view *view)
Definition: view.c:430
#define CDECL
Definition: compat.h:29
r parent
Definition: btrfs.c:3010
unsigned int BOOL
Definition: ntddk_ex.h:94
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
unsigned int UINT
Definition: sysinfo.c:13
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
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define calloc
Definition: rosglue.h:14
#define IDirect3DSwapChain8_Release(p)
Definition: d3d8.h:266
#define IDirect3DSwapChain8_AddRef(p)
Definition: d3d8.h:265
#define IDirect3DSurface8_AddRef(p)
Definition: d3d8.h:305
#define D3DERR_DEVICELOST
Definition: d3d8.h:78
#define IDirect3DDevice8_AddRef(p)
Definition: d3d8.h:943
#define IDirect3DDevice8_Release(p)
Definition: d3d8.h:944
#define TRACE(s)
Definition: solgame.cpp:4
Definition: dcommon.idl:28
IDirect3DDevice8 * parent_device
Definition: d3d8_private.h:196
IDirect3DSurface8 IDirect3DSurface8_iface
Definition: d3d8_private.h:190
struct wined3d_swapchain * swapchain
Definition: d3d8_private.h:199
unsigned int swap_interval
Definition: d3d8_private.h:182
IDirect3DSwapChain8 IDirect3DSwapChain8_iface
Definition: d3d8_private.h:177
struct wined3d_swapchain * wined3d_swapchain
Definition: d3d8_private.h:179
struct wined3d_swapchain_state_parent state_parent
Definition: d3d8_private.h:180
IDirect3DDevice8 * parent_device
Definition: d3d8_private.h:181
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
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#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:256
ULONG CDECL wined3d_swapchain_decref(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:144
HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device, const struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain)
Definition: swapchain.c:1732
ULONG CDECL wined3d_swapchain_incref(struct wined3d_swapchain *swapchain)
Definition: swapchain.c:135
HRESULT CDECL wined3d_swapchain_present(struct wined3d_swapchain *swapchain, const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, unsigned int swap_interval, uint32_t flags)
Definition: swapchain.c:192
#define WINED3D_SWAPCHAIN_IMPLICIT
Definition: wined3d.h:901
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539
#define E_NOINTERFACE
Definition: winerror.h:3479