VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/dlm/dlm_header.py@ 55762

Last change on this file since 55762 was 55762, checked in by vboxsync, 10 years ago

Host 3D: DLM: dump local stuff (preparing for saving Display Lists).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1# $Id: dlm_header.py 55762 2015-05-08 18:05:43Z vboxsync $
2import sys, cPickle, re, os
3
4sys.path.append( "../glapi_parser" )
5import apiutil
6
7# mode is "header" or "defs"
8mode = sys.argv[1]
9
10# Any new function implemented in the DLM has to have an entry added here.
11# Each function has its return type, function name, and parameters provided.
12# We'll use these to generate both a header file, and a definition file.
13additionalFunctions = [
14 ('CRDLM DLM_APIENTRY *', 'crDLMNewDLM', 'unsigned int configSize, const CRDLMConfig *config'),
15 ('CRDLMContextState DLM_APIENTRY *', 'crDLMNewContext', 'CRDLM *dlm'),
16 ('void DLM_APIENTRY', 'crDLMFreeContext', 'CRDLMContextState *state'),
17 ('void DLM_APIENTRY', 'crDLMUseDLM', 'CRDLM *dlm'),
18 ('void DLM_APIENTRY','crDLMFreeDLM', 'CRDLM *dlm'),
19 ('void DLM_APIENTRY', 'crDLMSetCurrentState', 'CRDLMContextState *state'),
20 ('CRDLMContextState DLM_APIENTRY *', 'crDLMGetCurrentState', 'void'),
21 ('CRDLMReplayState DLM_APIENTRY', 'crDLMGetReplayState', 'void'),
22 ('void DLM_APIENTRY', 'crDLMSetupClientState', 'SPUDispatchTable *dispatchTable'),
23 ('void DLM_APIENTRY', 'crDLMRestoreClientState', 'CRClientState *clientState, SPUDispatchTable *dispatchTable'),
24 ('void DLM_APIENTRY', 'crDLMSendAllDLMLists', 'CRDLM *dlm, SPUDispatchTable *dispatchTable'),
25 ('void DLM_APIENTRY', 'crDLMSendAllLists', 'SPUDispatchTable *dispatchTable'),
26 ('void DLM_APIENTRY', 'crDLMSendDLMList', 'CRDLM *dlm, unsigned long listIdentifier, SPUDispatchTable *dispatchTable'),
27 ('void DLM_APIENTRY', 'crDLMSendList', 'unsigned long listIdentifier, SPUDispatchTable *dispatchTable'),
28 ('void DLM_APIENTRY', 'crDLMReplayDLMList', 'CRDLM *dlm, unsigned long listIdentifier, SPUDispatchTable *dispatchTable'),
29 ('void DLM_APIENTRY', 'crDLMReplayList', 'unsigned long listIdentifier, SPUDispatchTable *dispatchTable'),
30 ('void DLM_APIENTRY', 'crDLMReplayDLMListState', 'CRDLM *dlm, unsigned long listIdentifier, SPUDispatchTable *dispatchTable'),
31 ('void DLM_APIENTRY', 'crDLMReplayListState', 'unsigned long listIdentifier, SPUDispatchTable *dispatchTable'),
32 ('void DLM_APIENTRY', 'crDLMReplayDLMLists', 'CRDLM *dlm, GLsizei n, GLenum type, const GLvoid *lists, SPUDispatchTable *dispatchTable'),
33 ('void DLM_APIENTRY', 'crDLMReplayLists', 'GLsizei n, GLenum type, const GLvoid *lists, SPUDispatchTable *dispatchTable'),
34 ('void DLM_APIENTRY', 'crDLMReplayDLMListsState', 'CRDLM *dlm, GLsizei n, GLenum type, const GLvoid *lists, SPUDispatchTable *dispatchTable'),
35 ('void DLM_APIENTRY', 'crDLMReplayListsState', 'GLsizei n, GLenum type, const GLvoid *lists, SPUDispatchTable *dispatchTable'),
36 ('CRDLMError DLM_APIENTRY', 'crDLMDeleteListContent', 'CRDLM *dlm, unsigned long listIdentifier'),
37 ('int DLM_APIENTRY', 'crDLMGetReferences', 'CRDLM *dlm, unsigned long listIdentifier, int firstIndex, int sizeofBuffer, unsigned int *buffer'),
38 ('CRDLMError DLM_APIENTRY', 'crDLMGetDLMBounds', 'CRDLM *dlm, unsigned long listIdentifier, CRDLMBounds *bounds'),
39 ('CRDLMError DLM_APIENTRY', 'crDLMGetBounds', 'unsigned long listIdentifier, CRDLMBounds *bounds'),
40 ('void DLM_APIENTRY', 'crDLMSetDLMBounds', 'CRDLM *dlm, unsigned long listIdentifier, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax'),
41 ('void DLM_APIENTRY', 'crDLMSetBounds', 'unsigned long listIdentifier, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax'),
42 ('void DLM_APIENTRY', 'crDLMComputeBoundingBox', 'unsigned long listId'),
43 ('GLboolean DLM_APIENTRY', 'crDLMListHasDLMBounds', 'CRDLM *dlm, unsigned long listIdentifier'),
44 ('GLboolean DLM_APIENTRY', 'crDLMListHasBounds', 'unsigned long listIdentifier'),
45 ('GLuint DLM_APIENTRY', 'crDLMGetCurrentList', 'void'),
46 ('GLenum DLM_APIENTRY', 'crDLMGetCurrentMode', 'void'),
47 ('void DLM_APIENTRY', 'crDLMErrorFunction', 'CRDLMErrorCallback callback'),
48 ('void DLM_APIENTRY', 'crDLMNewList', 'GLuint listIdentifier, GLenum mode'),
49 ('void DLM_APIENTRY', 'crDLMEndList', 'void'),
50 ('void DLM_APIENTRY', 'crDLMDeleteLists', 'GLuint firstListIdentifier, GLsizei range'),
51 ('GLboolean DLM_APIENTRY', 'crDLMIsList', 'GLuint list'),
52 ('GLuint DLM_APIENTRY', 'crDLMGenLists', 'GLsizei range'),
53 ('void DLM_APIENTRY', 'crDLMListBase', 'GLuint base'),
54 ('int32_t DLM_APIENTRY', 'crDLMSaveState', 'void'),
55 #('void DLM_APIENTRY', 'crDLMListSent', 'CRDLM *dlm, unsigned long listIdentifier'),
56 #('GLboolean DLM_APIENTRY', 'crDLMIsListSent', 'CRDLM *dlm, unsigned long listIdentifier'),
57 #('GLint DLM_APIENTRY', 'crDLMListSize', 'CRDLM *dlm, unsigned long listIdentifier'),
58]
59
60if mode == 'header':
61 print """#ifndef CR_DLM_H
62
63/* DO NOT EDIT. This file is auto-generated by %s. */
64#define CR_DLM_H
65
66#if defined(WINDOWS)
67#define DLM_APIENTRY
68#else
69#define DLM_APIENTRY
70#endif
71
72#include "chromium.h"
73#include "state/cr_client.h"
74#include "cr_spu.h"
75#include "cr_hash.h"
76#include "cr_threads.h"
77#include "cr_pack.h"
78#ifdef CHROMIUM_THREADSAFE
79#include "cr_threads.h"
80#endif
81
82/* 3D bounding box */
83typedef struct {
84 double xmin, xmax, ymin, ymax, zmin, zmax;
85} CRDLMBounds;
86
87/* Indicates whether we're currently involved in playback or not */
88typedef enum {
89 CRDLM_IMMEDIATE = 0,
90 CRDLM_REPLAY_STATE_FUNCTIONS = 1,
91 CRDLM_REPLAY_ALL_FUNCTIONS = 2
92} CRDLMReplayState;
93
94/* This is enough information to hold an instance of a single function call. */
95typedef struct DLMInstanceList {
96 struct DLMInstanceList *next;
97 struct DLMInstanceList *stateNext;
98 int cbInstance;
99 void (*execute)(struct DLMInstanceList *instance, SPUDispatchTable *dispatchTable);
100} DLMInstanceList;
101
102typedef struct {
103 DLMInstanceList *first, *last;
104 int numInstances;
105 DLMInstanceList *stateFirst, *stateLast;
106 CRHashTable *references; /* display lists that this display list calls */
107 CRDLMBounds bbox;
108 GLboolean listSent;
109} DLMListInfo;
110
111typedef struct {
112 /* This holds all the display list information, hashed by list identifier. */
113 CRHashTable *displayLists;
114
115 /* This is a count of the number of contexts/users that are using
116 * this DLM.
117 */
118 unsigned int userCount;
119
120#ifdef CHROMIUM_THREADSAFE
121 /* This mutex protects the displayLists hash table from simultaneous
122 * updates by multiple contexts.
123 */
124 CRmutex dlMutex;
125 CRtsd tsdKey;
126#endif
127
128 /* Configuration information - see the CRDLMConfig structure below
129 * for details.
130 */
131 unsigned int bufferSize;
132} CRDLM;
133
134/* This structure holds thread-specific state. Each thread can be
135 * associated with one (and only one) context; and each context can
136 * be associated with one (and only one) DLM. Making things interesting,
137 * though, is that each DLM can be associated with multiple contexts.
138 *
139 * So the thread-specific data key is associated with each context, not
140 * with each DLM. Two different threads can, through two different
141 * contexts that share a single DLM, each have independent state and
142 * conditions.
143 */
144
145typedef struct {
146 CRDLM *dlm; /* the DLM associated with this state */
147 unsigned long currentListIdentifier; /* open display list */
148 DLMListInfo *currentListInfo; /* open display list data */
149 GLenum currentListMode; /* GL_COMPILE or GL_COMPILE_AND_EXECUTE */
150 GLuint listBase;
151 CRDLMReplayState replayState; /* CRDLM_IMMEDIATE, CRDLM_REPLAY_STATE_FUNCTIONS, or CRDLM_REPLAY_ALL_FUNCTIONS */
152
153} CRDLMContextState;
154
155/* These additional structures are for passing information to and from the
156 * CRDLM interface routines.
157 */
158typedef struct {
159 /* The size, in bytes, that the packer will initially allocate for
160 * each new buffer.
161 */
162#define CRDLM_DEFAULT_BUFFERSIZE (1024*1024)
163 unsigned int bufferSize; /* this will be allocated for each buffer */
164} CRDLMConfig;
165
166/* Positive values match GL error values.
167 * 0 (GL_NO_ERROR) is returned for success
168 * Negative values are internal errors.
169 * Possible positive values (from GL/gl.h) are:
170 * GL_NO_ERROR (0x0)
171 * GL_INVALID_ENUM (0x0500)
172 * GL_INVALID_VALUE (0x0501)
173 * GL_INVALID_OPERATION (0x0502)
174 * GL_STACK_OVERFLOW (0x0503)
175 * GL_STACK_UNDERFLOW (0x0504)
176 * GL_OUT_OF_MEMORY (0x0505)
177 */
178typedef int CRDLMError;
179
180/* This error reported if there's no current state. The caller is responsible
181 * for appropriately allocating context state with crDLMNewContext(), and
182 * for making it current with crDLMMakeCurrent().
183 */
184#define CRDLM_ERROR_STATE (-1)
185
186
187typedef void (*CRDLMErrorCallback)(int line, const char *file, GLenum error, const char *info);
188
189
190#ifdef __cplusplus
191extern "C" {
192#endif
193""" % os.path.basename(sys.argv[0])
194elif mode == 'defs':
195 apiutil.CopyrightDef()
196 print '''\t; DO NOT EDIT. This code is generated by %s.
197
198EXPORTS''' % os.path.basename(sys.argv[0])
199else:
200 raise "unknown generation mode '%s'" % mode
201
202# Generate the list of functions, starting with those coded into
203# the module
204for (returnValue, name, parameters) in additionalFunctions:
205 if mode == 'header':
206 print "extern %s %s(%s);" % (returnValue, name, parameters)
207 elif mode == 'defs':
208 print "%s" % name
209
210# Continue with functions that are auto-generated.
211
212if mode == 'header':
213 print
214 print "/* auto-generated compilation functions begin here */"
215
216
217keys = apiutil.GetDispatchedFunctions(sys.argv[2]+"/APIspec.txt")
218for func_name in keys:
219 props = apiutil.Properties(func_name)
220 # We're interested in intercepting all calls that:
221 # - can be put into a display list (i.e. "not ("nolist" in props)")
222 # - change client-side state that affects saving DL elements (i.e. "setclient" in props)
223
224 if apiutil.CanCompile(func_name):
225 params = apiutil.Parameters(func_name)
226 argstring = apiutil.MakeDeclarationString(params)
227 if "useclient" in props or "pixelstore" in props:
228 argstring = argstring + ", CRClientState *c"
229
230 if mode == 'header':
231 print 'extern void DLM_APIENTRY crDLMCompile%s( %s );' % (func_name, argstring)
232 elif mode == 'defs':
233 print "crDLMCompile%s" % func_name
234
235# Next make declarations for all the checklist functions.
236if mode == 'header':
237 print """
238/* auto-generated CheckList functions begin here. There is one for each
239 * function that has a dual nature: even when there's an active glNewList,
240 * sometimes they are compiled into the display list, and sometimes they
241 * are treated like a control function. The CheckList function will
242 * return TRUE if the function should really be compiled into a display
243 * list. The calling SPU is responsible for checking this; but the
244 * DLM will also print an error if it detects an invalid use.
245 */
246"""
247elif mode == 'defs':
248 pass
249
250for func_name in keys:
251 if "checklist" in apiutil.ChromiumProps(func_name):
252 params = apiutil.Parameters(func_name)
253 argstring = apiutil.MakeDeclarationString(params)
254 if mode == 'header':
255 print 'int DLM_APIENTRY crDLMCheckList%s( %s );' % (func_name, argstring)
256 elif mode == 'defs':
257 print "crDLMCheckList%s" % func_name
258
259if mode == 'header':
260 print """
261#ifdef __cplusplus
262}
263#endif
264
265#endif /* CR_DLM_H */"""
Note: See TracBrowser for help on using the repository browser.

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