Skip to content

Commit

Permalink
mfplat: Fix returned buffer length in dxgi_surface_buffer_lock().
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Gofman authored and julliard committed Apr 27, 2023
1 parent 0c4e69e commit 5a162f2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dlls/mfplat/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ static HRESULT dxgi_surface_buffer_lock(struct buffer *buffer, MF2DBuffer_LockFl
if (buffer_start)
*buffer_start = *scanline0;
if (buffer_length)
*buffer_length = buffer->dxgi_surface.map_desc.RowPitch * buffer->_2d.height;
*buffer_length = buffer->dxgi_surface.map_desc.DepthPitch;
}

return hr;
Expand Down
52 changes: 49 additions & 3 deletions dlls/mfplat/tests/mfplat.c
Original file line number Diff line number Diff line change
Expand Up @@ -7255,6 +7255,7 @@ static ID3D12Device *create_d3d12_device(void)
static void test_d3d11_surface_buffer(void)
{
DWORD max_length, cur_length, length, color;
BYTE *data, *data2, *buffer_start;
IMFDXGIBuffer *dxgi_buffer;
D3D11_TEXTURE2D_DESC desc;
IMF2DBuffer2 *_2dbuffer2;
Expand All @@ -7263,7 +7264,6 @@ static void test_d3d11_surface_buffer(void)
IMFMediaBuffer *buffer;
ID3D11Device *device;
BYTE buff[64 * 64 * 4];
BYTE *data, *data2;
LONG pitch, pitch2;
UINT index, size;
IUnknown *obj;
Expand Down Expand Up @@ -7575,7 +7575,54 @@ static void test_d3d11_surface_buffer(void)

ID3D11Texture2D_Release(texture);

/* Subresource index 1. */
memset(&desc, 0, sizeof(desc));
desc.Width = 64;
desc.Height = 64;
desc.ArraySize = 1;
desc.MipLevels = 1;
desc.Format = DXGI_FORMAT_NV12;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;

hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
if (SUCCEEDED(hr))
{
hr = pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D, (IUnknown *)texture, 0, FALSE, &buffer);
ok(hr == S_OK, "got %#lx.\n", hr);
hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&_2dbuffer2);
ok(hr == S_OK, "got %#lx.\n", hr);

hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &buffer_start, &length);
ok(hr == S_OK, "got %#lx.\n", hr);

ok(pitch >= desc.Width, "got %ld.\n", pitch);
ok(length == pitch * desc.Height * 3 / 2, "got %lu.\n", length);

hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
ok(hr == S_OK, "got %#lx.\n", hr);

IMF2DBuffer2_Release(_2dbuffer2);
IMFMediaBuffer_Release(buffer);
ID3D11Texture2D_Release(texture);
}
else
{
win_skip("Failed to create NV12 texture, hr %#lx, skipping test.\n", hr);
ID3D11Device_Release(device);
return;
}

/* Subresource index 1.
* When WARP d3d11 device is used, this test leaves the device in a broken state, so it should
* be kept last. */
memset(&desc, 0, sizeof(desc));
desc.Width = 64;
desc.Height = 64;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;

hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
ok(hr == S_OK, "Failed to create a texture, hr %#lx.\n", hr);

Expand All @@ -7600,7 +7647,6 @@ static void test_d3d11_surface_buffer(void)

IMF2DBuffer_Release(_2d_buffer);
IMFMediaBuffer_Release(buffer);

ID3D11Texture2D_Release(texture);

ID3D11Device_Release(device);
Expand Down

0 comments on commit 5a162f2

Please sign in to comment.