From 8417e217006246026be632c3e50209be47e5adb1 Mon Sep 17 00:00:00 2001
From: Fatih Uzunoglu <fuzun54@outlook.com>
Date: Mon, 24 Mar 2025 20:41:18 +0200
Subject: [PATCH 1/5] qml: set ready count at appropriate time in `DragItem`

---
 modules/gui/qt/widgets/qml/DragItem.qml | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/modules/gui/qt/widgets/qml/DragItem.qml b/modules/gui/qt/widgets/qml/DragItem.qml
index 2ceb9a269337..fb6bcfe8863a 100644
--- a/modules/gui/qt/widgets/qml/DragItem.qml
+++ b/modules/gui/qt/widgets/qml/DragItem.qml
@@ -426,12 +426,15 @@ Item {
     Repeater {
         id: coverRepeater
 
-        model: dragItem._covers
+        readonly property var _model: dragItem._covers
 
-        property int notReadyCount: count
+        property int notReadyCount
 
-        onModelChanged: {
-            notReadyCount = count
+        on_ModelChanged: {
+            // Repeater signals model and count change after it reloads the items.
+            // So we need to adjust the ready count before that:
+            notReadyCount = _model.length
+            model = _model
         }
 
         onNotReadyCountChanged: {
-- 
GitLab


From 24ab921c8db562b1f50e42dc83da5e43d92b88eb Mon Sep 17 00:00:00 2001
From: Fatih Uzunoglu <fuzun54@outlook.com>
Date: Mon, 24 Mar 2025 23:50:28 +0200
Subject: [PATCH 2/5] qml: expose shader status in `ImageExt`

---
 modules/gui/qt/widgets/qml/ImageExt.qml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/gui/qt/widgets/qml/ImageExt.qml b/modules/gui/qt/widgets/qml/ImageExt.qml
index 551e5f5fde60..2013a973779e 100644
--- a/modules/gui/qt/widgets/qml/ImageExt.qml
+++ b/modules/gui/qt/widgets/qml/ImageExt.qml
@@ -51,6 +51,7 @@ Item {
     property alias sourceSize: image.sourceSize
     property alias sourceClipRect: image.sourceClipRect
     property alias status: image.status
+    property alias shaderStatus: shaderEffect.status
     property alias cache: image.cache
 
     // Padding represents how much the content is shrunk. For now this is a readonly property.
-- 
GitLab


From bb1957d69a7c839bb18b6accc2b4d085682ca449 Mon Sep 17 00:00:00 2001
From: Fatih Uzunoglu <fuzun54@outlook.com>
Date: Mon, 24 Mar 2025 23:58:06 +0200
Subject: [PATCH 3/5] qml: consider shader status in `DragItem` and handle the
 counter better

---
 modules/gui/qt/widgets/qml/DragItem.qml | 37 +++++++++++++++++++++----
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/modules/gui/qt/widgets/qml/DragItem.qml b/modules/gui/qt/widgets/qml/DragItem.qml
index fb6bcfe8863a..e9d77ba5f375 100644
--- a/modules/gui/qt/widgets/qml/DragItem.qml
+++ b/modules/gui/qt/widgets/qml/DragItem.qml
@@ -479,16 +479,41 @@ Item {
                 fillMode: Image.PreserveAspectCrop
 
                 readonly property real eDPR: MainCtx.effectiveDevicePixelRatio(Window.window)
+                property bool _triggerReadiness: false
 
-                onStatusChanged: {
-                    if (status === Image.Ready)
+                on_TriggerReadinessChanged: {
+                    // If it was already true (readiness already signalled), do not decrease the counter.
+                    // This handler is only called when the property changes.
+                    if (_triggerReadiness) {
                         coverRepeater.notReadyCount -= 1
-                    else if (status === Image.Error) {
+                    }
+                }
+
+                readonly property var _combinedStatus: [status, shaderStatus]
+
+                on_CombinedStatusChanged: {
+                    // Qt `ShaderEffect` documentation states:
+                    // > When runtime compilation is not in use and the shader properties
+                    // > refer to files with bytecode, the status is always Compiled.
+                    // However this is not correct, the status is reported to be "uncompiled" initially.
+                    // And sometimes the status remains "uncompiled" even when the shader is in use, for
+                    // that reason I only care about `ShaderEffect.Error` here and not `Compiled`.
+
+                    if (shaderStatus === ShaderEffect.Error) {
+                        _triggerReadiness = true // Not much to do in this case, shader could not be loaded.
+                        return
+                    }
+
+                    if (status === Image.Error) {
                         const fallbackSource = modelData.fallback ?? defaultCover
-                        if (source === fallbackSource)
-                            coverRepeater.notReadyCount -= 1
-                        else
+                        if (source === fallbackSource) {
+                            _triggerReadiness = true // Not much to do in this case either, fallback image could not be loaded.
+                        } else {
                             source = fallbackSource
+                        }
+                    } else if (status === Image.Ready /* && shaderStatus === ShaderEffect.Compiled */) {
+                        // FIXME: When Qt starts to report `ShaderEffect.Compiled` properly, start using it.
+                        _triggerReadiness = true // Only in this case the image is loaded and shown.
                     }
                 }
             }
-- 
GitLab


From e862c5afd1ce48774b646fa38c2b7279dd5ac58a Mon Sep 17 00:00:00 2001
From: Fatih Uzunoglu <fuzun54@outlook.com>
Date: Tue, 25 Mar 2025 00:04:15 +0200
Subject: [PATCH 4/5] qml: leverage `ImageExt` for background coloring and
 outlining in `DragItem`

The extra rectangles are useless because `ImageExt` can already do what they
are doing.
---
 modules/gui/qt/widgets/qml/DragItem.qml | 32 +++++++------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/modules/gui/qt/widgets/qml/DragItem.qml b/modules/gui/qt/widgets/qml/DragItem.qml
index e9d77ba5f375..2ecbb862b9f5 100644
--- a/modules/gui/qt/widgets/qml/DragItem.qml
+++ b/modules/gui/qt/widgets/qml/DragItem.qml
@@ -453,29 +453,18 @@ Item {
             width: dragItem.coverSize
             height: dragItem.coverSize
 
-            Rectangle {
-                id: bg
-
-                radius: coverRepeater.count > 1 ? dragItem.coverSize : 0.0
-                anchors.fill: parent
-                color: theme.bg.primary
-
-                DefaultShadow {
-                    anchors.centerIn: parent
-
-                    sourceItem: bg
-                }
-            }
-
             Widgets.ImageExt {
                 id: artworkCover
 
                 anchors.centerIn: parent
                 width: coverSize
                 height: coverSize
-                radius: bg.radius
+                radius: coverRepeater.count > 1 ? dragItem.coverSize : 0.0
                 source: modelData.artwork ?? ""
                 sourceSize: dragItem.imageSourceSize ?? Qt.size(width * eDPR, height * eDPR)
+                backgroundColor: theme.bg.primary
+                borderWidth: VLCStyle.dp(1, VLCStyle.scale)
+                borderColor: theme.border
                 fillMode: Image.PreserveAspectCrop
 
                 readonly property real eDPR: MainCtx.effectiveDevicePixelRatio(Window.window)
@@ -516,15 +505,12 @@ Item {
                         _triggerReadiness = true // Only in this case the image is loaded and shown.
                     }
                 }
-            }
 
-            Rectangle {
-                // for cover border
-                color: "transparent"
-                border.width: VLCStyle.dp(1, VLCStyle.scale)
-                border.color: theme.border
-                anchors.fill: parent
-                radius: bg.radius
+                DefaultShadow {
+                    anchors.centerIn: parent
+
+                    sourceItem: parent
+                }
             }
         }
     }
-- 
GitLab


From 1e9f677c17d564088032b3ffa2f70f640da2ea37 Mon Sep 17 00:00:00 2001
From: Fatih Uzunoglu <fuzun54@outlook.com>
Date: Tue, 25 Mar 2025 00:21:51 +0200
Subject: [PATCH 5/5] qml: disable asynchronous in `DragItem` image as a Qt bug
 workaround

---
 modules/gui/qt/widgets/qml/DragItem.qml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/modules/gui/qt/widgets/qml/DragItem.qml b/modules/gui/qt/widgets/qml/DragItem.qml
index 2ecbb862b9f5..3ecc2dabfb10 100644
--- a/modules/gui/qt/widgets/qml/DragItem.qml
+++ b/modules/gui/qt/widgets/qml/DragItem.qml
@@ -467,6 +467,9 @@ Item {
                 borderColor: theme.border
                 fillMode: Image.PreserveAspectCrop
 
+                // FIXME: Qt bug, asynchronous + texture provider + custom shader does not work properly with `grabToImage()`:
+                asynchronous: false
+
                 readonly property real eDPR: MainCtx.effectiveDevicePixelRatio(Window.window)
                 property bool _triggerReadiness: false
 
-- 
GitLab