]> git.cworth.org Git - apitrace/commitdiff
Merge branch 'master' into d3dretrace
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 30 Mar 2012 19:41:25 +0000 (20:41 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 30 Mar 2012 19:41:25 +0000 (20:41 +0100)
Conflicts:
retrace.py

CMakeLists.txt
d3dretrace.hpp [new file with mode: 0644]
d3dretrace.py [new file with mode: 0644]
d3dretrace_main.cpp [new file with mode: 0644]
glretrace.hpp
glretrace_main.cpp
retrace.cpp
retrace.hpp
retrace.py

index ed0905510333f44c722cf535f57b095351500679..03208fbf8ce3b4bea46019019684f71e873424f8 100755 (executable)
@@ -647,6 +647,21 @@ if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE)
     install (TARGETS eglretrace RUNTIME DESTINATION bin) 
 endif ()
 
+if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR)
+    add_custom_command (
+        OUTPUT d3dretrace_d3d9.cpp
+        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp
+        DEPENDS d3dretrace.py retrace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
+    )
+
+    include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
+    add_executable (d3dretrace
+        retrace.cpp
+        d3dretrace_main.cpp
+        d3dretrace_d3d9.cpp
+    )
+endif ()
+
 ##############################################################################
 # CLI
 
diff --git a/d3dretrace.hpp b/d3dretrace.hpp
new file mode 100644 (file)
index 0000000..cac94cc
--- /dev/null
@@ -0,0 +1,41 @@
+/**************************************************************************
+ *
+ * Copyright 2012 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef _D3DRETRACE_HPP_
+#define _D3DRETRACE_HPP_
+
+#include "retrace.hpp"
+
+
+namespace d3dretrace {
+
+
+extern const retrace::Entry d3d9_callbacks[];
+
+
+} /* namespace d3dretrace */
+
+
+#endif /* _D3DRETRACE_HPP_ */
diff --git a/d3dretrace.py b/d3dretrace.py
new file mode 100644 (file)
index 0000000..21c87b9
--- /dev/null
@@ -0,0 +1,52 @@
+##########################################################################
+#
+# Copyright 2011 Jose Fonseca
+# All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+##########################################################################/
+
+
+"""GL retracer generator."""
+
+
+import specs.stdapi as stdapi
+from specs.d3d9 import d3d9
+from retrace import Retracer
+
+
+class D3DRetracer(Retracer):
+
+    table_name = 'd3dretrace::d3d9_callbacks'
+
+
+if __name__ == '__main__':
+    print r'''
+#include <string.h>
+
+#include <iostream>
+
+#include "d3d9imports.hpp"
+#include "d3dretrace.hpp"
+
+
+'''
+    retracer = D3DRetracer()
+    retracer.retraceApi(d3d9)
diff --git a/d3dretrace_main.cpp b/d3dretrace_main.cpp
new file mode 100644 (file)
index 0000000..133f3a7
--- /dev/null
@@ -0,0 +1,103 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <string.h>
+
+#include "os_string.hpp"
+#include "retrace.hpp"
+#include "d3dretrace.hpp"
+
+
+namespace d3dretrace {
+
+static void display(void) {
+    retrace::Retracer retracer;
+
+    retracer.addCallbacks(d3d9_callbacks);
+
+    trace::Call *call;
+
+    while ((call = retrace::parser.parse_call())) {
+        retracer.retrace(*call);
+
+        delete call;
+    }
+
+    exit(0);
+}
+
+
+static void usage(void) {
+    std::cout << 
+        "Usage: d3dretrace [OPTION] TRACE\n"
+        "Replay TRACE.\n"
+        "\n"
+        "  -v           increase output verbosity\n"
+    ;
+}
+
+
+extern "C"
+int main(int argc, char **argv)
+{
+
+    int i;
+    for (i = 1; i < argc; ++i) {
+        const char *arg = argv[i];
+
+        if (arg[0] != '-') {
+            break;
+        }
+
+        if (!strcmp(arg, "--")) {
+            break;
+        } else if (!strcmp(arg, "--help")) {
+            usage();
+            return 0;
+        } else if (!strcmp(arg, "-v")) {
+            ++retrace::verbosity;
+        } else {
+            std::cerr << "error: unknown option " << arg << "\n";
+            usage();
+            return 1;
+        }
+    }
+
+    for ( ; i < argc; ++i) {
+        if (!retrace::parser.open(argv[i])) {
+            std::cerr << "error: failed to open " << argv[i] << "\n";
+            return 1;
+        }
+
+        display();
+
+        retrace::parser.close();
+    }
+
+    return 0;
+}
+
+} /* namespace glretrace */
index 83535223fcf3c7f1009d9731df459ff8a9090203..8ba2a80edd477b8e2b418f0c21bfb76b57aace32 100644 (file)
@@ -26,7 +26,6 @@
 #ifndef _GLRETRACE_HPP_
 #define _GLRETRACE_HPP_
 
-#include "trace_parser.hpp"
 #include "glws.hpp"
 #include "retrace.hpp"
 
@@ -36,7 +35,6 @@ namespace glretrace {
 
 extern bool double_buffer;
 extern bool insideGlBeginEnd;
-extern trace::Parser parser;
 extern glws::Profile defaultProfile;
 extern glws::Visual *visual[glws::PROFILE_MAX];
 extern glws::Drawable *drawable;
index 11f34ce8200ca16215780c0fbfce976f918ca414..16d3ec0de8599fd3ce5cf0379f4439b35578eeb6 100644 (file)
@@ -41,7 +41,6 @@ namespace glretrace {
 
 bool double_buffer = true;
 bool insideGlBeginEnd = false;
-trace::Parser parser;
 glws::Profile defaultProfile = glws::PROFILE_COMPAT;
 glws::Visual *visual[glws::PROFILE_MAX];
 glws::Drawable *drawable = NULL;
index d2e6d379b06d283ca729e1712e80a22044103189..1630995cdb440551232c6bdfcd214ea1f61f2abe 100644 (file)
@@ -35,6 +35,9 @@
 namespace retrace {
 
 
+trace::Parser parser;
+
+
 int verbosity = 0;
 bool profiling = false;
 
index dc11bb382243b13c51afe837c7fec40f6664a7de..1b5fdd23cdff7ba01ee17d3164d8697e332f2229 100644 (file)
 #include <ostream>
 
 #include "trace_model.hpp"
+#include "trace_parser.hpp"
 
 
 namespace retrace {
 
 
+extern trace::Parser parser;
+
+
 /**
  * Handle map.
  *
index 1203a0992e4cebde23706c2fc5a90190d420986d..d6e838755c39a02cd6f517af2866f9d0736c6074 100644 (file)
@@ -207,11 +207,41 @@ class Retracer:
         print '}'
         print
 
+    def retraceInterfaceMethod(self, interface, method):
+        print 'static void retrace_%s__%s(trace::Call &call) {' % (interface.name, method.name)
+        self.retraceInterfaceMethodBody(interface, method)
+        print '}'
+        print
+
     def retraceFunctionBody(self, function):
         if not function.sideeffects:
             print '    (void)call;'
             return
 
+        self.deserializeArgs(function)
+        
+        self.invokeFunction(function)
+
+        self.swizzleValues(function)
+
+    def retraceInterfaceMethodBody(self, interface, method):
+        if not method.sideeffects:
+            print '    (void)call;'
+            return
+
+        self.deserializeThisPointer(interface)
+
+        self.deserializeArgs(method)
+        
+        self.invokeInterfaceMethod(interface, method)
+
+        self.swizzleValues(method)
+
+    def deserializeThisPointer(self, interface):
+        print '    %s *_this;' % (interface.name,)
+        # FIXME
+
+    def deserializeArgs(self, function):
         print '    retrace::ScopedAllocator _allocator;'
         print '    (void)_allocator;'
         success = True
@@ -224,13 +254,17 @@ class Retracer:
             try:
                 self.extractArg(function, arg, arg_type, lvalue, rvalue)
             except NotImplementedError:
-                success = False
+                success =  False
                 print '    %s = 0; // FIXME' % arg.name
+
         if not success:
             print '    if (1) {'
             self.failFunction(function)
+            if function.name[-1].islower():
+                sys.stderr.write('warning: unsupported %s call\n' % function.name)
             print '    }'
-        self.invokeFunction(function)
+
+    def swizzleValues(self, function):
         for arg in function.args:
             if arg.output:
                 arg_type = ConstRemover().visit(arg.type)
@@ -247,9 +281,6 @@ class Retracer:
                 self.regiterSwizzledValue(function.type, lvalue, rvalue)
             except NotImplementedError:
                 print '    // XXX: result'
-        if not success:
-            if function.name[-1].islower():
-                sys.stderr.write('warning: unsupported %s call\n' % function.name)
 
     def failFunction(self, function):
         print '    if (retrace::verbosity >= 0) {'
@@ -276,25 +307,20 @@ class Retracer:
         else:
             print '    %s(%s);' % (function.name, arg_names)
 
+    def invokeInterfaceMethod(self, interface, method):
+        arg_names = ", ".join(method.argNames())
+        if method.type is not stdapi.Void:
+            print '    %s __result;' % (method.type)
+            print '    __result = _this->%s(%s);' % (method.name, arg_names)
+            print '    (void)__result;'
+        else:
+            print '    _this->%s(%s);' % (method.name, arg_names)
+
     def filterFunction(self, function):
         return True
 
     table_name = 'retrace::callbacks'
 
-    def retraceFunctions(self, functions):
-        functions = filter(self.filterFunction, functions)
-
-        for function in functions:
-            self.retraceFunction(function)
-
-        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
-
-
     def retraceApi(self, api):
 
         print '#include "trace_parser.hpp"'
@@ -314,5 +340,21 @@ class Retracer:
                 handle_names.add(handle.name)
         print
 
-        self.retraceFunctions(api.functions)
+        functions = filter(self.filterFunction, api.functions)
+        for function in functions:
+            self.retraceFunction(function)
+        interfaces = api.getAllInterfaces()
+        for interface in interfaces:
+            for method in interface.iterMethods():
+                self.retraceInterfaceMethod(interface, method)
+
+        print 'const retrace::Entry %s[] = {' % self.table_name
+        for function in functions:
+            print '    {"%s", &retrace_%s},' % (function.name, function.name)
+        for interface in interfaces:
+            for method in interface.iterMethods():
+                print '    {"%s::%s", &retrace_%s__%s},' % (interface.name, method.name, interface.name, method.name)
+        print '    {NULL, NULL}'
+        print '};'
+        print