VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_pack.h@ 49216

最後變更 在這個檔案從49216是 46757,由 vboxsync 提交於 12 年 前

wddm/crOpenGL: r0-based visible regions handling, r0-based chromium commands submission debugged, more on new presentation mechanism, cleanup, etc.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 13.4 KB
 
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_PACK_H
8#define CR_PACK_H
9
10#include "cr_compiler.h"
11#include "cr_error.h"
12#include "cr_protocol.h"
13#include "cr_opcodes.h"
14#include "cr_endian.h"
15#include "state/cr_statetypes.h"
16#include "state/cr_currentpointers.h"
17#include "state/cr_client.h"
18#ifdef CHROMIUM_THREADSAFE
19#include "cr_threads.h"
20#endif
21
22#include <iprt/types.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28typedef struct CRPackContext_t CRPackContext;
29
30/**
31 * Packer buffer
32 */
33typedef struct
34{
35 void *pack; /**< the actual storage space/buffer */
36 unsigned int size; /**< size of pack[] buffer */
37 unsigned int mtu;
38 unsigned char *data_start, *data_current, *data_end;
39 unsigned char *opcode_start, *opcode_current, *opcode_end;
40 GLboolean geometry_only; /**< just used for debugging */
41 GLboolean holds_BeginEnd;
42 GLboolean in_BeginEnd;
43 GLboolean canBarf;
44 GLboolean holds_List;
45 GLboolean in_List;
46 CRPackContext *context;
47} CRPackBuffer;
48
49typedef void (*CRPackFlushFunc)(void *arg);
50typedef void (*CRPackSendHugeFunc)(CROpcode, void *);
51typedef void (*CRPackErrorHandlerFunc)(int line, const char *file, GLenum error, const char *info);
52
53typedef enum
54{
55 CRPackBeginEndStateNone = 0, /* not in begin end */
56 CRPackBeginEndStateStarted, /* begin issued */
57 CRPackBeginEndStateFlushDone /* begin issued & buffer flash is done thus part of commands is issued to host */
58} CRPackBeginEndState;
59/**
60 * Packer context
61 */
62struct CRPackContext_t
63{
64 CRPackBuffer buffer; /**< not a pointer, see comments in pack_buffer.c */
65 CRPackFlushFunc Flush;
66 void *flush_arg;
67 CRPackSendHugeFunc SendHuge;
68 CRPackErrorHandlerFunc Error;
69 CRCurrentStatePointers current;
70 CRPackBeginEndState enmBeginEndState;
71 GLvectorf bounds_min, bounds_max;
72 int updateBBOX;
73 int swapping;
74 CRPackBuffer *currentBuffer;
75#ifdef CHROMIUM_THREADSAFE
76 CRmutex mutex;
77#endif
78 char *file; /**< for debugging only */
79 int line; /**< for debugging only */
80};
81
82#if !defined(IN_RING0)
83# define CR_PACKER_CONTEXT_ARGSINGLEDECL
84# define CR_PACKER_CONTEXT_ARGDECL
85# define CR_PACKER_CONTEXT_ARG
86# define CR_PACKER_CONTEXT_ARGCTX(C)
87# ifdef CHROMIUM_THREADSAFE
88extern CRtsd _PackerTSD;
89# define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = (CRPackContext *) crGetTSD(&_PackerTSD)
90# define CR_LOCK_PACKER_CONTEXT(PC) crLockMutex(&((PC)->mutex))
91# define CR_UNLOCK_PACKER_CONTEXT(PC) crUnlockMutex(&((PC)->mutex))
92# else
93extern DLLDATA(CRPackContext) cr_packer_globals;
94# define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = &cr_packer_globals
95# define CR_LOCK_PACKER_CONTEXT(PC)
96# define CR_UNLOCK_PACKER_CONTEXT(PC)
97# endif
98#else /* if defined IN_RING0 */
99# define CR_PACKER_CONTEXT_ARGSINGLEDECL CRPackContext *_pCtx
100# define CR_PACKER_CONTEXT_ARGDECL CR_PACKER_CONTEXT_ARGSINGLEDECL,
101# define CR_PACKER_CONTEXT_ARG _pCtx,
102# define CR_PACKER_CONTEXT_ARGCTX(C) C,
103# define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = _pCtx
104# define CR_LOCK_PACKER_CONTEXT(PC)
105# define CR_UNLOCK_PACKER_CONTEXT(PC)
106#endif
107
108extern DECLEXPORT(CRPackContext *) crPackNewContext(int swapping);
109extern DECLEXPORT(void) crPackDeleteContext(CRPackContext *pc);
110extern DECLEXPORT(void) crPackSetContext( CRPackContext *pc );
111extern DECLEXPORT(CRPackContext *) crPackGetContext( void );
112
113extern DECLEXPORT(void) crPackSetBuffer( CRPackContext *pc, CRPackBuffer *buffer );
114extern DECLEXPORT(void) crPackSetBufferDEBUG( const char *file, int line, CRPackContext *pc, CRPackBuffer *buffer );
115extern DECLEXPORT(void) crPackReleaseBuffer( CRPackContext *pc );
116extern DECLEXPORT(void) crPackResetPointers( CRPackContext *pc );
117
118extern DECLEXPORT(int) crPackMaxOpcodes( int buffer_size );
119extern DECLEXPORT(int) crPackMaxData( int buffer_size );
120extern DECLEXPORT(void) crPackInitBuffer( CRPackBuffer *buffer, void *buf, int size, int mtu
121#ifdef IN_RING0
122 , unsigned int num_opcodes
123#endif
124 );
125extern DECLEXPORT(void) crPackFlushFunc( CRPackContext *pc, CRPackFlushFunc ff );
126extern DECLEXPORT(void) crPackFlushArg( CRPackContext *pc, void *flush_arg );
127extern DECLEXPORT(void) crPackSendHugeFunc( CRPackContext *pc, CRPackSendHugeFunc shf );
128extern DECLEXPORT(void) crPackErrorFunction( CRPackContext *pc, CRPackErrorHandlerFunc errf );
129extern DECLEXPORT(void) crPackOffsetCurrentPointers( int offset );
130extern DECLEXPORT(void) crPackNullCurrentPointers( void );
131
132extern DECLEXPORT(void) crPackResetBoundingBox( CRPackContext *pc );
133extern DECLEXPORT(GLboolean) crPackGetBoundingBox( CRPackContext *pc,
134 GLfloat *xmin, GLfloat *ymin, GLfloat *zmin,
135 GLfloat *xmax, GLfloat *ymax, GLfloat *zmax);
136
137extern DECLEXPORT(void) crPackAppendBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
138extern DECLEXPORT(void) crPackAppendBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer, const CRrecti *bounds );
139extern DECLEXPORT(int) crPackCanHoldBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
140extern DECLEXPORT(int) crPackCanHoldBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
141
142#if defined(LINUX) || defined(WINDOWS)
143#define CR_UNALIGNED_ACCESS_OKAY
144#else
145#undef CR_UNALIGNED_ACCESS_OKAY
146#endif
147#ifndef IN_RING0
148extern DECLEXPORT(void) crWriteUnalignedDouble( void *buffer, double d );
149extern DECLEXPORT(void) crWriteSwappedDouble( void *buffer, double d );
150#endif
151
152extern DECLEXPORT(void) *crPackAlloc( CR_PACKER_CONTEXT_ARGDECL unsigned int len );
153extern DECLEXPORT(void) crHugePacket( CR_PACKER_CONTEXT_ARGDECL CROpcode op, void *ptr );
154extern DECLEXPORT(void) crPackFree( CR_PACKER_CONTEXT_ARGDECL void *ptr );
155extern DECLEXPORT(void) crNetworkPointerWrite( CRNetworkPointer *, void * );
156
157extern DECLEXPORT(void) crPackExpandDrawArrays(GLenum mode, GLint first, GLsizei count, CRClientState *c);
158extern DECLEXPORT(void) crPackExpandDrawArraysSWAP(GLenum mode, GLint first, GLsizei count, CRClientState *c);
159
160extern DECLEXPORT(void) crPackUnrollDrawElements(GLsizei count, GLenum type, const GLvoid *indices);
161extern DECLEXPORT(void) crPackUnrollDrawElementsSWAP(GLsizei count, GLenum type, const GLvoid *indices);
162
163extern DECLEXPORT(void) crPackExpandDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c);
164extern DECLEXPORT(void) crPackExpandDrawElementsSWAP(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c);
165
166extern DECLEXPORT(void) crPackExpandDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c);
167extern DECLEXPORT(void) crPackExpandDrawRangeElementsSWAP(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c);
168
169extern DECLEXPORT(void) crPackExpandArrayElement(GLint index, CRClientState *c);
170extern DECLEXPORT(void) crPackExpandArrayElementSWAP(GLint index, CRClientState *c);
171
172extern DECLEXPORT(void) crPackExpandMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount, CRClientState *c );
173extern DECLEXPORT(void) crPackExpandMultiDrawArraysEXTSWAP( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount, CRClientState *c );
174
175extern DECLEXPORT(void) crPackExpandMultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount, CRClientState *c );
176extern DECLEXPORT(void) crPackExpandMultiDrawElementsEXTSWAP( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount, CRClientState *c );
177
178
179/**
180 * Return number of opcodes in given buffer.
181 */
182static INLINE int
183crPackNumOpcodes(const CRPackBuffer *buffer)
184{
185 CRASSERT(buffer->opcode_start - buffer->opcode_current >= 0);
186 return buffer->opcode_start - buffer->opcode_current;
187}
188
189
190/**
191 * Return amount of data (in bytes) in buffer.
192 */
193static INLINE int
194crPackNumData(const CRPackBuffer *buffer)
195{
196 CRASSERT(buffer->data_current - buffer->data_start >= 0);
197 return buffer->data_current - buffer->data_start; /* in bytes */
198}
199
200
201static INLINE int
202crPackCanHoldOpcode(const CRPackContext *pc, int num_opcode, int num_data)
203{
204 int fitsInMTU, opcodesFit, dataFits;
205
206 CRASSERT(pc->currentBuffer);
207
208 fitsInMTU = (((pc->buffer.data_current - pc->buffer.opcode_current - 1
209 + num_opcode + num_data
210 + 0x3 ) & ~0x3) + sizeof(CRMessageOpcodes)
211 <= pc->buffer.mtu);
212 opcodesFit = (pc->buffer.opcode_current - num_opcode >= pc->buffer.opcode_end);
213 dataFits = (pc->buffer.data_current + num_data <= pc->buffer.data_end);
214
215 return fitsInMTU && opcodesFit && dataFits;
216}
217
218
219/**
220 * Alloc space for a message of 'len' bytes (plus 1 opcode).
221 * Only flush if buffer is full.
222 */
223#define CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, len, lock) \
224 do { \
225 THREADASSERT( pc ); \
226 if (lock) CR_LOCK_PACKER_CONTEXT(pc); \
227 CRASSERT( pc->currentBuffer ); \
228 if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
229 pc->Flush( pc->flush_arg ); \
230 CRASSERT(crPackCanHoldOpcode( pc, 1, (len) ) ); \
231 if (pc->enmBeginEndState == CRPackBeginEndStateStarted) { \
232 pc->enmBeginEndState = CRPackBeginEndStateFlushDone; \
233 } \
234 } \
235 data_ptr = pc->buffer.data_current; \
236 pc->buffer.data_current += (len); \
237 } while (0)
238
239
240/**
241 * As above, flush if the buffer contains vertex data and we're
242 * no longer inside glBegin/glEnd.
243 */
244#define CR_GET_BUFFERED_POINTER( pc, len ) \
245 do { \
246 CR_LOCK_PACKER_CONTEXT(pc); \
247 CRASSERT( pc->currentBuffer ); \
248 if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
249 CRASSERT( 0 ); /* should never be here currently */ \
250 pc->Flush( pc->flush_arg ); \
251 pc->buffer.holds_BeginEnd = 0; \
252 } \
253 CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
254 } while (0)
255
256/**
257 * As above, but without lock.
258 */
259#define CR_GET_BUFFERED_POINTER_NOLOCK( pc, len ) \
260 do { \
261 CRASSERT( pc->currentBuffer ); \
262 if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
263 CRASSERT( 0 ); /* should never be here currently */ \
264 pc->Flush( pc->flush_arg ); \
265 pc->buffer.holds_BeginEnd = 0; \
266 } \
267 CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
268 } while (0)
269
270
271/**
272 * As above, but for vertex data between glBegin/End (counts vertices).
273 */
274#define CR_GET_BUFFERED_COUNT_POINTER( pc, len ) \
275 do { \
276 CR_LOCK_PACKER_CONTEXT(pc); \
277 CRASSERT( pc->currentBuffer ); \
278 if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
279 pc->Flush( pc->flush_arg ); \
280 CRASSERT( crPackCanHoldOpcode( pc, 1, (len) ) ); \
281 if (pc->enmBeginEndState == CRPackBeginEndStateStarted) { \
282 pc->enmBeginEndState = CRPackBeginEndStateFlushDone; \
283 } \
284 } \
285 data_ptr = pc->buffer.data_current; \
286 pc->current.vtx_count++; \
287 pc->buffer.data_current += (len); \
288 } while (0)
289
290
291/**
292 * Allocate space for a msg/command that has no arguments, such
293 * as glFinish().
294 */
295#define CR_GET_BUFFERED_POINTER_NO_ARGS( pc ) \
296 CR_GET_BUFFERED_POINTER( pc, 4 ); \
297 WRITE_DATA( 0, GLuint, 0xdeadbeef )
298
299#define WRITE_DATA( offset, type, data ) \
300 *( (type *) (data_ptr + (offset))) = (data)
301
302/* Write data to current location and auto increment */
303#define WRITE_DATA_AI(type, data) \
304 { \
305 *((type*) (data_ptr)) = (data); \
306 data_ptr += sizeof(type); \
307 }
308
309#ifdef CR_UNALIGNED_ACCESS_OKAY
310#define WRITE_DOUBLE( offset, data ) \
311 WRITE_DATA( offset, GLdouble, data )
312#else
313# ifndef IN_RING0
314# define WRITE_DOUBLE( offset, data ) \
315 crWriteUnalignedDouble( data_ptr + (offset), (data) )
316# else
317# define WRITE_DOUBLE( offset, data ) \
318 AssertReleaseFailed()
319# endif
320#endif
321
322#ifndef IN_RING0
323#define WRITE_SWAPPED_DOUBLE( offset, data ) \
324 crWriteSwappedDouble( data_ptr + (offset), (data) )
325#else
326#define WRITE_SWAPPED_DOUBLE( offset, data ) \
327 AssertReleaseFailed()
328#endif
329
330#define WRITE_OPCODE( pc, opcode ) \
331 *(pc->buffer.opcode_current--) = (unsigned char) opcode
332
333#define WRITE_NETWORK_POINTER( offset, data ) \
334 crNetworkPointerWrite( (CRNetworkPointer *) ( data_ptr + (offset) ), (data) )
335
336#ifdef __cplusplus
337}
338#endif
339
340#endif /* CR_PACK_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette