VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_glstate.h@ 79660

Last change on this file since 79660 was 78376, 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 [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 12.4 KB
Line 
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 */
11struct CRContext;
12typedef 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
69extern "C" {
70#endif
71
72/**
73 * Bit vectors describing GL state
74 */
75typedef 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
106typedef void (*CRStateFlushFunc)( void *arg );
107
108
109typedef 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 */
129struct 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 */
210typedef 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
223DECLEXPORT(void) crStateInit(PCRStateTracker pState);
224DECLEXPORT(void) crStateDestroy(PCRStateTracker pState);
225DECLEXPORT(void) crStateVBoxDetachThread(PCRStateTracker pState);
226DECLEXPORT(void) crStateVBoxAttachThread(PCRStateTracker pState);
227DECLEXPORT(CRContext *) crStateCreateContext(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share);
228DECLEXPORT(CRContext *) crStateCreateContextEx(PCRStateTracker pState, const CRLimitsState *limits, GLint visBits, CRContext *share, GLint presetID);
229DECLEXPORT(void) crStateMakeCurrent(PCRStateTracker pState, CRContext *ctx);
230DECLEXPORT(void) crStateSetCurrent(PCRStateTracker pState, CRContext *ctx);
231DECLEXPORT(void) crStateCleanupCurrent(PCRStateTracker pState);
232DECLEXPORT(CRContext *) crStateGetCurrent(PCRStateTracker pState);
233DECLEXPORT(void) crStateDestroyContext(PCRStateTracker pState, CRContext *ctx);
234DECLEXPORT(GLboolean) crStateEnableDiffOnMakeCurrent(PCRStateTracker pState, GLboolean fEnable);
235
236void crStateSwitchPrepare(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO);
237void crStateSwitchPostprocess(CRContext *toCtx, CRContext *fromCtx, GLuint idDrawFBO, GLuint idReadFBO);
238
239void crStateSyncHWErrorState(CRContext *ctx);
240GLenum crStateCleanHWErrorState(PCRStateTracker pState);
241
242#define CR_STATE_CLEAN_HW_ERR_WARN(a_pState, _s) do {\
243 GLenum _err = crStateCleanHWErrorState((a_pState)); \
244 if (_err != GL_NO_ERROR) { \
245 static int _cErrPrints = 0; \
246 if (_cErrPrints < 5) { \
247 ++_cErrPrints; \
248 WARN(("%s %#x, ignoring.. (%d out of 5)", _s, _err, _cErrPrints)); \
249 } \
250 } \
251 } while (0)
252
253DECLEXPORT(void) crStateFlushFunc(PCRStateTracker pState, CRStateFlushFunc ff);
254DECLEXPORT(void) crStateFlushArg(PCRStateTracker pState, void *arg );
255DECLEXPORT(void) crStateDiffAPI(PCRStateTracker pState, SPUDispatchTable *api);
256DECLEXPORT(void) crStateUpdateColorBits(PCRStateTracker pState);
257
258DECLEXPORT(void) crStateSetCurrentPointers(CRContext *ctx, CRCurrentStatePointers *current);
259DECLEXPORT(void) crStateResetCurrentPointers(CRCurrentStatePointers *current);
260
261DECLEXPORT(void) crStateSetExtensionString(CRContext *ctx, const GLubyte *extensions);
262
263DECLEXPORT(void) crStateDiffContext(CRContext *from, CRContext *to);
264DECLEXPORT(void) crStateSwitchContext(CRContext *from, CRContext *to);
265
266DECLEXPORT(unsigned int) crStateHlpComponentsCount(GLenum pname);
267
268typedef struct CRFBDataElement
269{
270 /* FBO, can be NULL */
271 GLint idFBO;
272 /* to be used for glDraw/ReadBuffer, i.e. GL_FRONT, GL_BACK, GL_COLOR_ATTACHMENTX */
273 GLenum enmBuffer;
274 GLint posX;
275 GLint posY;
276 GLint width;
277 GLint height;
278 GLenum enmFormat;
279 GLenum enmType;
280 GLuint cbData;
281 GLvoid *pvData;
282} CRFBDataElement;
283
284typedef struct CRFBData
285{
286 /* override default draw and read buffers to be used for offscreen rendering */
287 GLint idOverrrideFBO;
288 uint32_t u32Version;
289 uint32_t cElements;
290 CRFBDataElement aElements[1];
291} CRFBData;
292
293DECLEXPORT(void) crStateApplyFBImage(CRContext *to, CRFBData *data);
294DECLEXPORT(int) crStateAcquireFBImage(CRContext *to, CRFBData *data);
295DECLEXPORT(void) crStateFreeFBImageLegacy(CRContext *to);
296
297DECLEXPORT(void) crStateGetTextureObjectAndImage(CRContext *g, GLenum texTarget, GLint level,
298 CRTextureObj **obj, CRTextureLevel **img);
299
300
301DECLEXPORT(void) crStateReleaseTexture(CRContext *pCtx, CRTextureObj *pObj);
302
303#ifndef IN_GUEST
304DECLEXPORT(int32_t) crStateSaveContext(CRContext *pContext, PSSMHANDLE pSSM);
305typedef DECLCALLBACK(CRContext*) FNCRSTATE_CONTEXT_GET(void*);
306typedef FNCRSTATE_CONTEXT_GET *PFNCRSTATE_CONTEXT_GET;
307DECLEXPORT(int32_t) crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version);
308DECLEXPORT(void) crStateFreeShared(PCRStateTracker pState, CRContext *pContext, CRSharedState *s);
309
310DECLEXPORT(int32_t) crStateLoadGlobals(PCRStateTracker pState, PSSMHANDLE pSSM, uint32_t u32Version);
311DECLEXPORT(int32_t) crStateSaveGlobals(PCRStateTracker pState, PSSMHANDLE pSSM);
312
313DECLEXPORT(CRSharedState *) crStateGlobalSharedAcquire(PCRStateTracker pState);
314DECLEXPORT(void) crStateGlobalSharedRelease(PCRStateTracker pState);
315#endif
316
317DECLEXPORT(void) crStateSetTextureUsed(PCRStateTracker pState, GLuint texture, GLboolean used);
318DECLEXPORT(void) crStatePinTexture(PCRStateTracker pState, GLuint texture, GLboolean pin);
319DECLEXPORT(void) crStateDeleteTextureCallback(void *texObj, void *pvUser);
320
321 /* XXX move these! */
322
323DECLEXPORT(void) STATE_APIENTRY crStateChromiumParameteriCR(PCRStateTracker pState, GLenum target, GLint value );
324DECLEXPORT(void) STATE_APIENTRY crStateChromiumParameterfCR(PCRStateTracker pState, GLenum target, GLfloat value );
325DECLEXPORT(void) STATE_APIENTRY crStateChromiumParametervCR(PCRStateTracker pState, GLenum target, GLenum type, GLsizei count, const GLvoid *values );
326DECLEXPORT(void) STATE_APIENTRY crStateGetChromiumParametervCR(PCRStateTracker pState, GLenum target, GLuint index, GLenum type,
327 GLsizei count, GLvoid *values );
328DECLEXPORT(void) STATE_APIENTRY crStateReadPixels(PCRStateTracker pState, GLint x, GLint y, GLsizei width, GLsizei height,
329 GLenum format, GLenum type, GLvoid *pixels );
330DECLEXPORT(void) STATE_APIENTRY crStateShareContext(PCRStateTracker pState, GLboolean value);
331DECLEXPORT(void) STATE_APIENTRY crStateShareLists(CRContext *pContext1, CRContext *pContext2);
332DECLEXPORT(void) STATE_APIENTRY crStateSetSharedContext(CRContext *pCtx);
333DECLEXPORT(GLboolean) STATE_APIENTRY crStateContextIsShared(CRContext *pCtx);
334DECLEXPORT(void) STATE_APIENTRY crStateQueryHWState(PCRStateTracker pState, GLuint fbFbo, GLuint bbFbo);
335#ifdef __cplusplus
336}
337#endif
338
339#endif /* CR_GLSTATE_H */
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