| 1 | // Copyright (C) 2016 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 | |
| 4 | #include "qsgsoftwarecontext_p.h" |
| 5 | |
| 6 | #include "qsgsoftwareinternalrectanglenode_p.h" |
| 7 | #include "qsgsoftwareinternalimagenode_p.h" |
| 8 | #include "qsgsoftwarepainternode_p.h" |
| 9 | #include "qsgsoftwarepixmaptexture_p.h" |
| 10 | #include "qsgsoftwareglyphnode_p.h" |
| 11 | #include "qsgsoftwarepublicnodes_p.h" |
| 12 | #include "qsgsoftwarelayer_p.h" |
| 13 | #include "qsgsoftwarerenderer_p.h" |
| 14 | #if QT_CONFIG(quick_sprite) |
| 15 | #include "qsgsoftwarespritenode_p.h" |
| 16 | #endif |
| 17 | |
| 18 | #include <QtCore/QCoreApplication> |
| 19 | #include <QtCore/QElapsedTimer> |
| 20 | |
| 21 | #include <QtGui/QWindow> |
| 22 | #include <QtQuick/private/qquickwindow_p.h> |
| 23 | #include <QtQuick/private/qquickitem_p.h> |
| 24 | |
| 25 | // Used for very high-level info about the renderering and gl context |
| 26 | // Includes GL_VERSION, type of render loop, atlas size, etc. |
| 27 | Q_LOGGING_CATEGORY(QSG_RASTER_LOG_INFO, "qt.scenegraph.info" ) |
| 28 | |
| 29 | // Used to debug the renderloop logic. Primarily useful for platform integrators |
| 30 | // and when investigating the render loop logic. |
| 31 | Q_LOGGING_CATEGORY(QSG_RASTER_LOG_RENDERLOOP, "qt.scenegraph.renderloop" ) |
| 32 | |
| 33 | // GLSL shader compilation |
| 34 | Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_COMPILATION, "qt.scenegraph.time.compilation" ) |
| 35 | |
| 36 | // polish, animations, sync, render and swap in the render loop |
| 37 | Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_RENDERLOOP, "qt.scenegraph.time.renderloop" ) |
| 38 | |
| 39 | // Texture uploads and swizzling |
| 40 | Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_TEXTURE, "qt.scenegraph.time.texture" ) |
| 41 | |
| 42 | // Glyph preparation (only for distance fields atm) |
| 43 | Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_GLYPH, "qt.scenegraph.time.glyph" ) |
| 44 | |
| 45 | // Timing inside the renderer base class |
| 46 | Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_RENDERER, "qt.scenegraph.time.renderer" ) |
| 47 | |
| 48 | QT_BEGIN_NAMESPACE |
| 49 | |
| 50 | QSGSoftwareRenderContext::QSGSoftwareRenderContext(QSGContext *ctx) |
| 51 | : QSGRenderContext(ctx) |
| 52 | , m_initialized(false) |
| 53 | , m_activePainter(nullptr) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | QSGSoftwareContext::QSGSoftwareContext(QObject *parent) |
| 58 | : QSGContext(parent) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | QSGInternalRectangleNode *QSGSoftwareContext::createInternalRectangleNode() |
| 63 | { |
| 64 | return new QSGSoftwareInternalRectangleNode(); |
| 65 | } |
| 66 | |
| 67 | QSGInternalImageNode *QSGSoftwareContext::createInternalImageNode(QSGRenderContext *renderContext) |
| 68 | { |
| 69 | Q_UNUSED(renderContext); |
| 70 | return new QSGSoftwareInternalImageNode(); |
| 71 | } |
| 72 | |
| 73 | QSGPainterNode *QSGSoftwareContext::createPainterNode(QQuickPaintedItem *item) |
| 74 | { |
| 75 | return new QSGSoftwarePainterNode(item); |
| 76 | } |
| 77 | |
| 78 | QSGGlyphNode *QSGSoftwareContext::createGlyphNode(QSGRenderContext *rc, QSGTextNode::RenderType renderType, int renderTypeQuality) |
| 79 | { |
| 80 | Q_UNUSED(rc); |
| 81 | Q_UNUSED(renderType); |
| 82 | Q_UNUSED(renderTypeQuality); |
| 83 | return new QSGSoftwareGlyphNode(); |
| 84 | } |
| 85 | |
| 86 | QSGLayer *QSGSoftwareContext::createLayer(QSGRenderContext *renderContext) |
| 87 | { |
| 88 | return new QSGSoftwareLayer(renderContext); |
| 89 | } |
| 90 | |
| 91 | QSurfaceFormat QSGSoftwareContext::defaultSurfaceFormat() const |
| 92 | { |
| 93 | QSurfaceFormat format = QSurfaceFormat::defaultFormat(); |
| 94 | format.setRenderableType(QSurfaceFormat::DefaultRenderableType); |
| 95 | format.setMajorVersion(0); |
| 96 | format.setMinorVersion(0); |
| 97 | return format; |
| 98 | } |
| 99 | |
| 100 | void QSGSoftwareRenderContext::initializeIfNeeded() |
| 101 | { |
| 102 | if (m_initialized) |
| 103 | return; |
| 104 | m_initialized = true; |
| 105 | emit initialized(); |
| 106 | } |
| 107 | |
| 108 | void QSGSoftwareRenderContext::invalidate() |
| 109 | { |
| 110 | qDeleteAll(c: m_texturesToDelete); |
| 111 | m_texturesToDelete.clear(); |
| 112 | |
| 113 | qDeleteAll(c: m_textures); |
| 114 | m_textures.clear(); |
| 115 | |
| 116 | Q_ASSERT(m_fontEnginesToClean.isEmpty()); |
| 117 | |
| 118 | qDeleteAll(c: m_glyphCaches); |
| 119 | m_glyphCaches.clear(); |
| 120 | |
| 121 | m_sg->renderContextInvalidated(renderContext: this); |
| 122 | emit invalidated(); |
| 123 | } |
| 124 | |
| 125 | QSGTexture *QSGSoftwareRenderContext::createTexture(const QImage &image, uint flags) const |
| 126 | { |
| 127 | return new QSGSoftwarePixmapTexture(image, flags); |
| 128 | } |
| 129 | |
| 130 | QSGRenderer *QSGSoftwareRenderContext::createRenderer(QSGRendererInterface::RenderMode) |
| 131 | { |
| 132 | return new QSGSoftwareRenderer(this); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | void QSGSoftwareRenderContext::renderNextFrame(QSGRenderer *renderer) |
| 137 | { |
| 138 | renderer->renderScene(); |
| 139 | } |
| 140 | |
| 141 | int QSGSoftwareRenderContext::maxTextureSize() const |
| 142 | { |
| 143 | return 2048; |
| 144 | } |
| 145 | |
| 146 | QSGRendererInterface *QSGSoftwareContext::rendererInterface(QSGRenderContext *renderContext) |
| 147 | { |
| 148 | Q_UNUSED(renderContext); |
| 149 | return this; |
| 150 | } |
| 151 | |
| 152 | QSGRectangleNode *QSGSoftwareContext::createRectangleNode() |
| 153 | { |
| 154 | return new QSGSoftwareRectangleNode; |
| 155 | } |
| 156 | |
| 157 | QSGImageNode *QSGSoftwareContext::createImageNode() |
| 158 | { |
| 159 | return new QSGSoftwareImageNode; |
| 160 | } |
| 161 | |
| 162 | QSGNinePatchNode *QSGSoftwareContext::createNinePatchNode() |
| 163 | { |
| 164 | return new QSGSoftwareNinePatchNode; |
| 165 | } |
| 166 | |
| 167 | #if QT_CONFIG(quick_sprite) |
| 168 | QSGSpriteNode *QSGSoftwareContext::createSpriteNode() |
| 169 | { |
| 170 | return new QSGSoftwareSpriteNode; |
| 171 | } |
| 172 | #endif |
| 173 | |
| 174 | QSGRendererInterface::GraphicsApi QSGSoftwareContext::graphicsApi() const |
| 175 | { |
| 176 | return Software; |
| 177 | } |
| 178 | |
| 179 | QSGRendererInterface::ShaderType QSGSoftwareContext::shaderType() const |
| 180 | { |
| 181 | return UnknownShadingLanguage; |
| 182 | } |
| 183 | |
| 184 | QSGRendererInterface::ShaderCompilationTypes QSGSoftwareContext::shaderCompilationType() const |
| 185 | { |
| 186 | return {}; |
| 187 | } |
| 188 | |
| 189 | QSGRendererInterface::ShaderSourceTypes QSGSoftwareContext::shaderSourceType() const |
| 190 | { |
| 191 | return {}; |
| 192 | } |
| 193 | |
| 194 | void *QSGSoftwareContext::getResource(QQuickWindow *window, Resource resource) const |
| 195 | { |
| 196 | if (!window) |
| 197 | return nullptr; |
| 198 | |
| 199 | auto cd = QQuickWindowPrivate::get(c: window); |
| 200 | |
| 201 | if (resource == PainterResource) |
| 202 | return window->isSceneGraphInitialized() ? static_cast<QSGSoftwareRenderContext *>(cd->context)->m_activePainter : nullptr; |
| 203 | else if (resource == RedirectPaintDevice) |
| 204 | return cd->redirect.rt.sw.paintDevice; |
| 205 | |
| 206 | return nullptr; |
| 207 | } |
| 208 | |
| 209 | QT_END_NAMESPACE |
| 210 | |
| 211 | #include "moc_qsgsoftwarecontext_p.cpp" |
| 212 | |