Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- v2: * Remove the trace in memory_2d_buffer_Lock2D() v3: * Redirect all invocations to helper functions. --- dlls/mfplat/buffer.c | 140 ++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 90 deletions(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index a7ba306223d..5a447817145 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -485,11 +485,17 @@ static ULONG WINAPI memory_2d_buffer_Release(IMF2DBuffer2 *iface) return IMFMediaBuffer_Release(&buffer->IMFMediaBuffer_iface); }
-static HRESULT memory_2d_buffer_lock(struct buffer *buffer, BYTE **scanline0, LONG *pitch, - BYTE **buffer_start, DWORD *buffer_length) +static HRESULT memory_2d_buffer_lock2d(IMF2DBuffer2 *iface, MF2DBuffer_LockFlags flags, BYTE **scanline0, + LONG *pitch, BYTE **buffer_start, DWORD *buffer_length) { + struct buffer *buffer = impl_from_IMF2DBuffer2(iface); HRESULT hr = S_OK;
+ if (!scanline0 || !pitch || !buffer_start || !buffer_length) + return E_POINTER; + + EnterCriticalSection(&buffer->cs); + if (buffer->_2d.linear_buffer) hr = MF_E_UNEXPECTED; else @@ -503,26 +509,19 @@ static HRESULT memory_2d_buffer_lock(struct buffer *buffer, BYTE **scanline0, LO *buffer_length = buffer->max_length; }
+ LeaveCriticalSection(&buffer->cs); + return hr; }
static HRESULT WINAPI memory_2d_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **scanline0, LONG *pitch) { - struct buffer *buffer = impl_from_IMF2DBuffer2(iface); - HRESULT hr; + DWORD buffer_length; + BYTE *buffer_start;
TRACE("%p, %p, %p.\n", iface, scanline0, pitch);
- if (!scanline0 || !pitch) - return E_POINTER; - - EnterCriticalSection(&buffer->cs); - - hr = memory_2d_buffer_lock(buffer, scanline0, pitch, NULL, NULL); - - LeaveCriticalSection(&buffer->cs); - - return hr; + return memory_2d_buffer_lock2d(iface, MF2DBuffer_LockFlags_ReadWrite, scanline0, pitch, &buffer_start, &buffer_length); }
static HRESULT WINAPI memory_2d_buffer_Unlock2D(IMF2DBuffer2 *iface) @@ -615,21 +614,9 @@ static HRESULT WINAPI memory_2d_buffer_ContiguousCopyFrom(IMF2DBuffer2 *iface, c static HRESULT WINAPI memory_2d_buffer_Lock2DSize(IMF2DBuffer2 *iface, MF2DBuffer_LockFlags flags, BYTE **scanline0, LONG *pitch, BYTE **buffer_start, DWORD *buffer_length) { - struct buffer *buffer = impl_from_IMF2DBuffer2(iface); - HRESULT hr; - TRACE("%p, %#x, %p, %p, %p, %p.\n", iface, flags, scanline0, pitch, buffer_start, buffer_length);
- if (!scanline0 || !pitch || !buffer_start || !buffer_length) - return E_POINTER; - - EnterCriticalSection(&buffer->cs); - - hr = memory_2d_buffer_lock(buffer, scanline0, pitch, buffer_start, buffer_length); - - LeaveCriticalSection(&buffer->cs); - - return hr; + return memory_2d_buffer_lock2d(iface, flags, scanline0, pitch, buffer_start, buffer_length); }
static HRESULT WINAPI memory_2d_buffer_Copy2DTo(IMF2DBuffer2 *iface, IMF2DBuffer2 *dest_buffer) @@ -655,14 +642,13 @@ static const IMF2DBuffer2Vtbl memory_2d_buffer_vtbl = memory_2d_buffer_Copy2DTo, };
-static HRESULT WINAPI d3d9_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **scanline0, LONG *pitch) +static HRESULT d3d9_surface_buffer_lock2d(IMF2DBuffer2 *iface, MF2DBuffer_LockFlags flags, BYTE **scanline0, + LONG *pitch, BYTE **buffer_start, DWORD *buffer_length) { struct buffer *buffer = impl_from_IMF2DBuffer2(iface); HRESULT hr = S_OK;
- TRACE("%p, %p, %p.\n", iface, scanline0, pitch); - - if (!scanline0 || !pitch) + if (!scanline0 || !pitch || !buffer_start || !buffer_length) return E_POINTER;
EnterCriticalSection(&buffer->cs); @@ -679,6 +665,10 @@ static HRESULT WINAPI d3d9_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **sca buffer->_2d.locks++; *scanline0 = buffer->d3d9_surface.rect.pBits; *pitch = buffer->d3d9_surface.rect.Pitch; + if (buffer_start) + *buffer_start = *scanline0; + if (buffer_length) + *buffer_length = buffer->d3d9_surface.rect.Pitch * buffer->_2d.height; }
LeaveCriticalSection(&buffer->cs); @@ -686,6 +676,16 @@ static HRESULT WINAPI d3d9_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **sca return hr; }
+static HRESULT WINAPI d3d9_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **scanline0, LONG *pitch) +{ + DWORD buffer_length; + BYTE *buffer_start; + + TRACE("%p, %p, %p.\n", iface, scanline0, pitch); + + return d3d9_surface_buffer_lock2d(iface, MF2DBuffer_LockFlags_ReadWrite, scanline0, pitch, &buffer_start, &buffer_length); +} + static HRESULT WINAPI d3d9_surface_buffer_Unlock2D(IMF2DBuffer2 *iface) { struct buffer *buffer = impl_from_IMF2DBuffer2(iface); @@ -743,37 +743,9 @@ static HRESULT WINAPI d3d9_surface_buffer_GetScanline0AndPitch(IMF2DBuffer2 *ifa static HRESULT WINAPI d3d9_surface_buffer_Lock2DSize(IMF2DBuffer2 *iface, MF2DBuffer_LockFlags flags, BYTE **scanline0, LONG *pitch, BYTE **buffer_start, DWORD *buffer_length) { - struct buffer *buffer = impl_from_IMF2DBuffer2(iface); - HRESULT hr = S_OK; - TRACE("%p, %#x, %p, %p, %p, %p.\n", iface, flags, scanline0, pitch, buffer_start, buffer_length);
- if (!scanline0 || !pitch || !buffer_start || !buffer_length) - return E_POINTER; - - EnterCriticalSection(&buffer->cs); - - if (buffer->_2d.linear_buffer) - hr = MF_E_UNEXPECTED; - else if (!buffer->_2d.locks) - { - hr = IDirect3DSurface9_LockRect(buffer->d3d9_surface.surface, &buffer->d3d9_surface.rect, NULL, 0); - } - - if (SUCCEEDED(hr)) - { - buffer->_2d.locks++; - *scanline0 = buffer->d3d9_surface.rect.pBits; - *pitch = buffer->d3d9_surface.rect.Pitch; - if (buffer_start) - *buffer_start = *scanline0; - if (buffer_length) - *buffer_length = buffer->d3d9_surface.rect.Pitch * buffer->_2d.height; - } - - LeaveCriticalSection(&buffer->cs); - - return hr; + return d3d9_surface_buffer_lock2d(iface, flags, scanline0, pitch, buffer_start, buffer_length); }
static const IMF2DBuffer2Vtbl d3d9_surface_buffer_vtbl = @@ -1030,14 +1002,13 @@ static HRESULT WINAPI dxgi_surface_buffer_SetCurrentLength(IMFMediaBuffer *iface return S_OK; }
-static HRESULT WINAPI dxgi_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **scanline0, LONG *pitch) +static HRESULT dxgi_surface_buffer_lock2d(IMF2DBuffer2 *iface, MF2DBuffer_LockFlags flags, + BYTE **scanline0, LONG *pitch, BYTE **buffer_start, DWORD *buffer_length) { struct buffer *buffer = impl_from_IMF2DBuffer2(iface); HRESULT hr = S_OK;
- TRACE("%p, %p, %p.\n", iface, scanline0, pitch); - - if (!scanline0 || !pitch) + if (!scanline0 || !pitch || !buffer_start || !buffer_length) return E_POINTER;
EnterCriticalSection(&buffer->cs); @@ -1051,6 +1022,10 @@ static HRESULT WINAPI dxgi_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **sca { *scanline0 = buffer->dxgi_surface.map_desc.pData; *pitch = buffer->dxgi_surface.map_desc.RowPitch; + if (buffer_start) + *buffer_start = *scanline0; + if (buffer_length) + *buffer_length = buffer->dxgi_surface.map_desc.RowPitch * buffer->_2d.height; }
LeaveCriticalSection(&buffer->cs); @@ -1058,6 +1033,16 @@ static HRESULT WINAPI dxgi_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **sca return hr; }
+static HRESULT WINAPI dxgi_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **scanline0, LONG *pitch) +{ + DWORD buffer_length; + BYTE *buffer_start; + + TRACE("%p, %p, %p.\n", iface, scanline0, pitch); + + return dxgi_surface_buffer_lock2d(iface, MF2DBuffer_LockFlags_ReadWrite, scanline0, pitch, &buffer_start, &buffer_length); +} + static HRESULT WINAPI dxgi_surface_buffer_Unlock2D(IMF2DBuffer2 *iface) { struct buffer *buffer = impl_from_IMF2DBuffer2(iface); @@ -1112,34 +1097,9 @@ static HRESULT WINAPI dxgi_surface_buffer_GetScanline0AndPitch(IMF2DBuffer2 *ifa static HRESULT WINAPI dxgi_surface_buffer_Lock2DSize(IMF2DBuffer2 *iface, MF2DBuffer_LockFlags flags, BYTE **scanline0, LONG *pitch, BYTE **buffer_start, DWORD *buffer_length) { - struct buffer *buffer = impl_from_IMF2DBuffer2(iface); - HRESULT hr = S_OK; - TRACE("%p, %#x, %p, %p, %p, %p.\n", iface, flags, scanline0, pitch, buffer_start, buffer_length);
- if (!scanline0 || !pitch || !buffer_start || !buffer_length) - return E_POINTER; - - EnterCriticalSection(&buffer->cs); - - if (buffer->_2d.linear_buffer) - hr = MF_E_UNEXPECTED; - else if (!buffer->_2d.locks++) - hr = dxgi_surface_buffer_map(buffer); - - if (SUCCEEDED(hr)) - { - *scanline0 = buffer->dxgi_surface.map_desc.pData; - *pitch = buffer->dxgi_surface.map_desc.RowPitch; - if (buffer_start) - *buffer_start = *scanline0; - if (buffer_length) - *buffer_length = buffer->dxgi_surface.map_desc.RowPitch * buffer->_2d.height; - } - - LeaveCriticalSection(&buffer->cs); - - return hr; + return dxgi_surface_buffer_lock2d(iface, flags, scanline0, pitch, buffer_start, buffer_length); }
static HRESULT WINAPI dxgi_buffer_QueryInterface(IMFDXGIBuffer *iface, REFIID riid, void **obj)