1 | /* $Id: server_texture.c 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox crOpenGL - teximage functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-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 "chromium.h"
|
---|
19 | #include "cr_error.h"
|
---|
20 | #include "server_dispatch.h"
|
---|
21 | #include "server.h"
|
---|
22 | #include "cr_mem.h"
|
---|
23 |
|
---|
24 | #define CR_NOTHING()
|
---|
25 |
|
---|
26 | #define CR_CHECKPTR(name) \
|
---|
27 | if (!realptr) \
|
---|
28 | { \
|
---|
29 | crWarning(#name " with NULL ptr, ignored!"); \
|
---|
30 | return; \
|
---|
31 | }
|
---|
32 |
|
---|
33 | #if !defined(CR_STATE_NO_TEXTURE_IMAGE_STORE)
|
---|
34 | # define CR_FIXPTR() (uintptr_t) realptr += (uintptr_t) cr_server.head_spu->dispatch_table.MapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_READ_ONLY_ARB)
|
---|
35 | #else
|
---|
36 | # define CR_FIXPTR()
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #if defined(CR_ARB_pixel_buffer_object)
|
---|
40 | # define CR_CHECKBUFFER(name, checkptr) \
|
---|
41 | if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB)) \
|
---|
42 | { \
|
---|
43 | CR_FIXPTR(); \
|
---|
44 | } \
|
---|
45 | else \
|
---|
46 | { \
|
---|
47 | checkptr \
|
---|
48 | }
|
---|
49 | #else
|
---|
50 | # define CR_CHECKBUFFER(name, checkptr) checkptr
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | #if defined(CR_ARB_pixel_buffer_object) && !defined(CR_STATE_NO_TEXTURE_IMAGE_STORE)
|
---|
54 | # define CR_FINISHBUFFER() \
|
---|
55 | if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB)) \
|
---|
56 | { \
|
---|
57 | if (!cr_server.head_spu->dispatch_table.UnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB)) \
|
---|
58 | { \
|
---|
59 | crWarning("UnmapBufferARB failed"); \
|
---|
60 | } \
|
---|
61 | }
|
---|
62 | #else
|
---|
63 | #define CR_FINISHBUFFER()
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | #define CR_FUNC_SUBIMAGE(name, def, call, ptrname) \
|
---|
67 | void SERVER_DISPATCH_APIENTRY \
|
---|
68 | crServerDispatch##name def \
|
---|
69 | { \
|
---|
70 | const GLvoid *realptr = ptrname; \
|
---|
71 | CR_CHECKBUFFER(name, CR_CHECKPTR(name)) \
|
---|
72 | crState##name call; \
|
---|
73 | CR_FINISHBUFFER() \
|
---|
74 | realptr = ptrname; \
|
---|
75 | cr_server.head_spu->dispatch_table.name call; \
|
---|
76 | }
|
---|
77 |
|
---|
78 | #define CR_FUNC_IMAGE(name, def, call, ptrname) \
|
---|
79 | void SERVER_DISPATCH_APIENTRY \
|
---|
80 | crServerDispatch##name def \
|
---|
81 | { \
|
---|
82 | const GLvoid *realptr = ptrname; \
|
---|
83 | CR_CHECKBUFFER(name, CR_NOTHING()) \
|
---|
84 | crState##name call; \
|
---|
85 | CR_FINISHBUFFER() \
|
---|
86 | realptr = ptrname; \
|
---|
87 | cr_server.head_spu->dispatch_table.name call; \
|
---|
88 | }
|
---|
89 |
|
---|
90 | #if defined(CR_ARB_texture_compression)
|
---|
91 | CR_FUNC_SUBIMAGE(CompressedTexSubImage1DARB,
|
---|
92 | (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid * data),
|
---|
93 | (target, level, xoffset, width, format, imagesize, realptr), data)
|
---|
94 |
|
---|
95 | CR_FUNC_SUBIMAGE(CompressedTexSubImage2DARB,
|
---|
96 | (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid * data),
|
---|
97 | (target, level, xoffset, yoffset, width, height, format, imagesize, realptr), data)
|
---|
98 |
|
---|
99 | CR_FUNC_SUBIMAGE(CompressedTexSubImage3DARB,
|
---|
100 | (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imagesize, const GLvoid * data),
|
---|
101 | (target, level, xoffset, yoffset, zoffset, width, height, depth, format, imagesize, realptr), data)
|
---|
102 |
|
---|
103 | CR_FUNC_IMAGE(CompressedTexImage1DARB,
|
---|
104 | (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid * data),
|
---|
105 | (target, level, internalFormat, width, border, imagesize, realptr), data)
|
---|
106 |
|
---|
107 | CR_FUNC_IMAGE(CompressedTexImage2DARB,
|
---|
108 | (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid * data),
|
---|
109 | (target, level, internalFormat, width, height, border, imagesize, realptr), data)
|
---|
110 |
|
---|
111 | CR_FUNC_IMAGE(CompressedTexImage3DARB,
|
---|
112 | (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid * data),
|
---|
113 | (target, level, internalFormat, width, height, depth, border, imagesize, realptr), data)
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | CR_FUNC_SUBIMAGE(TexSubImage1D,
|
---|
117 | (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid * pixels),
|
---|
118 | (target, level, xoffset, width, format, type, realptr), pixels)
|
---|
119 |
|
---|
120 | CR_FUNC_SUBIMAGE(TexSubImage2D,
|
---|
121 | (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels),
|
---|
122 | (target, level, xoffset, yoffset, width, height, format, type, realptr), pixels)
|
---|
123 |
|
---|
124 | CR_FUNC_SUBIMAGE(TexSubImage3D,
|
---|
125 | (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * pixels),
|
---|
126 | (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, realptr), pixels)
|
---|
127 |
|
---|
128 | CR_FUNC_IMAGE(TexImage1D,
|
---|
129 | (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
|
---|
130 | (target, level, internalFormat, width, border, format, type, realptr), pixels)
|
---|
131 |
|
---|
132 | CR_FUNC_IMAGE(TexImage2D,
|
---|
133 | (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
|
---|
134 | (target, level, internalFormat, width, height, border, format, type, realptr), pixels)
|
---|
135 |
|
---|
136 | CR_FUNC_IMAGE(TexImage3D,
|
---|
137 | (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
|
---|
138 | (target, level, internalFormat, width, height, depth, border, format, type, realptr), pixels)
|
---|
139 |
|
---|
140 |
|
---|
141 | void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvf( GLenum target, GLenum pname, GLfloat param )
|
---|
142 | {
|
---|
143 | crStateTexEnvf( target, pname, param );
|
---|
144 | if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
|
---|
145 | CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvf( target, pname, param ););
|
---|
146 | }
|
---|
147 |
|
---|
148 | void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvfv( GLenum target, GLenum pname, const GLfloat * params )
|
---|
149 | {
|
---|
150 | crStateTexEnvfv( target, pname, params );
|
---|
151 | if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
|
---|
152 | CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvfv( target, pname, params ););
|
---|
153 | }
|
---|
154 |
|
---|
155 | void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvi( GLenum target, GLenum pname, GLint param )
|
---|
156 | {
|
---|
157 | crStateTexEnvi( target, pname, param );
|
---|
158 | if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
|
---|
159 | CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvi( target, pname, param ););
|
---|
160 | }
|
---|
161 |
|
---|
162 | void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnviv( GLenum target, GLenum pname, const GLint * params )
|
---|
163 | {
|
---|
164 | crStateTexEnviv( target, pname, params );
|
---|
165 | if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
|
---|
166 | CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnviv( target, pname, params ););
|
---|
167 | }
|
---|
168 |
|
---|
169 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetTexEnvfv( GLenum target, GLenum pname, GLfloat * params )
|
---|
170 | {
|
---|
171 | GLfloat local_params[4];
|
---|
172 | (void) params;
|
---|
173 | if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
|
---|
174 | cr_server.head_spu->dispatch_table.GetTexEnvfv( target, pname, local_params );
|
---|
175 | else
|
---|
176 | crStateGetTexEnvfv( target, pname, local_params );
|
---|
177 |
|
---|
178 | crServerReturnValue( &(local_params[0]), crStateHlpComponentsCount(pname)*sizeof (GLfloat) );
|
---|
179 | }
|
---|
180 |
|
---|
181 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetTexEnviv( GLenum target, GLenum pname, GLint * params )
|
---|
182 | {
|
---|
183 | GLint local_params[4];
|
---|
184 | (void) params;
|
---|
185 | if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
|
---|
186 | cr_server.head_spu->dispatch_table.GetTexEnviv( target, pname, local_params );
|
---|
187 | else
|
---|
188 | crStateGetTexEnviv( target, pname, local_params );
|
---|
189 |
|
---|
190 | crServerReturnValue( &(local_params[0]), crStateHlpComponentsCount(pname)*sizeof (GLint) );
|
---|
191 | }
|
---|
192 |
|
---|
193 | void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
|
---|
194 | {
|
---|
195 | crStateBindTexture( target, texture );
|
---|
196 | cr_server.head_spu->dispatch_table.BindTexture(target, crStateGetTextureHWID(texture));
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteTextures( GLsizei n, const GLuint *textures)
|
---|
201 | {
|
---|
202 | GLuint *newTextures;
|
---|
203 | GLint i;
|
---|
204 |
|
---|
205 | if (n >= UINT32_MAX / sizeof(GLuint))
|
---|
206 | {
|
---|
207 | crError("crServerDispatchDeleteTextures: parameter 'n' is out of range");
|
---|
208 | return;
|
---|
209 | }
|
---|
210 |
|
---|
211 | newTextures = (GLuint *)crAlloc(n * sizeof(GLuint));
|
---|
212 |
|
---|
213 | if (!newTextures)
|
---|
214 | {
|
---|
215 | crError("crServerDispatchDeleteTextures: out of memory");
|
---|
216 | return;
|
---|
217 | }
|
---|
218 |
|
---|
219 | for (i = 0; i < n; i++)
|
---|
220 | {
|
---|
221 | newTextures[i] = crStateGetTextureHWID(textures[i]);
|
---|
222 | }
|
---|
223 |
|
---|
224 | // for (i = 0; i < n; ++i)
|
---|
225 | // {
|
---|
226 | // crDebug("DeleteTexture: %d, pid %d, ctx %d", textures[i], (uint32_t)cr_server.curClient->pid, cr_server.currentCtxInfo->pContext->id);
|
---|
227 | // }
|
---|
228 |
|
---|
229 |
|
---|
230 | crStateDeleteTextures(n, textures);
|
---|
231 | cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
|
---|
232 | crFree(newTextures);
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
|
---|
237 | {
|
---|
238 | GLuint *newTextures;
|
---|
239 | GLint i;
|
---|
240 |
|
---|
241 | if (n >= INT32_MAX / sizeof(GLuint))
|
---|
242 | {
|
---|
243 | crError("crServerDispatchPrioritizeTextures: parameter 'n' is out of range");
|
---|
244 | return;
|
---|
245 | }
|
---|
246 |
|
---|
247 | newTextures = (GLuint *)crAlloc(n * sizeof(GLuint));
|
---|
248 |
|
---|
249 | if (!newTextures)
|
---|
250 | {
|
---|
251 | crError("crServerDispatchPrioritizeTextures: out of memory");
|
---|
252 | return;
|
---|
253 | }
|
---|
254 |
|
---|
255 | crStatePrioritizeTextures(n, textures, priorities);
|
---|
256 |
|
---|
257 | for (i = 0; i < n; i++)
|
---|
258 | {
|
---|
259 | newTextures[i] = crStateGetTextureHWID(textures[i]);
|
---|
260 | }
|
---|
261 |
|
---|
262 | cr_server.head_spu->dispatch_table.PrioritizeTextures(n, newTextures, priorities);
|
---|
263 | crFree(newTextures);
|
---|
264 | }
|
---|
265 |
|
---|
266 |
|
---|
267 | /** @todo will fail for textures loaded from snapshot */
|
---|
268 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsTexture( GLuint texture )
|
---|
269 | {
|
---|
270 | GLboolean retval;
|
---|
271 | retval = cr_server.head_spu->dispatch_table.IsTexture(crStateGetTextureHWID(texture));
|
---|
272 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
273 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
278 | crServerDispatchAreTexturesResident(GLsizei n, const GLuint *textures,
|
---|
279 | GLboolean *residences)
|
---|
280 | {
|
---|
281 | GLboolean retval = GL_FALSE;
|
---|
282 | GLsizei i;
|
---|
283 | GLboolean *res;
|
---|
284 | GLuint *textures2;
|
---|
285 | (void) residences;
|
---|
286 |
|
---|
287 | if (n >= INT32_MAX / sizeof(GLuint))
|
---|
288 | {
|
---|
289 | crError("crServerDispatchAreTexturesResident: parameter 'n' is out of range");
|
---|
290 | return GL_FALSE;
|
---|
291 | }
|
---|
292 |
|
---|
293 | res = (GLboolean *)crCalloc(n * sizeof(GLboolean));
|
---|
294 | if (!res)
|
---|
295 | {
|
---|
296 | crError("crServerDispatchAreTexturesResident: out of memory");
|
---|
297 | return GL_FALSE;
|
---|
298 | }
|
---|
299 |
|
---|
300 | textures2 = (GLuint *)crAlloc(n * sizeof(GLuint));
|
---|
301 |
|
---|
302 | if (!textures2)
|
---|
303 | {
|
---|
304 | crError("crServerDispatchAreTexturesResident: out of memory");
|
---|
305 | crFree(res);
|
---|
306 | return GL_FALSE;
|
---|
307 | }
|
---|
308 |
|
---|
309 | for (i = 0; i < n; i++)
|
---|
310 | {
|
---|
311 | textures2[i] = crStateGetTextureHWID(textures[i]);
|
---|
312 | }
|
---|
313 | retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
|
---|
314 |
|
---|
315 | crFree(textures2);
|
---|
316 |
|
---|
317 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
318 |
|
---|
319 | crFree(res);
|
---|
320 |
|
---|
321 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
322 | }
|
---|
323 |
|
---|