| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qsgdefaultglyphnode_p_p.h" | - | ||||||||||||||||||
| 41 | #include <private/qsgmaterialshader_p.h> | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include <qopenglshaderprogram.h> | - | ||||||||||||||||||
| 44 | #include <qopenglframebufferobject.h> | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||||||||
| 47 | #include <qpa/qplatformintegration.h> | - | ||||||||||||||||||
| 48 | #include <private/qfontengine_p.h> | - | ||||||||||||||||||
| 49 | #include <private/qopenglextensions_p.h> | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | #include <QtQuick/qquickwindow.h> | - | ||||||||||||||||||
| 52 | #include <QtQuick/private/qsgtexture_p.h> | - | ||||||||||||||||||
| 53 | #include <QtQuick/private/qsgdefaultrendercontext_p.h> | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | #include <private/qrawfont_p.h> | - | ||||||||||||||||||
| 56 | #include <QtCore/qmath.h> | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | #ifndef GL_FRAMEBUFFER_SRGB | - | ||||||||||||||||||
| 61 | #define GL_FRAMEBUFFER_SRGB 0x8DB9 | - | ||||||||||||||||||
| 62 | #endif | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | #ifndef GL_FRAMEBUFFER_SRGB_CAPABLE | - | ||||||||||||||||||
| 65 | #define GL_FRAMEBUFFER_SRGB_CAPABLE 0x8DBA | - | ||||||||||||||||||
| 66 | #endif | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | static inline QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity) | - | ||||||||||||||||||
| 69 | { | - | ||||||||||||||||||
| 70 | float o = c.w() * globalOpacity; | - | ||||||||||||||||||
| 71 | return QVector4D(c.x() * o, c.y() * o, c.z() * o, o); executed 216 times by 1 test: return QVector4D(c.x() * o, c.y() * o, c.z() * o, o);Executed by:
| 216 | ||||||||||||||||||
| 72 | } | - | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | static inline qreal qsg_device_pixel_ratio(QOpenGLContext *ctx) | - | ||||||||||||||||||
| 75 | { | - | ||||||||||||||||||
| 76 | qreal devicePixelRatio = 1; | - | ||||||||||||||||||
| 77 | if (ctx->surface()->surfaceClass() == QSurface::Window) {
| 0-304 | ||||||||||||||||||
| 78 | QWindow *w = static_cast<QWindow *>(ctx->surface()); | - | ||||||||||||||||||
| 79 | if (QQuickWindow *qw = qobject_cast<QQuickWindow *>(w))
| 0-304 | ||||||||||||||||||
| 80 | devicePixelRatio = qw->effectiveDevicePixelRatio(); executed 304 times by 1 test: devicePixelRatio = qw->effectiveDevicePixelRatio();Executed by:
| 304 | ||||||||||||||||||
| 81 | else | - | ||||||||||||||||||
| 82 | devicePixelRatio = w->devicePixelRatio(); never executed: devicePixelRatio = w->devicePixelRatio(); | 0 | ||||||||||||||||||
| 83 | } else { | - | ||||||||||||||||||
| 84 | devicePixelRatio = ctx->screen() ? ctx->screen()->devicePixelRatio() : qGuiApp->devicePixelRatio();
| 0 | ||||||||||||||||||
| 85 | } never executed: end of block | 0 | ||||||||||||||||||
| 86 | return devicePixelRatio; executed 304 times by 1 test: return devicePixelRatio;Executed by:
| 304 | ||||||||||||||||||
| 87 | } | - | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | class QSGTextMaskShader : public QSGMaterialShader | - | ||||||||||||||||||
| 90 | { | - | ||||||||||||||||||
| 91 | public: | - | ||||||||||||||||||
| 92 | QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat); | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; | - | ||||||||||||||||||
| 95 | char const *const *attributeNames() const override; | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | protected: | - | ||||||||||||||||||
| 98 | void initialize() override; | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | int m_matrix_id; | - | ||||||||||||||||||
| 101 | int m_color_id; | - | ||||||||||||||||||
| 102 | int m_textureScale_id; | - | ||||||||||||||||||
| 103 | float m_devicePixelRatio; | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | QFontEngine::GlyphFormat m_glyphFormat; | - | ||||||||||||||||||
| 106 | }; | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | char const *const *QSGTextMaskShader::attributeNames() const | - | ||||||||||||||||||
| 109 | { | - | ||||||||||||||||||
| 110 | static char const *const attr[] = { "vCoord", "tCoord", nullptr }; | - | ||||||||||||||||||
| 111 | return attr; executed 664 times by 1 test: return attr;Executed by:
| 664 | ||||||||||||||||||
| 112 | } | - | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | QSGTextMaskShader::QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 115 | : QSGMaterialShader(*new QSGMaterialShaderPrivate) | - | ||||||||||||||||||
| 116 | , m_matrix_id(-1) | - | ||||||||||||||||||
| 117 | , m_color_id(-1) | - | ||||||||||||||||||
| 118 | , m_textureScale_id(-1) | - | ||||||||||||||||||
| 119 | , m_glyphFormat(glyphFormat) | - | ||||||||||||||||||
| 120 | { | - | ||||||||||||||||||
| 121 | setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/textmask.vert")); executed 16 times by 1 test: return qstring_literal_temp;Executed by:
| 16 | ||||||||||||||||||
| 122 | setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/textmask.frag")); executed 16 times by 1 test: return qstring_literal_temp;Executed by:
| 16 | ||||||||||||||||||
| 123 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 124 | - | |||||||||||||||||||
| 125 | static inline qreal fontSmoothingGamma() | - | ||||||||||||||||||
| 126 | { | - | ||||||||||||||||||
| 127 | static qreal fontSmoothingGamma = QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal(); | - | ||||||||||||||||||
| 128 | return fontSmoothingGamma; never executed: return fontSmoothingGamma; | 0 | ||||||||||||||||||
| 129 | } | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | void QSGTextMaskShader::initialize() | - | ||||||||||||||||||
| 132 | { | - | ||||||||||||||||||
| 133 | m_matrix_id = program()->uniformLocation("matrix"); | - | ||||||||||||||||||
| 134 | m_color_id = program()->uniformLocation("color"); | - | ||||||||||||||||||
| 135 | m_textureScale_id = program()->uniformLocation("textureScale"); | - | ||||||||||||||||||
| 136 | m_devicePixelRatio = (float) qsg_device_pixel_ratio(QOpenGLContext::currentContext()); | - | ||||||||||||||||||
| 137 | program()->setUniformValue("dpr", m_devicePixelRatio); | - | ||||||||||||||||||
| 138 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) | - | ||||||||||||||||||
| 141 | { | - | ||||||||||||||||||
| 142 | QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); | - | ||||||||||||||||||
| 143 | QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); | - | ||||||||||||||||||
| 144 | Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); | - | ||||||||||||||||||
| 145 | bool updated = material->ensureUpToDate(); | - | ||||||||||||||||||
| 146 | Q_ASSERT(material->texture()); | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | Q_ASSERT(oldMaterial == nullptr || oldMaterial->texture()); | - | ||||||||||||||||||
| 149 | if (updated
| 72-144 | ||||||||||||||||||
| 150 | || oldMaterial == nullptr
| 0-144 | ||||||||||||||||||
| 151 | || oldMaterial->texture()->textureId() != material->texture()->textureId()) {
| 0 | ||||||||||||||||||
| 152 | program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->cacheTextureWidth(), | - | ||||||||||||||||||
| 153 | 1.0 / material->cacheTextureHeight())); | - | ||||||||||||||||||
| 154 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||
| 155 | funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | // Set the mag/min filters to be nearest. We only need to do this when the texture | - | ||||||||||||||||||
| 158 | // has been recreated. | - | ||||||||||||||||||
| 159 | if (updated) {
| 72-144 | ||||||||||||||||||
| 160 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
| 161 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||
| 162 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 163 | } executed 216 times by 1 test: end of blockExecuted by:
| 216 | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | float devicePixelRatio = (float) qsg_device_pixel_ratio(QOpenGLContext::currentContext()); | - | ||||||||||||||||||
| 166 | if (m_devicePixelRatio != devicePixelRatio) {
| 0-216 | ||||||||||||||||||
| 167 | m_devicePixelRatio = devicePixelRatio; | - | ||||||||||||||||||
| 168 | program()->setUniformValue("dpr", m_devicePixelRatio); | - | ||||||||||||||||||
| 169 | } never executed: end of block | 0 | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | if (state.isMatrixDirty())
| 0-216 | ||||||||||||||||||
| 172 | program()->setUniformValue(m_matrix_id, state.combinedMatrix()); executed 216 times by 1 test: program()->setUniformValue(m_matrix_id, state.combinedMatrix());Executed by:
| 216 | ||||||||||||||||||
| 173 | } executed 216 times by 1 test: end of blockExecuted by:
| 216 | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | class QSG8BitTextMaskShader : public QSGTextMaskShader | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | public: | - | ||||||||||||||||||
| 178 | QSG8BitTextMaskShader(QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 179 | : QSGTextMaskShader(glyphFormat) | - | ||||||||||||||||||
| 180 | { | - | ||||||||||||||||||
| 181 | setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/8bittextmask.frag")); executed 16 times by 1 test: return qstring_literal_temp;Executed by:
| 16 | ||||||||||||||||||
| 182 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; | - | ||||||||||||||||||
| 185 | }; | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | void QSG8BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) | - | ||||||||||||||||||
| 188 | { | - | ||||||||||||||||||
| 189 | QSGTextMaskShader::updateState(state, newEffect, oldEffect); | - | ||||||||||||||||||
| 190 | QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); | - | ||||||||||||||||||
| 191 | QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); | - | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) {
| 0-216 | ||||||||||||||||||
| 194 | QVector4D color = qsg_premultiply(material->color(), state.opacity()); | - | ||||||||||||||||||
| 195 | program()->setUniformValue(m_color_id, color); | - | ||||||||||||||||||
| 196 | } executed 216 times by 1 test: end of blockExecuted by:
| 216 | ||||||||||||||||||
| 197 | } executed 216 times by 1 test: end of blockExecuted by:
| 216 | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | class QSG24BitTextMaskShader : public QSGTextMaskShader | - | ||||||||||||||||||
| 200 | { | - | ||||||||||||||||||
| 201 | public: | - | ||||||||||||||||||
| 202 | QSG24BitTextMaskShader(QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 203 | : QSGTextMaskShader(glyphFormat) | - | ||||||||||||||||||
| 204 | , m_useSRGB(false) | - | ||||||||||||||||||
| 205 | { | - | ||||||||||||||||||
| 206 | setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/24bittextmask.frag")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 207 | } never executed: end of block | 0 | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; | - | ||||||||||||||||||
| 210 | void initialize() override; | - | ||||||||||||||||||
| 211 | void activate() override; | - | ||||||||||||||||||
| 212 | void deactivate() override; | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | bool useSRGB() const; | - | ||||||||||||||||||
| 215 | uint m_useSRGB : 1; | - | ||||||||||||||||||
| 216 | }; | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | void QSG24BitTextMaskShader::initialize() | - | ||||||||||||||||||
| 219 | { | - | ||||||||||||||||||
| 220 | QSGTextMaskShader::initialize(); | - | ||||||||||||||||||
| 221 | // 0.25 was found to be acceptable error margin by experimentation. On Mac, the gamma is 2.0, | - | ||||||||||||||||||
| 222 | // but using sRGB looks okay. | - | ||||||||||||||||||
| 223 | if (QOpenGLContext::currentContext()->hasExtension(QByteArrayLiteral("GL_ARB_framebuffer_sRGB")) never executed: return ba;
| 0 | ||||||||||||||||||
| 224 | && m_glyphFormat == QFontEngine::Format_A32
| 0 | ||||||||||||||||||
| 225 | && qAbs(fontSmoothingGamma() - 2.2) < 0.25) {
| 0 | ||||||||||||||||||
| 226 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||
| 227 | GLint srgbCapable = 0; | - | ||||||||||||||||||
| 228 | funcs->glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE, &srgbCapable); | - | ||||||||||||||||||
| 229 | if (srgbCapable)
| 0 | ||||||||||||||||||
| 230 | m_useSRGB = true; never executed: m_useSRGB = true; | 0 | ||||||||||||||||||
| 231 | } never executed: end of block | 0 | ||||||||||||||||||
| 232 | } never executed: end of block | 0 | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | bool QSG24BitTextMaskShader::useSRGB() const | - | ||||||||||||||||||
| 235 | { | - | ||||||||||||||||||
| 236 | #ifdef Q_OS_MACOS | - | ||||||||||||||||||
| 237 | if (!m_useSRGB) | - | ||||||||||||||||||
| 238 | return false; | - | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | // m_useSRGB is true, but if some QOGLFBO was bound check it's texture format: | - | ||||||||||||||||||
| 241 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 242 | QOpenGLFramebufferObject *qfbo = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo; | - | ||||||||||||||||||
| 243 | bool fboInvalid = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo_invalid; | - | ||||||||||||||||||
| 244 | return !qfbo || fboInvalid || qfbo->format().internalTextureFormat() == GL_SRGB8_ALPHA8_EXT; | - | ||||||||||||||||||
| 245 | #else | - | ||||||||||||||||||
| 246 | return m_useSRGB; never executed: return m_useSRGB; | 0 | ||||||||||||||||||
| 247 | #endif | - | ||||||||||||||||||
| 248 | } | - | ||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | void QSG24BitTextMaskShader::activate() | - | ||||||||||||||||||
| 251 | { | - | ||||||||||||||||||
| 252 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||
| 253 | funcs->glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); | - | ||||||||||||||||||
| 254 | if (useSRGB())
| 0 | ||||||||||||||||||
| 255 | funcs->glEnable(GL_FRAMEBUFFER_SRGB); never executed: funcs->glEnable(0x8DB9); | 0 | ||||||||||||||||||
| 256 | } never executed: end of block | 0 | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | void QSG24BitTextMaskShader::deactivate() | - | ||||||||||||||||||
| 259 | { | - | ||||||||||||||||||
| 260 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||
| 261 | funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | - | ||||||||||||||||||
| 262 | if (useSRGB())
| 0 | ||||||||||||||||||
| 263 | funcs->glDisable(GL_FRAMEBUFFER_SRGB); never executed: funcs->glDisable(0x8DB9); | 0 | ||||||||||||||||||
| 264 | } never executed: end of block | 0 | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | static inline qreal qt_sRGB_to_linear_RGB(qreal f) | - | ||||||||||||||||||
| 267 | { | - | ||||||||||||||||||
| 268 | return f > 0.04045 ? qPow((f + 0.055) / 1.055, 2.4) : f / 12.92; never executed: return f > 0.04045 ? qPow((f + 0.055) / 1.055, 2.4) : f / 12.92; | 0 | ||||||||||||||||||
| 269 | } | - | ||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | static inline QVector4D qt_sRGB_to_linear_RGB(const QVector4D &color) | - | ||||||||||||||||||
| 272 | { | - | ||||||||||||||||||
| 273 | return QVector4D(qt_sRGB_to_linear_RGB(color.x()), never executed: return QVector4D(qt_sRGB_to_linear_RGB(color.x()), qt_sRGB_to_linear_RGB(color.y()), qt_sRGB_to_linear_RGB(color.z()), color.w()); | 0 | ||||||||||||||||||
| 274 | qt_sRGB_to_linear_RGB(color.y()), never executed: return QVector4D(qt_sRGB_to_linear_RGB(color.x()), qt_sRGB_to_linear_RGB(color.y()), qt_sRGB_to_linear_RGB(color.z()), color.w()); | 0 | ||||||||||||||||||
| 275 | qt_sRGB_to_linear_RGB(color.z()), never executed: return QVector4D(qt_sRGB_to_linear_RGB(color.x()), qt_sRGB_to_linear_RGB(color.y()), qt_sRGB_to_linear_RGB(color.z()), color.w()); | 0 | ||||||||||||||||||
| 276 | color.w()); never executed: return QVector4D(qt_sRGB_to_linear_RGB(color.x()), qt_sRGB_to_linear_RGB(color.y()), qt_sRGB_to_linear_RGB(color.z()), color.w()); | 0 | ||||||||||||||||||
| 277 | } | - | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) | - | ||||||||||||||||||
| 280 | { | - | ||||||||||||||||||
| 281 | QSGTextMaskShader::updateState(state, newEffect, oldEffect); | - | ||||||||||||||||||
| 282 | QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); | - | ||||||||||||||||||
| 283 | QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); | - | ||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) {
| 0 | ||||||||||||||||||
| 286 | QVector4D color = material->color(); | - | ||||||||||||||||||
| 287 | if (useSRGB())
| 0 | ||||||||||||||||||
| 288 | color = qt_sRGB_to_linear_RGB(color); never executed: color = qt_sRGB_to_linear_RGB(color); | 0 | ||||||||||||||||||
| 289 | QOpenGLContext::currentContext()->functions()->glBlendColor(color.x(), color.y(), color.z(), color.w()); | - | ||||||||||||||||||
| 290 | color = qsg_premultiply(color, state.opacity()); | - | ||||||||||||||||||
| 291 | program()->setUniformValue(m_color_id, color.w()); | - | ||||||||||||||||||
| 292 | } never executed: end of block | 0 | ||||||||||||||||||
| 293 | } never executed: end of block | 0 | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | class QSG32BitColorTextShader : public QSGTextMaskShader | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | public: | - | ||||||||||||||||||
| 298 | QSG32BitColorTextShader(QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 299 | : QSGTextMaskShader(glyphFormat) | - | ||||||||||||||||||
| 300 | { | - | ||||||||||||||||||
| 301 | setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/32bitcolortext.frag")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 302 | } never executed: end of block | 0 | ||||||||||||||||||
| 303 | - | |||||||||||||||||||
| 304 | void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; | - | ||||||||||||||||||
| 305 | }; | - | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | void QSG32BitColorTextShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) | - | ||||||||||||||||||
| 308 | { | - | ||||||||||||||||||
| 309 | QSGTextMaskShader::updateState(state, newEffect, oldEffect); | - | ||||||||||||||||||
| 310 | QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); | - | ||||||||||||||||||
| 311 | QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); | - | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) {
| 0 | ||||||||||||||||||
| 314 | float opacity = material->color().w() * state.opacity(); | - | ||||||||||||||||||
| 315 | program()->setUniformValue(m_color_id, opacity); | - | ||||||||||||||||||
| 316 | } never executed: end of block | 0 | ||||||||||||||||||
| 317 | } never executed: end of block | 0 | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | class QSGStyledTextShader : public QSG8BitTextMaskShader | - | ||||||||||||||||||
| 320 | { | - | ||||||||||||||||||
| 321 | public: | - | ||||||||||||||||||
| 322 | QSGStyledTextShader(QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 323 | : QSG8BitTextMaskShader(glyphFormat) | - | ||||||||||||||||||
| 324 | { | - | ||||||||||||||||||
| 325 | setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/styledtext.vert")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 326 | setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/styledtext.frag")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 327 | } never executed: end of block | 0 | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; | - | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | private: | - | ||||||||||||||||||
| 332 | void initialize() override; | - | ||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | int m_shift_id; | - | ||||||||||||||||||
| 335 | int m_styleColor_id; | - | ||||||||||||||||||
| 336 | }; | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | void QSGStyledTextShader::initialize() | - | ||||||||||||||||||
| 339 | { | - | ||||||||||||||||||
| 340 | QSG8BitTextMaskShader::initialize(); | - | ||||||||||||||||||
| 341 | m_shift_id = program()->uniformLocation("shift"); | - | ||||||||||||||||||
| 342 | m_styleColor_id = program()->uniformLocation("styleColor"); | - | ||||||||||||||||||
| 343 | } never executed: end of block | 0 | ||||||||||||||||||
| 344 | - | |||||||||||||||||||
| 345 | void QSGStyledTextShader::updateState(const RenderState &state, | - | ||||||||||||||||||
| 346 | QSGMaterial *newEffect, | - | ||||||||||||||||||
| 347 | QSGMaterial *oldEffect) | - | ||||||||||||||||||
| 348 | { | - | ||||||||||||||||||
| 349 | Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); | - | ||||||||||||||||||
| 350 | - | |||||||||||||||||||
| 351 | QSGStyledTextMaterial *material = static_cast<QSGStyledTextMaterial *>(newEffect); | - | ||||||||||||||||||
| 352 | QSGStyledTextMaterial *oldMaterial = static_cast<QSGStyledTextMaterial *>(oldEffect); | - | ||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | if (oldMaterial == nullptr || oldMaterial->styleShift() != material->styleShift())
| 0 | ||||||||||||||||||
| 355 | program()->setUniformValue(m_shift_id, material->styleShift()); never executed: program()->setUniformValue(m_shift_id, material->styleShift()); | 0 | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) {
| 0 | ||||||||||||||||||
| 358 | QVector4D color = qsg_premultiply(material->color(), state.opacity()); | - | ||||||||||||||||||
| 359 | program()->setUniformValue(m_color_id, color); | - | ||||||||||||||||||
| 360 | } never executed: end of block | 0 | ||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | if (oldMaterial == nullptr || material->styleColor() != oldMaterial->styleColor() || state.isOpacityDirty()) {
| 0 | ||||||||||||||||||
| 363 | QVector4D styleColor = qsg_premultiply(material->styleColor(), state.opacity()); | - | ||||||||||||||||||
| 364 | program()->setUniformValue(m_styleColor_id, styleColor); | - | ||||||||||||||||||
| 365 | } never executed: end of block | 0 | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | bool updated = material->ensureUpToDate(); | - | ||||||||||||||||||
| 368 | Q_ASSERT(material->texture()); | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | Q_ASSERT(oldMaterial == nullptr || oldMaterial->texture()); | - | ||||||||||||||||||
| 371 | if (updated
| 0 | ||||||||||||||||||
| 372 | || oldMaterial == nullptr
| 0 | ||||||||||||||||||
| 373 | || oldMaterial->texture()->textureId() != material->texture()->textureId()) {
| 0 | ||||||||||||||||||
| 374 | program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->cacheTextureWidth(), | - | ||||||||||||||||||
| 375 | 1.0 / material->cacheTextureHeight())); | - | ||||||||||||||||||
| 376 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||
| 377 | funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); | - | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | // Set the mag/min filters to be linear. We only need to do this when the texture | - | ||||||||||||||||||
| 380 | // has been recreated. | - | ||||||||||||||||||
| 381 | if (updated) {
| 0 | ||||||||||||||||||
| 382 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||
| 383 | funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||
| 384 | } never executed: end of block | 0 | ||||||||||||||||||
| 385 | } never executed: end of block | 0 | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | if (state.isMatrixDirty())
| 0 | ||||||||||||||||||
| 388 | program()->setUniformValue(m_matrix_id, state.combinedMatrix()); never executed: program()->setUniformValue(m_matrix_id, state.combinedMatrix()); | 0 | ||||||||||||||||||
| 389 | } never executed: end of block | 0 | ||||||||||||||||||
| 390 | - | |||||||||||||||||||
| 391 | class QSGOutlinedTextShader : public QSGStyledTextShader | - | ||||||||||||||||||
| 392 | { | - | ||||||||||||||||||
| 393 | public: | - | ||||||||||||||||||
| 394 | QSGOutlinedTextShader(QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 395 | : QSGStyledTextShader(glyphFormat) | - | ||||||||||||||||||
| 396 | { | - | ||||||||||||||||||
| 397 | setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/outlinedtext.vert")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 398 | setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/outlinedtext.frag")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 399 | } never executed: end of block | 0 | ||||||||||||||||||
| 400 | }; | - | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | QSGTextMaskMaterial::QSGTextMaskMaterial(const QRawFont &font, QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 403 | : m_texture(nullptr) | - | ||||||||||||||||||
| 404 | , m_glyphCache(nullptr) | - | ||||||||||||||||||
| 405 | , m_font(font) | - | ||||||||||||||||||
| 406 | { | - | ||||||||||||||||||
| 407 | init(glyphFormat); | - | ||||||||||||||||||
| 408 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | QSGTextMaskMaterial::~QSGTextMaskMaterial() | - | ||||||||||||||||||
| 411 | { | - | ||||||||||||||||||
| 412 | delete m_texture; | - | ||||||||||||||||||
| 413 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | void QSGTextMaskMaterial::init(QFontEngine::GlyphFormat glyphFormat) | - | ||||||||||||||||||
| 416 | { | - | ||||||||||||||||||
| 417 | Q_ASSERT(m_font.isValid()); | - | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | setFlag(Blending, true); | - | ||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext()); | - | ||||||||||||||||||
| 422 | Q_ASSERT(ctx != nullptr); | - | ||||||||||||||||||
| 423 | - | |||||||||||||||||||
| 424 | // The following piece of code will read/write to the font engine's caches, | - | ||||||||||||||||||
| 425 | // potentially from different threads. However, this is safe because this | - | ||||||||||||||||||
| 426 | // code is only called from QQuickItem::updatePaintNode() which is called | - | ||||||||||||||||||
| 427 | // only when the GUI is blocked, and multiple threads will call it in | - | ||||||||||||||||||
| 428 | // sequence. See also QSGRenderContext::invalidate | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | QRawFontPrivate *fontD = QRawFontPrivate::get(m_font); | - | ||||||||||||||||||
| 431 | if (QFontEngine *fontEngine = fontD->fontEngine) {
| 0-72 | ||||||||||||||||||
| 432 | if (glyphFormat == QFontEngine::Format_None) {
| 0-72 | ||||||||||||||||||
| 433 | glyphFormat = fontEngine->glyphFormat != QFontEngine::Format_None
| 0-72 | ||||||||||||||||||
| 434 | ? fontEngine->glyphFormat | - | ||||||||||||||||||
| 435 | : QFontEngine::Format_A32; | - | ||||||||||||||||||
| 436 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | qreal devicePixelRatio = qsg_device_pixel_ratio(ctx); | - | ||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | QTransform glyphCacheTransform = QTransform::fromScale(devicePixelRatio, devicePixelRatio); | - | ||||||||||||||||||
| 442 | if (!fontEngine->supportsTransformation(glyphCacheTransform))
| 0-72 | ||||||||||||||||||
| 443 | glyphCacheTransform = QTransform(); never executed: glyphCacheTransform = QTransform(); | 0 | ||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | m_glyphCache = fontEngine->glyphCache(ctx, glyphFormat, glyphCacheTransform); | - | ||||||||||||||||||
| 446 | if (!m_glyphCache || int(m_glyphCache->glyphFormat()) != glyphFormat) {
| 0-56 | ||||||||||||||||||
| 447 | m_glyphCache = new QOpenGLTextureGlyphCache(glyphFormat, glyphCacheTransform); | - | ||||||||||||||||||
| 448 | fontEngine->setGlyphCache(ctx, m_glyphCache.data()); | - | ||||||||||||||||||
| 449 | auto sg = QSGDefaultRenderContext::from(ctx); | - | ||||||||||||||||||
| 450 | Q_ASSERT(sg); | - | ||||||||||||||||||
| 451 | sg->registerFontengineForCleanup(fontEngine); | - | ||||||||||||||||||
| 452 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 453 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 454 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | void QSGTextMaskMaterial::populate(const QPointF &p, | - | ||||||||||||||||||
| 457 | const QVector<quint32> &glyphIndexes, | - | ||||||||||||||||||
| 458 | const QVector<QPointF> &glyphPositions, | - | ||||||||||||||||||
| 459 | QSGGeometry *geometry, | - | ||||||||||||||||||
| 460 | QRectF *boundingRect, | - | ||||||||||||||||||
| 461 | QPointF *baseLine, | - | ||||||||||||||||||
| 462 | const QMargins &margins) | - | ||||||||||||||||||
| 463 | { | - | ||||||||||||||||||
| 464 | Q_ASSERT(m_font.isValid()); | - | ||||||||||||||||||
| 465 | QVector<QFixedPoint> fixedPointPositions; | - | ||||||||||||||||||
| 466 | const int glyphPositionsSize = glyphPositions.size(); | - | ||||||||||||||||||
| 467 | fixedPointPositions.reserve(glyphPositionsSize); | - | ||||||||||||||||||
| 468 | for (int i=0; i < glyphPositionsSize; ++i)
| 72-4968 | ||||||||||||||||||
| 469 | fixedPointPositions.append(QFixedPoint::fromPointF(glyphPositions.at(i))); executed 4968 times by 1 test: fixedPointPositions.append(QFixedPoint::fromPointF(glyphPositions.at(i)));Executed by:
| 4968 | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | QTextureGlyphCache *cache = glyphCache(); | - | ||||||||||||||||||
| 472 | - | |||||||||||||||||||
| 473 | QRawFontPrivate *fontD = QRawFontPrivate::get(m_font); | - | ||||||||||||||||||
| 474 | cache->populate(fontD->fontEngine, glyphIndexes.size(), glyphIndexes.constData(), | - | ||||||||||||||||||
| 475 | fixedPointPositions.data()); | - | ||||||||||||||||||
| 476 | cache->fillInPendingGlyphs(); | - | ||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | int margin = fontD->fontEngine->glyphMargin(cache->glyphFormat()); | - | ||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | qreal glyphCacheScaleX = cache->transform().m11(); | - | ||||||||||||||||||
| 481 | qreal glyphCacheScaleY = cache->transform().m22(); | - | ||||||||||||||||||
| 482 | qreal glyphCacheInverseScaleX = 1.0 / glyphCacheScaleX; | - | ||||||||||||||||||
| 483 | qreal glyphCacheInverseScaleY = 1.0 / glyphCacheScaleY; | - | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | Q_ASSERT(geometry->indexType() == GL_UNSIGNED_SHORT); | - | ||||||||||||||||||
| 486 | geometry->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6); | - | ||||||||||||||||||
| 487 | QVector4D *vp = (QVector4D *)geometry->vertexDataAsTexturedPoint2D(); | - | ||||||||||||||||||
| 488 | Q_ASSERT(geometry->sizeOfVertex() == sizeof(QVector4D)); | - | ||||||||||||||||||
| 489 | ushort *ip = geometry->indexDataAsUShort(); | - | ||||||||||||||||||
| 490 | - | |||||||||||||||||||
| 491 | QPointF position(p.x(), p.y() - m_font.ascent()); | - | ||||||||||||||||||
| 492 | bool supportsSubPixelPositions = fontD->fontEngine->supportsSubPixelPositions(); | - | ||||||||||||||||||
| 493 | for (int i=0; i<glyphIndexes.size(); ++i) {
| 72-4968 | ||||||||||||||||||
| 494 | QFixed subPixelPosition; | - | ||||||||||||||||||
| 495 | if (supportsSubPixelPositions)
| 0-4968 | ||||||||||||||||||
| 496 | subPixelPosition = fontD->fontEngine->subPixelPositionForX(QFixed::fromReal(glyphPositions.at(i).x())); never executed: subPixelPosition = fontD->fontEngine->subPixelPositionForX(QFixed::fromReal(glyphPositions.at(i).x())); | 0 | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | QTextureGlyphCache::GlyphAndSubPixelPosition glyph(glyphIndexes.at(i), subPixelPosition); | - | ||||||||||||||||||
| 499 | const QTextureGlyphCache::Coord &c = cache->coords.value(glyph); | - | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | QPointF glyphPosition = glyphPositions.at(i) + position; | - | ||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | // On a retina screen the glyph positions are not pre-scaled (as opposed to | - | ||||||||||||||||||
| 504 | // eg. the raster paint engine). To ensure that we get the same behavior as | - | ||||||||||||||||||
| 505 | // the raster engine (and CoreText itself) when it comes to rounding of the | - | ||||||||||||||||||
| 506 | // coordinates, we need to apply the scale factor before rounding, and then | - | ||||||||||||||||||
| 507 | // apply the inverse scale to get back to the coordinate system of the node. | - | ||||||||||||||||||
| 508 | - | |||||||||||||||||||
| 509 | qreal x = (qFloor(glyphPosition.x() * glyphCacheScaleX) * glyphCacheInverseScaleX) + | - | ||||||||||||||||||
| 510 | (c.baseLineX * glyphCacheInverseScaleX) - margin; | - | ||||||||||||||||||
| 511 | qreal y = (qRound(glyphPosition.y() * glyphCacheScaleY) * glyphCacheInverseScaleY) - | - | ||||||||||||||||||
| 512 | (c.baseLineY * glyphCacheInverseScaleY) - margin; | - | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | qreal w = c.w * glyphCacheInverseScaleX; | - | ||||||||||||||||||
| 515 | qreal h = c.h * glyphCacheInverseScaleY; | - | ||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | *boundingRect |= QRectF(x + margin, y + margin, w, h); | - | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | float cx1 = x - margins.left(); | - | ||||||||||||||||||
| 520 | float cx2 = x + w + margins.right(); | - | ||||||||||||||||||
| 521 | float cy1 = y - margins.top(); | - | ||||||||||||||||||
| 522 | float cy2 = y + h + margins.bottom(); | - | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | float tx1 = c.x - margins.left(); | - | ||||||||||||||||||
| 525 | float tx2 = c.x + c.w + margins.right(); | - | ||||||||||||||||||
| 526 | float ty1 = c.y - margins.top(); | - | ||||||||||||||||||
| 527 | float ty2 = c.y + c.h + margins.bottom(); | - | ||||||||||||||||||
| 528 | - | |||||||||||||||||||
| 529 | if (baseLine->isNull())
| 72-4896 | ||||||||||||||||||
| 530 | *baseLine = glyphPosition; executed 72 times by 1 test: *baseLine = glyphPosition;Executed by:
| 72 | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | vp[4 * i + 0] = QVector4D(cx1, cy1, tx1, ty1); | - | ||||||||||||||||||
| 533 | vp[4 * i + 1] = QVector4D(cx2, cy1, tx2, ty1); | - | ||||||||||||||||||
| 534 | vp[4 * i + 2] = QVector4D(cx1, cy2, tx1, ty2); | - | ||||||||||||||||||
| 535 | vp[4 * i + 3] = QVector4D(cx2, cy2, tx2, ty2); | - | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | int o = i * 4; | - | ||||||||||||||||||
| 538 | ip[6 * i + 0] = o + 0; | - | ||||||||||||||||||
| 539 | ip[6 * i + 1] = o + 2; | - | ||||||||||||||||||
| 540 | ip[6 * i + 2] = o + 3; | - | ||||||||||||||||||
| 541 | ip[6 * i + 3] = o + 3; | - | ||||||||||||||||||
| 542 | ip[6 * i + 4] = o + 1; | - | ||||||||||||||||||
| 543 | ip[6 * i + 5] = o + 0; | - | ||||||||||||||||||
| 544 | } executed 4968 times by 1 test: end of blockExecuted by:
| 4968 | ||||||||||||||||||
| 545 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 546 | - | |||||||||||||||||||
| 547 | QSGMaterialType *QSGTextMaskMaterial::type() const | - | ||||||||||||||||||
| 548 | { | - | ||||||||||||||||||
| 549 | static QSGMaterialType argb, rgb, gray; | - | ||||||||||||||||||
| 550 | switch (glyphCache()->glyphFormat()) { | - | ||||||||||||||||||
| 551 | case QFontEngine::Format_ARGB: never executed: case QFontEngine::Format_ARGB: | 0 | ||||||||||||||||||
| 552 | return &argb; never executed: return &argb; | 0 | ||||||||||||||||||
| 553 | case QFontEngine::Format_A32: never executed: case QFontEngine::Format_A32: | 0 | ||||||||||||||||||
| 554 | return &rgb; never executed: return &rgb; | 0 | ||||||||||||||||||
| 555 | case QFontEngine::Format_A8: executed 216 times by 1 test: case QFontEngine::Format_A8:Executed by:
| 216 | ||||||||||||||||||
| 556 | default: never executed: default: | 0 | ||||||||||||||||||
| 557 | return &gray; executed 216 times by 1 test: return &gray;Executed by:
| 216 | ||||||||||||||||||
| 558 | } | - | ||||||||||||||||||
| 559 | } | - | ||||||||||||||||||
| 560 | - | |||||||||||||||||||
| 561 | QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const | - | ||||||||||||||||||
| 562 | { | - | ||||||||||||||||||
| 563 | return static_cast<QOpenGLTextureGlyphCache*>(m_glyphCache.data()); executed 1384 times by 1 test: return static_cast<QOpenGLTextureGlyphCache*>(m_glyphCache.data());Executed by:
| 1384 | ||||||||||||||||||
| 564 | } | - | ||||||||||||||||||
| 565 | - | |||||||||||||||||||
| 566 | QSGMaterialShader *QSGTextMaskMaterial::createShader() const | - | ||||||||||||||||||
| 567 | { | - | ||||||||||||||||||
| 568 | switch (QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat()) { | - | ||||||||||||||||||
| 569 | case QFontEngine::Format_ARGB: never executed: case QFontEngine::Format_ARGB: | 0 | ||||||||||||||||||
| 570 | return new QSG32BitColorTextShader(glyphFormat); never executed: return new QSG32BitColorTextShader(glyphFormat); | 0 | ||||||||||||||||||
| 571 | case QFontEngine::Format_A32: never executed: case QFontEngine::Format_A32: | 0 | ||||||||||||||||||
| 572 | return new QSG24BitTextMaskShader(glyphFormat); never executed: return new QSG24BitTextMaskShader(glyphFormat); | 0 | ||||||||||||||||||
| 573 | case QFontEngine::Format_A8: executed 16 times by 1 test: case QFontEngine::Format_A8:Executed by:
| 16 | ||||||||||||||||||
| 574 | default: never executed: default: | 0 | ||||||||||||||||||
| 575 | return new QSG8BitTextMaskShader(glyphFormat); executed 16 times by 1 test: return new QSG8BitTextMaskShader(glyphFormat);Executed by:
| 16 | ||||||||||||||||||
| 576 | } | - | ||||||||||||||||||
| 577 | } | - | ||||||||||||||||||
| 578 | - | |||||||||||||||||||
| 579 | static inline int qsg_colorDiff(const QVector4D &a, const QVector4D &b) | - | ||||||||||||||||||
| 580 | { | - | ||||||||||||||||||
| 581 | if (a.x() != b.x())
| 0 | ||||||||||||||||||
| 582 | return a.x() > b.x() ? 1 : -1; never executed: return a.x() > b.x() ? 1 : -1; | 0 | ||||||||||||||||||
| 583 | if (a.y() != b.y())
| 0 | ||||||||||||||||||
| 584 | return a.y() > b.y() ? 1 : -1; never executed: return a.y() > b.y() ? 1 : -1; | 0 | ||||||||||||||||||
| 585 | if (a.z() != b.z())
| 0 | ||||||||||||||||||
| 586 | return a.z() > b.z() ? 1 : -1; never executed: return a.z() > b.z() ? 1 : -1; | 0 | ||||||||||||||||||
| 587 | if (a.w() != b.w())
| 0 | ||||||||||||||||||
| 588 | return a.w() > b.w() ? 1 : -1; never executed: return a.w() > b.w() ? 1 : -1; | 0 | ||||||||||||||||||
| 589 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 590 | } | - | ||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | int QSGTextMaskMaterial::compare(const QSGMaterial *o) const | - | ||||||||||||||||||
| 593 | { | - | ||||||||||||||||||
| 594 | Q_ASSERT(o && type() == o->type()); | - | ||||||||||||||||||
| 595 | const QSGTextMaskMaterial *other = static_cast<const QSGTextMaskMaterial *>(o); | - | ||||||||||||||||||
| 596 | if (m_glyphCache != other->m_glyphCache)
| 0 | ||||||||||||||||||
| 597 | return m_glyphCache.data() < other->m_glyphCache.data() ? -1 : 1; never executed: return m_glyphCache.data() < other->m_glyphCache.data() ? -1 : 1; | 0 | ||||||||||||||||||
| 598 | return qsg_colorDiff(m_color, other->m_color); never executed: return qsg_colorDiff(m_color, other->m_color); | 0 | ||||||||||||||||||
| 599 | } | - | ||||||||||||||||||
| 600 | - | |||||||||||||||||||
| 601 | bool QSGTextMaskMaterial::ensureUpToDate() | - | ||||||||||||||||||
| 602 | { | - | ||||||||||||||||||
| 603 | QSize glyphCacheSize(glyphCache()->width(), glyphCache()->height()); | - | ||||||||||||||||||
| 604 | if (glyphCacheSize != m_size) {
| 72-144 | ||||||||||||||||||
| 605 | if (m_texture)
| 0-72 | ||||||||||||||||||
| 606 | delete m_texture; never executed: delete m_texture; | 0 | ||||||||||||||||||
| 607 | m_texture = new QSGPlainTexture(); | - | ||||||||||||||||||
| 608 | m_texture->setTextureId(glyphCache()->texture()); | - | ||||||||||||||||||
| 609 | m_texture->setTextureSize(QSize(glyphCache()->width(), glyphCache()->height())); | - | ||||||||||||||||||
| 610 | m_texture->setOwnsTexture(false); | - | ||||||||||||||||||
| 611 | - | |||||||||||||||||||
| 612 | m_size = glyphCacheSize; | - | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | return true; executed 72 times by 1 test: return true;Executed by:
| 72 | ||||||||||||||||||
| 615 | } else { | - | ||||||||||||||||||
| 616 | return false; executed 144 times by 1 test: return false;Executed by:
| 144 | ||||||||||||||||||
| 617 | } | - | ||||||||||||||||||
| 618 | } | - | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | int QSGTextMaskMaterial::cacheTextureWidth() const | - | ||||||||||||||||||
| 621 | { | - | ||||||||||||||||||
| 622 | return glyphCache()->width(); executed 216 times by 1 test: return glyphCache()->width();Executed by:
| 216 | ||||||||||||||||||
| 623 | } | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | int QSGTextMaskMaterial::cacheTextureHeight() const | - | ||||||||||||||||||
| 626 | { | - | ||||||||||||||||||
| 627 | return glyphCache()->height(); executed 216 times by 1 test: return glyphCache()->height();Executed by:
| 216 | ||||||||||||||||||
| 628 | } | - | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | QSGStyledTextMaterial::QSGStyledTextMaterial(const QRawFont &font) | - | ||||||||||||||||||
| 632 | : QSGTextMaskMaterial(font, QFontEngine::Format_A8) | - | ||||||||||||||||||
| 633 | { | - | ||||||||||||||||||
| 634 | } never executed: end of block | 0 | ||||||||||||||||||
| 635 | - | |||||||||||||||||||
| 636 | QSGMaterialType *QSGStyledTextMaterial::type() const | - | ||||||||||||||||||
| 637 | { | - | ||||||||||||||||||
| 638 | static QSGMaterialType type; | - | ||||||||||||||||||
| 639 | return &type; never executed: return &type; | 0 | ||||||||||||||||||
| 640 | } | - | ||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | QSGMaterialShader *QSGStyledTextMaterial::createShader() const | - | ||||||||||||||||||
| 643 | { | - | ||||||||||||||||||
| 644 | return new QSGStyledTextShader(glyphCache()->glyphFormat()); never executed: return new QSGStyledTextShader(glyphCache()->glyphFormat()); | 0 | ||||||||||||||||||
| 645 | } | - | ||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | int QSGStyledTextMaterial::compare(const QSGMaterial *o) const | - | ||||||||||||||||||
| 648 | { | - | ||||||||||||||||||
| 649 | const QSGStyledTextMaterial *other = static_cast<const QSGStyledTextMaterial *>(o); | - | ||||||||||||||||||
| 650 | - | |||||||||||||||||||
| 651 | if (m_styleShift != other->m_styleShift)
| 0 | ||||||||||||||||||
| 652 | return m_styleShift.y() - other->m_styleShift.y(); never executed: return m_styleShift.y() - other->m_styleShift.y(); | 0 | ||||||||||||||||||
| 653 | - | |||||||||||||||||||
| 654 | int diff = qsg_colorDiff(m_styleColor, other->m_styleColor); | - | ||||||||||||||||||
| 655 | if (diff == 0)
| 0 | ||||||||||||||||||
| 656 | return QSGTextMaskMaterial::compare(o); never executed: return QSGTextMaskMaterial::compare(o); | 0 | ||||||||||||||||||
| 657 | return diff; never executed: return diff; | 0 | ||||||||||||||||||
| 658 | } | - | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | - | |||||||||||||||||||
| 661 | QSGOutlinedTextMaterial::QSGOutlinedTextMaterial(const QRawFont &font) | - | ||||||||||||||||||
| 662 | : QSGStyledTextMaterial(font) | - | ||||||||||||||||||
| 663 | { | - | ||||||||||||||||||
| 664 | } never executed: end of block | 0 | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | QSGMaterialType *QSGOutlinedTextMaterial::type() const | - | ||||||||||||||||||
| 667 | { | - | ||||||||||||||||||
| 668 | static QSGMaterialType type; | - | ||||||||||||||||||
| 669 | return &type; never executed: return &type; | 0 | ||||||||||||||||||
| 670 | } | - | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | QSGMaterialShader *QSGOutlinedTextMaterial::createShader() const | - | ||||||||||||||||||
| 673 | { | - | ||||||||||||||||||
| 674 | return new QSGOutlinedTextShader(glyphCache()->glyphFormat()); never executed: return new QSGOutlinedTextShader(glyphCache()->glyphFormat()); | 0 | ||||||||||||||||||
| 675 | } | - | ||||||||||||||||||
| 676 | - | |||||||||||||||||||
| 677 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |