VirtualBox

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

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

Host 3D: Expando SPU, DLM module.

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