po: The Thai 'Time/Date' translation is incomplete so mark it as fuzzy.
[wine/multimedia.git] / dlls / d3d8 / cubetexture.c
blobf092f35bfa606ff704a364cb7176fa13b6233388
1 /*
2 * IDirect3DCubeTexture8 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
21 #include "config.h"
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 static inline IDirect3DCubeTexture8Impl *impl_from_IDirect3DCubeTexture8(IDirect3DCubeTexture8 *iface)
28 return CONTAINING_RECORD(iface, IDirect3DCubeTexture8Impl, IDirect3DCubeTexture8_iface);
31 static HRESULT WINAPI IDirect3DCubeTexture8Impl_QueryInterface(IDirect3DCubeTexture8 *iface,
32 REFIID riid, void **ppobj)
34 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
36 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDirect3DResource8)
40 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
41 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)) {
42 IUnknown_AddRef(iface);
43 *ppobj = This;
44 return S_OK;
47 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
48 *ppobj = NULL;
49 return E_NOINTERFACE;
52 static ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(IDirect3DCubeTexture8 *iface)
54 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
55 ULONG ref = InterlockedIncrement(&This->ref);
57 TRACE("%p increasing refcount to %u.\n", iface, ref);
59 if (ref == 1)
61 IUnknown_AddRef(This->parentDevice);
62 wined3d_mutex_lock();
63 wined3d_texture_incref(This->wined3d_texture);
64 wined3d_mutex_unlock();
67 return ref;
70 static ULONG WINAPI IDirect3DCubeTexture8Impl_Release(IDirect3DCubeTexture8 *iface)
72 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
73 ULONG ref = InterlockedDecrement(&This->ref);
75 TRACE("%p decreasing refcount to %u.\n", iface, ref);
77 if (ref == 0) {
78 IDirect3DDevice8 *parentDevice = This->parentDevice;
80 TRACE("Releasing child %p.\n", This->wined3d_texture);
82 wined3d_mutex_lock();
83 wined3d_texture_decref(This->wined3d_texture);
84 wined3d_mutex_unlock();
86 /* Release the device last, as it may cause the device to be destroyed. */
87 IDirect3DDevice8_Release(parentDevice);
89 return ref;
92 /* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
93 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8 *iface,
94 IDirect3DDevice8 **device)
96 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
98 TRACE("iface %p, device %p.\n", iface, device);
100 *device = This->parentDevice;
101 IDirect3DDevice8_AddRef(*device);
103 TRACE("Returning device %p.\n", *device);
105 return D3D_OK;
108 static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(IDirect3DCubeTexture8 *iface,
109 REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
111 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
112 struct wined3d_resource *resource;
113 HRESULT hr;
115 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
116 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
118 wined3d_mutex_lock();
119 resource = wined3d_texture_get_resource(This->wined3d_texture);
120 hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
121 wined3d_mutex_unlock();
123 return hr;
126 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(IDirect3DCubeTexture8 *iface,
127 REFGUID refguid, void *pData, DWORD *pSizeOfData)
129 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
130 struct wined3d_resource *resource;
131 HRESULT hr;
133 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
134 iface, debugstr_guid(refguid), pData, pSizeOfData);
136 wined3d_mutex_lock();
137 resource = wined3d_texture_get_resource(This->wined3d_texture);
138 hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
139 wined3d_mutex_unlock();
141 return hr;
144 static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(IDirect3DCubeTexture8 *iface,
145 REFGUID refguid)
147 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
148 struct wined3d_resource *resource;
149 HRESULT hr;
151 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
153 wined3d_mutex_lock();
154 resource = wined3d_texture_get_resource(This->wined3d_texture);
155 hr = wined3d_resource_free_private_data(resource, refguid);
156 wined3d_mutex_unlock();
158 return hr;
161 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(IDirect3DCubeTexture8 *iface,
162 DWORD PriorityNew)
164 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
165 DWORD ret;
167 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
169 wined3d_mutex_lock();
170 ret = wined3d_texture_set_priority(This->wined3d_texture, PriorityNew);
171 wined3d_mutex_unlock();
173 return ret;
176 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(IDirect3DCubeTexture8 *iface)
178 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
179 DWORD ret;
181 TRACE("iface %p.\n", iface);
183 wined3d_mutex_lock();
184 ret = wined3d_texture_get_priority(This->wined3d_texture);
185 wined3d_mutex_unlock();
187 return ret;
190 static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(IDirect3DCubeTexture8 *iface)
192 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
194 TRACE("iface %p.\n", iface);
196 wined3d_mutex_lock();
197 wined3d_texture_preload(This->wined3d_texture);
198 wined3d_mutex_unlock();
201 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(IDirect3DCubeTexture8 *iface)
203 TRACE("iface %p.\n", iface);
205 return D3DRTYPE_CUBETEXTURE;
208 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
209 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(IDirect3DCubeTexture8 *iface, DWORD LODNew)
211 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
212 DWORD lod;
214 TRACE("iface %p, lod %u.\n", iface, LODNew);
216 wined3d_mutex_lock();
217 lod = wined3d_texture_set_lod(This->wined3d_texture, LODNew);
218 wined3d_mutex_unlock();
220 return lod;
223 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(IDirect3DCubeTexture8 *iface)
225 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
226 DWORD lod;
228 TRACE("iface %p.\n", iface);
230 wined3d_mutex_lock();
231 lod = wined3d_texture_get_lod(This->wined3d_texture);
232 wined3d_mutex_unlock();
234 return lod;
237 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(IDirect3DCubeTexture8 *iface)
239 IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
240 DWORD cnt;
242 TRACE("iface %p.\n", iface);
244 wined3d_mutex_lock();
245 cnt = wined3d_texture_get_level_count(This->wined3d_texture);
246 wined3d_mutex_unlock();
248 return cnt;
251 /* IDirect3DCubeTexture8 Interface follow: */
252 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(IDirect3DCubeTexture8 *iface,
253 UINT level, D3DSURFACE_DESC *desc)
255 IDirect3DCubeTexture8Impl *texture = impl_from_IDirect3DCubeTexture8(iface);
256 struct wined3d_resource *sub_resource;
257 HRESULT hr = D3D_OK;
259 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
261 wined3d_mutex_lock();
262 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
263 hr = D3DERR_INVALIDCALL;
264 else
266 struct wined3d_resource_desc wined3d_desc;
268 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
269 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
270 desc->Type = wined3d_desc.resource_type;
271 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
272 desc->Pool = wined3d_desc.pool;
273 desc->Size = wined3d_desc.size;
274 desc->MultiSampleType = wined3d_desc.multisample_type;
275 desc->Width = wined3d_desc.width;
276 desc->Height = wined3d_desc.height;
278 wined3d_mutex_unlock();
280 return hr;
283 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(IDirect3DCubeTexture8 *iface,
284 D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface8 **surface)
286 IDirect3DCubeTexture8Impl *texture = impl_from_IDirect3DCubeTexture8(iface);
287 struct wined3d_resource *sub_resource;
288 UINT sub_resource_idx;
290 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
292 wined3d_mutex_lock();
293 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
294 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
296 wined3d_mutex_unlock();
297 return D3DERR_INVALIDCALL;
300 *surface = wined3d_resource_get_parent(sub_resource);
301 IDirect3DSurface8_AddRef(*surface);
302 wined3d_mutex_unlock();
304 return D3D_OK;
307 static HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(IDirect3DCubeTexture8 *iface,
308 D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
309 DWORD flags)
311 IDirect3DCubeTexture8Impl *texture = impl_from_IDirect3DCubeTexture8(iface);
312 struct wined3d_resource *sub_resource;
313 UINT sub_resource_idx;
314 HRESULT hr;
316 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
317 iface, face, level, locked_rect, rect, flags);
319 wined3d_mutex_lock();
320 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
321 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
322 hr = D3DERR_INVALIDCALL;
323 else
324 hr = IDirect3DSurface8_LockRect((IDirect3DSurface8 *)wined3d_resource_get_parent(sub_resource),
325 locked_rect, rect, flags);
326 wined3d_mutex_unlock();
328 return hr;
331 static HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(IDirect3DCubeTexture8 *iface,
332 D3DCUBEMAP_FACES face, UINT level)
334 IDirect3DCubeTexture8Impl *texture = impl_from_IDirect3DCubeTexture8(iface);
335 struct wined3d_resource *sub_resource;
336 UINT sub_resource_idx;
337 HRESULT hr;
339 TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
341 wined3d_mutex_lock();
342 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
343 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
344 hr = D3DERR_INVALIDCALL;
345 else
346 hr = IDirect3DSurface8_UnlockRect((IDirect3DSurface8 *)wined3d_resource_get_parent(sub_resource));
347 wined3d_mutex_unlock();
349 return hr;
352 static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(IDirect3DCubeTexture8 *iface,
353 D3DCUBEMAP_FACES face, const RECT *dirty_rect)
355 IDirect3DCubeTexture8Impl *texture = impl_from_IDirect3DCubeTexture8(iface);
356 HRESULT hr;
358 TRACE("iface %p, face %#x, dirty_rect %s.\n",
359 iface, face, wine_dbgstr_rect(dirty_rect));
361 wined3d_mutex_lock();
362 if (!dirty_rect)
363 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
364 else
366 struct wined3d_box dirty_region;
368 dirty_region.left = dirty_rect->left;
369 dirty_region.top = dirty_rect->top;
370 dirty_region.right = dirty_rect->right;
371 dirty_region.bottom = dirty_rect->bottom;
372 dirty_region.front = 0;
373 dirty_region.back = 1;
374 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
376 wined3d_mutex_unlock();
378 return hr;
381 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
383 /* IUnknown */
384 IDirect3DCubeTexture8Impl_QueryInterface,
385 IDirect3DCubeTexture8Impl_AddRef,
386 IDirect3DCubeTexture8Impl_Release,
387 /* IDirect3DResource8 */
388 IDirect3DCubeTexture8Impl_GetDevice,
389 IDirect3DCubeTexture8Impl_SetPrivateData,
390 IDirect3DCubeTexture8Impl_GetPrivateData,
391 IDirect3DCubeTexture8Impl_FreePrivateData,
392 IDirect3DCubeTexture8Impl_SetPriority,
393 IDirect3DCubeTexture8Impl_GetPriority,
394 IDirect3DCubeTexture8Impl_PreLoad,
395 IDirect3DCubeTexture8Impl_GetType,
396 /* IDirect3DBaseTexture8 */
397 IDirect3DCubeTexture8Impl_SetLOD,
398 IDirect3DCubeTexture8Impl_GetLOD,
399 IDirect3DCubeTexture8Impl_GetLevelCount,
400 /* IDirect3DCubeTexture8 */
401 IDirect3DCubeTexture8Impl_GetLevelDesc,
402 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
403 IDirect3DCubeTexture8Impl_LockRect,
404 IDirect3DCubeTexture8Impl_UnlockRect,
405 IDirect3DCubeTexture8Impl_AddDirtyRect
408 static void STDMETHODCALLTYPE d3d8_cubetexture_wined3d_object_destroyed(void *parent)
410 HeapFree(GetProcessHeap(), 0, parent);
413 static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops =
415 d3d8_cubetexture_wined3d_object_destroyed,
418 HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
419 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
421 HRESULT hr;
423 texture->IDirect3DCubeTexture8_iface.lpVtbl = &Direct3DCubeTexture8_Vtbl;
424 texture->ref = 1;
426 wined3d_mutex_lock();
427 hr = wined3d_texture_create_cube(device->wined3d_device, edge_length, levels,
428 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
429 &d3d8_cubetexture_wined3d_parent_ops, &texture->wined3d_texture);
430 wined3d_mutex_unlock();
431 if (FAILED(hr))
433 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
434 return hr;
437 texture->parentDevice = &device->IDirect3DDevice8_iface;
438 IDirect3DDevice8_AddRef(texture->parentDevice);
440 return D3D_OK;