2 * IDirect3DSwapChain8 implementation
4 * Copyright 2005 Oliver Stieber
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.
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.
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
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 static inline struct d3d8_swapchain *impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
28 return CONTAINING_RECORD(iface, struct d3d8_swapchain, IDirect3DSwapChain8_iface);
31 static HRESULT WINAPI d3d8_swapchain_QueryInterface(IDirect3DSwapChain8 *iface, REFIID riid, void **out)
33 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
35 if (IsEqualGUID(riid, &IID_IDirect3DSwapChain8)
36 || IsEqualGUID(riid, &IID_IUnknown))
38 IDirect3DSwapChain8_AddRef(iface);
43 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
49 static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface)
51 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
52 ULONG ref = InterlockedIncrement(&swapchain->refcount);
54 TRACE("%p increasing refcount to %u.\n", iface, ref);
58 if (swapchain->parent_device)
59 IDirect3DDevice8_AddRef(swapchain->parent_device);
61 wined3d_swapchain_incref(swapchain->wined3d_swapchain);
62 wined3d_mutex_unlock();
68 static ULONG WINAPI d3d8_swapchain_Release(IDirect3DSwapChain8 *iface)
70 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
71 ULONG ref = InterlockedDecrement(&swapchain->refcount);
73 TRACE("%p decreasing refcount to %u.\n", iface, ref);
77 IDirect3DDevice8 *parent_device = swapchain->parent_device;
80 wined3d_swapchain_decref(swapchain->wined3d_swapchain);
81 wined3d_mutex_unlock();
84 IDirect3DDevice8_Release(parent_device);
89 static HRESULT WINAPI d3d8_swapchain_Present(IDirect3DSwapChain8 *iface,
90 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
91 const RGNDATA *dirty_region)
93 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
96 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
97 iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), dst_window_override, dirty_region);
100 hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, src_rect,
101 dst_rect, dst_window_override, dirty_region, 0);
102 wined3d_mutex_unlock();
107 static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface,
108 UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
110 struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
111 struct wined3d_surface *wined3d_surface = NULL;
112 struct d3d8_surface *surface_impl;
115 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
116 iface, backbuffer_idx, backbuffer_type, backbuffer);
118 wined3d_mutex_lock();
119 if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
120 backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
122 surface_impl = wined3d_surface_get_parent(wined3d_surface);
123 *backbuffer = &surface_impl->IDirect3DSurface8_iface;
124 IDirect3DSurface8_AddRef(*backbuffer);
128 hr = D3DERR_INVALIDCALL;
130 wined3d_mutex_unlock();
135 static const IDirect3DSwapChain8Vtbl d3d8_swapchain_vtbl =
137 d3d8_swapchain_QueryInterface,
138 d3d8_swapchain_AddRef,
139 d3d8_swapchain_Release,
140 d3d8_swapchain_Present,
141 d3d8_swapchain_GetBackBuffer
144 static void STDMETHODCALLTYPE d3d8_swapchain_wined3d_object_released(void *parent)
146 HeapFree(GetProcessHeap(), 0, parent);
149 static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops =
151 d3d8_swapchain_wined3d_object_released,
154 static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device,
155 struct wined3d_swapchain_desc *desc)
159 swapchain->refcount = 1;
160 swapchain->IDirect3DSwapChain8_iface.lpVtbl = &d3d8_swapchain_vtbl;
162 wined3d_mutex_lock();
163 hr = wined3d_swapchain_create(device->wined3d_device, desc,
164 WINED3D_SURFACE_TYPE_OPENGL, swapchain, &d3d8_swapchain_wined3d_parent_ops,
165 &swapchain->wined3d_swapchain);
166 wined3d_mutex_unlock();
170 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
174 swapchain->parent_device = &device->IDirect3DDevice8_iface;
175 IDirect3DDevice8_AddRef(swapchain->parent_device);
180 HRESULT d3d8_swapchain_create(struct d3d8_device *device, struct wined3d_swapchain_desc *desc,
181 struct d3d8_swapchain **swapchain)
183 struct d3d8_swapchain *object;
186 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
188 ERR("Failed to allocate swapchain memory.\n");
189 return E_OUTOFMEMORY;
192 if (FAILED(hr = swapchain_init(object, device, desc)))
194 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
195 HeapFree(GetProcessHeap(), 0, object);
199 TRACE("Created swapchain %p.\n", object);