From 61d50cbc96e5331218a6a4e5614f50211f06c718 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 24 Jan 2019 08:54:38 +0100 Subject: Windows/Direct2d QPA: Use nullptr Change-Id: I6ce01caa58de78e0eb61e243ee1e7b05cc1f5568 Reviewed-by: Oliver Wolff --- .../platforms/windows/qwindowsopengltester.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowsopengltester.cpp') diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index 3efccf0f32..2046135725 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -330,10 +330,10 @@ bool QWindowsOpenGLTester::testDesktopGL() typedef BOOL (WINAPI *MakeCurrentType)(HDC, HGLRC); typedef PROC (WINAPI *WglGetProcAddressType)(LPCSTR); - HMODULE lib = 0; - HWND wnd = 0; - HDC dc = 0; - HGLRC context = 0; + HMODULE lib = nullptr; + HWND wnd = nullptr; + HDC dc = nullptr; + HGLRC context = nullptr; LPCTSTR className = L"qtopengltest"; CreateContextType CreateContext = nullptr; @@ -367,18 +367,18 @@ bool QWindowsOpenGLTester::testDesktopGL() WNDCLASS wclass; wclass.cbClsExtra = 0; wclass.cbWndExtra = 0; - wclass.hInstance = static_cast(GetModuleHandle(0)); - wclass.hIcon = 0; - wclass.hCursor = 0; + wclass.hInstance = static_cast(GetModuleHandle(nullptr)); + wclass.hIcon = nullptr; + wclass.hCursor = nullptr; wclass.hbrBackground = HBRUSH(COLOR_BACKGROUND); - wclass.lpszMenuName = 0; + wclass.lpszMenuName = nullptr; wclass.lpfnWndProc = DefWindowProc; wclass.lpszClassName = className; wclass.style = CS_OWNDC; if (!RegisterClass(&wclass)) goto cleanup; wnd = CreateWindow(className, L"qtopenglproxytest", WS_OVERLAPPED, - 0, 0, 640, 480, 0, 0, wclass.hInstance, 0); + 0, 0, 640, 480, nullptr, nullptr, wclass.hInstance, nullptr); if (!wnd) goto cleanup; dc = GetDC(wnd); @@ -447,14 +447,14 @@ bool QWindowsOpenGLTester::testDesktopGL() cleanup: if (MakeCurrent) - MakeCurrent(0, 0); + MakeCurrent(nullptr, nullptr); if (context) DeleteContext(context); if (dc && wnd) ReleaseDC(wnd, dc); if (wnd) { DestroyWindow(wnd); - UnregisterClass(className, GetModuleHandle(0)); + UnregisterClass(className, GetModuleHandle(nullptr)); } // No FreeLibrary. Some implementations, Mesa in particular, deadlock when trying to unload. -- cgit v1.2.3 From 15f88a7c01007ae1962b83aefc5a536e16fcb446 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 13 Mar 2019 13:32:34 +0100 Subject: Windows QPA: Output all adapters in diagnostics used by qtdiag Split up the code detecting the GPUs into small helpers. Add a QDirect3D9Handle class providing Direct3D9 functionality, add GpuDescription::detectAll() and add a QVariantList "gpuList" property to the native interface. Task-number: QTBUG-50371 Task-number: QTBUG-65882 Change-Id: I8673542d327837babc2ad8f507da76e8ff5524ea Reviewed-by: Oliver Wolff --- .../platforms/windows/qwindowsopengltester.cpp | 132 ++++++++++++++------- 1 file changed, 91 insertions(+), 41 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowsopengltester.cpp') diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index 2046135725..840a3a11c4 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -62,19 +62,70 @@ QT_BEGIN_NAMESPACE static const DWORD VENDOR_ID_AMD = 0x1002; -GpuDescription GpuDescription::detect() +static GpuDescription adapterIdentifierToGpuDescription(const D3DADAPTER_IDENTIFIER9 &adapterIdentifier) +{ + GpuDescription result; + result.vendorId = adapterIdentifier.VendorId; + result.deviceId = adapterIdentifier.DeviceId; + result.revision = adapterIdentifier.Revision; + result.subSysId = adapterIdentifier.SubSysId; + QVector version(4, 0); + version[0] = HIWORD(adapterIdentifier.DriverVersion.HighPart); // Product + version[1] = LOWORD(adapterIdentifier.DriverVersion.HighPart); // Version + version[2] = HIWORD(adapterIdentifier.DriverVersion.LowPart); // Sub version + version[3] = LOWORD(adapterIdentifier.DriverVersion.LowPart); // build + result.driverVersion = QVersionNumber(version); + result.driverName = adapterIdentifier.Driver; + result.description = adapterIdentifier.Description; + return result; +} + +class QDirect3D9Handle +{ +public: + Q_DISABLE_COPY(QDirect3D9Handle) + + QDirect3D9Handle(); + ~QDirect3D9Handle(); + + bool isValid() const { return m_direct3D9 != nullptr; } + + UINT adapterCount() const { return m_direct3D9 ? m_direct3D9->GetAdapterCount() : 0u; } + bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; + +private: + QSystemLibrary m_d3d9lib; + IDirect3D9 *m_direct3D9 = nullptr; +}; + +QDirect3D9Handle::QDirect3D9Handle() : + m_d3d9lib(QStringLiteral("d3d9")) { - typedef IDirect3D9 * (WINAPI *PtrDirect3DCreate9)(UINT); + using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); + if (m_d3d9lib.load()) { + if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9")) + m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION); + } +} + +QDirect3D9Handle::~QDirect3D9Handle() +{ + if (m_direct3D9) + m_direct3D9->Release(); +} + +bool QDirect3D9Handle::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const +{ + return m_direct3D9 + && SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier)); +} + +GpuDescription GpuDescription::detect() +{ GpuDescription result; - QSystemLibrary d3d9lib(QStringLiteral("d3d9")); - if (!d3d9lib.load()) - return result; - PtrDirect3DCreate9 direct3DCreate9 = (PtrDirect3DCreate9)d3d9lib.resolve("Direct3DCreate9"); - if (!direct3DCreate9) - return result; - IDirect3D9 *direct3D9 = direct3DCreate9(D3D_SDK_VERSION); - if (!direct3D9) + QDirect3D9Handle direct3D9; + if (!direct3D9.isValid()) return result; D3DADAPTER_IDENTIFIER9 adapterIdentifier; @@ -85,20 +136,8 @@ GpuDescription GpuDescription::detect() // and D3D uses by default. Therefore querying any additional adapters is // futile and not useful for our purposes in general, except for // identifying a few special cases later on. - HRESULT hr = direct3D9->GetAdapterIdentifier(0, 0, &adapterIdentifier); - if (SUCCEEDED(hr)) { - result.vendorId = adapterIdentifier.VendorId; - result.deviceId = adapterIdentifier.DeviceId; - result.revision = adapterIdentifier.Revision; - result.subSysId = adapterIdentifier.SubSysId; - QVector version(4, 0); - version[0] = HIWORD(adapterIdentifier.DriverVersion.HighPart); // Product - version[1] = LOWORD(adapterIdentifier.DriverVersion.HighPart); // Version - version[2] = HIWORD(adapterIdentifier.DriverVersion.LowPart); // Sub version - version[3] = LOWORD(adapterIdentifier.DriverVersion.LowPart); // build - result.driverVersion = QVersionNumber(version); - result.driverName = adapterIdentifier.Driver; - result.description = adapterIdentifier.Description; + if (direct3D9.retrieveAdapterIdentifier(0, &adapterIdentifier)) { + result = adapterIdentifierToGpuDescription(adapterIdentifier); isAMD = result.vendorId == VENDOR_ID_AMD; } @@ -106,30 +145,41 @@ GpuDescription GpuDescription::detect() // when starting apps on a screen connected to the Intel card) by looking // for a default AMD adapter and an additional non-AMD one. if (isAMD) { - const UINT adapterCount = direct3D9->GetAdapterCount(); + const UINT adapterCount = direct3D9.adapterCount(); for (UINT adp = 1; adp < adapterCount; ++adp) { - hr = direct3D9->GetAdapterIdentifier(adp, 0, &adapterIdentifier); - if (SUCCEEDED(hr)) { - if (adapterIdentifier.VendorId != VENDOR_ID_AMD) { - // Bingo. Now figure out the display for the AMD card. - DISPLAY_DEVICE dd; - memset(&dd, 0, sizeof(dd)); - dd.cb = sizeof(dd); - for (int dev = 0; EnumDisplayDevices(nullptr, dev, &dd, 0); ++dev) { - if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) { - // DeviceName is something like \\.\DISPLAY1 which can be used to - // match with the MONITORINFOEX::szDevice queried by QWindowsScreen. - result.gpuSuitableScreen = QString::fromWCharArray(dd.DeviceName); - break; - } + if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier) + && adapterIdentifier.VendorId != VENDOR_ID_AMD) { + // Bingo. Now figure out the display for the AMD card. + DISPLAY_DEVICE dd; + memset(&dd, 0, sizeof(dd)); + dd.cb = sizeof(dd); + for (int dev = 0; EnumDisplayDevices(nullptr, dev, &dd, 0); ++dev) { + if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) { + // DeviceName is something like \\.\DISPLAY1 which can be used to + // match with the MONITORINFOEX::szDevice queried by QWindowsScreen. + result.gpuSuitableScreen = QString::fromWCharArray(dd.DeviceName); + break; } - break; } + break; } } } - direct3D9->Release(); + return result; +} + +QVector GpuDescription::detectAll() +{ + QVector result; + QDirect3D9Handle direct3D9; + if (const UINT adapterCount = direct3D9.adapterCount()) { + for (UINT adp = 0; adp < adapterCount; ++adp) { + D3DADAPTER_IDENTIFIER9 adapterIdentifier; + if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier)) + result.append(adapterIdentifierToGpuDescription(adapterIdentifier)); + } + } return result; } -- cgit v1.2.3