From e14a0233f1e35537aa903a49e0605145e6fc0bc8 Mon Sep 17 00:00:00 2001
From: Fatih Uzunoglu <fuzun54@outlook.com>
Date: Fri, 29 Jul 2022 18:29:29 +0300
Subject: [PATCH] qml: enable layering in stackView when miniPlayer effect is
 available

---
 .../gui/qt/maininterface/qml/MainDisplay.qml  | 21 +++++++++++++++++++
 modules/gui/qt/player/qml/MiniPlayer.qml      |  1 +
 2 files changed, 22 insertions(+)

diff --git a/modules/gui/qt/maininterface/qml/MainDisplay.qml b/modules/gui/qt/maininterface/qml/MainDisplay.qml
index 0be5598c01d9..4ff89a92b16a 100644
--- a/modules/gui/qt/maininterface/qml/MainDisplay.qml
+++ b/modules/gui/qt/maininterface/qml/MainDisplay.qml
@@ -266,6 +266,27 @@ FocusScope {
                             leftMargin: VLCStyle.applicationHorizontalMargin
                         }
 
+                        // This item is the root of a large hierarchy
+                        // which requires many batches to be rendered.
+                        // When the miniPlayer effect is active, this
+                        // item (source item) gets rendered in an offscreen
+                        // surface. If we don't enable layer here,
+                        // it (along with children) gets rendered again
+                        // in the assigned window.
+                        // If layer is enabled, instead of rendering one
+                        // more time with many batches, a dynamic texture
+                        // from the offscreen surface is used. This behavior
+                        // reduces the amount of batches from 2x to x+1.
+                        // A side effect is having to draw a large texture
+                        // with blending on, but this must be cheaper redrawing
+                        // all the batches.
+                        // TODO: Reconsider this behavior when batching is optimized.
+                        layer.enabled: miniPlayer.visible && miniPlayer.effectAvailable
+
+                        // Enable clipping so that the effect does not sit
+                        // on top of the source.
+                        clip: miniPlayer.visible && miniPlayer.effectAvailable
+
                         Loader {
                             z: 1
                             anchors {
diff --git a/modules/gui/qt/player/qml/MiniPlayer.qml b/modules/gui/qt/player/qml/MiniPlayer.qml
index 1f5a0aeb8d8b..289052f64a80 100644
--- a/modules/gui/qt/player/qml/MiniPlayer.qml
+++ b/modules/gui/qt/player/qml/MiniPlayer.qml
@@ -35,6 +35,7 @@ FocusScope {
 
     property alias effectSource: effect.source
     property alias effectSourceRect: effect.sourceRect
+    property alias effectAvailable: effect.effectAvailable
 
     state: (Player.playingState === Player.PLAYING_STATE_STOPPED) ? ""
                                                                   : "expanded"
-- 
GitLab