wined3d: Move non-rendering surface specific code to the base class.
[wine] / dlls / wined3d / surface_base.c
1 /*
2  * IWineD3DSurface Implementation of management(non-rendering) functions
3  *
4  * Copyright 1998 Lionel Ulmer
5  * Copyright 2000-2001 TransGaming Technologies Inc.
6  * Copyright 2002-2005 Jason Edmeades
7  * Copyright 2002-2003 Raphael Junqueira
8  * Copyright 2004 Christian Costa
9  * Copyright 2005 Oliver Stieber
10  * Copyright 2006-2007 Stefan Dösinger for CodeWeavers
11  * Copyright 2007 Henri Verbeet
12  * Copyright 2006-2007 Roderick Colenbrander
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28
29 #include "config.h"
30 #include "wine/port.h"
31 #include "wined3d_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
34
35 /* Do NOT define GLINFO_LOCATION in this file. THIS CODE MUST NOT USE IT */
36
37 /* *******************************************
38    IWineD3DSurface IUnknown parts follow
39    ******************************************* */
40 HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj)
41 {
42     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
43     /* Warn ,but be nice about things */
44     TRACE("(%p)->(%s,%p)\n", This,debugstr_guid(riid),ppobj);
45
46     if (IsEqualGUID(riid, &IID_IUnknown)
47         || IsEqualGUID(riid, &IID_IWineD3DBase)
48         || IsEqualGUID(riid, &IID_IWineD3DResource)
49         || IsEqualGUID(riid, &IID_IWineD3DSurface)) {
50         IUnknown_AddRef((IUnknown*)iface);
51         *ppobj = This;
52         return S_OK;
53         }
54         *ppobj = NULL;
55         return E_NOINTERFACE;
56 }
57
58 ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface) {
59     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
60     ULONG ref = InterlockedIncrement(&This->resource.ref);
61     TRACE("(%p) : AddRef increasing from %d\n", This,ref - 1);
62     return ref;
63 }
64
65 /* ****************************************************
66    IWineD3DSurface IWineD3DResource parts follow
67    **************************************************** */
68 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice) {
69     return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
70 }
71
72 HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
73     return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
74 }
75
76 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
77     return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
78 }
79
80 HRESULT WINAPI IWineD3DBaseSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid) {
81     return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
82 }
83
84 DWORD   WINAPI IWineD3DBaseSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew) {
85     return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
86 }
87
88 DWORD   WINAPI IWineD3DBaseSurfaceImpl_GetPriority(IWineD3DSurface *iface) {
89     return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
90 }
91
92 WINED3DRESOURCETYPE WINAPI IWineD3DBaseSurfaceImpl_GetType(IWineD3DSurface *iface) {
93     TRACE("(%p) : calling resourceimpl_GetType\n", iface);
94     return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
95 }
96
97 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent) {
98     TRACE("(%p) : calling resourceimpl_GetParent\n", iface);
99     return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
100 }
101
102 /* ******************************************************
103    IWineD3DSurface IWineD3DSurface parts follow
104    ****************************************************** */
105
106 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer) {
107     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
108     IWineD3DBase *container = 0;
109
110     TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
111
112     if (!ppContainer) {
113         ERR("Called without a valid ppContainer.\n");
114     }
115
116     /** From MSDN:
117      * If the surface is created using CreateImageSurface/CreateOffscreenPlainSurface, CreateRenderTarget,
118      * or CreateDepthStencilSurface, the surface is considered stand alone. In this case,
119      * GetContainer will return the Direct3D device used to create the surface.
120      */
121     if (This->container) {
122         container = This->container;
123     } else {
124         container = (IWineD3DBase *)This->resource.wineD3DDevice;
125     }
126
127     TRACE("Relaying to QueryInterface\n");
128     return IUnknown_QueryInterface(container, riid, ppContainer);
129 }
130
131 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc) {
132     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
133
134     TRACE("(%p) : copying into %p\n", This, pDesc);
135     if(pDesc->Format != NULL)             *(pDesc->Format) = This->resource.format;
136     if(pDesc->Type != NULL)               *(pDesc->Type)   = This->resource.resourceType;
137     if(pDesc->Usage != NULL)              *(pDesc->Usage)              = This->resource.usage;
138     if(pDesc->Pool != NULL)               *(pDesc->Pool)               = This->resource.pool;
139     if(pDesc->Size != NULL)               *(pDesc->Size)               = This->resource.size;   /* dx8 only */
140     if(pDesc->MultiSampleType != NULL)    *(pDesc->MultiSampleType)    = This->currentDesc.MultiSampleType;
141     if(pDesc->MultiSampleQuality != NULL) *(pDesc->MultiSampleQuality) = This->currentDesc.MultiSampleQuality;
142     if(pDesc->Width != NULL)              *(pDesc->Width)              = This->currentDesc.Width;
143     if(pDesc->Height != NULL)             *(pDesc->Height)             = This->currentDesc.Height;
144     return WINED3D_OK;
145 }
146
147 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags) {
148     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
149     TRACE("(%p)->(%x)\n", This, Flags);
150
151     switch (Flags)
152     {
153         case WINEDDGBS_CANBLT:
154         case WINEDDGBS_ISBLTDONE:
155             return WINED3D_OK;
156
157         default:
158             return WINED3DERR_INVALIDCALL;
159     }
160 }
161
162 HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags) {
163     /* XXX: DDERR_INVALIDSURFACETYPE */
164
165     TRACE("(%p)->(%08x)\n",iface,Flags);
166     switch (Flags) {
167         case WINEDDGFS_CANFLIP:
168         case WINEDDGFS_ISFLIPDONE:
169             return WINED3D_OK;
170
171         default:
172             return WINED3DERR_INVALIDCALL;
173     }
174 }
175
176 HRESULT WINAPI IWineD3DBaseSurfaceImpl_IsLost(IWineD3DSurface *iface) {
177     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
178     TRACE("(%p)\n", This);
179
180     /* D3D8 and 9 loose full devices, ddraw only surfaces */
181     return This->Flags & SFLAG_LOST ? WINED3DERR_DEVICELOST : WINED3D_OK;
182 }
183
184 HRESULT WINAPI IWineD3DBaseSurfaceImpl_Restore(IWineD3DSurface *iface) {
185     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
186     TRACE("(%p)\n", This);
187
188     /* So far we don't lose anything :) */
189     This->Flags &= ~SFLAG_LOST;
190     return WINED3D_OK;
191 }