| 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 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | QSGSoftwareRenderContext::QSGSoftwareRenderContext(QSGContext *ctx) |
| 28 | : QSGRenderContext(ctx) |
| 29 | , m_initialized(false) |
| 30 | , m_activePainter(nullptr) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | QSGSoftwareContext::QSGSoftwareContext(QObject *parent) |
| 35 | : QSGContext(parent) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | QSGInternalRectangleNode *QSGSoftwareContext::createInternalRectangleNode() |
| 40 | { |
| 41 | return new QSGSoftwareInternalRectangleNode(); |
| 42 | } |
| 43 | |
| 44 | QSGInternalImageNode *QSGSoftwareContext::createInternalImageNode(QSGRenderContext *renderContext) |
| 45 | { |
| 46 | Q_UNUSED(renderContext); |
| 47 | return new QSGSoftwareInternalImageNode(); |
| 48 | } |
| 49 | |
| 50 | QSGPainterNode *QSGSoftwareContext::createPainterNode(QQuickPaintedItem *item) |
| 51 | { |
| 52 | return new QSGSoftwarePainterNode(item); |
| 53 | } |
| 54 | |
| 55 | QSGGlyphNode *QSGSoftwareContext::createGlyphNode(QSGRenderContext *rc, QSGTextNode::RenderType renderType, int renderTypeQuality) |
| 56 | { |
| 57 | Q_UNUSED(rc); |
| 58 | Q_UNUSED(renderType); |
| 59 | Q_UNUSED(renderTypeQuality); |
| 60 | return new QSGSoftwareGlyphNode(); |
| 61 | } |
| 62 | |
| 63 | QSGLayer *QSGSoftwareContext::createLayer(QSGRenderContext *renderContext) |
| 64 | { |
| 65 | return new QSGSoftwareLayer(renderContext); |
| 66 | } |
| 67 | |
| 68 | QSurfaceFormat QSGSoftwareContext::defaultSurfaceFormat() const |
| 69 | { |
| 70 | QSurfaceFormat format = QSurfaceFormat::defaultFormat(); |
| 71 | format.setRenderableType(QSurfaceFormat::DefaultRenderableType); |
| 72 | format.setMajorVersion(0); |
| 73 | format.setMinorVersion(0); |
| 74 | if (QQuickWindow::hasDefaultAlphaBuffer()) |
| 75 | format.setAlphaBufferSize(8); |
| 76 | return format; |
| 77 | } |
| 78 | |
| 79 | void QSGSoftwareRenderContext::initializeIfNeeded() |
| 80 | { |
| 81 | if (m_initialized) |
| 82 | return; |
| 83 | m_initialized = true; |
| 84 | emit initialized(); |
| 85 | } |
| 86 | |
| 87 | void QSGSoftwareRenderContext::invalidate() |
| 88 | { |
| 89 | qDeleteAll(c: m_texturesToDelete); |
| 90 | m_texturesToDelete.clear(); |
| 91 | |
| 92 | qDeleteAll(c: m_textures); |
| 93 | m_textures.clear(); |
| 94 | |
| 95 | Q_ASSERT(m_fontEnginesToClean.isEmpty()); |
| 96 | |
| 97 | qDeleteAll(c: m_glyphCaches); |
| 98 | m_glyphCaches.clear(); |
| 99 | |
| 100 | qDeleteAll(c: m_staleGlyphCaches); |
| 101 | m_staleGlyphCaches.clear(); |
| 102 | |
| 103 | m_sg->renderContextInvalidated(renderContext: this); |
| 104 | emit invalidated(); |
| 105 | } |
| 106 | |
| 107 | QSGTexture *QSGSoftwareRenderContext::createTexture(const QImage &image, uint flags) const |
| 108 | { |
| 109 | return new QSGSoftwarePixmapTexture(image, flags); |
| 110 | } |
| 111 | |
| 112 | QSGRenderer *QSGSoftwareRenderContext::createRenderer(QSGRendererInterface::RenderMode) |
| 113 | { |
| 114 | return new QSGSoftwareRenderer(this); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | void QSGSoftwareRenderContext::renderNextFrame(QSGRenderer *renderer) |
| 119 | { |
| 120 | renderer->renderScene(); |
| 121 | } |
| 122 | |
| 123 | int QSGSoftwareRenderContext::maxTextureSize() const |
| 124 | { |
| 125 | return 2048; |
| 126 | } |
| 127 | |
| 128 | QSGRendererInterface *QSGSoftwareContext::rendererInterface(QSGRenderContext *renderContext) |
| 129 | { |
| 130 | Q_UNUSED(renderContext); |
| 131 | return this; |
| 132 | } |
| 133 | |
| 134 | QSGRectangleNode *QSGSoftwareContext::createRectangleNode() |
| 135 | { |
| 136 | return new QSGSoftwareRectangleNode; |
| 137 | } |
| 138 | |
| 139 | QSGImageNode *QSGSoftwareContext::createImageNode() |
| 140 | { |
| 141 | return new QSGSoftwareImageNode; |
| 142 | } |
| 143 | |
| 144 | QSGNinePatchNode *QSGSoftwareContext::createNinePatchNode() |
| 145 | { |
| 146 | return new QSGSoftwareNinePatchNode; |
| 147 | } |
| 148 | |
| 149 | #if QT_CONFIG(quick_sprite) |
| 150 | QSGSpriteNode *QSGSoftwareContext::createSpriteNode() |
| 151 | { |
| 152 | return new QSGSoftwareSpriteNode; |
| 153 | } |
| 154 | #endif |
| 155 | |
| 156 | QSGRendererInterface::GraphicsApi QSGSoftwareContext::graphicsApi() const |
| 157 | { |
| 158 | return Software; |
| 159 | } |
| 160 | |
| 161 | QSGRendererInterface::ShaderType QSGSoftwareContext::shaderType() const |
| 162 | { |
| 163 | return UnknownShadingLanguage; |
| 164 | } |
| 165 | |
| 166 | QSGRendererInterface::ShaderCompilationTypes QSGSoftwareContext::shaderCompilationType() const |
| 167 | { |
| 168 | return {}; |
| 169 | } |
| 170 | |
| 171 | QSGRendererInterface::ShaderSourceTypes QSGSoftwareContext::shaderSourceType() const |
| 172 | { |
| 173 | return {}; |
| 174 | } |
| 175 | |
| 176 | void *QSGSoftwareContext::getResource(QQuickWindow *window, Resource resource) const |
| 177 | { |
| 178 | if (!window) |
| 179 | return nullptr; |
| 180 | |
| 181 | auto cd = QQuickWindowPrivate::get(c: window); |
| 182 | |
| 183 | if (resource == PainterResource) |
| 184 | return window->isSceneGraphInitialized() ? static_cast<QSGSoftwareRenderContext *>(cd->context)->m_activePainter : nullptr; |
| 185 | else if (resource == RedirectPaintDevice) |
| 186 | return cd->redirect.rt.sw.paintDevice; |
| 187 | |
| 188 | return nullptr; |
| 189 | } |
| 190 | |
| 191 | QT_END_NAMESPACE |
| 192 | |
| 193 | #include "moc_qsgsoftwarecontext_p.cpp" |
| 194 |
