8#include <private/qdrawhelper_p.h>
15 : QImageTextureGlyphCache(format, matrix, color),
22 m_resizeWithTextureCopy = m_rhi->backend() != QRhi::OpenGLES2;
27 m_rc->deferredReleaseGlyphCacheTexture(m_texture);
32 QRhiTexture *t = m_rhi->newTexture(format, m_size, 1, QRhiTexture::UsedAsTransferSource);
34 qWarning(
"Failed to build new glyph cache texture of size %dx%d", m_size.width(), m_size.height());
38 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
43 if (format == QRhiTexture::RED_OR_ALPHA8)
44 data.fill(0, m_size.width() * m_size.height());
46 data.fill(0, m_size.width() * m_size.height() * 4);
48 subresDesc.setSourceSize(m_size);
49 resourceUpdates->uploadTexture(t, QRhiTextureUploadEntry(0, 0, subresDesc));
56 width = qMax(128, width);
57 height = qMax(32, height);
59 if (!m_resizeWithTextureCopy)
60 QImageTextureGlyphCache::createTextureData(width, height);
62 m_size = QSize(width, height);
67 width = qMax(128, width);
68 height = qMax(32, height);
70 if (m_size.width() >= width && m_size.height() >= height)
73 m_size = QSize(width, height);
76 QRhiTexture *t = createEmptyTexture(m_texture->format());
80 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
81 if (m_resizeWithTextureCopy) {
82 resourceUpdates->copyTexture(t, m_texture);
84 QImageTextureGlyphCache::resizeTextureData(width, height);
86 prepareGlyphImage(&img);
88 const QSize oldSize = m_texture->pixelSize();
89 subresDesc.setSourceSize(QSize(qMin(oldSize.width(), width), qMin(oldSize.height(), height)));
90 resourceUpdates->uploadTexture(t, QRhiTextureUploadEntry(0, 0, subresDesc));
93 m_rc->deferredReleaseGlyphCacheTexture(m_texture);
100 Q_ASSERT(m_uploads.isEmpty());
105 const int maskWidth = img->width();
106 const int maskHeight = img->height();
107#if Q_BYTE_ORDER != Q_BIG_ENDIAN
108 const bool supportsBgra = m_rhi->isTextureFormatSupported(QRhiTexture::BGRA8);
112 if (img->format() == QImage::Format_Mono) {
113 *img =
std::move(*img).convertToFormat(QImage::Format_Grayscale8);
114 }
else if (img->format() == QImage::Format_RGB32 || img->format() == QImage::Format_ARGB32_Premultiplied) {
117 if (img->format() == QImage::Format_RGB32
118#if Q_BYTE_ORDER != Q_BIG_ENDIAN
122 for (
int y = 0; y < maskHeight; ++y) {
123 QRgb *src =
reinterpret_cast<
QRgb *>(img->scanLine(y));
124 for (
int x = 0; x < maskWidth; ++x) {
127 if (img->format() == QImage::Format_RGB32) {
131 int avg = (r + g + b + 1) / 3;
135#if Q_BYTE_ORDER != Q_BIG_ENDIAN
138 rgb = ARGB2RGBA(rgb);
145#if Q_BYTE_ORDER != Q_BIG_ENDIAN
157 if (!m_resizeWithTextureCopy) {
158 QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition);
161 mask = image().copy(QRect(c.x, c.y, c.w, c.h));
163 mask = textureMapForGlyph(glyph, subPixelPosition);
166 prepareGlyphImage(&mask);
168 subresDesc.setImage(mask);
169 subresDesc.setDestinationTopLeft(QPoint(c.x, c.y));
170 m_uploads.append(QRhiTextureUploadEntry(0, 0, subresDesc));
175 if (m_uploads.isEmpty())
179 QRhiTexture::Format texFormat;
180 if (m_format == QFontEngine::Format_A32 || m_format == QFontEngine::Format_ARGB)
181 texFormat = m_bgra ? QRhiTexture::BGRA8 : QRhiTexture::RGBA8;
183 texFormat = QRhiTexture::RED_OR_ALPHA8;
185 m_texture = createEmptyTexture(texFormat);
190 QRhiResourceUpdateBatch *resourceUpdates = m_rc->glyphCacheResourceUpdates();
192 desc.setEntries(m_uploads.cbegin(), m_uploads.cend());
193 resourceUpdates->uploadTexture(m_texture, desc);
199 if (m_format == QFontEngine::Format_Mono)
207 return m_rhi->resourceLimit(QRhi::TextureSizeMax);
212 if (!m_resizeWithTextureCopy)
213 return qMin(1024, m_rhi->resourceLimit(QRhi::TextureSizeMax));
215 return m_rhi->resourceLimit(QRhi::TextureSizeMax);
220 if (QRhiResourceUpdateBatch *resourceUpdates = m_rc->maybeGlyphCacheResourceUpdates()) {
221 mergeInto->merge(resourceUpdates);
222 m_rc->resetGlyphCacheResources();
230 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
Combined button and popup list for selecting options.
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)