mshtml: Added beginning OnDataAvailable implementation.
[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 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 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     IUnknown *containerParent = NULL;
46
47     TRACE("(%p)\n", This);
48
49     IWineD3DSurface_GetContainerParent(This->wineD3DSurface, &containerParent);
50     if (containerParent) {
51         /* Forward to the containerParent */
52         TRACE("(%p) : Forwarding to %p\n", This, containerParent);
53         return IUnknown_AddRef(containerParent);
54     } else {
55         /* No container, handle our own refcounting */
56         ULONG ref = InterlockedIncrement(&This->ref);
57         TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
58
59         return ref;
60     }
61
62 }
63
64 ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
65     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
66     IUnknown *containerParent = NULL;
67
68     TRACE("(%p)\n", This);
69
70     IWineD3DSurface_GetContainerParent(This->wineD3DSurface, &containerParent);
71     if (containerParent) {
72         /* Forward to the containerParent */
73         TRACE("(%p) : Forwarding to %p\n", This, containerParent);
74         return IUnknown_Release(containerParent);
75     } else {
76         /* No container, handle our own refcounting */
77         ULONG ref = InterlockedDecrement(&This->ref);
78         TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
79
80         if (ref == 0) {
81             IWineD3DSurface_Release(This->wineD3DSurface);
82             if (This->parentDevice) IUnknown_Release(This->parentDevice);
83             HeapFree(GetProcessHeap(), 0, This);
84         }
85
86         return ref;
87     }
88 }
89
90 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
91 HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface, IDirect3DDevice9** ppDevice) {
92     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
93     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
94 }
95
96 HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
97     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
98     TRACE("(%p) Relay\n", This);
99     return IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
100 }
101
102 HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
103     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
104     TRACE("(%p) Relay\n", This);
105     return IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
106 }
107
108 HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
109     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
110     TRACE("(%p) Relay\n", This);
111     return IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
112 }
113
114 DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
115     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
116     TRACE("(%p) Relay\n", This);
117     return IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
118 }
119
120 DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
121     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
122     TRACE("(%p) Relay\n", This);
123     return IWineD3DSurface_GetPriority(This->wineD3DSurface);
124 }
125
126 void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
127     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
128     TRACE("(%p) Relay\n", This);
129     IWineD3DSurface_PreLoad(This->wineD3DSurface);
130     return ;
131 }
132
133 D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
134     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
135     TRACE("(%p) Relay\n", This);
136     return IWineD3DSurface_GetType(This->wineD3DSurface);
137 }
138
139 /* IDirect3DSurface9 Interface follow: */
140 HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
141     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
142     IWineD3DBase *wineD3DContainer = NULL;
143     IUnknown *wineD3DContainerParent = NULL;
144     HRESULT res;
145
146     TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
147
148     if (!ppContainer) {
149         ERR("Called without a valid ppContainer\n");
150     }
151
152     /* Get the WineD3D container. */
153     res = IWineD3DSurface_GetContainer(This->wineD3DSurface, &IID_IWineD3DBase, (void **)&wineD3DContainer);
154     if (res != D3D_OK) return res;
155
156     if (!wineD3DContainer) {
157         ERR("IWineD3DSurface_GetContainer should never return NULL\n");
158     }
159
160     /* Get the parent */
161     IWineD3DBase_GetParent(wineD3DContainer, &wineD3DContainerParent);
162     IUnknown_Release(wineD3DContainer);
163
164     if (!wineD3DContainerParent) {
165         ERR("IWineD3DBase_GetParent should never return NULL\n");
166     }
167
168     /* Now, query the interface of the parent for the riid */
169     res = IUnknown_QueryInterface(wineD3DContainerParent, riid, ppContainer);
170     IUnknown_Release(wineD3DContainerParent);
171
172     TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
173
174     return res;
175 }
176
177 HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
178     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
179     WINED3DSURFACE_DESC    wined3ddesc;
180     UINT                   tmpInt = -1;
181     TRACE("(%p) Relay\n", This);
182
183     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
184     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
185     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
186     wined3ddesc.Usage               = &pDesc->Usage;
187     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
188     wined3ddesc.Size                = &tmpInt;
189     wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
190     wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
191     wined3ddesc.Width               = &pDesc->Width;
192     wined3ddesc.Height              = &pDesc->Height;
193
194     return IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
195 }
196
197 HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
198     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
199     TRACE("(%p) Relay\n", This);
200     TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %ld\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
201     return IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
202 }
203
204 HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
205     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
206     TRACE("(%p) Relay\n", This);
207     return IWineD3DSurface_UnlockRect(This->wineD3DSurface);
208 }
209
210 HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
211     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
212     TRACE("(%p) Relay\n", This);
213     return IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
214 }
215
216 HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
217     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
218     TRACE("(%p) Relay\n", This);
219     return IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
220 }
221
222
223 const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
224 {
225     /* IUnknown */
226     IDirect3DSurface9Impl_QueryInterface,
227     IDirect3DSurface9Impl_AddRef,
228     IDirect3DSurface9Impl_Release,
229     /* IDirect3DResource9 */
230     IDirect3DSurface9Impl_GetDevice,
231     IDirect3DSurface9Impl_SetPrivateData,
232     IDirect3DSurface9Impl_GetPrivateData,
233     IDirect3DSurface9Impl_FreePrivateData,
234     IDirect3DSurface9Impl_SetPriority,
235     IDirect3DSurface9Impl_GetPriority,
236     IDirect3DSurface9Impl_PreLoad,
237     IDirect3DSurface9Impl_GetType,
238     /* IDirect3DSurface9 */
239     IDirect3DSurface9Impl_GetContainer,
240     IDirect3DSurface9Impl_GetDesc,
241     IDirect3DSurface9Impl_LockRect,
242     IDirect3DSurface9Impl_UnlockRect,
243     IDirect3DSurface9Impl_GetDC,
244     IDirect3DSurface9Impl_ReleaseDC
245 };