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;
}
#if DIRECT3D_VERSION >= 0x0900
+static inline size_t
+_getLockSize(IDirect3DVertexBuffer9 *pBuffer, UINT OffsetToLock, UINT SizeToLock, void ** ppbData) {
+ if (SizeToLock == 0) {
+ D3DVERTEXBUFFER_DESC Desc;
+ HRESULT hr = pBuffer->GetDesc(&Desc);
+ if (FAILED(hr)) {
+ return 0;
+ }
+ SizeToLock = Desc.Size;
+ }
+
+ return SizeToLock;
+}
+
+
+static inline size_t
+_getLockSize(IDirect3DIndexBuffer9 *pBuffer, UINT OffsetToLock, UINT SizeToLock, void ** ppbData) {
+ if (SizeToLock == 0) {
+ D3DINDEXBUFFER_DESC Desc;
+ HRESULT hr = pBuffer->GetDesc(&Desc);
+ if (FAILED(hr)) {
+ return 0;
+ }
+ SizeToLock = Desc.Size;
+ }
+
+ return SizeToLock;
+}
+
+
static inline size_t
_getLockSize(IDirect3DSurface9 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect) {
HRESULT hr;
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);
}