aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgrhitextureglyphcache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph/qsgrhitextureglyphcache.cpp')
-rw-r--r--src/quick/scenegraph/qsgrhitextureglyphcache.cpp72
1 files changed, 32 insertions, 40 deletions
diff --git a/src/quick/scenegraph/qsgrhitextureglyphcache.cpp b/src/quick/scenegraph/qsgrhitextureglyphcache.cpp
index 2324db5762..7e626be8e2 100644
--- a/src/quick/scenegraph/qsgrhitextureglyphcache.cpp
+++ b/src/quick/scenegraph/qsgrhitextureglyphcache.cpp
@@ -23,15 +23,7 @@ QSGRhiTextureGlyphCache::QSGRhiTextureGlyphCache(QSGDefaultRenderContext *rc,
QSGRhiTextureGlyphCache::~QSGRhiTextureGlyphCache()
{
- // A plain delete should work, but just in case commitResourceUpdates was
- // not called and something is enqueued on the update batch for m_texture,
- // defer until the end of the frame.
- if (m_texture)
- m_texture->deleteLater();
-
- // should be empty, but just in case
- for (QRhiTexture *t : std::as_const(m_pendingDispose))
- t->deleteLater();
+ m_rc->deferredReleaseGlyphCacheTexture(m_texture);
}
QRhiTexture *QSGRhiTextureGlyphCache::createEmptyTexture(QRhiTexture::Format format)
@@ -97,7 +89,7 @@ void QSGRhiTextureGlyphCache::resizeTextureData(int width, int height)
resourceUpdates->uploadTexture(t, QRhiTextureUploadEntry(0, 0, subresDesc));
}
- m_pendingDispose.insert(m_texture);
+ m_rc->deferredReleaseGlyphCacheTexture(m_texture);
m_texture = t;
}
}
@@ -117,36 +109,42 @@ void QSGRhiTextureGlyphCache::prepareGlyphImage(QImage *img)
m_bgra = false;
if (img->format() == QImage::Format_Mono) {
- *img = img->convertToFormat(QImage::Format_Grayscale8);
- } else if (img->depth() == 32) {
- if (img->format() == QImage::Format_RGB32 || img->format() == QImage::Format_ARGB32_Premultiplied) {
- // We need to make the alpha component equal to the average of the RGB values.
- // This is needed when drawing sub-pixel antialiased text on translucent targets.
+ *img = std::move(*img).convertToFormat(QImage::Format_Grayscale8);
+ } else if (img->format() == QImage::Format_RGB32 || img->format() == QImage::Format_ARGB32_Premultiplied) {
+ // We need to make the alpha component equal to the average of the RGB values.
+ // This is needed when drawing sub-pixel antialiased text on translucent targets.
+ if (img->format() == QImage::Format_RGB32
+#if Q_BYTE_ORDER != Q_BIG_ENDIAN
+ || !supportsBgra
+#endif
+ ) {
for (int y = 0; y < maskHeight; ++y) {
- QRgb *src = (QRgb *) img->scanLine(y);
+ QRgb *src = reinterpret_cast<QRgb *>(img->scanLine(y));
for (int x = 0; x < maskWidth; ++x) {
- int r = qRed(src[x]);
- int g = qGreen(src[x]);
- int b = qBlue(src[x]);
- int avg;
- if (img->format() == QImage::Format_RGB32)
- avg = (r + g + b + 1) / 3; // "+1" for rounding.
- else // Format_ARGB_Premultiplied
- avg = qAlpha(src[x]);
-
- src[x] = qRgba(r, g, b, avg);
+ QRgb &rgb = src[x];
+
+ if (img->format() == QImage::Format_RGB32) {
+ int r = qRed(rgb);
+ int g = qGreen(rgb);
+ int b = qBlue(rgb);
+ int avg = (r + g + b + 1) / 3; // "+1" for rounding.
+ rgb = qRgba(r, g, b, avg);
+ }
+
#if Q_BYTE_ORDER != Q_BIG_ENDIAN
- if (supportsBgra) {
- m_bgra = true;
- } else {
+ if (!supportsBgra) {
// swizzle the bits to accommodate for the RGBA upload.
- src[x] = ARGB2RGBA(src[x]);
+ rgb = ARGB2RGBA(rgb);
m_bgra = false;
}
#endif
}
}
}
+#if Q_BYTE_ORDER != Q_BIG_ENDIAN
+ if (supportsBgra)
+ m_bgra = true;
+#endif
}
}
@@ -157,9 +155,9 @@ void QSGRhiTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, const Q
if (!m_resizeWithTextureCopy) {
QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition);
- mask = image();
- subresDesc.setSourceTopLeft(QPoint(c.x, c.y));
- subresDesc.setSourceSize(QSize(c.w, c.h));
+ // Explicitly copy() here to avoid fillTexture detaching the *entire* image() when
+ // it is still referenced by QRhiTextureSubresourceUploadDescription.
+ mask = image().copy(QRect(c.x, c.y, c.w, c.h));
} else {
mask = textureMapForGlyph(glyph, subPixelPosition);
}
@@ -220,14 +218,8 @@ void QSGRhiTextureGlyphCache::commitResourceUpdates(QRhiResourceUpdateBatch *mer
{
if (QRhiResourceUpdateBatch *resourceUpdates = m_rc->maybeGlyphCacheResourceUpdates()) {
mergeInto->merge(resourceUpdates);
- m_rc->releaseGlyphCacheResourceUpdates();
+ m_rc->resetGlyphCacheResources();
}
-
- // now let's assume the resource updates will be committed in this frame
- for (QRhiTexture *t : std::as_const(m_pendingDispose))
- t->deleteLater(); // will be deleted after the frame is submitted -> safe
-
- m_pendingDispose.clear();
}
bool QSGRhiTextureGlyphCache::eightBitFormatIsAlphaSwizzled() const