#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;
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__':
HRESULT hr;
hr = pfnD3DXAssembleShader(pSrcData, strlen(pSrcData), NULL, NULL, 0, &pTokens, NULL);
- if (hr == D3D_OK) {
+ if (SUCCEEDED(hr)) {
return (DWORD *)pTokens->GetBufferPointer();
}
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")]),
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", [
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):
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