5#include <private/qquickmultieffect_p_p.h>
6#include <private/qquickshadereffect_p.h>
7#include <private/qquickshadereffectsource_p.h>
162 setFlag(ItemHasContents);
216 return d->autoPaddingEnabled();
248 return d->paddingRect();
254 d->setPaddingRect(
rect);
269 return d->brightness();
290 return d->contrast();
311 return d->saturation();
332 return d->colorization();
354 return d->colorizationColor();
360 d->setColorizationColor(
color);
373 return d->blurEnabled();
453 return d->blurMultiplier();
472 return d->shadowEnabled();
493 return d->shadowOpacity();
518 return d->shadowBlur();
543 return d->shadowHorizontalOffset();
549 d->setShadowHorizontalOffset(
offset);
568 return d->shadowVerticalOffset();
574 d->setShadowVerticalOffset(
offset);
590 return d->shadowColor();
615 return d->shadowScale();
634 return d->maskEnabled();
654 return d->maskSource();
660 d->setMaskSource(
item);
678 return d->maskThresholdMin();
684 d->setMaskThresholdMin(threshold);
701 return d->maskSpreadAtMin();
707 d->setMaskSpreadAtMin(spread);
725 return d->maskThresholdMax();
731 d->setMaskThresholdMax(threshold);
748 return d->maskSpreadAtMax();
754 d->setMaskSpreadAtMax(spread);
769 return d->maskInverted();
775 d->setMaskInverted(inverted);
790 return d->itemRect();
802 return d->fragmentShader();
814 return d->vertexShader();
830 return d->hasProxySource();
847 d->handleGeometryChange(newGeometry, oldGeometry);
853 d->handleItemChange(change,
value);
894 if (
item == m_sourceItem)
899 m_shaderSource->
setInput(m_sourceItem);
908 return m_autoPaddingEnabled;
914 if (
enabled == m_autoPaddingEnabled)
917 m_autoPaddingEnabled =
enabled;
920 Q_EMIT q->autoPaddingEnabledChanged();
925 return m_paddingRect;
931 if (
rect == m_paddingRect)
933 m_paddingRect =
rect;
937 emit q->paddingRectChanged();
953 m_shaderEffect->
setProperty(
"brightness", m_brightness);
972 m_shaderEffect->
setProperty(
"contrast", m_contrast);
991 m_shaderEffect->
setProperty(
"saturation", m_saturation);
999 return m_colorization;
1012 Q_EMIT q->colorizationChanged();
1017 return m_colorizationColor;
1023 if (
color == m_colorizationColor)
1026 m_colorizationColor =
color;
1030 Q_EMIT q->colorizationColorChanged();
1035 return m_blurEnabled;
1050 Q_EMIT q->blurEnabledChanged();
1096 return m_blurMultiplier;
1112 Q_EMIT q->blurMultiplierChanged();
1117 return m_shadowEnabled;
1123 if (
enabled == m_shadowEnabled)
1132 Q_EMIT q->shadowEnabledChanged();
1137 return m_shadowOpacity;
1150 Q_EMIT q->shadowOpacityChanged();
1155 return m_shadowBlur;
1168 Q_EMIT q->shadowBlurChanged();
1173 return m_shadowHorizontalOffset;
1179 if (
offset == m_shadowHorizontalOffset)
1182 m_shadowHorizontalOffset =
offset;
1186 Q_EMIT q->shadowHorizontalOffsetChanged();
1191 return m_shadowVerticalOffset;
1197 if (
offset == m_shadowVerticalOffset)
1200 m_shadowVerticalOffset =
offset;
1204 Q_EMIT q->shadowVerticalOffsetChanged();
1209 return m_shadowColor;
1215 if (
color == m_shadowColor)
1218 m_shadowColor =
color;
1222 Q_EMIT q->shadowColorChanged();
1227 return m_shadowScale;
1239 m_shaderEffect->
setProperty(
"shadowScale", 1.0 / m_shadowScale);
1242 Q_EMIT q->shadowScaleChanged();
1247 return m_maskEnabled;
1260 Q_EMIT q->maskEnabledChanged();
1265 return m_maskSourceItem;
1271 if (
item == m_maskSourceItem)
1274 m_maskSourceItem =
item;
1275 if (m_shaderEffect) {
1276 auto maskSourceVariant = QVariant::fromValue<QQuickItem*>(m_maskSourceItem);
1277 m_shaderEffect->
setProperty(
"maskSrc", maskSourceVariant);
1281 Q_EMIT q->maskSourceChanged();
1286 return m_maskThresholdMin;
1292 if (threshold == m_maskThresholdMin)
1295 m_maskThresholdMin = threshold;
1299 Q_EMIT q->maskThresholdMinChanged();
1304 return m_maskSpreadAtMin;
1310 if (spread == m_maskSpreadAtMin)
1313 m_maskSpreadAtMin = spread;
1317 Q_EMIT q->maskSpreadAtMinChanged();
1322 return m_maskThresholdMax;
1328 if (threshold == m_maskThresholdMax)
1331 m_maskThresholdMax = threshold;
1335 Q_EMIT q->maskThresholdMaxChanged();
1340 return m_maskSpreadAtMax;
1346 if (spread == m_maskSpreadAtMax)
1349 m_maskSpreadAtMax = spread;
1353 Q_EMIT q->maskSpreadAtMaxChanged();
1358 return m_maskInverted;
1364 if (inverted == m_maskInverted)
1367 m_maskInverted = inverted;
1369 m_shaderEffect->
setProperty(
"maskInverted",
float(m_maskInverted));
1372 Q_EMIT q->maskInvertedChanged();
1377 if (!m_shaderEffect || !m_shaderSource)
1381 if (sourceRect.
width() > 0 && sourceRect.
height() > 0)
1389 return m_fragShader;
1394 return m_vertShader;
1399 return m_shaderSource && m_shaderSource->
isActive();
1409 if (!
q->isComponentComplete())
1413 if (
q->width() <= 0 ||
q->height() <= 0)
1422 m_shaderEffect->
setSize(
q->size());
1425 m_shaderSource->
setSize(
q->size());
1426 m_shaderSource->
setInput(m_sourceItem);
1437 auto sourceVariant = QVariant::fromValue<QQuickItem*>(m_shaderSource->
output());
1438 m_shaderEffect->
setProperty(
"src", sourceVariant);
1439 m_shaderEffect->
setProperty(
"brightness", m_brightness);
1440 m_shaderEffect->
setProperty(
"contrast", m_contrast);
1441 m_shaderEffect->
setProperty(
"saturation", m_saturation);
1442 m_shaderEffect->
setProperty(
"shadowScale", 1.0 / m_shadowScale);
1443 auto maskSourceVariant = QVariant::fromValue<QQuickItem*>(m_maskSourceItem);
1444 m_shaderEffect->
setProperty(
"maskSrc", maskSourceVariant);
1445 m_shaderEffect->
setProperty(
"maskInverted",
float(m_maskInverted));
1453 m_initialized =
true;
1458 if (!m_shaderEffect)
1463 const qreal c0 = 0.0001;
1464 const qreal c1 = 1.0 - c0;
1465 const qreal mt1 = m_maskThresholdMin + c0;
1466 const qreal ms1 = m_maskSpreadAtMin + 1.0;
1467 const qreal mt2 = c1 - m_maskThresholdMax;
1468 const qreal ms2 = m_maskSpreadAtMax + 1.0;
1470 mt1 * ms1 - (ms1 - c1),
1472 mt2 * ms2 - (ms2 - c1),
1474 m_shaderEffect->
setProperty(
"mask", maskThresholdSpread);
1479 if (!m_shaderEffect)
1484 (1.0 -
scale) * (0.5 + 0.5 * (m_paddingRect.
y() - m_paddingRect.
height()) / m_shaderEffect->
height()));
1490 if (!m_shaderEffect)
1494 m_shaderEffect->
setProperty(
"shadowOffset", shadowOffset);
1499 if (!m_shaderEffect)
1502 float alpha = std::clamp(
float(m_colorizationColor.
alphaF() * m_colorization), 0.0f, 1.0f);
1504 m_colorizationColor.
greenF(),
1505 m_colorizationColor.
blueF(),
1512 if (!m_shaderEffect)
1515 float alpha = std::clamp(
float(m_shadowColor.
alphaF() * m_shadowOpacity), 0.0f, 1.0f);
1518 m_shadowColor.
blueF(),
1526 return qSqrt(blurAmount *
float(m_blurMax) / 64.0f) * 1.2f - 0.2f;
1531 return std::max(0.0f, std::min(1.0f, 1.0f -
v * 2.0f));
1536 float bw1 =
blurWeight(std::fabs(blurLod - 0.1f));
1537 float bw2 =
blurWeight(std::fabs(blurLod - 0.3f));
1538 float bw3 =
blurWeight(std::fabs(blurLod - 0.5f));
1539 float bw4 =
blurWeight(std::fabs(blurLod - 0.7f));
1540 float bw5 =
blurWeight(std::fabs(blurLod - 0.9f));
1541 float bw6 =
blurWeight(std::fabs(blurLod - 1.1f));
1542 float bsum = bw1 + bw2 + bw3 + bw4 + bw5 + bw6;
1543 blurWeight1 =
QVector4D(bw1 / bsum, bw2 / bsum, bw3 / bsum, bw4 / bsum);
1544 blurWeight2 =
QVector2D(bw5 / bsum, bw6 / bsum);
1549 if (!m_shaderEffect)
1553 m_shaderEffect->
setProperty(
"blurWeight1", m_blurWeight1);
1554 m_shaderEffect->
setProperty(
"blurWeight2", m_blurWeight2);
1559 if (!m_shaderEffect)
1562 getBlurWeights(blurLod, m_shadowBlurWeight1, m_shadowBlurWeight2);
1563 m_shaderEffect->
setProperty(
"shadowBlurWeight1", m_shadowBlurWeight1);
1564 m_shaderEffect->
setProperty(
"shadowBlurWeight2", m_shadowBlurWeight2);
1569 if (m_blurEffects.isEmpty() || !m_shaderSource || !m_sourceItem)
1575 QSizeF firstItemSize(std::ceil(sourceSize.
width() / 16) * 8,
1576 std::ceil(sourceSize.
height() / 16) * 8);
1578 if (!
forceUpdate && m_firstBlurItemSize == firstItemSize)
1581 qCDebug(lcQuickEffect) <<
"Source size:" << sourceSize;
1582 m_firstBlurItemSize = firstItemSize;
1584 for (
int i = 0;
i < m_blurEffects.size();
i++) {
1585 auto *blurEffect = m_blurEffects[
i];
1586 QSizeF itemSize = (
i == 0) ? firstItemSize : m_blurEffects[
i - 1]->size() * 0.5;
1587 qCDebug(lcQuickEffect) <<
"Blur item" <<
i <<
":" << itemSize;
1588 blurEffect->setSize(itemSize);
1591 (1.0 + m_blurMultiplier) / itemSize.
height());
1592 blurEffect->setProperty(
"offset",
offset);
1599 if (!
q->isComponentComplete() || !m_shaderEffect)
1603 if (m_shadowEnabled)
1609 if (m_blurEnabled && m_blurMax > 0)
1611 if (m_shadowEnabled)
1616 bool shaderChanged =
false;
1617 if (fShader != m_fragShader) {
1618 shaderChanged =
true;
1619 m_fragShader = fShader;
1622 Q_EMIT q->fragmentShaderChanged();
1624 if (vShader != m_vertShader) {
1625 shaderChanged =
true;
1626 m_vertShader = vShader;
1629 Q_EMIT q->vertexShaderChanged();
1631 if (shaderChanged) {
1632 qCDebug(lcQuickEffect) <<
this <<
"Shaders: " << m_fragShader << m_vertShader;
1640 if ((m_blurEnabled || m_shadowEnabled) && m_blurMax > 0) {
1643 else if (m_blurMax > 16)
1649 if (blurLevel != m_blurLevel || (blurLevel > 0 && m_blurEffects.isEmpty()) ||
forceUpdate) {
1654 if (blurLevel > m_blurLevel)
1657 m_blurLevel = blurLevel;
1663 if (!m_shaderEffect)
1671 int itemsAmount = blurLevel == 0 ? 0 : blurLevel + 2;
1673 if (m_blurEffects.size() < itemsAmount) {
1680 for (
int i = m_blurEffects.size();
i < itemsAmount;
i++) {
1681 auto blurEffect = qobject_cast<QQuickShaderEffect*>(blurComponent.create());
1682 blurEffect->setParent(
q);
1683 blurEffect->setParentItem(
q);
1684 auto sourceVariant = QVariant::fromValue<QQuickItem*>(blurEffect);
1686 m_shaderEffect->
setProperty(sourceProperty.toUtf8(), sourceVariant);
1689 blurEffect->setProperty(
"source", sourceVariant);
1691 priv->layer()->setEnabled(
true);
1692 priv->layer()->setSmooth(
true);
1693 blurEffect->setVertexShader(blurVs);
1694 blurEffect->setFragmentShader(blurFs);
1695 m_blurEffects << blurEffect;
1700 if (!m_dummyShaderSource)
1702 for (
int i = 0;
i < m_blurEffects.size();
i++) {
1703 auto *blurEffect = m_blurEffects[
i];
1704 auto sourceItem = (
i >= itemsAmount) ?
1705 static_cast<QQuickItem *
>(m_dummyShaderSource) : (
i == 0) ?
1708 auto sourceVariant = QVariant::fromValue<QQuickItem*>(sourceItem);
1709 blurEffect->setProperty(
"source", sourceVariant);
1716 if (!m_shaderEffect || !m_shaderSource)
1719 const bool blurItemsNeeded = (m_blurEnabled || m_shadowEnabled) && (m_blurMax > 0);
1720 const int itemPadding = m_autoPaddingEnabled && blurItemsNeeded ? m_blurMax * (1.0 + m_blurMultiplier) : 0;
1723 if (m_paddingRect !=
QRectF() || itemPadding > 0) {
1724 QRectF effectRect(-m_paddingRect.
x() - itemPadding,
1725 -m_paddingRect.
y() - itemPadding,
1726 q->width() + m_paddingRect.
x() + m_paddingRect.
width() + (itemPadding * 2),
1727 q->height() + m_paddingRect.
y() + m_paddingRect.
height() + (itemPadding * 2));
1728 m_shaderEffect->
setX(effectRect.x());
1729 m_shaderEffect->
setY(effectRect.y());
1730 m_shaderEffect->
setWidth(effectRect.width());
1731 m_shaderEffect->
setHeight(effectRect.height());
1739 const qreal baseWidth = m_sourceItem && m_sourceItem->
width() > 0 ? m_sourceItem->
width() :
q->width();
1740 const qreal baseHeight = m_sourceItem && m_sourceItem->
height() > 0 ? m_sourceItem->
height() :
q->height();
1743 const qreal widthMultiplier =
q->width() > 0 ? baseWidth /
q->width() : 1.0;
1744 const qreal heightMultiplier =
q->height() > 0 ? baseHeight /
q->height() : 1.0;
1745 const qreal xPadding = itemPadding * widthMultiplier;
1746 const qreal yPadding = itemPadding * heightMultiplier;
1748 m_paddingRect.
y() * heightMultiplier,
1749 m_paddingRect.
width() * widthMultiplier,
1750 m_paddingRect.
height() * heightMultiplier);
1752 -
rect.y() - yPadding,
1753 baseWidth +
rect.x() +
rect.width() + xPadding * 2,
1754 baseHeight +
rect.y() +
rect.height() + yPadding * 2);
1757 m_shaderEffect->
setX(0);
1758 m_shaderEffect->
setY(0);
1759 m_shaderEffect->
setSize(
q->size());
1760 m_shaderSource->
setSize(
q->size());
1767 Q_EMIT q->paddingRectChanged();
1774 if (!m_shaderSource)
1777 auto sourceVariant = QVariant::fromValue<QQuickItem*>(m_shaderSource->
output());
1778 m_shaderEffect->
setProperty(
"src", sourceVariant);
1788 if (!m_shaderSource)
1791 m_shaderSource->
polish();
1796#include "moc_qquickmultieffect_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
float greenF() const noexcept
Returns the green color component of this color.
float redF() const noexcept
Returns the red color component of this color.
float alphaF() const noexcept
Returns the alpha color component of this color.
float blueF() const noexcept
Returns the blue color component of this color.
void setSourceRect(const QRectF &sourceRect)
void setInput(QQuickItem *input)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
The QQmlComponent class encapsulates a QML component definition.
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setSize(const QSizeF &size)
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void setParentItem(QQuickItem *parent)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
qreal width
This property holds the width of this item.
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
qreal height
This property holds the height of this item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
void polish()
Schedules a polish event for this item.
void setShadowOpacity(qreal shadowOpacity)
void setShadowColor(const QColor &color)
void setMaskSpreadAtMax(qreal spread)
bool maskInverted() const
void setColorizationColor(const QColor &color)
void setMaskThresholdMin(qreal threshold)
void updateEffectShaders()
void setColorization(qreal colorization)
void setShadowVerticalOffset(qreal offset)
void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
void setSource(QQuickItem *item)
qreal colorization() const
void setShadowBlur(qreal shadowBlur)
void setMaskSource(QQuickItem *item)
float blurWeight(float v)
QQuickItem * source() const
QString vertexShader() const
void updateShadowOffset()
~QQuickMultiEffectPrivate()
void setBlurMax(int blurMax)
QQuickMultiEffectPrivate()
void updateCenterOffset()
void setShadowScale(qreal shadowScale)
void updateProxyActiveCheck()
qreal maskSpreadAtMin() const
void setMaskThresholdMax(qreal threshold)
qreal shadowOpacity() const
QColor colorizationColor() const
qreal maskThresholdMax() const
void setShadowEnabled(bool enabled)
qreal shadowScale() const
void setMaskSpreadAtMin(qreal spread)
void updateMaskThresholdSpread()
void setBlurEnabled(bool enabled)
bool hasProxySource() const
QString fragmentShader() const
QQuickItem * maskSource() const
void setSaturation(qreal saturation)
qreal blurMultiplier() const
void proxyOutputChanged()
void updateBlurLevel(bool forceUpdate=false)
void setMaskInverted(bool inverted)
qreal shadowHorizontalOffset() const
void setBlurMultiplier(qreal blurMultiplier)
void setShadowHorizontalOffset(qreal offset)
float calculateLod(float blurAmount)
bool autoPaddingEnabled() const
void getBlurWeights(float blurLod, QVector4D &blurWeight1, QVector2D &blurWeight2)
QColor shadowColor() const
void setPaddingRect(const QRectF &rect)
qreal maskThresholdMin() const
void setContrast(qreal contrast)
void updateBlurItemSizes(bool forceUpdate=false)
qreal maskSpreadAtMax() const
void setBrightness(qreal brightness)
QRectF paddingRect() const
void updateColorizationColor()
void updateBlurItemsAmount(int blurLevel)
bool shadowEnabled() const
void handleGeometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void updateSourcePadding()
qreal shadowVerticalOffset() const
void updateShadowBlurWeights()
void setAutoPaddingEnabled(bool enabled)
void setMaskEnabled(bool enabled)
void setShadowHorizontalOffset(qreal offset)
qreal shadowHorizontalOffset
void setMaskEnabled(bool enabled)
void setBrightness(qreal brightness)
void setPaddingRect(const QRectF &rect)
void setShadowEnabled(bool enabled)
void setShadowOpacity(qreal shadowOpacity)
void setContrast(qreal contrast)
~QQuickMultiEffect() override
void setMaskSpreadAtMin(qreal spread)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void hasProxySourceChanged()
void setMaskThresholdMin(qreal threshold)
void setMaskInverted(bool inverted)
void setMaskThresholdMax(qreal threshold)
void setMaskSpreadAtMax(qreal spread)
void setSource(QQuickItem *item)
void setShadowBlur(qreal shadowBlur)
void setColorizationColor(const QColor &color)
qreal shadowVerticalOffset
void setShadowScale(qreal shadowScale)
void setAutoPaddingEnabled(bool enabled)
void setMaskSource(QQuickItem *item)
void setShadowColor(const QColor &color)
void setBlurMultiplier(qreal blurMultiplier)
void setBlurMax(int blurMax)
void setBlurEnabled(bool enabled)
void setSaturation(qreal saturation)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
void setColorization(qreal colorization)
void setShadowVerticalOffset(qreal offset)
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
void setFragmentShader(const QUrl &fileUrl)
void setVertexShader(const QUrl &fileUrl)
\inmodule QtCore\reentrant
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
constexpr qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVector2D class represents a vector or vertex in 2D space.
The QVector4D class represents a vector or vertex in 4D space.
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
qfloat16 qSqrt(qfloat16 f)
static QPointF centerOffset(const QSizeF &screenSize, const QRectF &visibleArea)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLsizei const GLfloat * v
[13]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum GLuint GLintptr offset
GLdouble GLdouble GLdouble GLdouble q
GLfloat GLfloat GLfloat alpha
GLenum GLenum GLenum GLenum GLenum scale
QQmlEngine * qmlEngine(const QObject *obj)
void forceUpdate(QQuickItem *item)
#define QStringLiteral(str)