summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qimagereader.cpp2
-rw-r--r--src/gui/image/qpixmapcache.cpp33
-rw-r--r--src/gui/opengl/qopengltextureglyphcache.cpp4
-rw-r--r--src/gui/opengl/qopengltextureglyphcache_p.h2
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp4
-rw-r--r--src/gui/painting/qtextureglyphcache.cpp2
-rw-r--r--src/gui/painting/qtextureglyphcache_p.h8
-rw-r--r--src/gui/text/qfontengine.cpp12
-rw-r--r--src/gui/text/qfontengine_p.h4
-rw-r--r--src/gui/text/qfontengineglyphcache_p.h7
10 files changed, 61 insertions, 17 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index ade6a9eaaa..360cc16319 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -1074,7 +1074,7 @@ QList<QByteArray> QImageReader::supportedSubTypes() const
\since 5.5
Returns the transformation metadata of the image, including image orientation. If the format
- does not support transformation metadata \c QImageIOHandler::Transformation_None is returned.
+ does not support transformation metadata, QImageIOHandler::TransformationNone is returned.
\sa setAutoTransform(), autoTransform()
*/
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 66907bebd7..f6684eac7d 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -42,6 +42,8 @@
#include "qobject.h"
#include "qdebug.h"
#include "qpixmapcache_p.h"
+#include "qthread.h"
+#include "qcoreapplication.h"
QT_BEGIN_NAMESPACE
@@ -83,6 +85,9 @@ QT_BEGIN_NAMESPACE
with QPixmapCache} explains how to use QPixmapCache to speed up
applications by caching the results of painting.
+ \note QPixmapCache is only usable from the application's main thread.
+ Access from other threads will be ignored and return failure.
+
\sa QCache, QPixmap
*/
@@ -98,6 +103,14 @@ static inline int cost(const QPixmap &pixmap)
return static_cast<int>(qBound(1LL, costKb, costMax));
}
+static inline bool qt_pixmapcache_thread_test()
+{
+ if (Q_LIKELY(QCoreApplication::instance() && QThread::currentThread() == QCoreApplication::instance()->thread()))
+ return true;
+
+ return false;
+}
+
/*!
\class QPixmapCache::Key
\brief The QPixmapCache::Key class can be used for efficient access
@@ -490,6 +503,8 @@ QPixmapCacheEntry::~QPixmapCacheEntry()
QPixmap *QPixmapCache::find(const QString &key)
{
+ if (!qt_pixmapcache_thread_test())
+ return nullptr;
return pm_cache()->object(key);
}
@@ -519,6 +534,8 @@ bool QPixmapCache::find(const QString &key, QPixmap &pixmap)
bool QPixmapCache::find(const QString &key, QPixmap *pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
QPixmap *ptr = pm_cache()->object(key);
if (ptr && pixmap)
*pixmap = *ptr;
@@ -536,6 +553,8 @@ bool QPixmapCache::find(const QString &key, QPixmap *pixmap)
*/
bool QPixmapCache::find(const Key &key, QPixmap *pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
//The key is not valid anymore, a flush happened before probably
if (!key.d || !key.d->isValid)
return false;
@@ -567,6 +586,8 @@ bool QPixmapCache::find(const Key &key, QPixmap *pixmap)
bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
return pm_cache()->insert(key, pixmap, cost(pixmap));
}
@@ -587,6 +608,8 @@ bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
*/
QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return QPixmapCache::Key();
return pm_cache()->insert(pixmap, cost(pixmap));
}
@@ -601,6 +624,8 @@ QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
*/
bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)
{
+ if (!qt_pixmapcache_thread_test())
+ return false;
//The key is not valid anymore, a flush happened before probably
if (!key.d || !key.d->isValid)
return false;
@@ -630,6 +655,8 @@ int QPixmapCache::cacheLimit()
void QPixmapCache::setCacheLimit(int n)
{
+ if (!qt_pixmapcache_thread_test())
+ return;
pm_cache()->setMaxCost(n);
}
@@ -638,6 +665,8 @@ void QPixmapCache::setCacheLimit(int n)
*/
void QPixmapCache::remove(const QString &key)
{
+ if (!qt_pixmapcache_thread_test())
+ return;
pm_cache()->remove(key);
}
@@ -649,6 +678,8 @@ void QPixmapCache::remove(const QString &key)
*/
void QPixmapCache::remove(const Key &key)
{
+ if (!qt_pixmapcache_thread_test())
+ return;
//The key is not valid anymore, a flush happened before probably
if (!key.d || !key.d->isValid)
return;
@@ -661,6 +692,8 @@ void QPixmapCache::remove(const Key &key)
void QPixmapCache::clear()
{
+ if (!QCoreApplication::closingDown() && !qt_pixmapcache_thread_test())
+ return;
QT_TRY {
if (pm_cache.exists())
pm_cache->clear();
diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp
index e3cbba955d..490dc99749 100644
--- a/src/gui/opengl/qopengltextureglyphcache.cpp
+++ b/src/gui/opengl/qopengltextureglyphcache.cpp
@@ -53,8 +53,8 @@ static int next_qopengltextureglyphcache_serial_number()
return 1 + serial.fetchAndAddRelaxed(1);
}
-QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
- : QImageTextureGlyphCache(format, matrix)
+QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color)
+ : QImageTextureGlyphCache(format, matrix, color)
, m_textureResource(0)
, pex(0)
, m_blitProgram(0)
diff --git a/src/gui/opengl/qopengltextureglyphcache_p.h b/src/gui/opengl/qopengltextureglyphcache_p.h
index 598cb00ee5..38c9aede7d 100644
--- a/src/gui/opengl/qopengltextureglyphcache_p.h
+++ b/src/gui/opengl/qopengltextureglyphcache_p.h
@@ -110,7 +110,7 @@ public:
class Q_GUI_EXPORT QOpenGLTextureGlyphCache : public QImageTextureGlyphCache
{
public:
- QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat glyphFormat, const QTransform &matrix);
+ QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat glyphFormat, const QTransform &matrix, const QColor &color = QColor());
~QOpenGLTextureGlyphCache();
virtual void createTextureData(int width, int height) override;
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 2d2041c907..4b06afd4eb 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -2927,9 +2927,9 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs,
QFontEngine::GlyphFormat glyphFormat = fontEngine->glyphFormat != QFontEngine::Format_None ? fontEngine->glyphFormat : d->glyphCacheFormat;
QImageTextureGlyphCache *cache =
- static_cast<QImageTextureGlyphCache *>(fontEngine->glyphCache(0, glyphFormat, s->matrix));
+ static_cast<QImageTextureGlyphCache *>(fontEngine->glyphCache(0, glyphFormat, s->matrix, QColor(s->penData.solidColor)));
if (!cache) {
- cache = new QImageTextureGlyphCache(glyphFormat, s->matrix);
+ cache = new QImageTextureGlyphCache(glyphFormat, s->matrix, QColor(s->penData.solidColor));
fontEngine->setGlyphCache(0, cache);
}
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp
index 99b04aaba6..06fa4bf95e 100644
--- a/src/gui/painting/qtextureglyphcache.cpp
+++ b/src/gui/painting/qtextureglyphcache.cpp
@@ -267,7 +267,7 @@ QImage QTextureGlyphCache::textureMapForGlyph(glyph_t g, QFixed subPixelPosition
case QFontEngine::Format_A32:
return m_current_fontengine->alphaRGBMapForGlyph(g, subPixelPosition, m_transform);
case QFontEngine::Format_ARGB:
- return m_current_fontengine->bitmapForGlyph(g, subPixelPosition, m_transform);
+ return m_current_fontengine->bitmapForGlyph(g, subPixelPosition, m_transform, color());
default:
return m_current_fontengine->alphaMapForGlyph(g, subPixelPosition, m_transform);
}
diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h
index 3da28872b1..c105e89e50 100644
--- a/src/gui/painting/qtextureglyphcache_p.h
+++ b/src/gui/painting/qtextureglyphcache_p.h
@@ -74,8 +74,8 @@ class QTextItemInt;
class Q_GUI_EXPORT QTextureGlyphCache : public QFontEngineGlyphCache
{
public:
- QTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
- : QFontEngineGlyphCache(format, matrix), m_current_fontengine(0),
+ QTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
+ : QFontEngineGlyphCache(format, matrix, color), m_current_fontengine(0),
m_w(0), m_h(0), m_cx(0), m_cy(0), m_currentRowHeight(0)
{ }
@@ -165,8 +165,8 @@ inline uint qHash(const QTextureGlyphCache::GlyphAndSubPixelPosition &g)
class Q_GUI_EXPORT QImageTextureGlyphCache : public QTextureGlyphCache
{
public:
- QImageTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
- : QTextureGlyphCache(format, matrix) { }
+ QImageTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
+ : QTextureGlyphCache(format, matrix, color) { }
~QImageTextureGlyphCache();
virtual void createTextureData(int width, int height) override;
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 1719855e68..e435177843 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -899,7 +899,7 @@ QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed /*subPixelPosition
return rgbMask;
}
-QImage QFontEngine::bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform&)
+QImage QFontEngine::bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform&, const QColor &)
{
Q_UNUSED(subPixelPosition);
@@ -1075,7 +1075,10 @@ void QFontEngine::setGlyphCache(const void *context, QFontEngineGlyphCache *cach
}
-QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context, GlyphFormat format, const QTransform &transform) const
+QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context,
+ GlyphFormat format,
+ const QTransform &transform,
+ const QColor &color) const
{
const QHash<const void*, GlyphCaches>::const_iterator caches = m_glyphCaches.constFind(context);
if (caches == m_glyphCaches.cend())
@@ -1083,8 +1086,11 @@ QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context, GlyphFormat
for (GlyphCaches::const_iterator it = caches->begin(), end = caches->end(); it != end; ++it) {
QFontEngineGlyphCache *cache = it->cache.data();
- if (format == cache->glyphFormat() && qtransform_equals_no_translate(cache->m_transform, transform))
+ if (format == cache->glyphFormat()
+ && (format != Format_ARGB || color == cache->color())
+ && qtransform_equals_no_translate(cache->m_transform, transform)) {
return cache;
+ }
}
return nullptr;
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h
index 708c79c2ae..682395ece6 100644
--- a/src/gui/text/qfontengine_p.h
+++ b/src/gui/text/qfontengine_p.h
@@ -190,7 +190,7 @@ public:
virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t);
virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t);
virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t);
- virtual QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t);
+ virtual QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t, const QColor &color = QColor());
virtual QImage *lockedAlphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition,
GlyphFormat neededFormat,
const QTransform &t = QTransform(),
@@ -252,7 +252,7 @@ public:
void clearGlyphCache(const void *key);
void setGlyphCache(const void *key, QFontEngineGlyphCache *data);
- QFontEngineGlyphCache *glyphCache(const void *key, GlyphFormat format, const QTransform &transform) const;
+ QFontEngineGlyphCache *glyphCache(const void *key, GlyphFormat format, const QTransform &transform, const QColor &color = QColor()) const;
static const uchar *getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize);
static quint32 getTrueTypeGlyphIndex(const uchar *cmap, int cmapSize, uint unicode);
diff --git a/src/gui/text/qfontengineglyphcache_p.h b/src/gui/text/qfontengineglyphcache_p.h
index fd5db1ecf5..532be10a83 100644
--- a/src/gui/text/qfontengineglyphcache_p.h
+++ b/src/gui/text/qfontengineglyphcache_p.h
@@ -65,7 +65,10 @@ QT_BEGIN_NAMESPACE
class Q_GUI_EXPORT QFontEngineGlyphCache: public QSharedData
{
public:
- QFontEngineGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix) : m_format(format), m_transform(matrix)
+ QFontEngineGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix, const QColor &color = QColor())
+ : m_format(format)
+ , m_transform(matrix)
+ , m_color(color)
{
Q_ASSERT(m_format != QFontEngine::Format_None);
}
@@ -74,9 +77,11 @@ public:
QFontEngine::GlyphFormat glyphFormat() const { return m_format; }
const QTransform &transform() const { return m_transform; }
+ const QColor &color() const { return m_color; }
QFontEngine::GlyphFormat m_format;
QTransform m_transform;
+ QColor m_color;
};
typedef QHash<void *, QList<QFontEngineGlyphCache *> > GlyphPointerHash;
typedef QHash<int, QList<QFontEngineGlyphCache *> > GlyphIntHash;