winsock: Implement getnameinfo.
[wine] / dlls / d3d8 / surface.c
1 /*
2  * IDirect3DSurface8 implementation
3  *
4  * Copyright 2005 Oliver Stieber
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DSurface8 IUnknown parts follow: */
27 HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface, REFIID riid, LPVOID *ppobj) {
28     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
29
30     if (IsEqualGUID(riid, &IID_IUnknown)
31         || IsEqualGUID(riid, &IID_IDirect3DResource8)
32         || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
33         IUnknown_AddRef(iface);
34         *ppobj = This;
35         return D3D_OK;
36     }
37
38     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39     return E_NOINTERFACE;
40 }
41
42 ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
43     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
44     ULONG ref = InterlockedIncrement(&This->ref);
45
46     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
47
48     return ref;
49 }
50
51 ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
52     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
53     ULONG ref = InterlockedDecrement(&This->ref);
54
55     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
56
57     if (ref == 0) {
58         IWineD3DSurface_Release(This->wineD3DSurface);
59         HeapFree(GetProcessHeap(), 0, This);
60     }
61     return ref;
62 }
63
64 /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
65 HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8 **ppDevice) {
66     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
67     return IDirect3DResource8Impl_GetDevice((LPDIRECT3DRESOURCE8) This, ppDevice);
68 }
69
70 HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
71     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
72     TRACE("(%p) Relay\n", This);
73     return IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
74 }
75
76 HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
77     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
78     TRACE("(%p) Relay\n", This);
79     return IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
80 }
81
82 HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
83     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
84     TRACE("(%p) Relay\n", This);
85     return IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
86 }
87
88 /* IDirect3DSurface8 Interface follow: */
89 HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) {
90     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
91     HRESULT res;
92     IUnknown *IWineContainer = NULL;
93
94     TRACE("(%p) Relay\n", This);
95
96     /* The container returned from IWineD3DSurface_GetContainer is either an IWineD3DDevice,
97        one of the subclasses of IWineD3DBaseTexture or an IWineD3DSwapChain  */
98     /* Get the IUnknown container. */
99     res = IWineD3DSurface_GetContainer(This->wineD3DSurface, &IID_IUnknown, (void **)&IWineContainer);
100     if (res == D3D_OK && IWineContainer != NULL) {
101
102         /* Now find out what kind of container it is (so that we can get its parent)*/
103         IUnknown  *IUnknownParent = NULL;
104         IUnknown  *myContainer    = NULL;
105         if (D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DDevice, (void **)&myContainer)) {
106             IWineD3DDevice_GetParent((IWineD3DDevice *)IWineContainer, &IUnknownParent);
107             IUnknown_Release(myContainer);
108         } else 
109         if (D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DBaseTexture, (void **)&myContainer)) {
110             IWineD3DBaseTexture_GetParent((IWineD3DBaseTexture *)IWineContainer, &IUnknownParent);
111             IUnknown_Release(myContainer);
112         } else
113         if (D3D_OK == IUnknown_QueryInterface(IWineContainer, &IID_IWineD3DSwapChain, (void **)&myContainer)) {
114             IWineD3DSwapChain_GetParent((IWineD3DSwapChain *)IWineContainer, &IUnknownParent);
115             IUnknown_Release(myContainer);
116         } else {
117             FIXME("Container is of unknown interface\n");
118         }
119         /* Tidy up.. */
120         IUnknown_Release((IWineD3DDevice *)IWineContainer);
121
122         /* Now, query the interface of the parent for the riid */
123         if (IUnknownParent != NULL) {
124             res = IUnknown_QueryInterface(IUnknownParent, riid, ppContainer);
125             /* Tidy up.. */
126             IUnknown_Release(IUnknownParent);
127         }
128     }
129
130     TRACE("(%p) : returning %p\n", This, *ppContainer);    
131     return res;
132 }
133
134 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
135     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
136     WINED3DSURFACE_DESC    wined3ddesc;
137     UINT                   tmpInt = -1;
138     TRACE("(%p) Relay\n", This);
139
140     /* As d3d8 and d3d8 structures differ, pass in ptrs to where data needs to go */
141     memset(&wined3ddesc, 0, sizeof(wined3ddesc));
142     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
143     wined3ddesc.Type                = &pDesc->Type;
144     wined3ddesc.Usage               = &pDesc->Usage;
145     wined3ddesc.Pool                = &pDesc->Pool;
146     wined3ddesc.Size                = &tmpInt;
147     wined3ddesc.MultiSampleType     = &pDesc->MultiSampleType;
148     wined3ddesc.Width               = &pDesc->Width;
149     wined3ddesc.Height              = &pDesc->Height;
150
151     return IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
152 }
153
154 HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
155     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
156     TRACE("(%p) Relay\n", This);
157     TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %ld\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
158     return IWineD3DSurface_LockRect(This->wineD3DSurface, pLockedRect, pRect, Flags);
159 }
160
161 HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
162     IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
163     TRACE("(%p) Relay\n", This);
164     return IWineD3DSurface_UnlockRect(This->wineD3DSurface);
165 }
166
167 const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
168 {
169     /* IUnknown */
170     IDirect3DSurface8Impl_QueryInterface,
171     IDirect3DSurface8Impl_AddRef,
172     IDirect3DSurface8Impl_Release,
173     /* IDirect3DResource8 */
174     IDirect3DSurface8Impl_GetDevice,
175     IDirect3DSurface8Impl_SetPrivateData,
176     IDirect3DSurface8Impl_GetPrivateData,
177     IDirect3DSurface8Impl_FreePrivateData,
178     /* IDirect3DSurface8 */
179     IDirect3DSurface8Impl_GetContainer,
180     IDirect3DSurface8Impl_GetDesc,
181     IDirect3DSurface8Impl_LockRect,
182     IDirect3DSurface8Impl_UnlockRect
183 };