diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-06-10 09:32:24 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2016-06-10 09:32:24 +0000 |
commit | c9d8b85ec9efd90f9bd8071a58dc04f54c2c365d (patch) | |
tree | 34179a1dfbb17de5affde7ac6305b4a9d295fc82 /src/quick/items/context2d | |
parent | 4de6c1bc6cc1894f9f60cfef6d403a933d2c18cd (diff) | |
parent | 272b9a8ad6d1a1c3ea3e4aa64fb9f94d163a562f (diff) |
Merge "Merge remote-tracking branch 'origin/wip/scenegraphng' into dev" into refs/staging/dev
Diffstat (limited to 'src/quick/items/context2d')
-rw-r--r-- | src/quick/items/context2d/qquickcanvasitem.cpp | 75 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2d.cpp | 45 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp | 6 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtexture.cpp | 17 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtexture_p.h | 18 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtile.cpp | 13 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtile_p.h | 9 |
7 files changed, 116 insertions, 67 deletions
diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp index 4abcc722d1..7ffb715346 100644 --- a/src/quick/items/context2d/qquickcanvasitem.cpp +++ b/src/quick/items/context2d/qquickcanvasitem.cpp @@ -43,7 +43,7 @@ #include <private/qquickcanvascontext_p.h> #include <private/qquickcontext2d_p.h> #include <private/qquickcontext2dtexture_p.h> -#include <qsgsimpletexturenode.h> +#include <private/qsgadaptationlayer_p.h> #include <QtQuick/private/qquickpixmapcache_p.h> #include <QtGui/QGuiApplication> @@ -59,24 +59,11 @@ QT_BEGIN_NAMESPACE -class QQuickCanvasNode : public QSGSimpleTextureNode -{ -public: - QQuickCanvasNode() { - qsgnode_set_description(this, QStringLiteral("canvasnode")); - setOwnsTexture(false); - } - - ~QQuickCanvasNode() { - delete texture(); - } -}; - class QQuickCanvasTextureProvider : public QSGTextureProvider { public: - QQuickCanvasNode *node; - QSGTexture *texture() const Q_DECL_OVERRIDE { return node ? node->texture() : 0; } + QSGTexture *tex; + QSGTexture *texture() const Q_DECL_OVERRIDE { return tex; } void fireTextureChanged() { emit textureChanged(); } }; @@ -187,7 +174,8 @@ public: QUrl baseUrl; QMap<int, QV4::PersistentValue> animationCallbacks; mutable QQuickCanvasTextureProvider *textureProvider; - QQuickCanvasNode *node; + QSGImageNode *node; + QSGTexture *nodeTexture; }; QQuickCanvasItemPrivate::QQuickCanvasItemPrivate() @@ -203,6 +191,7 @@ QQuickCanvasItemPrivate::QQuickCanvasItemPrivate() , renderStrategy(QQuickCanvasItem::Immediate) , textureProvider(0) , node(0) + , nodeTexture(0) { implicitAntialiasing = true; } @@ -256,17 +245,18 @@ QQuickCanvasItemPrivate::~QQuickCanvasItemPrivate() The Canvas item supports two render targets: \c Canvas.Image and \c Canvas.FramebufferObject. - The \c Canvas.Image render target is a \a QImage object. This render - target supports background thread rendering, allowing complex or long - running painting to be executed without blocking the UI. + The \c Canvas.Image render target is a \a QImage object. This render target + supports background thread rendering, allowing complex or long running + painting to be executed without blocking the UI. This is the only render + target that is supported by all Qt Quick backends. The Canvas.FramebufferObject render target utilizes OpenGL hardware acceleration rather than rendering into system memory, which in many cases - results in faster rendering. Canvas.FramebufferObject relies on the - OpenGL extensions \c GL_EXT_framebuffer_multisample and - \c GL_EXT_framebuffer_blit for antialiasing. It will also use more - graphics memory when rendering strategy is anything other than - Canvas.Cooperative. + results in faster rendering. Canvas.FramebufferObject relies on the OpenGL + extensions \c GL_EXT_framebuffer_multisample and \c GL_EXT_framebuffer_blit + for antialiasing. It will also use more graphics memory when rendering + strategy is anything other than Canvas.Cooperative. Framebuffer objects may + not be available with Qt Quick backends other than OpenGL. The default render target is Canvas.Image and the default renderStrategy is Canvas.Immediate. @@ -301,7 +291,14 @@ QQuickCanvasItemPrivate::~QQuickCanvasItemPrivate() and can be used directly in \l {ShaderEffect}{ShaderEffects} and other classes that consume texture providers. - \sa Context2D + \note In general large canvases, frequent updates, and animation should be + avoided with the Canvas.Image render target. This is because with + accelerated graphics APIs each update will lead to a texture upload. Also, + if possible, prefer QQuickPaintedItem and implement drawing in C++ via + QPainter instead of the more expensive and likely less performing + JavaScript and Context2D approach. + + \sa Context2D QQuickPaintedItem */ QQuickCanvasItem::QQuickCanvasItem(QQuickItem *parent) @@ -735,16 +732,16 @@ QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData if (!d->context || d->canvasWindow.size().isEmpty()) { if (d->textureProvider) { - d->textureProvider->node = 0; + d->textureProvider->tex = 0; d->textureProvider->fireTextureChanged(); } delete oldNode; return 0; } - QQuickCanvasNode *node = static_cast<QQuickCanvasNode*>(oldNode); + QSGImageNode *node = static_cast<QSGImageNode *>(oldNode); if (!node) { - node = new QQuickCanvasNode(); + node = QQuickWindowPrivate::get(window())->context->sceneGraphContext()->createImageNode(); d->node = node; } @@ -761,22 +758,27 @@ QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData QQuickContext2D *ctx = qobject_cast<QQuickContext2D *>(d->context); QQuickContext2DTexture *factory = ctx->texture(); - QSGTexture *texture = factory->textureForNextFrame(node->texture(), window()); + QSGTexture *texture = factory->textureForNextFrame(d->nodeTexture, window()); if (!texture) { delete node; d->node = 0; + delete d->nodeTexture; + d->nodeTexture = 0; if (d->textureProvider) { - d->textureProvider->node = 0; + d->textureProvider->tex = 0; d->textureProvider->fireTextureChanged(); } return 0; } + d->nodeTexture = texture; node->setTexture(texture); - node->setRect(QRectF(QPoint(0, 0), d->canvasWindow.size())); + node->setTargetRect(QRectF(QPoint(0, 0), d->canvasWindow.size())); + node->setInnerTargetRect(QRectF(QPoint(0, 0), d->canvasWindow.size())); + node->update(); if (d->textureProvider) { - d->textureProvider->node = node; + d->textureProvider->tex = d->nodeTexture; d->textureProvider->fireTextureChanged(); } return node; @@ -796,14 +798,17 @@ QSGTextureProvider *QQuickCanvasItem::textureProvider() const return QQuickItem::textureProvider(); Q_D(const QQuickCanvasItem); +#ifndef QT_NO_OPENGL QQuickWindow *w = window(); - if (!w || !w->openglContext() || QThread::currentThread() != w->openglContext()->thread()) { + if (!w || !w->isSceneGraphInitialized() + || QThread::currentThread() != QQuickWindowPrivate::get(w)->context->thread()) { qWarning("QQuickCanvasItem::textureProvider: can only be queried on the rendering thread of an exposed window"); return 0; } +#endif if (!d->textureProvider) d->textureProvider = new QQuickCanvasTextureProvider; - d->textureProvider->node = d->node; + d->textureProvider->tex = d->nodeTexture; return d->textureProvider; } diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index 10b02b1f32..b924701f2b 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -43,6 +43,7 @@ #include <private/qquickcontext2dtexture_p.h> #include <private/qquickitem_p.h> #include <QtQuick/private/qquickshadereffectsource_p.h> +#include <qsgrendererinterface.h> #include <QtQuick/private/qsgcontext_p.h> #include <private/qquicksvgparser_p.h> @@ -74,6 +75,10 @@ #include <private/qguiapplication_p.h> #include <qpa/qplatformintegration.h> +#ifndef QT_NO_OPENGL +# include <private/qsgdefaultrendercontext_p.h> +#endif + #include <cmath> #if defined(Q_OS_QNX) || defined(Q_OS_ANDROID) #include <ctype.h> @@ -3980,10 +3985,12 @@ public: ~QQuickContext2DThreadCleanup() { +#ifndef QT_NO_OPENGL context->makeCurrent(surface); delete texture; context->doneCurrent(); delete context; +#endif surface->deleteLater(); } @@ -4019,6 +4026,7 @@ QQuickContext2D::~QQuickContext2D() delete m_buffer; if (m_renderTarget == QQuickCanvasItem::FramebufferObject) { +#ifndef QT_NO_OPENGL if (m_renderStrategy == QQuickCanvasItem::Immediate && m_glContext) { Q_ASSERT(QThread::currentThread() == m_glContext->thread()); m_glContext->makeCurrent(m_surface.data()); @@ -4039,6 +4047,7 @@ QQuickContext2D::~QQuickContext2D() m_texture->deleteLater(); } } +#endif } else { // Image based does not have GL resources, but must still be deleted // on its designated thread after it has completed whatever it might @@ -4064,8 +4073,6 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args m_canvas = canvasItem; m_renderTarget = canvasItem->renderTarget(); - - QQuickWindow *window = canvasItem->window(); m_renderStrategy = canvasItem->renderStrategy(); #ifdef Q_OS_WIN @@ -4084,12 +4091,24 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args m_renderTarget = QQuickCanvasItem::Image; } + // Disable Framebuffer Object based rendering when not running with OpenGL + if (m_renderTarget == QQuickCanvasItem::FramebufferObject) { + QSGRendererInterface *rif = canvasItem->window()->rendererInterface(); + if (rif && rif->graphicsApi() != QSGRendererInterface::OpenGL) + m_renderTarget = QQuickCanvasItem::Image; + } + switch (m_renderTarget) { case QQuickCanvasItem::Image: m_texture = new QQuickContext2DImageTexture; break; case QQuickCanvasItem::FramebufferObject: +#ifndef QT_NO_OPENGL m_texture = new QQuickContext2DFBOTexture; +#else + // It shouldn't be possible to use a FramebufferObject without OpenGL + m_texture = nullptr; +#endif break; } @@ -4103,18 +4122,27 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args m_thread = QThread::currentThread(); QThread *renderThread = m_thread; - QThread *sceneGraphThread = window->openglContext() ? window->openglContext()->thread() : 0; +#ifndef QT_NO_OPENGL + QQuickWindow *window = canvasItem->window(); + QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window); + QThread *sceneGraphThread = wd->context->thread(); if (m_renderStrategy == QQuickCanvasItem::Threaded) renderThread = QQuickContext2DRenderThread::instance(qmlEngine(canvasItem)); else if (m_renderStrategy == QQuickCanvasItem::Cooperative) renderThread = sceneGraphThread; +#else + if (m_renderStrategy == QQuickCanvasItem::Threaded) + renderThread = QQuickContext2DRenderThread::instance(qmlEngine(canvasItem)); +#endif + if (renderThread && renderThread != QThread::currentThread()) m_texture->moveToThread(renderThread); - +#ifndef QT_NO_OPENGL if (m_renderTarget == QQuickCanvasItem::FramebufferObject && renderThread != sceneGraphThread) { - QOpenGLContext *cc = QQuickWindowPrivate::get(window)->context->openglContext(); + auto openglRenderContext = static_cast<const QSGDefaultRenderContext *>(QQuickWindowPrivate::get(window)->context); + QOpenGLContext *cc = openglRenderContext->openglContext(); m_surface.reset(new QOffscreenSurface); m_surface->setFormat(window->format()); m_surface->create(); @@ -4125,7 +4153,7 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args m_glContext->moveToThread(renderThread); m_texture->initializeOpenGL(m_glContext, m_surface.data()); } - +#endif connect(m_texture, SIGNAL(textureChanged()), SIGNAL(textureChanged())); reset(); @@ -4172,6 +4200,7 @@ QImage QQuickContext2D::toImage(const QRectF& bounds) flush(); m_texture->grabImage(bounds); } else { +#ifndef QT_NO_OPENGL QQuickWindow *window = m_canvas->window(); QOpenGLContext *ctx = window ? window->openglContext() : 0; if (ctx && ctx->isValid()) { @@ -4187,6 +4216,10 @@ QImage QQuickContext2D::toImage(const QRectF& bounds) qWarning() << "Cannot read pixels from canvas before opengl context is valid"; return QImage(); } +#else + flush(); + m_texture->grabImage(bounds); +#endif } } else if (m_renderStrategy == QQuickCanvasItem::Cooperative) { qWarning() << "Pixel readback is not supported in Cooperative mode, please try Threaded or Immediate mode"; diff --git a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp index 58b374e696..8d659040b3 100644 --- a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp +++ b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp @@ -42,9 +42,11 @@ #include <qqml.h> #include <QtCore/QMutex> #include <QtQuick/qsgtexture.h> -#include <QtGui/QOpenGLContext> #include <QtGui/QPaintEngine> -#include <QtGui/private/qopenglpaintengine_p.h> +#ifndef QT_NO_OPENGL +# include <QtGui/QOpenGLContext> +# include <QtGui/private/qopenglpaintengine_p.h> +#endif #define HAS_SHADOW(offsetX, offsetY, blur, color) (color.isValid() && color.alpha() && (blur || offsetX || offsetY)) diff --git a/src/quick/items/context2d/qquickcontext2dtexture.cpp b/src/quick/items/context2d/qquickcontext2dtexture.cpp index f3513f447a..ddecf7c3d4 100644 --- a/src/quick/items/context2d/qquickcontext2dtexture.cpp +++ b/src/quick/items/context2d/qquickcontext2dtexture.cpp @@ -44,14 +44,16 @@ #include <QtQuick/private/qsgtexture_p.h> #include "qquickcontext2dcommandbuffer_p.h" #include <QOpenGLPaintDevice> - +#ifndef QT_NO_OPENGL #include <QOpenGLFramebufferObject> #include <QOpenGLFramebufferObjectFormat> +#include <QOpenGLFunctions> +#endif #include <QtCore/QThread> #include <QtGui/QGuiApplication> QT_BEGIN_NAMESPACE - +#ifndef QT_NO_OPENGL #define QT_MINIMUM_FBO_SIZE 64 static inline int qt_next_power_of_two(int v) @@ -85,10 +87,12 @@ struct GLAcquireContext { } QOpenGLContext *ctx; }; - +#endif QQuickContext2DTexture::QQuickContext2DTexture() : m_context(0) +#ifndef QT_NO_OPENGL , m_gl(0) +#endif , m_surface(0) , m_item(0) , m_canvasWindowChanged(false) @@ -250,9 +254,9 @@ void QQuickContext2DTexture::paint(QQuickContext2DCommandBuffer *ccb) return; } QQuickContext2D::mutex.unlock(); - +#ifndef QT_NO_OPENGL GLAcquireContext currentContext(m_gl, m_surface); - +#endif if (!m_tiledCanvas) { paintWithoutTiles(ccb); delete ccb; @@ -379,7 +383,7 @@ bool QQuickContext2DTexture::event(QEvent *e) } return QObject::event(e); } - +#ifndef QT_NO_OPENGL static inline QSize npotAdjustedSize(const QSize &size) { static bool checked = false; @@ -646,6 +650,7 @@ void QQuickContext2DFBOTexture::endPainting() m_fbo->bindDefault(); } +#endif QQuickContext2DImageTexture::QQuickContext2DImageTexture() : QQuickContext2DTexture() diff --git a/src/quick/items/context2d/qquickcontext2dtexture_p.h b/src/quick/items/context2d/qquickcontext2dtexture_p.h index edc7283283..ed38382892 100644 --- a/src/quick/items/context2d/qquickcontext2dtexture_p.h +++ b/src/quick/items/context2d/qquickcontext2dtexture_p.h @@ -54,10 +54,10 @@ #include <QtQuick/qsgtexture.h> #include "qquickcanvasitem_p.h" #include "qquickcontext2d_p.h" - -#include <QOpenGLContext> -#include <QOpenGLFramebufferObject> - +#ifndef QT_NO_OPENGL +# include <QOpenGLContext> +# include <QOpenGLFramebufferObject> +#endif #include <QtCore/QMutex> #include <QtCore/QWaitCondition> #include <QtCore/QThread> @@ -121,11 +121,12 @@ public: // Called during sync() on the scene graph thread while GUI is blocked. virtual QSGTexture *textureForNextFrame(QSGTexture *lastFrame, QQuickWindow *window) = 0; bool event(QEvent *e); - +#ifndef QT_NO_OPENGL void initializeOpenGL(QOpenGLContext *gl, QOffscreenSurface *s) { m_gl = gl; m_surface = s; } +#endif Q_SIGNALS: void textureChanged(); @@ -152,8 +153,9 @@ protected: QList<QQuickContext2DTile*> m_tiles; QQuickContext2D *m_context; - +#ifndef QT_NO_OPENGL QOpenGLContext *m_gl; +#endif QSurface *m_surface; QQuickContext2D::State m_state; @@ -174,7 +176,7 @@ protected: uint m_painting : 1; uint m_onCustomThread : 1; // Not GUI and not SGRender }; - +#ifndef QT_NO_OPENGL class QQuickContext2DFBOTexture : public QQuickContext2DTexture { Q_OBJECT @@ -209,7 +211,7 @@ private: GLuint m_displayTextures[2]; int m_displayTexture; }; - +#endif class QSGPlainTexture; class QQuickContext2DImageTexture : public QQuickContext2DTexture { diff --git a/src/quick/items/context2d/qquickcontext2dtile.cpp b/src/quick/items/context2d/qquickcontext2dtile.cpp index a1503762de..95b6c9d961 100644 --- a/src/quick/items/context2d/qquickcontext2dtile.cpp +++ b/src/quick/items/context2d/qquickcontext2dtile.cpp @@ -38,10 +38,11 @@ ****************************************************************************/ #include "qquickcontext2dtile_p.h" - -#include <QOpenGLFramebufferObject> -#include <QOpenGLFramebufferObjectFormat> -#include <QOpenGLPaintDevice> +#ifndef QT_NO_OPENGL +# include <QOpenGLFramebufferObject> +# include <QOpenGLFramebufferObjectFormat> +# include <QOpenGLPaintDevice> +#endif QT_BEGIN_NAMESPACE @@ -96,7 +97,7 @@ QPainter* QQuickContext2DTile::createPainter(bool smooth, bool antialiasing) return 0; } - +#ifndef QT_NO_OPENGL QQuickContext2DFBOTile::QQuickContext2DFBOTile() : QQuickContext2DTile() , m_fbo(0) @@ -146,7 +147,7 @@ void QQuickContext2DFBOTile::setRect(const QRect& r) m_fbo = new QOpenGLFramebufferObject(r.size(), format); } } - +#endif QQuickContext2DImageTile::QQuickContext2DImageTile() : QQuickContext2DTile() diff --git a/src/quick/items/context2d/qquickcontext2dtile_p.h b/src/quick/items/context2d/qquickcontext2dtile_p.h index d9be2023c4..a87202daae 100644 --- a/src/quick/items/context2d/qquickcontext2dtile_p.h +++ b/src/quick/items/context2d/qquickcontext2dtile_p.h @@ -52,8 +52,9 @@ // #include "qquickcontext2d_p.h" -#include <QOpenGLFramebufferObject> - +#ifndef QT_NO_OPENGL +# include <QOpenGLFramebufferObject> +#endif QT_BEGIN_NAMESPACE class QQuickContext2DTexture; @@ -82,7 +83,7 @@ protected: QPainter m_painter; }; - +#ifndef QT_NO_OPENGL class QQuickContext2DFBOTile : public QQuickContext2DTile { public: @@ -99,7 +100,7 @@ private: QOpenGLFramebufferObject *m_fbo; }; - +#endif class QQuickContext2DImageTile : public QQuickContext2DTile { public: |