diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2020-06-17 10:05:32 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2020-07-06 16:30:11 +0200 |
commit | 08203aef3ab102bfb91928f37846b2b19a4540ee (patch) | |
tree | b5b6be71629475e96c509e11e2b67644698588a3 /src/webengine/render_widget_host_view_qt_delegate_quick.cpp | |
parent | 45e3909e0fb628b6283fef8ea94861b7ca87093b (diff) |
Move scenegraph handling out of core
Replace Display{Producer,Consumer,FrameSink} with the new classes
Compositor and Compositor::Observer.
The Compositor subclasses are implemented by the OutputSurfaces,
replacing DisplayProducer in this role. Unlike DisplayProducer, the
new classes do not use QtQuick scenegraph types, but rather give
access to the software QImage or OpenGL texture directly.
The connection to the "other half" is simplified by replacing
DisplayConsumer with Compositor::Observer, which is no longer
implemented by RenderWidgetHostViewQt, but directly by its delegates
in the quick and widgets libraries. RenderWidgetHostViewQt now only
provides the delegate with a Compositor::Id which is used to connect
the corresponding Compositor and Observer.
The delegates are responsible for generating QtQuick scenegraph nodes
from the information provided by the Compositor subclasses.
Behavior with software and old OpenGL scenegraph backends is
unchanged: both continue to work. As for the RHI scenegraph backend,
the code here is correct but nonetheless not working: changes are
needed in qtbase to make RHI use the global share context for its
OpenGL context.
Fixes: QTBUG-78682
Change-Id: I837da8860a18ec366ed33f6ecc44c147245e1101
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/webengine/render_widget_host_view_qt_delegate_quick.cpp')
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quick.cpp | 83 |
1 files changed, 59 insertions, 24 deletions
diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp index c0d4dd4a5..9ed660f2e 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -85,10 +85,12 @@ RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(RenderW } #endif + bind(client->compositorId()); } RenderWidgetHostViewQtDelegateQuick::~RenderWidgetHostViewQtDelegateQuick() { + unbind(); QQuickWebEngineViewPrivate::bindViewAndWidget(nullptr, this); } @@ -167,30 +169,10 @@ QWindow* RenderWidgetHostViewQtDelegateQuick::window() const return QQuickItem::window(); } -QSGTexture *RenderWidgetHostViewQtDelegateQuick::createTextureFromImage(const QImage &image) +void RenderWidgetHostViewQtDelegateQuick::readyToSwap() { - return QQuickItem::window()->createTextureFromImage(image, QQuickWindow::TextureCanUseAtlas); -} - -QSGLayer *RenderWidgetHostViewQtDelegateQuick::createLayer() -{ - QSGRenderContext *renderContext = QQuickWindowPrivate::get(QQuickItem::window())->context; - return renderContext->sceneGraphContext()->createLayer(renderContext); -} - -QSGImageNode *RenderWidgetHostViewQtDelegateQuick::createImageNode() -{ - return QQuickItem::window()->createImageNode(); -} - -QSGRectangleNode *RenderWidgetHostViewQtDelegateQuick::createRectangleNode() -{ - return QQuickItem::window()->createRectangleNode(); -} - -void RenderWidgetHostViewQtDelegateQuick::update() -{ - QQuickItem::update(); + // Call update() on UI thread. + QMetaObject::invokeMethod(this, &QQuickItem::update, Qt::QueuedConnection); } void RenderWidgetHostViewQtDelegateQuick::updateCursor(const QCursor &cursor) @@ -345,6 +327,8 @@ void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const It disconnect(c); m_windowConnections.clear(); if (value.window) { + m_windowConnections.append(connect(value.window, SIGNAL(beforeRendering()), + SLOT(onBeforeRendering()), Qt::DirectConnection)); m_windowConnections.append(connect(value.window, SIGNAL(xChanged(int)), SLOT(onWindowPosChanged()))); m_windowConnections.append(connect(value.window, SIGNAL(yChanged(int)), SLOT(onWindowPosChanged()))); if (!m_isPopup) @@ -359,7 +343,58 @@ void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const It QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { - return m_client->updatePaintNode(oldNode); + auto comp = compositor(); + if (!comp) + return nullptr; + + QQuickWindow *win = QQuickItem::window(); + + // Delete old node before swapFrame to decrement refcount of + // QImage in software mode. + delete oldNode; + QSGImageNode *node = win->createImageNode(); + node->setOwnsTexture(true); + + comp->swapFrame(); + + if (comp->type() == Compositor::Type::Software) { + QImage image = comp->image(); + float pixPerDip = comp->devicePixelRatio(); + QSizeF sizeInDips = QSizeF(image.size()) / pixPerDip; + node->setRect(QRectF(QPointF(0, 0), sizeInDips)); + node->setTexture(win->createTextureFromImage(image)); + } else if (comp->type() == Compositor::Type::OpenGL) { + QSize texSize = comp->textureSize(); + float pixPerDip = comp->devicePixelRatio(); + QSizeF sizeInDips = QSizeF(texSize) / pixPerDip; + node->setRect(QRectF(QPointF(0, 0), sizeInDips)); + QQuickWindow::CreateTextureOptions texOpts; + if (comp->hasAlphaChannel()) + texOpts.setFlag(QQuickWindow::TextureHasAlphaChannel); + int texId = comp->textureId(); + node->setTexture(win->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture, + texId, 0, texSize, texOpts)); + node->setTextureCoordinatesTransform(QSGImageNode::MirrorVertically); + } else { + Q_UNREACHABLE(); + } + +#if QT_CONFIG(webengine_testsupport) + if (m_view) + QMetaObject::invokeMethod( + m_view, [view = m_view]() { view->d_ptr->didCompositorFrameSwap(); }, + Qt::QueuedConnection); +#endif + + return node; +} + +void RenderWidgetHostViewQtDelegateQuick::onBeforeRendering() +{ + auto comp = compositor(); + if (!comp || comp->type() != Compositor::Type::OpenGL) + return; + comp->waitForTexture(); } void RenderWidgetHostViewQtDelegateQuick::onWindowPosChanged() |