5#include <private/qsgmaterialshader_p.h>
7#include <QtGui/private/qguiapplication_p.h>
8#include <qpa/qplatformintegration.h>
9#include <private/qfontengine_p.h>
11#include <QtQuick/qquickwindow.h>
12#include <QtQuick/private/qsgtexture_p.h>
13#include <QtQuick/private/qsgdefaultrendercontext_p.h>
15#include <private/qrawfont_p.h>
16#include <QtCore/qmath.h>
22 float o =
c.w() * globalOpacity;
42 : m_glyphFormat(glyphFormat)
61 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
69 Q_ASSERT(oldMat ==
nullptr || oldMat->texture());
73 const int projectionMatrixCount =
qMin(
state.projectionMatrixCount(), newMaterial->viewCount());
76 if (
state.isMatrixDirty()) {
78 memcpy(
buf->data() +
offset, mv.constData(), 64);
83 for (
int viewIndex = 0; viewIndex < projectionMatrixCount; ++viewIndex) {
84 if (
state.isMatrixDirty()) {
86 memcpy(
buf->data() +
offset,
p.constData(), 64);
93 QRhiTexture *oldRtex = oldMat ? oldMat->texture()->rhiTexture() :
nullptr;
94 QRhiTexture *newRtex = mat->texture()->rhiTexture();
95 if (updated || !oldMat || oldRtex != newRtex) {
97 1.0f / mat->rhiGlyphCache()->height());
98 memcpy(
buf->data() +
offset, &textureScale, 8);
104 float dpr =
state.devicePixelRatio();
110 mat->rhiGlyphCache()->commitResourceUpdates(
state.resourceUpdateBatch());
154 if (oldMat ==
nullptr || mat->color() != oldMat->color() ||
state.isOpacityDirty()) {
189 if (oldMat ==
nullptr || mat->color() != oldMat->color() ||
state.isOpacityDirty()) {
208 ps->
srcColor = GraphicsPipelineState::ConstantColor;
209 ps->
dstColor = GraphicsPipelineState::OneMinusSrcColor;
241 if (oldMat ==
nullptr || mat->color() != oldMat->color() ||
state.isOpacityDirty()) {
279 if (oldMat ==
nullptr || mat->styleColor() != oldMat->styleColor() ||
state.isOpacityDirty()) {
286 if (oldMat ==
nullptr || oldMat->styleShift() != mat->styleShift()) {
324 if (m_retainedFontEngine !=
nullptr)
331 if (m_color ==
color)
351 updateCache(glyphFormat);
366 ? fontEngine->glyphFormat
370 qreal devicePixelRatio;
381 if (!fontEngine->supportsTransformation(glyphCacheTransform))
385 m_glyphCache = fontEngine->glyphCache(
cacheKey, glyphFormat, glyphCacheTransform,
color);
386 if (!m_glyphCache ||
int(m_glyphCache->
glyphFormat()) != glyphFormat) {
388 fontEngine->setGlyphCache(
cacheKey, m_glyphCache.
data());
389 if (m_retainedFontEngine !=
nullptr)
394 m_retainedFontEngine = fontEngine;
401 const QVector<quint32> &glyphIndexes,
402 const QVector<QPointF> &glyphPositions,
410 QVector<QFixedPoint> fixedPointPositions;
411 const int glyphPositionsSize = glyphPositions.size();
412 fixedPointPositions.reserve(glyphPositionsSize);
413 for (
int i=0;
i < glyphPositionsSize; ++
i)
419 cache->populate(fontD->fontEngine,
421 glyphIndexes.constData(),
422 fixedPointPositions.data(),
423 QPainter::RenderHints(),
425 cache->fillInPendingGlyphs();
427 int margin = fontD->fontEngine->glyphMargin(
cache->glyphFormat());
429 qreal glyphCacheScaleX =
cache->transform().m11();
430 qreal glyphCacheScaleY =
cache->transform().m22();
431 qreal glyphCacheInverseScaleX = 1.0 / glyphCacheScaleX;
432 qreal glyphCacheInverseScaleY = 1.0 / glyphCacheScaleY;
433 qreal scaledMargin = margin * glyphCacheInverseScaleX;
436 geometry->
allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6);
441 bool supportsSubPixelPositions = fontD->fontEngine->supportsHorizontalSubPixelPositions();
442 for (
int i=0;
i<glyphIndexes.size(); ++
i) {
444 QFixedPoint fixedPointPosition = fixedPointPositions.at(
i);
447 if (supportsSubPixelPositions)
448 subPixelPosition = fontD->fontEngine->subPixelPositionForX(
QFixed::fromReal(fixedPointPosition.x.toReal() * glyphCacheScaleX));
460 qreal x = (
qFloor(glyphPosition.x() * glyphCacheScaleX) * glyphCacheInverseScaleX) +
461 (
c.baseLineX * glyphCacheInverseScaleX) - scaledMargin;
462 qreal y = (
qRound(glyphPosition.y() * glyphCacheScaleY) * glyphCacheInverseScaleY) -
463 (
c.baseLineY * glyphCacheInverseScaleY) - scaledMargin;
465 qreal w =
c.w * glyphCacheInverseScaleX;
466 qreal h =
c.h * glyphCacheInverseScaleY;
470 float cx1 =
x - margins.
left();
471 float cx2 =
x +
w + margins.
right();
472 float cy1 =
y - margins.
top();
473 float cy2 =
y +
h + margins.
bottom();
475 float tx1 =
c.x - margins.
left();
476 float tx2 =
c.x +
c.w + margins.
right();
477 float ty1 =
c.y - margins.
top();
478 float ty2 =
c.y +
c.h + margins.
bottom();
481 *baseLine = glyphPosition;
483 vp[4 *
i + 0] =
QVector4D(cx1, cy1, tx1, ty1);
484 vp[4 *
i + 1] =
QVector4D(cx2, cy1, tx2, ty1);
485 vp[4 *
i + 2] =
QVector4D(cx1, cy2, tx1, ty2);
486 vp[4 *
i + 3] =
QVector4D(cx2, cy2, tx2, ty2);
489 ip[6 *
i + 0] =
o + 0;
490 ip[6 *
i + 1] =
o + 2;
491 ip[6 *
i + 2] =
o + 3;
492 ip[6 *
i + 3] =
o + 3;
493 ip[6 *
i + 4] =
o + 1;
494 ip[6 *
i + 5] =
o + 0;
527 switch (glyphFormat) {
541 return a.x() >
b.x() ? 1 : -1;
543 return a.y() >
b.y() ? 1 : -1;
545 return a.z() >
b.z() ? 1 : -1;
547 return a.w() >
b.w() ? 1 : -1;
555 if (m_glyphCache !=
other->m_glyphCache)
556 return m_glyphCache.
data() <
other->m_glyphCache.data() ? -1 : 1;
563 QSize glyphCacheSize(
gc->width(),
gc->height());
564 if (glyphCacheSize != m_size) {
571 m_size = glyphCacheSize;
600 if (m_styleShift !=
other->m_styleShift)
601 return m_styleShift.
y() -
other->m_styleShift.y();
The QColor class provides colors based on RGB, HSV or CMYK values.
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
T * data() const noexcept
Returns a pointer to the shared data object.
QFontEngine::GlyphFormat glyphFormat() const
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
\inmodule QtCore\reentrant
bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns fa...
static QRawFontPrivate * get(const QRawFont &font)
The QRawFont class provides access to a single physical instance of a font.
qreal ascent() const
Returns the ascent of this QRawFont in pixel units.
bool isValid() const
Returns true if the QRawFont is valid and false otherwise.
\inmodule QtCore\reentrant
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...
QSG24BitTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat, 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...
QSG32BitColorTextRhiShader(QFontEngine::GlyphFormat glyphFormat, 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...
QSG8BitTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat, int viewCount, bool alphaTexture)
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...
qreal currentDevicePixelRatio() const
QRhi * rhi() const override
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Convenience function to access the vertex data as a mutable array of QSGGeometry::TexturedPoint2D.
int indexType() const
Returns the primitive type used for indices in this geometry object.
void allocate(int vertexCount, int indexCount=0)
Resizes the vertex and index data of this geometry object to fit vertexCount vertices and indexCount ...
int sizeOfVertex() const
Returns the size in bytes of one vertex.
quint16 * indexDataAsUShort()
Convenience function to access the index data as a mutable array of 16-bit unsigned integers.
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGMaterialShader class represents a graphics API independent shader program.
void setShaderFileName(Stage stage, const QString &filename)
Sets the filename for the shader for the specified stage.
void setFlag(Flags flags, bool on=true)
Sets the flags on this material shader if on is true; otherwise clears the specified flags.
@ UpdatesGraphicsPipelineState
The QSGMaterial class encapsulates rendering state for a shader program.
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
QSGOutlinedTextMaterial(QSGRenderContext *rc, const QRawFont &font)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGOutlinedTextRhiShader(QFontEngine::GlyphFormat glyphFormat, int viewCount, bool alphaTexture)
void setTextureSize(const QSize &size)
void setTexture(QRhiTexture *texture)
void setOwnsTexture(bool owns)
void registerFontengineForCleanup(QFontEngine *engine)
void unregisterFontengineForCleanup(QFontEngine *engine)
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGStyledTextMaterial(QSGRenderContext *rc, const QRawFont &font)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
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...
QSGStyledTextRhiShader(QFontEngine::GlyphFormat glyphFormat, int viewCount, bool alphaTexture)
QSGTextMaskMaterial(QSGRenderContext *rc, const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat=QFontEngine::Format_None)
const QVector4D & color() const
virtual ~QSGTextMaskMaterial()
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
void setColor(const QColor &c)
QTextureGlyphCache * glyphCache() const
QSGRhiTextureGlyphCache * rhiGlyphCache() const
void populate(const QPointF &position, const QVector< quint32 > &glyphIndexes, const QVector< QPointF > &glyphPositions, QSGGeometry *geometry, QRectF *boundingRect, QPointF *baseLine, const QMargins &margins=QMargins(0, 0, 0, 0))
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,...
QFontEngine::GlyphFormat m_glyphFormat
QSGTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat, int viewCount)
quint32 m_currentUbufOffset
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 setFiltering(Filtering filter)
Sets the sampling mode to filter.
The QVector2D class represents a vector or vertex in 2D space.
constexpr float y() const noexcept
Returns the y coordinate of this point.
The QVector4D class represents a vector or vertex in 4D space.
constexpr float x() const noexcept
Returns the x coordinate of this point.
constexpr float w() const noexcept
Returns the w coordinate of this point.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float z() const noexcept
Returns the z coordinate of this point.
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
int qRound(qfloat16 d) noexcept
static QByteArray cacheKey(Args &&...args)
constexpr const T & qMin(const T &a, const T &b)
T qobject_cast(QObject *object)
\variable QObject::staticMetaObject
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLuint GLintptr offset
GLfloat GLfloat GLfloat GLfloat h
static const QRectF boundingRect(const QPointF *points, int pointCount)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static QT_BEGIN_NAMESPACE QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity)
static int qsg_colorDiff(const QVector4D &a, const QVector4D &b)
#define QStringLiteral(str)
void gc(QV4::ExecutionEngine &engine, GCFlags flags)
static constexpr QFixedPoint fromPointF(const QPointF &p)
static constexpr QFixed fromReal(qreal r)
Describes state changes that the material wants to apply to the currently active graphics pipeline st...
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.