From d275d0ad4ca04f2c88962010d7857f5b6d433646 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 30 Apr 2012 23:18:05 +0100 Subject: [PATCH] Handle variations of LockRect. --- helpers/d3dsize.hpp | 60 +++++++++++++++++++++++++++++++++++++++++-- retrace/d3dretrace.py | 18 +++++++------ specs/d3d9.py | 2 +- specs/d3d9types.py | 7 +---- specs/stdapi.py | 6 ++--- wrappers/d3d9trace.py | 32 +++++++++++------------ 6 files changed, 89 insertions(+), 36 deletions(-) diff --git a/helpers/d3dsize.hpp b/helpers/d3dsize.hpp index 1697dd6..97fccd3 100644 --- a/helpers/d3dsize.hpp +++ b/helpers/d3dsize.hpp @@ -159,10 +159,66 @@ _formatSize(D3DFORMAT Format, UINT Width, UINT Height, INT Pitch) { #if DIRECT3D_VERSION >= 0x0900 + +static inline size_t +_getLockSize(IDirect3DSurface9 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect) { + HRESULT hr; + + D3DSURFACE_DESC Desc; + hr = pSurface->GetDesc(&Desc); + if (FAILED(hr)) { + return 0; + } + + 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); +} + + +static inline size_t +_getLockSize(IDirect3DTexture9 *pTexture, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect) { + HRESULT hr; + + D3DSURFACE_DESC Desc; + hr = pTexture->GetLevelDesc(Level, &Desc); + if (FAILED(hr)) { + return 0; + } + + 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); +} + + static inline size_t -_lockSize(IDirect3DSurface9 *pSurface, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect) { +_getLockSize(IDirect3DCubeTexture9 *pTexture, D3DCUBEMAP_FACES FaceType, UINT Level, const D3DLOCKED_RECT *pLockedRect, const RECT *pRect) { + HRESULT hr; + + (void)FaceType; + D3DSURFACE_DESC Desc; - pSurface->GetDesc(&Desc); + hr = pTexture->GetLevelDesc(Level, &Desc); + if (FAILED(hr)) { + return 0; + } UINT Width; UINT Height; diff --git a/retrace/d3dretrace.py b/retrace/d3dretrace.py index f1e8a68..36b75b1 100644 --- a/retrace/d3dretrace.py +++ b/retrace/d3dretrace.py @@ -61,20 +61,22 @@ class D3DRetracer(Retracer): print r' }' if interface.name in self.bufferInterfaceNames and method.name == 'Lock' or \ - interface.name == 'IDirect3DSurface9' and method.name == 'LockRect': - getDescMethod = interface.getMethodByName('GetDesc') - descArg = getDescMethod.args[0] - assert descArg.output - descType = getDescMethod.args[0].type.type + method.name == 'LockRect': if interface.name in self.bufferInterfaceNames: + getDescMethod = interface.getMethodByName('GetDesc') + descArg = getDescMethod.args[0] + assert descArg.output + descType = getDescMethod.args[0].type.type print ' if (!SizeToLock) {' print ' %s Desc;' % descType print ' _this->GetDesc(&Desc);' print ' SizeToLock = Desc.Size;' print ' }' - elif interface.name == 'IDirect3DSurface9': - print ' size_t m_SizeToLock = _lockSize(_this, pLockedRect, pRect);' + elif method.name == 'LockRect': + print ' size_t _LockedSize = _getLockSize(_this, %s);' % ', '.join(method.argNames()[:-1]) + else: + raise NotImplementedError if __name__ == '__main__': @@ -214,7 +216,7 @@ found: HRESULT hr; hr = pfnD3DXAssembleShader(pSrcData, strlen(pSrcData), NULL, NULL, 0, &pTokens, NULL); - if (hr == D3D_OK) { + if (SUCCEEDED(hr)) { return (DWORD *)pTokens->GetBufferPointer(); } diff --git a/specs/d3d9.py b/specs/d3d9.py index d2b4d63..2fd7755 100644 --- a/specs/d3d9.py +++ b/specs/d3d9.py @@ -361,7 +361,7 @@ IDirect3DIndexBuffer9.methods += [ IDirect3DSurface9.methods += [ Method(HRESULT, "GetContainer", [(REFIID, "riid"), Out(Pointer(ObjPointer(Void)), "ppContainer")], sideeffects=False), Method(HRESULT, "GetDesc", [Out(Pointer(D3DSURFACE_DESC), "pDesc")], sideeffects=False), - Method(HRESULT, "LockRect", [Out(Pointer(D3DLOCKED_RECT_), "pLockedRect"), (ConstPointer(RECT), "pRect"), (D3DLOCK, "Flags")]), + Method(HRESULT, "LockRect", [Out(Pointer(D3DLOCKED_RECT), "pLockedRect"), (ConstPointer(RECT), "pRect"), (D3DLOCK, "Flags")]), Method(HRESULT, "UnlockRect", []), Method(HRESULT, "GetDC", [Out(Pointer(HDC), "phdc")]), Method(HRESULT, "ReleaseDC", [(HDC, "hdc")]), diff --git a/specs/d3d9types.py b/specs/d3d9types.py index b588055..b624263 100644 --- a/specs/d3d9types.py +++ b/specs/d3d9types.py @@ -926,12 +926,7 @@ D3DVOLUME_DESC = Struct("D3DVOLUME_DESC", [ D3DLOCKED_RECT = Struct("D3DLOCKED_RECT", [ (INT, "Pitch"), - (OpaquePointer(Void), "pBits"), -]) - -D3DLOCKED_RECT_ = Struct("D3DLOCKED_RECT", [ - (INT, "Pitch"), - (LinearPointer(Void, "m_SizeToLock"), "pBits"), + (LinearPointer(Void, "_LockedSize"), "pBits"), ]) D3DBOX = Struct("D3DBOX", [ diff --git a/specs/stdapi.py b/specs/stdapi.py index ff7508b..57e9aa6 100644 --- a/specs/stdapi.py +++ b/specs/stdapi.py @@ -402,9 +402,9 @@ class Interface(Type): return visitor.visitInterface(self, *args, **kwargs) def getMethodByName(self, name): - for methods in self.methods: - if methods.name == name: - return methods + for method in self.iterMethods(): + if method.name == name: + return method return None def iterMethods(self): diff --git a/wrappers/d3d9trace.py b/wrappers/d3d9trace.py index 566ac76..b2afdf9 100644 --- a/wrappers/d3d9trace.py +++ b/wrappers/d3d9trace.py @@ -47,40 +47,40 @@ class D3D9Tracer(DllTracer): DllTracer.declareWrapperInterfaceVariables(self, interface) if interface.name in self.bufferInterfaceNames or \ - interface.name == 'IDirect3DSurface9': - print ' UINT m_SizeToLock;' + interface.getMethodByName('LockRect') is not None: + print ' size_t _LockedSize;' print ' VOID *m_pbData;' + def implementWrapperInterfaceMethodBody(self, interface, base, method): if interface.name in self.bufferInterfaceNames and method.name == 'Unlock' or \ - interface.name == 'IDirect3DSurface9' and method.name == 'UnlockRect': + method.name == 'UnlockRect': print ' if (m_pbData) {' - self.emit_memcpy('(LPBYTE)m_pbData', '(LPBYTE)m_pbData', 'm_SizeToLock') + self.emit_memcpy('(LPBYTE)m_pbData', '(LPBYTE)m_pbData', '_LockedSize') print ' }' DllTracer.implementWrapperInterfaceMethodBody(self, interface, base, method) if interface.name in self.bufferInterfaceNames and method.name == 'Lock' or \ - interface.name == 'IDirect3DSurface9' and method.name == 'LockRect': - # FIXME: handle recursive locks - - getDescMethod = interface.getMethodByName('GetDesc') - descArg = getDescMethod.args[0] - assert descArg.output - descType = getDescMethod.args[0].type.type + method.name == 'LockRect': - print ' if (_result == D3D_OK && !(Flags & D3DLOCK_READONLY)) {' + print ' if (SUCCEEDED(_result) && !(Flags & D3DLOCK_READONLY)) {' if interface.name in self.bufferInterfaceNames: + # FIXME: handle recursive locks + getDescMethod = interface.getMethodByName('GetDesc') + descArg = getDescMethod.args[0] + assert descArg.output + descType = getDescMethod.args[0].type.type print ' if (SizeToLock) {' - print ' m_SizeToLock = SizeToLock;' + print ' _LockedSize = SizeToLock;' print ' } else {' print ' %s Desc;' % descType print ' m_pInstance->GetDesc(&Desc);' - print ' m_SizeToLock = Desc.Size;' + print ' _LockedSize = Desc.Size;' print ' }' print ' m_pbData = *ppbData;' - elif interface.name == 'IDirect3DSurface9': - print ' m_SizeToLock = _lockSize(_this, pLockedRect, pRect);' + elif method.name == 'LockRect': + print ' _LockedSize = _getLockSize(_this, %s);' % ', '.join(method.argNames()[:-1]) print ' m_pbData = pLockedRect->pBits;' else: raise NotImplementedError -- 2.43.0