VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d9/stateblock.c@ 48345

Last change on this file since 48345 was 48345, checked in by vboxsync, 11 years ago

header fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
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/*
24 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "d3d9_private.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
36
37static inline struct d3d9_stateblock *impl_from_IDirect3DStateBlock9(IDirect3DStateBlock9 *iface)
38{
39 return CONTAINING_RECORD(iface, struct d3d9_stateblock, IDirect3DStateBlock9_iface);
40}
41
42static HRESULT WINAPI d3d9_stateblock_QueryInterface(IDirect3DStateBlock9 *iface, REFIID riid, void **out)
43{
44 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
45
46 if (IsEqualGUID(riid, &IID_IDirect3DStateBlock9)
47 || IsEqualGUID(riid, &IID_IUnknown))
48 {
49 IDirect3DStateBlock9_AddRef(iface);
50 *out = iface;
51 return S_OK;
52 }
53
54 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
55
56 *out = NULL;
57 return E_NOINTERFACE;
58}
59
60static ULONG WINAPI d3d9_stateblock_AddRef(IDirect3DStateBlock9 *iface)
61{
62 struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
63 ULONG refcount = InterlockedIncrement(&stateblock->refcount);
64
65 TRACE("%p increasing refcount to %u.\n", iface, refcount);
66
67 return refcount;
68}
69
70static ULONG WINAPI d3d9_stateblock_Release(IDirect3DStateBlock9 *iface)
71{
72 struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
73 ULONG refcount = InterlockedDecrement(&stateblock->refcount);
74
75 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
76
77 if (!refcount)
78 {
79 wined3d_mutex_lock();
80 wined3d_stateblock_decref(stateblock->wined3d_stateblock);
81 wined3d_mutex_unlock();
82
83 IDirect3DDevice9Ex_Release(stateblock->parent_device);
84 HeapFree(GetProcessHeap(), 0, stateblock);
85 }
86
87 return refcount;
88}
89
90static HRESULT WINAPI d3d9_stateblock_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device)
91{
92 struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
93
94 TRACE("iface %p, device %p.\n", iface, device);
95
96 *device = (IDirect3DDevice9 *)stateblock->parent_device;
97 IDirect3DDevice9_AddRef(*device);
98
99 TRACE("Returning device %p.\n", *device);
100
101 return D3D_OK;
102}
103
104static HRESULT WINAPI d3d9_stateblock_Capture(IDirect3DStateBlock9 *iface)
105{
106 struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
107
108 TRACE("iface %p.\n", iface);
109
110 wined3d_mutex_lock();
111 wined3d_stateblock_capture(stateblock->wined3d_stateblock);
112 wined3d_mutex_unlock();
113
114 return D3D_OK;
115}
116
117static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
118{
119 struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
120
121 TRACE("iface %p.\n", iface);
122
123 wined3d_mutex_lock();
124 wined3d_stateblock_apply(stateblock->wined3d_stateblock);
125 wined3d_mutex_unlock();
126
127 return D3D_OK;
128}
129
130
131static const struct IDirect3DStateBlock9Vtbl d3d9_stateblock_vtbl =
132{
133 /* IUnknown */
134 d3d9_stateblock_QueryInterface,
135 d3d9_stateblock_AddRef,
136 d3d9_stateblock_Release,
137 /* IDirect3DStateBlock9 */
138 d3d9_stateblock_GetDevice,
139 d3d9_stateblock_Capture,
140 d3d9_stateblock_Apply,
141};
142
143HRESULT stateblock_init(struct d3d9_stateblock *stateblock, struct d3d9_device *device,
144 D3DSTATEBLOCKTYPE type, struct wined3d_stateblock *wined3d_stateblock)
145{
146 HRESULT hr;
147
148 stateblock->IDirect3DStateBlock9_iface.lpVtbl = &d3d9_stateblock_vtbl;
149 stateblock->refcount = 1;
150
151 if (wined3d_stateblock)
152 {
153 stateblock->wined3d_stateblock = wined3d_stateblock;
154 }
155 else
156 {
157 wined3d_mutex_lock();
158 hr = wined3d_stateblock_create(device->wined3d_device,
159 (enum wined3d_stateblock_type)type, &stateblock->wined3d_stateblock);
160 wined3d_mutex_unlock();
161 if (FAILED(hr))
162 {
163 WARN("Failed to create wined3d stateblock, hr %#x.\n", hr);
164 return hr;
165 }
166 }
167
168 stateblock->parent_device = &device->IDirect3DDevice9Ex_iface;
169 IDirect3DDevice9Ex_AddRef(stateblock->parent_device);
170
171 return D3D_OK;
172}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette