Add a stub dll for the System Event Notification Service.
[wine] / dlls / d3d9 / surface.c
1 /*
2  * IDirect3DSurface9 implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  *                     Raphael Junqueira
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
26
27 /* IDirect3DSurface9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DResource9)
33         || IsEqualGUID(riid, &IID_IDirect3DSurface9)) {
34         IDirect3DSurface9Impl_AddRef(iface);
35         *ppobj = This;
36         return D3D_OK;
37     }
38
39     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
40     return E_NOINTERFACE;
41 }
42
43 ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
44     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
48
49     return ref;
50 }
51
52 ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
53     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
57
58     if (ref == 0) {
59         IWineD3DSurface_Release(This->wineD3DSurface);
60         HeapFree(GetProcessHeap(), 0, This);
61     }
62     return ref;
63 }
64
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);
69 }
70
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);
74 }
75
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);
79 }
80
81 HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
82     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
83     return IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
84 }
85
86 DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
87     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
88     return IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
89 }
90
91 DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
92     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
93     return IWineD3DSurface_GetPriority(This->wineD3DSurface);
94 }
95
96 void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
97     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
98     IWineD3DSurface_PreLoad(This->wineD3DSurface);
99     return ;
100 }
101
102 D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
103     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
104     return IWineD3DSurface_GetType(This->wineD3DSurface);
105 }
106
107 /* IDirect3DSurface9 Interface follow: */
108 HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
109     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
110     HRESULT res;
111
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);
116
117     if (res == D3D_OK) {
118         IWineD3DDevice *myDevice = NULL;
119         IWineD3DResource_GetDevice((IWineD3DSurface *)This->wineD3DSurface, &myDevice);
120
121         if (IWineContainer == (IUnknown *)myDevice) {
122             IWineD3DDevice_GetParent((IWineD3DDevice *)IWineContainer, (IUnknown **)ppContainer);
123             IWineD3DDevice_Release((IWineD3DDevice *)IWineContainer);
124         } else {
125             IWineD3DResource_GetParent((IWineD3DResource *)IWineContainer, (IUnknown **)ppContainer);
126             IWineD3DResource_Release((IWineD3DResource *)IWineContainer);
127         }
128
129         IWineD3DDevice_Release(myDevice);
130     }
131
132     return res;
133 }
134
135 HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
136     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
137     WINED3DSURFACE_DESC    wined3ddesc;
138     UINT                   tmpInt = -1;
139
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;
150
151     return IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
152 }
153
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);
157 }
158
159 HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
160     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
161     return IWineD3DSurface_UnlockRect(This->wineD3DSurface);
162 }
163
164 HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
165     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
166     return IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
167 }
168
169 HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
170     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
171     return IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
172 }
173
174
175 IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
176 {
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
194 };
195
196 /* Internal function called back during the CreateTexture and CreateCubeTextures to create the surface(s) */
197 HRESULT WINAPI D3D9CB_CreateSurface(IUnknown  *pDevice,
198                                     UINT       Width, 
199                                     UINT       Height, 
200                                     D3DFORMAT  Format, 
201                                     D3DPOOL    Pool,
202                                     IWineD3DSurface **ppSurface, 
203                                     HANDLE   * pSharedHandle) {
204     
205     HRESULT res = D3D_OK;
206     IDirect3DSurface9Impl *d3dSurface = NULL;
207
208     res = IDirect3DDevice9_CreateOffscreenPlainSurface((IDirect3DDevice9 *)pDevice, Width, Height, 
209                                          Format, Pool, (IDirect3DSurface9 **)&d3dSurface, pSharedHandle);
210     if (res == D3D_OK) {
211         *ppSurface = d3dSurface->wineD3DSurface;
212     } else {
213         *ppSurface = NULL;
214     }
215     return res;
216 }