riched32: Added class style to process double click events.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DSurface9 IUnknown parts follow: */
28 static 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         IUnknown_AddRef(iface);
35         *ppobj = This;
36         return S_OK;
37     }
38
39     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
40     *ppobj = NULL;
41     return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
45     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
46
47     TRACE("(%p)\n", This);
48
49     if (This->forwardReference) {
50         /* Forward refcounting */
51         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
52         return IUnknown_AddRef(This->forwardReference);
53     } else {
54         /* No container, handle our own refcounting */
55         ULONG ref = InterlockedIncrement(&This->ref);
56         if(ref == 1 && This->parentDevice) IUnknown_AddRef(This->parentDevice);
57         TRACE("(%p) : AddRef from %d\n", This, ref - 1);
58
59         return ref;
60     }
61
62 }
63
64 static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
65     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
66
67     TRACE("(%p)\n", This);
68
69     if (This->forwardReference) {
70         /* Forward to the containerParent */
71         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
72         return IUnknown_Release(This->forwardReference);
73     } else {
74         /* No container, handle our own refcounting */
75         ULONG ref = InterlockedDecrement(&This->ref);
76         TRACE("(%p) : ReleaseRef to %d\n", This, ref);
77
78         if (ref == 0) {
79             if (This->parentDevice) IUnknown_Release(This->parentDevice);
80             if (!This->isImplicit) {
81                 EnterCriticalSection(&d3d9_cs);
82                 IWineD3DSurface_Release(This->wineD3DSurface);
83                 LeaveCriticalSection(&d3d9_cs);
84                 HeapFree(GetProcessHeap(), 0, This);
85             }
86         }
87
88         return ref;
89     }
90 }
91
92 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
93 static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface, IDirect3DDevice9** ppDevice) {
94     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
95     HRESULT hr;
96     TRACE("(%p)->(%p)\n", This, ppDevice);
97
98     EnterCriticalSection(&d3d9_cs);
99     hr = IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
100     LeaveCriticalSection(&d3d9_cs);
101     return hr;
102 }
103
104 static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
105     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
106     HRESULT hr;
107     TRACE("(%p) Relay\n", This);
108
109     EnterCriticalSection(&d3d9_cs);
110     hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
111     LeaveCriticalSection(&d3d9_cs);
112     return hr;
113 }
114
115 static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
116     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
117     HRESULT hr;
118     TRACE("(%p) Relay\n", This);
119
120     EnterCriticalSection(&d3d9_cs);
121     hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
122     LeaveCriticalSection(&d3d9_cs);
123     return hr;
124 }
125
126 static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
127     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
128     HRESULT hr;
129     TRACE("(%p) Relay\n", This);
130
131     EnterCriticalSection(&d3d9_cs);
132     hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
133     LeaveCriticalSection(&d3d9_cs);
134     return hr;
135 }
136
137 static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
138     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
139     HRESULT hr;
140     TRACE("(%p) Relay\n", This);
141
142     EnterCriticalSection(&d3d9_cs);
143     hr = IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
144     LeaveCriticalSection(&d3d9_cs);
145     return hr;
146 }
147
148 static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
149     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
150     HRESULT hr;
151     TRACE("(%p) Relay\n", This);
152
153     EnterCriticalSection(&d3d9_cs);
154     hr = IWineD3DSurface_GetPriority(This->wineD3DSurface);
155     LeaveCriticalSection(&d3d9_cs);
156     return hr;
157 }
158
159 static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
160     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
161     TRACE("(%p) Relay\n", This);
162
163     EnterCriticalSection(&d3d9_cs);
164     IWineD3DSurface_PreLoad(This->wineD3DSurface);
165     LeaveCriticalSection(&d3d9_cs);
166     return ;
167 }
168
169 static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
170     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
171     D3DRESOURCETYPE ret;
172     TRACE("(%p) Relay\n", This);
173
174     EnterCriticalSection(&d3d9_cs);
175     ret = IWineD3DSurface_GetType(This->wineD3DSurface);
176     LeaveCriticalSection(&d3d9_cs);
177     return ret;
178 }
179
180 /* IDirect3DSurface9 Interface follow: */
181 static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
182     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
183     HRESULT res;
184
185     TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
186
187     if (!This->container) return E_NOINTERFACE;
188
189     if (!ppContainer) {
190         ERR("Called without a valid ppContainer\n");
191     }
192
193     res = IUnknown_QueryInterface(This->container, riid, ppContainer);
194
195     TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
196
197     return res;
198 }
199
200 static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
201     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
202     WINED3DSURFACE_DESC    wined3ddesc;
203     UINT                   tmpInt = -1;
204     HRESULT hr;
205     TRACE("(%p) Relay\n", This);
206
207     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
208     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
209     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
210     wined3ddesc.Usage               = &pDesc->Usage;
211     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
212     wined3ddesc.Size                = &tmpInt;
213     wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
214     wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
215     wined3ddesc.Width               = &pDesc->Width;
216     wined3ddesc.Height              = &pDesc->Height;
217
218     EnterCriticalSection(&d3d9_cs);
219     hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
220     LeaveCriticalSection(&d3d9_cs);
221     return hr;
222 }
223
224 static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
225     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
226     HRESULT hr;
227     TRACE("(%p) Relay\n", This);
228
229     EnterCriticalSection(&d3d9_cs);
230     TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
231     hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
232     LeaveCriticalSection(&d3d9_cs);
233     return hr;
234 }
235
236 static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
237     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
238     HRESULT hr;
239     TRACE("(%p) Relay\n", This);
240
241     EnterCriticalSection(&d3d9_cs);
242     hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
243     LeaveCriticalSection(&d3d9_cs);
244     return hr;
245 }
246
247 static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
248     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
249     HRESULT hr;
250     TRACE("(%p) Relay\n", This);
251
252     EnterCriticalSection(&d3d9_cs);
253     hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
254     LeaveCriticalSection(&d3d9_cs);
255     return hr;
256 }
257
258 static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
259     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
260     HRESULT hr;
261     TRACE("(%p) Relay\n", This);
262
263     EnterCriticalSection(&d3d9_cs);
264     hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
265     LeaveCriticalSection(&d3d9_cs);
266     return hr;
267 }
268
269
270 const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
271 {
272     /* IUnknown */
273     IDirect3DSurface9Impl_QueryInterface,
274     IDirect3DSurface9Impl_AddRef,
275     IDirect3DSurface9Impl_Release,
276     /* IDirect3DResource9 */
277     IDirect3DSurface9Impl_GetDevice,
278     IDirect3DSurface9Impl_SetPrivateData,
279     IDirect3DSurface9Impl_GetPrivateData,
280     IDirect3DSurface9Impl_FreePrivateData,
281     IDirect3DSurface9Impl_SetPriority,
282     IDirect3DSurface9Impl_GetPriority,
283     IDirect3DSurface9Impl_PreLoad,
284     IDirect3DSurface9Impl_GetType,
285     /* IDirect3DSurface9 */
286     IDirect3DSurface9Impl_GetContainer,
287     IDirect3DSurface9Impl_GetDesc,
288     IDirect3DSurface9Impl_LockRect,
289     IDirect3DSurface9Impl_UnlockRect,
290     IDirect3DSurface9Impl_GetDC,
291     IDirect3DSurface9Impl_ReleaseDC
292 };