xref: /reactos/dll/directx/wine/d3d8/d3d8_main.c (revision 1734f297)
1 /*
2  * Direct3D 8
3  *
4  * Copyright 2005 Oliver Stieber
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21 
22 #include "config.h"
23 #include "initguid.h"
24 #include "d3d8_private.h"
25 #include "wine/debug.h"
26 
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
28 
29 HRESULT WINAPI D3D8GetSWInfo(void) {
30     FIXME("(void): stub\n");
31     return 0;
32 }
33 
34 void WINAPI DebugSetMute(void) {
35     /* nothing to do */
36 }
37 
38 IDirect3D8 * WINAPI DECLSPEC_HOTPATCH Direct3DCreate8(UINT sdk_version)
39 {
40     struct d3d8 *object;
41 
42     TRACE("sdk_version %#x.\n", sdk_version);
43 
44     if (!(object = heap_alloc_zero(sizeof(*object))))
45         return NULL;
46 
47     if (!d3d8_init(object))
48     {
49         WARN("Failed to initialize d3d8.\n");
50         heap_free(object);
51         return NULL;
52     }
53 
54     TRACE("Created d3d8 object %p.\n", object);
55 
56     return &object->IDirect3D8_iface;
57 }
58 
59 /***********************************************************************
60  *              ValidateVertexShader (D3D8.@)
61  */
62 HRESULT WINAPI ValidateVertexShader(DWORD *vertexshader, DWORD *reserved1, DWORD *reserved2,
63                                     BOOL return_error, char **errors)
64 {
65     const char *message = "";
66     HRESULT hr = E_FAIL;
67 
68     TRACE("(%p %p %p %d %p): semi-stub\n", vertexshader, reserved1, reserved2, return_error, errors);
69 
70     if (!vertexshader)
71     {
72         message = "(Global Validation Error) Version Token: Code pointer cannot be NULL.\n";
73         goto done;
74     }
75 
76     switch (*vertexshader)
77     {
78         case 0xFFFE0101:
79         case 0xFFFE0100:
80             hr = S_OK;
81             break;
82 
83         default:
84             WARN("Invalid shader version token %#x.\n", *vertexshader);
85             message = "(Global Validation Error) Version Token: Unsupported vertex shader version.\n";
86     }
87 
88 done:
89     if (!return_error) message = "";
90     if (errors && (*errors = HeapAlloc(GetProcessHeap(), 0, strlen(message) + 1)))
91         strcpy(*errors, message);
92 
93     return hr;
94 }
95 
96 /***********************************************************************
97  *              ValidatePixelShader (D3D8.@)
98  */
99 HRESULT WINAPI ValidatePixelShader(DWORD *pixelshader, DWORD *reserved1, BOOL return_error, char **errors)
100 {
101     const char *message = "";
102     HRESULT hr = E_FAIL;
103 
104     TRACE("(%p %p %d %p): semi-stub\n", pixelshader, reserved1, return_error, errors);
105 
106     if (!pixelshader)
107         return E_FAIL;
108 
109    switch (*pixelshader)
110    {
111         case 0xFFFF0100:
112         case 0xFFFF0101:
113         case 0xFFFF0102:
114         case 0xFFFF0103:
115         case 0xFFFF0104:
116             hr = S_OK;
117             break;
118         default:
119             WARN("Invalid shader version token %#x.\n", *pixelshader);
120             message = "(Global Validation Error) Version Token: Unsupported pixel shader version.\n";
121     }
122 
123     if (!return_error) message = "";
124     if (errors && (*errors = HeapAlloc(GetProcessHeap(), 0, strlen(message) + 1)))
125         strcpy(*errors, message);
126 
127     return hr;
128 }
129 
130 void d3d8_resource_cleanup(struct d3d8_resource *resource)
131 {
132     wined3d_private_store_cleanup(&resource->private_store);
133 }
134 
135 HRESULT d3d8_resource_free_private_data(struct d3d8_resource *resource, const GUID *guid)
136 {
137     struct wined3d_private_data *entry;
138 
139     wined3d_mutex_lock();
140     entry = wined3d_private_store_get_private_data(&resource->private_store, guid);
141     if (!entry)
142     {
143         wined3d_mutex_unlock();
144         return D3DERR_NOTFOUND;
145     }
146 
147     wined3d_private_store_free_private_data(&resource->private_store, entry);
148     wined3d_mutex_unlock();
149 
150     return D3D_OK;
151 }
152 
153 HRESULT d3d8_resource_get_private_data(struct d3d8_resource *resource, const GUID *guid,
154         void *data, DWORD *data_size)
155 {
156     const struct wined3d_private_data *stored_data;
157     DWORD size_in;
158     HRESULT hr;
159 
160     wined3d_mutex_lock();
161     stored_data = wined3d_private_store_get_private_data(&resource->private_store, guid);
162     if (!stored_data)
163     {
164         hr = D3DERR_NOTFOUND;
165         goto done;
166     }
167 
168     size_in = *data_size;
169     *data_size = stored_data->size;
170     if (!data)
171     {
172         hr = D3D_OK;
173         goto done;
174     }
175     if (size_in < stored_data->size)
176     {
177         hr = D3DERR_MOREDATA;
178         goto done;
179     }
180 
181     if (stored_data->flags & WINED3DSPD_IUNKNOWN)
182         IUnknown_AddRef(stored_data->content.object);
183     memcpy(data, stored_data->content.data, stored_data->size);
184     hr = D3D_OK;
185 
186 done:
187     wined3d_mutex_unlock();
188     return hr;
189 }
190 
191 void d3d8_resource_init(struct d3d8_resource *resource)
192 {
193     resource->refcount = 1;
194     wined3d_private_store_init(&resource->private_store);
195 }
196 
197 HRESULT d3d8_resource_set_private_data(struct d3d8_resource *resource, const GUID *guid,
198         const void *data, DWORD data_size, DWORD flags)
199 {
200     HRESULT hr;
201 
202     wined3d_mutex_lock();
203     hr = wined3d_private_store_set_private_data(&resource->private_store, guid, data, data_size, flags);
204     wined3d_mutex_unlock();
205     return hr;
206 }
207