Nikolay Sivov : dxva2: Check content formats for software device in GetVideoProcessorRenderTargets().

Alexandre Julliard julliard at winehq.org
Thu Apr 8 16:14:03 CDT 2021


Module: wine
Branch: master
Commit: 0cd91a522ee39a92b6250e8342f02d9d1e7af0fb
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0cd91a522ee39a92b6250e8342f02d9d1e7af0fb

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Thu Apr  8 12:19:38 2021 +0300

dxva2: Check content formats for software device in GetVideoProcessorRenderTargets().

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dxva2/main.c        |  8 ++++++-
 dlls/dxva2/tests/dxva2.c | 60 ++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/dlls/dxva2/main.c b/dlls/dxva2/main.c
index 069f03d8077..8952de17b1e 100644
--- a/dlls/dxva2/main.c
+++ b/dlls/dxva2/main.c
@@ -399,7 +399,13 @@ static HRESULT WINAPI device_manager_processor_service_GetVideoProcessorRenderTa
 
     if (IsEqualGUID(deviceguid, &DXVA2_VideoProcSoftwareDevice))
     {
-        /* FIXME: filter some input formats */
+        if (!(video_desc->Format == D3DFMT_A8R8G8B8 ||
+                video_desc->Format == D3DFMT_X8R8G8B8 ||
+                video_desc->Format == D3DFMT_YUY2))
+        {
+            WARN("Unsupported content format %#x.\n", video_desc->Format);
+            return E_FAIL;
+        }
 
         if (!(*formats = CoTaskMemAlloc(2 * sizeof(**formats))))
             return E_OUTOFMEMORY;
diff --git a/dlls/dxva2/tests/dxva2.c b/dlls/dxva2/tests/dxva2.c
index a49635e7596..1de1712d163 100644
--- a/dlls/dxva2/tests/dxva2.c
+++ b/dlls/dxva2/tests/dxva2.c
@@ -78,6 +78,14 @@ static void test_surface_desc(IDirect3DSurface9 *surface)
     ok(desc.Height == 64, "Unexpected height %u.\n", desc.Height);
 }
 
+static void init_video_desc(DXVA2_VideoDesc *video_desc, D3DFORMAT format)
+{
+    memset(video_desc, 0, sizeof(*video_desc));
+    video_desc->SampleWidth = 64;
+    video_desc->SampleHeight = 64;
+    video_desc->Format = format;
+}
+
 static void test_device_manager(void)
 {
     IDirectXVideoProcessorService *processor_service;
@@ -92,11 +100,29 @@ static void test_device_manager(void)
     D3DFORMAT *formats;
     UINT token, count;
     IDirect3D9 *d3d;
+    unsigned int i;
     HWND window;
     GUID *guids;
     HRESULT hr;
     RECT rect;
 
+    static const D3DFORMAT rt_formats[] =
+    {
+        D3DFMT_A8R8G8B8,
+        D3DFMT_X8R8G8B8,
+        D3DFMT_YUY2,
+    };
+    static const D3DFORMAT rt_unsupported_formats[] =
+    {
+        D3DFMT_A1R5G5B5,
+        D3DFMT_X1R5G5B5,
+        D3DFMT_A2R10G10B10,
+        D3DFMT_A8B8G8R8,
+        D3DFMT_X8B8G8R8,
+        D3DFMT_R5G6B5,
+        D3DFMT_UYVY,
+    };
+
     window = create_window();
     d3d = Direct3DCreate9(D3D_SDK_VERSION);
     ok(!!d3d, "Failed to create a D3D object.\n");
@@ -316,22 +342,36 @@ static void test_device_manager(void)
     hr = DXVA2CreateVideoService(device, &IID_IDirectXVideoProcessorService, (void **)&proc_service);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
 
-    memset(&video_desc, 0, sizeof(video_desc));
-    video_desc.SampleWidth = 64;
-    video_desc.SampleHeight = 64;
-    video_desc.Format = D3DFMT_A8R8G8B8;
+    init_video_desc(&video_desc, D3DFMT_A8R8G8B8);
 
     hr = IDirectXVideoProcessorService_GetVideoProcessorDeviceGuids(proc_service, &video_desc, &count, &guids);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
     ok(count, "Unexpected format count %u.\n", count);
     CoTaskMemFree(guids);
 
-    count = 0;
-    hr = IDirectXVideoProcessorService_GetVideoProcessorRenderTargets(proc_service, &DXVA2_VideoProcSoftwareDevice,
-            &video_desc, &count, &formats);
-    ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
-    ok(count, "Unexpected format count %u.\n", count);
-    CoTaskMemFree(formats);
+    for (i = 0; i < ARRAY_SIZE(rt_formats); ++i)
+    {
+        init_video_desc(&video_desc, rt_formats[i]);
+
+        count = 0;
+        hr = IDirectXVideoProcessorService_GetVideoProcessorRenderTargets(proc_service, &DXVA2_VideoProcSoftwareDevice,
+                &video_desc, &count, &formats);
+        ok(hr == S_OK, "Unexpected hr %#x, format %d.\n", hr, rt_formats[i]);
+        ok(count == 2, "Unexpected format count %u.\n", count);
+        if (count == 2)
+            ok(formats[0] == D3DFMT_X8R8G8B8 && formats[1] == D3DFMT_A8R8G8B8, "Unexpected formats %d,%d.\n",
+                    formats[0], formats[1]);
+        CoTaskMemFree(formats);
+    }
+
+    for (i = 0; i < ARRAY_SIZE(rt_unsupported_formats); ++i)
+    {
+        init_video_desc(&video_desc, rt_unsupported_formats[i]);
+
+        hr = IDirectXVideoProcessorService_GetVideoProcessorRenderTargets(proc_service, &DXVA2_VideoProcSoftwareDevice,
+                &video_desc, &count, &formats);
+        ok(hr == E_FAIL, "Unexpected hr %#x, format %d.\n", hr, rt_unsupported_formats[i]);
+    }
 
     IDirectXVideoProcessorService_Release(proc_service);
 




More information about the wine-cvs mailing list