ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

shader.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2003 Jason Edmeades
00003  *                     Raphael Junqueira
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018  */
00019 
00020 #include "config.h"
00021 #include <assert.h>
00022 #include "d3d9_private.h"
00023 
00024 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
00025 
00026 static inline IDirect3DVertexShader9Impl *impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
00027 {
00028     return CONTAINING_RECORD(iface, IDirect3DVertexShader9Impl, IDirect3DVertexShader9_iface);
00029 }
00030 
00031 static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **object)
00032 {
00033     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
00034 
00035     if (IsEqualGUID(riid, &IID_IDirect3DVertexShader9)
00036             || IsEqualGUID(riid, &IID_IUnknown))
00037     {
00038         IDirect3DVertexShader9_AddRef(iface);
00039         *object = iface;
00040         return S_OK;
00041     }
00042 
00043     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
00044 
00045     *object = NULL;
00046     return E_NOINTERFACE;
00047 }
00048 
00049 static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
00050 {
00051     IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
00052     ULONG refcount = InterlockedIncrement(&shader->ref);
00053 
00054     TRACE("%p increasing refcount to %u.\n", iface, refcount);
00055 
00056     if (refcount == 1)
00057     {
00058         IDirect3DDevice9Ex_AddRef(shader->parentDevice);
00059         wined3d_mutex_lock();
00060         wined3d_shader_incref(shader->wined3d_shader);
00061         wined3d_mutex_unlock();
00062     }
00063 
00064     return refcount;
00065 }
00066 
00067 static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
00068 {
00069     IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
00070     ULONG refcount = InterlockedDecrement(&shader->ref);
00071 
00072     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
00073 
00074     if (!refcount)
00075     {
00076         IDirect3DDevice9Ex *device = shader->parentDevice;
00077 
00078         wined3d_mutex_lock();
00079         wined3d_shader_decref(shader->wined3d_shader);
00080         wined3d_mutex_unlock();
00081 
00082         /* Release the device last, as it may cause the device to be destroyed. */
00083         IDirect3DDevice9Ex_Release(device);
00084     }
00085 
00086     return refcount;
00087 }
00088 
00089 static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
00090 {
00091     IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
00092 
00093     TRACE("iface %p, device %p.\n", iface, device);
00094 
00095     *device = (IDirect3DDevice9 *)shader->parentDevice;
00096     IDirect3DDevice9_AddRef(*device);
00097 
00098     TRACE("Returning device %p.\n", *device);
00099 
00100     return D3D_OK;
00101 }
00102 
00103 static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface,
00104         void *data, UINT *data_size)
00105 {
00106     IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
00107     HRESULT hr;
00108 
00109     TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
00110 
00111     wined3d_mutex_lock();
00112     hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
00113     wined3d_mutex_unlock();
00114 
00115     return hr;
00116 }
00117 
00118 static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl =
00119 {
00120     /* IUnknown */
00121     d3d9_vertexshader_QueryInterface,
00122     d3d9_vertexshader_AddRef,
00123     d3d9_vertexshader_Release,
00124     /* IDirect3DVertexShader9 */
00125     d3d9_vertexshader_GetDevice,
00126     d3d9_vertexshader_GetFunction,
00127 };
00128 
00129 static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
00130 {
00131     HeapFree(GetProcessHeap(), 0, parent);
00132 }
00133 
00134 static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
00135 {
00136     d3d9_vertexshader_wined3d_object_destroyed,
00137 };
00138 
00139 HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
00140 {
00141     HRESULT hr;
00142 
00143     shader->ref = 1;
00144     shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl;
00145 
00146     wined3d_mutex_lock();
00147     hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL,
00148             shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
00149     wined3d_mutex_unlock();
00150     if (FAILED(hr))
00151     {
00152         WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
00153         return hr;
00154     }
00155 
00156     shader->parentDevice = &device->IDirect3DDevice9Ex_iface;
00157     IDirect3DDevice9Ex_AddRef(shader->parentDevice);
00158 
00159     return D3D_OK;
00160 }
00161 
00162 IDirect3DVertexShader9Impl *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
00163 {
00164     if (!iface)
00165         return NULL;
00166     assert(iface->lpVtbl == &d3d9_vertexshader_vtbl);
00167 
00168     return impl_from_IDirect3DVertexShader9(iface);
00169 }
00170 
00171 static inline IDirect3DPixelShader9Impl *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
00172 {
00173     return CONTAINING_RECORD(iface, IDirect3DPixelShader9Impl, IDirect3DPixelShader9_iface);
00174 }
00175 
00176 static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **object)
00177 {
00178     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
00179 
00180     if (IsEqualGUID(riid, &IID_IDirect3DPixelShader9)
00181             || IsEqualGUID(riid, &IID_IUnknown))
00182     {
00183         IDirect3DPixelShader9_AddRef(iface);
00184         *object = iface;
00185         return S_OK;
00186     }
00187 
00188     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
00189 
00190     *object = NULL;
00191     return E_NOINTERFACE;
00192 }
00193 
00194 static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
00195 {
00196     IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
00197     ULONG refcount = InterlockedIncrement(&shader->ref);
00198 
00199     TRACE("%p increasing refcount to %u.\n", iface, refcount);
00200 
00201     if (refcount == 1)
00202     {
00203         IDirect3DDevice9Ex_AddRef(shader->parentDevice);
00204         wined3d_mutex_lock();
00205         wined3d_shader_incref(shader->wined3d_shader);
00206         wined3d_mutex_unlock();
00207     }
00208 
00209     return refcount;
00210 }
00211 
00212 static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
00213 {
00214     IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
00215     ULONG refcount = InterlockedDecrement(&shader->ref);
00216 
00217     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
00218 
00219     if (!refcount)
00220     {
00221         IDirect3DDevice9Ex *device = shader->parentDevice;
00222 
00223         wined3d_mutex_lock();
00224         wined3d_shader_decref(shader->wined3d_shader);
00225         wined3d_mutex_unlock();
00226 
00227         /* Release the device last, as it may cause the device to be destroyed. */
00228         IDirect3DDevice9Ex_Release(device);
00229     }
00230 
00231     return refcount;
00232 }
00233 
00234 static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface,
00235         IDirect3DDevice9 **device)
00236 {
00237     IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
00238 
00239     TRACE("iface %p, device %p.\n", iface, device);
00240 
00241     *device = (IDirect3DDevice9 *)shader->parentDevice;
00242     IDirect3DDevice9_AddRef(*device);
00243 
00244     TRACE("Returning device %p.\n", *device);
00245 
00246     return D3D_OK;
00247 }
00248 
00249 static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data,
00250         UINT *data_size)
00251 {
00252     IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
00253     HRESULT hr;
00254 
00255     TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
00256 
00257     wined3d_mutex_lock();
00258     hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
00259     wined3d_mutex_unlock();
00260 
00261     return hr;
00262 }
00263 
00264 static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl =
00265 {
00266     /* IUnknown */
00267     d3d9_pixelshader_QueryInterface,
00268     d3d9_pixelshader_AddRef,
00269     d3d9_pixelshader_Release,
00270     /* IDirect3DPixelShader9 */
00271     d3d9_pixelshader_GetDevice,
00272     d3d9_pixelshader_GetFunction,
00273 };
00274 
00275 static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
00276 {
00277     HeapFree(GetProcessHeap(), 0, parent);
00278 }
00279 
00280 static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
00281 {
00282     d3d9_pixelshader_wined3d_object_destroyed,
00283 };
00284 
00285 HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
00286 {
00287     HRESULT hr;
00288 
00289     shader->ref = 1;
00290     shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl;
00291 
00292     wined3d_mutex_lock();
00293     hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
00294             &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
00295     wined3d_mutex_unlock();
00296     if (FAILED(hr))
00297     {
00298         WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
00299         return hr;
00300     }
00301 
00302     shader->parentDevice = &device->IDirect3DDevice9Ex_iface;
00303     IDirect3DDevice9Ex_AddRef(shader->parentDevice);
00304 
00305     return D3D_OK;
00306 }
00307 
00308 IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
00309 {
00310     if (!iface)
00311         return NULL;
00312     assert(iface->lpVtbl == &d3d9_pixelshader_vtbl);
00313 
00314     return impl_from_IDirect3DPixelShader9(iface);
00315 }

Generated on Thu May 24 2012 04:22:19 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.