diff options
author | José Fonseca <jose.r.fonseca@gmail.com> | 2011-10-07 23:36:39 +0100 |
---|---|---|
committer | José Fonseca <jose.r.fonseca@gmail.com> | 2011-10-07 23:36:39 +0100 |
commit | 2741ed8b85842cf5f08fe6dff8d4ae5626434046 (patch) | |
tree | f279aededc60370c6b4cd92a4b382749ffa03f66 | |
parent | 69fe7f8e041e615035e333e0581c003137007e63 (diff) |
Use a vector to dispatch calls when retracing.
As opposed to generated switch tables.
Speeds up retracing speed by 8%, and should speed up compilation times too.
-rwxr-xr-x | CMakeLists.txt | 2 | ||||
-rw-r--r-- | glretrace.hpp | 8 | ||||
-rw-r--r-- | glretrace.py | 2 | ||||
-rw-r--r-- | glretrace_cgl.cpp | 20 | ||||
-rw-r--r-- | glretrace_glx.cpp | 7 | ||||
-rw-r--r-- | glretrace_main.cpp | 21 | ||||
-rw-r--r-- | glretrace_wgl.cpp | 1034 | ||||
-rw-r--r-- | retrace.cpp | 46 | ||||
-rw-r--r-- | retrace.hpp | 32 | ||||
-rw-r--r-- | retrace.py | 23 |
10 files changed, 151 insertions, 1044 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d5db92..8987c7d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -390,7 +390,7 @@ endif () add_custom_command ( OUTPUT glretrace_gl.cpp COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp - DEPENDS glretrace.py retrace.py codegen.py specs/glapi.py specs/gltypes.py specs/stdapi.py + DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py ) add_custom_command ( diff --git a/glretrace.hpp b/glretrace.hpp index 5b93f2d..9cf615e 100644 --- a/glretrace.hpp +++ b/glretrace.hpp @@ -28,6 +28,7 @@ #include "trace_parser.hpp" #include "glws.hpp" +#include "retrace.hpp" namespace glretrace { @@ -62,9 +63,10 @@ extern unsigned dump_state; void checkGlError(Trace::Call &call); -void retrace_call_cgl(Trace::Call &call); -void retrace_call_glx(Trace::Call &call); -void retrace_call_wgl(Trace::Call &call); +extern const retrace::Entry gl_callbacks[]; +extern const retrace::Entry cgl_callbacks[]; +extern const retrace::Entry glx_callbacks[]; +extern const retrace::Entry wgl_callbacks[]; void snapshot(unsigned call_no); void frame_complete(unsigned call_no); diff --git a/glretrace.py b/glretrace.py index 4edd93a..925fb18 100644 --- a/glretrace.py +++ b/glretrace.py @@ -34,6 +34,8 @@ from retrace import Retracer class GlRetracer(Retracer): + table_name = 'glretrace::gl_callbacks' + def retrace_function(self, function): Retracer.retrace_function(self, function) diff --git a/glretrace_cgl.cpp b/glretrace_cgl.cpp index 8cb5786..411706b 100644 --- a/glretrace_cgl.cpp +++ b/glretrace_cgl.cpp @@ -112,19 +112,9 @@ static void retrace_CGLFlushDrawable(Trace::Call &call) { } -void glretrace::retrace_call_cgl(Trace::Call &call) { - const char *name = call.name(); - - if (strcmp(name, "CGLSetCurrentContext") == 0) { - retrace_CGLSetCurrentContext(call); - return; - } - - if (strcmp(name, "CGLFlushDrawable") == 0) { - retrace_CGLFlushDrawable(call); - return; - } - - return; -} +const retrace::Entry glretrace::cgl_callbacks[] = { + {"CGLSetCurrentContext", &retrace_CGLSetCurrentContext}, + {"CGLFlushDrawable", &retrace_CGLFlushDrawable}, + {NULL, NULL}, +}; diff --git a/glretrace_glx.cpp b/glretrace_glx.cpp index 72535ae..72357ed 100644 --- a/glretrace_glx.cpp +++ b/glretrace_glx.cpp @@ -164,7 +164,7 @@ static void retrace_glXMakeContextCurrent(Trace::Call &call) { } } -static const retrace::Entry callbacks[] = { +const retrace::Entry glretrace::glx_callbacks[] = { //{"glXBindChannelToWindowSGIX", &retrace_glXBindChannelToWindowSGIX}, //{"glXBindSwapBarrierNV", &retrace_glXBindSwapBarrierNV}, //{"glXBindSwapBarrierSGIX", &retrace_glXBindSwapBarrierSGIX}, @@ -255,9 +255,6 @@ static const retrace::Entry callbacks[] = { {"glXWaitGL", &retrace::ignore}, {"glXWaitVideoSyncSGI", &retrace::ignore}, {"glXWaitX", &retrace::ignore}, + {NULL, NULL}, }; -void glretrace::retrace_call_glx(Trace::Call &call) { - retrace::dispatch(call, callbacks, sizeof(callbacks)/sizeof(callbacks[0])); -} - diff --git a/glretrace_main.cpp b/glretrace_main.cpp index cd35889..80660d7 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -194,28 +194,23 @@ void frame_complete(unsigned call_no) { static void display(void) { + retrace::Retracer retracer; + + retracer.addCallbacks(gl_callbacks); + retracer.addCallbacks(glx_callbacks); + retracer.addCallbacks(wgl_callbacks); + retracer.addCallbacks(cgl_callbacks); + startTime = OS::GetTime(); Trace::Call *call; while ((call = parser.parse_call())) { - const char *name = call->name(); - if (retrace::verbosity >= 1) { std::cout << *call; std::cout.flush(); } - if (name[0] == 'C' && name[1] == 'G' && name[2] == 'L') { - glretrace::retrace_call_cgl(*call); - } - else if (name[0] == 'w' && name[1] == 'g' && name[2] == 'l') { - glretrace::retrace_call_wgl(*call); - } - else if (name[0] == 'g' && name[1] == 'l' && name[2] == 'X') { - glretrace::retrace_call_glx(*call); - } else { - retrace::retrace_call(*call); - } + retracer.retrace(*call); if (!insideGlBeginEnd && drawable && context && diff --git a/glretrace_wgl.cpp b/glretrace_wgl.cpp index a3ca05b..d88f27a 100644 --- a/glretrace_wgl.cpp +++ b/glretrace_wgl.cpp @@ -242,980 +242,62 @@ static void retrace_glAddSwapHintRectWIN(Trace::Call &call) { static void retrace_wglGetProcAddress(Trace::Call &call) { } -void glretrace::retrace_call_wgl(Trace::Call &call) { - const char *name = call.name(); - - switch (name[0]) { - case 'g': - if (name[1] == 'l' && name[2] == 'A' && name[3] == 'd' && name[4] == 'd' && name[5] == 'S' && name[6] == 'w' && name[7] == 'a' && name[8] == 'p' && name[9] == 'H' && name[10] == 'i' && name[11] == 'n' && name[12] == 't' && name[13] == 'R' && name[14] == 'e' && name[15] == 'c' && name[16] == 't' && name[17] == 'W' && name[18] == 'I' && name[19] == 'N' && name[20] == '\0') { - // glAddSwapHintRectWIN - retrace_glAddSwapHintRectWIN(call); - return; - } - break; - case 'w': - switch (name[1]) { - case 'g': - switch (name[2]) { - case 'l': - switch (name[3]) { - case 'A': - if (name[4] == 'l' && name[5] == 'l' && name[6] == 'o' && name[7] == 'c' && name[8] == 'a' && name[9] == 't' && name[10] == 'e' && name[11] == 'M' && name[12] == 'e' && name[13] == 'm' && name[14] == 'o' && name[15] == 'r' && name[16] == 'y' && name[17] == 'N' && name[18] == 'V' && name[19] == '\0') { - // wglAllocateMemoryNV - retrace_wglAllocateMemoryNV(call); - return; - } - break; - case 'B': - if (name[4] == 'i' && name[5] == 'n' && name[6] == 'd' && name[7] == 'T' && name[8] == 'e' && name[9] == 'x' && name[10] == 'I' && name[11] == 'm' && name[12] == 'a' && name[13] == 'g' && name[14] == 'e' && name[15] == 'A' && name[16] == 'R' && name[17] == 'B' && name[18] == '\0') { - // wglBindTexImageARB - retrace_wglBindTexImageARB(call); - return; - } - break; - case 'C': - switch (name[4]) { - case 'h': - switch (name[5]) { - case 'o': - switch (name[6]) { - case 'o': - switch (name[7]) { - case 's': - switch (name[8]) { - case 'e': - switch (name[9]) { - case 'P': - switch (name[10]) { - case 'i': - switch (name[11]) { - case 'x': - switch (name[12]) { - case 'e': - switch (name[13]) { - case 'l': - switch (name[14]) { - case 'F': - switch (name[15]) { - case 'o': - switch (name[16]) { - case 'r': - switch (name[17]) { - case 'm': - switch (name[18]) { - case 'a': - switch (name[19]) { - case 't': - switch (name[20]) { - case '\0': - // wglChoosePixelFormat - retrace_wglChoosePixelFormat(call); - return; - break; - case 'A': - if (name[21] == 'R' && name[22] == 'B' && name[23] == '\0') { - // wglChoosePixelFormatARB - retrace_wglChoosePixelFormatARB(call); - return; - } - break; - case 'E': - if (name[21] == 'X' && name[22] == 'T' && name[23] == '\0') { - // wglChoosePixelFormatEXT - retrace_wglChoosePixelFormatEXT(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'o': - if (name[5] == 'p' && name[6] == 'y' && name[7] == 'C' && name[8] == 'o' && name[9] == 'n' && name[10] == 't' && name[11] == 'e' && name[12] == 'x' && name[13] == 't' && name[14] == '\0') { - // wglCopyContext - retrace_wglCopyContext(call); - return; - } - break; - case 'r': - switch (name[5]) { - case 'e': - switch (name[6]) { - case 'a': - switch (name[7]) { - case 't': - switch (name[8]) { - case 'e': - switch (name[9]) { - case 'B': - if (name[10] == 'u' && name[11] == 'f' && name[12] == 'f' && name[13] == 'e' && name[14] == 'r' && name[15] == 'R' && name[16] == 'e' && name[17] == 'g' && name[18] == 'i' && name[19] == 'o' && name[20] == 'n' && name[21] == 'A' && name[22] == 'R' && name[23] == 'B' && name[24] == '\0') { - // wglCreateBufferRegionARB - retrace_wglCreateBufferRegionARB(call); - return; - } - break; - case 'C': - switch (name[10]) { - case 'o': - switch (name[11]) { - case 'n': - switch (name[12]) { - case 't': - switch (name[13]) { - case 'e': - switch (name[14]) { - case 'x': - switch (name[15]) { - case 't': - switch (name[16]) { - case '\0': - // wglCreateContext - retrace_wglCreateContext(call); - return; - break; - case 'A': - if (name[17] == 't' && name[18] == 't' && name[19] == 'r' && name[20] == 'i' && name[21] == 'b' && name[22] == 's' && name[23] == 'A' && name[24] == 'R' && name[25] == 'B' && name[26] == '\0') { - // wglCreateContextAttribsARB - retrace_wglCreateContextAttribsARB(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'L': - if (name[10] == 'a' && name[11] == 'y' && name[12] == 'e' && name[13] == 'r' && name[14] == 'C' && name[15] == 'o' && name[16] == 'n' && name[17] == 't' && name[18] == 'e' && name[19] == 'x' && name[20] == 't' && name[21] == '\0') { - // wglCreateLayerContext - retrace_wglCreateLayerContext(call); - return; - } - break; - case 'P': - if (name[10] == 'b' && name[11] == 'u' && name[12] == 'f' && name[13] == 'f' && name[14] == 'e' && name[15] == 'r' && name[16] == 'A' && name[17] == 'R' && name[18] == 'B' && name[19] == '\0') { - // wglCreatePbufferARB - retrace_wglCreatePbufferARB(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'D': - switch (name[4]) { - case 'e': - switch (name[5]) { - case 'l': - switch (name[6]) { - case 'e': - switch (name[7]) { - case 't': - switch (name[8]) { - case 'e': - switch (name[9]) { - case 'B': - if (name[10] == 'u' && name[11] == 'f' && name[12] == 'f' && name[13] == 'e' && name[14] == 'r' && name[15] == 'R' && name[16] == 'e' && name[17] == 'g' && name[18] == 'i' && name[19] == 'o' && name[20] == 'n' && name[21] == 'A' && name[22] == 'R' && name[23] == 'B' && name[24] == '\0') { - // wglDeleteBufferRegionARB - retrace_wglDeleteBufferRegionARB(call); - return; - } - break; - case 'C': - if (name[10] == 'o' && name[11] == 'n' && name[12] == 't' && name[13] == 'e' && name[14] == 'x' && name[15] == 't' && name[16] == '\0') { - // wglDeleteContext - retrace_wglDeleteContext(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - case 's': - switch (name[6]) { - case 'c': - switch (name[7]) { - case 'r': - switch (name[8]) { - case 'i': - switch (name[9]) { - case 'b': - switch (name[10]) { - case 'e': - switch (name[11]) { - case 'L': - if (name[12] == 'a' && name[13] == 'y' && name[14] == 'e' && name[15] == 'r' && name[16] == 'P' && name[17] == 'l' && name[18] == 'a' && name[19] == 'n' && name[20] == 'e' && name[21] == '\0') { - // wglDescribeLayerPlane - retrace_wglDescribeLayerPlane(call); - return; - } - break; - case 'P': - if (name[12] == 'i' && name[13] == 'x' && name[14] == 'e' && name[15] == 'l' && name[16] == 'F' && name[17] == 'o' && name[18] == 'r' && name[19] == 'm' && name[20] == 'a' && name[21] == 't' && name[22] == '\0') { - // wglDescribePixelFormat - retrace_wglDescribePixelFormat(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 't': - if (name[7] == 'r' && name[8] == 'o' && name[9] == 'y' && name[10] == 'P' && name[11] == 'b' && name[12] == 'u' && name[13] == 'f' && name[14] == 'f' && name[15] == 'e' && name[16] == 'r' && name[17] == 'A' && name[18] == 'R' && name[19] == 'B' && name[20] == '\0') { - // wglDestroyPbufferARB - retrace_wglDestroyPbufferARB(call); - return; - } - break; - } - break; - } - break; - } - break; - case 'F': - if (name[4] == 'r' && name[5] == 'e' && name[6] == 'e' && name[7] == 'M' && name[8] == 'e' && name[9] == 'm' && name[10] == 'o' && name[11] == 'r' && name[12] == 'y' && name[13] == 'N' && name[14] == 'V' && name[15] == '\0') { - // wglFreeMemoryNV - retrace_wglFreeMemoryNV(call); - return; - } - break; - case 'G': - switch (name[4]) { - case 'e': - switch (name[5]) { - case 't': - switch (name[6]) { - case 'C': - switch (name[7]) { - case 'u': - switch (name[8]) { - case 'r': - switch (name[9]) { - case 'r': - switch (name[10]) { - case 'e': - switch (name[11]) { - case 'n': - switch (name[12]) { - case 't': - switch (name[13]) { - case 'C': - if (name[14] == 'o' && name[15] == 'n' && name[16] == 't' && name[17] == 'e' && name[18] == 'x' && name[19] == 't' && name[20] == '\0') { - // wglGetCurrentContext - return; - } - break; - case 'D': - if (name[14] == 'C' && name[15] == '\0') { - // wglGetCurrentDC - return; - } - break; - case 'R': - switch (name[14]) { - case 'e': - switch (name[15]) { - case 'a': - switch (name[16]) { - case 'd': - switch (name[17]) { - case 'D': - switch (name[18]) { - case 'C': - switch (name[19]) { - case 'A': - if (name[20] == 'R' && name[21] == 'B' && name[22] == '\0') { - // wglGetCurrentReadDCARB - return; - } - break; - case 'E': - if (name[20] == 'X' && name[21] == 'T' && name[22] == '\0') { - // wglGetCurrentReadDCEXT - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'D': - if (name[7] == 'e' && name[8] == 'f' && name[9] == 'a' && name[10] == 'u' && name[11] == 'l' && name[12] == 't' && name[13] == 'P' && name[14] == 'r' && name[15] == 'o' && name[16] == 'c' && name[17] == 'A' && name[18] == 'd' && name[19] == 'd' && name[20] == 'r' && name[21] == 'e' && name[22] == 's' && name[23] == 's' && name[24] == '\0') { - // wglGetDefaultProcAddress - return; - } - break; - case 'E': - switch (name[7]) { - case 'x': - switch (name[8]) { - case 't': - switch (name[9]) { - case 'e': - switch (name[10]) { - case 'n': - switch (name[11]) { - case 's': - switch (name[12]) { - case 'i': - switch (name[13]) { - case 'o': - switch (name[14]) { - case 'n': - switch (name[15]) { - case 's': - switch (name[16]) { - case 'S': - switch (name[17]) { - case 't': - switch (name[18]) { - case 'r': - switch (name[19]) { - case 'i': - switch (name[20]) { - case 'n': - switch (name[21]) { - case 'g': - switch (name[22]) { - case 'A': - if (name[23] == 'R' && name[24] == 'B' && name[25] == '\0') { - // wglGetExtensionsStringARB - return; - } - break; - case 'E': - if (name[23] == 'X' && name[24] == 'T' && name[25] == '\0') { - // wglGetExtensionsStringEXT - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'L': - if (name[7] == 'a' && name[8] == 'y' && name[9] == 'e' && name[10] == 'r' && name[11] == 'P' && name[12] == 'a' && name[13] == 'l' && name[14] == 'e' && name[15] == 't' && name[16] == 't' && name[17] == 'e' && name[18] == 'E' && name[19] == 'n' && name[20] == 't' && name[21] == 'r' && name[22] == 'i' && name[23] == 'e' && name[24] == 's' && name[25] == '\0') { - // wglGetLayerPaletteEntries - return; - } - break; - case 'P': - switch (name[7]) { - case 'b': - if (name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 'D' && name[14] == 'C' && name[15] == 'A' && name[16] == 'R' && name[17] == 'B' && name[18] == '\0') { - // wglGetPbufferDCARB - retrace_wglGetPbufferDCARB(call); - return; - } - break; - case 'i': - switch (name[8]) { - case 'x': - switch (name[9]) { - case 'e': - switch (name[10]) { - case 'l': - switch (name[11]) { - case 'F': - switch (name[12]) { - case 'o': - switch (name[13]) { - case 'r': - switch (name[14]) { - case 'm': - switch (name[15]) { - case 'a': - switch (name[16]) { - case 't': - switch (name[17]) { - case '\0': - // wglGetPixelFormat - return; - break; - case 'A': - switch (name[18]) { - case 't': - switch (name[19]) { - case 't': - switch (name[20]) { - case 'r': - switch (name[21]) { - case 'i': - switch (name[22]) { - case 'b': - switch (name[23]) { - case 'f': - switch (name[24]) { - case 'v': - switch (name[25]) { - case 'A': - if (name[26] == 'R' && name[27] == 'B' && name[28] == '\0') { - // wglGetPixelFormatAttribfvARB - return; - } - break; - case 'E': - if (name[26] == 'X' && name[27] == 'T' && name[28] == '\0') { - // wglGetPixelFormatAttribfvEXT - return; - } - break; - } - break; - } - break; - case 'i': - switch (name[24]) { - case 'v': - switch (name[25]) { - case 'A': - if (name[26] == 'R' && name[27] == 'B' && name[28] == '\0') { - // wglGetPixelFormatAttribivARB - return; - } - break; - case 'E': - if (name[26] == 'X' && name[27] == 'T' && name[28] == '\0') { - // wglGetPixelFormatAttribivEXT - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'r': - if (name[8] == 'o' && name[9] == 'c' && name[10] == 'A' && name[11] == 'd' && name[12] == 'd' && name[13] == 'r' && name[14] == 'e' && name[15] == 's' && name[16] == 's' && name[17] == '\0') { - // wglGetProcAddress - retrace_wglGetProcAddress(call); - return; - } - break; - } - break; - case 'S': - if (name[7] == 'w' && name[8] == 'a' && name[9] == 'p' && name[10] == 'I' && name[11] == 'n' && name[12] == 't' && name[13] == 'e' && name[14] == 'r' && name[15] == 'v' && name[16] == 'a' && name[17] == 'l' && name[18] == 'E' && name[19] == 'X' && name[20] == 'T' && name[21] == '\0') { - // wglGetSwapIntervalEXT - return; - } - break; - } - break; - } - break; - } - break; - case 'M': - switch (name[4]) { - case 'a': - switch (name[5]) { - case 'k': - switch (name[6]) { - case 'e': - switch (name[7]) { - case 'C': - switch (name[8]) { - case 'o': - switch (name[9]) { - case 'n': - switch (name[10]) { - case 't': - switch (name[11]) { - case 'e': - switch (name[12]) { - case 'x': - switch (name[13]) { - case 't': - switch (name[14]) { - case 'C': - switch (name[15]) { - case 'u': - switch (name[16]) { - case 'r': - switch (name[17]) { - case 'r': - switch (name[18]) { - case 'e': - switch (name[19]) { - case 'n': - switch (name[20]) { - case 't': - switch (name[21]) { - case 'A': - if (name[22] == 'R' && name[23] == 'B' && name[24] == '\0') { - // wglMakeContextCurrentARB - retrace_wglMakeContextCurrentARB(call); - return; - } - break; - case 'E': - if (name[22] == 'X' && name[23] == 'T' && name[24] == '\0') { - // wglMakeContextCurrentEXT - retrace_wglMakeContextCurrentEXT(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'u': - if (name[9] == 'r' && name[10] == 'r' && name[11] == 'e' && name[12] == 'n' && name[13] == 't' && name[14] == '\0') { - // wglMakeCurrent - retrace_wglMakeCurrent(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'Q': - if (name[4] == 'u' && name[5] == 'e' && name[6] == 'r' && name[7] == 'y' && name[8] == 'P' && name[9] == 'b' && name[10] == 'u' && name[11] == 'f' && name[12] == 'f' && name[13] == 'e' && name[14] == 'r' && name[15] == 'A' && name[16] == 'R' && name[17] == 'B' && name[18] == '\0') { - // wglQueryPbufferARB - retrace_wglQueryPbufferARB(call); - return; - } - break; - case 'R': - switch (name[4]) { - case 'e': - switch (name[5]) { - case 'a': - if (name[6] == 'l' && name[7] == 'i' && name[8] == 'z' && name[9] == 'e' && name[10] == 'L' && name[11] == 'a' && name[12] == 'y' && name[13] == 'e' && name[14] == 'r' && name[15] == 'P' && name[16] == 'a' && name[17] == 'l' && name[18] == 'e' && name[19] == 't' && name[20] == 't' && name[21] == 'e' && name[22] == '\0') { - // wglRealizeLayerPalette - retrace_wglRealizeLayerPalette(call); - return; - } - break; - case 'l': - switch (name[6]) { - case 'e': - switch (name[7]) { - case 'a': - switch (name[8]) { - case 's': - switch (name[9]) { - case 'e': - switch (name[10]) { - case 'P': - if (name[11] == 'b' && name[12] == 'u' && name[13] == 'f' && name[14] == 'f' && name[15] == 'e' && name[16] == 'r' && name[17] == 'D' && name[18] == 'C' && name[19] == 'A' && name[20] == 'R' && name[21] == 'B' && name[22] == '\0') { - // wglReleasePbufferDCARB - retrace_wglReleasePbufferDCARB(call); - return; - } - break; - case 'T': - if (name[11] == 'e' && name[12] == 'x' && name[13] == 'I' && name[14] == 'm' && name[15] == 'a' && name[16] == 'g' && name[17] == 'e' && name[18] == 'A' && name[19] == 'R' && name[20] == 'B' && name[21] == '\0') { - // wglReleaseTexImageARB - retrace_wglReleaseTexImageARB(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 's': - if (name[6] == 't' && name[7] == 'o' && name[8] == 'r' && name[9] == 'e' && name[10] == 'B' && name[11] == 'u' && name[12] == 'f' && name[13] == 'f' && name[14] == 'e' && name[15] == 'r' && name[16] == 'R' && name[17] == 'e' && name[18] == 'g' && name[19] == 'i' && name[20] == 'o' && name[21] == 'n' && name[22] == 'A' && name[23] == 'R' && name[24] == 'B' && name[25] == '\0') { - // wglRestoreBufferRegionARB - retrace_wglRestoreBufferRegionARB(call); - return; - } - break; - } - break; - } - break; - case 'S': - switch (name[4]) { - case 'a': - if (name[5] == 'v' && name[6] == 'e' && name[7] == 'B' && name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 'R' && name[14] == 'e' && name[15] == 'g' && name[16] == 'i' && name[17] == 'o' && name[18] == 'n' && name[19] == 'A' && name[20] == 'R' && name[21] == 'B' && name[22] == '\0') { - // wglSaveBufferRegionARB - retrace_wglSaveBufferRegionARB(call); - return; - } - break; - case 'e': - switch (name[5]) { - case 't': - switch (name[6]) { - case 'L': - if (name[7] == 'a' && name[8] == 'y' && name[9] == 'e' && name[10] == 'r' && name[11] == 'P' && name[12] == 'a' && name[13] == 'l' && name[14] == 'e' && name[15] == 't' && name[16] == 't' && name[17] == 'e' && name[18] == 'E' && name[19] == 'n' && name[20] == 't' && name[21] == 'r' && name[22] == 'i' && name[23] == 'e' && name[24] == 's' && name[25] == '\0') { - // wglSetLayerPaletteEntries - retrace_wglSetLayerPaletteEntries(call); - return; - } - break; - case 'P': - switch (name[7]) { - case 'b': - if (name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 'A' && name[14] == 't' && name[15] == 't' && name[16] == 'r' && name[17] == 'i' && name[18] == 'b' && name[19] == 'A' && name[20] == 'R' && name[21] == 'B' && name[22] == '\0') { - // wglSetPbufferAttribARB - retrace_wglSetPbufferAttribARB(call); - return; - } - break; - case 'i': - if (name[8] == 'x' && name[9] == 'e' && name[10] == 'l' && name[11] == 'F' && name[12] == 'o' && name[13] == 'r' && name[14] == 'm' && name[15] == 'a' && name[16] == 't' && name[17] == '\0') { - // wglSetPixelFormat - retrace_wglSetPixelFormat(call); - return; - } - break; - } - break; - } - break; - } - break; - case 'h': - if (name[5] == 'a' && name[6] == 'r' && name[7] == 'e' && name[8] == 'L' && name[9] == 'i' && name[10] == 's' && name[11] == 't' && name[12] == 's' && name[13] == '\0') { - // wglShareLists - retrace_wglShareLists(call); - return; - } - break; - case 'w': - switch (name[5]) { - case 'a': - switch (name[6]) { - case 'p': - switch (name[7]) { - case 'B': - if (name[8] == 'u' && name[9] == 'f' && name[10] == 'f' && name[11] == 'e' && name[12] == 'r' && name[13] == 's' && name[14] == '\0') { - // wglSwapBuffers - retrace_wglSwapBuffers(call); - return; - } - break; - case 'I': - if (name[8] == 'n' && name[9] == 't' && name[10] == 'e' && name[11] == 'r' && name[12] == 'v' && name[13] == 'a' && name[14] == 'l' && name[15] == 'E' && name[16] == 'X' && name[17] == 'T' && name[18] == '\0') { - // wglSwapIntervalEXT - retrace_wglSwapIntervalEXT(call); - return; - } - break; - case 'L': - if (name[8] == 'a' && name[9] == 'y' && name[10] == 'e' && name[11] == 'r' && name[12] == 'B' && name[13] == 'u' && name[14] == 'f' && name[15] == 'f' && name[16] == 'e' && name[17] == 'r' && name[18] == 's' && name[19] == '\0') { - // wglSwapLayerBuffers - retrace_wglSwapLayerBuffers(call); - return; - } - break; - case 'M': - if (name[8] == 'u' && name[9] == 'l' && name[10] == 't' && name[11] == 'i' && name[12] == 'p' && name[13] == 'l' && name[14] == 'e' && name[15] == 'B' && name[16] == 'u' && name[17] == 'f' && name[18] == 'f' && name[19] == 'e' && name[20] == 'r' && name[21] == 's' && name[22] == '\0') { - // wglSwapMultipleBuffers - retrace_wglSwapMultipleBuffers(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'U': - switch (name[4]) { - case 's': - switch (name[5]) { - case 'e': - switch (name[6]) { - case 'F': - switch (name[7]) { - case 'o': - switch (name[8]) { - case 'n': - switch (name[9]) { - case 't': - switch (name[10]) { - case 'B': - switch (name[11]) { - case 'i': - switch (name[12]) { - case 't': - switch (name[13]) { - case 'm': - switch (name[14]) { - case 'a': - switch (name[15]) { - case 'p': - switch (name[16]) { - case 's': - switch (name[17]) { - case 'A': - if (name[18] == '\0') { - // wglUseFontBitmapsA - retrace_wglUseFontBitmapsA(call); - return; - } - break; - case 'W': - if (name[18] == '\0') { - // wglUseFontBitmapsW - retrace_wglUseFontBitmapsW(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - case 'O': - switch (name[11]) { - case 'u': - switch (name[12]) { - case 't': - switch (name[13]) { - case 'l': - switch (name[14]) { - case 'i': - switch (name[15]) { - case 'n': - switch (name[16]) { - case 'e': - switch (name[17]) { - case 's': - switch (name[18]) { - case 'A': - if (name[19] == '\0') { - // wglUseFontOutlinesA - retrace_wglUseFontOutlinesA(call); - return; - } - break; - case 'W': - if (name[19] == '\0') { - // wglUseFontOutlinesW - retrace_wglUseFontOutlinesW(call); - return; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - retrace::retrace_unknown(call); -} +const retrace::Entry glretrace::wgl_callbacks[] = { + {"glAddSwapHintRectWIN", &retrace_glAddSwapHintRectWIN}, + {"wglAllocateMemoryNV", &retrace_wglAllocateMemoryNV}, + {"wglBindTexImageARB", &retrace_wglBindTexImageARB}, + {"wglChoosePixelFormat", &retrace_wglChoosePixelFormat}, + {"wglChoosePixelFormatARB", &retrace_wglChoosePixelFormatARB}, + {"wglChoosePixelFormatEXT", &retrace_wglChoosePixelFormatEXT}, + {"wglCopyContext", &retrace_wglCopyContext}, + {"wglCreateBufferRegionARB", &retrace_wglCreateBufferRegionARB}, + {"wglCreateContext", &retrace_wglCreateContext}, + {"wglCreateContextAttribsARB", &retrace_wglCreateContextAttribsARB}, + {"wglCreateLayerContext", &retrace_wglCreateLayerContext}, + {"wglCreatePbufferARB", &retrace_wglCreatePbufferARB}, + {"wglDeleteBufferRegionARB", &retrace_wglDeleteBufferRegionARB}, + {"wglDeleteContext", &retrace_wglDeleteContext}, + {"wglDescribeLayerPlane", &retrace_wglDescribeLayerPlane}, + {"wglDescribePixelFormat", &retrace_wglDescribePixelFormat}, + {"wglDestroyPbufferARB", &retrace_wglDestroyPbufferARB}, + {"wglFreeMemoryNV", &retrace_wglFreeMemoryNV}, + {"wglGetCurrentContext", &retrace::ignore}, + {"wglGetCurrentDC", &retrace::ignore}, + {"wglGetCurrentReadDCARB", &retrace::ignore}, + {"wglGetCurrentReadDCEXT", &retrace::ignore}, + {"wglGetDefaultProcAddress", &retrace::ignore}, + {"wglGetExtensionsStringARB", &retrace::ignore}, + {"wglGetExtensionsStringEXT", &retrace::ignore}, + {"wglGetLayerPaletteEntries", &retrace::ignore}, + {"wglGetPbufferDCARB", &retrace_wglGetPbufferDCARB}, + {"wglGetPixelFormat", &retrace::ignore}, + {"wglGetPixelFormatAttribfvARB", &retrace::ignore}, + {"wglGetPixelFormatAttribfvEXT", &retrace::ignore}, + {"wglGetPixelFormatAttribivARB", &retrace::ignore}, + {"wglGetPixelFormatAttribivEXT", &retrace::ignore}, + {"wglGetProcAddress", &retrace_wglGetProcAddress}, + {"wglGetSwapIntervalEXT", &retrace::ignore}, + {"wglMakeContextCurrentARB", &retrace_wglMakeContextCurrentARB}, + {"wglMakeContextCurrentEXT", &retrace_wglMakeContextCurrentEXT}, + {"wglMakeCurrent", &retrace_wglMakeCurrent}, + {"wglQueryPbufferARB", &retrace_wglQueryPbufferARB}, + {"wglRealizeLayerPalette", &retrace_wglRealizeLayerPalette}, + {"wglReleasePbufferDCARB", &retrace_wglReleasePbufferDCARB}, + {"wglReleaseTexImageARB", &retrace_wglReleaseTexImageARB}, + {"wglRestoreBufferRegionARB", &retrace_wglRestoreBufferRegionARB}, + {"wglSaveBufferRegionARB", &retrace_wglSaveBufferRegionARB}, + {"wglSetLayerPaletteEntries", &retrace_wglSetLayerPaletteEntries}, + {"wglSetPbufferAttribARB", &retrace_wglSetPbufferAttribARB}, + {"wglSetPixelFormat", &retrace_wglSetPixelFormat}, + {"wglShareLists", &retrace_wglShareLists}, + {"wglSwapBuffers", &retrace_wglSwapBuffers}, + {"wglSwapIntervalEXT", &retrace_wglSwapIntervalEXT}, + {"wglSwapLayerBuffers", &retrace_wglSwapLayerBuffers}, + {"wglSwapMultipleBuffers", &retrace_wglSwapMultipleBuffers}, + {"wglUseFontBitmapsA", &retrace_wglUseFontBitmapsA}, + {"wglUseFontBitmapsW", &retrace_wglUseFontBitmapsW}, + {"wglUseFontOutlinesA", &retrace_wglUseFontOutlinesA}, + {"wglUseFontOutlinesW", &retrace_wglUseFontOutlinesW}, + {NULL, NULL} +}; diff --git a/retrace.cpp b/retrace.cpp index 07ee5b5..ecdef5b 100644 --- a/retrace.cpp +++ b/retrace.cpp @@ -46,19 +46,45 @@ void retrace_unknown(Trace::Call &call) { } } -void dispatch(Trace::Call &call, const Entry *entries, unsigned num_entries) -{ - /* TODO: do a bisection instead of a linear search */ - - const char *name = call.name(); - for (unsigned i = 0; i < num_entries; ++i) { - if (strcmp(name, entries[i].name) == 0) { - entries[i].callback(call); - return; +inline void Retracer::addCallback(const Entry *entry) { + assert(entry->name); + assert(entry->callback); + map[entry->name] = entry->callback; +} + + +void Retracer::addCallbacks(const Entry *entries) { + while (entries->name && entries->callback) { + addCallback(entries++); + } +} + + +void Retracer::retrace(Trace::Call &call) { + Callback callback = 0; + + Trace::Id id = call.sig->id; + if (id >= callbacks.size()) { + callbacks.resize(id + 1); + callback = 0; + } else { + callback = callbacks[id]; + } + + if (!callback) { + Map::const_iterator it = map.find(call.name()); + if (it == map.end()) { + callback = &retrace_unknown; + } else { + callback = it->second; } + callbacks[id] = callback; } - retrace_unknown(call); + assert(callback); + assert(callbacks[id] == callback); + + callback(call); } diff --git a/retrace.hpp b/retrace.hpp index f134438..806d6ed 100644 --- a/retrace.hpp +++ b/retrace.hpp @@ -26,6 +26,8 @@ #ifndef _RETRACE_HPP_ #define _RETRACE_HPP_ +#include <string.h> + #include <map> #include "trace_model.hpp" @@ -82,8 +84,6 @@ public: extern int verbosity; -void retrace_call(Trace::Call &call); - void ignore(Trace::Call &call); void retrace_unknown(Trace::Call &call); @@ -95,10 +95,32 @@ struct Entry { Callback callback; }; -#define RETRACE_DISPATCH_ENTRY(name) {#name, &retrace_##name} -#define RETRACE_IGNORE_ENTRY(name) {#name, &retrace_ignore} -void dispatch(Trace::Call &call, const Entry *entries, unsigned num_entries); +struct stringComparer { + bool operator() (const char *a, const char *b) { + return strcmp(a, b) < 0; + } +}; + + +class Retracer +{ + typedef std::map<const char *, Callback, stringComparer> Map; + Map map; + + std::vector<Callback> callbacks; + +public: + Retracer() {} + + virtual ~Retracer() {} + + void addCallback(const Entry *entry); + void addCallbacks(const Entry *entries); + + void retrace(Trace::Call &call); +}; + } /* namespace retrace */ @@ -28,7 +28,6 @@ import specs.stdapi as stdapi import specs.glapi as glapi -from codegen import * class ConstRemover(stdapi.Rebuilder): @@ -250,27 +249,19 @@ class Retracer: def filter_function(self, function): return True + table_name = 'retrace::callbacks' + def retrace_functions(self, functions): functions = filter(self.filter_function, functions) for function in functions: self.retrace_function(function) - print 'void retrace::retrace_call(Trace::Call &call) {' - print ' const char *name = call.name();' - print - - func_dict = dict([(function.name, function) for function in functions]) - - def handle_case(function_name): - function = func_dict[function_name] - print ' retrace_%s(call);' % function.name - print ' return;' - - string_switch('name', func_dict.keys(), handle_case) - - print ' retrace_unknown(call);' - print '}' + print 'const retrace::Entry %s[] = {' % self.table_name + for function in functions: + print ' {"%s", &retrace_%s},' % (function.name, function.name) + print ' {NULL, NULL}' + print '};' print |