2 * IDirect3DTexture8 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
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DTexture8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
30 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DResource8)
32 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
33 || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
34 IUnknown_AddRef(iface);
39 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
44 static ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
45 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
46 ULONG ref = InterlockedIncrement(&This->ref);
48 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
53 static ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
54 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
55 ULONG ref = InterlockedDecrement(&This->ref);
57 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
60 EnterCriticalSection(&d3d8_cs);
61 IWineD3DTexture_Destroy(This->wineD3DTexture, D3D8CB_DestroySurface);
62 LeaveCriticalSection(&d3d8_cs);
63 IUnknown_Release(This->parentDevice);
64 HeapFree(GetProcessHeap(), 0, This);
69 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
70 static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
71 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
73 TRACE("(%p) Relay\n", This);
74 EnterCriticalSection(&d3d8_cs);
75 hr = IDirect3DResource8Impl_GetDevice((LPDIRECT3DRESOURCE8) This, ppDevice);
76 LeaveCriticalSection(&d3d8_cs);
80 static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
81 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
83 TRACE("(%p) Relay\n", This);
85 EnterCriticalSection(&d3d8_cs);
86 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
87 LeaveCriticalSection(&d3d8_cs);
91 static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void *pData, DWORD* pSizeOfData) {
92 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
94 TRACE("(%p) Relay\n", This);
96 EnterCriticalSection(&d3d8_cs);
97 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
98 LeaveCriticalSection(&d3d8_cs);
102 static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
103 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
105 TRACE("(%p) Relay\n", This);
107 EnterCriticalSection(&d3d8_cs);
108 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
109 LeaveCriticalSection(&d3d8_cs);
113 static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
114 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
116 TRACE("(%p) Relay\n", This);
118 EnterCriticalSection(&d3d8_cs);
119 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
120 LeaveCriticalSection(&d3d8_cs);
124 static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
125 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
127 TRACE("(%p) Relay\n", This);
129 EnterCriticalSection(&d3d8_cs);
130 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
131 LeaveCriticalSection(&d3d8_cs);
135 static void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
136 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
137 TRACE("(%p) Relay\n", This);
139 EnterCriticalSection(&d3d8_cs);
140 IWineD3DTexture_PreLoad(This->wineD3DTexture);
141 LeaveCriticalSection(&d3d8_cs);
144 static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
145 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
146 D3DRESOURCETYPE type;
147 TRACE("(%p) Relay\n", This);
149 EnterCriticalSection(&d3d8_cs);
150 type = IWineD3DTexture_GetType(This->wineD3DTexture);
151 LeaveCriticalSection(&d3d8_cs);
155 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
156 static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
157 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
159 TRACE("(%p) Relay\n", This);
161 EnterCriticalSection(&d3d8_cs);
162 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
163 LeaveCriticalSection(&d3d8_cs);
167 static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
168 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
170 TRACE("(%p) Relay\n", This);
172 EnterCriticalSection(&d3d8_cs);
173 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
174 LeaveCriticalSection(&d3d8_cs);
178 static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
179 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
181 TRACE("(%p) Relay\n", This);
183 EnterCriticalSection(&d3d8_cs);
184 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
185 LeaveCriticalSection(&d3d8_cs);
189 /* IDirect3DTexture8 Interface follow: */
190 static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
191 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
194 WINED3DSURFACE_DESC wined3ddesc;
195 TRACE("(%p) Relay\n", This);
197 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
198 memset(&wined3ddesc, 0, sizeof(wined3ddesc));
199 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
200 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
201 wined3ddesc.Usage = &pDesc->Usage;
202 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
203 wined3ddesc.Size = &pDesc->Size;
204 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
205 wined3ddesc.Width = &pDesc->Width;
206 wined3ddesc.Height = &pDesc->Height;
208 EnterCriticalSection(&d3d8_cs);
209 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
210 LeaveCriticalSection(&d3d8_cs);
212 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
217 static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8 **ppSurfaceLevel) {
218 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
219 HRESULT hrc = D3D_OK;
220 IWineD3DSurface *mySurface = NULL;
222 TRACE("(%p) Relay\n", This);
223 EnterCriticalSection(&d3d8_cs);
224 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
225 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
226 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
227 IWineD3DSurface_Release(mySurface);
229 LeaveCriticalSection(&d3d8_cs);
233 static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
234 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
236 TRACE("(%p) Relay\n", This);
238 EnterCriticalSection(&d3d8_cs);
239 hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
240 LeaveCriticalSection(&d3d8_cs);
244 static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
245 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
247 TRACE("(%p) Relay\n", This);
249 EnterCriticalSection(&d3d8_cs);
250 hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
251 LeaveCriticalSection(&d3d8_cs);
255 static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT *pDirtyRect) {
256 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
258 TRACE("(%p) Relay\n", This);
260 EnterCriticalSection(&d3d8_cs);
261 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
262 LeaveCriticalSection(&d3d8_cs);
266 const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
269 IDirect3DTexture8Impl_QueryInterface,
270 IDirect3DTexture8Impl_AddRef,
271 IDirect3DTexture8Impl_Release,
272 /* IDirect3DResource8 */
273 IDirect3DTexture8Impl_GetDevice,
274 IDirect3DTexture8Impl_SetPrivateData,
275 IDirect3DTexture8Impl_GetPrivateData,
276 IDirect3DTexture8Impl_FreePrivateData,
277 IDirect3DTexture8Impl_SetPriority,
278 IDirect3DTexture8Impl_GetPriority,
279 IDirect3DTexture8Impl_PreLoad,
280 IDirect3DTexture8Impl_GetType,
281 /* IDirect3dBaseTexture8 */
282 IDirect3DTexture8Impl_SetLOD,
283 IDirect3DTexture8Impl_GetLOD,
284 IDirect3DTexture8Impl_GetLevelCount,
285 /* IDirect3DTexture8 */
286 IDirect3DTexture8Impl_GetLevelDesc,
287 IDirect3DTexture8Impl_GetSurfaceLevel,
288 IDirect3DTexture8Impl_LockRect,
289 IDirect3DTexture8Impl_UnlockRect,
290 IDirect3DTexture8Impl_AddDirtyRect