[vlc-commits] [Git][videolan/vlc][master] 9 commits: qt: introduce `BackdropBlendItem`

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Tue Nov 24 16:10:43 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
7664971c by Pierre Lamot at 2026-11-24T16:52:36+01:00
qt: introduce `BackdropBlendItem`

This is a base class for items that replace what is rendered beneath them
with a color, weighted by a coverage computed by a custom fragment shader:

    dst = color * coverage + dst * (1 - coverage)

The color is passed as blend constant, so that this can be done in a single
pass with a fixed blending state, including for the alpha channel. Where the
coverage is 1, the color is written as is, similar to `ViewBlockingRectangle`,
but with partial coverage (anti-aliasing, gradients) being supported.

Subclasses only provide the fragment shader and the values of their uniforms,
the material, the material shader and the vertex shader are shared.

- - - - -
84e88988 by Pierre Lamot at 2026-11-24T16:52:36+01:00
qml: fix rounded corner of the central content when the background is not plain

Rather than having a ViewBlockingRectangle + a Rounded Rectangle on top of it,
here we create an ad-hoc item that will implement the ViewBlocking pixel forced
transparency and the rounded part as a single pass.

fix:  #30176

- - - - -
0d3f5dd3 by Pierre Lamot at 2026-11-24T16:52:36+01:00
qt: introduce `FadingEdgeMask`

This item fades what is rendered beneath it into a color, starting from
one of its edges.

With an opaque color, this is equivalent to a gradient rectangle from the
color to transparent. With a translucent color, the content is faded into
the color rather than being blended over by it, which gives the correct
result when the content is on top of a uniform translucent background
(such as the acrylic background), without needing layering.

Co-authored-by: Fatih Uzunoglu <fuzun54 at outlook.com>

- - - - -
b87edafb by Pierre Lamot at 2026-11-24T16:52:36+01:00
qml: use `FadingEdgeMask` in `FadingEdge`

It replaces the gradient rectangles used when the background is opaque,
which gives the same result.

Note that `FadingEdgeMask` requires RHI, without it the fading edge effect
is no longer shown, as it is already the case when layering would be used.

- - - - -
ad28bd13 by Pierre Lamot at 2026-11-24T16:52:36+01:00
qml: introduce optimization hint `FadingEdge::uniformBackdrop`

When the background color is not opaque, but there is nothing beneath
it that the content needs to blend in to, `FadingEdgeMask` can be used
instead of layering, which lowers video memory consumption.

Co-authored-by: Fatih Uzunoglu <fuzun54 at outlook.com>

- - - - -
ae767d7c by Fatih Uzunoglu at 2026-11-24T16:52:36+01:00
qml: care about `FadingEdge::uniformBackdrop` in `PlaylistPane`

- - - - -
34d034cd by Fatih Uzunoglu at 2026-11-24T16:52:36+01:00
qml: care about `FadingEdge::uniformBackdrop` in `SideNavigationPane`

- - - - -
b88b7b61 by Fatih Uzunoglu at 2026-11-24T16:52:36+01:00
qml: expose the view in `SideNavigationPane`

We can do this since content item is not meant
to be modified here.

- - - - -
d3f8b7af by Fatih Uzunoglu at 2026-11-24T16:52:36+01:00
qml: set `FadingEdge::uniformBackdrop` when applicable in `MainDisplay`

- - - - -


17 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/maininterface/qml/SideNavigationPane.qml
- modules/gui/qt/meson.build
- modules/gui/qt/playlist/qml/PlaylistPane.qml
- + modules/gui/qt/shaders/Arc.frag
- + modules/gui/qt/shaders/BackdropBlend.vert
- + modules/gui/qt/shaders/FadingEdgeMask.frag
- modules/gui/qt/shaders/meson.build
- + modules/gui/qt/widgets/native/backdropblenditem.cpp
- + modules/gui/qt/widgets/native/backdropblenditem.hpp
- + modules/gui/qt/widgets/native/fadingedgemask.cpp
- + modules/gui/qt/widgets/native/fadingedgemask.hpp
- + modules/gui/qt/widgets/native/roundedcornermask.cpp
- + modules/gui/qt/widgets/native/roundedcornermask.hpp
- modules/gui/qt/widgets/qml/FadingEdge.qml


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -381,7 +381,10 @@ libqt_plugin_la_SOURCES = \
 	widgets/native/qvlcframe.cpp \
 	widgets/native/qvlcframe.hpp \
 	widgets/native/searchlineedit.cpp widgets/native/searchlineedit.hpp \
