msvcrt: Fix _splitpath and _wsplitpath implementation.
[wine/wine-gecko.git] / dlls / d3d9 / pixelshader.c
blob1d4fd95d4828839fdbe9b0f81707ec4747ca4626
1 /*
2 * IDirect3DPixelShader9 implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DPixelShader9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DPixelShader9Impl_QueryInterface(LPDIRECT3DPIXELSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
31 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DPixelShader9)) {
35 IDirect3DPixelShader9_AddRef(iface);
36 *ppobj = This;
37 return S_OK;
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41 *ppobj = NULL;
42 return E_NOINTERFACE;
45 static ULONG WINAPI IDirect3DPixelShader9Impl_AddRef(LPDIRECT3DPIXELSHADER9 iface) {
46 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("%p increasing refcount to %u.\n", iface, ref);
51 if (ref == 1)
53 IDirect3DDevice9Ex_AddRef(This->parentDevice);
54 wined3d_mutex_lock();
55 IWineD3DPixelShader_AddRef(This->wineD3DPixelShader);
56 wined3d_mutex_unlock();
59 return ref;
62 static ULONG WINAPI IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 iface) {
63 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
64 ULONG ref = InterlockedDecrement(&This->ref);
66 TRACE("%p decreasing refcount to %u.\n", iface, ref);
68 if (ref == 0) {
69 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
71 wined3d_mutex_lock();
72 IWineD3DPixelShader_Release(This->wineD3DPixelShader);
73 wined3d_mutex_unlock();
75 /* Release the device last, as it may cause the device to be destroyed. */
76 IDirect3DDevice9Ex_Release(parentDevice);
78 return ref;
81 /* IDirect3DPixelShader9 Interface follow: */
82 static HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device)
84 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
86 TRACE("iface %p, device %p.\n", iface, device);
88 *device = (IDirect3DDevice9 *)This->parentDevice;
89 IDirect3DDevice9_AddRef(*device);
91 TRACE("Returning device %p.\n", *device);
93 return D3D_OK;
96 static HRESULT WINAPI IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
97 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
98 HRESULT hr;
100 TRACE("iface %p, data %p, data_size %p.\n", iface, pData, pSizeOfData);
102 wined3d_mutex_lock();
103 hr = IWineD3DPixelShader_GetFunction(This->wineD3DPixelShader, pData, pSizeOfData);
104 wined3d_mutex_unlock();
106 return hr;
110 static const IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl =
112 /* IUnknown */
113 IDirect3DPixelShader9Impl_QueryInterface,
114 IDirect3DPixelShader9Impl_AddRef,
115 IDirect3DPixelShader9Impl_Release,
116 /* IDirect3DPixelShader9 */
117 IDirect3DPixelShader9Impl_GetDevice,
118 IDirect3DPixelShader9Impl_GetFunction
121 static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
123 HeapFree(GetProcessHeap(), 0, parent);
126 static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
128 d3d9_pixelshader_wined3d_object_destroyed,
131 HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
133 HRESULT hr;
135 shader->ref = 1;
136 shader->lpVtbl = &Direct3DPixelShader9_Vtbl;
138 wined3d_mutex_lock();
139 hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code, NULL, shader,
140 &d3d9_pixelshader_wined3d_parent_ops, &shader->wineD3DPixelShader);
141 wined3d_mutex_unlock();
142 if (FAILED(hr))
144 WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
145 return hr;
148 shader->parentDevice = (IDirect3DDevice9Ex *)device;
149 IDirect3DDevice9Ex_AddRef(shader->parentDevice);
151 return D3D_OK;