1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
/* Copyright (c) 2001, Stanford University
* All rights reserved.
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#ifndef CR_GLSTATE_H
#define CR_GLSTATE_H
/* Forward declaration since some of the state/cr_*.h files need the CRContext type */
struct CRContext;
typedef struct CRContext CRContext;
#include "cr_version.h"
#include "state/cr_buffer.h"
#include "state/cr_bufferobject.h"
#include "state/cr_client.h"
#include "state/cr_current.h"
#include "state/cr_evaluators.h"
#include "state/cr_feedback.h"
#include "state/cr_fog.h"
#include "state/cr_hint.h"
#include "state/cr_lighting.h"
#include "state/cr_limits.h"
#include "state/cr_line.h"
#include "state/cr_lists.h"
#include "state/cr_multisample.h"
#include "state/cr_occlude.h"
#include "state/cr_pixel.h"
#include "state/cr_point.h"
#include "state/cr_polygon.h"
#include "state/cr_program.h"
#include "state/cr_regcombiner.h"
#include "state/cr_stencil.h"
#include "state/cr_texture.h"
#include "state/cr_transform.h"
#include "state/cr_viewport.h"
#include "state/cr_attrib.h"
#include "state/cr_framebuffer.h"
#include "state/cr_glsl.h"
#include "state/cr_statefuncs.h"
#include "state/cr_stateerror.h"
#include "spu_dispatch_table.h"
#ifdef CHROMIUM_THREADSAFE
# include <cr_threads.h>
#endif
#include <iprt/cdefs.h>
# include <VBox/vmm/ssm.h>
# include <iprt/asm.h>
# define CR_STATE_SHAREDOBJ_USAGE_INIT(_pObj) (crMemset((_pObj)->ctxUsage, 0, sizeof ((_pObj)->ctxUsage)))
# define CR_STATE_SHAREDOBJ_USAGE_SET(_pObj, _pCtx) (ASMBitSet((_pObj)->ctxUsage, (_pCtx)->id))
# define CR_STATE_SHAREDOBJ_USAGE_IS_SET(_pObj, _pCtx) (ASMBitTest((_pObj)->ctxUsage, (_pCtx)->id))
# define CR_STATE_SHAREDOBJ_USAGE_CLEAR_IDX(_pObj, _i) (ASMBitClear((_pObj)->ctxUsage, (_i)))
# define CR_STATE_SHAREDOBJ_USAGE_CLEAR(_pObj, _pCtx) (CR_STATE_SHAREDOBJ_USAGE_CLEAR_IDX((_pObj), (_pCtx)->id))
# define CR_STATE_SHAREDOBJ_USAGE_IS_USED(_pObj) (ASMBitFirstSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3) >= 0)
# define CR_STATE_SHAREDOBJ_USAGE_GET_FIRST_USED_IDX(_pObj) (ASMBitFirstSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3))
# define CR_STATE_SHAREDOBJ_USAGE_GET_NEXT_USED_IDX(_pObj, _i) (ASMBitNextSet((_pObj)->ctxUsage, sizeof ((_pObj)->ctxUsage)<<3, (_i)))
# define CR_STATE_SHAREDOBJ_USAGE_FOREACH_USED_IDX(_pObj, _i) for ((_i) = CR_STATE_SHAREDOBJ_USAGE_GET_FIRST_USED_IDX(_pObj); ((int)(_i)) >= 0; (_i) = CR_STATE_SHAREDOBJ_USAGE_GET_NEXT_USED_IDX((_pObj), ((int)(_i))))
#define CR_MAX_EXTENTS 256
#ifdef __cplusplus
extern "C" {
#endif
/**
* Bit vectors describing GL state
*/
typedef struct {
CRAttribBits attrib;
CRBufferBits buffer;
#ifdef CR_ARB_vertex_buffer_object
CRBufferObjectBits bufferobject;
#endif
CRClientBits client;
CRCurrentBits current;
CREvaluatorBits eval;
CRFeedbackBits feedback;
CRFogBits fog;
CRHintBits hint;
CRLightingBits lighting;
CRLineBits line;
CRListsBits lists;
CRMultisampleBits multisample;
#if CR_ARB_occlusion_query
CROcclusionBits occlusion;
#endif
CRPixelBits pixel;
CRPointBits point;
CRPolygonBits polygon;
CRProgramBits program;
CRRegCombinerBits regcombiner;
CRSelectionBits selection;
CRStencilBits stencil;
CRTextureBits texture;
CRTransformBits transform;
CRViewportBits viewport;
} CRStateBits;
typedef void (*CRStateFlushFunc)( void *arg );
typedef struct _CRSharedState {
CRHashTable *textureTable; /* all texture objects */
CRHashTable *dlistTable; /* all display lists */
CRHashTable *buffersTable; /* vbo/pbo */
CRHashTable *fbTable; /* frame buffers */
CRHashTable *rbTable; /* render buffers */
volatile int32_t refCount;
GLint id; /*unique shared state id, it's not always matching some existing context id!*/
GLint saveCount;
/* Indicates that we have to resend data to GPU on first glMakeCurrent call with owning context */
GLboolean bTexResyncNeeded;
GLboolean bVBOResyncNeeded;
GLboolean bFBOResyncNeeded;
} CRSharedState;
/**
* Chromium version of the state variables in OpenGL
*/
struct CRContext {
int id;
#ifdef CHROMIUM_THREADSAFE
/* we keep reference counting of context's makeCurrent for different threads
* this is primarily needed to avoid having an invalid memory reference in the TLS
* when the context is assigned to more than one threads and then destroyed from
* one of those, i.e.
* 1. Thread1 -> MakeCurrent(ctx1);
* 2. Thread2 -> MakeCurrent(ctx1);
* 3. Thread1 -> Destroy(ctx1);
* => Thread2 still refers to destroyed ctx1
* */
VBOXTLSREFDATA
#endif
CRbitvalue bitid[CR_MAX_BITARRAY];
CRbitvalue neg_bitid[CR_MAX_BITARRAY];
CRSharedState *shared;
GLenum renderMode;
GLenum error;
CRStateFlushFunc flush_func;
void *flush_arg;
CRAttribState attrib;
CRBufferState buffer;
#ifdef CR_ARB_vertex_buffer_object
CRBufferObjectState bufferobject;
#endif
CRClientState client;
CRCurrentState current;
CREvaluatorState eval;
CRExtensionState extensions;
CRFeedbackState feedback;
CRFogState fog;
CRHintState hint;
CRLightingState lighting;
CRLimitsState limits;
CRLineState line;
CRListsState lists;
CRMultisampleState multisample;
#if CR_ARB_occlusion_query
CROcclusionState occlusion;
#endif
CRPixelState pixel;
CRPointState point;
CRPolygonState polygon;
CRProgramState program;
CRRegCombinerState regcombiner;
CRSelectionState selection;
CRStencilState stencil;
CRTextureState texture;
CRTransformState transform;
CRViewportState viewport;
#ifdef CR_EXT_framebuffer_object
CRFramebufferObjectState framebufferobject;
#endif
#ifdef CR_OPENGL_VERSION_2_0
CRGLSLState glsl;
#endif
/** For buffering vertices for selection/feedback */
/*@{*/
GLuint vCount;
CRVertex vBuffer[4];
GLboolean lineReset;
GLboolean lineLoop;
/*@}*/
};
DECLEXPORT(void) crStateInit(void);
DECLEXPORT(void) crStateDestroy(void);
DECLEXPORT(void) crStateVBoxDetachThread(void);
DECLEXPORT(void) crStateVBoxAttachThread(void);
DECLEXPORT(CRContext *) crStateCreateContext(const CRLimitsState *limits, GLint visBits, CRContext *share);
DECLEXPORT(CRContext *) crStateCreateContextEx(const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID);
DECLEXPORT(void) crStateMakeCurrent(CRContext *ctx);
DECLEXPORT(void) crStateSetCurrent(CRContext *ctx);
DECLEXPORT(void) crStateCleanupCurrent(void);
DECLEXPORT(CRContext *) crStateGetCurrent(void);
DECLEXPORT(void) crStateDestroyContext(CRContext *ctx);
DECLEXPORT(GLboolean) crStateEnableDiffOnMakeCurrent(GLboolean fEnable);
void crStateSwitchPrepare(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO);
void crStateSwitchPostprocess(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO);
void crStateSyncHWErrorState(CRContext *ctx);
GLenum crStateCleanHWErrorState(void);
#define CR_STATE_CLEAN_HW_ERR_WARN(_s) do {\
GLenum _err = crStateCleanHWErrorState(); \
if (_err != GL_NO_ERROR) { \
static int _cErrPrints = 0; \
if (_cErrPrints < 5) { \
++_cErrPrints; \
WARN(("%s %#x, ignoring.. (%d out of 5)", _s, _err, _cErrPrints)); \
} \
} \
} while (0)
DECLEXPORT(void) crStateFlushFunc( CRStateFlushFunc ff );
DECLEXPORT(void) crStateFlushArg( void *arg );
DECLEXPORT(void) crStateDiffAPI( SPUDispatchTable *api );
DECLEXPORT(void) crStateUpdateColorBits( void );
DECLEXPORT(void) crStateSetCurrentPointers( CRContext *ctx, CRCurrentStatePointers *current );
DECLEXPORT(void) crStateResetCurrentPointers( CRCurrentStatePointers *current );
DECLEXPORT(void) crStateSetExtensionString( CRContext *ctx, const GLubyte *extensions );
DECLEXPORT(void) crStateDiffContext( CRContext *from, CRContext *to );
DECLEXPORT(void) crStateSwitchContext( CRContext *from, CRContext *to );
DECLEXPORT(unsigned int) crStateHlpComponentsCount( GLenum pname );
typedef struct CRFBDataElement
{
/* FBO, can be NULL */
GLint idFBO;
/* to be used for glDraw/ReadBuffer, i.e. GL_FRONT, GL_BACK, GL_COLOR_ATTACHMENTX */
GLenum enmBuffer;
GLint posX;
GLint posY;
GLint width;
GLint height;
GLenum enmFormat;
GLenum enmType;
GLuint cbData;
GLvoid *pvData;
} CRFBDataElement;
typedef struct CRFBData
{
/* override default draw and read buffers to be used for offscreen rendering */
GLint idOverrrideFBO;
uint32_t u32Version;
uint32_t cElements;
CRFBDataElement aElements[1];
} CRFBData;
DECLEXPORT(void) crStateApplyFBImage(CRContext *to, CRFBData *data);
DECLEXPORT(int) crStateAcquireFBImage(CRContext *to, CRFBData *data);
DECLEXPORT(void) crStateFreeFBImageLegacy(CRContext *to);
DECLEXPORT(void) crStateGetTextureObjectAndImage(CRContext *g, GLenum texTarget, GLint level,
CRTextureObj **obj, CRTextureLevel **img);
DECLEXPORT(void) crStateReleaseTexture(CRContext *pCtx, CRTextureObj *pObj);
#ifndef IN_GUEST
DECLEXPORT(int32_t) crStateSaveContext(CRContext *pContext, PSSMHANDLE pSSM);
typedef DECLCALLBACK(CRContext*) FNCRSTATE_CONTEXT_GET(void*);
typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version);
DECLEXPORT(void) crStateFreeShared(CRContext *pContext, CRSharedState *s);
DECLEXPORT(int32_t) crStateLoadGlobals(PSSMHANDLE pSSM, uint32_t u32Version);
DECLEXPORT(int32_t) crStateSaveGlobals(PSSMHANDLE pSSM);
DECLEXPORT(CRSharedState *) crStateGlobalSharedAcquire(void);
DECLEXPORT(void) crStateGlobalSharedRelease(void);
#endif
DECLEXPORT(void) crStateSetTextureUsed(GLuint texture, GLboolean used);
DECLEXPORT(void) crStatePinTexture(GLuint texture, GLboolean pin);
DECLEXPORT(void) crStateDeleteTextureCallback(void *texObj);
/* XXX move these! */
DECLEXPORT(void) STATE_APIENTRY
crStateChromiumParameteriCR( GLenum target, GLint value );
DECLEXPORT(void) STATE_APIENTRY
crStateChromiumParameterfCR( GLenum target, GLfloat value );
DECLEXPORT(void) STATE_APIENTRY
crStateChromiumParametervCR( GLenum target, GLenum type, GLsizei count, const GLvoid *values );
DECLEXPORT(void) STATE_APIENTRY
crStateGetChromiumParametervCR( GLenum target, GLuint index, GLenum type,
GLsizei count, GLvoid *values );
DECLEXPORT(void) STATE_APIENTRY
crStateReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid *pixels );
DECLEXPORT(void) STATE_APIENTRY crStateShareContext(GLboolean value);
DECLEXPORT(void) STATE_APIENTRY crStateShareLists(CRContext *pContext1, CRContext *pContext2);
DECLEXPORT(void) STATE_APIENTRY crStateSetSharedContext(CRContext *pCtx);
DECLEXPORT(GLboolean) STATE_APIENTRY crStateContextIsShared(CRContext *pCtx);
DECLEXPORT(void) STATE_APIENTRY crStateQueryHWState(GLuint fbFbo, GLuint bbFbo);
#ifdef __cplusplus
}
#endif
#endif /* CR_GLSTATE_H */
|