[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: remove unused class
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Mon Jul 25 18:41:17 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
8afb6b9b by Prince Gupta at 2022-07-25T18:25:04+00:00
qt: remove unused class
- - - - -
75f7213a by Prince Gupta at 2022-07-25T18:25:04+00:00
qt: fix image response handling
only delete image response on finished
documentation of QQuickImageResponse mentions that a response may only
be deleted after QQuickImageResponse::finished signal
quote from QQuickImageResponse::cancel signal
```
Note: finished() should not be emitted until the response is complete,
regardless of whether or not cancel() was called. If it is called
prematurely, the engine may destroy the response while it is still active
, leading to a crash.
```
- - - - -
2 changed files:
- modules/gui/qt/widgets/native/roundimage.cpp
- modules/gui/qt/widgets/native/roundimage.hpp
Changes:
=====================================
modules/gui/qt/widgets/native/roundimage.cpp
=====================================
@@ -244,68 +244,6 @@ namespace
};
#endif
- class ImageProviderAsyncAdaptor : public QQuickImageResponse
- {
- public:
- ImageProviderAsyncAdaptor(QQuickImageProvider *provider, const QString &id, const QSize &requestedSize, const qreal radius)
- {
- task.reset(new ProviderImageGetter(provider, id, requestedSize, radius));
- connect(task.get(), &ProviderImageGetter::result, this, [this]()
- {
- result = task->takeResult();
- task.reset();
-
- emit finished();
- });
-
- task->start(*QThreadPool::globalInstance());
- }
-
- QQuickTextureFactory *textureFactory() const override
- {
- return result.isNull() ? nullptr : QQuickTextureFactory::textureFactoryForImage(result);
- }
-
- private:
- class ProviderImageGetter : public AsyncTask<QImage>
- {
- public:
- ProviderImageGetter(QQuickImageProvider *provider, const QString &id, const QSize &requestedSize, const qreal radius)
- : provider {provider}
- , id{id}
- , requestedSize{requestedSize}
- , radius {radius}
- {
- }
-
- QImage execute() override
- {
- auto img = provider->requestImage(id, &sourceSize, requestedSize);
- if (!img.isNull())
- {
- QSize targetSize = sourceSize;
- if (requestedSize.isValid())
- targetSize.scale(requestedSize, Qt::KeepAspectRatioByExpanding);
-
- applyRadius(targetSize, radius, img);
- }
-
- return img;
- }
-
- private:
- QQuickImageProvider *provider;
- QString id;
- QSize requestedSize;
- qreal radius;
- QSize sourceSize;
- };
-
- TaskHandle<ProviderImageGetter> task;
- QImage result;
- };
-
-
// adapts a given QQuickImageResponse to produce a image with radius
class ImageResponseRadiusAdaptor : public QQuickImageResponse
{
@@ -383,13 +321,10 @@ namespace
if (!provider)
return nullptr;
- assert(provider->imageType() == QQmlImageProviderBase::Image
- || provider->imageType() == QQmlImageProviderBase::ImageResponse);
+ assert(provider->imageType() == QQmlImageProviderBase::ImageResponse);
const auto imageId = url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);;
- if (provider->imageType() == QQmlImageProviderBase::Image)
- return new ImageProviderAsyncAdaptor(static_cast<QQuickImageProvider *>(provider), imageId, requestedSize, radius);
if (provider->imageType() == QQmlImageProviderBase::ImageResponse)
{
auto rawImageResponse = static_cast<QQuickAsyncImageProvider *>(provider)->requestImageResponse(imageId, requestedSize);
@@ -425,7 +360,7 @@ RoundImage::RoundImage(QQuickItem *parent) : QQuickItem {parent}
RoundImage::~RoundImage()
{
- resetImageRequest();
+ resetImageResponse(true);
}
QSGNode *RoundImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
@@ -535,17 +470,17 @@ void RoundImage::setDPR(const qreal value)
regenerateRoundImage();
}
-void RoundImage::handleImageRequestFinished()
+void RoundImage::handleImageResponseFinished()
{
- const QString error = m_activeImageRequest->errorString();
+ const QString error = m_activeImageResponse->errorString();
QImage image;
- if (auto textureFactory = m_activeImageRequest->textureFactory())
+ if (auto textureFactory = m_activeImageResponse->textureFactory())
{
image = textureFactory->image();
delete textureFactory;
}
- resetImageRequest();
+ resetImageResponse(false);
if (image.isNull())
{
@@ -566,14 +501,16 @@ void RoundImage::handleImageRequestFinished()
imageCache.insert(key, new QImage(image), image.sizeInBytes());
}
-void RoundImage::resetImageRequest()
+void RoundImage::resetImageResponse(bool cancel)
{
- if (!m_activeImageRequest)
+ if (!m_activeImageResponse)
return;
- m_activeImageRequest->disconnect(this);
- m_activeImageRequest->deleteLater();
- m_activeImageRequest = nullptr;
+ if (cancel)
+ m_activeImageResponse->cancel();
+
+ m_activeImageResponse->disconnect(this);
+ m_activeImageResponse = nullptr;
}
void RoundImage::load()
@@ -596,8 +533,10 @@ void RoundImage::load()
return;
}
- m_activeImageRequest = getAsyncImageResponse(source(), QSizeF {scaledWidth, scaledHeight}.toSize(), scaledRadius, engine);
- connect(m_activeImageRequest, &QQuickImageResponse::finished, this, &RoundImage::handleImageRequestFinished);
+ m_activeImageResponse = getAsyncImageResponse(source(), QSizeF {scaledWidth, scaledHeight}.toSize(), scaledRadius, engine);
+
+ connect(m_activeImageResponse, &QQuickImageResponse::finished, this, &RoundImage::handleImageResponseFinished);
+ connect(m_activeImageResponse, &QQuickImageResponse::finished, m_activeImageResponse, &QObject::deleteLater);
}
void RoundImage::setRoundImage(QImage image)
@@ -633,7 +572,7 @@ void RoundImage::regenerateRoundImage()
// remove old contents
setRoundImage({});
- resetImageRequest();
+ resetImageResponse(true);
// use Qt::QueuedConnection to delay generation, so that dependent properties
// subsequent updates can be merged, f.e when VLCStyle.scale changes
=====================================
modules/gui/qt/widgets/native/roundimage.hpp
=====================================
@@ -77,8 +77,8 @@ protected:
private:
void setDPR(qreal value);
- void handleImageRequestFinished();
- void resetImageRequest();
+ void handleImageResponseFinished();
+ void resetImageResponse(bool cancel);
void load();
void setRoundImage(QImage image);
void setStatus(const Status status);
@@ -92,7 +92,7 @@ private:
QImage m_roundImage;
bool m_dirty = false;
- QQuickImageResponse *m_activeImageRequest {};
+ QQuickImageResponse *m_activeImageResponse {};
bool m_enqueuedGeneration = false;
};
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/61556384147016a0a43351af9c13f1a898c85a89...75f7213abfc5c1623a0c520d16887f9f3b6aecb8
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/61556384147016a0a43351af9c13f1a898c85a89...75f7213abfc5c1623a0c520d16887f9f3b6aecb8
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list