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_p.h
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
5#ifndef QSGRHIDISTANCEFIELDGLYPHCACHE_H
6#define QSGRHIDISTANCEFIELDGLYPHCACHE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20#include <private/qsgareaallocator_p.h>
21#include <rhi/qrhi.h>
22
24
25class QSGDefaultRenderContext;
26
27class Q_QUICK_EXPORT QSGRhiDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache
28{
29public:
30 QSGRhiDistanceFieldGlyphCache(QSGDefaultRenderContext *rc, const QRawFont &font, int renderTypeQuality);
31 virtual ~QSGRhiDistanceFieldGlyphCache();
32
33 void requestGlyphs(const QSet<glyph_t> &glyphs) override;
34 void storeGlyphs(const QList<QDistanceField> &glyphs) override;
35 void referenceGlyphs(const QSet<glyph_t> &glyphs) override;
36 void releaseGlyphs(const QSet<glyph_t> &glyphs) override;
37
38 bool useTextureResizeWorkaround() const;
39 bool createFullSizeTextures() const;
40 bool isActive() const override;
41 int maxTextureSize() const;
42
43 void setMaxTextureCount(int max) { m_maxTextureCount = max; }
44 int maxTextureCount() const { return m_maxTextureCount; }
45
46 void commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto);
47
48 bool eightBitFormatIsAlphaSwizzled() const override;
49 bool screenSpaceDerivativesSupported() const override;
50
51#if defined(QSG_DISTANCEFIELD_CACHE_DEBUG)
52 void saveTexture(QRhiTexture *texture, const QString &nameBase) const override;
53#endif
54
55private:
56 bool loadPregeneratedCache(const QRawFont &font);
57
58 struct TextureInfo {
59 QRhiTexture *texture;
60 QSize size;
61 QRect allocatedArea;
62 QDistanceField image;
63 int padding = -1;
64 QVarLengthArray<QRhiTextureUploadEntry, 16> uploads;
65
66 TextureInfo(const QRect &preallocRect = QRect()) : texture(nullptr), allocatedArea(preallocRect) { }
67 };
68
69 void createTexture(TextureInfo *texInfo, int width, int height, const void *pixels);
70 void createTexture(TextureInfo *texInfo, int width, int height);
71 void resizeTexture(TextureInfo *texInfo, int width, int height);
72
73 TextureInfo *textureInfo(int index)
74 {
75 for (int i = m_textures.size(); i <= index; ++i) {
76 if (createFullSizeTextures())
77 m_textures.append(QRect(0, 0, maxTextureSize(), maxTextureSize()));
78 else
79 m_textures.append(TextureInfo());
80 }
81
82 return &m_textures[index];
83 }
84
85 QSGDefaultRenderContext *m_rc;
86 QRhi *m_rhi;
87 mutable int m_maxTextureSize = 0;
88 int m_maxTextureCount = 3;
89 QSGAreaAllocator *m_areaAllocator = nullptr;
90 QList<TextureInfo> m_textures;
91 QHash<glyph_t, TextureInfo *> m_glyphsTexture;
92 QSet<glyph_t> m_unusedGlyphs;
93 QSet<glyph_t> m_referencedGlyphs;
94 QSet<QRhiTexture *> m_pendingDispose;
95};
96
97QT_END_NAMESPACE
98
99#endif // QSGRHIDISTANCEFIELDGLYPHCACHE_H
DistanceFieldAnisotropicOutlineTextMaterialRhiShader(bool alphaTexture, int viewCount)
DistanceFieldAnisotropicShiftedTextMaterialRhiShader(bool alphaTexture, int viewCount)
DistanceFieldAnisotropicTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
DistanceFieldOutlineTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
DistanceFieldShiftedStyleTextMaterialRhiShader(bool alphaTexture, int viewCount)
DistanceFieldStyledTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSGDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount)
QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to enable the material to provide a custom set of graphics...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount)
Combined button and popup list for selecting options.
static float thresholdFunc(float glyphScale)
static QT_BEGIN_NAMESPACE float qt_sg_envFloat(const char *name, float defaultValue)
static float spreadFunc(float glyphScale)