Zhiyi Zhang : wined3d: Move cursor size check against display mode out of wined3d_device_set_cursor_properties().

Alexandre Julliard julliard at winehq.org
Tue Mar 31 16:44:23 CDT 2020


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

Author: Zhiyi Zhang <zzhang at codeweavers.com>
Date:   Tue Mar 31 21:40:18 2020 +0800

wined3d: Move cursor size check against display mode out of wined3d_device_set_cursor_properties().

Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d3d8/device.c    | 22 ++++++++++++++++++++++
 dlls/d3d9/device.c    | 22 ++++++++++++++++++++++
 dlls/wined3d/device.c | 15 ---------------
 3 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 23e93df061..3b3153c6d4 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -739,6 +739,8 @@ static HRESULT WINAPI d3d8_device_SetCursorProperties(IDirect3DDevice8 *iface,
 {
     struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
     struct d3d8_surface *bitmap_impl = unsafe_impl_from_IDirect3DSurface8(bitmap);
+    D3DSURFACE_DESC surface_desc;
+    D3DDISPLAYMODE mode;
     HRESULT hr;
 
     TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
@@ -750,6 +752,26 @@ static HRESULT WINAPI d3d8_device_SetCursorProperties(IDirect3DDevice8 *iface,
         return D3DERR_INVALIDCALL;
     }
 
+    if (FAILED(hr = IDirect3DSurface8_GetDesc(bitmap, &surface_desc)))
+    {
+        WARN("Failed to get surface description, hr %#x.\n", hr);
+        return hr;
+    }
+
+    if (FAILED(hr = IDirect3D8_GetAdapterDisplayMode(device->d3d_parent, device->adapter_ordinal,
+            &mode)))
+    {
+        WARN("Failed to get device display mode, hr %#x.\n", hr);
+        return hr;
+    }
+
+    if (surface_desc.Width > mode.Width || surface_desc.Height > mode.Height)
+    {
+        WARN("Surface dimension %ux%u exceeds display mode %ux%u.\n", surface_desc.Width,
+                surface_desc.Height, mode.Width, mode.Height);
+        return D3DERR_INVALIDCALL;
+    }
+
     wined3d_mutex_lock();
     hr = wined3d_device_set_cursor_properties(device->wined3d_device,
             hotspot_x, hotspot_y, bitmap_impl->wined3d_texture, bitmap_impl->sub_resource_idx);
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 61cb505d77..53137da28f 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -787,6 +787,8 @@ static HRESULT WINAPI d3d9_device_SetCursorProperties(IDirect3DDevice9Ex *iface,
 {
     struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
     struct d3d9_surface *bitmap_impl = unsafe_impl_from_IDirect3DSurface9(bitmap);
+    D3DSURFACE_DESC surface_desc;
+    D3DDISPLAYMODE mode;
     HRESULT hr;
 
     TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
@@ -798,6 +800,26 @@ static HRESULT WINAPI d3d9_device_SetCursorProperties(IDirect3DDevice9Ex *iface,
         return D3DERR_INVALIDCALL;
     }
 
+    if (FAILED(hr = IDirect3DSurface9_GetDesc(bitmap, &surface_desc)))
+    {
+        WARN("Failed to get surface description, hr %#x.\n", hr);
+        return hr;
+    }
+
+    if (FAILED(hr = IDirect3D9_GetAdapterDisplayMode(&device->d3d_parent->IDirect3D9Ex_iface,
+            device->adapter_ordinal, &mode)))
+    {
+        WARN("Failed to get device display mode, hr %#x.\n", hr);
+        return hr;
+    }
+
+    if (surface_desc.Width > mode.Width || surface_desc.Height > mode.Height)
+    {
+        WARN("Surface dimension %ux%u exceeds display mode %ux%u.\n", surface_desc.Width,
+                surface_desc.Height, mode.Width, mode.Height);
+        return D3DERR_INVALIDCALL;
+    }
+
     wined3d_mutex_lock();
     hr = wined3d_device_set_cursor_properties(device->wined3d_device,
             hotspot_x, hotspot_y, bitmap_impl->wined3d_texture, bitmap_impl->sub_resource_idx);
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 05087fee24..ee007568d4 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4910,9 +4910,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device
 {
     unsigned int texture_level = sub_resource_idx % texture->level_count;
     unsigned int cursor_width, cursor_height;
-    struct wined3d_display_mode mode;
     struct wined3d_map_desc map_desc;
-    HRESULT hr;
 
     TRACE("device %p, x_hotspot %u, y_hotspot %u, texture %p, sub_resource_idx %u.\n",
             device, x_hotspot, y_hotspot, texture, sub_resource_idx);
@@ -4943,19 +4941,6 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device
         return WINED3DERR_INVALIDCALL;
     }
 
-    if (FAILED(hr = wined3d_output_get_display_mode(&device->adapter->outputs[0], &mode, NULL)))
-    {
-        ERR("Failed to get display mode, hr %#x.\n", hr);
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    if (cursor_width > mode.width || cursor_height > mode.height)
-    {
-        WARN("Texture %p, sub-resource %u dimensions are %ux%u, but screen dimensions are %ux%u.\n",
-                texture, sub_resource_idx, cursor_width, cursor_height, mode.width, mode.height);
-        return WINED3DERR_INVALIDCALL;
-    }
-
     /* Do not store the surface's pointer because the application may
      * release it after setting the cursor image. Windows doesn't
      * addref the set surface, so we can't do this either without




More information about the wine-cvs mailing list