VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack.py@ 50973

最後變更 在這個檔案從50973是 50973,由 vboxsync 提交於 11 年 前

crOpenGL: command blocks (disabled for now)

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 10.2 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
6import sys
7
8import apiutil
9
10
11apiutil.CopyrightC()
12
13print """/* DO NOT EDIT! THIS CODE IS AUTOGENERATED BY unpack.py */
14
15#include "unpacker.h"
16#include "cr_opcodes.h"
17#include "cr_error.h"
18#include "cr_mem.h"
19#include "cr_spu.h"
20#include "unpack_extend.h"
21#include <stdio.h>
22#include <memory.h>
23
24#include <iprt/cdefs.h>
25
26DECLEXPORT(const unsigned char *) cr_unpackData = NULL;
27SPUDispatchTable cr_unpackDispatch;
28
29static void crUnpackExtend(void);
30static void crUnpackExtendDbg(void);
31
32/*#define CR_UNPACK_DEBUG_OPCODES*/
33/*#define CR_UNPACK_DEBUG_LAST_OPCODES*/
34"""
35
36nodebug_opcodes = [
37 "CR_MULTITEXCOORD2FARB_OPCODE",
38 "CR_VERTEX3F_OPCODE",
39 "CR_NORMAL3F_OPCODE",
40 "CR_COLOR4UB_OPCODE",
41 "CR_LOADIDENTITY_OPCODE",
42 "CR_MATRIXMODE_OPCODE",
43 "CR_LOADMATRIXF_OPCODE",
44 "CR_DISABLE_OPCODE",
45 "CR_COLOR4F_OPCODE",
46 "CR_ENABLE_OPCODE",
47 "CR_BEGIN_OPCODE",
48 "CR_END_OPCODE",
49 "CR_SECONDARYCOLOR3FEXT_OPCODE"
50]
51
52nodebug_extopcodes = [
53 "CR_ACTIVETEXTUREARB_EXTEND_OPCODE"
54]
55
56#
57# Useful functions
58#
59
60def ReadData( offset, arg_type ):
61 """Emit a READ_DOUBLE or READ_DATA call for pulling a GL function
62 argument out of the buffer's operand area."""
63 if arg_type == "GLdouble" or arg_type == "GLclampd":
64 retval = "READ_DOUBLE( %d )" % offset
65 else:
66 retval = "READ_DATA( %d, %s )" % (offset, arg_type)
67 return retval
68
69
70def FindReturnPointer( return_type, params ):
71 """For GL functions that return values (either as the return value or
72 through a pointer parameter) emit a SET_RETURN_PTR call."""
73 arg_len = apiutil.PacketLength( params )
74 if (return_type != 'void'):
75 print '\tSET_RETURN_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
76 else:
77 paramList = [ ('foo', 'void *', 0) ]
78 print '\tSET_RETURN_PTR( %d );' % (arg_len + 8 - apiutil.PacketLength(paramList))
79
80
81def FindWritebackPointer( return_type, params ):
82 """Emit a SET_WRITEBACK_PTR call."""
83 arg_len = apiutil.PacketLength( params )
84 if return_type != 'void':
85 paramList = [ ('foo', 'void *', 0) ]
86 arg_len += apiutil.PacketLength( paramList )
87
88 print '\tSET_WRITEBACK_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
89
90
91def MakeNormalCall( return_type, func_name, params, counter_init = 0 ):
92 counter = counter_init
93 copy_of_params = params[:]
94
95 for i in range( 0, len(params) ):
96 (name, type, vecSize) = params[i]
97 if apiutil.IsPointer(copy_of_params[i][1]):
98 params[i] = ('NULL', type, vecSize)
99 copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
100 if not "get" in apiutil.Properties(func_name):
101 print '\tcrError( "%s needs to be special cased!" );' % func_name
102 else:
103 print "\t%s %s = %s;" % ( copy_of_params[i][1], name, ReadData( counter, copy_of_params[i][1] ) )
104 counter += apiutil.sizeof(copy_of_params[i][1])
105
106 if ("get" in apiutil.Properties(func_name)):
107 FindReturnPointer( return_type, params )
108 FindWritebackPointer( return_type, params )
109
110 if return_type != "void":
111 print "\t(void)",
112 else:
113 print "\t",
114 print "cr_unpackDispatch.%s( %s );" % (func_name, apiutil.MakeCallString(params))
115
116
117def MakeVectorCall( return_type, func_name, arg_type ):
118 """Convert a call like glVertex3f to glVertex3fv."""
119 vec_func = apiutil.VectorFunction(func_name)
120 params = apiutil.Parameters(vec_func)
121 assert len(params) == 1
122 (arg_name, vecType, vecSize) = params[0]
123
124 if arg_type == "GLdouble" or arg_type == "GLclampd":
125 print "#ifdef CR_UNALIGNED_ACCESS_OKAY"
126 print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
127 print "#else"
128 for index in range(0, vecSize):
129 print "\tGLdouble v" + `index` + " = READ_DOUBLE(", `index * 8`, ");"
130 if return_type != "void":
131 print "\t(void) cr_unpackDispatch.%s(" % func_name,
132 else:
133 print "\tcr_unpackDispatch.%s(" % func_name,
134 for index in range(0, vecSize):
135 print "v" + `index`,
136 if index != vecSize - 1:
137 print ",",
138 print ");"
139 print "#endif"
140 else:
141 print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
142
143
144
145keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
146
147
148#
149# Generate unpack functions for all the simple functions.
150#
151for func_name in keys:
152 if (not "pack" in apiutil.ChromiumProps(func_name) or
153 apiutil.FindSpecial( "unpacker", func_name )):
154 continue
155
156 params = apiutil.Parameters(func_name)
157 return_type = apiutil.ReturnType(func_name)
158
159 print "static void crUnpack%s(void)" % func_name
160 print "{"
161
162 vector_func = apiutil.VectorFunction(func_name)
163 if (vector_func and len(apiutil.Parameters(vector_func)) == 1):
164 MakeVectorCall( return_type, func_name, params[0][1] )
165 else:
166 MakeNormalCall( return_type, func_name, params )
167 packet_length = apiutil.PacketLength( params )
168 if packet_length == 0:
169 print "\tINCR_DATA_PTR_NO_ARGS( );"
170 else:
171 print "\tINCR_DATA_PTR( %d );" % packet_length
172 print "}\n"
173
174
175#
176# Emit some code
177#
178print """
179typedef struct __dispatchNode {
180 const unsigned char *unpackData;
181 struct __dispatchNode *next;
182} DispatchNode;
183
184static DispatchNode *unpackStack = NULL;
185
186static SPUDispatchTable *cr_lastDispatch = NULL;
187
188void crUnpackPush(void)
189{
190 DispatchNode *node = (DispatchNode*)crAlloc( sizeof( *node ) );
191 node->next = unpackStack;
192 unpackStack = node;
193 node->unpackData = cr_unpackData;
194}
195
196void crUnpackPop(void)
197{
198 DispatchNode *node = unpackStack;
199
200 if (!node)
201 {
202 crError( "crUnpackPop called with an empty stack!" );
203 }
204 unpackStack = node->next;
205 cr_unpackData = node->unpackData;
206 crFree( node );
207}
208
209void crUnpack( const void *data, const void *opcodes,
210 unsigned int num_opcodes, SPUDispatchTable *table )
211{
212 unsigned int i;
213 const unsigned char *unpack_opcodes;
214 if (table != cr_lastDispatch)
215 {
216 crSPUCopyDispatchTable( &cr_unpackDispatch, table );
217 cr_lastDispatch = table;
218 }
219
220 unpack_opcodes = (const unsigned char *)opcodes;
221 cr_unpackData = (const unsigned char *)data;
222
223#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
224 crDebug("crUnpack: %d opcodes", num_opcodes);
225#endif
226
227 for (i = 0 ; i < num_opcodes ; i++)
228 {
229
230 CRDBGPTR_CHECKZ(writeback_ptr);
231 CRDBGPTR_CHECKZ(return_ptr);
232
233 /*crDebug(\"Unpacking opcode \%d\", *unpack_opcodes);*/
234 switch( *unpack_opcodes )
235 {"""
236
237#
238# Emit switch cases for all unextended opcodes
239#
240for func_name in keys:
241 if "pack" in apiutil.ChromiumProps(func_name):
242 print '\t\t\tcase %s:' % apiutil.OpcodeName( func_name )
243 if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
244 print """
245#ifdef CR_UNPACK_DEBUG_LAST_OPCODES
246 if (i==(num_opcodes-1))
247#endif
248#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
249 crDebug("Unpack: %s");
250#endif """ % apiutil.OpcodeName(func_name)
251 print '\t\t\t\tcrUnpack%s(); \n\t\t\t\tbreak;' % func_name
252
253print """
254 case CR_EXTEND_OPCODE:
255 #ifdef CR_UNPACK_DEBUG_OPCODES
256 crUnpackExtendDbg();
257 #else
258 # ifdef CR_UNPACK_DEBUG_LAST_OPCODES
259 if (i==(num_opcodes-1)) crUnpackExtendDbg();
260 else
261 # endif
262 crUnpackExtend();
263 #endif
264 break;
265 case CR_CMDBLOCKBEGIN_OPCODE:
266 case CR_CMDBLOCKEND_OPCODE:
267 case CR_NOP_OPCODE:
268 INCR_DATA_PTR_NO_ARGS( );
269 break;
270 default:
271 crError( "Unknown opcode: %d", *unpack_opcodes );
272 break;
273 }
274
275 CRDBGPTR_CHECKZ(writeback_ptr);
276 CRDBGPTR_CHECKZ(return_ptr);
277
278 unpack_opcodes--;
279 }
280}"""
281
282
283#
284# Emit unpack functions for extended opcodes, non-special functions only.
285#
286for func_name in keys:
287 if ("extpack" in apiutil.ChromiumProps(func_name)
288 and not apiutil.FindSpecial("unpacker", func_name)):
289 return_type = apiutil.ReturnType(func_name)
290 params = apiutil.Parameters(func_name)
291 print 'static void crUnpackExtend%s(void)' % func_name
292 print '{'
293 MakeNormalCall( return_type, func_name, params, 8 )
294 print '}\n'
295
296print 'static void crUnpackExtend(void)'
297print '{'
298print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
299print ''
300print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
301print '\tswitch( extend_opcode )'
302print '\t{'
303
304
305#
306# Emit switch statement for extended opcodes
307#
308for func_name in keys:
309 if "extpack" in apiutil.ChromiumProps(func_name):
310 print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
311# print '\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
312 print '\t\t\tcrUnpackExtend%s( );' % func_name
313 print '\t\t\tbreak;'
314
315print """ default:
316 crError( "Unknown extended opcode: %d", (int) extend_opcode );
317 break;
318 }
319 INCR_VAR_PTR();
320}"""
321
322print 'static void crUnpackExtendDbg(void)'
323print '{'
324print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
325print ''
326print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
327print '\tswitch( extend_opcode )'
328print '\t{'
329
330
331#
332# Emit switch statement for extended opcodes
333#
334for func_name in keys:
335 if "extpack" in apiutil.ChromiumProps(func_name):
336 print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
337 if not apiutil.ExtendedOpcodeName(func_name) in nodebug_extopcodes:
338 print '\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
339 print '\t\t\tcrUnpackExtend%s( );' % func_name
340 print '\t\t\tbreak;'
341
342print """ default:
343 crError( "Unknown extended opcode: %d", (int) extend_opcode );
344 break;
345 }
346 INCR_VAR_PTR();
347}"""
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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