VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_texture.cpp@ 78375

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

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1/* $Id: server_texture.cpp 78375 2019-05-03 21:51:02Z 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(&cr_server.StateTracker, 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(&cr_server.StateTracker, 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, state_call, call, ptrname) \
67void SERVER_DISPATCH_APIENTRY \
68crServerDispatch##name def \
69{ \
70 const GLvoid *realptr = ptrname; \
71 CR_CHECKBUFFER(name, CR_CHECKPTR(name)) \
72 crState##name state_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, state_call, call, ptrname) \
79void SERVER_DISPATCH_APIENTRY \
80crServerDispatch##name def \
81{ \
82 const GLvoid *realptr = ptrname; \
83 CR_CHECKBUFFER(name, CR_NOTHING()) \
84 crState##name state_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)
91CR_FUNC_SUBIMAGE(CompressedTexSubImage1DARB,
92 (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid * data),
93 (&cr_server.StateTracker, target, level, xoffset, width, format, imagesize, realptr),
94 (target, level, xoffset, width, format, imagesize, realptr), data)
95
96CR_FUNC_SUBIMAGE(CompressedTexSubImage2DARB,
97 (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid * data),
98 (&cr_server.StateTracker, target, level, xoffset, yoffset, width, height, format, imagesize, realptr),
99 (target, level, xoffset, yoffset, width, height, format, imagesize, realptr), data)
100
101CR_FUNC_SUBIMAGE(CompressedTexSubImage3DARB,
102 (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imagesize, const GLvoid * data),
103 (&cr_server.StateTracker, target, level, xoffset, yoffset, zoffset, width, height, depth, format, imagesize, realptr),
104 (target, level, xoffset, yoffset, zoffset, width, height, depth, format, imagesize, realptr), data)
105
106CR_FUNC_IMAGE(CompressedTexImage1DARB,
107 (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid * data),
108 (&cr_server.StateTracker, target, level, internalFormat, width, border, imagesize, realptr),
109 (target, level, internalFormat, width, border, imagesize, realptr), data)
110
111CR_FUNC_IMAGE(CompressedTexImage2DARB,
112 (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid * data),
113 (&cr_server.StateTracker, target, level, internalFormat, width, height, border, imagesize, realptr),
114 (target, level, internalFormat, width, height, border, imagesize, realptr), data)
115
116CR_FUNC_IMAGE(CompressedTexImage3DARB,
117 (GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid * data),
118 (&cr_server.StateTracker, target, level, internalFormat, width, height, depth, border, imagesize, realptr),
119 (target, level, internalFormat, width, height, depth, border, imagesize, realptr), data)
120#endif
121
122CR_FUNC_SUBIMAGE(TexSubImage1D,
123 (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid * pixels),
124 (&cr_server.StateTracker, target, level, xoffset, width, format, type, realptr),
125 (target, level, xoffset, width, format, type, realptr), pixels)
126
127CR_FUNC_SUBIMAGE(TexSubImage2D,
128 (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels),
129 (&cr_server.StateTracker, target, level, xoffset, yoffset, width, height, format, type, realptr),
130 (target, level, xoffset, yoffset, width, height, format, type, realptr), pixels)
131
132CR_FUNC_SUBIMAGE(TexSubImage3D,
133 (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * pixels),
134 (&cr_server.StateTracker, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, realptr),
135 (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, realptr), pixels)
136
137CR_FUNC_IMAGE(TexImage1D,
138 (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
139 (&cr_server.StateTracker, target, level, internalFormat, width, border, format, type, realptr),
140 (target, level, internalFormat, width, border, format, type, realptr), pixels)
141
142CR_FUNC_IMAGE(TexImage2D,
143 (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
144 (&cr_server.StateTracker, target, level, internalFormat, width, height, border, format, type, realptr),
145 (target, level, internalFormat, width, height, border, format, type, realptr), pixels)
146
147CR_FUNC_IMAGE(TexImage3D,
148 (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * pixels),
149 (&cr_server.StateTracker, target, level, internalFormat, width, height, depth, border, format, type, realptr),
150 (target, level, internalFormat, width, height, depth, border, format, type, realptr), pixels)
151
152
153void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvf( GLenum target, GLenum pname, GLfloat param )
154{
155 crStateTexEnvf(&cr_server.StateTracker, target, pname, param );
156 if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
157 CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvf( target, pname, param ););
158}
159
160void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvfv( GLenum target, GLenum pname, const GLfloat * params )
161{
162 crStateTexEnvfv(&cr_server.StateTracker, target, pname, params );
163 if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
164 CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvfv( target, pname, params ););
165}
166
167void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnvi( GLenum target, GLenum pname, GLint param )
168{
169 crStateTexEnvi(&cr_server.StateTracker, target, pname, param );
170 if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
171 CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnvi( target, pname, param ););
172}
173
174void SERVER_DISPATCH_APIENTRY crServerDispatchTexEnviv( GLenum target, GLenum pname, const GLint * params )
175{
176 crStateTexEnviv(&cr_server.StateTracker, target, pname, params );
177 if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
178 CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.TexEnviv( target, pname, params ););
179}
180
181void SERVER_DISPATCH_APIENTRY crServerDispatchGetTexEnvfv( GLenum target, GLenum pname, GLfloat * params )
182{
183 unsigned int cComponents = 0;
184 GLfloat local_params[4] = {0};
185 (void) params;
186 if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
187 cr_server.head_spu->dispatch_table.GetTexEnvfv( target, pname, local_params );
188 else
189 crStateGetTexEnvfv(&cr_server.StateTracker, target, pname, local_params );
190
191 cComponents = RT_MIN(crStateHlpComponentsCount(pname), RT_ELEMENTS(local_params));
192 crServerReturnValue( &(local_params[0]), cComponents*sizeof (GLfloat) );
193}
194
195void SERVER_DISPATCH_APIENTRY crServerDispatchGetTexEnviv( GLenum target, GLenum pname, GLint * params )
196{
197 unsigned int cComponents = 0;
198 GLint local_params[4] = {0};
199 (void) params;
200 if (GL_POINT_SPRITE != target && pname != GL_COORD_REPLACE)
201 cr_server.head_spu->dispatch_table.GetTexEnviv( target, pname, local_params );
202 else
203 crStateGetTexEnviv(&cr_server.StateTracker, target, pname, local_params );
204
205 cComponents = RT_MIN(crStateHlpComponentsCount(pname), RT_ELEMENTS(local_params));
206 crServerReturnValue( &(local_params[0]), cComponents*sizeof (GLint) );
207}
208
209void SERVER_DISPATCH_APIENTRY crServerDispatchBindTexture( GLenum target, GLuint texture )
210{
211 crStateBindTexture(&cr_server.StateTracker, target, texture );
212 cr_server.head_spu->dispatch_table.BindTexture(target, crStateGetTextureHWID(&cr_server.StateTracker, texture));
213}
214
215
216void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteTextures( GLsizei n, const GLuint *textures)
217{
218 GLuint *newTextures;
219 GLint i;
220
221 if (n <= 0 || n >= INT32_MAX / sizeof(GLuint))
222 {
223 crError("crServerDispatchDeleteTextures: parameter 'n' is out of range");
224 return;
225 }
226
227 newTextures = (GLuint *)crAlloc(n * sizeof(GLuint));
228
229 if (!newTextures)
230 {
231 crError("crServerDispatchDeleteTextures: out of memory");
232 return;
233 }
234
235 for (i = 0; i < n; i++)
236 {
237 newTextures[i] = crStateGetTextureHWID(&cr_server.StateTracker, textures[i]);
238 }
239
240// for (i = 0; i < n; ++i)
241// {
242// crDebug("DeleteTexture: %d, pid %d, ctx %d", textures[i], (uint32_t)cr_server.curClient->pid, cr_server.currentCtxInfo->pContext->id);
243// }
244
245
246 crStateDeleteTextures(&cr_server.StateTracker, n, textures);
247 cr_server.head_spu->dispatch_table.DeleteTextures(n, newTextures);
248 crFree(newTextures);
249}
250
251
252void SERVER_DISPATCH_APIENTRY crServerDispatchPrioritizeTextures( GLsizei n, const GLuint * textures, const GLclampf * priorities )
253{
254 GLuint *newTextures;
255 GLint i;
256
257 if (n <= 0 || n >= INT32_MAX / sizeof(GLuint))
258 {
259 crError("crServerDispatchPrioritizeTextures: parameter 'n' is out of range");
260 return;
261 }
262
263 newTextures = (GLuint *)crAlloc(n * sizeof(GLuint));
264
265 if (!newTextures)
266 {
267 crError("crServerDispatchPrioritizeTextures: out of memory");
268 return;
269 }
270
271 crStatePrioritizeTextures(&cr_server.StateTracker, n, textures, priorities);
272
273 for (i = 0; i < n; i++)
274 {
275 newTextures[i] = crStateGetTextureHWID(&cr_server.StateTracker, textures[i]);
276 }
277
278 cr_server.head_spu->dispatch_table.PrioritizeTextures(n, newTextures, priorities);
279 crFree(newTextures);
280}
281
282
283/** @todo will fail for textures loaded from snapshot */
284GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsTexture( GLuint texture )
285{
286 GLboolean retval;
287 retval = cr_server.head_spu->dispatch_table.IsTexture(crStateGetTextureHWID(&cr_server.StateTracker, texture));
288 crServerReturnValue( &retval, sizeof(retval) );
289 return retval; /* WILL PROBABLY BE IGNORED */
290}
291
292
293GLboolean SERVER_DISPATCH_APIENTRY
294crServerDispatchAreTexturesResident(GLsizei n, const GLuint *textures,
295 GLboolean *residences)
296{
297 GLboolean retval = GL_FALSE;
298 GLsizei i;
299 GLboolean *res;
300 GLuint *textures2;
301 (void) residences;
302
303 if (n <= 0 || n >= INT32_MAX / sizeof(GLuint))
304 {
305 crError("crServerDispatchAreTexturesResident: parameter 'n' is out of range");
306 return GL_FALSE;
307 }
308
309 res = (GLboolean *)crCalloc(n * sizeof(GLboolean));
310 if (!res)
311 {
312 crError("crServerDispatchAreTexturesResident: out of memory");
313 return GL_FALSE;
314 }
315
316 textures2 = (GLuint *)crAlloc(n * sizeof(GLuint));
317
318 if (!textures2)
319 {
320 crError("crServerDispatchAreTexturesResident: out of memory");
321 crFree(res);
322 return GL_FALSE;
323 }
324
325 for (i = 0; i < n; i++)
326 {
327 textures2[i] = crStateGetTextureHWID(&cr_server.StateTracker, textures[i]);
328 }
329 retval = cr_server.head_spu->dispatch_table.AreTexturesResident(n, textures2, res);
330
331 crFree(textures2);
332
333 crServerReturnValue(res, n * sizeof(GLboolean));
334
335 crFree(res);
336
337 return retval; /* WILL PROBABLY BE IGNORED */
338}
339
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