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