| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include <private/qtquickglobal_p.h> |
| 5 | |
| 6 | QT_REQUIRE_CONFIG(quick_shadereffect); |
| 7 | |
| 8 | #include "qqmlparserstatus.h" |
| 9 | |
| 10 | #include <QtQuick/qtquickglobal.h> |
| 11 | #include <QtGui/qcolor.h> |
| 12 | #include <QtCore/qobject.h> |
| 13 | #include <QtCore/qsize.h> |
| 14 | #include <QtCore/qvector.h> |
| 15 | #include <QtCore/qbytearray.h> |
| 16 | #include <QtQml/qqml.h> |
| 17 | |
| 18 | #ifndef QQUICKSHADEREFFECTMESH_P_H |
| 19 | #define QQUICKSHADEREFFECTMESH_P_H |
| 20 | |
| 21 | // |
| 22 | // W A R N I N G |
| 23 | // ------------- |
| 24 | // |
| 25 | // This file is not part of the Qt API. It exists purely as an |
| 26 | // implementation detail. This header file may change from version to |
| 27 | // version without notice, or even be removed. |
| 28 | // |
| 29 | // We mean it. |
| 30 | // |
| 31 | |
| 32 | QT_BEGIN_NAMESPACE |
| 33 | |
| 34 | Q_QUICK_EXPORT const char *qtPositionAttributeName(); |
| 35 | Q_QUICK_EXPORT const char *qtTexCoordAttributeName(); |
| 36 | |
| 37 | class QSGGeometry; |
| 38 | class QRectF; |
| 39 | |
| 40 | class Q_QUICK_EXPORT QQuickShaderEffectMesh : public QObject |
| 41 | { |
| 42 | Q_OBJECT |
| 43 | |
| 44 | QML_NAMED_ELEMENT(ShaderEffectMesh) |
| 45 | QML_ADDED_IN_VERSION(2, 0) |
| 46 | QML_UNCREATABLE("Cannot create instance of abstract class ShaderEffectMesh." ) |
| 47 | |
| 48 | public: |
| 49 | QQuickShaderEffectMesh(QObject *parent = nullptr); |
| 50 | virtual bool validateAttributes(const QVector<QByteArray> &attributes, int *posIndex) = 0; |
| 51 | // If 'geometry' != 0, 'attrCount' is the same as last time the function was called. |
| 52 | virtual QSGGeometry *updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, |
| 53 | const QRectF &srcRect, const QRectF &rect) = 0; |
| 54 | // If updateGeometry() fails, the reason should appear in the log. |
| 55 | virtual QString log() const { return QString(); } |
| 56 | |
| 57 | Q_SIGNALS: |
| 58 | // Emitted when the geometry needs to be updated. |
| 59 | void geometryChanged(); |
| 60 | |
| 61 | protected: |
| 62 | QQuickShaderEffectMesh(QObjectPrivate &dd, QObject *parent = nullptr); |
| 63 | }; |
| 64 | |
| 65 | class Q_QUICK_EXPORT QQuickGridMesh : public QQuickShaderEffectMesh |
| 66 | { |
| 67 | Q_OBJECT |
| 68 | Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged) |
| 69 | QML_NAMED_ELEMENT(GridMesh) |
| 70 | QML_ADDED_IN_VERSION(2, 0) |
| 71 | public: |
| 72 | QQuickGridMesh(QObject *parent = nullptr); |
| 73 | bool validateAttributes(const QVector<QByteArray> &attributes, int *posIndex) override; |
| 74 | QSGGeometry *updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, |
| 75 | const QRectF &srcRect, const QRectF &rect) override; |
| 76 | QString log() const override { return m_log; } |
| 77 | |
| 78 | void setResolution(const QSize &res); |
| 79 | QSize resolution() const; |
| 80 | |
| 81 | Q_SIGNALS: |
| 82 | void resolutionChanged(); |
| 83 | |
| 84 | private: |
| 85 | QSize m_resolution; |
| 86 | QString m_log; |
| 87 | }; |
| 88 | |
| 89 | class QQuickScaleGrid; |
| 90 | class QQuickBorderImageMesh : public QQuickShaderEffectMesh |
| 91 | { |
| 92 | Q_OBJECT |
| 93 | |
| 94 | Q_PROPERTY(QQuickScaleGrid *border READ border CONSTANT) |
| 95 | Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged) |
| 96 | Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) |
| 97 | Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) |
| 98 | |
| 99 | QML_NAMED_ELEMENT(BorderImageMesh) |
| 100 | QML_ADDED_IN_VERSION(2, 8) |
| 101 | |
| 102 | public: |
| 103 | QQuickBorderImageMesh(QObject *parent = nullptr); |
| 104 | |
| 105 | bool validateAttributes(const QVector<QByteArray> &attributes, int *posIndex) override; |
| 106 | QSGGeometry *updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, |
| 107 | const QRectF &srcRect, const QRectF &rect) override; |
| 108 | |
| 109 | QQuickScaleGrid *border() const; |
| 110 | |
| 111 | enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; |
| 112 | Q_ENUM(TileMode) |
| 113 | |
| 114 | QSize size() const; |
| 115 | void setSize(const QSize &size); |
| 116 | |
| 117 | TileMode horizontalTileMode() const; |
| 118 | void setHorizontalTileMode(TileMode); |
| 119 | |
| 120 | TileMode verticalTileMode() const; |
| 121 | void setVerticalTileMode(TileMode); |
| 122 | |
| 123 | Q_SIGNALS: |
| 124 | void sizeChanged(); |
| 125 | void horizontalTileModeChanged(); |
| 126 | void verticalTileModeChanged(); |
| 127 | |
| 128 | private: |
| 129 | QQuickScaleGrid *m_border; |
| 130 | QSize m_size; |
| 131 | TileMode m_horizontalTileMode; |
| 132 | TileMode m_verticalTileMode; |
| 133 | }; |
| 134 | |
| 135 | inline QColor qt_premultiply_color(const QColor &c) |
| 136 | { |
| 137 | float r, g, b, a; |
| 138 | c.getRgbF(r: &r, g: &g, b: &b, a: &a); |
| 139 | return QColor::fromRgbF(r: r * a, g: g * a, b: b * a, a); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | QT_END_NAMESPACE |
| 144 | |
| 145 | #endif // QQUICKSHADEREFFECTMESH_P_H |
| 146 | |