From 5b376af5065bf756a1a08f33a551cc187d4de937 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 11 May 2020 16:33:45 +0200 Subject: Switch to a built-in OpacityMask effect for Imagine style No point in pulling in Graphical Effects just for this. Instead, follow what we did for RectangularGlow in the Material style. Task-number: QTBUG-78631 Change-Id: Ibe5f9c18ea4dbdca78ac24facbd5786deebb716f Reviewed-by: Mitch Curtis --- src/imports/controls/imagine/.prev_CMakeLists.txt | 158 ++++++++++++++++++++- src/imports/controls/imagine/CMakeLists.txt | 8 +- src/imports/controls/imagine/DelayButton.qml | 1 - src/imports/controls/imagine/OpacityMask.qml | 68 +++++++++ src/imports/controls/imagine/ProgressBar.qml | 1 - src/imports/controls/imagine/imagine.pri | 1 + src/imports/controls/imagine/imagine.pro | 5 +- src/imports/controls/imagine/qmldir | 1 - .../imagine/qtquickcontrols2imaginestyleplugin.cpp | 3 + .../imagine/shaders/+glslcore/OpacityMask.frag | 13 ++ .../controls/imagine/shaders/+qsb/OpacityMask.frag | Bin 0 -> 1409 bytes .../controls/imagine/shaders/OpacityMask.frag | 7 + .../controls/imagine/shaders/OpacityMask_rhi.frag | 17 +++ src/imports/controls/imagine/shaders/compile.bat | 40 ++++++ 14 files changed, 315 insertions(+), 8 deletions(-) create mode 100644 src/imports/controls/imagine/OpacityMask.qml create mode 100644 src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag create mode 100644 src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag create mode 100644 src/imports/controls/imagine/shaders/OpacityMask.frag create mode 100644 src/imports/controls/imagine/shaders/OpacityMask_rhi.frag create mode 100644 src/imports/controls/imagine/shaders/compile.bat (limited to 'src/imports/controls/imagine') diff --git a/src/imports/controls/imagine/.prev_CMakeLists.txt b/src/imports/controls/imagine/.prev_CMakeLists.txt index 5deb1489..5533f872 100644 --- a/src/imports/controls/imagine/.prev_CMakeLists.txt +++ b/src/imports/controls/imagine/.prev_CMakeLists.txt @@ -4,14 +4,13 @@ ## qtquickcontrols2imaginestyleplugin Plugin: ##################################################################### -add_qml_module(qtquickcontrols2imaginestyleplugin +qt_add_qml_module(qtquickcontrols2imaginestyleplugin TARGET_PATH "QtQuick/Controls.2/Imagine" URI "QtQuick.Controls.Imagine" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2ImagineStylePlugin DEPENDENCIES QtQuick.Controls/2.5 - QtGraphicalEffects/1.0 SKIP_TYPE_REGISTRATION SOURCES qquickimageselector.cpp qquickimageselector_p.h @@ -50,9 +49,12 @@ endforeach() set(qmake_qtquickcontrols2imaginestyle_resource_files ${resource_glob_0} ${resource_glob_1} + "shaders/+glslcore/OpacityMask.frag" + "shaders/+qsb/OpacityMask.frag" + "shaders/OpacityMask.frag" ) -add_qt_resource(qtquickcontrols2imaginestyleplugin "qmake_qtquickcontrols2imaginestyle" +qt_add_resource(qtquickcontrols2imaginestyleplugin "qmake_qtquickcontrols2imaginestyle" PREFIX "qt-project.org/imports/QtQuick/Controls.2/Imagine" FILES @@ -81,11 +83,13 @@ set(qml_files "Drawer.qml" "Frame.qml" "GroupBox.qml" + "HorizontalHeaderView.qml" "ItemDelegate.qml" "Label.qml" "Menu.qml" "MenuItem.qml" "MenuSeparator.qml" + "OpacityMask.qml" "PageIndicator.qml" "Page.qml" "Pane.qml" @@ -114,6 +118,154 @@ set(qml_files "ToolSeparator.qml" "ToolTip.qml" "Tumbler.qml" + "VerticalHeaderView.qml" +) +set_source_files_properties(ApplicationWindow.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(BusyIndicator.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Button.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(CheckBox.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(CheckDelegate.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ComboBox.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(DelayButton.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Dial.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Dialog.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(DialogButtonBox.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Drawer.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Frame.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(GroupBox.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(HorizontalHeaderView.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ItemDelegate.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Label.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Menu.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(MenuItem.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(MenuSeparator.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(OpacityMask.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(PageIndicator.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Page.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Pane.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Popup.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ProgressBar.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(RadioButton.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(RadioDelegate.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(RangeSlider.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(RoundButton.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ScrollBar.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ScrollIndicator.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Slider.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(SpinBox.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(SplitView.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(StackView.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(SwipeDelegate.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(SwipeView.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Switch.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(SwitchDelegate.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(TextField.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(TextArea.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(TabBar.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(TabButton.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ToolBar.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ToolButton.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ToolSeparator.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(ToolTip.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(Tumbler.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) +set_source_files_properties(VerticalHeaderView.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE ) qt6_target_qml_files(qtquickcontrols2imaginestyleplugin diff --git a/src/imports/controls/imagine/CMakeLists.txt b/src/imports/controls/imagine/CMakeLists.txt index ee7e8242..5533f872 100644 --- a/src/imports/controls/imagine/CMakeLists.txt +++ b/src/imports/controls/imagine/CMakeLists.txt @@ -11,7 +11,6 @@ qt_add_qml_module(qtquickcontrols2imaginestyleplugin CLASSNAME QtQuickControls2ImagineStylePlugin DEPENDENCIES QtQuick.Controls/2.5 - QtGraphicalEffects/1.0 SKIP_TYPE_REGISTRATION SOURCES qquickimageselector.cpp qquickimageselector_p.h @@ -50,6 +49,9 @@ endforeach() set(qmake_qtquickcontrols2imaginestyle_resource_files ${resource_glob_0} ${resource_glob_1} + "shaders/+glslcore/OpacityMask.frag" + "shaders/+qsb/OpacityMask.frag" + "shaders/OpacityMask.frag" ) qt_add_resource(qtquickcontrols2imaginestyleplugin "qmake_qtquickcontrols2imaginestyle" @@ -87,6 +89,7 @@ set(qml_files "Menu.qml" "MenuItem.qml" "MenuSeparator.qml" + "OpacityMask.qml" "PageIndicator.qml" "Page.qml" "Pane.qml" @@ -174,6 +177,9 @@ set_source_files_properties(MenuItem.qml PROPERTIES set_source_files_properties(MenuSeparator.qml PROPERTIES QT_QML_SKIP_QMLDIR_ENTRY TRUE ) +set_source_files_properties(OpacityMask.qml PROPERTIES + QT_QML_SKIP_QMLDIR_ENTRY TRUE +) set_source_files_properties(PageIndicator.qml PROPERTIES QT_QML_SKIP_QMLDIR_ENTRY TRUE ) diff --git a/src/imports/controls/imagine/DelayButton.qml b/src/imports/controls/imagine/DelayButton.qml index f60b5eae..ed4ad1e5 100644 --- a/src/imports/controls/imagine/DelayButton.qml +++ b/src/imports/controls/imagine/DelayButton.qml @@ -38,7 +38,6 @@ import QtQuick 2.12 import QtQuick.Templates 2.12 as T import QtQuick.Controls.Imagine 2.12 import QtQuick.Controls.Imagine.impl 2.12 -import QtGraphicalEffects 1.12 T.DelayButton { id: control diff --git a/src/imports/controls/imagine/OpacityMask.qml b/src/imports/controls/imagine/OpacityMask.qml new file mode 100644 index 00000000..040bdcf4 --- /dev/null +++ b/src/imports/controls/imagine/OpacityMask.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 + +/* + A cross-graphics API implementation of QtGraphicalEffects' OpacityMask. + */ +Item { + id: rootItem + + property variant source + property variant maskSource + property bool cached: false + + ShaderEffectSource { + id: cacheItem + anchors.fill: parent + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + ShaderEffect { + id: shaderItem + property variant source: rootItem.source + property variant maskSource: rootItem.maskSource + + anchors.fill: parent + + fragmentShader: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Imagine/shaders/OpacityMask.frag" + } +} diff --git a/src/imports/controls/imagine/ProgressBar.qml b/src/imports/controls/imagine/ProgressBar.qml index 2f78004e..69d352eb 100644 --- a/src/imports/controls/imagine/ProgressBar.qml +++ b/src/imports/controls/imagine/ProgressBar.qml @@ -38,7 +38,6 @@ import QtQuick 2.12 import QtQuick.Templates 2.12 as T import QtQuick.Controls.Imagine 2.12 import QtQuick.Controls.Imagine.impl 2.12 -import QtGraphicalEffects 1.12 T.ProgressBar { id: control diff --git a/src/imports/controls/imagine/imagine.pri b/src/imports/controls/imagine/imagine.pri index 4c6bcf1b..9033808f 100644 --- a/src/imports/controls/imagine/imagine.pri +++ b/src/imports/controls/imagine/imagine.pri @@ -18,6 +18,7 @@ QML_FILES += \ $$PWD/Menu.qml \ $$PWD/MenuItem.qml \ $$PWD/MenuSeparator.qml \ + $$PWD/OpacityMask.qml \ $$PWD/PageIndicator.qml \ $$PWD/Page.qml \ $$PWD/Pane.qml \ diff --git a/src/imports/controls/imagine/imagine.pro b/src/imports/controls/imagine/imagine.pro index f16bd081..66aec543 100644 --- a/src/imports/controls/imagine/imagine.pro +++ b/src/imports/controls/imagine/imagine.pro @@ -21,7 +21,10 @@ SOURCES += \ qtquickcontrols2imaginestyle.prefix = qt-project.org/imports/QtQuick/Controls.2/Imagine qtquickcontrols2imaginestyle.files += \ $$files($$PWD/images/*.png) \ - $$files($$PWD/images/*.webp) + $$files($$PWD/images/*.webp) \ + $$files($$PWD/shaders/OpacityMask.frag) \ + $$files($$PWD/shaders/+glslcore/OpacityMask.frag) \ + $$files($$PWD/shaders/+qsb/OpacityMask.frag) RESOURCES += qtquickcontrols2imaginestyle CONFIG += no_cxx_module install_qml_files builtin_resources qtquickcompiler diff --git a/src/imports/controls/imagine/qmldir b/src/imports/controls/imagine/qmldir index 7b4b3ea0..4319a82c 100644 --- a/src/imports/controls/imagine/qmldir +++ b/src/imports/controls/imagine/qmldir @@ -2,4 +2,3 @@ module QtQuick.Controls.Imagine plugin qtquickcontrols2imaginestyleplugin classname QtQuickControls2ImagineStylePlugin depends QtQuick.Controls 2.5 -depends QtGraphicalEffects 1.0 diff --git a/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp b/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp index 41fd0e85..dd20c84b 100644 --- a/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp +++ b/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp @@ -77,6 +77,9 @@ void QtQuickControls2ImagineStylePlugin::registerTypes(const char *uri) qmlRegisterType(import, 2, 3, "ImageSelector"); qmlRegisterType(import, 2, 3, "NinePatchImage"); qmlRegisterType(import, 2, 3, "NinePatchImageSelector"); + + // Qt 6.0, import version may need to be updated. + qmlRegisterType(resolvedUrl(QStringLiteral("OpacityMask.qml")), import, 2, 0, "OpacityMask"); } QString QtQuickControls2ImagineStylePlugin::name() const diff --git a/src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag b/src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag new file mode 100644 index 00000000..529e2696 --- /dev/null +++ b/src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag @@ -0,0 +1,13 @@ +#version 150 + +uniform float qt_Opacity; +uniform sampler2D source; +uniform sampler2D maskSource; + +in vec2 qt_TexCoord0; +out vec4 fragColor; + +void main() +{ + fragColor = texture(source, qt_TexCoord0.st) * (texture(maskSource, qt_TexCoord0.st).a) * qt_Opacity; +} diff --git a/src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag b/src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag new file mode 100644 index 00000000..331b30b8 Binary files /dev/null and b/src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag differ diff --git a/src/imports/controls/imagine/shaders/OpacityMask.frag b/src/imports/controls/imagine/shaders/OpacityMask.frag new file mode 100644 index 00000000..84f9bc3e --- /dev/null +++ b/src/imports/controls/imagine/shaders/OpacityMask.frag @@ -0,0 +1,7 @@ +varying highp vec2 qt_TexCoord0; +uniform highp float qt_Opacity; +uniform lowp sampler2D source; +uniform lowp sampler2D maskSource; +void main(void) { + gl_FragColor = texture2D(source, qt_TexCoord0.st) * (texture2D(maskSource, qt_TexCoord0.st).a) * qt_Opacity; +} diff --git a/src/imports/controls/imagine/shaders/OpacityMask_rhi.frag b/src/imports/controls/imagine/shaders/OpacityMask_rhi.frag new file mode 100644 index 00000000..9ae32499 --- /dev/null +++ b/src/imports/controls/imagine/shaders/OpacityMask_rhi.frag @@ -0,0 +1,17 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + mat4 qt_Matrix; + float qt_Opacity; +} ubuf; + +layout(binding = 1) uniform sampler2D source; +layout(binding = 2) uniform sampler2D maskSource; + +void main() +{ + fragColor = texture(source, qt_TexCoord0.st) * (texture(maskSource, qt_TexCoord0.st).a) * ubuf.qt_Opacity; +} diff --git a/src/imports/controls/imagine/shaders/compile.bat b/src/imports/controls/imagine/shaders/compile.bat new file mode 100644 index 00000000..8f16d7ac --- /dev/null +++ b/src/imports/controls/imagine/shaders/compile.bat @@ -0,0 +1,40 @@ +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: Copyright (C) 2020 The Qt Company Ltd. +:: Contact: https://www.qt.io/licensing/ +:: +:: This file is part of the QtQuick module of the Qt Toolkit. +:: +:: $QT_BEGIN_LICENSE:LGPL$ +:: Commercial License Usage +:: Licensees holding valid commercial Qt licenses may use this file in +:: accordance with the commercial license agreement provided with the +:: Software or, alternatively, in accordance with the terms contained in +:: a written agreement between you and The Qt Company. For licensing terms +:: and conditions see https://www.qt.io/terms-conditions. For further +:: information use the contact form at https://www.qt.io/contact-us. +:: +:: GNU Lesser General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU Lesser +:: General Public License version 3 as published by the Free Software +:: Foundation and appearing in the file LICENSE.LGPL3 included in the +:: packaging of this file. Please review the following information to +:: ensure the GNU Lesser General Public License version 3 requirements +:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +:: +:: GNU General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU +:: General Public License version 2.0 or (at your option) the GNU General +:: Public license version 3 or any later version approved by the KDE Free +:: Qt Foundation. The licenses are as published by the Free Software +:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +:: included in the packaging of this file. Please review the following +:: information to ensure the GNU General Public License requirements will +:: be met: https://www.gnu.org/licenses/gpl-2.0.html and +:: https://www.gnu.org/licenses/gpl-3.0.html. +:: +:: $QT_END_LICENSE$ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o +qsb/OpacityMask.frag OpacityMask_rhi.frag -- cgit v1.2.3