| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include <private/qtquickglobal_p.h> |
| 41 | |
| 42 | QT_REQUIRE_CONFIG(quick_shadereffect); |
| 43 | |
| 44 | #include "qqmlparserstatus.h" |
| 45 | |
| 46 | #include <QtQuick/qtquickglobal.h> |
| 47 | #include <QtGui/qcolor.h> |
| 48 | #include <QtCore/qobject.h> |
| 49 | #include <QtCore/qsize.h> |
| 50 | #include <QtCore/qvector.h> |
| 51 | #include <QtCore/qbytearray.h> |
| 52 | #include <QtQml/qqml.h> |
| 53 | |
| 54 | #ifndef QQUICKSHADEREFFECTMESH_P_H |
| 55 | #define QQUICKSHADEREFFECTMESH_P_H |
| 56 | |
| 57 | // |
| 58 | // W A R N I N G |
| 59 | // ------------- |
| 60 | // |
| 61 | // This file is not part of the Qt API. It exists purely as an |
| 62 | // implementation detail. This header file may change from version to |
| 63 | // version without notice, or even be removed. |
| 64 | // |
| 65 | // We mean it. |
| 66 | // |
| 67 | |
| 68 | QT_BEGIN_NAMESPACE |
| 69 | |
| 70 | Q_QUICK_PRIVATE_EXPORT const char *qtPositionAttributeName(); |
| 71 | Q_QUICK_PRIVATE_EXPORT const char *qtTexCoordAttributeName(); |
| 72 | |
| 73 | class QSGGeometry; |
| 74 | class QRectF; |
| 75 | |
| 76 | class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectMesh : public QObject |
| 77 | { |
| 78 | Q_OBJECT |
| 79 | |
| 80 | QML_NAMED_ELEMENT(ShaderEffectMesh) |
| 81 | QML_UNCREATABLE("Cannot create instance of abstract class ShaderEffectMesh." ) |
| 82 | |
| 83 | public: |
| 84 | QQuickShaderEffectMesh(QObject *parent = nullptr); |
| 85 | virtual bool validateAttributes(const QVector<QByteArray> &attributes, int *posIndex) = 0; |
| 86 | // If 'geometry' != 0, 'attrCount' is the same as last time the function was called. |
| 87 | virtual QSGGeometry *updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, |
| 88 | const QRectF &srcRect, const QRectF &rect) = 0; |
| 89 | // If updateGeometry() fails, the reason should appear in the log. |
| 90 | virtual QString log() const { return QString(); } |
| 91 | |
| 92 | Q_SIGNALS: |
| 93 | // Emitted when the geometry needs to be updated. |
| 94 | void geometryChanged(); |
| 95 | |
| 96 | protected: |
| 97 | QQuickShaderEffectMesh(QObjectPrivate &dd, QObject *parent = nullptr); |
| 98 | }; |
| 99 | |
| 100 | class Q_QUICK_PRIVATE_EXPORT QQuickGridMesh : public QQuickShaderEffectMesh |
| 101 | { |
| 102 | Q_OBJECT |
| 103 | Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged) |
| 104 | QML_NAMED_ELEMENT(GridMesh) |
| 105 | public: |
| 106 | QQuickGridMesh(QObject *parent = nullptr); |
| 107 | bool validateAttributes(const QVector<QByteArray> &attributes, int *posIndex) override; |
| 108 | QSGGeometry *updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, |
| 109 | const QRectF &srcRect, const QRectF &rect) override; |
| 110 | QString log() const override { return m_log; } |
| 111 | |
| 112 | void setResolution(const QSize &res); |
| 113 | QSize resolution() const; |
| 114 | |
| 115 | Q_SIGNALS: |
| 116 | void resolutionChanged(); |
| 117 | |
| 118 | private: |
| 119 | QSize m_resolution; |
| 120 | QString m_log; |
| 121 | }; |
| 122 | |
| 123 | class QQuickScaleGrid; |
| 124 | class QQuickBorderImageMesh : public QQuickShaderEffectMesh |
| 125 | { |
| 126 | Q_OBJECT |
| 127 | |
| 128 | Q_PROPERTY(QQuickScaleGrid *border READ border CONSTANT) |
| 129 | Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged) |
| 130 | Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) |
| 131 | Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) |
| 132 | |
| 133 | QML_NAMED_ELEMENT(BorderImageMesh) |
| 134 | QML_ADDED_IN_MINOR_VERSION(8) |
| 135 | |
| 136 | public: |
| 137 | QQuickBorderImageMesh(QObject *parent = nullptr); |
| 138 | |
| 139 | bool validateAttributes(const QVector<QByteArray> &attributes, int *posIndex) override; |
| 140 | QSGGeometry *updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, |
| 141 | const QRectF &srcRect, const QRectF &rect) override; |
| 142 | |
| 143 | QQuickScaleGrid *border() const; |
| 144 | |
| 145 | enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; |
| 146 | Q_ENUM(TileMode) |
| 147 | |
| 148 | QSize size() const; |
| 149 | void setSize(const QSize &size); |
| 150 | |
| 151 | TileMode horizontalTileMode() const; |
| 152 | void setHorizontalTileMode(TileMode); |
| 153 | |
| 154 | TileMode verticalTileMode() const; |
| 155 | void setVerticalTileMode(TileMode); |
| 156 | |
| 157 | Q_SIGNALS: |
| 158 | void sizeChanged(); |
| 159 | void horizontalTileModeChanged(); |
| 160 | void verticalTileModeChanged(); |
| 161 | |
| 162 | private: |
| 163 | QQuickScaleGrid *m_border; |
| 164 | QSize m_size; |
| 165 | TileMode m_horizontalTileMode; |
| 166 | TileMode m_verticalTileMode; |
| 167 | }; |
| 168 | |
| 169 | inline QColor qt_premultiply_color(const QColor &c) |
| 170 | { |
| 171 | return QColor::fromRgbF(r: c.redF() * c.alphaF(), g: c.greenF() * c.alphaF(), b: c.blueF() * c.alphaF(), a: c.alphaF()); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | QT_END_NAMESPACE |
| 176 | |
| 177 | #endif // QQUICKSHADEREFFECTMESH_P_H |
| 178 | |