VirtualBox

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

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

Host 3D: extend SPU structure with interface for save/restore internal SPU state; provide plug for Expando SPU saving state; drop unused and confusing stuff from DLM module.

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