1 ##########################################################################
3 # Copyright 2008-2009 VMware, Inc.
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
27 """WGL tracing code generator."""
30 from wglapi import wglapi
31 from trace import Tracer
35 public_symbols = set([
38 "glAreTexturesResident",
91 "glCopyTexSubImage1D",
92 "glCopyTexSubImage2D",
101 "glDisableClientState",
110 "glEnableClientState",
153 "glGetPolygonStipple",
161 "glGetTexLevelParameterfv",
162 "glGetTexLevelParameteriv",
163 "glGetTexParameterfv",
164 "glGetTexParameteriv",
179 "glInterleavedArrays",
244 "glPrioritizeTextures",
246 "glPushClientAttrib",
373 "wglChoosePixelFormat",
376 "wglCreateLayerContext",
378 "wglDescribeLayerPlane",
379 "wglDescribePixelFormat",
380 "wglGetCurrentContext",
382 "wglGetDefaultProcAddress",
383 "wglGetLayerPaletteEntries",
387 "wglRealizeLayerPalette",
388 "wglSetLayerPaletteEntries",
392 "wglSwapLayerBuffers",
393 "wglSwapMultipleBuffers",
394 "wglUseFontBitmapsA",
395 "wglUseFontBitmapsW",
396 "wglUseFontOutlinesA",
397 "wglUseFontOutlinesW",
400 class WglTracer(Tracer):
402 def get_function_address(self, function):
403 #print 'DebugBreak();'
404 if function.name in public_symbols:
405 return '__GetProcAddress("%s")' % (function.name,)
407 print ' if (!pwglGetProcAddress) {'
408 print ' pwglGetProcAddress = (PwglGetProcAddress)__GetProcAddress("wglGetProcAddress");'
409 print ' if (!pwglGetProcAddress)'
410 print ' Trace::Abort();'
412 return 'pwglGetProcAddress("%s")' % (function.name,)
414 def wrap_ret(self, function, instance):
415 if function.name == "wglGetProcAddress":
416 print ' if (%s) {' % instance
418 func_dict = dict([(f.name, f) for f in wglapi.functions])
420 def handle_case(function_name):
421 f = func_dict[function_name]
422 ptype = self.function_pointer_type(f)
423 pvalue = self.function_pointer_value(f)
424 print ' %s = (%s)%s;' % (pvalue, ptype, instance)
425 print ' %s = (%s)&%s;' % (instance, function.type, f.name);
427 def handle_default():
428 print ' OS::DebugMessage("apitrace: unknown function \\"%s\\"\\n", lpszProc);'
430 string_switch('lpszProc', func_dict.keys(), handle_case, handle_default)
434 if __name__ == '__main__':
436 print '#define _GDI32_'
438 print '#include "glimports.hpp"'
440 print '#include "trace_write.hpp"'
441 print '#include "os.hpp"'
442 print '#include "glsize.hpp"'
446 static HINSTANCE g_hDll = NULL;
449 __GetProcAddress(LPCSTR lpProcName)
452 char szDll[MAX_PATH] = {0};
454 if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
458 strcat(szDll, "\\\\opengl32.dll");
460 g_hDll = LoadLibraryA(szDll);
466 return GetProcAddress(g_hDll, lpProcName);
471 tracer.trace_api(wglapi)
473 print '} /* extern "C" */'