Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/mfplat/tests/mfplat.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 83877041694..7e72abbde22 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -5725,6 +5725,8 @@ static void test_MFCreate2DMediaBuffer(void) { 1, 4, D3DFMT_A8R8G8B8, 16, 64 }, { 4, 1, D3DFMT_A8R8G8B8, 16, 64 }, }; + static const char two_aas[] = { 0xaa, 0xaa }; + static const char eight_bbs[] = { 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb }; DWORD max_length, length, length2; BYTE *buffer_start, *data, *data2; LONG pitch, pitch2, stride; @@ -5783,6 +5785,8 @@ static void test_MFCreate2DMediaBuffer(void) ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr); ok(max_length == length, "Unexpected length.\n");
+ memset(data, 0xaa, length); + length = 0; pMFGetPlaneSize(MAKEFOURCC('N','V','1','2'), 2, 3, &length); ok(max_length == length && length == 9, "Unexpected length %lu.\n", length); @@ -5835,6 +5839,10 @@ static void test_MFCreate2DMediaBuffer(void) ok(!!data, "Expected data pointer.\n"); ok(pitch == 64, "Unexpected pitch %ld.\n", pitch);
+ for (i = 0; i < 4; i++) + ok(memcmp(&data[64 * i], two_aas, sizeof(two_aas)) == 0, "Invalid data instead of 0xaa.\n"); + memset(data, 0xbb, 194); + hr = IMF2DBuffer_Lock2D(_2dbuffer, &data2, &pitch); ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr); ok(data == data2, "Expected data pointer.\n"); @@ -5861,6 +5869,15 @@ static void test_MFCreate2DMediaBuffer(void) hr = IMF2DBuffer_Unlock2D(_2dbuffer); ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
+ hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL); + ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr); + + todo_wine + ok(memcmp(data, eight_bbs, sizeof(eight_bbs)) == 0, "Invalid data instead of 0xbb.\n"); + + hr = IMFMediaBuffer_Unlock(buffer); + ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr); + hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&_2dbuffer2); ok(hr == S_OK || broken(hr == E_NOINTERFACE), "Failed to get interface, hr %#lx.\n", hr);
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/mfplat/buffer.c | 4 ++++ dlls/mfplat/tests/mfplat.c | 1 - 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index 2ec714c1419..133af2af470 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -311,6 +311,10 @@ static HRESULT WINAPI memory_1d_2d_buffer_Lock(IMFMediaBuffer *iface, BYTE **dat { if (!(buffer->_2d.linear_buffer = malloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT)))) hr = E_OUTOFMEMORY; + + if (SUCCEEDED(hr)) + copy_image(buffer, buffer->_2d.linear_buffer, buffer->_2d.width, buffer->data, buffer->_2d.pitch, + buffer->_2d.width, buffer->_2d.height); }
if (SUCCEEDED(hr)) diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 7e72abbde22..16d24bbff51 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -5872,7 +5872,6 @@ static void test_MFCreate2DMediaBuffer(void) hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL); ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
- todo_wine ok(memcmp(data, eight_bbs, sizeof(eight_bbs)) == 0, "Invalid data instead of 0xbb.\n");
hr = IMFMediaBuffer_Unlock(buffer);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- I can't see any reference to why buffer sizes should be extended to 64 bytes and not test seems to be upset about this change. --- dlls/mfplat/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index 133af2af470..19a7ad33bba 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -309,7 +309,7 @@ static HRESULT WINAPI memory_1d_2d_buffer_Lock(IMFMediaBuffer *iface, BYTE **dat hr = MF_E_INVALIDREQUEST; else if (!buffer->_2d.linear_buffer) { - if (!(buffer->_2d.linear_buffer = malloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT)))) + if (!(buffer->_2d.linear_buffer = malloc(buffer->_2d.plane_size))) hr = E_OUTOFMEMORY;
if (SUCCEEDED(hr)) @@ -384,7 +384,7 @@ static HRESULT WINAPI d3d9_surface_buffer_Lock(IMFMediaBuffer *iface, BYTE **dat { D3DLOCKED_RECT rect;
- if (!(buffer->_2d.linear_buffer = malloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT)))) + if (!(buffer->_2d.linear_buffer = malloc(buffer->_2d.plane_size))) hr = E_OUTOFMEMORY;
if (SUCCEEDED(hr)) @@ -963,7 +963,7 @@ static HRESULT WINAPI dxgi_surface_buffer_Lock(IMFMediaBuffer *iface, BYTE **dat hr = MF_E_INVALIDREQUEST; else if (!buffer->_2d.linear_buffer) { - if (!(buffer->_2d.linear_buffer = malloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT)))) + if (!(buffer->_2d.linear_buffer = malloc(buffer->_2d.plane_size))) hr = E_OUTOFMEMORY;
if (SUCCEEDED(hr))
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/mfplat/buffer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index 19a7ad33bba..e3f863c6345 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -670,13 +670,14 @@ static HRESULT WINAPI d3d9_surface_buffer_Lock2D(IMF2DBuffer2 *iface, BYTE **sca
if (buffer->_2d.linear_buffer) hr = MF_E_UNEXPECTED; - else if (!buffer->_2d.locks++) + 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; } @@ -755,13 +756,14 @@ static HRESULT WINAPI d3d9_surface_buffer_Lock2DSize(IMF2DBuffer2 *iface, MF2DBu
if (buffer->_2d.linear_buffer) hr = MF_E_UNEXPECTED; - else if (!buffer->_2d.locks++) + 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)
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
This is what seems to be happening on Windows 10. On the other hand, I am not seeing on native the current behavior of interpreting a zero alignment parameter as a request to align to 64 bytes boundaries.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/mfplat/buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index e3f863c6345..18c77c87ec2 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -1264,7 +1264,8 @@ static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD { size_t size;
- if (!alignment) alignment = MF_64_BYTE_ALIGNMENT; + if (alignment < MF_16_BYTE_ALIGNMENT) + alignment = MF_16_BYTE_ALIGNMENT; alignment++;
if (alignment & (alignment - 1))
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
It is totally fine (though maybe a little strange) to allocate 10 bytes requesting an alignment to a megabyte boundary or more, and this shouldn't result in wasting an (nearly) entire megabyte of memory.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/mfplat/buffer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index 18c77c87ec2..8ea2283e24b 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -1262,8 +1262,6 @@ static const IMFDXGIBufferVtbl dxgi_buffer_vtbl = static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD alignment, const IMFMediaBufferVtbl *vtbl) { - size_t size; - if (alignment < MF_16_BYTE_ALIGNMENT) alignment = MF_16_BYTE_ALIGNMENT; alignment++; @@ -1279,10 +1277,9 @@ static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD alignment++; }
- size = ALIGN_SIZE(max_length, alignment - 1); - if (!(buffer->data = _aligned_malloc(size, alignment))) + if (!(buffer->data = _aligned_malloc(max_length, alignment))) return E_OUTOFMEMORY; - memset(buffer->data, 0, size); + memset(buffer->data, 0, max_length);
buffer->IMFMediaBuffer_iface.lpVtbl = vtbl; buffer->refcount = 1;
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com