From 4d15f5287905a2d8e4f4aa44494d01ecc3bf0cac Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 10 Nov 2014 14:22:05 +0100 Subject: [PATCH] Revert "Fix pixel bleed in BorderImage" This reverts commit a9238292145e05d36be7c35bdd50829c6400a3de. It also reverts follow-up commits: 87755d0437413cfb875c50e3dfa53030601567c9 c2c710e5a8d66fa696276aa69c2e3b00436eefe5 cc8a76ce8ea76afe912902067e95ca2abf9e482f The new implementation is much too slow because it will cause each section of the border image to be uploaded to the atlas, and it will not be shared between different border images nor between different sizes of the border. The performance regression is so significant that it's not worth it for the original bug fix. We leave the tests around, so some of those might regress due to this. Change-Id: I3f56f4564255ebb77e6487881a6a11b19ad0234e Task-number: QTBUG-42288 Task-number: QTBUG-35838 Reviewed-by: Michael Brasser --- src/quick/items/qquickborderimage.cpp | 424 ++++----------------------- src/quick/items/qquickborderimage_p.h | 2 - src/quick/items/qquickborderimage_p_p.h | 10 - src/quick/items/qquickimagebase_p_p.h | 3 - src/quick/scenegraph/qsgadaptationlayer_p.h | 12 - src/quick/scenegraph/qsgdefaultimagenode.cpp | 57 +--- src/quick/scenegraph/qsgdefaultimagenode_p.h | 3 +- 7 files changed, 72 insertions(+), 439 deletions(-) diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp index 07b8958..38bbc66 100644 --- a/src/quick/items/qquickborderimage.cpp +++ b/src/quick/items/qquickborderimage.cpp @@ -540,390 +540,90 @@ void QQuickBorderImage::doUpdate() update(); } -QImage QQuickBorderImage::shallowCopy(const QImage &image, const QRect &rect) -{ - if (image.depth() == 1) { - return image.copy(rect); - } else { - const uchar *bits = image.constBits() + image.bytesPerLine() * rect.y() + (image.depth() / 8) * rect.x(); - return QImage(bits, rect.width(), rect.height(), image.bytesPerLine(), image.format()); - } -} - QSGNode *QQuickBorderImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { Q_D(QQuickBorderImage); - if (!d->pix.isReady() || width() <= 0 || height() <= 0) { + QSGTexture *texture = d->sceneGraphRenderContext()->textureForFactory(d->pix.textureFactory(), window()); + + if (!texture || width() <= 0 || height() <= 0) { delete oldNode; return 0; } - // Don't implicitly create the scalegrid in the rendering thread... - QRectF innerSourceRect(0, 0, 1, 1); - QRectF innerTargetRect(0, 0, width(), height()); - int borderLeft = 0, borderTop = 0, borderRight = 0, borderBottom = 0; - - bool updateNode = !oldNode; - if (d->border) { - const QQuickScaleGrid *border = d->getScaleGrid(); - - borderLeft = qBound(0, border->left(), d->pix.width()); - borderTop = qBound(0, border->top(), d->pix.height()); - borderRight = d->pix.rect().width() - qBound(0, border->right(), d->pix.rect().width() - borderLeft); - borderBottom = d->pix.rect().height() - qBound(0, border->bottom(), d->pix.rect().height() - borderTop); - - innerSourceRect = QRectF(borderLeft / qreal(d->pix.width()), - borderTop / qreal(d->pix.height()), - qMax(0, borderRight - borderLeft) / d->pix.width(), - qMax(0, borderBottom - borderTop) / d->pix.height()); - innerTargetRect = QRectF(borderLeft, - borderTop, - qMax(0, width() - border->right() - border->left()), - qMax(0, height() - border->bottom() - border->top())); - - QSizeF newSize(width(), height()); - if (innerSourceRect != d->oldInnerSourceRect - || innerTargetRect != d->oldInnerTargetRect - || newSize != d->oldSize) { - updateNode = true; - } - - d->oldInnerSourceRect = innerSourceRect; - d->oldInnerTargetRect = innerTargetRect; - d->oldSize = newSize; - } + QSGImageNode *node = static_cast(oldNode); bool updatePixmap = d->pixmapChanged; d->pixmapChanged = false; - if (updateNode) { - delete oldNode; - oldNode = new QSGNode; + if (!node) { + node = d->sceneGraphContext()->createImageNode(); updatePixmap = true; - - for (int i=0; i<9; ++i) - d->regions[i].node = 0; - - if (innerSourceRect.left() > 0) { - if (innerSourceRect.top() > 0) { - QRectF rect(0, - 0, - innerTargetRect.left(), - innerTargetRect.top()); - - if (!rect.isEmpty()) { - d->regions[0].node = d->sceneGraphContext()->createImageNode(); - d->regions[0].node->setTargetRect(rect); - d->regions[0].node->setInnerTargetRect(rect); - d->regions[0].targetRect = rect; - } - } - - if (innerSourceRect.bottom() < 1) { - QRectF rect(0, - innerTargetRect.bottom(), - innerTargetRect.left(), - height() - innerTargetRect.height() - innerTargetRect.top()); - - if (!rect.isEmpty()) { - d->regions[6].node = d->sceneGraphContext()->createImageNode(); - d->regions[6].node->setTargetRect(rect); - d->regions[6].node->setInnerTargetRect(rect); - d->regions[6].targetRect = rect; - } - } - - if (innerSourceRect.top() < innerSourceRect.bottom()) { - QRectF rect(0, - innerTargetRect.top(), - innerTargetRect.left(), - innerTargetRect.height()); - - if (!rect.isEmpty()) { - d->regions[3].node = d->sceneGraphContext()->createImageNode(); - d->regions[3].node->setTargetRect(rect); - d->regions[3].node->setInnerTargetRect(rect); - d->regions[3].targetRect = rect; - } - } - } - - if (innerSourceRect.right() < 1) { - if (innerSourceRect.top() > 0) { - QRectF rect(innerTargetRect.right(), - 0, - width() - innerTargetRect.width() - innerTargetRect.left(), - innerTargetRect.top()); - - if (!rect.isEmpty()) { - d->regions[2].node = d->sceneGraphContext()->createImageNode(); - d->regions[2].node->setTargetRect(rect); - d->regions[2].node->setInnerTargetRect(rect); - d->regions[2].targetRect = rect; - } - } - - if (innerSourceRect.bottom() < 1) { - QRectF rect(innerTargetRect.right(), - innerTargetRect.bottom(), - width() - innerTargetRect.width() - innerTargetRect.left(), - height() - innerTargetRect.height() - innerTargetRect.top()); - - if (!rect.isEmpty()) { - d->regions[8].node = d->sceneGraphContext()->createImageNode(); - d->regions[8].node->setTargetRect(rect); - d->regions[8].node->setInnerTargetRect(rect); - d->regions[8].targetRect = rect; - } - } - - if (innerSourceRect.top() < innerSourceRect.bottom()) { - QRectF rect(innerTargetRect.right(), - innerTargetRect.top(), - width() - innerTargetRect.width() - innerTargetRect.left(), - innerTargetRect.height()); - - if (!rect.isEmpty()) { - d->regions[5].node = d->sceneGraphContext()->createImageNode(); - d->regions[5].node->setTargetRect(rect); - d->regions[5].node->setInnerTargetRect(rect); - d->regions[5].targetRect = rect; - } - } - } - - if (innerSourceRect.top() > 0 && innerSourceRect.left() < innerSourceRect.right()) { - QRectF rect(innerTargetRect.left(), - 0, - innerTargetRect.width(), - innerTargetRect.top()); - - if (!rect.isEmpty()) { - d->regions[1].node = d->sceneGraphContext()->createImageNode(); - d->regions[1].node->setTargetRect(rect); - d->regions[1].node->setInnerTargetRect(rect); - d->regions[1].targetRect = rect; - } - } - - if (innerSourceRect.bottom() < 1 && innerSourceRect.left() < innerSourceRect.right()) { - QRectF rect(innerTargetRect.left(), - innerTargetRect.bottom(), - innerTargetRect.width(), - height() - innerTargetRect.height() - innerTargetRect.top()); - - if (!rect.isEmpty()) { - d->regions[7].node = d->sceneGraphContext()->createImageNode(); - d->regions[7].node->setTargetRect(rect); - d->regions[7].node->setInnerTargetRect(rect); - d->regions[7].targetRect = rect; - } - } - - if (innerSourceRect.left() < innerSourceRect.right() - && innerSourceRect.top() < innerSourceRect.bottom()) { - if (!innerTargetRect.isEmpty()) { - d->regions[4].node = d->sceneGraphContext()->createImageNode(); - d->regions[4].node->setInnerTargetRect(innerTargetRect); - d->regions[4].node->setTargetRect(innerTargetRect); - d->regions[4].targetRect = innerTargetRect; - } - } - - for (int i=0; i<9; ++i) { - if (d->regions[i].node != 0) - oldNode->appendChildNode(d->regions[i].node); - } - } - - - QImage image = d->pix.image(); - - if (d->regions[0].node != 0) { - if (updatePixmap) - d->regions[0].image = shallowCopy(image, QRect(QPoint(0, 0), QSize(borderLeft, borderTop))); - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingFlags(QSGImageNode::AntialiasingLeft | QSGImageNode::AntialiasingTop); - if (d->regions[1].node == 0 && d->regions[2].node == 0) - antialiasing |= QSGImageNode::AntialiasingRight; - if (d->regions[3].node == 0 && d->regions[6].node == 0) - antialiasing |= QSGImageNode::AntialiasingBottom; - d->regions[0].node->setAntialiasing(antialiasing); } - if (d->regions[1].node != 0) { - if (updatePixmap) - d->regions[1].image = shallowCopy(image, QRect(QPoint(borderLeft, 0), QSize(borderRight - borderLeft, borderTop))); - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingTop; - if (d->regions[0].node == 0) - antialiasing |= QSGImageNode::AntialiasingLeft; - if (d->regions[2].node == 0) - antialiasing |= QSGImageNode::AntialiasingRight; - if (d->regions[4].node == 0 && d->regions[7].node == 0) - antialiasing |= QSGImageNode::AntialiasingBottom; - d->regions[1].node->setAntialiasing(antialiasing); - } - - if (d->regions[2].node != 0) { - if (updatePixmap) - d->regions[2].image = shallowCopy(image, QRect(QPoint(borderRight, 0), QSize(d->pix.rect().width() - borderRight, borderTop))); + if (updatePixmap) + node->setTexture(texture); - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingFlags(QSGImageNode::AntialiasingTop | QSGImageNode::AntialiasingRight); - if (d->regions[0].node == 0 && d->regions[1].node == 0) - antialiasing |= QSGImageNode::AntialiasingLeft; - if (d->regions[5].node == 0 && d->regions[8].node == 0) - antialiasing |= QSGImageNode::AntialiasingBottom; - d->regions[2].node->setAntialiasing(antialiasing); - } - - if (d->regions[3].node != 0) { - if (updatePixmap) - d->regions[3].image = shallowCopy(image, QRect(QPoint(0, borderTop), QSize(borderLeft, borderBottom - borderTop))); - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingLeft; - if (d->regions[4].node == 0 && d->regions[5].node == 0) - antialiasing |= QSGImageNode::AntialiasingRight; - if (d->regions[6].node == 0) - antialiasing |= QSGImageNode::AntialiasingBottom; - if (d->regions[0].node == 0) - antialiasing |= QSGImageNode::AntialiasingTop; - d->regions[3].node->setAntialiasing(antialiasing); + // Don't implicitly create the scalegrid in the rendering thread... + QRectF innerSourceRect(0, 0, 1, 1); + QRectF targetRect(0, 0, width(), height()); + QRectF innerTargetRect = targetRect; + if (d->border) { + const QQuickScaleGrid *border = d->getScaleGrid(); + innerSourceRect = QRectF(border->left() / qreal(d->pix.width()), + border->top() / qreal(d->pix.height()), + qMax(0, d->pix.width() - border->right() - border->left()) / d->pix.width(), + qMax(0, d->pix.height() - border->bottom() - border->top()) / d->pix.height()); + innerTargetRect = QRectF(border->left(), + border->top(), + qMax(0, width() - border->right() - border->left()), + qMax(0, height() - border->bottom() - border->top())); } - - if (d->regions[4].node != 0) { - if (updatePixmap) { - if (innerSourceRect == QRectF(0, 0, 1, 1)) { - d->regions[4].image = image; - } else { - d->regions[4].image = shallowCopy(image, QRect(QPoint(borderLeft, borderTop), QSize(borderRight - borderLeft, borderBottom - borderTop))); - } + qreal hTiles = 1; + qreal vTiles = 1; + if (innerSourceRect.width() != 0) { + switch (d->horizontalTileMode) { + case QQuickBorderImage::Repeat: + hTiles = innerTargetRect.width() / qreal(innerSourceRect.width() * d->pix.width()); + break; + case QQuickBorderImage::Round: + hTiles = qCeil(innerTargetRect.width() / qreal(innerSourceRect.width() * d->pix.width())); + break; + default: + break; } - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingNone; - if (d->regions[3].node == 0) - antialiasing |= QSGImageNode::AntialiasingLeft; - if (d->regions[5].node == 0) - antialiasing |= QSGImageNode::AntialiasingRight; - if (d->regions[1].node == 0) - antialiasing |= QSGImageNode::AntialiasingTop; - if (d->regions[7].node == 0) - antialiasing |= QSGImageNode::AntialiasingBottom; - d->regions[4].node->setAntialiasing(antialiasing); } - - if (d->regions[5].node != 0) { - if (updatePixmap) - d->regions[5].image = shallowCopy(image, QRect(QPoint(borderRight, borderTop), QSize(d->pix.rect().width() - borderRight, borderBottom - borderTop))); - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingRight; - if (d->regions[4].node == 0 && d->regions[3].node == 0) - antialiasing |= QSGImageNode::AntialiasingLeft; - if (d->regions[2].node == 0) - antialiasing |= QSGImageNode::AntialiasingTop; - if (d->regions[8].node == 0) - antialiasing |= QSGImageNode::AntialiasingBottom; - d->regions[5].node->setAntialiasing(antialiasing); - } - - if (d->regions[6].node != 0) { - if (updatePixmap) - d->regions[6].image = shallowCopy(image, QRect(QPoint(0, borderBottom), QSize(borderLeft, d->pix.rect().height() - borderBottom))); - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingFlags(QSGImageNode::AntialiasingBottom | QSGImageNode::AntialiasingLeft); - if (d->regions[7].node == 0 && d->regions[8].node == 0) - antialiasing |= QSGImageNode::AntialiasingRight; - if (d->regions[3].node == 0 && d->regions[0].node == 0) - antialiasing |= QSGImageNode::AntialiasingTop; - d->regions[6].node->setAntialiasing(antialiasing); - } - - if (d->regions[7].node != 0) { - if (updatePixmap) - d->regions[7].image = shallowCopy(image, QRect(QPoint(borderLeft, borderBottom), QSize(borderRight - borderLeft, d->pix.rect().height() - borderBottom))); - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingBottom; - if (d->regions[6].node == 0) - antialiasing |= QSGImageNode::AntialiasingLeft; - if (d->regions[8].node == 0) - antialiasing |= QSGImageNode::AntialiasingRight; - if (d->regions[4].node == 0 && d->regions[1].node == 0) - antialiasing |= QSGImageNode::AntialiasingTop; - d->regions[7].node->setAntialiasing(antialiasing); - } - - if (d->regions[8].node != 0) { - if (updatePixmap) - d->regions[8].image = shallowCopy(image, QRect(QPoint(borderRight, borderBottom), QSize(d->pix.rect().width() - borderRight, d->pix.rect().height() - borderBottom))); - - QSGImageNode::AntialiasingFlags antialiasing = QSGImageNode::AntialiasingFlags(QSGImageNode::AntialiasingBottom | QSGImageNode::AntialiasingRight); - if (d->regions[7].node == 0 && d->regions[6].node == 0) - antialiasing |= QSGImageNode::AntialiasingLeft; - if (d->regions[5].node == 0 && d->regions[2].node == 0) - antialiasing |= QSGImageNode::AntialiasingTop; - d->regions[8].node->setAntialiasing(antialiasing); + if (innerSourceRect.height() != 0) { + switch (d->verticalTileMode) { + case QQuickBorderImage::Repeat: + vTiles = innerTargetRect.height() / qreal(innerSourceRect.height() * d->pix.height()); + break; + case QQuickBorderImage::Round: + vTiles = qCeil(innerTargetRect.height() / qreal(innerSourceRect.height() * d->pix.height())); + break; + default: + break; + } } - for (int i=0; i<9; ++i) { - if (d->regions[i].node != 0) { - if (updatePixmap) { - QQuickTextureFactory *textureFactory = QSGContext::createTextureFactoryFromImage(d->regions[i].image); - if (textureFactory == 0) - textureFactory = new QQuickDefaultTextureFactory(d->regions[i].image); - d->regions[i].textureFactory.reset(textureFactory); - d->regions[i].node->setTexture(d->sceneGraphRenderContext()->textureForFactory(d->regions[i].textureFactory.data(), - window())); - } - - d->regions[i].node->setInnerSourceRect(QRectF(0, 0, 1, 1)); - d->regions[i].node->setMipmapFiltering(QSGTexture::None); - d->regions[i].node->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest); - d->regions[i].node->setMirror(d->mirror); - - - qreal hTiles = 1; - qreal vTiles = 1; - - if (innerSourceRect.width() != 0) { - switch (d->horizontalTileMode) { - case QQuickBorderImage::Repeat: - hTiles = d->regions[i].targetRect.width() / qreal(d->regions[i].image.width()); - break; - case QQuickBorderImage::Round: - hTiles = qCeil(d->regions[i].targetRect.width() / qreal(d->regions[i].image.width())); - break; - default: - break; - } - } - - if (innerSourceRect.height() != 0) { - switch (d->verticalTileMode) { - case QQuickBorderImage::Repeat: - vTiles = d->regions[i].targetRect.height() / qreal(d->regions[i].image.height()); - break; - case QQuickBorderImage::Round: - vTiles = qCeil(d->regions[i].targetRect.height() / qreal(d->regions[i].image.height())); - break; - default: - break; - } - } - - if (vTiles > 1 || hTiles > 1) { - d->regions[i].node->setHorizontalWrapMode(QSGTexture::Repeat); - d->regions[i].node->setVerticalWrapMode(QSGTexture::Repeat); - } else { - d->regions[i].node->setHorizontalWrapMode(QSGTexture::ClampToEdge); - d->regions[i].node->setVerticalWrapMode(QSGTexture::ClampToEdge); - } - - d->regions[i].node->setSubSourceRect(QRectF(0, 0, hTiles, vTiles)); - d->regions[i].node->update(); - } + node->setTargetRect(targetRect); + node->setInnerSourceRect(innerSourceRect); + node->setInnerTargetRect(innerTargetRect); + node->setSubSourceRect(QRectF(0, 0, hTiles, vTiles)); + node->setMirror(d->mirror); + + node->setMipmapFiltering(QSGTexture::None); + node->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest); + if (innerSourceRect == QRectF(0, 0, 1, 1) && (vTiles > 1 || hTiles > 1)) { + node->setHorizontalWrapMode(QSGTexture::Repeat); + node->setVerticalWrapMode(QSGTexture::Repeat); + } else { + node->setHorizontalWrapMode(QSGTexture::ClampToEdge); + node->setVerticalWrapMode(QSGTexture::ClampToEdge); } + node->setAntialiasing(d->antialiasing); + node->update(); - return oldNode; + return node; } void QQuickBorderImage::pixmapChange() diff --git a/src/quick/items/qquickborderimage_p.h b/src/quick/items/qquickborderimage_p.h index 1d08981..6a2469a 100644 --- a/src/quick/items/qquickborderimage_p.h +++ b/src/quick/items/qquickborderimage_p.h @@ -87,8 +87,6 @@ private Q_SLOTS: void sciRequestFinished(); private: - static QImage shallowCopy(const QImage &image, const QRect &rect); - Q_DISABLE_COPY(QQuickBorderImage) Q_DECLARE_PRIVATE(QQuickBorderImage) }; diff --git a/src/quick/items/qquickborderimage_p_p.h b/src/quick/items/qquickborderimage_p_p.h index bda2867..d5b959f 100644 --- a/src/quick/items/qquickborderimage_p_p.h +++ b/src/quick/items/qquickborderimage_p_p.h @@ -89,16 +89,6 @@ public: QQuickBorderImage::TileMode verticalTileMode; int redirectCount; - struct BorderImageRegion - { - BorderImageRegion() : node(0), textureFactory(0) {} - QImage image; - QSGImageNode *node; - QScopedPointer textureFactory; - QRectF targetRect; - }; - BorderImageRegion regions[9]; - bool pixmapChanged : 1; }; diff --git a/src/quick/items/qquickimagebase_p_p.h b/src/quick/items/qquickimagebase_p_p.h index 21d11a7..f30eacb 100644 --- a/src/quick/items/qquickimagebase_p_p.h +++ b/src/quick/items/qquickimagebase_p_p.h @@ -75,9 +75,6 @@ public: QSize sourcesize; QSize oldSourceSize; qreal devicePixelRatio; - QRectF oldInnerSourceRect; - QRectF oldInnerTargetRect; - QSizeF oldSize; bool async : 1; bool cache : 1; bool mirror: 1; diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h index 962fc5a..ef21385 100644 --- a/src/quick/scenegraph/qsgadaptationlayer_p.h +++ b/src/quick/scenegraph/qsgadaptationlayer_p.h @@ -126,17 +126,6 @@ public: class Q_QUICK_PRIVATE_EXPORT QSGImageNode : public QSGVisitableNode { public: - enum AntialiasingFlag - { - AntialiasingNone = 0, - AntialiasingLeft = 1, - AntialiasingRight = 2, - AntialiasingTop = 4, - AntialiasingBottom = 8, - AntialiasingAll = AntialiasingLeft | AntialiasingRight | AntialiasingBottom | AntialiasingTop - }; - Q_DECLARE_FLAGS(AntialiasingFlags, AntialiasingFlag) - virtual void setTargetRect(const QRectF &rect) = 0; virtual void setInnerTargetRect(const QRectF &rect) = 0; virtual void setInnerSourceRect(const QRectF &rect) = 0; @@ -151,7 +140,6 @@ public: virtual void setFiltering(QSGTexture::Filtering filtering) = 0; virtual void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) = 0; virtual void setVerticalWrapMode(QSGTexture::WrapMode wrapMode) = 0; - virtual void setAntialiasing(AntialiasingFlags flags) { Q_UNUSED(flags); } virtual void update() = 0; diff --git a/src/quick/scenegraph/qsgdefaultimagenode.cpp b/src/quick/scenegraph/qsgdefaultimagenode.cpp index 69df506..7f85c31 100644 --- a/src/quick/scenegraph/qsgdefaultimagenode.cpp +++ b/src/quick/scenegraph/qsgdefaultimagenode.cpp @@ -140,11 +140,10 @@ void SmoothTextureMaterialShader::initialize() QSGDefaultImageNode::QSGDefaultImageNode() : m_innerSourceRect(0, 0, 1, 1) , m_subSourceRect(0, 0, 1, 1) + , m_antialiasing(false) , m_mirror(false) , m_dirtyGeometry(false) , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) - , m_antialiasing(AntialiasingNone) - { setMaterial(&m_materialO); setOpaqueMaterial(&m_material); @@ -250,20 +249,10 @@ void QSGDefaultImageNode::setTexture(QSGTexture *texture) void QSGDefaultImageNode::setAntialiasing(bool antialiasing) { - AntialiasingFlags antialiasingFlags = antialiasing - ? AntialiasingAll - : AntialiasingNone; - - setAntialiasing(antialiasingFlags); -} - -void QSGDefaultImageNode::setAntialiasing(AntialiasingFlags antialiasingFlags) -{ - if (antialiasingFlags == m_antialiasing) + if (antialiasing == m_antialiasing) return; - - m_antialiasing = antialiasingFlags; - if (m_antialiasing != AntialiasingNone) { + m_antialiasing = antialiasing; + if (m_antialiasing) { setMaterial(&m_smoothMaterial); setOpaqueMaterial(0); setGeometry(new QSGGeometry(smoothAttributeSet(), 0)); @@ -375,14 +364,11 @@ void QSGDefaultImageNode::updateGeometry() } // An image can be rendered as a single quad if: - // - There is antialiasing on all or no edges // - There are no margins, and either: // - the image isn't repeated // - the source rectangle fills the entire texture so that texture wrapping can be used, // and NPOT is supported - if (!hasMargins - && (m_antialiasing == AntialiasingAll || m_antialiasing == AntialiasingNone) - && (!hasTiles || (fullTexture && wrapSupported))) { + if (!hasMargins && (!hasTiles || (fullTexture && wrapSupported))) { QRectF sr; if (!fullTexture) { sr = QRectF(innerSourceRect.x() + (m_subSourceRect.left() - floorLeft) * innerSourceRect.width(), @@ -561,35 +547,10 @@ void QSGDefaultImageNode::updateGeometry() topDv = bottomDv *= 0.5f; } - if (!m_antialiasing.testFlag(AntialiasingTop)) { - topDy = 0.0f; - topDv = 0.0f; - } - - if (!m_antialiasing.testFlag(AntialiasingBottom)) { - bottomDy = 0.0f; - bottomDv = 0.0f; - } - - if (!m_antialiasing.testFlag(AntialiasingLeft)) { - leftDx = 0.0f; - leftDu = 0.0f; - } - - if (!m_antialiasing.testFlag(AntialiasingRight)) { - rightDx = 0.0f; - rightDu = 0.0f; - } - // This delta is how much the fuzziness can reach out from the image. float delta = float(qAbs(m_targetRect.width()) < qAbs(m_targetRect.height()) ? m_targetRect.width() : m_targetRect.height()) * 0.5f; - float deltaTop = m_antialiasing.testFlag(AntialiasingTop) ? delta : 0.0f; - float deltaBottom = m_antialiasing.testFlag(AntialiasingBottom) ? delta : 0.0f; - float deltaLeft = m_antialiasing.testFlag(AntialiasingLeft) ? delta : 0.0f; - float deltaRight = m_antialiasing.testFlag(AntialiasingRight) ? delta : 0.0f; - quint16 index = 0; ys = yData.data(); for (int j = 0; j < vCells; ++j, ys += 2) { @@ -639,28 +600,28 @@ void QSGDefaultImageNode::updateGeometry() if (isTop) { vertices[topLeft].dy = vertices[topRight].dy = topDy; vertices[topLeft].dv = vertices[topRight].dv = topDv; - vertices[topLeft + 1].dy = vertices[topRight + 1].dy = -deltaTop; + vertices[topLeft + 1].dy = vertices[topRight + 1].dy = -delta; appendQuad(&indices, topLeft + 1, topRight + 1, topLeft, topRight); } if (isBottom) { vertices[bottomLeft].dy = vertices[bottomRight].dy = -bottomDy; vertices[bottomLeft].dv = vertices[bottomRight].dv = -bottomDv; - vertices[bottomLeft + 1].dy = vertices[bottomRight + 1].dy = deltaBottom; + vertices[bottomLeft + 1].dy = vertices[bottomRight + 1].dy = delta; appendQuad(&indices, bottomLeft, bottomRight, bottomLeft + 1, bottomRight + 1); } if (isLeft) { vertices[topLeft].dx = vertices[bottomLeft].dx = leftDx; vertices[topLeft].du = vertices[bottomLeft].du = leftDu; - vertices[topLeft + 1].dx = vertices[bottomLeft + 1].dx = -deltaLeft; + vertices[topLeft + 1].dx = vertices[bottomLeft + 1].dx = -delta; appendQuad(&indices, topLeft + 1, topLeft, bottomLeft + 1, bottomLeft); } if (isRight) { vertices[topRight].dx = vertices[bottomRight].dx = -rightDx; vertices[topRight].du = vertices[bottomRight].du = -rightDu; - vertices[topRight + 1].dx = vertices[bottomRight + 1].dx = deltaRight; + vertices[topRight + 1].dx = vertices[bottomRight + 1].dx = delta; appendQuad(&indices, topRight, topRight + 1, bottomRight, bottomRight + 1); } } diff --git a/src/quick/scenegraph/qsgdefaultimagenode_p.h b/src/quick/scenegraph/qsgdefaultimagenode_p.h index 558e4d8..26b0872 100644 --- a/src/quick/scenegraph/qsgdefaultimagenode_p.h +++ b/src/quick/scenegraph/qsgdefaultimagenode_p.h @@ -62,7 +62,6 @@ public: virtual void setSubSourceRect(const QRectF &rect); virtual void setTexture(QSGTexture *t); virtual void setAntialiasing(bool antialiasing); - virtual void setAntialiasing(AntialiasingFlags antialiasing); virtual void setMirror(bool mirror); virtual void update(); @@ -85,11 +84,11 @@ private: QSGTextureMaterial m_materialO; QSGSmoothTextureMaterial m_smoothMaterial; + uint m_antialiasing : 1; uint m_mirror : 1; uint m_dirtyGeometry : 1; QSGGeometry m_geometry; - AntialiasingFlags m_antialiasing; }; QT_END_NAMESPACE -- 2.7.4