From: Giovanni Mascellani gmascellani@codeweavers.com
This is a generic implementation, which is probably fine for buffers backed by system memory. The implementation for buffers backed by GPU memory can probably be optimized. --- dlls/mfplat/buffer.c | 23 +++++++++++++++++++++-- dlls/mfplat/tests/mfplat.c | 10 +++++----- 2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c index f090dd13417..63647c33ece 100644 --- a/dlls/mfplat/buffer.c +++ b/dlls/mfplat/buffer.c @@ -608,9 +608,28 @@ static HRESULT WINAPI memory_2d_buffer_ContiguousCopyTo(IMF2DBuffer2 *iface, BYT
static HRESULT WINAPI memory_2d_buffer_ContiguousCopyFrom(IMF2DBuffer2 *iface, const BYTE *src_buffer, DWORD src_length) { - FIXME("%p, %p, %lu.\n", iface, src_buffer, src_length); + struct buffer *buffer = impl_from_IMF2DBuffer2(iface); + BYTE *dst_scanline0, *dst_buffer_start; + DWORD dst_length; + LONG dst_pitch; + HRESULT hr;
- return E_NOTIMPL; + TRACE("%p, %p, %lu.\n", iface, src_buffer, src_length); + + if (src_length < buffer->_2d.plane_size) + return E_INVALIDARG; + + hr = IMF2DBuffer2_Lock2DSize(iface, MF2DBuffer_LockFlags_Write, &dst_scanline0, &dst_pitch, &dst_buffer_start, &dst_length); + + if (SUCCEEDED(hr)) + { + copy_image(buffer, dst_scanline0, dst_pitch, src_buffer, buffer->_2d.width, buffer->_2d.width, buffer->_2d.height); + + if (FAILED(IMF2DBuffer2_Unlock2D(iface))) + WARN("Couldn't unlock destination buffer %p, hr %#lx.\n", iface, hr); + } + + return hr; }
static HRESULT WINAPI memory_2d_buffer_Lock2DSize(IMF2DBuffer2 *iface, MF2DBuffer_LockFlags flags, BYTE **scanline0, diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 9b4c51ef4b8..56861ce377a 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -6195,7 +6195,7 @@ static void test_MFCreate2DMediaBuffer(void) data2[j] = j & 0x7f;
hr = IMF2DBuffer2_ContiguousCopyFrom(_2dbuffer2, data2, ptr->contiguous_length - 1); - todo_wine ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
hr = IMFMediaBuffer_Lock(buffer, &data, &length2, NULL); ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr); @@ -6207,7 +6207,7 @@ static void test_MFCreate2DMediaBuffer(void) ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
hr = IMF2DBuffer2_ContiguousCopyFrom(_2dbuffer2, data2, ptr->contiguous_length + 16); - todo_wine ok(hr == S_OK, "Failed to copy from contiguous buffer, hr %#lx.\n", hr); + ok(hr == S_OK, "Failed to copy from contiguous buffer, hr %#lx.\n", hr);
hr = IMFMediaBuffer_Lock(buffer, &data, &length2, NULL); ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr); @@ -6226,7 +6226,7 @@ static void test_MFCreate2DMediaBuffer(void) if (data[j] != (j & 0x7f)) break; } - todo_wine ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data[j], j & 0x7f, j); + ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data[j], j & 0x7f, j);
memset(data, 0xff, length2);
@@ -6234,7 +6234,7 @@ static void test_MFCreate2DMediaBuffer(void) ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
hr = IMF2DBuffer2_ContiguousCopyFrom(_2dbuffer2, data2, ptr->contiguous_length); - todo_wine ok(hr == S_OK, "Failed to copy from contiguous buffer, hr %#lx.\n", hr); + ok(hr == S_OK, "Failed to copy from contiguous buffer, hr %#lx.\n", hr);
free(data2);
@@ -6255,7 +6255,7 @@ static void test_MFCreate2DMediaBuffer(void) if (data[j] != (j & 0x7f)) break; } - todo_wine ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data[j], j & 0x7f, j); + ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data[j], j & 0x7f, j);
hr = pMFGetStrideForBitmapInfoHeader(ptr->subtype->Data1, ptr->width, &stride); ok(hr == S_OK, "Failed to get stride, hr %#lx.\n", hr);