]> git.cworth.org Git - apitrace/commitdiff
Trace LockBox blobs.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 1 May 2012 21:28:28 +0000 (22:28 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 1 May 2012 21:28:28 +0000 (22:28 +0100)
helpers/d3dsize.hpp
retrace/d3dretrace.py
specs/d3d9types.py
wrappers/d3d9trace.py

index 92503fe8b8daca95164418d9aa7045a0a9156889..31fcd740a95c55d2bc645e6d58191f984821c891 100644 (file)
@@ -118,7 +118,21 @@ _shaderSize(const DWORD *pFunction)
 
 
 static size_t
-_formatSize(D3DFORMAT Format, UINT Width, UINT Height, INT Pitch) {
+_getLockSize(D3DFORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth = 1, INT SlicePitch = 0) {
+    if (Width == 0 || Height == 0 || Depth == 0) {
+        return 0;
+    }
+
+    if (RowPitch < 0) {
+        os::log("apitrace: warning: %s: negative row pitch %i\n", __FUNCTION__, RowPitch);
+        return 0;
+    }
+
+    if (SlicePitch < 0) {
+        os::log("apitrace: warning: %s: negative slice pitch %i\n", __FUNCTION__, SlicePitch);
+        return 0;
+    }
+
     switch ((DWORD)Format) {
     case D3DFMT_DXT1:
     case D3DFMT_DXT2:
@@ -139,7 +153,7 @@ _formatSize(D3DFORMAT Format, UINT Width, UINT Height, INT Pitch) {
         break;
 
     case D3DFMT_NV12:
-        return (Height + ((Height + 1) / 2)) * Pitch;
+        return (Height + ((Height + 1) / 2)) * RowPitch;
 
     case D3DFMT_NULL:
         return 0;
@@ -150,7 +164,13 @@ _formatSize(D3DFORMAT Format, UINT Width, UINT Height, INT Pitch) {
 
     (void)Width;
 
-    return Height * Pitch;
+    size_t size = Height * RowPitch;
+
+    if (Depth > 1) {
+        size += (Depth - 1) * SlicePitch;
+    }
+
+    return size;
 }
 
 
@@ -210,7 +230,7 @@ _getLockSize(IDirect3DSurface9 *pSurface, const D3DLOCKED_RECT *pLockedRect, con
         Height = Desc.Height;
     }
 
-    return _formatSize(Desc.Format, Width, Height, pLockedRect->Pitch);
+    return _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
 }
 
 
@@ -234,7 +254,7 @@ _getLockSize(IDirect3DTexture9 *pTexture, UINT Level, const D3DLOCKED_RECT *pLoc
         Height = Desc.Height;
     }
 
-    return _formatSize(Desc.Format, Width, Height, pLockedRect->Pitch);
+    return _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
 }
 
 
@@ -260,7 +280,61 @@ _getLockSize(IDirect3DCubeTexture9 *pTexture, D3DCUBEMAP_FACES FaceType, UINT Le
         Height = Desc.Height;
     }
 
-    return _formatSize(Desc.Format, Width, Height, pLockedRect->Pitch);
+    return _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
+}
+
+
+static inline size_t
+_getLockSize(IDirect3DVolume9 *pVolume, const D3DLOCKED_BOX *pLockedBox, const D3DBOX *pBox) {
+    HRESULT hr;
+
+    D3DVOLUME_DESC Desc;
+    hr = pVolume->GetDesc(&Desc);
+    if (FAILED(hr)) {
+        return 0;
+    }
+
+    UINT Width;
+    UINT Height;
+    UINT Depth;
+    if (pBox) {
+        Width  = pBox->Right  - pBox->Left;
+        Height = pBox->Bottom - pBox->Top;
+        Depth  = pBox->Back   - pBox->Front;
+    } else {
+        Width  = Desc.Width;
+        Height = Desc.Height;
+        Depth  = Desc.Depth;
+    }
+
+    return _getLockSize(Desc.Format, Width, Height, pLockedBox->RowPitch, Depth, pLockedBox->SlicePitch);
+}
+
+
+static inline size_t
+_getLockSize(IDirect3DVolumeTexture9 *pTexture, UINT Level, const D3DLOCKED_BOX *pLockedBox, const D3DBOX *pBox) {
+    HRESULT hr;
+
+    D3DVOLUME_DESC Desc;
+    hr = pTexture->GetLevelDesc(Level, &Desc);
+    if (FAILED(hr)) {
+        return 0;
+    }
+
+    UINT Width;
+    UINT Height;
+    UINT Depth;
+    if (pBox) {
+        Width  = pBox->Right  - pBox->Left;
+        Height = pBox->Bottom - pBox->Top;
+        Depth  = pBox->Back   - pBox->Front;
+    } else {
+        Width  = Desc.Width;
+        Height = Desc.Height;
+        Depth  = Desc.Depth;
+    }
+
+    return _getLockSize(Desc.Format, Width, Height, pLockedBox->RowPitch, Depth, pLockedBox->SlicePitch);
 }
 
 
index 8af52654cd8da33300995d6c4a9de2001082b4a3..14ce35934366dbde3147a274b1224cd4fdf14af4 100644 (file)
@@ -60,7 +60,7 @@ class D3DRetracer(Retracer):
             print r'        retrace::warning(call) << "failed\n";'
             print r'    }'
 
-        if method.name in ('Lock', 'LockRect'):
+        if method.name in ('Lock', 'LockRect', 'LockBox'):
             print '        size_t _LockedSize = _getLockSize(_this, %s);' % ', '.join(method.argNames()[:-1])
 
 
index b624263e5e850a41dd44bf49d5216591a0441ba3..6622e73df9397fd09ff2b81d076e85c88d34bd1e 100644 (file)
@@ -941,7 +941,7 @@ D3DBOX = Struct("D3DBOX", [
 D3DLOCKED_BOX = Struct("D3DLOCKED_BOX", [
     (INT, "RowPitch"),
     (INT, "SlicePitch"),
-    (OpaquePointer(Void), "pBits"),
+    (LinearPointer(Void, "_LockedSize"), "pBits"),
 ])
 
 D3DRANGE = Struct("D3DRANGE", [
index dbace8fe54ffc07ebaeca84f70f69a46803becf4..ef5a14c6f436aacdab461f6622af0bbfc85eacbd 100644 (file)
@@ -42,20 +42,21 @@ class D3D9Tracer(DllTracer):
         DllTracer.declareWrapperInterfaceVariables(self, interface)
         
         if interface.getMethodByName('Lock') is not None or \
-           interface.getMethodByName('LockRect') is not None:
+           interface.getMethodByName('LockRect') is not None or \
+           interface.getMethodByName('LockBox') is not None:
             print '    size_t _LockedSize;'
             print '    VOID *m_pbData;'
 
 
     def implementWrapperInterfaceMethodBody(self, interface, base, method):
-        if method.name in ('Unlock', 'UnlockRect'):
+        if method.name in ('Unlock', 'UnlockRect', 'UnlockBox'):
             print '    if (m_pbData) {'
             self.emit_memcpy('(LPBYTE)m_pbData', '(LPBYTE)m_pbData', '_LockedSize')
             print '    }'
 
         DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method)
 
-        if method.name in ('Lock', 'LockRect'):
+        if method.name in ('Lock', 'LockRect', 'LockedBox'):
             print '    if (SUCCEEDED(_result) && !(Flags & D3DLOCK_READONLY)) {'
             print '        _LockedSize = _getLockSize(_this, %s);' % ', '.join(method.argNames()[:-1])
             if method.name == 'Lock':
@@ -63,6 +64,8 @@ class D3D9Tracer(DllTracer):
                 print '        m_pbData = *ppbData;'
             elif method.name == 'LockRect':
                 print '        m_pbData = pLockedRect->pBits;'
+            elif method.name == 'LockBox':
+                print '        m_pbData = pLockedBox->pBits;'
             else:
                 raise NotImplementedError
             print '    } else {'