[D3D8][D3D9][DDRAW][WINED3D]
[reactos.git] / reactos / dll / directx / wine / d3d9 / d3d9_main.c
1 /*
2 * Direct3D 9
3 *
4 * Copyright 2002-2003 Jason Edmeades
5 * Copyright 2002-2003 Raphael Junqueira
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 #include "d3d9_private.h"
25
26 static int D3DPERF_event_level = 0;
27
28 void WINAPI DebugSetMute(void) {
29 /* nothing to do */
30 }
31
32 IDirect3D9 * WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT sdk_version)
33 {
34 struct d3d9 *object;
35
36 TRACE("sdk_version %#x.\n", sdk_version);
37
38 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
39 return NULL;
40
41 if (!d3d9_init(object, FALSE))
42 {
43 WARN("Failed to initialize d3d9.\n");
44 HeapFree(GetProcessHeap(), 0, object);
45 return NULL;
46 }
47
48 TRACE("Created d3d9 object %p.\n", object);
49
50 return (IDirect3D9 *)&object->IDirect3D9Ex_iface;
51 }
52
53 HRESULT WINAPI DECLSPEC_HOTPATCH Direct3DCreate9Ex(UINT sdk_version, IDirect3D9Ex **d3d9ex)
54 {
55 struct d3d9 *object;
56
57 TRACE("sdk_version %#x, d3d9ex %p.\n", sdk_version, d3d9ex);
58
59 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
60 return E_OUTOFMEMORY;
61
62 if (!d3d9_init(object, TRUE))
63 {
64 WARN("Failed to initialize d3d9.\n");
65 HeapFree(GetProcessHeap(), 0, object);
66 return D3DERR_NOTAVAILABLE;
67 }
68
69 TRACE("Created d3d9 object %p.\n", object);
70 *d3d9ex = &object->IDirect3D9Ex_iface;
71
72 return D3D_OK;
73 }
74
75 /*******************************************************************
76 * Direct3DShaderValidatorCreate9 (D3D9.@)
77 *
78 * No documentation available for this function.
79 * SDK only says it is internal and shouldn't be used.
80 */
81 void* WINAPI Direct3DShaderValidatorCreate9(void)
82 {
83 static int once;
84
85 if (!once++) FIXME("stub\n");
86 return NULL;
87 }
88
89 /***********************************************************************
90 * D3DPERF_BeginEvent (D3D9.@)
91 */
92 int WINAPI D3DPERF_BeginEvent(D3DCOLOR color, const WCHAR *name)
93 {
94 TRACE("color 0x%08x, name %s.\n", color, debugstr_w(name));
95
96 return D3DPERF_event_level++;
97 }
98
99 /***********************************************************************
100 * D3DPERF_EndEvent (D3D9.@)
101 */
102 int WINAPI D3DPERF_EndEvent(void) {
103 TRACE("(void) : stub\n");
104
105 return --D3DPERF_event_level;
106 }
107
108 /***********************************************************************
109 * D3DPERF_GetStatus (D3D9.@)
110 */
111 DWORD WINAPI D3DPERF_GetStatus(void) {
112 FIXME("(void) : stub\n");
113
114 return 0;
115 }
116
117 /***********************************************************************
118 * D3DPERF_SetOptions (D3D9.@)
119 *
120 */
121 void WINAPI D3DPERF_SetOptions(DWORD options)
122 {
123 FIXME("(%#x) : stub\n", options);
124 }
125
126 /***********************************************************************
127 * D3DPERF_QueryRepeatFrame (D3D9.@)
128 */
129 BOOL WINAPI D3DPERF_QueryRepeatFrame(void) {
130 FIXME("(void) : stub\n");
131
132 return FALSE;
133 }
134
135 /***********************************************************************
136 * D3DPERF_SetMarker (D3D9.@)
137 */
138 void WINAPI D3DPERF_SetMarker(D3DCOLOR color, const WCHAR *name)
139 {
140 FIXME("color 0x%08x, name %s stub!\n", color, debugstr_w(name));
141 }
142
143 /***********************************************************************
144 * D3DPERF_SetRegion (D3D9.@)
145 */
146 void WINAPI D3DPERF_SetRegion(D3DCOLOR color, const WCHAR *name)
147 {
148 FIXME("color 0x%08x, name %s stub!\n", color, debugstr_w(name));
149 }
150
151 void d3d9_resource_cleanup(struct d3d9_resource *resource)
152 {
153 wined3d_private_store_cleanup(&resource->private_store);
154 }
155
156 HRESULT d3d9_resource_free_private_data(struct d3d9_resource *resource, const GUID *guid)
157 {
158 struct wined3d_private_data *entry;
159
160 wined3d_mutex_lock();
161 entry = wined3d_private_store_get_private_data(&resource->private_store, guid);
162 if (!entry)
163 {
164 wined3d_mutex_unlock();
165 return D3DERR_NOTFOUND;
166 }
167
168 wined3d_private_store_free_private_data(&resource->private_store, entry);
169 wined3d_mutex_unlock();
170
171 return D3D_OK;
172 }
173
174 HRESULT d3d9_resource_get_private_data(struct d3d9_resource *resource, const GUID *guid,
175 void *data, DWORD *data_size)
176 {
177 const struct wined3d_private_data *stored_data;
178 DWORD size_in;
179 HRESULT hr;
180
181 wined3d_mutex_lock();
182 stored_data = wined3d_private_store_get_private_data(&resource->private_store, guid);
183 if (!stored_data)
184 {
185 hr = D3DERR_NOTFOUND;
186 goto done;
187 }
188
189 size_in = *data_size;
190 *data_size = stored_data->size;
191 if (!data)
192 {
193 hr = D3D_OK;
194 goto done;
195 }
196 if (size_in < stored_data->size)
197 {
198 hr = D3DERR_MOREDATA;
199 goto done;
200 }
201
202 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
203 IUnknown_AddRef(stored_data->content.object);
204 memcpy(data, stored_data->content.data, stored_data->size);
205 hr = D3D_OK;
206
207 done:
208 wined3d_mutex_unlock();
209 return hr;
210 }
211
212 void d3d9_resource_init(struct d3d9_resource *resource)
213 {
214 resource->refcount = 1;
215 wined3d_private_store_init(&resource->private_store);
216 }
217
218 HRESULT d3d9_resource_set_private_data(struct d3d9_resource *resource, const GUID *guid,
219 const void *data, DWORD data_size, DWORD flags)
220 {
221 HRESULT hr;
222
223 wined3d_mutex_lock();
224 hr = wined3d_private_store_set_private_data(&resource->private_store, guid, data, data_size, flags);
225 wined3d_mutex_unlock();
226 return hr;
227 }