Merge branch 'qt/smartresize' into 'master'

qt: do not empty the content on size change if source is the same in RoundImage

See merge request videolan/vlc!4040
This commit is contained in:
Fatih Uzunoğlu 2024-04-28 07:10:48 +00:00
commit 5100d2caae
2 changed files with 21 additions and 5 deletions

View File

@ -333,15 +333,18 @@ QSGNode *RoundImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
oldNode = nullptr;
}
if (m_roundImage.isNull())
if (m_dirty && m_roundImage.isNull())
{
delete oldNode;
m_dirty = false;
m_oldSource.clear();
return nullptr;
}
if (!oldNode)
{
assert(!m_roundImage.isNull());
if (m_QSGCustomGeometry)
{
customImageNode = new QSGRoundedRectangularImageNode;
@ -353,12 +356,15 @@ QSGNode *RoundImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
assert(imageNode);
imageNode->setOwnsTexture(true);
}
m_dirty = true;
}
if (m_dirty)
{
m_dirty = false;
assert(window());
assert(!m_roundImage.isNull());
QQuickWindow::CreateTextureOptions flags = QQuickWindow::TextureCanUseAtlas;
@ -383,6 +389,8 @@ QSGNode *RoundImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
}
}
m_oldSource = m_source;
// Geometry:
if (m_QSGCustomGeometry)
{
@ -459,6 +467,9 @@ void RoundImage::itemChange(QQuickItem::ItemChange change, const QQuickItem::Ite
if (change == QQuickItem::ItemDevicePixelRatioHasChanged)
setDPR(value.realValue);
if (change == QQuickItem::ItemVisibleHasChanged && !isVisible())
m_oldSource.clear();
QQuickItem::itemChange(change, value);
}
@ -503,7 +514,8 @@ void RoundImage::load()
connect(m_activeImageResponse.get(), &RoundImageRequest::requestCompleted, this, &RoundImage::onRequestCompleted);
//at this point m_activeImageResponse is either in Loading or Error status
onRequestCompleted(RoundImage::Loading, {});
if (m_source != m_oldSource)
onRequestCompleted(RoundImage::Loading, {});
}
void RoundImage::onRequestCompleted(Status status, const QImage& image)
@ -564,10 +576,13 @@ void RoundImage::regenerateRoundImage()
if (!isComponentComplete() || m_enqueuedGeneration)
return;
setStatus(source().isEmpty() ? Status::Null : Status::Loading);
if (m_oldSource != m_source)
{
setStatus(source().isEmpty() ? Status::Null : Status::Loading);
// remove old contents
setRoundImage({});
// remove old contents
setRoundImage({});
}
m_activeImageResponse.reset();

View File

@ -99,6 +99,7 @@ private:
bool m_enqueuedGeneration = false;
QUrl m_source;
QUrl m_oldSource;
qreal m_radius = 0.0;
qreal m_dpr = 1.0; // device pixel ratio
bool m_cache = true;