xref: /reactos/dll/directx/wine/d3d9/d3d9_main.c (revision 9987f029)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Direct3D 9
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2002-2003 Jason Edmeades
5c2c66affSColin Finck  * Copyright 2002-2003 Raphael Junqueira
6c2c66affSColin Finck  * Copyright 2005 Oliver Stieber
7c2c66affSColin Finck  *
8c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
9c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
10c2c66affSColin Finck  * License as published by the Free Software Foundation; either
11c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
12c2c66affSColin Finck  *
13c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
14c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16c2c66affSColin Finck  * Lesser General Public License for more details.
17c2c66affSColin Finck  *
18c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
19c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
20c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21c2c66affSColin Finck  *
22c2c66affSColin Finck  */
23c2c66affSColin Finck 
24*9987f029SAmine Khaldi #include "config.h"
25*9987f029SAmine Khaldi #include "initguid.h"
26c2c66affSColin Finck #include "d3d9_private.h"
27c2c66affSColin Finck 
28*9987f029SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
29*9987f029SAmine Khaldi 
30c2c66affSColin Finck static int D3DPERF_event_level = 0;
31c2c66affSColin Finck 
DebugSetMute(void)32c2c66affSColin Finck void WINAPI DebugSetMute(void) {
33c2c66affSColin Finck     /* nothing to do */
34c2c66affSColin Finck }
35c2c66affSColin Finck 
Direct3DCreate9(UINT sdk_version)36c2c66affSColin Finck IDirect3D9 * WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT sdk_version)
37c2c66affSColin Finck {
38c2c66affSColin Finck     struct d3d9 *object;
39c2c66affSColin Finck 
40c2c66affSColin Finck     TRACE("sdk_version %#x.\n", sdk_version);
41c2c66affSColin Finck 
42*9987f029SAmine Khaldi     if (!(object = heap_alloc_zero(sizeof(*object))))
43c2c66affSColin Finck         return NULL;
44c2c66affSColin Finck 
45c2c66affSColin Finck     if (!d3d9_init(object, FALSE))
46c2c66affSColin Finck     {
47c2c66affSColin Finck         WARN("Failed to initialize d3d9.\n");
48*9987f029SAmine Khaldi         heap_free(object);
49c2c66affSColin Finck         return NULL;
50c2c66affSColin Finck     }
51c2c66affSColin Finck 
52c2c66affSColin Finck     TRACE("Created d3d9 object %p.\n", object);
53c2c66affSColin Finck 
54c2c66affSColin Finck     return (IDirect3D9 *)&object->IDirect3D9Ex_iface;
55c2c66affSColin Finck }
56c2c66affSColin Finck 
Direct3DCreate9Ex(UINT sdk_version,IDirect3D9Ex ** d3d9ex)57c2c66affSColin Finck HRESULT WINAPI DECLSPEC_HOTPATCH Direct3DCreate9Ex(UINT sdk_version, IDirect3D9Ex **d3d9ex)
58c2c66affSColin Finck {
59c2c66affSColin Finck     struct d3d9 *object;
60c2c66affSColin Finck 
61c2c66affSColin Finck     TRACE("sdk_version %#x, d3d9ex %p.\n", sdk_version, d3d9ex);
62c2c66affSColin Finck 
63*9987f029SAmine Khaldi     if (!(object = heap_alloc_zero(sizeof(*object))))
64c2c66affSColin Finck         return E_OUTOFMEMORY;
65c2c66affSColin Finck 
66c2c66affSColin Finck     if (!d3d9_init(object, TRUE))
67c2c66affSColin Finck     {
68c2c66affSColin Finck         WARN("Failed to initialize d3d9.\n");
69*9987f029SAmine Khaldi         heap_free(object);
70c2c66affSColin Finck         return D3DERR_NOTAVAILABLE;
71c2c66affSColin Finck     }
72c2c66affSColin Finck 
73c2c66affSColin Finck     TRACE("Created d3d9 object %p.\n", object);
74c2c66affSColin Finck     *d3d9ex = &object->IDirect3D9Ex_iface;
75c2c66affSColin Finck 
76c2c66affSColin Finck     return D3D_OK;
77c2c66affSColin Finck }
78c2c66affSColin Finck 
79c2c66affSColin Finck /*******************************************************************
80c2c66affSColin Finck  *       Direct3DShaderValidatorCreate9 (D3D9.@)
81c2c66affSColin Finck  *
82c2c66affSColin Finck  * No documentation available for this function.
83c2c66affSColin Finck  * SDK only says it is internal and shouldn't be used.
84c2c66affSColin Finck  */
Direct3DShaderValidatorCreate9(void)85c2c66affSColin Finck void* WINAPI Direct3DShaderValidatorCreate9(void)
86c2c66affSColin Finck {
87c2c66affSColin Finck     static int once;
88c2c66affSColin Finck 
89c2c66affSColin Finck     if (!once++) FIXME("stub\n");
90c2c66affSColin Finck     return NULL;
91c2c66affSColin Finck }
92c2c66affSColin Finck 
93c2c66affSColin Finck /***********************************************************************
94c2c66affSColin Finck  *              D3DPERF_BeginEvent (D3D9.@)
95c2c66affSColin Finck  */
D3DPERF_BeginEvent(D3DCOLOR color,const WCHAR * name)96c2c66affSColin Finck int WINAPI D3DPERF_BeginEvent(D3DCOLOR color, const WCHAR *name)
97c2c66affSColin Finck {
98c2c66affSColin Finck     TRACE("color 0x%08x, name %s.\n", color, debugstr_w(name));
99c2c66affSColin Finck 
100c2c66affSColin Finck     return D3DPERF_event_level++;
101c2c66affSColin Finck }
102c2c66affSColin Finck 
103c2c66affSColin Finck /***********************************************************************
104c2c66affSColin Finck  *              D3DPERF_EndEvent (D3D9.@)
105c2c66affSColin Finck  */
D3DPERF_EndEvent(void)106c2c66affSColin Finck int WINAPI D3DPERF_EndEvent(void) {
107c2c66affSColin Finck     TRACE("(void) : stub\n");
108c2c66affSColin Finck 
109c2c66affSColin Finck     return --D3DPERF_event_level;
110c2c66affSColin Finck }
111c2c66affSColin Finck 
112c2c66affSColin Finck /***********************************************************************
113c2c66affSColin Finck  *              D3DPERF_GetStatus (D3D9.@)
114c2c66affSColin Finck  */
D3DPERF_GetStatus(void)115c2c66affSColin Finck DWORD WINAPI D3DPERF_GetStatus(void) {
116c2c66affSColin Finck     FIXME("(void) : stub\n");
117c2c66affSColin Finck 
118c2c66affSColin Finck     return 0;
119c2c66affSColin Finck }
120c2c66affSColin Finck 
121c2c66affSColin Finck /***********************************************************************
122c2c66affSColin Finck  *              D3DPERF_SetOptions (D3D9.@)
123c2c66affSColin Finck  *
124c2c66affSColin Finck  */
D3DPERF_SetOptions(DWORD options)125c2c66affSColin Finck void WINAPI D3DPERF_SetOptions(DWORD options)
126c2c66affSColin Finck {
127c2c66affSColin Finck   FIXME("(%#x) : stub\n", options);
128c2c66affSColin Finck }
129c2c66affSColin Finck 
130c2c66affSColin Finck /***********************************************************************
131c2c66affSColin Finck  *              D3DPERF_QueryRepeatFrame (D3D9.@)
132c2c66affSColin Finck  */
D3DPERF_QueryRepeatFrame(void)133c2c66affSColin Finck BOOL WINAPI D3DPERF_QueryRepeatFrame(void) {
134c2c66affSColin Finck     FIXME("(void) : stub\n");
135c2c66affSColin Finck 
136c2c66affSColin Finck     return FALSE;
137c2c66affSColin Finck }
138c2c66affSColin Finck 
139c2c66affSColin Finck /***********************************************************************
140c2c66affSColin Finck  *              D3DPERF_SetMarker (D3D9.@)
141c2c66affSColin Finck  */
D3DPERF_SetMarker(D3DCOLOR color,const WCHAR * name)142c2c66affSColin Finck void WINAPI D3DPERF_SetMarker(D3DCOLOR color, const WCHAR *name)
143c2c66affSColin Finck {
144c2c66affSColin Finck     FIXME("color 0x%08x, name %s stub!\n", color, debugstr_w(name));
145c2c66affSColin Finck }
146c2c66affSColin Finck 
147c2c66affSColin Finck /***********************************************************************
148c2c66affSColin Finck  *              D3DPERF_SetRegion (D3D9.@)
149c2c66affSColin Finck  */
D3DPERF_SetRegion(D3DCOLOR color,const WCHAR * name)150c2c66affSColin Finck void WINAPI D3DPERF_SetRegion(D3DCOLOR color, const WCHAR *name)
151c2c66affSColin Finck {
152c2c66affSColin Finck     FIXME("color 0x%08x, name %s stub!\n", color, debugstr_w(name));
153c2c66affSColin Finck }
154c2c66affSColin Finck 
d3d9_resource_cleanup(struct d3d9_resource * resource)155c2c66affSColin Finck void d3d9_resource_cleanup(struct d3d9_resource *resource)
156c2c66affSColin Finck {
157c2c66affSColin Finck     wined3d_private_store_cleanup(&resource->private_store);
158c2c66affSColin Finck }
159c2c66affSColin Finck 
d3d9_resource_free_private_data(struct d3d9_resource * resource,const GUID * guid)160c2c66affSColin Finck HRESULT d3d9_resource_free_private_data(struct d3d9_resource *resource, const GUID *guid)
161c2c66affSColin Finck {
162c2c66affSColin Finck     struct wined3d_private_data *entry;
163c2c66affSColin Finck 
164c2c66affSColin Finck     wined3d_mutex_lock();
165c2c66affSColin Finck     entry = wined3d_private_store_get_private_data(&resource->private_store, guid);
166c2c66affSColin Finck     if (!entry)
167c2c66affSColin Finck     {
168c2c66affSColin Finck         wined3d_mutex_unlock();
169c2c66affSColin Finck         return D3DERR_NOTFOUND;
170c2c66affSColin Finck     }
171c2c66affSColin Finck 
172c2c66affSColin Finck     wined3d_private_store_free_private_data(&resource->private_store, entry);
173c2c66affSColin Finck     wined3d_mutex_unlock();
174c2c66affSColin Finck 
175c2c66affSColin Finck     return D3D_OK;
176c2c66affSColin Finck }
177c2c66affSColin Finck 
d3d9_resource_get_private_data(struct d3d9_resource * resource,const GUID * guid,void * data,DWORD * data_size)178c2c66affSColin Finck HRESULT d3d9_resource_get_private_data(struct d3d9_resource *resource, const GUID *guid,
179c2c66affSColin Finck         void *data, DWORD *data_size)
180c2c66affSColin Finck {
181c2c66affSColin Finck     const struct wined3d_private_data *stored_data;
182c2c66affSColin Finck     DWORD size_in;
183c2c66affSColin Finck     HRESULT hr;
184c2c66affSColin Finck 
185c2c66affSColin Finck     wined3d_mutex_lock();
186c2c66affSColin Finck     stored_data = wined3d_private_store_get_private_data(&resource->private_store, guid);
187c2c66affSColin Finck     if (!stored_data)
188c2c66affSColin Finck     {
189c2c66affSColin Finck         hr = D3DERR_NOTFOUND;
190c2c66affSColin Finck         goto done;
191c2c66affSColin Finck     }
192c2c66affSColin Finck 
193c2c66affSColin Finck     size_in = *data_size;
194c2c66affSColin Finck     *data_size = stored_data->size;
195c2c66affSColin Finck     if (!data)
196c2c66affSColin Finck     {
197c2c66affSColin Finck         hr = D3D_OK;
198c2c66affSColin Finck         goto done;
199c2c66affSColin Finck     }
200c2c66affSColin Finck     if (size_in < stored_data->size)
201c2c66affSColin Finck     {
202c2c66affSColin Finck         hr = D3DERR_MOREDATA;
203c2c66affSColin Finck         goto done;
204c2c66affSColin Finck     }
205c2c66affSColin Finck 
206c2c66affSColin Finck     if (stored_data->flags & WINED3DSPD_IUNKNOWN)
207c2c66affSColin Finck         IUnknown_AddRef(stored_data->content.object);
208c2c66affSColin Finck     memcpy(data, stored_data->content.data, stored_data->size);
209c2c66affSColin Finck     hr = D3D_OK;
210c2c66affSColin Finck 
211c2c66affSColin Finck done:
212c2c66affSColin Finck     wined3d_mutex_unlock();
213c2c66affSColin Finck     return hr;
214c2c66affSColin Finck }
215c2c66affSColin Finck 
d3d9_resource_init(struct d3d9_resource * resource)216c2c66affSColin Finck void d3d9_resource_init(struct d3d9_resource *resource)
217c2c66affSColin Finck {
218c2c66affSColin Finck     resource->refcount = 1;
219c2c66affSColin Finck     wined3d_private_store_init(&resource->private_store);
220c2c66affSColin Finck }
221c2c66affSColin Finck 
d3d9_resource_set_private_data(struct d3d9_resource * resource,const GUID * guid,const void * data,DWORD data_size,DWORD flags)222c2c66affSColin Finck HRESULT d3d9_resource_set_private_data(struct d3d9_resource *resource, const GUID *guid,
223c2c66affSColin Finck         const void *data, DWORD data_size, DWORD flags)
224c2c66affSColin Finck {
225c2c66affSColin Finck     HRESULT hr;
226c2c66affSColin Finck 
227c2c66affSColin Finck     wined3d_mutex_lock();
228c2c66affSColin Finck     hr = wined3d_private_store_set_private_data(&resource->private_store, guid, data, data_size, flags);
229c2c66affSColin Finck     wined3d_mutex_unlock();
230c2c66affSColin Finck     return hr;
231c2c66affSColin Finck }
232