7#include <private/qdrawhelper_p.h>
14 : QImageTextureGlyphCache(format, matrix, color),
21 m_resizeWithTextureCopy = m_rhi->backend() != QRhi::OpenGLES2;
26 m_rc->deferredReleaseGlyphCacheTexture(m_texture);
31 QRhiTexture *t = m_rhi->newTexture(format, m_size, 1, QRhiTexture::UsedAsTransferSource);
33 qWarning(
"Failed to build new glyph cache texture of size %dx%d", m_size.width(), m_size.height());
37 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
42 if (format == QRhiTexture::RED_OR_ALPHA8)
43 data.fill(0, m_size.width() * m_size.height());
45 data.fill(0, m_size.width() * m_size.height() * 4);
47 subresDesc.setSourceSize(m_size);
48 resourceUpdates->uploadTexture(t, QRhiTextureUploadEntry(0, 0, subresDesc));
55 width = qMax(128, width);
56 height = qMax(32, height);
58 if (!m_resizeWithTextureCopy)
59 QImageTextureGlyphCache::createTextureData(width, height);
61 m_size = QSize(width, height);
66 width = qMax(128, width);
67 height = qMax(32, height);
69 if (m_size.width() >= width && m_size.height() >= height)
72 m_size = QSize(width, height);
75 QRhiTexture *t = createEmptyTexture(m_texture->format());
79 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
80 if (m_resizeWithTextureCopy) {
81 resourceUpdates->copyTexture(t, m_texture);
83 QImageTextureGlyphCache::resizeTextureData(width, height);
85 prepareGlyphImage(&img);
87 const QSize oldSize = m_texture->pixelSize();
88 subresDesc.setSourceSize(QSize(qMin(oldSize.width(), width), qMin(oldSize.height(), height)));
89 resourceUpdates->uploadTexture(t, QRhiTextureUploadEntry(0, 0, subresDesc));
92 m_rc->deferredReleaseGlyphCacheTexture(m_texture);
99 Q_ASSERT(m_uploads.isEmpty());
104 const int maskWidth = img->width();
105 const int maskHeight = img->height();
106#if Q_BYTE_ORDER != Q_BIG_ENDIAN
107 const bool supportsBgra = m_rhi->isTextureFormatSupported(QRhiTexture::BGRA8);
111 if (img->format() == QImage::Format_Mono) {
112 *img = std::move(*img).convertToFormat(QImage::Format_Grayscale8);
113 }
else if (img->format() == QImage::Format_RGB32 || img->format() == QImage::Format_ARGB32_Premultiplied) {
116 if (img->format() == QImage::Format_RGB32
117#if Q_BYTE_ORDER != Q_BIG_ENDIAN
121 for (
int y = 0; y < maskHeight; ++y) {
122 QRgb *src =
reinterpret_cast<
QRgb *>(img->scanLine(y));
123 for (
int x = 0; x < maskWidth; ++x) {
126 if (img->format() == QImage::Format_RGB32) {
130 int avg = (r + g + b + 1) / 3;
134#if Q_BYTE_ORDER != Q_BIG_ENDIAN
137 rgb = ARGB2RGBA(rgb);
144#if Q_BYTE_ORDER != Q_BIG_ENDIAN
156 if (!m_resizeWithTextureCopy) {
157 QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition);
160 mask = image().copy(QRect(c.x, c.y, c.w, c.h));
162 mask = textureMapForGlyph(glyph, subPixelPosition);
165 prepareGlyphImage(&mask);
167 subresDesc.setImage(mask);
168 subresDesc.setDestinationTopLeft(QPoint(c.x, c.y));
169 m_uploads.append(QRhiTextureUploadEntry(0, 0, subresDesc));
174 if (m_uploads.isEmpty())
178 QRhiTexture::Format texFormat;
179 if (m_format == QFontEngine::Format_A32 || m_format == QFontEngine::Format_ARGB)
180 texFormat = m_bgra ? QRhiTexture::BGRA8 : QRhiTexture::RGBA8;
182 texFormat = QRhiTexture::RED_OR_ALPHA8;
184 m_texture = createEmptyTexture(texFormat);
189 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
191 desc.setEntries(m_uploads.cbegin(), m_uploads.cend());
192 resourceUpdates->uploadTexture(m_texture, desc);
198 if (m_format == QFontEngine::Format_Mono)
206 return m_rhi->resourceLimit(QRhi::TextureSizeMax);
211 if (!m_resizeWithTextureCopy)
212 return qMin(1024, m_rhi->resourceLimit(QRhi::TextureSizeMax));
214 return m_rhi->resourceLimit(QRhi::TextureSizeMax);
219 if (QRhiResourceUpdateBatch *resourceUpdates = m_rc->maybeGlyphCacheResourceUpdates()) {
220 mergeInto->merge(resourceUpdates);
221 m_rc->resetGlyphCacheResources();
229 return !m_rhi->isFeatureSupported(QRhi::RedOrAlpha8IsRed);
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
~QSGRhiTextureGlyphCache()
void resizeTextureData(int width, int height) override
void commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto)
void endFillTexture() override
void beginFillTexture() override
int glyphPadding() const override
int maxTextureHeight() const override
bool eightBitFormatIsAlphaSwizzled() const
int maxTextureWidth() const override
void fillTexture(const Coord &c, glyph_t glyph, const QFixedPoint &subPixelPosition) override
void createTextureData(int width, int height) override
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr QRgb qRgba(int r, int g, int b, int a)
constexpr int qBlue(QRgb rgb)