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 | /*
|
---|
22 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
23 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
24 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
25 | * a choice of LGPL license versions is made available with the language indicating
|
---|
26 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
27 | * of the LGPL is applied is otherwise unspecified.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #include "config.h"
|
---|
31 | #include "d3d8_private.h"
|
---|
32 |
|
---|
33 | WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
---|
34 |
|
---|
35 | static inline struct d3d8_swapchain *impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
|
---|
36 | {
|
---|
37 | return CONTAINING_RECORD(iface, struct d3d8_swapchain, IDirect3DSwapChain8_iface);
|
---|
38 | }
|
---|
39 |
|
---|
40 | static HRESULT WINAPI d3d8_swapchain_QueryInterface(IDirect3DSwapChain8 *iface, REFIID riid, void **out)
|
---|
41 | {
|
---|
42 | TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
---|
43 |
|
---|
44 | if (IsEqualGUID(riid, &IID_IDirect3DSwapChain8)
|
---|
45 | || IsEqualGUID(riid, &IID_IUnknown))
|
---|
46 | {
|
---|
47 | IDirect3DSwapChain8_AddRef(iface);
|
---|
48 | *out = iface;
|
---|
49 | return S_OK;
|
---|
50 | }
|
---|
51 |
|
---|
52 | WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
---|
53 |
|
---|
54 | *out = NULL;
|
---|
55 | return E_NOINTERFACE;
|
---|
56 | }
|
---|
57 |
|
---|
58 | static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface)
|
---|
59 | {
|
---|
60 | struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
---|
61 | ULONG ref = InterlockedIncrement(&swapchain->refcount);
|
---|
62 |
|
---|
63 | TRACE("%p increasing refcount to %u.\n", iface, ref);
|
---|
64 |
|
---|
65 | if (ref == 1)
|
---|
66 | {
|
---|
67 | if (swapchain->parent_device)
|
---|
68 | IDirect3DDevice8_AddRef(swapchain->parent_device);
|
---|
69 | wined3d_mutex_lock();
|
---|
70 | wined3d_swapchain_incref(swapchain->wined3d_swapchain);
|
---|
71 | wined3d_mutex_unlock();
|
---|
72 | }
|
---|
73 |
|
---|
74 | return ref;
|
---|
75 | }
|
---|
76 |
|
---|
77 | static ULONG WINAPI d3d8_swapchain_Release(IDirect3DSwapChain8 *iface)
|
---|
78 | {
|
---|
79 | struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
---|
80 | ULONG ref = InterlockedDecrement(&swapchain->refcount);
|
---|
81 |
|
---|
82 | TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
---|
83 |
|
---|
84 | if (!ref)
|
---|
85 | {
|
---|
86 | IDirect3DDevice8 *parent_device = swapchain->parent_device;
|
---|
87 |
|
---|
88 | wined3d_mutex_lock();
|
---|
89 | wined3d_swapchain_decref(swapchain->wined3d_swapchain);
|
---|
90 | wined3d_mutex_unlock();
|
---|
91 |
|
---|
92 | if (parent_device)
|
---|
93 | IDirect3DDevice8_Release(parent_device);
|
---|
94 | }
|
---|
95 | return ref;
|
---|
96 | }
|
---|
97 |
|
---|
98 | static HRESULT WINAPI d3d8_swapchain_Present(IDirect3DSwapChain8 *iface,
|
---|
99 | const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
|
---|
100 | const RGNDATA *dirty_region)
|
---|
101 | {
|
---|
102 | struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
---|
103 | HRESULT hr;
|
---|
104 |
|
---|
105 | TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
|
---|
106 | iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), dst_window_override, dirty_region);
|
---|
107 |
|
---|
108 | wined3d_mutex_lock();
|
---|
109 | hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, src_rect,
|
---|
110 | dst_rect, dst_window_override, dirty_region, 0);
|
---|
111 | wined3d_mutex_unlock();
|
---|
112 |
|
---|
113 | return hr;
|
---|
114 | }
|
---|
115 |
|
---|
116 | static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface,
|
---|
117 | UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
|
---|
118 | {
|
---|
119 | struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
---|
120 | struct wined3d_surface *wined3d_surface = NULL;
|
---|
121 | struct d3d8_surface *surface_impl;
|
---|
122 | HRESULT hr = D3D_OK;
|
---|
123 |
|
---|
124 | TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
|
---|
125 | iface, backbuffer_idx, backbuffer_type, backbuffer);
|
---|
126 |
|
---|
127 | wined3d_mutex_lock();
|
---|
128 | if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
|
---|
129 | backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
|
---|
130 | {
|
---|
131 | surface_impl = wined3d_surface_get_parent(wined3d_surface);
|
---|
132 | *backbuffer = &surface_impl->IDirect3DSurface8_iface;
|
---|
133 | IDirect3DSurface8_AddRef(*backbuffer);
|
---|
134 | }
|
---|
135 | else
|
---|
136 | {
|
---|
137 | hr = D3DERR_INVALIDCALL;
|
---|
138 | }
|
---|
139 | wined3d_mutex_unlock();
|
---|
140 |
|
---|
141 | return hr;
|
---|
142 | }
|
---|
143 |
|
---|
144 | static const IDirect3DSwapChain8Vtbl d3d8_swapchain_vtbl =
|
---|
145 | {
|
---|
146 | d3d8_swapchain_QueryInterface,
|
---|
147 | d3d8_swapchain_AddRef,
|
---|
148 | d3d8_swapchain_Release,
|
---|
149 | d3d8_swapchain_Present,
|
---|
150 | d3d8_swapchain_GetBackBuffer
|
---|
151 | };
|
---|
152 |
|
---|
153 | static void STDMETHODCALLTYPE d3d8_swapchain_wined3d_object_released(void *parent)
|
---|
154 | {
|
---|
155 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
156 | }
|
---|
157 |
|
---|
158 | static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops =
|
---|
159 | {
|
---|
160 | d3d8_swapchain_wined3d_object_released,
|
---|
161 | };
|
---|
162 |
|
---|
163 | static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device,
|
---|
164 | struct wined3d_swapchain_desc *desc)
|
---|
165 | {
|
---|
166 | HRESULT hr;
|
---|
167 |
|
---|
168 | swapchain->refcount = 1;
|
---|
169 | swapchain->IDirect3DSwapChain8_iface.lpVtbl = &d3d8_swapchain_vtbl;
|
---|
170 |
|
---|
171 | wined3d_mutex_lock();
|
---|
172 | hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
|
---|
173 | &d3d8_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain);
|
---|
174 | wined3d_mutex_unlock();
|
---|
175 |
|
---|
176 | if (FAILED(hr))
|
---|
177 | {
|
---|
178 | WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
|
---|
179 | return hr;
|
---|
180 | }
|
---|
181 |
|
---|
182 | swapchain->parent_device = &device->IDirect3DDevice8_iface;
|
---|
183 | IDirect3DDevice8_AddRef(swapchain->parent_device);
|
---|
184 |
|
---|
185 | return D3D_OK;
|
---|
186 | }
|
---|
187 |
|
---|
188 | HRESULT d3d8_swapchain_create(struct d3d8_device *device, struct wined3d_swapchain_desc *desc,
|
---|
189 | struct d3d8_swapchain **swapchain)
|
---|
190 | {
|
---|
191 | struct d3d8_swapchain *object;
|
---|
192 | HRESULT hr;
|
---|
193 |
|
---|
194 | if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
---|
195 | return E_OUTOFMEMORY;
|
---|
196 |
|
---|
197 | if (FAILED(hr = swapchain_init(object, device, desc)))
|
---|
198 | {
|
---|
199 | WARN("Failed to initialize swapchain, hr %#x.\n", hr);
|
---|
200 | HeapFree(GetProcessHeap(), 0, object);
|
---|
201 | return hr;
|
---|
202 | }
|
---|
203 |
|
---|
204 | TRACE("Created swapchain %p.\n", object);
|
---|
205 | *swapchain = object;
|
---|
206 |
|
---|
207 | return D3D_OK;
|
---|
208 | }
|
---|