-	widgets/native/viewblockingrectangle.cpp widgets/native/viewblockingrectangle.hpp
+	widgets/native/viewblockingrectangle.cpp widgets/native/viewblockingrectangle.hpp \
+	widgets/native/backdropblenditem.cpp widgets/native/backdropblenditem.hpp \
+	widgets/native/roundedcornermask.cpp widgets/native/roundedcornermask.hpp \
+	widgets/native/fadingedgemask.cpp widgets/native/fadingedgemask.hpp
 
 # Meta-object compilation
 
@@ -537,7 +540,10 @@ nodist_libqt_plugin_la_SOURCES = \
 	widgets/native/navigation_attached.moc.cpp \
 	widgets/native/mlfolderseditor.moc.cpp \
 	widgets/native/searchlineedit.moc.cpp \
-	widgets/native/viewblockingrectangle.moc.cpp
+	widgets/native/viewblockingrectangle.moc.cpp \
+	widgets/native/backdropblenditem.moc.cpp \
+	widgets/native/roundedcornermask.moc.cpp \
+	widgets/native/fadingedgemask.moc.cpp
 
 nodist_libqt_plugin_la_SOURCES += \
 	dialogs/extended/ui_equalizer.h \
@@ -1472,11 +1478,14 @@ libqt_plugin_la_SHADER_FRAG = shaders/FadingEdge.frag \
                               shaders/VoronoiSnow.frag \
                               shaders/DualKawaseBlur_upsample.frag \
                               shaders/DualKawaseBlur_downsample.frag \
-                              shaders/DualKawaseBlur_upsample_postprocess.frag
+                              shaders/DualKawaseBlur_upsample_postprocess.frag \
+                              shaders/Arc.frag \
+                              shaders/FadingEdgeMask.frag
 
 libqt_plugin_la_SHADER_VERT = shaders/FadingEdgeX.vert \
                               shaders/FadingEdgeY.vert \
-                              shaders/SubTexture.vert
+                              shaders/SubTexture.vert \
+                              shaders/BackdropBlend.vert
 
 libqt_plugin_la_SHADER = $(libqt_plugin_la_SHADER_FRAG) $(libqt_plugin_la_SHADER_VERT)
 


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -77,6 +77,8 @@
 #include "widgets/native/csdthemeimage.hpp"
 #include "widgets/native/navigation_attached.hpp"
 #include "widgets/native/viewblockingrectangle.hpp"
+#include "widgets/native/roundedcornermask.hpp"
+#include "widgets/native/fadingedgemask.hpp"
 
 #include "videosurface.hpp"
 #include "mainctx.hpp"
@@ -438,6 +440,8 @@ void MainUI::registerQMLTypes()
         // @uri VLC.Widgets
         qmlRegisterType<CSDThemeImage>(uri, versionMajor, versionMinor, "CSDThemeImage");
         qmlRegisterType<ViewBlockingRectangle>( uri, versionMajor, versionMinor, "ViewBlockingRectangle" );
+        qmlRegisterTypesAndRevisions<RoundedCornerMask>( uri, versionMajor );
+        qmlRegisterTypesAndRevisions<FadingEdgeMask>( uri, versionMajor );
         qmlRegisterTypesAndRevisions<PointingToolTipAttached>( uri, versionMajor );
 
         qmlRegisterModule(uri, versionMajor, versionMinor);


