Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgrhidistancefieldglyphcache.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6#include "qsgcontext_p.h"
8#include <QtGui/private/qdistancefield_p.h>
9#include <QtCore/qelapsedtimer.h>
10#include <QtQml/private/qqmlglobal_p.h>
11#include <qmath.h>
12#include <qendian.h>
13
15
16DEFINE_BOOL_CONFIG_OPTION(qmlUseGlyphCacheWorkaround, QML_USE_GLYPHCACHE_WORKAROUND)
17DEFINE_BOOL_CONFIG_OPTION(qsgPreferFullSizeGlyphCacheTextures, QSG_PREFER_FULLSIZE_GLYPHCACHE_TEXTURES)
18
19#if !defined(QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING)
20# define QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING 2
21#endif
22
23QSGRhiDistanceFieldGlyphCache::QSGRhiDistanceFieldGlyphCache(QSGDefaultRenderContext *rc,
24 const QRawFont &font,
25 int renderTypeQuality)
26 : QSGDistanceFieldGlyphCache(font, renderTypeQuality)
27 , m_rc(rc)
28 , m_rhi(rc->rhi())
29{
30 // Load a pregenerated cache if the font contains one
31 loadPregeneratedCache(font);
32}
33
34QSGRhiDistanceFieldGlyphCache::~QSGRhiDistanceFieldGlyphCache()
35{
36 for (const TextureInfo &t : std::as_const(m_textures))
37 m_rc->deferredReleaseGlyphCacheTexture(t.texture);
38
39 delete m_areaAllocator;
40}
41
42void QSGRhiDistanceFieldGlyphCache::requestGlyphs(const QSet<glyph_t> &glyphs)
43{
44 QList<GlyphPosition> glyphPositions;
45 QList<glyph_t> glyphsToRender;
46
47 if (m_areaAllocator == nullptr)
48 m_areaAllocator = new QSGAreaAllocator(QSize(maxTextureSize(), m_maxTextureCount * maxTextureSize()));
49
50 for (QSet<glyph_t>::const_iterator it = glyphs.constBegin(); it != glyphs.constEnd() ; ++it) {
51 glyph_t glyphIndex = *it;
52
54 QRectF boundingRect = glyphData(glyphIndex).boundingRect;
55 int glyphWidth = qCeil(boundingRect.width() + distanceFieldRadius() * 2);
56 int glyphHeight = qCeil(boundingRect.height() + distanceFieldRadius() * 2);
57 QSize glyphSize(glyphWidth + padding * 2, glyphHeight + padding * 2);
58 QRect alloc = m_areaAllocator->allocate(glyphSize);
59
60 if (alloc.isNull()) {
61 // Unallocate unused glyphs until we can allocated the new glyph
62 while (alloc.isNull() && !m_unusedGlyphs.isEmpty()) {
63 glyph_t unusedGlyph = *m_unusedGlyphs.constBegin();
64
65 TexCoord unusedCoord = glyphTexCoord(unusedGlyph);
66 if (!unusedCoord.isNull()) {
67 QRectF unusedGlyphBoundingRect = glyphData(unusedGlyph).boundingRect;
68 int unusedGlyphWidth = qCeil(unusedGlyphBoundingRect.width() + distanceFieldRadius() * 2);
69 int unusedGlyphHeight = qCeil(unusedGlyphBoundingRect.height() + distanceFieldRadius() * 2);
70 m_areaAllocator->deallocate(QRect(unusedCoord.x - padding,
71 unusedCoord.y - padding,
72 padding * 2 + unusedGlyphWidth,
73 padding * 2 + unusedGlyphHeight));
74 }
75
76 m_unusedGlyphs.remove(unusedGlyph);
77 m_glyphsTexture.remove(unusedGlyph);
78 removeGlyph(unusedGlyph);
79
80 alloc = m_areaAllocator->allocate(glyphSize);
81 }
82
83 // Not enough space left for this glyph... skip to the next one
84 if (alloc.isNull())
85 continue;
86 }
87
88 TextureInfo *tex = textureInfo(alloc.y() / maxTextureSize());
89 alloc = QRect(alloc.x(), alloc.y() % maxTextureSize(), alloc.width(), alloc.height());
90
91 tex->allocatedArea |= alloc;
92 Q_ASSERT(tex->padding == padding || tex->padding < 0);
93 tex->padding = padding;
94
95 GlyphPosition p;
96 p.glyph = glyphIndex;
97 p.position = alloc.topLeft() + QPoint(padding, padding);
98
99 glyphPositions.append(p);
100 glyphsToRender.append(glyphIndex);
101 m_glyphsTexture.insert(glyphIndex, tex);
102 }
103
104 setGlyphsPosition(glyphPositions);
105 markGlyphsToRender(glyphsToRender);
106}
107
108bool QSGRhiDistanceFieldGlyphCache::isActive() const
109{
110 return !m_referencedGlyphs.empty();
111}
112
113void QSGRhiDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> &glyphs)
114{
115 typedef QHash<TextureInfo *, QList<glyph_t> > GlyphTextureHash;
116 typedef GlyphTextureHash::const_iterator GlyphTextureHashConstIt;
117
118 GlyphTextureHash glyphTextures;
119
120 QVarLengthArray<QRhiTextureUploadEntry, 32> uploads;
121 for (int i = 0; i < glyphs.size(); ++i) {
122 QDistanceField glyph = glyphs.at(i);
123 glyph_t glyphIndex = glyph.glyph();
124 TexCoord c = glyphTexCoord(glyphIndex);
125 TextureInfo *texInfo = m_glyphsTexture.value(glyphIndex);
126
127 resizeTexture(texInfo, texInfo->allocatedArea.width(), texInfo->allocatedArea.height());
128
129 glyphTextures[texInfo].append(glyphIndex);
130
131 int padding = texInfo->padding;
132 int expectedWidth = qCeil(c.width + c.xMargin * 2);
133 glyph = glyph.copy(-padding, -padding,
134 expectedWidth + padding * 2, glyph.height() + padding * 2);
135
136 if (useTextureResizeWorkaround()) {
137 uchar *inBits = glyph.scanLine(0);
138 uchar *outBits = texInfo->image.scanLine(int(c.y) - padding) + int(c.x) - padding;
139 for (int y = 0; y < glyph.height(); ++y) {
140 memcpy(outBits, inBits, glyph.width());
141 inBits += glyph.width();
142 outBits += texInfo->image.width();
143 }
144 }
145
146 QRhiTextureSubresourceUploadDescription subresDesc(glyph.constBits(), glyph.width() * glyph.height());
147 subresDesc.setSourceSize(QSize(glyph.width(), glyph.height()));
148 subresDesc.setDestinationTopLeft(QPoint(c.x - padding, c.y - padding));
149 texInfo->uploads.append(QRhiTextureUploadEntry(0, 0, subresDesc));
150 }
151
152 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
153 for (int i = 0; i < glyphs.size(); ++i) {
154 TextureInfo *texInfo = m_glyphsTexture.value(glyphs.at(i).glyph());
155 if (!texInfo->uploads.isEmpty()) {
156 QRhiTextureUploadDescription desc;
157 desc.setEntries(texInfo->uploads.cbegin(), texInfo->uploads.cend());
158 resourceUpdates->uploadTexture(texInfo->texture, desc);
159 texInfo->uploads.clear();
160 }
161 }
162
163 for (GlyphTextureHashConstIt i = glyphTextures.constBegin(), cend = glyphTextures.constEnd(); i != cend; ++i) {
164 Texture t;
165 t.texture = i.key()->texture;
166 t.size = i.key()->size;
167 setGlyphsTexture(i.value(), t);
168 }
169}
170
171void QSGRhiDistanceFieldGlyphCache::referenceGlyphs(const QSet<glyph_t> &glyphs)
172{
173 m_referencedGlyphs += glyphs;
174 m_unusedGlyphs -= glyphs;
175}
176
177void QSGRhiDistanceFieldGlyphCache::releaseGlyphs(const QSet<glyph_t> &glyphs)
178{
179 m_referencedGlyphs -= glyphs;
180 m_unusedGlyphs += glyphs;
181}
182
183void QSGRhiDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
184 int width,
185 int height)
186{
187 QByteArray zeroBuf(width * height, 0);
188 createTexture(texInfo, width, height, zeroBuf.constData());
189}
190
191void QSGRhiDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
192 int width,
193 int height,
194 const void *pixels)
195{
196 if (useTextureResizeWorkaround() && texInfo->image.isNull()) {
197 texInfo->image = QDistanceField(width, height);
198 memcpy(texInfo->image.bits(), pixels, width * height);
199 }
200
201 texInfo->texture = m_rhi->newTexture(QRhiTexture::RED_OR_ALPHA8, QSize(width, height), 1, QRhiTexture::UsedAsTransferSource);
202 if (texInfo->texture->create()) {
203 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
204 QRhiTextureSubresourceUploadDescription subresDesc(pixels, width * height);
205 subresDesc.setSourceSize(QSize(width, height));
206 resourceUpdates->uploadTexture(texInfo->texture, QRhiTextureUploadEntry(0, 0, subresDesc));
207 } else {
208 qWarning("Failed to create distance field glyph cache");
209 }
210
211 texInfo->size = QSize(width, height);
212}
213
214void QSGRhiDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int width, int height)
215{
216 int oldWidth = texInfo->size.width();
217 int oldHeight = texInfo->size.height();
218 if (width == oldWidth && height == oldHeight)
219 return;
220
221 QRhiTexture *oldTexture = texInfo->texture;
222 createTexture(texInfo, width, height);
223
224 if (!oldTexture)
225 return;
226
227 updateRhiTexture(oldTexture, texInfo->texture, texInfo->size);
228
229 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
230 if (useTextureResizeWorkaround()) {
231 QRhiTextureSubresourceUploadDescription subresDesc(texInfo->image.constBits(),
232 oldWidth * oldHeight);
233 subresDesc.setSourceSize(QSize(oldWidth, oldHeight));
234 resourceUpdates->uploadTexture(texInfo->texture, QRhiTextureUploadEntry(0, 0, subresDesc));
235 texInfo->image = texInfo->image.copy(0, 0, width, height);
236 } else {
237 resourceUpdates->copyTexture(texInfo->texture, oldTexture);
238 }
239
240 m_rc->deferredReleaseGlyphCacheTexture(oldTexture);
241}
242
243bool QSGRhiDistanceFieldGlyphCache::useTextureResizeWorkaround() const
244{
245 static bool set = false;
246 static bool useWorkaround = false;
247 if (!set) {
248 useWorkaround = m_rhi->backend() == QRhi::OpenGLES2 || qmlUseGlyphCacheWorkaround();
249 set = true;
250 }
251 return useWorkaround;
252}
253
254bool QSGRhiDistanceFieldGlyphCache::createFullSizeTextures() const
255{
256 return qsgPreferFullSizeGlyphCacheTextures() && glyphCount() > QT_DISTANCEFIELD_HIGHGLYPHCOUNT();
257}
258
259int QSGRhiDistanceFieldGlyphCache::maxTextureSize() const
260{
261 if (!m_maxTextureSize)
262 m_maxTextureSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
263 return m_maxTextureSize;
264}
265
266namespace {
267 struct Qtdf {
268 // We need these structs to be tightly packed, but some compilers we use do not
269 // support #pragma pack(1), so we need to hardcode the offsets/sizes in the
270 // file format
271 enum TableSize {
272 HeaderSize = 14,
273 GlyphRecordSize = 46,
274 TextureRecordSize = 17
275 };
276
277 enum Offset {
278 // Header
279 majorVersion = 0,
280 minorVersion = 1,
281 pixelSize = 2,
282 textureSize = 4,
283 flags = 8,
284 headerPadding = 9,
285 numGlyphs = 10,
286
287 // Glyph record
288 glyphIndex = 0,
289 textureOffsetX = 4,
290 textureOffsetY = 8,
291 textureWidth = 12,
292 textureHeight = 16,
293 xMargin = 20,
294 yMargin = 24,
295 boundingRectX = 28,
296 boundingRectY = 32,
297 boundingRectWidth = 36,
298 boundingRectHeight = 40,
299 textureIndex = 44,
300
301 // Texture record
302 allocatedX = 0,
303 allocatedY = 4,
304 allocatedWidth = 8,
305 allocatedHeight = 12,
306 texturePadding = 16
307
308 };
309
310 template <typename T>
311 static inline T fetch(const char *data, Offset offset)
312 {
313 return qFromBigEndian<T>(data + int(offset));
314 }
315 };
316}
317
318bool QSGRhiDistanceFieldGlyphCache::loadPregeneratedCache(const QRawFont &font)
319{
320 // The pregenerated data must be loaded first, otherwise the area allocator
321 // will be wrong
322 if (m_areaAllocator != nullptr) {
323 qWarning("Font cache must be loaded before cache is used");
324 return false;
325 }
326
327 static QElapsedTimer timer;
328
329 bool profile = QSG_LOG_TIME_GLYPH().isDebugEnabled();
330 if (profile)
331 timer.start();
332
333 QByteArray qtdfTable = font.fontTable("qtdf");
334 if (qtdfTable.isEmpty())
335 return false;
336
337 typedef QHash<TextureInfo *, QList<glyph_t> > GlyphTextureHash;
338
339 GlyphTextureHash glyphTextures;
340
341 if (uint(qtdfTable.size()) < Qtdf::HeaderSize) {
342 qWarning("Invalid qtdf table in font '%s'",
343 qPrintable(font.familyName()));
344 return false;
345 }
346
347 const char *qtdfTableStart = qtdfTable.constData();
348 const char *qtdfTableEnd = qtdfTableStart + qtdfTable.size();
349
350 int padding = 0;
351 int textureCount = 0;
352 {
353 quint8 majorVersion = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::majorVersion);
354 quint8 minorVersion = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::minorVersion);
355 if (majorVersion != 5 || minorVersion != 12) {
356 qWarning("Invalid version of qtdf table %d.%d in font '%s'",
357 majorVersion,
358 minorVersion,
359 qPrintable(font.familyName()));
360 return false;
361 }
362
363 qreal pixelSize = qreal(Qtdf::fetch<quint16>(qtdfTableStart, Qtdf::pixelSize));
364 m_maxTextureSize = Qtdf::fetch<quint32>(qtdfTableStart, Qtdf::textureSize);
365 m_doubleGlyphResolution = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::flags) == 1;
366 padding = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::headerPadding);
367
368 if (pixelSize <= 0.0) {
369 qWarning("Invalid pixel size in '%s'", qPrintable(font.familyName()));
370 return false;
371 }
372
373 if (m_maxTextureSize <= 0) {
374 qWarning("Invalid texture size in '%s'", qPrintable(font.familyName()));
375 return false;
376 }
377
378 int systemMaxTextureSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
379
380 if (m_maxTextureSize > systemMaxTextureSize) {
381 qWarning("System maximum texture size is %d. This is lower than the value in '%s', which is %d",
382 systemMaxTextureSize,
383 qPrintable(font.familyName()),
384 m_maxTextureSize);
385 }
386
388 qWarning("Padding mismatch in '%s'. Font requires %d, but Qt is compiled with %d.",
389 qPrintable(font.familyName()),
390 padding,
392 }
393
394 m_referenceFont.setPixelSize(pixelSize);
395
396 quint32 glyphCount = Qtdf::fetch<quint32>(qtdfTableStart, Qtdf::numGlyphs);
397 m_unusedGlyphs.reserve(glyphCount);
398
399 const char *allocatorData = qtdfTableStart + Qtdf::HeaderSize;
400 {
401 m_areaAllocator = new QSGAreaAllocator(QSize(0, 0));
402 allocatorData = m_areaAllocator->deserialize(allocatorData, qtdfTableEnd - allocatorData);
403 if (allocatorData == nullptr)
404 return false;
405 }
406
407 if (m_areaAllocator->size().height() % m_maxTextureSize != 0) {
408 qWarning("Area allocator size mismatch in '%s'", qPrintable(font.familyName()));
409 return false;
410 }
411
412 textureCount = m_areaAllocator->size().height() / m_maxTextureSize;
413 m_maxTextureCount = qMax(m_maxTextureCount, textureCount);
414
415 const char *textureRecord = allocatorData;
416 for (int i = 0; i < textureCount; ++i, textureRecord += Qtdf::TextureRecordSize) {
417 if (qtdfTableEnd - textureRecord < Qtdf::TextureRecordSize) {
418 qWarning("qtdf table too small in font '%s'.",
419 qPrintable(font.familyName()));
420 return false;
421 }
422
423 TextureInfo *tex = textureInfo(i);
424 tex->allocatedArea.setX(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedX));
425 tex->allocatedArea.setY(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedY));
426 tex->allocatedArea.setWidth(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedWidth));
427 tex->allocatedArea.setHeight(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedHeight));
428 tex->padding = Qtdf::fetch<quint8>(textureRecord, Qtdf::texturePadding);
429 }
430
431 const char *glyphRecord = textureRecord;
432 for (quint32 i = 0; i < glyphCount; ++i, glyphRecord += Qtdf::GlyphRecordSize) {
433 if (qtdfTableEnd - glyphRecord < Qtdf:: GlyphRecordSize) {
434 qWarning("qtdf table too small in font '%s'.",
435 qPrintable(font.familyName()));
436 return false;
437 }
438
439 glyph_t glyph = Qtdf::fetch<quint32>(glyphRecord, Qtdf::glyphIndex);
440 m_unusedGlyphs.insert(glyph);
441
442 GlyphData &glyphData = emptyData(glyph);
443
444#define FROM_FIXED_POINT(value) \
445(((qreal)value)/(qreal)65536)
446
447 glyphData.texCoord.x = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureOffsetX));
448 glyphData.texCoord.y = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureOffsetY));
449 glyphData.texCoord.width = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureWidth));
450 glyphData.texCoord.height = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureHeight));
451 glyphData.texCoord.xMargin = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::xMargin));
452 glyphData.texCoord.yMargin = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::yMargin));
453 glyphData.boundingRect.setX(FROM_FIXED_POINT(Qtdf::fetch<qint32>(glyphRecord, Qtdf::boundingRectX)));
454 glyphData.boundingRect.setY(FROM_FIXED_POINT(Qtdf::fetch<qint32>(glyphRecord, Qtdf::boundingRectY)));
455 glyphData.boundingRect.setWidth(FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::boundingRectWidth)));
456 glyphData.boundingRect.setHeight(FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::boundingRectHeight)));
457
458#undef FROM_FIXED_POINT
459
460 int textureIndex = Qtdf::fetch<quint16>(glyphRecord, Qtdf::textureIndex);
461 if (textureIndex < 0 || textureIndex >= textureCount) {
462 qWarning("Invalid texture index %d (texture count == %d) in '%s'",
463 textureIndex,
464 textureCount,
465 qPrintable(font.familyName()));
466 return false;
467 }
468
469
470 TextureInfo *texInfo = textureInfo(textureIndex);
471 m_glyphsTexture.insert(glyph, texInfo);
472
473 glyphTextures[texInfo].append(glyph);
474 }
475
476 const uchar *textureData = reinterpret_cast<const uchar *>(glyphRecord);
477 for (int i = 0; i < textureCount; ++i) {
478
479 TextureInfo *texInfo = textureInfo(i);
480
481 int width = texInfo->allocatedArea.width();
482 int height = texInfo->allocatedArea.height();
483 qint64 size = qint64(width) * height;
484 if (qtdfTableEnd - reinterpret_cast<const char *>(textureData) < size) {
485 qWarning("qtdf table too small in font '%s'.",
486 qPrintable(font.familyName()));
487 return false;
488 }
489
490 createTexture(texInfo, width, height, textureData);
491
492 QList<glyph_t> glyphs = glyphTextures.value(texInfo);
493
494 Texture t;
495 t.texture = texInfo->texture;
496 t.size = texInfo->size;
497
498 setGlyphsTexture(glyphs, t);
499
500 textureData += size;
501 }
502 }
503
504 if (profile) {
505 quint64 now = timer.elapsed();
506 qCDebug(QSG_LOG_TIME_GLYPH,
507 "distancefield: %d pre-generated glyphs loaded in %dms",
508 int(m_unusedGlyphs.size()),
509 int(now));
510 }
511
512 return true;
513}
514
515void QSGRhiDistanceFieldGlyphCache::commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto)
516{
517 if (QRhiResourceUpdateBatch *resourceUpdates = m_rc->maybeGlyphCacheResourceUpdates()) {
518 mergeInto->merge(resourceUpdates);
519 m_rc->resetGlyphCacheResources();
520 }
521}
522
523bool QSGRhiDistanceFieldGlyphCache::eightBitFormatIsAlphaSwizzled() const
524{
525 // return true when the shaders for 8-bit formats need .a instead of .r
526 // when sampling the texture
527 return !m_rhi->isFeatureSupported(QRhi::RedOrAlpha8IsRed);
528}
529
530bool QSGRhiDistanceFieldGlyphCache::screenSpaceDerivativesSupported() const
531{
532 return m_rhi->isFeatureSupported(QRhi::ScreenSpaceDerivatives);
533}
534
535#if defined(QSG_DISTANCEFIELD_CACHE_DEBUG)
536void QSGRhiDistanceFieldGlyphCache::saveTexture(QRhiTexture *texture, const QString &nameBase) const
537{
538 quint64 textureId = texture->nativeTexture().object;
539 QString fileName = nameBase + QLatin1Char('_') + QString::number(textureId, 16);
540 fileName.replace(QLatin1Char('/'), QLatin1Char('_'));
541 fileName.replace(QLatin1Char(' '), QLatin1Char('_'));
542 fileName.append(QLatin1String(".png"));
543
544 QRhiReadbackResult *rbResult = new QRhiReadbackResult;
545 rbResult->completed = [rbResult, fileName] {
546 const QSize size = rbResult->pixelSize;
547 const qint64 numPixels = qint64(size.width()) * size.height();
548 if (numPixels == rbResult->data.size()) {
549 // 1 bpp data, may be packed; copy it to ensure QImage scanline alignment
550 QImage image(size, QImage::Format_Grayscale8);
551 const char *p = rbResult->data.constData();
552 for (int i = 0; i < size.height(); i++)
553 memcpy(image.scanLine(i), p + (i * size.width()), size.width());
554 image.save(fileName);
555 } else if (4 * numPixels == rbResult->data.size()) {
556 // 4 bpp data
557 const uchar *p = reinterpret_cast<const uchar *>(rbResult->data.constData());
558 QImage image(p, size.width(), size.height(), QImage::Format_RGBA8888);
559 image.save(fileName);
560 } else {
561 qWarning("Unhandled data format in glyph texture");
562 }
563 delete rbResult;
564 };
565
566 QRhiReadbackDescription rb(texture);
567 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
568 resourceUpdates->readBackTexture(rb, rbResult);
569}
570#endif
571
572QT_END_NAMESPACE
Combined button and popup list for selecting options.
#define QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING
#define FROM_FIXED_POINT(value)