~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/d3d9/stateblock.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * IDirect3DStateBlock9 implementation
  3  *
  4  * Copyright 2002-2003 Raphael Junqueira
  5  * Copyright 2002-2003 Jason Edmeades
  6  * Copyright 2005 Oliver Stieber
  7  *
  8  * This library is free software; you can redistribute it and/or
  9  * modify it under the terms of the GNU Lesser General Public
 10  * License as published by the Free Software Foundation; either
 11  * version 2.1 of the License, or (at your option) any later version.
 12  *
 13  * This library is distributed in the hope that it will be useful,
 14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16  * Lesser General Public License for more details.
 17  *
 18  * You should have received a copy of the GNU Lesser General Public
 19  * License along with this library; if not, write to the Free Software
 20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 21  */
 22 
 23 #include "config.h"
 24 #include "d3d9_private.h"
 25 
 26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
 27 
 28 /* IDirect3DStateBlock9 IUnknown parts follow: */
 29 static HRESULT WINAPI IDirect3DStateBlock9Impl_QueryInterface(LPDIRECT3DSTATEBLOCK9 iface, REFIID riid, LPVOID* ppobj) {
 30     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
 31 
 32     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
 33 
 34     if (IsEqualGUID(riid, &IID_IUnknown)
 35         || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
 36         IDirect3DStateBlock9_AddRef(iface);
 37         *ppobj = This;
 38         return S_OK;
 39     }
 40 
 41     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
 42     *ppobj = NULL;
 43     return E_NOINTERFACE;
 44 }
 45 
 46 static ULONG WINAPI IDirect3DStateBlock9Impl_AddRef(LPDIRECT3DSTATEBLOCK9 iface) {
 47     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
 48     ULONG ref = InterlockedIncrement(&This->ref);
 49 
 50     TRACE("%p increasing refcount to %u.\n", iface, ref);
 51 
 52     return ref;
 53 }
 54 
 55 static ULONG WINAPI IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface) {
 56     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
 57     ULONG ref = InterlockedDecrement(&This->ref);
 58 
 59     TRACE("%p decreasing refcount to %u.\n", iface, ref);
 60 
 61     if (ref == 0) {
 62         wined3d_mutex_lock();
 63         IWineD3DStateBlock_Release(This->wineD3DStateBlock);
 64         wined3d_mutex_unlock();
 65 
 66         IDirect3DDevice9Ex_Release(This->parentDevice);
 67         HeapFree(GetProcessHeap(), 0, This);
 68     }
 69     return ref;
 70 }
 71 
 72 /* IDirect3DStateBlock9 Interface follow: */
 73 static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(LPDIRECT3DSTATEBLOCK9 iface, IDirect3DDevice9** ppDevice) {
 74     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
 75     IWineD3DDevice *wined3d_device;
 76     HRESULT hr;
 77 
 78     TRACE("iface %p, device %p.\n", iface, ppDevice);
 79 
 80     wined3d_mutex_lock();
 81     hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
 82     if (SUCCEEDED(hr))
 83     {
 84         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
 85         IWineD3DDevice_Release(wined3d_device);
 86     }
 87     wined3d_mutex_unlock();
 88 
 89     return hr;
 90 }
 91 
 92 static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
 93     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
 94     HRESULT hr;
 95 
 96     TRACE("iface %p.\n", iface);
 97 
 98     wined3d_mutex_lock();
 99     hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
100     wined3d_mutex_unlock();
101 
102     return hr;
103 }
104 
105 static HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface) {
106     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
107     HRESULT hr;
108 
109     TRACE("iface %p.\n", iface);
110 
111     wined3d_mutex_lock();
112     hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
113     wined3d_mutex_unlock();
114 
115     return hr;
116 }
117 
118 
119 static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl =
120 {
121     /* IUnknown */
122     IDirect3DStateBlock9Impl_QueryInterface,
123     IDirect3DStateBlock9Impl_AddRef,
124     IDirect3DStateBlock9Impl_Release,
125     /* IDirect3DStateBlock9 */
126     IDirect3DStateBlock9Impl_GetDevice,
127     IDirect3DStateBlock9Impl_Capture,
128     IDirect3DStateBlock9Impl_Apply
129 };
130 
131 
132 /* IDirect3DDevice9 IDirect3DStateBlock9 Methods follow: */
133 HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface, D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppStateBlock) {
134    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
135    IDirect3DStateBlock9Impl* object;
136    HRESULT hrc = D3D_OK;
137 
138    TRACE("iface %p, type %#x, stateblock %p.\n", iface, Type, ppStateBlock);
139 
140    if(Type != D3DSBT_ALL         && Type != D3DSBT_PIXELSTATE &&
141       Type != D3DSBT_VERTEXSTATE                              ) {
142        WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
143        return D3DERR_INVALIDCALL;
144    }
145 
146    object  = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
147    if (NULL == object) return E_OUTOFMEMORY;
148    object->lpVtbl = &Direct3DStateBlock9_Vtbl;
149    object->ref = 1;
150 
151    wined3d_mutex_lock();
152    hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown*)object);
153    wined3d_mutex_unlock();
154 
155    if(hrc != D3D_OK){
156        FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
157        HeapFree(GetProcessHeap(), 0, object);
158    } else {
159         IDirect3DDevice9Ex_AddRef(iface);
160         object->parentDevice = iface;
161         *ppStateBlock = (IDirect3DStateBlock9*)object;
162         TRACE("(%p) : Created stateblock %p\n", This, object);
163    }
164    TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
165    return hrc;
166 }
167 
168 HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
169 {
170     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
171     HRESULT hr;
172 
173     TRACE("iface %p.\n", iface);
174 
175     wined3d_mutex_lock();
176     hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
177     wined3d_mutex_unlock();
178 
179     return hr;
180 }
181 
182 HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **ppSB)
183 {
184     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
185     IWineD3DStateBlock *wineD3DStateBlock;
186     IDirect3DStateBlock9Impl *object;
187     HRESULT hr;
188 
189     TRACE("iface %p, stateblock %p.\n", iface, ppSB);
190 
191     /* Tell wineD3D to endstateblock before anything else (in case we run out
192      * of memory later and cause locking problems) */
193     wined3d_mutex_lock();
194     hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
195     wined3d_mutex_unlock();
196 
197     if (hr!= D3D_OK)
198     {
199        WARN("IWineD3DDevice_EndStateBlock returned an error\n");
200        return hr;
201     }
202     /* allocate a new IDirectD3DStateBlock */
203     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
204     if (!object) return E_OUTOFMEMORY;
205     object->ref = 1;
206     object->lpVtbl = &Direct3DStateBlock9_Vtbl;
207     object->wineD3DStateBlock = wineD3DStateBlock;
208 
209     IDirect3DDevice9Ex_AddRef(iface);
210     object->parentDevice = iface;
211     *ppSB=(IDirect3DStateBlock9*)object;
212     TRACE("(%p) Returning *ppSB %p, wineD3DStateBlock %p\n", This, *ppSB, wineD3DStateBlock);
213     return D3D_OK;
214 }
215 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.