From: José Fonseca Date: Tue, 1 May 2012 21:28:28 +0000 (+0100) Subject: Trace LockBox blobs. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=93fa73af855d48fbd95ed50930bdb8ec50602ed6 Trace LockBox blobs. --- diff --git a/helpers/d3dsize.hpp b/helpers/d3dsize.hpp index 92503fe..31fcd74 100644 --- a/helpers/d3dsize.hpp +++ b/helpers/d3dsize.hpp @@ -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); } diff --git a/retrace/d3dretrace.py b/retrace/d3dretrace.py index 8af5265..14ce359 100644 --- a/retrace/d3dretrace.py +++ b/retrace/d3dretrace.py @@ -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]) diff --git a/specs/d3d9types.py b/specs/d3d9types.py index b624263..6622e73 100644 --- a/specs/d3d9types.py +++ b/specs/d3d9types.py @@ -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", [ diff --git a/wrappers/d3d9trace.py b/wrappers/d3d9trace.py index dbace8f..ef5a14c 100644 --- a/wrappers/d3d9trace.py +++ b/wrappers/d3d9trace.py @@ -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 {'