VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/swapchain.c@ 68890

Last change on this file since 68890 was 51270, checked in by vboxsync, 11 years ago

wine: update to 1.6.2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 KB
Line 
1/*
2 * IDirect3DSwapChain9 implementation
3 *
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23/*
24 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "d3d9_private.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
36
37static inline struct d3d9_swapchain *impl_from_IDirect3DSwapChain9Ex(IDirect3DSwapChain9Ex *iface)
38{
39 return CONTAINING_RECORD(iface, struct d3d9_swapchain, IDirect3DSwapChain9Ex_iface);
40}
41
42static HRESULT WINAPI d3d9_swapchain_QueryInterface(IDirect3DSwapChain9Ex *iface, REFIID riid, void **out)
43{
44 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
45
46 if (IsEqualGUID(riid, &IID_IDirect3DSwapChain9)
47 || IsEqualGUID(riid, &IID_IUnknown))
48 {
49 IDirect3DSwapChain9Ex_AddRef(iface);
50 *out = iface;
51 return S_OK;
52 }
53
54 if (IsEqualGUID(riid, &IID_IDirect3DSwapChain9Ex))
55 {
56 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
57 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(swapchain->parent_device);
58
59 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
60 * It doesn't matter with which function the device was created. */
61 if (!device->d3d_parent->extended)
62 {
63 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
64 *out = NULL;
65 return E_NOINTERFACE;
66 }
67
68 IDirect3DSwapChain9Ex_AddRef(iface);
69 *out = iface;
70 return S_OK;
71 }
72
73 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
74
75 *out = NULL;
76 return E_NOINTERFACE;
77}
78
79static ULONG WINAPI d3d9_swapchain_AddRef(IDirect3DSwapChain9Ex *iface)
80{
81 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
82 ULONG refcount = InterlockedIncrement(&swapchain->refcount);
83
84 TRACE("%p increasing refcount to %u.\n", iface, refcount);
85
86 if (refcount == 1)
87 {
88 if (swapchain->parent_device)
89 IDirect3DDevice9Ex_AddRef(swapchain->parent_device);
90
91 wined3d_mutex_lock();
92 wined3d_swapchain_incref(swapchain->wined3d_swapchain);
93 wined3d_mutex_unlock();
94 }
95
96 return refcount;
97}
98
99static ULONG WINAPI d3d9_swapchain_Release(IDirect3DSwapChain9Ex *iface)
100{
101 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
102 ULONG refcount = InterlockedDecrement(&swapchain->refcount);
103
104 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
105
106 if (!refcount)
107 {
108 IDirect3DDevice9Ex *parent_device = swapchain->parent_device;
109
110 wined3d_mutex_lock();
111 wined3d_swapchain_decref(swapchain->wined3d_swapchain);
112 wined3d_mutex_unlock();
113
114 /* Release the device last, as it may cause the device to be destroyed. */
115 if (parent_device)
116 IDirect3DDevice9Ex_Release(parent_device);
117 }
118
119 return refcount;
120}
121
122static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_swapchain_Present(IDirect3DSwapChain9Ex *iface,
123 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
124 const RGNDATA *dirty_region, DWORD flags)
125{
126 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
127 HRESULT hr;
128
129 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
130 iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
131 dst_window_override, dirty_region, flags);
132
133 wined3d_mutex_lock();
134 hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, src_rect,
135 dst_rect, dst_window_override, dirty_region, flags);
136 wined3d_mutex_unlock();
137
138 return hr;
139}
140
141static HRESULT WINAPI d3d9_swapchain_GetFrontBufferData(IDirect3DSwapChain9Ex *iface, IDirect3DSurface9 *surface)
142{
143 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
144 struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(surface);
145 HRESULT hr;
146
147 TRACE("iface %p, surface %p.\n", iface, surface);
148
149 wined3d_mutex_lock();
150 hr = wined3d_swapchain_get_front_buffer_data(swapchain->wined3d_swapchain, dst->wined3d_surface);
151 wined3d_mutex_unlock();
152
153 return hr;
154}
155
156static HRESULT WINAPI d3d9_swapchain_GetBackBuffer(IDirect3DSwapChain9Ex *iface,
157 UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface9 **backbuffer)
158{
159 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
160 struct wined3d_surface *wined3d_surface = NULL;
161 struct d3d9_surface *surface_impl;
162 HRESULT hr = D3D_OK;
163
164 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
165 iface, backbuffer_idx, backbuffer_type, backbuffer);
166
167 wined3d_mutex_lock();
168 if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
169 backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
170 {
171 surface_impl = wined3d_surface_get_parent(wined3d_surface);
172 *backbuffer = &surface_impl->IDirect3DSurface9_iface;
173 IDirect3DSurface9_AddRef(*backbuffer);
174 }
175 else
176 {
177 hr = D3DERR_INVALIDCALL;
178 }
179 wined3d_mutex_unlock();
180
181 return hr;
182}
183
184static HRESULT WINAPI d3d9_swapchain_GetRasterStatus(IDirect3DSwapChain9Ex *iface, D3DRASTER_STATUS *raster_status)
185{
186 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
187 HRESULT hr;
188
189 TRACE("iface %p, raster_status %p.\n", iface, raster_status);
190
191 wined3d_mutex_lock();
192 hr = wined3d_swapchain_get_raster_status(swapchain->wined3d_swapchain,
193 (struct wined3d_raster_status *)raster_status);
194 wined3d_mutex_unlock();
195
196 return hr;
197}
198
199static HRESULT WINAPI d3d9_swapchain_GetDisplayMode(IDirect3DSwapChain9Ex *iface, D3DDISPLAYMODE *mode)
200{
201 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
202 struct wined3d_display_mode wined3d_mode;
203 HRESULT hr;
204
205 TRACE("iface %p, mode %p.\n", iface, mode);
206
207 wined3d_mutex_lock();
208 hr = wined3d_swapchain_get_display_mode(swapchain->wined3d_swapchain, &wined3d_mode, NULL);
209 wined3d_mutex_unlock();
210
211 if (SUCCEEDED(hr))
212 {
213 mode->Width = wined3d_mode.width;
214 mode->Height = wined3d_mode.height;
215 mode->RefreshRate = wined3d_mode.refresh_rate;
216 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
217 }
218
219 return hr;
220}
221
222static HRESULT WINAPI d3d9_swapchain_GetDevice(IDirect3DSwapChain9Ex *iface, IDirect3DDevice9 **device)
223{
224 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
225
226 TRACE("iface %p, device %p.\n", iface, device);
227
228 *device = (IDirect3DDevice9 *)swapchain->parent_device;
229 IDirect3DDevice9_AddRef(*device);
230
231 TRACE("Returning device %p.\n", *device);
232
233 return D3D_OK;
234}
235
236static HRESULT WINAPI d3d9_swapchain_GetPresentParameters(IDirect3DSwapChain9Ex *iface,
237 D3DPRESENT_PARAMETERS *parameters)
238{
239 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
240 struct wined3d_swapchain_desc desc;
241
242 TRACE("iface %p, parameters %p.\n", iface, parameters);
243
244 wined3d_mutex_lock();
245 wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &desc);
246 wined3d_mutex_unlock();
247 present_parameters_from_wined3d_swapchain_desc(parameters, &desc);
248
249 return D3D_OK;
250}
251
252static HRESULT WINAPI d3d9_swapchain_GetLastPresentCount(IDirect3DSwapChain9Ex *iface,
253 UINT *last_present_count)
254{
255 FIXME("iface %p, last_present_count %p, stub!\n", iface, last_present_count);
256
257 if (last_present_count)
258 *last_present_count = 0;
259
260 return D3D_OK;
261}
262
263static HRESULT WINAPI d3d9_swapchain_GetPresentStatistics(IDirect3DSwapChain9Ex *iface,
264 D3DPRESENTSTATS *present_stats)
265{
266 FIXME("iface %p, present_stats %p, stub!\n", iface, present_stats);
267
268 if (present_stats)
269 memset(present_stats, 0, sizeof(*present_stats));
270
271 return D3D_OK;
272}
273
274static HRESULT WINAPI d3d9_swapchain_GetDisplayModeEx(IDirect3DSwapChain9Ex *iface,
275 D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
276{
277 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
278 struct wined3d_display_mode wined3d_mode;
279 HRESULT hr;
280
281 TRACE("iface %p, mode %p, rotation %p.\n", iface, mode, rotation);
282
283 if (mode->Size != sizeof(*mode))
284 return D3DERR_INVALIDCALL;
285
286 wined3d_mutex_lock();
287 hr = wined3d_swapchain_get_display_mode(swapchain->wined3d_swapchain, &wined3d_mode,
288 (enum wined3d_display_rotation *)rotation);
289 wined3d_mutex_unlock();
290
291 if (SUCCEEDED(hr))
292 {
293 mode->Width = wined3d_mode.width;
294 mode->Height = wined3d_mode.height;
295 mode->RefreshRate = wined3d_mode.refresh_rate;
296 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
297 mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
298 }
299
300 return hr;
301}
302
303static const struct IDirect3DSwapChain9ExVtbl d3d9_swapchain_vtbl =
304{
305 /* IUnknown */
306 d3d9_swapchain_QueryInterface,
307 d3d9_swapchain_AddRef,
308 d3d9_swapchain_Release,
309 /* IDirect3DSwapChain9 */
310 d3d9_swapchain_Present,
311 d3d9_swapchain_GetFrontBufferData,
312 d3d9_swapchain_GetBackBuffer,
313 d3d9_swapchain_GetRasterStatus,
314 d3d9_swapchain_GetDisplayMode,
315 d3d9_swapchain_GetDevice,
316 d3d9_swapchain_GetPresentParameters,
317 /* IDirect3DSwapChain9Ex */
318 d3d9_swapchain_GetLastPresentCount,
319 d3d9_swapchain_GetPresentStatistics,
320 d3d9_swapchain_GetDisplayModeEx
321};
322
323static void STDMETHODCALLTYPE d3d9_swapchain_wined3d_object_released(void *parent)
324{
325 HeapFree(GetProcessHeap(), 0, parent);
326}
327
328static const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops =
329{
330 d3d9_swapchain_wined3d_object_released,
331};
332
333static HRESULT swapchain_init(struct d3d9_swapchain *swapchain, struct d3d9_device *device,
334 struct wined3d_swapchain_desc *desc)
335{
336 HRESULT hr;
337
338 swapchain->refcount = 1;
339 swapchain->IDirect3DSwapChain9Ex_iface.lpVtbl = &d3d9_swapchain_vtbl;
340
341 wined3d_mutex_lock();
342 hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
343 &d3d9_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain);
344 wined3d_mutex_unlock();
345
346 if (FAILED(hr))
347 {
348 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
349 return hr;
350 }
351
352 swapchain->parent_device = &device->IDirect3DDevice9Ex_iface;
353 IDirect3DDevice9Ex_AddRef(swapchain->parent_device);
354
355 return D3D_OK;
356}
357
358HRESULT d3d9_swapchain_create(struct d3d9_device *device, struct wined3d_swapchain_desc *desc,
359 struct d3d9_swapchain **swapchain)
360{
361 struct d3d9_swapchain *object;
362 HRESULT hr;
363
364 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
365 return E_OUTOFMEMORY;
366
367 if (FAILED(hr = swapchain_init(object, device, desc)))
368 {
369 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
370 HeapFree(GetProcessHeap(), 0, object);
371 return hr;
372 }
373
374 TRACE("Created swapchain %p.\n", object);
375 *swapchain = object;
376
377 return D3D_OK;
378}
379
380#ifdef VBOX_WITH_WDDM
381VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9Present(IDirect3DSwapChain9 *iface,
382 IDirect3DSurface9 *surf) /* use the given surface as a frontbuffer content source */
383{
384 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
385 struct d3d9_surface *rt = unsafe_impl_from_IDirect3DSurface9(surf);
386 HRESULT hr;
387 wined3d_mutex_lock();
388 hr = wined3d_swapchain_present_rt(swapchain->wined3d_swapchain, rt->wined3d_surface);
389 wined3d_mutex_unlock();
390 return hr;
391}
392
393VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9GetHostWinID(IDirect3DSwapChain9 *iface, int32_t *pi32Id)
394{
395 struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
396 HRESULT hr;
397 wined3d_mutex_lock();
398 hr = wined3d_swapchain_get_host_win_id(swapchain->wined3d_swapchain, pi32Id);
399 wined3d_mutex_unlock();
400 return hr;
401}
402#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette