]> git.cworth.org Git - apitrace/commitdiff
retrace: Allow multiple dumpers to co-exist.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 14 Nov 2012 09:17:35 +0000 (09:17 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 14 Nov 2012 09:17:35 +0000 (09:17 +0000)
retrace/d3d9retrace.py
retrace/glretrace_main.cpp
retrace/retrace.hpp
retrace/retrace_main.cpp

index 4b5853bdd3e2be3e0b987cbe2c9a9daf4b429a61..9884d92d4f8fe602f31e662e802a6e8f2fc21da5 100644 (file)
@@ -36,27 +36,47 @@ class D3DRetracer(Retracer):
 
     def retraceApi(self, api):
         print '''
-static IDirect3DDevice9 *
-pLastDirect3DDevice9 = NULL;
 
-image::Image *
-retrace::getSnapshot(void) {
-    if (!pLastDirect3DDevice9) {
-        return NULL;
+class D3D9Dumper : public retrace::Dumper {
+public:
+    IDirect3DDevice9 *pLastDirect3DDevice9;
+
+    D3D9Dumper() :
+        pLastDirect3DDevice9(NULL)
+    {}
+
+    image::Image *
+    getSnapshot(void) {
+        if (!pLastDirect3DDevice9) {
+            return NULL;
+        }
+        return d3dstate::getRenderTargetImage(pLastDirect3DDevice9);
     }
-    return d3dstate::getRenderTargetImage(pLastDirect3DDevice9);
-}
 
+    bool
+    dumpState(std::ostream &os) {
+        if (!pLastDirect3DDevice9) {
+            return false;
+        }
+        d3dstate::dumpDevice(os, pLastDirect3DDevice9);
+        return true;
+    }
 
-bool
-retrace::dumpState(std::ostream &os)
-{
-    if (!pLastDirect3DDevice9) {
-        return false;
+    inline void
+    bindDevice(IDirect3DDevice9 *pDevice) {
+        pLastDirect3DDevice9 = pDevice;
+        retrace::dumper = this;
     }
-    d3dstate::dumpDevice(os, pLastDirect3DDevice9);
-    return true;
-}
+    
+    inline void
+    unbindDevice(IDirect3DDevice9 *pDevice) {
+        if (pLastDirect3DDevice9 == pDevice) {
+            pLastDirect3DDevice9 = NULL;
+        }
+    }
+};
+
+static D3D9Dumper d3d9Dumper;
 '''
 
         print '// Swizzling mapping for lock addresses'
@@ -84,7 +104,10 @@ retrace::dumpState(std::ostream &os)
     def invokeInterfaceMethod(self, interface, method):
         # keep track of the last used device for state dumping
         if interface.name in ('IDirect3DDevice9', 'IDirect3DDevice9Ex'):
-            print r'    pLastDirect3DDevice9 = _this;'
+            if method.name == 'Release':
+                print r'    d3d9Dumper.unbindDevice(_this);'
+            else:
+                print r'    d3d9Dumper.bindDevice(_this);'
 
         # create windows as neccessary
         if method.name in ('CreateDevice', 'CreateDeviceEx', 'CreateAdditionalSwapChain'):
index 5ccb2e2d2a2955f6b83a03da4508cfbd8ad5d57c..1418ca3d0fcc9bd54326263af35763136dd656c8 100755 (executable)
@@ -391,9 +391,35 @@ debugOutputCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsi
 } /* namespace glretrace */
 
 
+class GLDumper : public retrace::Dumper {
+public:
+    image::Image *
+    getSnapshot(void) {
+        if (!glretrace::getCurrentContext()) {
+            return NULL;
+        }
+        return glstate::getDrawBufferImage();
+    }
+
+    bool
+    dumpState(std::ostream &os) {
+        glretrace::Context *currentContext = glretrace::getCurrentContext();
+        if (glretrace::insideGlBeginEnd ||
+            !currentContext) {
+            return false;
+        }
+        glstate::dumpCurrentContext(os);
+        return true;
+    }
+};
+
+static GLDumper glDumper;
+
+
 void
 retrace::setUp(void) {
     glws::init();
+    dumper = &glDumper;
 }
 
 
@@ -408,31 +434,6 @@ retrace::addCallbacks(retrace::Retracer &retracer)
 }
 
 
-image::Image *
-retrace::getSnapshot(void) {
-    if (!glretrace::getCurrentContext()) {
-        return NULL;
-    }
-
-    return glstate::getDrawBufferImage();
-}
-
-
-bool
-retrace::dumpState(std::ostream &os)
-{
-    glretrace::Context *currentContext = glretrace::getCurrentContext();
-
-    if (glretrace::insideGlBeginEnd ||
-        !currentContext) {
-        return false;
-    }
-
-    glstate::dumpCurrentContext(os);
-
-    return true;
-}
-
 void
 retrace::flushRendering(void) {
     glretrace::Context *currentContext = glretrace::getCurrentContext();
index 56cebc6195135dfcd7f7e0bf51158f1bf0ede755..ab1ba5c20dd7af242f226c8386b4201b898518fb 100644 (file)
@@ -211,6 +211,24 @@ public:
 };
 
 
+class Dumper
+{
+public:
+    virtual image::Image *
+    getSnapshot(void) {
+        return NULL;
+    }
+
+    virtual bool
+    dumpState(std::ostream &os) {
+        return false;
+    }
+};
+
+
+extern Dumper *dumper;
+
+
 void
 setUp(void);
 
@@ -220,11 +238,7 @@ addCallbacks(retrace::Retracer &retracer);
 void
 frameComplete(trace::Call &call);
 
-image::Image *
-getSnapshot(void);
 
-bool
-dumpState(std::ostream &os);
 
 void
 flushRendering(void);
index e3e74f84cf20d979928b6fd704593939f22305ba..bc23bc4a4bea7b02a576943eaca9dabf6b910511 100644 (file)
@@ -79,6 +79,11 @@ frameComplete(trace::Call &call) {
 }
 
 
+static Dumper defaultDumper;
+
+Dumper *dumper = &defaultDumper;
+
+
 /**
  * Take/compare snapshots.
  */
@@ -99,7 +104,7 @@ takeSnapshot(unsigned call_no) {
         }
     }
 
-    image::Image *src = getSnapshot();
+    image::Image *src = dumper->getSnapshot();
     if (!src) {
         return;
     }
@@ -162,7 +167,7 @@ retraceCall(trace::Call *call) {
         takeSnapshot(call->no);
 
     if (call->no >= dumpStateCallNo &&
-        dumpState(std::cout)) {
+        dumper->dumpState(std::cout)) {
         exit(0);
     }
 }