[vlc-commits] [Git][videolan/vlc][master] contrib: qt: cache the resolved symbol in `createDirectCompositionDevice()`

François Cartegnie (@fcartegnie) gitlab at videolan.org
Tue Oct 13 08:24:09 UTC 2026



François Cartegnie pushed to branch master at VideoLAN / VLC


Commits:
1176b56b by Fatih Uzunoglu at 2026-10-13T09:42:01+02:00
contrib: qt: cache the resolved symbol in `createDirectCompositionDevice()`

This function should be considered a "hot path", since Qt RHI can be
initialized many times, such as when `QQuickWindow` backed by Qt RHI
is re-created. QML's declarative approach makes this very easy to be
in such a situation, especially with `Popup` with
`windowType: Popup.Window`.

Note that due to "magic statics", this should be thread safe (since
Qt RHI itself should be thread safe).

This change also prevents spamming "Unable to resolve ...".

- - - - -


1 changed file:

- contrib/src/qt/0001-Try-DCompositionCreateDevice3-first-if-available.patch


Changes:

=====================================
contrib/src/qt/0001-Try-DCompositionCreateDevice3-first-if-available.patch
=====================================
@@ -1,4 +1,4 @@
-From 2e74ca54c146bda95482900faba547e96ece24a1 Mon Sep 17 00:00:00 2001
+From 9958323702722501b6569675627db1b9c0f27220 Mon Sep 17 00:00:00 2001
 From: Fatih Uzunoglu <fuzun54 at outlook.com>
 Date: Wed, 24 Jan 2024 16:31:06 +0200
 Subject: [PATCH] Try DCompositionCreateDevice3() first if available
@@ -6,34 +6,60 @@ Subject: [PATCH] Try DCompositionCreateDevice3() first if available
 When the native acrylic effect is not available, the application uses
 effects that can be created through IDCompositionDevice3 with the
 Direct Composition integration.
+
+It also uses `static` variable to not repeatedly resolve the same
+symbol every time the function called.
 ---
- src/gui/rhi/qrhid3dhelpers.cpp | 13 ++++++++++++-
- 1 file changed, 12 insertions(+), 1 deletion(-)
+ src/gui/rhi/qrhid3dhelpers.cpp | 31 +++++++++++++++++++++++++------
+ 1 file changed, 25 insertions(+), 6 deletions(-)
 
 diff --git a/src/gui/rhi/qrhid3dhelpers.cpp b/src/gui/rhi/qrhid3dhelpers.cpp
-index 216c358cbe..79efb386eb 100644
+index 5d935ce5984..4fb65a57826 100644
 --- a/src/gui/rhi/qrhid3dhelpers.cpp
 +++ b/src/gui/rhi/qrhid3dhelpers.cpp
-@@ -110,7 +110,18 @@ IDCompositionDevice *createDirectCompositionDevice()
+@@ -26,17 +26,36 @@ pD3DCompile resolveD3DCompile()
+ 
+ IDCompositionDevice *createDirectCompositionDevice()
+ {
+-    QSystemLibrary dcomplib(QStringLiteral("dcomp"));
+     typedef HRESULT (__stdcall *DCompositionCreateDeviceFuncPtr)(
+         _In_opt_ IDXGIDevice *dxgiDevice,
          _In_ REFIID iid,
          _Outptr_ void **dcompositionDevice);
-     DCompositionCreateDeviceFuncPtr func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(
+-    DCompositionCreateDeviceFuncPtr func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(
 -        dcomplib.resolve("DCompositionCreateDevice"));
-+        dcomplib.resolve("DCompositionCreateDevice3"));
+-    if (!func) {
+-        qWarning("Unable to resolve DCompositionCreateDevice, perhaps dcomp.dll is missing?");
++
++    static const auto func = []() {
++        QSystemLibrary dcomplib(QStringLiteral("dcomp"));
++
++        DCompositionCreateDeviceFuncPtr func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(dcomplib.resolve("DCompositionCreateDevice3"));
 +
-+    if (!func) {
-+        qDebug("Could not resolve DCompositionCreateDevice3, dcomp.dll missing or old. Trying DCompositionCreateDevice2...");
-+        func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(dcomplib.resolve("DCompositionCreateDevice2"));
-+    }
++        if (!func) {
++            qDebug("Could not resolve DCompositionCreateDevice3, dcomp.dll is missing or old. Trying DCompositionCreateDevice2...");
++            func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(dcomplib.resolve("DCompositionCreateDevice2"));
++        }
 +
-+    if (!func) {
-+        qDebug("Could not resolve DCompositionCreateDevice2, dcomp.dll missing or old. Trying DCompositionCreateDevice...");
-+        func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(dcomplib.resolve("DCompositionCreateDevice"));
-+    }
++        if (!func) {
++            qDebug("Could not resolve DCompositionCreateDevice2, dcomp.dll is missing or old. Trying DCompositionCreateDevice...");
++            func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(dcomplib.resolve("DCompositionCreateDevice"));
++        }
 +
-     if (!func) {
-         qWarning("Unable to resolve DCompositionCreateDevice, perhaps dcomp.dll is missing?");
++        if (!func) {
++            qDebug("Unable to resolve DCompositionCreateDevice, perhaps dcomp.dll is missing?");
++        }
++
++        return func;
++    }();
++
++    if (!func)
          return nullptr;
+-    }
++
+     IDCompositionDevice *device = nullptr;
+     HRESULT hr = func(nullptr, __uuidof(IDCompositionDevice), reinterpret_cast<void **>(&device));
+     if (FAILED(hr)) {
 -- 
-2.44.0
+2.55.0
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/1176b56bdef7b96c9d6518b62be37ec8c32d92ed

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/1176b56bdef7b96c9d6518b62be37ec8c32d92ed
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list