VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getshaders.c@ 77235

Last change on this file since 77235 was 76787, checked in by vboxsync, 6 years ago

3D: Parameters validation corrected, bugref:9327

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 11.9 KB
Line 
1/* $Id: server_getshaders.c 76787 2019-01-11 20:00:15Z vboxsync $ */
2/** @file
3 * VBox OpenGL GLSL related get functions
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "cr_spu.h"
19#include "chromium.h"
20#include "cr_error.h"
21#include "cr_mem.h"
22#include "cr_net.h"
23#include "server_dispatch.h"
24#include "server.h"
25
26#include <iprt/assert.h>
27
28#ifdef CR_OPENGL_VERSION_2_0
29
30typedef struct _crGetActive_t
31{
32 GLsizei length;
33 GLint size;
34 GLenum type;
35} crGetActive_t;
36
37void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
38{
39 crGetActive_t *pLocal = NULL;
40
41 if (bufSize > 0 && bufSize < INT32_MAX / 2)
42 pLocal = (crGetActive_t*)crCalloc(bufSize + sizeof(crGetActive_t));
43
44 if (!pLocal)
45 {
46 crGetActive_t zero;
47 zero.length = 0;
48 crServerReturnValue(&zero, sizeof(zero));
49 return;
50 }
51
52 cr_server.head_spu->dispatch_table.GetActiveAttrib(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
53 crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
54 crFree(pLocal);
55}
56
57void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
58{
59 crGetActive_t *pLocal = NULL;
60
61 if (bufSize > 0 && bufSize < INT32_MAX / 2)
62 pLocal = (crGetActive_t*) crCalloc(bufSize + sizeof(crGetActive_t));
63
64 if (!pLocal)
65 {
66 crGetActive_t zero;
67 zero.length = 0;
68 crServerReturnValue(&zero, sizeof(zero));
69 return;
70 }
71
72 cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
73 crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
74 crFree(pLocal);
75}
76
77void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders)
78{
79 GLsizei *pLocal = NULL;
80
81 if (maxCount > 0 && maxCount < INT32_MAX / sizeof(GLuint) / 2)
82 pLocal = (GLsizei*) crCalloc(maxCount * sizeof(GLuint) + sizeof(GLsizei));
83
84 if (!pLocal)
85 {
86 GLsizei zero=0;
87 crServerReturnValue(&zero, sizeof(zero));
88 return;
89 }
90 /* initial (fallback )value */
91 *pLocal = 0;
92 cr_server.head_spu->dispatch_table.GetAttachedShaders(crStateGetProgramHWID(program), maxCount, pLocal, (GLuint*)&pLocal[1]);
93
94 {
95 GLsizei i;
96 GLuint *ids=(GLuint*)&pLocal[1];
97
98 for (i=0; i<*pLocal; ++i)
99 ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
100 }
101
102 crServerReturnValue(pLocal, (*pLocal)*sizeof(GLuint)+sizeof(GLsizei));
103 crFree(pLocal);
104}
105
106void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedObjectsARB(VBoxGLhandleARB containerObj, GLsizei maxCount, GLsizei * count, VBoxGLhandleARB * obj)
107{
108 GLsizei *pLocal = NULL;
109
110 if (maxCount > 0 && maxCount < INT32_MAX / sizeof(VBoxGLhandleARB) / 2)
111 pLocal = (GLsizei*) crCalloc(maxCount * sizeof(VBoxGLhandleARB) + sizeof(GLsizei));
112
113 if (!pLocal)
114 {
115 GLsizei zero=0;
116 crServerReturnValue(&zero, sizeof(zero));
117 return;
118 }
119 /* initial (fallback )value */
120 *pLocal = 0;
121 cr_server.head_spu->dispatch_table.GetAttachedObjectsARB(crStateGetProgramHWID(containerObj), maxCount, pLocal, (VBoxGLhandleARB*)&pLocal[1]);
122
123 {
124 GLsizei i;
125 GLuint *ids=(GLuint*)&pLocal[1];
126
127 for (i=0; i<*pLocal; ++i)
128 ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
129 }
130
131 crServerReturnValue(pLocal, (*pLocal)*sizeof(VBoxGLhandleARB)+sizeof(GLsizei));
132 crFree(pLocal);
133}
134
135AssertCompile(sizeof(GLsizei) == 4);
136
137void SERVER_DISPATCH_APIENTRY crServerDispatchGetInfoLogARB(VBoxGLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog)
138{
139 GLsizei *pLocal = NULL;
140 GLuint hwid;
141
142 if (maxLength > 0 && maxLength < INT32_MAX / 2)
143 pLocal = (GLsizei*) crCalloc(maxLength + sizeof(GLsizei));
144
145 if (!pLocal)
146 {
147 GLsizei zero=0;
148 crServerReturnValue(&zero, sizeof(zero));
149 return;
150 }
151 /* initial (fallback )value */
152 *pLocal = 0;
153 /** @todo recheck*/
154 hwid = crStateGetProgramHWID(obj);
155 if (!hwid) hwid = crStateGetShaderHWID(obj);
156 cr_server.head_spu->dispatch_table.GetInfoLogARB(hwid, maxLength, pLocal, (char*)&pLocal[1]);
157 CRASSERT((*pLocal) <= maxLength);
158 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
159 crFree(pLocal);
160}
161
162void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog)
163{
164 GLsizei *pLocal = NULL;
165
166 if (bufSize > 0 && bufSize < INT32_MAX / 2)
167 pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
168
169 if (!pLocal)
170 {
171 GLsizei zero=0;
172 crServerReturnValue(&zero, sizeof(zero));
173 return;
174 }
175 /* initial (fallback )value */
176 *pLocal = 0;
177 cr_server.head_spu->dispatch_table.GetShaderInfoLog(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
178 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
179 crFree(pLocal);
180}
181
182void SERVER_DISPATCH_APIENTRY crServerDispatchGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog)
183{
184 GLsizei *pLocal = NULL;
185
186 if (bufSize > 0 && bufSize < INT32_MAX / 2)
187 pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
188
189 if (!pLocal)
190 {
191 GLsizei zero=0;
192 crServerReturnValue(&zero, sizeof(zero));
193 return;
194 }
195 /* initial (fallback )value */
196 *pLocal = 0;
197 cr_server.head_spu->dispatch_table.GetProgramInfoLog(crStateGetProgramHWID(program), bufSize, pLocal, (char*)&pLocal[1]);
198 CRASSERT(pLocal[0] <= bufSize);
199 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
200 crFree(pLocal);
201}
202
203void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, char *source)
204{
205 GLsizei *pLocal = NULL;
206
207 if (bufSize > 0 && bufSize < INT32_MAX / 2)
208 pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
209
210 if (!pLocal)
211 {
212 GLsizei zero=0;
213 crServerReturnValue(&zero, sizeof(zero));
214 return;
215 }
216 /* initial (fallback )value */
217 *pLocal = 0;
218 cr_server.head_spu->dispatch_table.GetShaderSource(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
219 CRASSERT(pLocal[0] <= bufSize);
220 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
221 crFree(pLocal);
222}
223
224void SERVER_DISPATCH_APIENTRY
225crServerDispatchGetUniformsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
226{
227 GLsizei *pLocal = NULL;
228
229 (void) cbData;
230 (void) pData;
231
232 if (maxcbData > 0 && maxcbData < INT32_MAX / 2)
233 pLocal = (GLsizei*) crCalloc(maxcbData + sizeof(GLsizei));
234
235 if (!pLocal)
236 {
237 GLsizei zero=0;
238 crServerReturnValue(&zero, sizeof(zero));
239 return;
240 }
241
242 /* initial (fallback )value */
243 *pLocal = 0;
244 crStateGLSLProgramCacheUniforms(program, maxcbData, pLocal, (char*)&pLocal[1]);
245
246 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
247 crFree(pLocal);
248}
249
250void SERVER_DISPATCH_APIENTRY
251crServerDispatchGetAttribsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
252{
253 GLsizei *pLocal = NULL;
254
255 (void) cbData;
256 (void) pData;
257
258 if (maxcbData > 0 && maxcbData < INT32_MAX / 2)
259 pLocal = (GLsizei*) crCalloc(maxcbData + sizeof(GLsizei));
260
261 if (!pLocal)
262 {
263 GLsizei zero=0;
264 crServerReturnValue(&zero, sizeof(zero));
265 return;
266 }
267
268 /* initial (fallback )value */
269 *pLocal = 0;
270 crStateGLSLProgramCacheAttribs(program, maxcbData, pLocal, (char*)&pLocal[1]);
271
272 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
273 crFree(pLocal);
274}
275
276static GLint __GetUniformSize(GLuint program, GLint location)
277{
278 GLint size = 0;
279 GLenum type = 0;
280
281 /** @todo check if index and location is the same*/
282 cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), location, 0, NULL, &size, &type, NULL);
283
284 return crStateGetUniformSize(type);
285}
286
287void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformfv(GLuint program, GLint location, GLfloat *params)
288{
289 int size = __GetUniformSize(program, location) * sizeof(GLfloat);
290 GLfloat *pLocal;
291
292 pLocal = (GLfloat*) crCalloc(size);
293 if (!pLocal)
294 {
295 GLsizei zero=0;
296 crServerReturnValue(&zero, sizeof(zero));
297 return;
298 }
299
300 cr_server.head_spu->dispatch_table.GetUniformfv(crStateGetProgramHWID(program), location, pLocal);
301
302 crServerReturnValue(pLocal, size);
303 crFree(pLocal);
304}
305
306void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformiv(GLuint program, GLint location, GLint *params)
307{
308 int size = __GetUniformSize(program, location) * sizeof(GLint);
309 GLint *pLocal;
310
311 pLocal = (GLint*) crCalloc(size);
312 if (!pLocal)
313 {
314 GLsizei zero=0;
315 crServerReturnValue(&zero, sizeof(zero));
316 return;
317 }
318
319 cr_server.head_spu->dispatch_table.GetUniformiv(crStateGetProgramHWID(program), location, pLocal);
320
321 crServerReturnValue(pLocal, size);
322 crFree(pLocal);
323}
324
325GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateShader(GLenum type)
326{
327 GLuint retval, hwVal;
328 hwVal = cr_server.head_spu->dispatch_table.CreateShader(type);
329 retval = crStateCreateShader(hwVal, type);
330 crServerReturnValue(&retval, sizeof(retval));
331 return retval; /* ignored */
332}
333
334GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateProgram(void)
335{
336 GLuint retval, hwVal;
337 hwVal = cr_server.head_spu->dispatch_table.CreateProgram();
338 retval = crStateCreateProgram(hwVal);
339 crServerReturnValue(&retval, sizeof(retval));
340 return retval; /* ignored */
341}
342
343GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsShader(GLuint shader)
344{
345 GLboolean retval;
346 retval = cr_server.head_spu->dispatch_table.IsShader(crStateGetShaderHWID(shader));
347 crServerReturnValue(&retval, sizeof(retval));
348 return retval; /* ignored */
349}
350
351GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgram(GLuint program)
352{
353 GLboolean retval;
354 retval = cr_server.head_spu->dispatch_table.IsProgram(crStateGetProgramHWID(program));
355 crServerReturnValue(&retval, sizeof(retval));
356 return retval; /* ignored */
357}
358
359void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterfvARB( VBoxGLhandleARB obj, GLenum pname, GLfloat * params )
360{
361 GLfloat local_params[1];
362 GLuint hwid = crStateGetProgramHWID(obj);
363 (void) params;
364
365 if (!hwid)
366 {
367 hwid = crStateGetShaderHWID(obj);
368 if (!hwid)
369 {
370 crWarning("Unknown object %i, in crServerDispatchGetObjectParameterfvARB", obj);
371 }
372 }
373
374 cr_server.head_spu->dispatch_table.GetObjectParameterfvARB( hwid, pname, local_params );
375 crServerReturnValue( &(local_params[0]), 1*sizeof(GLfloat) );
376}
377
378void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterivARB( VBoxGLhandleARB obj, GLenum pname, GLint * params )
379{
380 GLint local_params[1];
381 GLuint hwid = crStateGetProgramHWID(obj);
382 if (!hwid)
383 {
384 hwid = crStateGetShaderHWID(obj);
385 if (!hwid)
386 {
387 crWarning("Unknown object %i, in crServerDispatchGetObjectParameterivARB", obj);
388 }
389 }
390
391 (void) params;
392 cr_server.head_spu->dispatch_table.GetObjectParameterivARB( hwid, pname, local_params );
393 crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
394}
395#endif /* #ifdef CR_OPENGL_VERSION_2_0 */
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