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