Implements OleLoadPicturePath.
[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, 
113        one of the subclasses of IWineD3DBaseTexture or a IWineD3DSwapChain  */
114     IUnknown *IWineContainer = NULL;
115
116     TRACE("(%p) Relay\n", This);
117
118     /* Get the IUnknown container. */
119     res = IWineD3DSurface_GetContainer(This->wineD3DSurface, &IID_IUnknown, (void **)&IWineContainer);    
120     if (res == D3D_OK && IWineContainer != NULL) {
121     
122         /* Now find out what kind of container it is (so that we can get its parent)*/
123         IUnknown  *IUnknownParent = NULL;
124         IUnknown  *myContainer    = NULL;
125         if(D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DDevice, (void **)&myContainer)){
126             IWineD3DDevice_GetParent((IWineD3DDevice *)IWineContainer, &IUnknownParent);
127             IUnknown_Release(myContainer);
128         } else 
129         if(D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DBaseTexture, (void **)&myContainer)){
130             IWineD3DBaseTexture_GetParent((IWineD3DBaseTexture *)IWineContainer, &IUnknownParent);            
131             IUnknown_Release(myContainer);
132         } else
133         if(D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DSwapChain, (void **)&myContainer)){
134             IWineD3DBaseTexture_GetParent((IWineD3DBaseTexture *)IWineContainer, &IUnknownParent);
135             IUnknown_Release(myContainer);
136         }else{
137             FIXME("Container is of unknown interface\n");
138         }
139         /* Tidy up.. */
140         IUnknown_Release((IWineD3DDevice *)IWineContainer);
141
142         /* Now, query the interface of the parent for the riid */
143         if(IUnknownParent != NULL){                
144             res = IUnknown_QueryInterface(IUnknownParent, riid, ppContainer);            
145             /* Tidy up.. */
146             IUnknown_Release(IUnknownParent);
147         }
148         
149     }
150
151     TRACE("(%p) : returning %p\n", This, *ppContainer);    
152     return res;
153 }
154
155 HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
156     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
157     WINED3DSURFACE_DESC    wined3ddesc;
158     UINT                   tmpInt = -1;
159
160     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
161     wined3ddesc.Format              = &pDesc->Format;
162     wined3ddesc.Type                = &pDesc->Type;
163     wined3ddesc.Usage               = &pDesc->Usage;
164     wined3ddesc.Pool                = &pDesc->Pool;
165     wined3ddesc.Size                = &tmpInt;
166     wined3ddesc.MultiSampleType     = &pDesc->MultiSampleType;
167     wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
168     wined3ddesc.Width               = &pDesc->Width;
169     wined3ddesc.Height              = &pDesc->Height;
170
171     return IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
172 }
173
174 HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
175     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
176     return IWineD3DSurface_LockRect(This->wineD3DSurface, pLockedRect, pRect, Flags);
177 }
178
179 HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
180     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
181     return IWineD3DSurface_UnlockRect(This->wineD3DSurface);
182 }
183
184 HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
185     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
186     return IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
187 }
188
189 HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
190     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
191     return IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
192 }
193
194
195 IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
196 {
197     IDirect3DSurface9Impl_QueryInterface,
198     IDirect3DSurface9Impl_AddRef,
199     IDirect3DSurface9Impl_Release,
200     IDirect3DSurface9Impl_GetDevice,
201     IDirect3DSurface9Impl_SetPrivateData,
202     IDirect3DSurface9Impl_GetPrivateData,
203     IDirect3DSurface9Impl_FreePrivateData,
204     IDirect3DSurface9Impl_SetPriority,
205     IDirect3DSurface9Impl_GetPriority,
206     IDirect3DSurface9Impl_PreLoad,
207     IDirect3DSurface9Impl_GetType,
208     IDirect3DSurface9Impl_GetContainer,
209     IDirect3DSurface9Impl_GetDesc,
210     IDirect3DSurface9Impl_LockRect,
211     IDirect3DSurface9Impl_UnlockRect,
212     IDirect3DSurface9Impl_GetDC,
213     IDirect3DSurface9Impl_ReleaseDC
214 };