=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -497,37 +497,23 @@ FocusScope {
                 rightPadding: playlistLoader.shown ? 0 : VLCStyle.applicationHorizontalMargin
 
                 // Top-left corner rounding:
-                Widgets.AcrylicBackground {
+                // `RoundedCornerMask` replaces the area outside of the arc with anti-aliasing,
+                // regardless of the page content, but it requires RHI. Otherwise, we don't draw the rounded corner
+                Widgets.RoundedCornerMask {
                     id: topLeftCornerBackground
 
-                    z: 99
-                    color: sidebar.background.color
-                    visible: sidebar.visible && (stackViewTopLeftRadiusRectangle.topLeftRadius !== undefined)
-
                     anchors.left: stackView.left
-                    anchors.leftMargin: -1
+                    anchors.leftMargin: 0
                     anchors.top: stackView.top
 
-                    // (-1) is to prevent seams
-                    width: stackViewTopLeftRadiusRectangle.width - 1
-                    height: stackViewTopLeftRadiusRectangle.height - 1
-
-                    Rectangle {
-                        id: stackViewTopLeftRadiusRectangle
-
-                        width: (stackViewTopLeftRadiusRectangle.topLeftRadius * 2)
-                        height: (stackViewTopLeftRadiusRectangle.topLeftRadius * 2)
-
-                        anchors.top: parent.top
-                        anchors.left: parent.left
-                        anchors.leftMargin: 1
+                    z: 99
 
-                        color: stackViewParent.color
+                    width: VLCStyle.mainView_topLeftRadius
+                    height: VLCStyle.mainView_topLeftRadius
 
-                        property real implicitTopLeftRadius: VLCStyle.mainView_topLeftRadius
+                    visible: supported && sidebar.visible
 
-                        topLeftRadius: implicitTopLeftRadius
-                    }
+                    color: sidebar.background.color
                 }
 
                 onCurrentItemChanged: {
@@ -620,6 +606,8 @@ FocusScope {
 
             readonly property bool needExternalBackgroundProvider: (visible && !background?.visible)
 
+            view.fadingEdge.uniformBackdrop: useAcrylic
+
             NavigationBarContextMenu {
                 id: navigationBarContextMenu
 
@@ -802,6 +790,7 @@ FocusScope {
                 useAcrylic: !VLCStyle.isScreenSmall
 
                 view.fadingEdge.pixelAlignedForDPR: !miniPlayer.visible
+                view.fadingEdge.uniformBackdrop: useAcrylic
 
                 // Otherwise `stackViewParent`'s layer effect becomes the background provider
                 background.visible: useAcrylic || (!MainCtx.backdropBlurRequested() || (GraphicsInfo.shaderType !== GraphicsInfo.RhiShader))


=====================================
modules/gui/qt/maininterface/qml/SideNavigationPane.qml
=====================================
@@ -44,6 +44,8 @@ T.Pane {
 
     property alias model: navigationModel
 
+    property alias view: listView
+
     readonly property int minimumWidth: VLCStyle.expandNavigationPaneWidth + safeAreaLeftMargin + safeAreaRightMargin
 
     implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
@@ -122,8 +124,8 @@ T.Pane {
 
                 colorContext.colorSet: ColorContext.Window
 
-                fadingEdge.backgroundColor:  (root.background && root.background.visible && (root.background.color.a >= 1.0)) ? root.background.color
-                                                                                                                              : "transparent"
+                fadingEdge.backgroundColor:  (root.background && root.background.visible && (root.background.color.a >= 1.0 || fadingEdge.uniformBackdrop)) ? root.background.color
+                                                                                                                                                            : "transparent"
 
                 component DelegateAnimation : NumberAnimation {
                     easing.type: Easing.InOutSine


=====================================
modules/gui/qt/meson.build
=====================================
@@ -167,6 +167,9 @@ moc_headers = files(
     'widgets/native/mlfolderseditor.hpp',
     'widgets/native/searchlineedit.hpp',
     'widgets/native/viewblockingrectangle.hpp',
+    'widgets/native/backdropblenditem.hpp',
+    'widgets/native/roundedcornermask.hpp',
+    'widgets/native/fadingedgemask.hpp',
 )
 
 if host_system == 'windows'
@@ -535,6 +538,12 @@ qt_plugin_sources = files(
     'widgets/native/searchlineedit.hpp',
     'widgets/native/viewblockingrectangle.cpp',
     'widgets/native/viewblockingrectangle.hpp',
+    'widgets/native/backdropblenditem.cpp',
+    'widgets/native/backdropblenditem.hpp',
+    'widgets/native/roundedcornermask.cpp',
+    'widgets/native/roundedcornermask.hpp',
+    'widgets/native/fadingedgemask.cpp',
+    'widgets/native/fadingedgemask.hpp',
 )
 
 if host_system == 'windows'


=====================================
modules/gui/qt/playlist/qml/PlaylistPane.qml
=====================================
@@ -375,8 +375,8 @@ T.Pane {
                 }
             }
 
-            fadingEdge.backgroundColor: (root.background && root.background.visible && (root.background.color.a >= 1.0)) ? root.background.color
-                                                                                                                         : Qt.alpha(root.background.color, 0.0)
+            fadingEdge.backgroundColor: (root.background && root.background.visible && (root.background.color.a >= 1.0 || fadingEdge.uniformBackdrop)) ? root.background.color
+                                                                                                                                                       : Qt.alpha(root.background.color, 0.0)
 
             function mappedSelectedIndexes() : var {
                 let mappedSelectedIndexes


=====================================
modules/gui/qt/shaders/Arc.frag
=====================================
@@ -0,0 +1,45 @@
+#version 440
+
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+// See `RoundedCornerMask` and `BackdropBlendItem`.
+
+layout(location = 0) in vec2 coord;
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+    mat4 qt_Matrix;
+    float qt_Opacity;
+    float flipX; // 1.0 for right corners
+    float flipY; // 1.0 for bottom corners
+};
+
+void main()
+{
+    // Mirror the position so that the corner is always at the origin:
+    vec2 pos = mix(coord, vec2(1.0) - coord, vec2(flipX, flipY));
+
+    float dist = length(pos - vec2(1.0)) - 1.0; // > 0 outside the arc
+
+    // Anti-aliasing over one device pixel:
+    float aa = max(fwidth(dist), 1e-4);
+    float coverage = clamp(dist / aa + 0.5, 0.0, 1.0);
+
+    fragColor = vec4(coverage * qt_Opacity);
+}


=====================================
modules/gui/qt/shaders/BackdropBlend.vert
=====================================
@@ -0,0 +1,40 @@
+#version 440
+
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+// Shared vertex shader of `BackdropBlendItem` subclasses.
+
+layout(location = 0) in vec4 qt_Vertex;
+layout(location = 1) in vec2 qt_MultiTexCoord0;
+
+// Position in item coordinates:
+layout(location = 0) out vec2 coord;
+
+// Only the common part of the uniform block is declared here, the
+// fragment shaders declare the full block (see `BackdropBlendItem`):
+layout(std140, binding = 0) uniform qt_buf {
+    mat4 qt_Matrix;
+    float qt_Opacity;
+} qt_ubuf; // must use a name that does not clash with the fragment shader
+
+void main()
+{
+    coord = qt_MultiTexCoord0;
+    gl_Position = qt_ubuf.qt_Matrix * qt_Vertex;
+}


=====================================
modules/gui/qt/shaders/FadingEdgeMask.frag
=====================================
@@ -0,0 +1,53 @@
+#version 440
+
+#define DITHERING
+
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+// See `FadingEdgeMask` and `BackdropBlendItem`.
+
+#extension GL_GOOGLE_include_directive : enable
+
+#include "Common.glsl"
+
+layout(location = 0) in vec2 coord;
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+    mat4 qt_Matrix;
+    float qt_Opacity;
+    float vertical; // 1.0 for top and bottom edges
+    float flip;     // 1.0 for bottom and right edges
+};
+
+void main()
+{
+    float pos = mix(coord.x, coord.y, vertical);
+    pos = mix(pos, 1.0 - pos, flip);
+
+    // 1.0 at the edge, 0.0 at the opposite edge:
+    float coverage = 1.0 - smoothstep(0.0, 1.0, pos);
+
+    fragColor = vec4(coverage * qt_Opacity);
+
+#ifdef DITHERING
+    float noise = (rand(coord) - 0.5) * DITHERING_STRENGTH;
+    fragColor = clamp(fragColor + vec4(noise) * step(DITHERING_CUTOFF, fragColor.a), 0.0, 1.0);
+#endif
+}


=====================================
modules/gui/qt/shaders/meson.build
=====================================
@@ -24,6 +24,9 @@ shader_sources = [
     'DualKawaseBlur_downsample.frag',
     'DualKawaseBlur_upsample.frag',
     'DualKawaseBlur_upsample_postprocess.frag',
+    'BackdropBlend.vert',
+    'Arc.frag',
+    'FadingEdgeMask.frag',
 ]
 
 shader_files = files(shader_sources)


=====================================
modules/gui/qt/widgets/native/backdropblenditem.cpp
=====================================
@@ -0,0 +1,256 @@
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+#include "backdropblenditem.hpp"
+
+#include <QQuickWindow>
+#include <QSGGeometryNode>
+#include <QSGMaterial>
+#include <QSGMaterialShader>
+#include <QSGRendererInterface>
+
+#include <cstring>
+
+namespace {
+
+class BackdropBlendMaterial : public QSGMaterial
+{
+public:
+    BackdropBlendMaterial(QSGMaterialType *type, const QString& fragmentShader)
+        : m_type(type)
+        , m_fragmentShader(fragmentShader)
+    {
+        // This puts the node in the alpha pass, which is rendered after the
+        // opaque pass and in back to front order. This is necessary so that
+        // the content below is already rendered when this node is rendered:
+        setFlag(QSGMaterial::Blending);
+    }
+
+    QSGMaterialType *type() const override
+    {
+        return m_type;
+    }
+
+    QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override;
+
+    int compare(const QSGMaterial *other) const override
+    {
+        const auto o = static_cast<const BackdropBlendMaterial *>(other);
+
+        // The color is part of the pipeline state (blend constant):
+        const QRgb a = m_color.rgba();
+        const QRgb b = o->m_color.rgba();
+        if (a != b)
+            return (a < b) ? -1 : 1;
+
+        if (m_uniforms.size() != o->m_uniforms.size())
+            return (m_uniforms.size() < o->m_uniforms.size()) ? -1 : 1;
+
+        for (qsizetype i = 0; i < m_uniforms.size(); ++i)
+        {
+            if (m_uniforms[i] != o->m_uniforms[i])
+                return (m_uniforms[i] < o->m_uniforms[i]) ? -1 : 1;
+        }
+
+        return 0;
+    }
+
+    QSGMaterialType *const m_type;
+    const QString m_fragmentShader;
+
+    QColor m_color {Qt::transparent};
+    QVector<float> m_uniforms;
+};
+
+class BackdropBlendMaterialShader : public QSGMaterialShader
+{
+public:
+    explicit BackdropBlendMaterialShader(const QString& fragmentShader)
+    {
+        setShaderFileName(VertexStage, QStringLiteral(":/shaders/BackdropBlend.vert.qsb"));
+        setShaderFileName(FragmentStage, fragmentShader);
+        setFlag(UpdatesGraphicsPipelineState);
+    }
+
+    bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
+    {
+        const auto material = static_cast<BackdropBlendMaterial *>(newMaterial);
+        const auto old = static_cast<BackdropBlendMaterial *>(oldMaterial);
+
+        QByteArray *buf = state.uniformData();
+
+        bool changed = false;
+
+        if (state.isMatrixDirty())
+        {
+            const QMatrix4x4 m = state.combinedMatrix();
+            assert(buf->size() >= 64);
+            memcpy(buf->data(), m.constData(), 64);
+            changed = true;
+        }
+
+        if (state.isOpacityDirty())
+        {
+            const float opacity = state.opacity();
+            assert(buf->size() >= 68);
+            memcpy(buf->data() + 64, &opacity, 4);
+            changed = true;
+        }
+
+        if (!old || old->m_uniforms != material->m_uniforms)
+        {
+            // Consecutive floats are tightly packed with std140:
+            const qsizetype size = material->m_uniforms.size() * sizeof(float);
+            assert(buf->size() >= 68 + size);
+            memcpy(buf->data() + 68, material->m_uniforms.constData(), size);
+            changed = true;
+        }
+
+        return changed;
+    }
+
+    bool updateGraphicsPipelineState(RenderState &, GraphicsPipelineState *ps,
+                                     QSGMaterial *newMaterial, QSGMaterial *) override
+    {
+        const auto material = static_cast<BackdropBlendMaterial *>(newMaterial);
+
+        bool changeMade = false;
+
+        // `dst = constant * src + dst * (1 - src)`, where the fragment shader
+        // outputs the same value (coverage) in all the channels. Using the
+        // same factors for the alpha channel is intended:
+        if (!ps->blendEnable)
+        {
+            ps->blendEnable = true;
+            changeMade = true;
+        }
+
+        if (Q_LIKELY(ps->srcColor != GraphicsPipelineState::ConstantColor))
+        {
+            ps->srcColor = GraphicsPipelineState::ConstantColor;
+            changeMade = true;
+        }
+
+        if (Q_LIKELY(ps->dstColor != GraphicsPipelineState::OneMinusSrcColor))
+        {
+            ps->dstColor = GraphicsPipelineState::OneMinusSrcColor;
+            changeMade = true;
+        }
+
+        const QColor color = material->m_color.toRgb();
+        const float alpha = color.alphaF();
+        const QColor blendConstant = QColor::fromRgbF(color.redF() * alpha,
+                                                      color.greenF() * alpha,
+                                                      color.blueF() * alpha,
+                                                      alpha);
+        if (Q_LIKELY(ps->blendConstant != blendConstant))
+        {
+            ps->blendConstant = blendConstant;
+            changeMade = true;
+        }
+
+        return changeMade;
+    }
+};
+
+QSGMaterialShader *BackdropBlendMaterial::createShader(QSGRendererInterface::RenderMode) const
+{
+    return new BackdropBlendMaterialShader(m_fragmentShader);
+}
+
+} // anonymous namespace
+
+BackdropBlendItem::BackdropBlendItem(QQuickItem *parent)
+    : QQuickItem(parent)
+{
+    setFlag(QQuickItem::ItemHasContents);
+    connect(this, &QQuickItem::windowChanged, this, &BackdropBlendItem::updateSupported);
+
+    connect(this, &QQuickItem::widthChanged, this, &BackdropBlendItem::markDirtyGeometry);
+    connect(this, &QQuickItem::heightChanged, this, &BackdropBlendItem::markDirtyGeometry);
+}
+
+void BackdropBlendItem::setColor(const QColor& color)
+{
+    if (m_color == color)
+        return;
+    m_color = color;
+    emit colorChanged();
+    update();
+}
+
+void BackdropBlendItem::updateSupported()
+{
+    const QQuickWindow* const w = window();
+    const bool supported = w && w->rendererInterface() &&
+                           QSGRendererInterface::isApiRhiBased(w->rendererInterface()->graphicsApi());
+
+    if (m_supported == supported)
+        return;
+    m_supported = supported;
+    emit supportedChanged();
+}
+
+QSGNode *BackdropBlendItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+{
+    auto node = static_cast<QSGGeometryNode *>(oldNode);
+
+    const QRectF rect = boundingRect();
+    const QRectF text = QRectF(0.0, 0.0, 1.0, 1.0);
+
+    if (!m_supported || rect.isEmpty())
+    {
+        delete node;
+        return nullptr;
+    }
+
+    if (!node)
+    {
+        node = new QSGGeometryNode;
+
+        auto geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4);
+        geometry->setVertexDataPattern(QSGGeometry::DynamicPattern);
+
+        node->setGeometry(geometry);
+        node->setFlag(QSGNode::OwnsGeometry);
+
+        node->setMaterial(new BackdropBlendMaterial(materialType(), fragmentShader()));
+        node->setFlag(QSGNode::OwnsMaterial);
+    }
+
+    // The vertex position may be transformed by the renderer when batching,
+    // so the position in item coordinates is also passed as texture coordinate:
+    if (m_dirtyGeometry)
+    {
+        QSGGeometry::updateTexturedRectGeometry(node->geometry(), rect, text);
+        node->geometry()->markVertexDataDirty();
+        node->markDirty(QSGNode::DirtyGeometry);
+        m_dirtyGeometry = false;
+    }
+
+    const auto material = static_cast<BackdropBlendMaterial *>(node->material());
+    QVector<float> values = uniforms();
+    if (material->m_color != m_color || material->m_uniforms != values)
+    {
+        material->m_color = m_color;
+        material->m_uniforms = std::move(values);
+        node->markDirty(QSGNode::DirtyMaterial);
+    }
+
+    return node;
+}


=====================================
modules/gui/qt/widgets/native/backdropblenditem.hpp
=====================================
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+#ifndef BACKDROPBLENDITEM_HPP
+#define BACKDROPBLENDITEM_HPP
+
+#include <QQuickItem>
+#include <QColor>
+#include <QVector>
+
+class QSGMaterialType;
+
+// Base class for items that replace what is rendered beneath them with `color`,
+// weighted by a coverage computed by the fragment shader of the subclass:
+//
+//     dst = color * coverage + dst * (1 - coverage)
+//
+// This is done in all the channels, including the alpha channel. Where coverage
+// is 1, the color is written as is (akin to `ViewBlockingRectangle`, it is not
+// blended over what is beneath). Where coverage is 0, nothing is changed. This
+// allows masking arbitrary content without rendering it into an intermediate
+// texture, as long as this item is rendered after (above) the content.
+//
+// The color is provided to the graphics pipeline as blend constant, the fragment
+// shader only outputs the coverage (multiplied by `qt_Opacity`) in all channels.
+//
+// Fragment shaders get the position in item coordinates (`coord`, at location 0)
+// from `BackdropBlend.vert`, and must declare the following uniform block, where
+// the members following `qt_Opacity` are the values returned by `uniforms()`:
+//
+//     layout(std140, binding = 0) uniform buf {
+//         mat4 qt_Matrix;
+//         float qt_Opacity;
+//         float ...;
+//     };
+//
+// This item requires a RHI based scene graph adaptation, nothing is rendered
+// otherwise (see `supported`).
+class BackdropBlendItem : public QQuickItem
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
+
+    Q_PROPERTY(bool supported READ supported NOTIFY supportedChanged FINAL)
+
+public:
+    explicit BackdropBlendItem(QQuickItem *parent = nullptr);
+
+    QColor color() const { return m_color; }
+    void setColor(const QColor& color);
+
+    bool supported() const { return m_supported; }
+
+protected:
+    // The material type must be unique per fragment shader:
+    virtual QSGMaterialType *materialType() const = 0;
+    virtual QString fragmentShader() const = 0;
+    // Values of the uniform block members following `qt_Opacity`, in order.
+    // Called from the rendering thread, while the GUI thread is blocked.
+    // Call `update()` when they change:
+    virtual QVector<float> uniforms() const { return {}; };
+
+    QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
+
+private:
+    void updateSupported();
+
+    // We should not need to schedule update ourselves by calling
+    // `::update()`, Qt should do it implicitly with width/height
+    // change:
+    void markDirtyGeometry() { m_dirtyGeometry = true; }
+
+    QColor m_color {Qt::transparent};
+    bool m_supported = false;
+
+    bool m_dirtyGeometry = true;
+
+signals:
+    void colorChanged();
+    void supportedChanged();
+};
+
+#endif


=====================================
modules/gui/qt/widgets/native/fadingedgemask.cpp
=====================================
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+#include "fadingedgemask.hpp"
+
+#include <QSGMaterial>
+
+void FadingEdgeMask::setEdge(Qt::Edge edge)
+{
+    if (m_edge == edge)
+        return;
+    m_edge = edge;
+    emit edgeChanged();
+    update();
+}
+
+QSGMaterialType *FadingEdgeMask::materialType() const
+{
+    static QSGMaterialType type;
+    return &type;
+}
+
+QString FadingEdgeMask::fragmentShader() const
+{
+    return QStringLiteral(":/shaders/FadingEdgeMask.frag.qsb");
+}
+
+QVector<float> FadingEdgeMask::uniforms() const
+{
+    const bool vertical = (m_edge == Qt::TopEdge || m_edge == Qt::BottomEdge);
+    const bool flip = (m_edge == Qt::BottomEdge || m_edge == Qt::RightEdge);
+
+    return { vertical ? 1.f : 0.f,
+             flip ? 1.f : 0.f };
+}


=====================================
modules/gui/qt/widgets/native/fadingedgemask.hpp
=====================================
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+#ifndef FADINGEDGEMASK_HPP
+#define FADINGEDGEMASK_HPP
+
+#include "backdropblenditem.hpp"
+
+// This item fades what is rendered beneath it into `color`, from the `edge`
+// where `color` fully replaces the content, to the opposite edge where the
+// content is left untouched (see `BackdropBlendItem`).
+//
+// When `color` is opaque, this is equivalent to a gradient rectangle from
+// `color` to transparent. When it is not opaque, the content is faded into
+// the color (as opposed to being blended over by it), this means that the
+// result is correct if what is beneath the content is `color` itself, such as
+// when the content is on top of a uniform translucent background.
+class FadingEdgeMask : public BackdropBlendItem
+{
+    Q_OBJECT
+
+    QML_ELEMENT
+
+    Q_PROPERTY(Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged FINAL)
+
+public:
+    using BackdropBlendItem::BackdropBlendItem;
+
+    Qt::Edge edge() const { return m_edge; }
+    void setEdge(Qt::Edge edge);
+
+protected:
+    QSGMaterialType *materialType() const override;
+    QString fragmentShader() const override;
+    QVector<float> uniforms() const override;
+
+private:
+    Qt::Edge m_edge = Qt::TopEdge;
+
+signals:
+    void edgeChanged();
+};
+
+#endif


=====================================
modules/gui/qt/widgets/native/roundedcornermask.cpp
=====================================
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+#include "roundedcornermask.hpp"
+
+#include <QSGMaterial>
+
+void RoundedCornerMask::setCorner(Qt::Corner corner)
+{
+    if (m_corner == corner)
+        return;
+    m_corner = corner;
+    emit cornerChanged();
+    update();
+}
+
+QSGMaterialType *RoundedCornerMask::materialType() const
+{
+    static QSGMaterialType type;
+    return &type;
+}
+
+QString RoundedCornerMask::fragmentShader() const
+{
+    return QStringLiteral(":/shaders/Arc.frag.qsb");
+}
+
+QVector<float> RoundedCornerMask::uniforms() const
+{
+    const bool right = (m_corner == Qt::TopRightCorner || m_corner == Qt::BottomRightCorner);
+    const bool bottom = (m_corner == Qt::BottomLeftCorner || m_corner == Qt::BottomRightCorner);
+
+    return { right ? 1.f : 0.f,
+             bottom ? 1.f : 0.f };
+}


=====================================
modules/gui/qt/widgets/native/roundedcornermask.hpp
=====================================
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (C) 2026 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.
+ *****************************************************************************/
+
+#ifndef ROUNDEDCORNERMASK_HPP
+#define ROUNDEDCORNERMASK_HPP
+
+#include "backdropblenditem.hpp"
+
+// This item replaces the area outside of a rounded corner arc with `color`,
+// with anti-aliasing at the arc edge (see `BackdropBlendItem`). This allows
+// rounding the corner of arbitrary content without rendering it into an
+// intermediate texture, as long as this item is rendered after (above) the
+// content.
+//
+// The item is expected to be square, its size being the radius of the arc. The
+// arc center is placed at the opposite of the `corner` of the item.
+class RoundedCornerMask : public BackdropBlendItem
+{
+    Q_OBJECT
+
+    QML_ELEMENT
+
+    Q_PROPERTY(Qt::Corner corner READ corner WRITE setCorner NOTIFY cornerChanged FINAL)
+
+public:
+    using BackdropBlendItem::BackdropBlendItem;
+
+    Qt::Corner corner() const { return m_corner; }
+    void setCorner(Qt::Corner corner);
+
+protected:
+    QSGMaterialType *materialType() const override;
+    QString fragmentShader() const override;
+    QVector<float> uniforms() const override;
+
+private:
+    Qt::Corner m_corner = Qt::TopLeftCorner;
+
+signals:
+    void cornerChanged();
+};
+
+#endif


=====================================
modules/gui/qt/widgets/qml/FadingEdge.qml
=====================================
@@ -21,6 +21,7 @@ import QtQuick.Window
 import VLC.MainInterface
 import VLC.Style
 import VLC.Util
+import VLC.Widgets
 
 Item {
     id: root
@@ -32,6 +33,17 @@ Item {
     // which results lower memory consumption:
     property alias backgroundColor: backgroundRect.color
 
+    // Set this property to `true` if beneath the
+    // target Qt Quick Scene has uniform background.
+    // In other words, when background color is not
+    // opaque, but it has nothing to blend in to.
+    // This is an optimization hint that eliminates
+    // layering, which helps lowering video memory
+    // consumption. This property does not have an
+    // effect if `enforceClipping` is set, since then
+    // layering is necessary:
+    property bool uniformBackdrop: false
+
     property Item sourceItem
 
     property real beginningMargin
@@ -56,13 +68,14 @@ Item {
     // size intended, which may increase greatly depending on the fraction
     // of the display scale. Also note that if the QML item size is fractional
     // itself, it is ceiled regardless of the display scale or this property.
+    // This property is not relevant when `useLayering` is not set.
     property bool pixelAlignedForDPR: true
 
     readonly property bool effectCompatible: (GraphicsInfo.shaderType === GraphicsInfo.RhiShader)
 
     readonly property bool implicitClipping: !!_shaderEffect?.visible
 
-    property bool useLayering: effectCompatible && (enforceClipping || backgroundColor.a < 1.0)
+    property bool useLayering: effectCompatible && (enforceClipping || (!uniformBackdrop && backgroundColor.a < 1.0))
 
     // Sometimes `Item::clip` may not be suitable to use with item views,
     // this includes, but not limited to, when display margins are set.
@@ -109,19 +122,21 @@ Item {
         visible: !!root._shaderEffectSource?.visible && (color.a > 0.0)
     }
 
-    // Fading edge effect provider when background is opaque:
-    // This is an optimization, because layering is not used.
-    component FadingEdgeRectangleForOpaqueBackground : Rectangle {
-        id: fadingEdgeRectangle
+    // Fading edge effect provider when layering is not used:
+    // This is an optimization, as layering requires an intermediate texture.
+    component FadingEdgeMaskForBackground : FadingEdgeMask {
+        id: fadingEdgeMask
 
         implicitHeight: root.fadeSize
         implicitWidth: root.fadeSize
 
-        visible: (opacity > 0.0 || enabled) && !root.useLayering
+        visible: supported && (opacity > 0.0 || enabled) && !root.useLayering
 
         opacity: enabled ? 1.0 : 0.0
 
-        // Animating opacity is expected to be less expensive than animating gradient stop.
+        color: root.backgroundColor
+
+        // Animating opacity is expected to be less expensive than updating the uniforms.
         Behavior on opacity {
             id: opacityBehavior
 
@@ -138,18 +153,7 @@ Item {
             // This is used to prevent animating at initialization:
             MainCtx.setTimeout(() => {
                 opacityBehavior.enabled = true
-            }, 50, [], fadingEdgeRectangle)
-        }
-
-        required property color colorStop0
-        required property color colorStop1
-
-        gradient: Gradient {
-            orientation: (root.orientation === Qt.Horizontal) ? Gradient.Horizontal
-                                                              : Gradient.Vertical
-
-            GradientStop { position: 0.0; color: fadingEdgeRectangle.colorStop0; }
-            GradientStop { position: 1.0; color: fadingEdgeRectangle.colorStop1; }
+            }, 50, [], fadingEdgeMask)
         }
     }
 
@@ -164,7 +168,7 @@ Item {
             bottomMargin: (root.orientation === Qt.Vertical ? -root.endMargin : 0)
         }
 
-        FadingEdgeRectangleForOpaqueBackground {
+        FadingEdgeMaskForBackground {
             anchors {
                 top: parent.top
                 left: parent.left
@@ -174,11 +178,10 @@ Item {
             }
 
             enabled: root.enableBeginningFade
-            colorStop0: root.backgroundColor
-            colorStop1: "transparent"
+            edge: (root.orientation === Qt.Horizontal) ? Qt.LeftEdge : Qt.TopEdge
         }
 
-        FadingEdgeRectangleForOpaqueBackground {
+        FadingEdgeMaskForBackground {
             anchors {
                 bottom: parent.bottom
                 right: parent.right
@@ -188,8 +191,7 @@ Item {
             }
 
             enabled: root.enableEndFade
-            colorStop0: "transparent"
-            colorStop1: root.backgroundColor
+            edge: (root.orientation === Qt.Horizontal) ? Qt.RightEdge : Qt.BottomEdge
         }
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e463a04c9d88e1fca091abe4ede74a3d49309df0...d3f8b7afffb26628498de515b9b3382f785eaaa4

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e463a04c9d88e1fca091abe4ede74a3d49309df0...d3f8b7afffb26628498de515b9b3382f785eaaa4
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