VirtualBox

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

最後變更 在這個檔案從64572是 63942,由 vboxsync 提交於 8 年 前

OpenGL: fixed the most annoying coding style flaws, mainly removing spaces after '(' and before ')', no semantic change

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

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