2 * IDirect3DSurface9 implementation
4 * Copyright 2002-2005 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface
);
27 /* IDirect3DSurface9 IUnknown parts follow: */
28 HRESULT WINAPI
IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface
, REFIID riid
, LPVOID
* ppobj
) {
29 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
31 if (IsEqualGUID(riid
, &IID_IUnknown
)
32 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
33 || IsEqualGUID(riid
, &IID_IDirect3DSurface9
)) {
34 IDirect3DSurface9Impl_AddRef(iface
);
39 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
43 ULONG WINAPI
IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface
) {
44 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
45 ULONG ref
= InterlockedIncrement(&This
->ref
);
47 TRACE("(%p) : AddRef from %ld\n", This
, ref
- 1);
52 ULONG WINAPI
IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface
) {
53 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
54 ULONG ref
= InterlockedDecrement(&This
->ref
);
56 TRACE("(%p) : ReleaseRef to %ld\n", This
, ref
);
59 IWineD3DSurface_Release(This
->wineD3DSurface
);
60 HeapFree(GetProcessHeap(), 0, This
);
65 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
66 HRESULT WINAPI
IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface
, IDirect3DDevice9
** ppDevice
) {
67 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
68 return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9
) This
, ppDevice
);
71 HRESULT WINAPI
IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
72 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
73 return IWineD3DSurface_SetPrivateData(This
->wineD3DSurface
, refguid
, pData
, SizeOfData
, Flags
);
76 HRESULT WINAPI
IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
77 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
78 return IWineD3DSurface_GetPrivateData(This
->wineD3DSurface
, refguid
, pData
, pSizeOfData
);
81 HRESULT WINAPI
IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface
, REFGUID refguid
) {
82 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
83 return IWineD3DSurface_FreePrivateData(This
->wineD3DSurface
, refguid
);
86 DWORD WINAPI
IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface
, DWORD PriorityNew
) {
87 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
88 return IWineD3DSurface_SetPriority(This
->wineD3DSurface
, PriorityNew
);
91 DWORD WINAPI
IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface
) {
92 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
93 return IWineD3DSurface_GetPriority(This
->wineD3DSurface
);
96 void WINAPI
IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface
) {
97 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
98 IWineD3DSurface_PreLoad(This
->wineD3DSurface
);
102 D3DRESOURCETYPE WINAPI
IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface
) {
103 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
104 return IWineD3DSurface_GetType(This
->wineD3DSurface
);
107 /* IDirect3DSurface9 Interface follow: */
108 HRESULT WINAPI
IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface
, REFIID riid
, void** ppContainer
) {
109 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
112 /* The container returned from IWineD3DSurface_GetContainer is either a IWineD3DDevice or
113 opne of the subclasses of resource */
114 IUnknown
*IWineContainer
= NULL
;
115 res
= IWineD3DSurface_GetContainer(This
->wineD3DSurface
, riid
, (void **)&IWineContainer
);
118 IWineD3DDevice
*myDevice
= NULL
;
119 IWineD3DResource_GetDevice((IWineD3DSurface
*)This
->wineD3DSurface
, &myDevice
);
121 if (IWineContainer
== (IUnknown
*)myDevice
) {
122 IWineD3DDevice_GetParent((IWineD3DDevice
*)IWineContainer
, (IUnknown
**)ppContainer
);
123 IWineD3DDevice_Release((IWineD3DDevice
*)IWineContainer
);
125 IWineD3DResource_GetParent((IWineD3DResource
*)IWineContainer
, (IUnknown
**)ppContainer
);
126 IWineD3DResource_Release((IWineD3DResource
*)IWineContainer
);
129 IWineD3DDevice_Release(myDevice
);
135 HRESULT WINAPI
IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface
, D3DSURFACE_DESC
* pDesc
) {
136 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
137 WINED3DSURFACE_DESC wined3ddesc
;
140 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
141 wined3ddesc
.Format
= &pDesc
->Format
;
142 wined3ddesc
.Type
= &pDesc
->Type
;
143 wined3ddesc
.Usage
= &pDesc
->Usage
;
144 wined3ddesc
.Pool
= &pDesc
->Pool
;
145 wined3ddesc
.Size
= &tmpInt
;
146 wined3ddesc
.MultiSampleType
= &pDesc
->MultiSampleType
;
147 wined3ddesc
.MultiSampleQuality
= &pDesc
->MultiSampleQuality
;
148 wined3ddesc
.Width
= &pDesc
->Width
;
149 wined3ddesc
.Height
= &pDesc
->Height
;
151 return IWineD3DSurface_GetDesc(This
->wineD3DSurface
, &wined3ddesc
);
154 HRESULT WINAPI
IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface
, D3DLOCKED_RECT
* pLockedRect
, CONST RECT
* pRect
, DWORD Flags
) {
155 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
156 return IWineD3DSurface_LockRect(This
->wineD3DSurface
, pLockedRect
, pRect
, Flags
);
159 HRESULT WINAPI
IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface
) {
160 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
161 return IWineD3DSurface_UnlockRect(This
->wineD3DSurface
);
164 HRESULT WINAPI
IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface
, HDC
* phdc
) {
165 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
166 return IWineD3DSurface_GetDC(This
->wineD3DSurface
, phdc
);
169 HRESULT WINAPI
IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface
, HDC hdc
) {
170 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
171 return IWineD3DSurface_ReleaseDC(This
->wineD3DSurface
, hdc
);
175 IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl
=
177 IDirect3DSurface9Impl_QueryInterface
,
178 IDirect3DSurface9Impl_AddRef
,
179 IDirect3DSurface9Impl_Release
,
180 IDirect3DSurface9Impl_GetDevice
,
181 IDirect3DSurface9Impl_SetPrivateData
,
182 IDirect3DSurface9Impl_GetPrivateData
,
183 IDirect3DSurface9Impl_FreePrivateData
,
184 IDirect3DSurface9Impl_SetPriority
,
185 IDirect3DSurface9Impl_GetPriority
,
186 IDirect3DSurface9Impl_PreLoad
,
187 IDirect3DSurface9Impl_GetType
,
188 IDirect3DSurface9Impl_GetContainer
,
189 IDirect3DSurface9Impl_GetDesc
,
190 IDirect3DSurface9Impl_LockRect
,
191 IDirect3DSurface9Impl_UnlockRect
,
192 IDirect3DSurface9Impl_GetDC
,
193 IDirect3DSurface9Impl_ReleaseDC
196 /* Internal function called back during the CreateTexture and CreateCubeTextures to create the surface(s) */
197 HRESULT WINAPI
D3D9CB_CreateSurface(IUnknown
*pDevice
,
202 IWineD3DSurface
**ppSurface
,
203 HANDLE
* pSharedHandle
) {
205 HRESULT res
= D3D_OK
;
206 IDirect3DSurface9Impl
*d3dSurface
= NULL
;
208 res
= IDirect3DDevice9_CreateOffscreenPlainSurface((IDirect3DDevice9
*)pDevice
, Width
, Height
,
209 Format
, Pool
, (IDirect3DSurface9
**)&d3dSurface
, pSharedHandle
);
211 *ppSurface
= d3dSurface
->wineD3DSurface
;