VirtualBox

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

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

Host 3D: Chromium server: add Expando SPU and DLM module in order to record and save OpenGL Display Lists (currently disabled).

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