1 | /*
|
---|
2 | * IDirect3DTexture8 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 | * Sun 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, Sun 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 | /* IDirect3DTexture8 IUnknown parts follow: */
|
---|
36 | static HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
|
---|
37 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
38 |
|
---|
39 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
|
---|
40 |
|
---|
41 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
42 | || IsEqualGUID(riid, &IID_IDirect3DResource8)
|
---|
43 | || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
|
---|
44 | || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
|
---|
45 | IUnknown_AddRef(iface);
|
---|
46 | *ppobj = This;
|
---|
47 | return S_OK;
|
---|
48 | }
|
---|
49 |
|
---|
50 | WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
|
---|
51 | *ppobj = NULL;
|
---|
52 | return E_NOINTERFACE;
|
---|
53 | }
|
---|
54 |
|
---|
55 | static ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
|
---|
56 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
57 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
58 |
|
---|
59 | TRACE("%p increasing refcount to %u.\n", iface, ref);
|
---|
60 |
|
---|
61 | if (ref == 1)
|
---|
62 | {
|
---|
63 | IDirect3DDevice8_AddRef(This->parentDevice);
|
---|
64 | wined3d_mutex_lock();
|
---|
65 | IWineD3DTexture_AddRef(This->wineD3DTexture);
|
---|
66 | wined3d_mutex_unlock();
|
---|
67 | }
|
---|
68 |
|
---|
69 | return ref;
|
---|
70 | }
|
---|
71 |
|
---|
72 | static ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
|
---|
73 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
74 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
75 |
|
---|
76 | TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
---|
77 |
|
---|
78 | if (ref == 0) {
|
---|
79 | IDirect3DDevice8 *parentDevice = This->parentDevice;
|
---|
80 |
|
---|
81 | wined3d_mutex_lock();
|
---|
82 | IWineD3DTexture_Release(This->wineD3DTexture);
|
---|
83 | wined3d_mutex_unlock();
|
---|
84 |
|
---|
85 | /* Release the device last, as it may cause the device to be destroyed. */
|
---|
86 | IDirect3DDevice8_Release(parentDevice);
|
---|
87 | }
|
---|
88 | return ref;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
|
---|
92 | static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(IDirect3DTexture8 *iface, IDirect3DDevice8 **device)
|
---|
93 | {
|
---|
94 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
95 |
|
---|
96 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
97 |
|
---|
98 | *device = (IDirect3DDevice8 *)This->parentDevice;
|
---|
99 | IDirect3DDevice8_AddRef(*device);
|
---|
100 |
|
---|
101 | TRACE("Returning device %p.\n", *device);
|
---|
102 |
|
---|
103 | return D3D_OK;
|
---|
104 | }
|
---|
105 |
|
---|
106 | static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
|
---|
107 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
108 | HRESULT hr;
|
---|
109 |
|
---|
110 | TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
|
---|
111 | iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
|
---|
112 |
|
---|
113 | wined3d_mutex_lock();
|
---|
114 | hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
|
---|
115 | wined3d_mutex_unlock();
|
---|
116 |
|
---|
117 | return hr;
|
---|
118 | }
|
---|
119 |
|
---|
120 | static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void *pData, DWORD* pSizeOfData) {
|
---|
121 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
122 | HRESULT hr;
|
---|
123 |
|
---|
124 | TRACE("iface %p, guid %s, data %p, data_size %p.\n",
|
---|
125 | iface, debugstr_guid(refguid), pData, pSizeOfData);
|
---|
126 |
|
---|
127 | wined3d_mutex_lock();
|
---|
128 | hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
|
---|
129 | wined3d_mutex_unlock();
|
---|
130 |
|
---|
131 | return hr;
|
---|
132 | }
|
---|
133 |
|
---|
134 | static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
|
---|
135 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
136 | HRESULT hr;
|
---|
137 |
|
---|
138 | TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
|
---|
139 |
|
---|
140 | wined3d_mutex_lock();
|
---|
141 | hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
|
---|
142 | wined3d_mutex_unlock();
|
---|
143 |
|
---|
144 | return hr;
|
---|
145 | }
|
---|
146 |
|
---|
147 | static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
|
---|
148 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
149 | DWORD ret;
|
---|
150 |
|
---|
151 | TRACE("iface %p, priority %u.\n", iface, PriorityNew);
|
---|
152 |
|
---|
153 | wined3d_mutex_lock();
|
---|
154 | ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
|
---|
155 | wined3d_mutex_unlock();
|
---|
156 |
|
---|
157 | return ret;
|
---|
158 | }
|
---|
159 |
|
---|
160 | static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
|
---|
161 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
162 | DWORD ret;
|
---|
163 |
|
---|
164 | TRACE("iface %p.\n", iface);
|
---|
165 |
|
---|
166 | wined3d_mutex_lock();
|
---|
167 | ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
|
---|
168 | wined3d_mutex_unlock();
|
---|
169 |
|
---|
170 | return ret;
|
---|
171 | }
|
---|
172 |
|
---|
173 | static void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
|
---|
174 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
175 |
|
---|
176 | TRACE("iface %p.\n", iface);
|
---|
177 |
|
---|
178 | wined3d_mutex_lock();
|
---|
179 | IWineD3DTexture_PreLoad(This->wineD3DTexture);
|
---|
180 | wined3d_mutex_unlock();
|
---|
181 | }
|
---|
182 |
|
---|
183 | static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
|
---|
184 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
185 | D3DRESOURCETYPE type;
|
---|
186 |
|
---|
187 | TRACE("iface %p.\n", iface);
|
---|
188 |
|
---|
189 | wined3d_mutex_lock();
|
---|
190 | type = IWineD3DTexture_GetType(This->wineD3DTexture);
|
---|
191 | wined3d_mutex_unlock();
|
---|
192 |
|
---|
193 | return type;
|
---|
194 | }
|
---|
195 |
|
---|
196 | /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
|
---|
197 | static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
|
---|
198 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
199 | DWORD ret;
|
---|
200 |
|
---|
201 | TRACE("iface %p, lod %u.\n", iface, LODNew);
|
---|
202 |
|
---|
203 | wined3d_mutex_lock();
|
---|
204 | ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
|
---|
205 | wined3d_mutex_unlock();
|
---|
206 |
|
---|
207 | return ret;
|
---|
208 | }
|
---|
209 |
|
---|
210 | static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
|
---|
211 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
212 | DWORD ret;
|
---|
213 |
|
---|
214 | TRACE("iface %p.\n", iface);
|
---|
215 |
|
---|
216 | wined3d_mutex_lock();
|
---|
217 | ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
|
---|
218 | wined3d_mutex_unlock();
|
---|
219 |
|
---|
220 | return ret;
|
---|
221 | }
|
---|
222 |
|
---|
223 | static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
|
---|
224 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
225 | DWORD ret;
|
---|
226 |
|
---|
227 | TRACE("iface %p.\n", iface);
|
---|
228 |
|
---|
229 | wined3d_mutex_lock();
|
---|
230 | ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
|
---|
231 | wined3d_mutex_unlock();
|
---|
232 |
|
---|
233 | return ret;
|
---|
234 | }
|
---|
235 |
|
---|
236 | /* IDirect3DTexture8 Interface follow: */
|
---|
237 | static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
|
---|
238 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
239 | WINED3DSURFACE_DESC wined3ddesc;
|
---|
240 | HRESULT hr;
|
---|
241 |
|
---|
242 | TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
|
---|
243 |
|
---|
244 | wined3d_mutex_lock();
|
---|
245 | hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
|
---|
246 | wined3d_mutex_unlock();
|
---|
247 |
|
---|
248 | if (SUCCEEDED(hr))
|
---|
249 | {
|
---|
250 | pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
|
---|
251 | pDesc->Type = wined3ddesc.resource_type;
|
---|
252 | pDesc->Usage = wined3ddesc.usage;
|
---|
253 | pDesc->Pool = wined3ddesc.pool;
|
---|
254 | pDesc->Size = wined3ddesc.size;
|
---|
255 | pDesc->MultiSampleType = wined3ddesc.multisample_type;
|
---|
256 | pDesc->Width = wined3ddesc.width;
|
---|
257 | pDesc->Height = wined3ddesc.height;
|
---|
258 | }
|
---|
259 |
|
---|
260 | return hr;
|
---|
261 | }
|
---|
262 |
|
---|
263 | static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8 **ppSurfaceLevel) {
|
---|
264 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
265 | HRESULT hrc = D3D_OK;
|
---|
266 | IWineD3DSurface *mySurface = NULL;
|
---|
267 |
|
---|
268 | TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
|
---|
269 |
|
---|
270 | wined3d_mutex_lock();
|
---|
271 | hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
|
---|
272 | if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
|
---|
273 | IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
|
---|
274 | IWineD3DSurface_Release(mySurface);
|
---|
275 | }
|
---|
276 | wined3d_mutex_unlock();
|
---|
277 |
|
---|
278 | return hrc;
|
---|
279 | }
|
---|
280 |
|
---|
281 | static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
|
---|
282 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
283 | HRESULT hr;
|
---|
284 |
|
---|
285 | TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
|
---|
286 | iface, Level, pLockedRect, pRect, Flags);
|
---|
287 |
|
---|
288 | wined3d_mutex_lock();
|
---|
289 | hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
|
---|
290 | wined3d_mutex_unlock();
|
---|
291 |
|
---|
292 | return hr;
|
---|
293 | }
|
---|
294 |
|
---|
295 | static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
|
---|
296 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
297 | HRESULT hr;
|
---|
298 |
|
---|
299 | TRACE("iface %p, level %u.\n", iface, Level);
|
---|
300 |
|
---|
301 | wined3d_mutex_lock();
|
---|
302 | hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
|
---|
303 | wined3d_mutex_unlock();
|
---|
304 |
|
---|
305 | return hr;
|
---|
306 | }
|
---|
307 |
|
---|
308 | static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT *pDirtyRect) {
|
---|
309 | IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
|
---|
310 | HRESULT hr;
|
---|
311 |
|
---|
312 | TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
|
---|
313 |
|
---|
314 | wined3d_mutex_lock();
|
---|
315 | hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
|
---|
316 | wined3d_mutex_unlock();
|
---|
317 |
|
---|
318 | return hr;
|
---|
319 | }
|
---|
320 |
|
---|
321 | static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
|
---|
322 | {
|
---|
323 | /* IUnknown */
|
---|
324 | IDirect3DTexture8Impl_QueryInterface,
|
---|
325 | IDirect3DTexture8Impl_AddRef,
|
---|
326 | IDirect3DTexture8Impl_Release,
|
---|
327 | /* IDirect3DResource8 */
|
---|
328 | IDirect3DTexture8Impl_GetDevice,
|
---|
329 | IDirect3DTexture8Impl_SetPrivateData,
|
---|
330 | IDirect3DTexture8Impl_GetPrivateData,
|
---|
331 | IDirect3DTexture8Impl_FreePrivateData,
|
---|
332 | IDirect3DTexture8Impl_SetPriority,
|
---|
333 | IDirect3DTexture8Impl_GetPriority,
|
---|
334 | IDirect3DTexture8Impl_PreLoad,
|
---|
335 | IDirect3DTexture8Impl_GetType,
|
---|
336 | /* IDirect3dBaseTexture8 */
|
---|
337 | IDirect3DTexture8Impl_SetLOD,
|
---|
338 | IDirect3DTexture8Impl_GetLOD,
|
---|
339 | IDirect3DTexture8Impl_GetLevelCount,
|
---|
340 | /* IDirect3DTexture8 */
|
---|
341 | IDirect3DTexture8Impl_GetLevelDesc,
|
---|
342 | IDirect3DTexture8Impl_GetSurfaceLevel,
|
---|
343 | IDirect3DTexture8Impl_LockRect,
|
---|
344 | IDirect3DTexture8Impl_UnlockRect,
|
---|
345 | IDirect3DTexture8Impl_AddDirtyRect
|
---|
346 | };
|
---|
347 |
|
---|
348 | static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
|
---|
349 | {
|
---|
350 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
351 | }
|
---|
352 |
|
---|
353 | static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
|
---|
354 | {
|
---|
355 | d3d8_texture_wined3d_object_destroyed,
|
---|
356 | };
|
---|
357 |
|
---|
358 | HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
|
---|
359 | UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
|
---|
360 | {
|
---|
361 | HRESULT hr;
|
---|
362 |
|
---|
363 | texture->lpVtbl = &Direct3DTexture8_Vtbl;
|
---|
364 | texture->ref = 1;
|
---|
365 |
|
---|
366 | wined3d_mutex_lock();
|
---|
367 | hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
|
---|
368 | usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
|
---|
369 | &texture->wineD3DTexture, (IUnknown *)texture, &d3d8_texture_wined3d_parent_ops);
|
---|
370 | wined3d_mutex_unlock();
|
---|
371 | if (FAILED(hr))
|
---|
372 | {
|
---|
373 | WARN("Failed to create wined3d texture, hr %#x.\n", hr);
|
---|
374 | return hr;
|
---|
375 | }
|
---|
376 |
|
---|
377 | texture->parentDevice = (IDirect3DDevice8 *)device;
|
---|
378 | IDirect3DDevice8_AddRef(texture->parentDevice);
|
---|
379 |
|
---|
380 | return D3D_OK;
|
---|
381 | }
|
---|