[vlc-commits] [Git][videolan/vlc][master] 3 commits: qml: introduce PartialEffect

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Jan 5 17:51:33 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
555584ed by Fatih Uzunoglu at 2024-01-05T17:08:29+00:00
qml: introduce PartialEffect

- - - - -
37d6c519 by Fatih Uzunoglu at 2024-01-05T17:08:29+00:00
qml: simplify FrostedGlassEffect and use PartialEffect

- - - - -
d6829a70 by Fatih Uzunoglu at 2024-01-05T17:08:29+00:00
qml: adjust shader variable precision in FrostedGlassEffect

- - - - -


5 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/vlc.qrc
- modules/gui/qt/widgets/qml/FrostedGlassEffect.qml
- + modules/gui/qt/widgets/qml/PartialEffect.qml


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -1073,7 +1073,8 @@ libqt_plugin_la_QML = \
 	widgets/qml/DoubleShadow.qml \
 	widgets/qml/FadingEdge.qml \
 	widgets/qml/FadingEdgeForListView.qml \
-	widgets/qml/PopupIconToolButton.qml
+	widgets/qml/PopupIconToolButton.qml \
+	widgets/qml/PartialEffect.qml
 
 lib_qt_plugin_la_QRC = vlc.qrc
 


=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -231,21 +231,29 @@ FocusScope {
                                ((GraphicsInfo.shaderSourceType & GraphicsInfo.ShaderSourceString))) &&
                                (miniPlayer.visible || (loaderProgress.active && loaderProgress.item.visible))
 
