Prevent QPixmap::load from touching QPixmapCache in non-gui threads
Change-Id: Ied0fec48c81298743f694f317dd60e58d356f69a Fixes: QTBUG-72523 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
parent
3b514f8535
commit
9bbeb7e6e8
@ -714,8 +714,8 @@ QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode)
|
|||||||
control the conversion.
|
control the conversion.
|
||||||
|
|
||||||
Note that QPixmaps are automatically added to the QPixmapCache
|
Note that QPixmaps are automatically added to the QPixmapCache
|
||||||
when loaded from a file; the key used is internal and can not
|
when loaded from a file in main thread; the key used is internal
|
||||||
be acquired.
|
and cannot be acquired.
|
||||||
|
|
||||||
\sa loadFromData(), {QPixmap#Reading and Writing Image
|
\sa loadFromData(), {QPixmap#Reading and Writing Image
|
||||||
Files}{Reading and Writing Image Files}
|
Files}{Reading and Writing Image Files}
|
||||||
@ -729,6 +729,7 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
|
|||||||
// Note: If no extension is provided, we try to match the
|
// Note: If no extension is provided, we try to match the
|
||||||
// file against known plugin extensions
|
// file against known plugin extensions
|
||||||
if (info.completeSuffix().isEmpty() || info.exists()) {
|
if (info.completeSuffix().isEmpty() || info.exists()) {
|
||||||
|
const bool inGuiThread = qApp->thread() == QThread::currentThread();
|
||||||
|
|
||||||
QString key = QLatin1String("qt_pixmap")
|
QString key = QLatin1String("qt_pixmap")
|
||||||
% info.absoluteFilePath()
|
% info.absoluteFilePath()
|
||||||
@ -736,12 +737,13 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
|
|||||||
% HexString<quint64>(info.size())
|
% HexString<quint64>(info.size())
|
||||||
% HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType);
|
% HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType);
|
||||||
|
|
||||||
if (QPixmapCache::find(key, this))
|
if (inGuiThread && QPixmapCache::find(key, this))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
data = QPlatformPixmap::create(0, 0, data ? data->pixelType() : QPlatformPixmap::PixmapType);
|
data = QPlatformPixmap::create(0, 0, data ? data->pixelType() : QPlatformPixmap::PixmapType);
|
||||||
|
|
||||||
if (data->fromFile(fileName, format, flags)) {
|
if (data->fromFile(fileName, format, flags)) {
|
||||||
|
if (inGuiThread)
|
||||||
QPixmapCache::insert(key, *this);
|
QPixmapCache::insert(key, *this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user