[vlc-commits] [Git][videolan/vlc][master] 2 commits: qml: use sub-texture for source instead of filtering when feasible in `PartialEffect`
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sat Oct 25 10:52:44 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
1f9dca1b by Fatih Uzunoglu at 2025-10-25T10:37:40+00:00
qml: use sub-texture for source instead of filtering when feasible in `PartialEffect`
Providing `sourceVisualRect` now makes the source visual to use sub-texture
instead of filtering out the effect part, which is done when blending is
enabled.
When blending is off, since the opaque effect is drawn first, the fragments
of the source visual that are obscured by the effect area should already be
discarded due to early fragment test, provided that the scene graph uses
depth buffer (which is the default). If not, `sourceVisualRect` can be used
to have the same benefit.
- - - - -
7fd61bea by Fatih Uzunoglu at 2025-10-25T10:37:40+00:00
qml: provide `sourceVisualRect` for the partial effect in `MainDisplay`
- - - - -
2 changed files:
- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/widgets/qml/PartialEffect.qml
Changes:
=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -263,6 +263,8 @@ FocusScope {
width,
height - stackView.height)
+ sourceVisualRect: blending ? Qt.rect(0, 0, width, effectRect.y) : Qt.rect(0, 0, 0, 0)
+
effect: frostedGlassEffect
Widgets.FrostedGlassEffect {
=====================================
modules/gui/qt/widgets/qml/PartialEffect.qml
=====================================
@@ -41,10 +41,21 @@ Item {
// Rectangular area where the effect should be applied:
property alias effectRect: textureProviderItem.effectRect
+ // Not mandatory to provide, but when feasible (such as, effect is not
+ // an isolated inner area), provide it for optimization. When not provided,
+ // the source visual is going to cover the whole area, and if source is not
+ // opaque (blending is enabled), the effect part is going to be filtered in
+ // fragment shader, which is more expensive than sub-texturing by means of
+ // this property. That being said, when source is opaque (blending is off),
+ // then providing this may serve no purpose due to early fragment test as
+ // long as the scene graph uses depth buffer (default). For that reason, it
+ // is recommended to provide this only in non-opaque cases (blending is set):
+ property rect sourceVisualRect
+
property Item effect
property string samplerName: "source"
- // Enable blending if background of source is not opaque.
+ // Enable blending if source or the effect is not opaque.
// This comes with a performance penalty.
property alias blending: sourceProxy.blending
@@ -53,14 +64,17 @@ Item {
ShaderEffect {
id: sourceProxy
- anchors.fill: parent
+ x: root.sourceVisualRect.x
+ y: root.sourceVisualRect.y
+ width: useSubTexture ? root.sourceVisualRect.width : parent.width
+ height: useSubTexture ? root.sourceVisualRect.height : parent.height
blending: false
- property alias source: root.source
+ readonly property Item source: useSubTexture ? sourceVisualTextureProviderItem : root.source
readonly property rect discardRect: {
- if (blending)
+ if (blending && !useSubTexture)
return Qt.rect(textureProviderItem.x / root.width,
textureProviderItem.y / root.height,
(textureProviderItem.x + textureProviderItem.width) / root.width,
@@ -69,14 +83,25 @@ Item {
return Qt.rect(0, 0, 0, 0)
}
+ readonly property bool useSubTexture: (root.sourceVisualRect.width > 0.0 && root.sourceVisualRect.height > 0.0)
+
+ supportsAtlasTextures: true
+
// cullMode: ShaderEffect.BackFaceCulling // QTBUG-136611 (Layering breaks culling with OpenGL)
- // 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: (discardRect.width > 0.0 && discardRect.height > 0.0) ? "qrc:///shaders/RectFilter.frag.qsb" : ""
+
+ Widgets.TextureProviderItem {
+ id: sourceVisualTextureProviderItem
+ source: root.source
- fragmentShader: blending ? "qrc:///shaders/RectFilter.frag.qsb" : ""
+ // If the effect is in a isolated inner area, filtering is necessary. Otherwise, we can simply
+ // use sub-texturing for the source itself as well (we already use sub-texture for the effect area).
+ textureSubRect: (sourceProxy.useSubTexture) ? Qt.rect(root.sourceVisualRect.x * textureProviderItem.eDPR,
+ root.sourceVisualRect.y * textureProviderItem.eDPR,
+ root.sourceVisualRect.width * textureProviderItem.eDPR,
+ root.sourceVisualRect.height * textureProviderItem.eDPR) : undefined
+ }
}
// We use texture provider that uses QSGTextureView.
@@ -111,19 +136,6 @@ Item {
}
}
- onChildrenChanged: {
- // Do not add visual(QQuickItem) children to this item,
- // because Qt thinks that it needs to use implicit layering.
- // "If needed, MultiEffect will internally generate a
- // ShaderEffectSource as the texture source."
- // Adding children to a texture provider item is not going
- // make them rendered in the texture. Instead, simply add
- // to the source. If source is layered, the source would
- // be a `ShaderEffectSource`, in that case `sourceItem`
- // can be used to reach to the real source.
- console.assert(textureProviderItem.children.length === 0)
- }
-
// Effect's source is sub-texture through the texture provider:
Binding {
target: root.effect
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9a8e6a553263a0625c76e8108886a471e7ce81fb...7fd61bea89450c6c20a94d59118d24cf2e2cb0bf
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9a8e6a553263a0625c76e8108886a471e7ce81fb...7fd61bea89450c6c20a94d59118d24cf2e2cb0bf
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