]> git.cworth.org Git - apitrace/commitdiff
Factor out the lock rect size computation.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 29 Apr 2012 22:22:52 +0000 (23:22 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 29 Apr 2012 22:22:52 +0000 (23:22 +0100)
helpers/d3dsize.hpp
retrace/d3dretrace.py
wrappers/d3d9trace.py
wrappers/trace.py

index ef3bdff85e69f6f5b1e9ae6c260aa85652bec186..1697dd6364153b5cfabc16bb70556091502908a9 100644 (file)
@@ -116,7 +116,69 @@ _shaderSize(const DWORD *pFunction)
     }
 }
 
+
+static size_t
+_formatSize(D3DFORMAT Format, UINT Width, UINT Height, INT Pitch) {
+    switch ((DWORD)Format) {
+    case D3DFMT_DXT1:
+    case D3DFMT_DXT2:
+    case D3DFMT_DXT3:
+    case D3DFMT_DXT4:
+    case D3DFMT_DXT5:
+    case D3DFMT_ATI1:
+    case D3DFMT_ATI2:
+        Width /= 4;
+        Height /= 4;
+        break;
+
+    case D3DFMT_UYVY:
+    case D3DFMT_R8G8_B8G8:
+    case D3DFMT_YUY2:
+    case D3DFMT_G8R8_G8B8:
+        Width /= 2;
+        break;
+
+    case D3DFMT_NV12:
+        return (Height + ((Height + 1) / 2)) * Pitch;
+
+    case D3DFMT_NULL:
+        return 0;
+
+    default:
+        break;
+    }
+
+    (void)Width;
+
+    return Height * Pitch;
+}
+
+
 #endif /* DIRECT3D_VERSION >= 0x0800 */
 
 
+#if DIRECT3D_VERSION >= 0x0900
+
+static inline size_t
+_lockSize(IDirect3DSurface9 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect) {
+    D3DSURFACE_DESC Desc;
+    pSurface->GetDesc(&Desc);
+
+    UINT Width;
+    UINT Height;
+    if (pRect) {
+        Width  = pRect->right  - pRect->left;
+        Height = pRect->bottom - pRect->top;
+    } else {
+        Width  = Desc.Width;
+        Height = Desc.Height;
+    }
+
+    return _formatSize(Desc.Format, Width, Height, pLockedRect->Pitch);
+}
+
+
+#endif /* DIRECT3D_VERSION >= 0x0900 */
+
+
 #endif /* _D3D_SIZE_HPP_ */
index c3bec0e7ba2eee31b8bbe07e43b1a873f5ae20ad..f1e8a68781a5d5d708fe143c59bcaae040d37a4d 100644 (file)
@@ -74,20 +74,7 @@ class D3DRetracer(Retracer):
                 print '            SizeToLock = Desc.Size;'
                 print '        }'
             elif interface.name == 'IDirect3DSurface9':
-                print '        UINT Width;'
-                print '        UINT Height;'
-                print '        if (pRect) {'
-                print '            Width  = pRect->right  - pRect->left;'
-                print '            Height = pRect->bottom - pRect->top;'
-                print '        } else {'
-                print '            %s Desc;' % descType
-                print '            _this->GetDesc(&Desc);'
-                print '            Width  = Desc.Width;'
-                print '            Height = Desc.Height;'
-                print '        }'
-                print '        UINT m_SizeToLock = Height * pLockedRect->Pitch;'
-                # TODO: take in consideration the width and pixels and blocks
-                print '        (void)Width;'
+                print '        size_t m_SizeToLock = _lockSize(_this, pLockedRect, pRect);'
 
 
 if __name__ == '__main__':
@@ -97,6 +84,7 @@ if __name__ == '__main__':
 #include <iostream>
 
 #include "d3d9imports.hpp"
+#include "d3dsize.hpp"
 #include "d3dretrace.hpp"
 
 
index 300cfa2005a8795614d02b7ab2d7371fe577adfb..566ac76e0b7015c9e03a08bd65b54ec4e0a0ca2f 100644 (file)
@@ -80,20 +80,7 @@ class D3D9Tracer(DllTracer):
                 print '        }'
                 print '        m_pbData = *ppbData;'
             elif interface.name == 'IDirect3DSurface9':
-                print '        UINT Width;'
-                print '        UINT Height;'
-                print '        if (pRect) {'
-                print '            Width  = pRect->right  - pRect->left;'
-                print '            Height = pRect->bottom - pRect->top;'
-                print '        } else {'
-                print '            %s Desc;' % descType
-                print '            m_pInstance->GetDesc(&Desc);'
-                print '            Width  = Desc.Width;'
-                print '            Height = Desc.Height;'
-                print '        }'
-                print '        m_SizeToLock = Height * pLockedRect->Pitch;'
-                # TODO: take in consideration the width and pixels and blocks
-                print '        (void)Width;'
+                print '        m_SizeToLock = _lockSize(_this, pLockedRect, pRect);'
                 print '        m_pbData = pLockedRect->pBits;'
             else:
                 raise NotImplementedError
index 8bffbfb74409077eb072b07566090eaa6223c10c..eea2fdc22d6f21a57cb928407ead4cebfcf310e6 100644 (file)
@@ -564,6 +564,9 @@ class Tracer:
     def implementWrapperInterfaceMethodBody(self, interface, base, method):
         print '    static const char * _args[%u] = {%s};' % (len(method.args) + 1, ', '.join(['"this"'] + ['"%s"' % arg.name for arg in method.args]))
         print '    static const trace::FunctionSig _sig = {%u, "%s", %u, _args};' % (method.id, interface.name + '::' + method.name, len(method.args) + 1)
+
+        print '    %s *_this = static_cast<%s *>(m_pInstance);' % (base, base)
+
         print '    unsigned _call = trace::localWriter.beginEnter(&_sig);'
         print '    trace::localWriter.beginArg(0);'
         print '    trace::localWriter.writePointer((uintptr_t)m_pInstance);'
@@ -647,7 +650,7 @@ class Tracer:
             result = ''
         else:
             result = '_result = '
-        print '    %sstatic_cast<%s *>(m_pInstance)->%s(%s);' % (result, base, method.name, ', '.join([str(arg.name) for arg in method.args]))
+        print '    %s_this->%s(%s);' % (result, method.name, ', '.join([str(arg.name) for arg in method.args]))
     
     def emit_memcpy(self, dest, src, length):
         print '        unsigned _call = trace::localWriter.beginEnter(&trace::memcpy_sig);'