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:
break;
case D3DFMT_NV12:
- return (Height + ((Height + 1) / 2)) * Pitch;
+ return (Height + ((Height + 1) / 2)) * RowPitch;
case D3DFMT_NULL:
return 0;
(void)Width;
- return Height * Pitch;
+ size_t size = Height * RowPitch;
+
+ if (Depth > 1) {
+ size += (Depth - 1) * SlicePitch;
+ }
+
+ return size;
}
Height = Desc.Height;
}
- return _formatSize(Desc.Format, Width, Height, pLockedRect->Pitch);
+ return _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
}
Height = Desc.Height;
}
- return _formatSize(Desc.Format, Width, Height, pLockedRect->Pitch);
+ return _getLockSize(Desc.Format, Width, Height, pLockedRect->Pitch);
}
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);
}
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':
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 {'