[PATCH 2/5] wined3d: Refactor wined3d_get_adapter_identifier() to wined3d_adapter_get_identifier().

Zhiyi Zhang zzhang at codeweavers.com
Tue Mar 10 04:35:09 CDT 2020


wined3d_adapter_get_identifier() uses a struct wined3d_adapter pointer
as parameter.

Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/d3d8/directx.c       |  9 ++++++++-
 dlls/d3d9/directx.c       | 18 ++++++++++++++++--
 dlls/ddraw/ddraw.c        |  4 ++--
 dlls/ddraw/main.c         |  2 +-
 dlls/dxgi/adapter.c       |  8 ++++----
 dlls/wined3d/directx.c    | 14 +++-----------
 dlls/wined3d/wined3d.spec |  2 +-
 include/wine/wined3d.h    |  4 ++--
 8 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/dlls/d3d8/directx.c b/dlls/d3d8/directx.c
index e56246613fa..d60088f2a3c 100644
--- a/dlls/d3d8/directx.c
+++ b/dlls/d3d8/directx.c
@@ -105,11 +105,17 @@ static HRESULT WINAPI d3d8_GetAdapterIdentifier(IDirect3D8 *iface, UINT adapter,
 {
     struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
     struct wined3d_adapter_identifier adapter_id;
+    struct wined3d_adapter *wined3d_adapter;
+    unsigned int output_idx;
     HRESULT hr;
 
     TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
             iface, adapter, flags, identifier);
 
+    output_idx = adapter;
+    if (output_idx >= d3d8->wined3d_output_count)
+        return D3DERR_INVALIDCALL;
+
     adapter_id.driver = identifier->Driver;
     adapter_id.driver_size = sizeof(identifier->Driver);
     adapter_id.description = identifier->Description;
@@ -117,7 +123,8 @@ static HRESULT WINAPI d3d8_GetAdapterIdentifier(IDirect3D8 *iface, UINT adapter,
     adapter_id.device_name = NULL; /* d3d9 only */
     adapter_id.device_name_size = 0; /* d3d9 only */
 
-    if (SUCCEEDED(hr = wined3d_get_adapter_identifier(d3d8->wined3d, adapter, flags, &adapter_id)))
+    wined3d_adapter = wined3d_output_get_adapter(d3d8->wined3d_outputs[output_idx]);
+    if (SUCCEEDED(hr = wined3d_adapter_get_identifier(wined3d_adapter, flags, &adapter_id)))
     {
         identifier->DriverVersion = adapter_id.driver_version;
         identifier->VendorId = adapter_id.vendor_id;
diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c
index cd52a0e68f5..501ae45877b 100644
--- a/dlls/d3d9/directx.c
+++ b/dlls/d3d9/directx.c
@@ -120,11 +120,17 @@ static HRESULT WINAPI d3d9_GetAdapterIdentifier(IDirect3D9Ex *iface, UINT adapte
 {
     struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
     struct wined3d_adapter_identifier adapter_id;
+    struct wined3d_adapter *wined3d_adapter;
+    unsigned int output_idx;
     HRESULT hr;
 
     TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
             iface, adapter, flags, identifier);
 
+    output_idx = adapter;
+    if (output_idx >= d3d9->wined3d_output_count)
+        return D3DERR_INVALIDCALL;
+
     adapter_id.driver = identifier->Driver;
     adapter_id.driver_size = sizeof(identifier->Driver);
     adapter_id.description = identifier->Description;
@@ -132,7 +138,8 @@ static HRESULT WINAPI d3d9_GetAdapterIdentifier(IDirect3D9Ex *iface, UINT adapte
     adapter_id.device_name = identifier->DeviceName;
     adapter_id.device_name_size = sizeof(identifier->DeviceName);
 
-    if (SUCCEEDED(hr = wined3d_get_adapter_identifier(d3d9->wined3d, adapter, flags, &adapter_id)))
+    wined3d_adapter = wined3d_output_get_adapter(d3d9->wined3d_outputs[output_idx]);
+    if (SUCCEEDED(hr = wined3d_adapter_get_identifier(wined3d_adapter, flags, &adapter_id)))
     {
         identifier->DriverVersion = adapter_id.driver_version;
         identifier->VendorId = adapter_id.vendor_id;
@@ -590,15 +597,22 @@ static HRESULT WINAPI d3d9_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUI
 {
     struct d3d9 *d3d9 = impl_from_IDirect3D9Ex(iface);
     struct wined3d_adapter_identifier adapter_id;
+    struct wined3d_adapter *wined3d_adapter;
+    unsigned int output_idx;
     HRESULT hr;
 
     TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
 
+    output_idx = adapter;
+    if (output_idx >= d3d9->wined3d_output_count)
+        return D3DERR_INVALIDCALL;
+
     adapter_id.driver_size = 0;
     adapter_id.description_size = 0;
     adapter_id.device_name_size = 0;
 
-    if (SUCCEEDED(hr = wined3d_get_adapter_identifier(d3d9->wined3d, adapter, 0, &adapter_id)))
+    wined3d_adapter = wined3d_output_get_adapter(d3d9->wined3d_outputs[output_idx]);
+    if (SUCCEEDED(hr = wined3d_adapter_get_identifier(wined3d_adapter, 0, &adapter_id)))
         *luid = adapter_id.adapter_luid;
 
     return hr;
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index d3a536e4127..5487855be67 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -1928,7 +1928,7 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *c
     {
         struct wined3d_adapter_identifier desc = {0};
 
-        hr = wined3d_get_adapter_identifier(ddraw->wined3d, WINED3DADAPTER_DEFAULT, 0, &desc);
+        hr = wined3d_adapter_get_identifier(ddraw->wined3d_adapter, 0, &desc);
         total_vidmem = min(UINT_MAX, desc.video_memory);
         *total = framebuffer_size > total_vidmem ? 0 : total_vidmem - framebuffer_size;
         TRACE("Total video memory %#x.\n", *total);
@@ -2609,7 +2609,7 @@ static HRESULT WINAPI ddraw7_GetDeviceIdentifier(IDirectDraw7 *iface,
     adapter_id.description_size = sizeof(DDDI->szDescription);
     adapter_id.device_name_size = 0;
     wined3d_mutex_lock();
-    hr = wined3d_get_adapter_identifier(ddraw->wined3d, WINED3DADAPTER_DEFAULT, 0x0, &adapter_id);
+    hr = wined3d_adapter_get_identifier(ddraw->wined3d_adapter, 0x0, &adapter_id);
     wined3d_mutex_unlock();
     if (FAILED(hr)) return hr;
 
diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c
index dee93de123e..20c0f3f9537 100644
--- a/dlls/ddraw/main.c
+++ b/dlls/ddraw/main.c
@@ -78,7 +78,7 @@ static void ddraw_enumerate_secondary_devices(struct wined3d *wined3d, LPDDENUMC
         adapter_id.description_size = sizeof(DriverDescription);
 
         wined3d_mutex_lock();
-        if (FAILED(hr = wined3d_get_adapter_identifier(wined3d, adapter_idx, 0x0, &adapter_id)))
+        if (FAILED(hr = wined3d_adapter_get_identifier(wined3d_adapter, 0x0, &adapter_id)))
         {
             WARN("Failed to get adapter identifier, hr %#x.\n", hr);
             wined3d_mutex_unlock();
diff --git a/dlls/dxgi/adapter.c b/dlls/dxgi/adapter.c
index 8d2879e4129..2bd69954e10 100644
--- a/dlls/dxgi/adapter.c
+++ b/dlls/dxgi/adapter.c
@@ -163,7 +163,7 @@ static HRESULT dxgi_adapter_get_desc(struct dxgi_adapter *adapter, DXGI_ADAPTER_
     adapter_id.description_size = sizeof(description);
     adapter_id.device_name_size = 0;
 
-    if (FAILED(hr = wined3d_get_adapter_identifier(adapter->factory->wined3d, adapter->ordinal, 0, &adapter_id)))
+    if (FAILED(hr = wined3d_adapter_get_identifier(adapter->wined3d_adapter, 0, &adapter_id)))
         return hr;
 
     if (!MultiByteToWideChar(CP_ACP, 0, description, -1, desc->Description, ARRAY_SIZE(description)))
@@ -233,7 +233,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_adapter_CheckInterfaceSupport(IWineDXGIAda
     wined3d = adapter->factory->wined3d;
     hr = wined3d_get_device_caps(wined3d, adapter->ordinal, WINED3D_DEVICE_TYPE_HAL, &caps);
     if (SUCCEEDED(hr))
-        hr = wined3d_get_adapter_identifier(wined3d, adapter->ordinal, 0, &adapter_id);
+        hr = wined3d_adapter_get_identifier(adapter->wined3d_adapter, 0, &adapter_id);
     wined3d_mutex_unlock();
 
     if (FAILED(hr))
@@ -316,7 +316,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_adapter_QueryVideoMemoryInfo(IWineDXGIAdap
     adapter_id.description_size = 0;
     adapter_id.device_name_size = 0;
 
-    if (FAILED(hr = wined3d_get_adapter_identifier(adapter->factory->wined3d, adapter->ordinal, 0, &adapter_id)))
+    if (FAILED(hr = wined3d_adapter_get_identifier(adapter->wined3d_adapter, 0, &adapter_id)))
         return hr;
 
     switch (segment_group)
@@ -387,7 +387,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_adapter_get_adapter_info(IWineDXGIAdapter
     TRACE("iface %p, info %p.\n", iface, info);
 
     memset(&adapter_id, 0, sizeof(adapter_id));
-    if (SUCCEEDED(hr = wined3d_get_adapter_identifier(adapter->factory->wined3d, adapter->ordinal, 0, &adapter_id)))
+    if (SUCCEEDED(hr = wined3d_adapter_get_identifier(adapter->wined3d_adapter, 0, &adapter_id)))
     {
         info->driver_uuid = adapter_id.driver_uuid;
         info->device_uuid = adapter_id.device_uuid;
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index ecfa444e050..722b12f0a30 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -1347,21 +1347,13 @@ HRESULT CDECL wined3d_output_set_display_mode(struct wined3d_output *output,
     return WINED3D_OK;
 }
 
-HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d,
-        UINT adapter_idx, DWORD flags, struct wined3d_adapter_identifier *identifier)
+HRESULT CDECL wined3d_adapter_get_identifier(const struct wined3d_adapter *adapter,
+        DWORD flags, struct wined3d_adapter_identifier *identifier)
 {
-    const struct wined3d_adapter *adapter;
-
-    TRACE("wined3d %p, adapter_idx %u, flags %#x, identifier %p.\n",
-            wined3d, adapter_idx, flags, identifier);
+    TRACE("adapter %p, flags %#x, identifier %p.\n", adapter, flags, identifier);
 
     wined3d_mutex_lock();
 
-    if (adapter_idx >= wined3d->adapter_count)
-        goto fail;
-
-    adapter = wined3d->adapters[adapter_idx];
-
     wined3d_copy_name(identifier->driver, adapter->driver_info.name, identifier->driver_size);
     wined3d_copy_name(identifier->description, adapter->driver_info.description, identifier->description_size);
 
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index d4b0a147262..076386ac64a 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -11,7 +11,6 @@
 @ cdecl wined3d_decref(ptr)
 @ cdecl wined3d_get_adapter(ptr long)
 @ cdecl wined3d_get_adapter_count(ptr)
-@ cdecl wined3d_get_adapter_identifier(ptr long long ptr)
 @ cdecl wined3d_get_device_caps(ptr long long ptr)
 @ cdecl wined3d_get_output_desc(ptr long ptr)
 @ cdecl wined3d_incref(ptr)
@@ -19,6 +18,7 @@
 @ cdecl wined3d_register_window(ptr ptr ptr long)
 @ cdecl wined3d_unregister_windows(ptr)
 
+@ cdecl wined3d_adapter_get_identifier(ptr long ptr)
 @ cdecl wined3d_adapter_get_output(ptr long)
 @ cdecl wined3d_adapter_get_output_count(ptr)
 
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 5ff935dd8ea..752c98261de 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2268,8 +2268,6 @@ ULONG __cdecl wined3d_decref(struct wined3d *wined3d);
 struct wined3d_adapter * __cdecl wined3d_get_adapter(const struct wined3d *wined3d,
         unsigned int idx);
 UINT __cdecl wined3d_get_adapter_count(const struct wined3d *wined3d);
-HRESULT __cdecl wined3d_get_adapter_identifier(const struct wined3d *wined3d, UINT adapter_idx,
-        DWORD flags, struct wined3d_adapter_identifier *identifier);
 HRESULT __cdecl wined3d_get_device_caps(const struct wined3d *wined3d, unsigned int adapter_idx,
         enum wined3d_device_type device_type, struct wined3d_caps *caps);
 HRESULT __cdecl wined3d_get_output_desc(const struct wined3d *wined3d, unsigned int adapter_idx,
@@ -2280,6 +2278,8 @@ BOOL __cdecl wined3d_register_window(struct wined3d *wined3d, HWND window,
         struct wined3d_device *device, unsigned int flags);
 void __cdecl wined3d_unregister_windows(struct wined3d *wined3d);
 
+HRESULT __cdecl wined3d_adapter_get_identifier(const struct wined3d_adapter *adapter,
+        DWORD flags, struct wined3d_adapter_identifier *identifier);
 struct wined3d_output * __cdecl wined3d_adapter_get_output(const struct wined3d_adapter *adapter,
         unsigned int idx);
 unsigned int __cdecl wined3d_adapter_get_output_count(const struct wined3d_adapter *adapter);
-- 
2.20.1




More information about the wine-devel mailing list