Skip to content

Commit

Permalink
mfplat/buffer: Implement IMF2DBuffer::ContiguousCopyFrom().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
giomasce authored and julliard committed May 8, 2023
1 parent cd719c7 commit da1885c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
23 changes: 21 additions & 2 deletions dlls/mfplat/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions dlls/mfplat/tests/mfplat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -6226,15 +6226,15 @@ 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);

hr = IMFMediaBuffer_Unlock(buffer);
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);

Expand All @@ -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);
Expand Down

0 comments on commit da1885c

Please sign in to comment.