-                layer.effect: Widgets.FrostedGlassEffect {
-                    ColorContext {
-                        id: frostedTheme
-                        palette: VLCStyle.palette
-                        colorSet: ColorContext.Window
-                    }
+                layer.effect: Widgets.PartialEffect {
+                    id: stackViewParentLayerEffect
 
                     blending: stackViewParent.color.a < (1.0 - Number.EPSILON)
 
-                    tint: frostedTheme.bg.secondary
-
                     effectRect: Qt.rect(0,
                                         stackView.height,
                                         width,
                                         height - stackView.height)
+
+                    effectLayer.effect: Component {
+                        Widgets.FrostedGlassEffect {
+                            ColorContext {
+                                id: frostedTheme
+                                palette: VLCStyle.palette
+                                colorSet: ColorContext.Window
+                            }
+
+                            blending: stackViewParentLayerEffect.blending
+
+                            tint: frostedTheme.bg.secondary
+                        }
+                    }
                 }
 
                 Widgets.PageLoader {


=====================================
modules/gui/qt/vlc.qrc
=====================================
@@ -228,6 +228,7 @@
         <file alias="FadingEdge.qml">widgets/qml/FadingEdge.qml</file>
         <file alias="FadingEdgeForListView.qml">widgets/qml/FadingEdgeForListView.qml</file>
         <file alias="PopupIconToolButton.qml">widgets/qml/PopupIconToolButton.qml</file>
+        <file alias="PartialEffect.qml">widgets/qml/PartialEffect.qml</file>
     </qresource>
     <qresource prefix="/network">
         <file alias="AddressbarButton.qml">network/qml/AddressbarButton.qml</file>


=====================================
modules/gui/qt/widgets/qml/FrostedGlassEffect.qml
=====================================
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (C) 2022 VLC authors and VideoLAN
+ * Copyright (C) 2024 VLC authors and VideoLAN
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,141 +22,61 @@ import QtGraphicalEffects 1.12
 import "qrc:///style/"
 
 // This item can be used as a layer effect.
-// Right now, it has the following limitations:
-// * The blur effect is processed for the whole source,
-//   even though it is only shown for the area denoted
-//   by effectRect. This is caused by FastBlur not
-//   accepting a source rectangle.
-Item {
-    id: effect
+// Make sure that the sampler name is set to "source" (default).
+FastBlur {
+    id: root
 
-    property var source
+    radius: 64
 
-    // Rectangular area where the effect should be applied:
-    property alias effectRect: blurProxy.sourceRect
-
-    property alias blurRadius: blurEffect.radius
+    property bool blending: false
 
     property color tint: "transparent"
     property real tintStrength: Qt.colorEqual(tint, "transparent") ? 0.0 : 0.7
     property real noiseStrength: 0.02
     property real exclusionStrength: 0.09
 
-    // Enable blending if background is not fully opaque:
-    // This comes with a performance penalty.
-    property bool blending: false
-
-    ShaderEffect {
-        anchors.fill: parent
-
-        property alias source: effect.source
-
-        readonly property rect discardRect: {
-            if (effect.blending)
-                return Qt.rect(blurProxy.x / effect.width, blurProxy.y / effect.height,
-                               (blurProxy.x + blurProxy.width) / effect.width, (blurProxy.y + blurProxy.height) / effect.height)
-            else // If blending is not enabled, no need to make the normalization calculations
-                return Qt.rect(0, 0, 0, 0)
-        }
+    layer.enabled: true
+    layer.effect: ShaderEffect {
+        readonly property color tint: root.tint
+        readonly property real tintStrength: root.tintStrength
+        readonly property real noiseStrength: root.noiseStrength
+        readonly property real exclusionStrength: root.exclusionStrength
 
         cullMode: ShaderEffect.BackFaceCulling
 
-        blending: effect.blending
-
-        // Simple filter that is only enabled when blending is active.
-        // We do not want the source to be rendered below the frosted glass effect.
-        fragmentShader: blending ? "
-                varying highp vec2 qt_TexCoord0;
-                uniform sampler2D source;
-                uniform lowp float qt_Opacity;
-                uniform highp vec4 discardRect;
-
-                void main() {
-                    if (((qt_TexCoord0.x >= discardRect.x && qt_TexCoord0.x <= discardRect.w) &&
-                        (qt_TexCoord0.y >= discardRect.y && qt_TexCoord0.y <= discardRect.z)))
-                      discard;
-
-                    highp vec4 texel = texture2D(source, qt_TexCoord0);
-
-                    gl_FragColor = texel * qt_Opacity;
-                }" : ""
-    }
-
-    FastBlur {
-        id: blurEffect
-
-        anchors.fill: parent
-
-        source: effect.source
-
-        radius: 64
-
-        visible: false
-    }
-
-    ShaderEffectSource {
-        id: blurProxy
-
-        x: Math.floor(sourceRect.x)
-        y: Math.floor(sourceRect.y)
-        width: sourceRect.width > 0 ? Math.ceil(sourceRect.width)
-                                    : implicitWidth
-        height: sourceRect.height > 0 ? Math.ceil(sourceRect.height)
-                                      : implicitHeight
-
-        implicitWidth: Math.ceil(parent.width)
-        implicitHeight: Math.ceil(parent.height)
-
-        sourceItem: blurEffect
-        recursive: false
-        samples: 0
-        smooth: false
-
-        mipmap: false
-
-        layer.enabled: true
-        layer.effect: ShaderEffect {
-            readonly property color tint: effect.tint
-            readonly property real tintStrength: effect.tintStrength
-            readonly property real noiseStrength: effect.noiseStrength
-            readonly property real exclusionStrength: effect.exclusionStrength
-
-            cullMode: ShaderEffect.BackFaceCulling
-
-            blending: effect.blending
+        blending: root.blending
 
-            fragmentShader: "
-                uniform lowp sampler2D source; // this item
-                varying highp vec2 qt_TexCoord0;
+        fragmentShader: "
+            uniform lowp sampler2D source;
+            varying highp vec2 qt_TexCoord0;
 
-                uniform lowp float qt_Opacity;
+            uniform lowp float qt_Opacity;
 
-                uniform lowp vec4  tint;
+            uniform lowp vec4 tint;
 
-                uniform lowp float exclusionStrength;
-                uniform lowp float noiseStrength;
-                uniform lowp float tintStrength;
+            uniform lowp float exclusionStrength;
+            uniform lowp float noiseStrength;
+            uniform lowp float tintStrength;
 
-                mediump float rand(highp vec2 co){
-                    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
-                }
+            highp float rand(highp vec2 co){
+                return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
+            }
 
-                mediump vec4 exclude(mediump vec4 src, mediump vec4 dst)
-                {
-                    return src + dst - 2.0 * src * dst;
-                }
+            highp vec4 exclude(highp vec4 src, highp vec4 dst)
+            {
+                return src + dst - 2.0 * src * dst;
+            }
 
-                void main() {
-                   mediump float r = rand(qt_TexCoord0) - 0.5;
-                   mediump vec4 noise = vec4(r,r,r,1.0) * noiseStrength;
-                   mediump vec4 blurred  = texture2D(source, qt_TexCoord0);
+            void main() {
+               highp float r = rand(qt_TexCoord0) - 0.5;
+               highp vec4 noise = vec4(r,r,r,1.0) * noiseStrength;
+               highp vec4 blurred  = texture2D(source, qt_TexCoord0);
 
-                   mediump vec4 exclColor = vec4(exclusionStrength, exclusionStrength, exclusionStrength, 0.0);
+               highp vec4 exclColor = vec4(exclusionStrength, exclusionStrength, exclusionStrength, 0.0);
 
-                   blurred = exclude(blurred, exclColor);
+               blurred = exclude(blurred, exclColor);
 
-                   gl_FragColor = (mix(blurred, tint, tintStrength) + noise) * qt_Opacity;
-                }"
-        }
+               gl_FragColor = (mix(blurred, tint, tintStrength) + noise) * qt_Opacity;
+            }"
     }
 }


=====================================
modules/gui/qt/widgets/qml/PartialEffect.qml
=====================================
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ * Copyright (C) 2024 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+import QtQuick 2.12
+
+// This item can be used as a layer effect.
+// The purpose of this item is to apply an effect to a partial
+// area of an item without re-rendering the source item multiple
+// times.
+Item {
+    id: root
+
+    // source must be a texture provider Item.
+    // If layer is enabled, the source (parent) will be a texture provider
+    // and automatically set by Qt.
+    // Some items, such as Image and ShaderEffectSource can be implicitly
+    // a texture provider without creating an extra layer.
+    // Make sure that the sampler name is set to "source" (default) if
+    // this is used as a layer effect.
+    property Item source
+
+    // Default layer properties are used except that `enabled` is set by default.
+    // The geometry of the effect will be adjusted to `effectRect` automatically.
+    property alias effectLayer: effectProxy.layer
+
+    // Rectangular area where the effect should be applied:
+    property alias effectRect: effectProxy.effectRect
+
+    // Enable blending if background of source is not opaque.
+    // This comes with a performance penalty.
+    property alias blending: sourceProxy.blending
+
+    // This item displays the item with the rect denoted by effectRect
+    // being transparent (only when blending is set):
+    ShaderEffect {
+        id: sourceProxy
+
+        anchors.fill: parent
+
+        blending: false
+
+        property alias source: root.source
+
+        readonly property rect discardRect: {
+            if (blending)
+                return Qt.rect(effectProxy.x / root.width,
+                               effectProxy.y / root.height,
+                               (effectProxy.x + effectProxy.width) / root.width,
+                               (effectProxy.y + effectProxy.height) / root.height)
+            else // If blending is not enabled, no need to make the normalization calculations
+                return Qt.rect(0, 0, 0, 0)
+        }
+
+        cullMode: ShaderEffect.BackFaceCulling
+
+        // Simple filter that is only enabled when blending is active.
+        // We do not want the source to be rendered below the frosted glass effect.
+        // NOTE: It might be a better idea to enable this at all times if texture sampling
+        //       is costlier than branching.
+        fragmentShader: blending ? "
+                varying highp vec2 qt_TexCoord0;
+
+                uniform lowp sampler2D source;
+                uniform lowp float qt_Opacity;
+                uniform highp vec4 discardRect;
+
+                void main() {
+                    if (((qt_TexCoord0.x >= discardRect.x && qt_TexCoord0.x <= discardRect.w) &&
+                        (qt_TexCoord0.y >= discardRect.y && qt_TexCoord0.y <= discardRect.z)))
+                      discard;
+
+                    highp vec4 texel = texture2D(source, qt_TexCoord0);
+
+                    gl_FragColor = texel * qt_Opacity;
+                }" : ""
+    }
+
+    // This item represents the region where the effect is applied.
+    // `effectLayer` only has access to the area denoted with
+    // the property `effectRect`
+    ShaderEffect {
+        id: effectProxy
+
+        x: effectRect.x
+        y: effectRect.y
+        width: effectRect.width
+        height: effectRect.height
+
+        blending: root.blending
+
+        // This item is used to show effect
+        // so it is pointless to show if
+        // there is no effect to show.
+        visible: layer.enabled
+
+        // cullMode: ShaderEffect.BackFaceCulling
+
+        property rect effectRect
+
+        property alias source: root.source
+
+        readonly property rect normalEffectRect: Qt.rect(effectRect.x / root.width,
+                                                         effectRect.y / root.height,
+                                                         effectRect.width / root.width,
+                                                         effectRect.height / root.height)
+
+        vertexShader: "
+            uniform highp mat4 qt_Matrix;
+            uniform highp vec4 normalEffectRect;
+
+            attribute highp vec4 qt_Vertex;
+            attribute highp vec2 qt_MultiTexCoord0;
+
+            varying highp vec2 qt_TexCoord0;
+
+            void main() {
+                qt_TexCoord0 = normalEffectRect.xy + normalEffectRect.zw * qt_MultiTexCoord0;
+                gl_Position = qt_Matrix * qt_Vertex;
+            }"
+
+        layer.enabled: layer.effect
+    }
+}



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3a174676a3526236f964bec7f635c71076d77c3f...d6829a7037783ab24cf511e4a55a4178e85b49af

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3a174676a3526236f964bec7f635c71076d77c3f...d6829a7037783ab24cf511e4a55a4178e85b49af
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list