]> git.cworth.org Git - apitrace/commitdiff
Handle variations of LockRect.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 30 Apr 2012 22:18:05 +0000 (23:18 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 30 Apr 2012 22:18:05 +0000 (23:18 +0100)
helpers/d3dsize.hpp
retrace/d3dretrace.py
specs/d3d9.py
specs/d3d9types.py
specs/stdapi.py
wrappers/d3d9trace.py

index 1697dd6364153b5cfabc16bb70556091502908a9..97fccd3e5d99f5a176042354431d46f775df562a 100644 (file)
@@ -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;
index f1e8a68781a5d5d708fe143c59bcaae040d37a4d..36b75b185d4500630e60ddd17eaf4605dbf0ef28 100644 (file)
@@ -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();
         }
 
index d2b4d63edcc115b75832296e7bb82165552ec832..2fd7755d8a972209454c4637115b22b68f0f15d1 100644 (file)
@@ -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")]),
index b588055ea0985f92e8c6b627704366f3e2358b03..b624263e5e850a41dd44bf49d5216591a0441ba3 100644 (file)
@@ -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", [
index ff7508b7021257e4c57f6edd6660bd33e35ec6fc..57e9aa6eb1fcacda7aa77e976b6f1c06dbb9334c 100644 (file)
@@ -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):
index 566ac76e0b7015c9e03a08bd65b54ec4e0a0ca2f..b2afdf9b9dce4e2de92c6ea58aaaa1edf903e694 100644 (file)
@@ -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