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