diff --git a/examples/examples.pro b/examples/examples.pro index 7940e289de2f5fe3b2892c4caadb75f43a1fff76..3114e68871eba2171de9070f8c15cefe3485d103 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,7 +1,8 @@ TEMPLATE=subdirs SUBDIRS += webengine/quicknanobrowser -qtHaveModule(widgets) { + +qtHaveModule(widgets):equals(QT_MAJOR_VERSION, 5):greaterThan(QT_MINOR_VERSION, 2) { SUBDIRS += \ webenginewidgets/browser \ webenginewidgets/fancybrowser diff --git a/examples/webenginewidgets/browser/main.cpp b/examples/webenginewidgets/browser/main.cpp index 9baf01f42296724d636b55ecb708b8d55e8647f7..d49a920b58f9933ce81c0a0808d6b6cf74ee658e 100644 --- a/examples/webenginewidgets/browser/main.cpp +++ b/examples/webenginewidgets/browser/main.cpp @@ -41,12 +41,17 @@ #include "browserapplication.h" +#include <qtwebenginewidgetsglobal.h> + int main(int argc, char **argv) { Q_INIT_RESOURCE(data); BrowserApplication application(argc, argv); if (!application.isTheOnlyBrowser()) return 0; + + QWebEngineWidgets::initialize(); + application.newMainWindow(); return application.exec(); } diff --git a/examples/webenginewidgets/fancybrowser/main.cpp b/examples/webenginewidgets/fancybrowser/main.cpp index 451f247f3f715c4a04a215ed1a38f114583d15b1..c18b98d9dd6b00eb97bc70f7d8927d7324f6924b 100644 --- a/examples/webenginewidgets/fancybrowser/main.cpp +++ b/examples/webenginewidgets/fancybrowser/main.cpp @@ -40,10 +40,13 @@ #include <QtWidgets> #include "mainwindow.h" +#include <qtwebenginewidgetsglobal.h> int main(int argc, char * argv[]) { QApplication app(argc, argv); + QWebEngineWidgets::initialize(); + QUrl url; if (argc > 1) url = QUrl::fromUserInput(argv[1]); diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 628aa6ed2a1369e055ddd1b1c17578a94ea15d0c..86ff11efb6d3a415fdf3ba5621045f0de26ab2fe 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -58,6 +58,7 @@ #include "web_contents_view_qt.h" #include <QGuiApplication> +#include <QtGui/private/qopenglcontext_p.h> #include <QtQuick/private/qsgcontext_p.h> #include <qpa/qplatformnativeinterface.h> @@ -248,9 +249,13 @@ private: void ShareGroupQtQuick::AboutToAddFirstContext() { // This currently has to be setup by ::main in all applications using QQuickWebEngineView with delegated rendering. +#if (QT_VERSION < QT_VERSION_CHECK(5, 3, 0)) QOpenGLContext *shareContext = QSGContext::sharedOpenGLContext(); +#else + QOpenGLContext *shareContext = QOpenGLContextPrivate::globalShareContext(); +#endif if (!shareContext) { - qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QWebEngine::initialize() in your main() function."); + qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QWebEngine::initialize() or QWebEngineWidgets::initialize() in your main() function."); } m_shareContextQtQuick = make_scoped_refptr(new QtShareGLContext(shareContext)); } diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index 2cfcd4afe78482abd51b7f67ac333484ac9b4614..1f7084d18ed9cfaa8c85f421b9e5578e4f15f1f0 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -70,7 +70,6 @@ #include <QSGSimpleTextureNode> #include <QSGTexture> #include <QtQuick/private/qquickclipnode_p.h> -#include <QtQuick/private/qquickwindow_p.h> #include <QtQuick/private/qsgadaptationlayer_p.h> #include <QtQuick/private/qsgcontext_p.h> #include <QtQuick/private/qsgrenderer_p.h> @@ -286,8 +285,8 @@ void MailboxTexture::fetchTexture(gpu::gles2::MailboxManager *mailboxManager) m_textureId = service_id(tex); } -DelegatedFrameNode::DelegatedFrameNode(QQuickWindow *window) - : m_window(window) +DelegatedFrameNode::DelegatedFrameNode(QSGRenderContext *sgRenderContext) + : m_sgRenderContext(sgRenderContext) , m_numPendingSyncPoints(0) { setFlag(UsePreprocess); @@ -370,10 +369,8 @@ void DelegatedFrameNode::commit(DelegatedFrameNodeData* data, cc::ReturnedResour QSGNode *renderPassParent = 0; if (pass != rootRenderPass) { QSharedPointer<RenderPassTexture> rpTexture = findRenderPassTexture(pass->id, oldRenderPassTextures); - if (!rpTexture) { - QSGRenderContext *sgrc = QQuickWindowPrivate::get(m_window)->context; - rpTexture = QSharedPointer<RenderPassTexture>(new RenderPassTexture(pass->id, sgrc)); - } + if (!rpTexture) + rpTexture = QSharedPointer<RenderPassTexture>(new RenderPassTexture(pass->id, m_sgRenderContext)); m_renderPassTextures.append(rpTexture); rpTexture->setDevicePixelRatio(m_data->frameDevicePixelRatio); rpTexture->setRect(toQt(pass->output_rect)); @@ -404,8 +401,7 @@ void DelegatedFrameNode::commit(DelegatedFrameNodeData* data, cc::ReturnedResour switch (quad->material) { case cc::DrawQuad::CHECKERBOARD: { const cc::CheckerboardDrawQuad *cbquad = cc::CheckerboardDrawQuad::MaterialCast(quad); - QSGRenderContext *sgrc = QQuickWindowPrivate::get(m_window)->context; - QSGRectangleNode *rectangleNode = sgrc->sceneGraphContext()->createRectangleNode(); + QSGRectangleNode *rectangleNode = m_sgRenderContext->sceneGraphContext()->createRectangleNode(); rectangleNode->setRect(toQt(quad->rect)); rectangleNode->setColor(toQt(cbquad->color)); @@ -450,8 +446,7 @@ void DelegatedFrameNode::commit(DelegatedFrameNodeData* data, cc::ReturnedResour break; } case cc::DrawQuad::SOLID_COLOR: { const cc::SolidColorDrawQuad *scquad = cc::SolidColorDrawQuad::MaterialCast(quad); - QSGRenderContext *sgrc = QQuickWindowPrivate::get(m_window)->context; - QSGRectangleNode *rectangleNode = sgrc->sceneGraphContext()->createRectangleNode(); + QSGRectangleNode *rectangleNode = m_sgRenderContext->sceneGraphContext()->createRectangleNode(); // Qt only supports MSAA and this flag shouldn't be needed. // If we ever want to use QSGRectangleNode::setAntialiasing for this we should diff --git a/src/core/delegated_frame_node.h b/src/core/delegated_frame_node.h index 71a3e1d2541ffc2a97565950e3e57ef5834f65a2..2148948212d48aff2d36611eea8ec45211dfd81a 100644 --- a/src/core/delegated_frame_node.h +++ b/src/core/delegated_frame_node.h @@ -51,7 +51,7 @@ #include <QWaitCondition> QT_BEGIN_NAMESPACE -class QQuickWindow; +class QSGRenderContext; QT_END_NAMESPACE namespace cc { @@ -73,14 +73,14 @@ public: class DelegatedFrameNode : public QSGTransformNode { public: - DelegatedFrameNode(QQuickWindow *window); + DelegatedFrameNode(QSGRenderContext *sgRenderContext); ~DelegatedFrameNode(); void preprocess(); void commit(DelegatedFrameNodeData* data, cc::ReturnedResourceArray *resourcesToRelease); private: QExplicitlySharedDataPointer<DelegatedFrameNodeData> m_data; - QQuickWindow *m_window; + QSGRenderContext *m_sgRenderContext; QList<QSharedPointer<RenderPassTexture> > m_renderPassTextures; int m_numPendingSyncPoints; QWaitCondition m_mailboxesFetchedWaitCond; diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 7430f67565c68bee26ad08866740bccae4d044c7..7df9ee46af781b01a92344503b4eb97b65c5a45b 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -685,11 +685,11 @@ void RenderWidgetHostViewQt::paint(QPainter *painter, const QRectF& boundingRect m_backingStore->paintToTarget(painter, boundingRect); } -QSGNode *RenderWidgetHostViewQt::updatePaintNode(QSGNode *oldNode, QQuickWindow *window) +QSGNode *RenderWidgetHostViewQt::updatePaintNode(QSGNode *oldNode, QSGRenderContext *sgRenderContext) { DelegatedFrameNode *frameNode = static_cast<DelegatedFrameNode *>(oldNode); if (!frameNode) - frameNode = new DelegatedFrameNode(window); + frameNode = new DelegatedFrameNode(sgRenderContext); frameNode->commit(m_frameNodeData.data(), &m_resourcesToRelease); diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index 7ecfe7ecb6ef9ae95247f1f45a8db6dd117bd425..208336b8b9d0f949e6212a585eb6e68df8c73e23 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -168,7 +168,7 @@ public: // Overridden from RenderWidgetHostViewQtDelegateClient. virtual void paint(QPainter *, const QRectF& boundingRect) Q_DECL_OVERRIDE; - virtual QSGNode *updatePaintNode(QSGNode *, QQuickWindow *) Q_DECL_OVERRIDE; + virtual QSGNode *updatePaintNode(QSGNode *, QSGRenderContext *) Q_DECL_OVERRIDE; virtual void fetchBackingStore() Q_DECL_OVERRIDE; virtual void notifyResize() Q_DECL_OVERRIDE; virtual bool forwardEvent(QEvent *) Q_DECL_OVERRIDE; diff --git a/src/core/render_widget_host_view_qt_delegate.h b/src/core/render_widget_host_view_qt_delegate.h index 08d66745b39a2fe185e090af5023806254312267..ddfa2b3c86b659ab582fd650bfbccd9d9d6849ee 100644 --- a/src/core/render_widget_host_view_qt_delegate.h +++ b/src/core/render_widget_host_view_qt_delegate.h @@ -51,8 +51,8 @@ QT_BEGIN_NAMESPACE class QCursor; class QEvent; class QPainter; -class QQuickWindow; class QSGNode; +class QSGRenderContext; class QVariant; class QWindow; class QInputMethodEvent; @@ -64,7 +64,7 @@ class QWEBENGINE_EXPORT RenderWidgetHostViewQtDelegateClient { public: virtual ~RenderWidgetHostViewQtDelegateClient() { } virtual void paint(QPainter *, const QRectF& boundingRect) = 0; - virtual QSGNode *updatePaintNode(QSGNode *, QQuickWindow *) = 0; + virtual QSGNode *updatePaintNode(QSGNode *, QSGRenderContext *) = 0; virtual void fetchBackingStore() = 0; virtual void notifyResize() = 0; virtual bool forwardEvent(QEvent *) = 0; diff --git a/src/src.pro b/src/src.pro index 536fcad5cb290eba4791f44cf9fcdc23cb41be26..6d902497f7688ecae0be01e1ccef20c3eb8c40b1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -2,7 +2,7 @@ TEMPLATE = subdirs process.depends = core webengine.depends = core -webenginewidgets.depends = core +webenginewidgets.depends = core webengine webengine_plugin.subdir = webengine/plugin webengine_plugin.target = sub-webengine-plugin webengine_plugin.depends = webengine @@ -21,6 +21,6 @@ SUBDIRS += core \ # Another example of where this could be necessary is to make it easy to build proprietery codecs support. !contains(WEBENGINE_CONFIG, no_ui_delegates): SUBDIRS += webengine/ui -qtHaveModule(widgets) { +qtHaveModule(widgets):equals(QT_MAJOR_VERSION, 5):greaterThan(QT_MINOR_VERSION, 2) { SUBDIRS += webenginewidgets } diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp index 4aa72ba6f0c681b3ae37ab94421232f8e21da242..7340d32d15b7f3db150dfaec5cfce1ad5ffad96f 100644 --- a/src/webengine/api/qtwebengineglobal.cpp +++ b/src/webengine/api/qtwebengineglobal.cpp @@ -41,8 +41,10 @@ #include "qtwebengineglobal.h" -#include <private/qsgcontext_p.h> #include <QGuiApplication> +#include <QThread> +#include <private/qopenglcontext_p.h> +#include <private/qsgcontext_p.h> static QOpenGLContext *shareContext; @@ -56,11 +58,11 @@ void QWebEngine::initialize() { QCoreApplication *app = QCoreApplication::instance(); if (!app) { - qFatal("QWebEngine::initialize() must be called after the construction of the application object."); + qFatal("QWebEngine(Widgets)::initialize() must be called after the construction of the application object."); return; } if (app->thread() != QThread::currentThread()) { - qFatal("QWebEngine::initialize() must be called from the Qt gui thread."); + qFatal("QWebEngine(Widgets)::initialize() must be called from the Qt gui thread."); return; } @@ -70,6 +72,10 @@ void QWebEngine::initialize() shareContext = new QOpenGLContext; shareContext->create(); qAddPostRoutine(deleteShareContext); +#if (QT_VERSION < QT_VERSION_CHECK(5, 3, 0)) QSGContext::setSharedOpenGLContext(shareContext); +#else + QOpenGLContextPrivate::setGlobalShareContext(shareContext); +#endif } 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 693b12e07a8db98af36c0ab38850d32ce97f408e..e2804ef9b8bcf8c22c9a259e5b8ffef7391aa862 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -66,7 +66,7 @@ void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const It QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { - return m_client->updatePaintNode(oldNode, QQuickItem::window()); + return m_client->updatePaintNode(oldNode, QQuickWindowPrivate::get(QQuickItem::window())->context); } RenderWidgetHostViewQtDelegateQuickPainted::RenderWidgetHostViewQtDelegateQuickPainted(RenderWidgetHostViewQtDelegateClient *client, bool isPopup) diff --git a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f3792248e06780653568ebca09593f4012cb51c5 --- /dev/null +++ b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtwebenginewidgetsglobal.h" + +#include "qtwebengineglobal.h" + +void QWebEngineWidgets::initialize() +{ + QWebEngine::initialize(); +} diff --git a/src/webenginewidgets/api/qtwebenginewidgetsglobal.h b/src/webenginewidgets/api/qtwebenginewidgetsglobal.h index d875c1cbeb2ea42ea4bfe622cd72e3ec3b251cdf..1836de35762eb1db4ea52c73d25271df9308bd3b 100644 --- a/src/webenginewidgets/api/qtwebenginewidgetsglobal.h +++ b/src/webenginewidgets/api/qtwebenginewidgetsglobal.h @@ -55,6 +55,12 @@ QT_BEGIN_NAMESPACE # define QWEBENGINEWIDGETS_EXPORT #endif +class QWEBENGINEWIDGETS_EXPORT QWebEngineWidgets +{ +public: + static void initialize(); +}; + QT_END_NAMESPACE #endif // QTWEBENGINEWIDGETSGLOBAL_H diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index a5e5f8320e920a4ed07d474407434ef94b05c8a2..a879a94ef9844e7e83d0daf60bc07ed4d8d6e0cb 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -148,7 +148,7 @@ void CallbackDirectory::CallbackSharedDataPointer::doDeref() QWebEnginePagePrivate::QWebEnginePagePrivate() : QObjectPrivate(QObjectPrivateVersion) - , adapter(new WebContentsAdapter(SoftwareRenderingMode)) + , adapter(new WebContentsAdapter(HardwareAccelerationMode)) , history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this))) , view(0) { @@ -353,7 +353,7 @@ void QWebEnginePagePrivate::_q_webActionTriggered(bool checked) void QWebEnginePagePrivate::recreateFromSerializedHistory(QDataStream &input) { - QExplicitlySharedDataPointer<WebContentsAdapter> newWebContents = WebContentsAdapter::createFromSerializedNavigationHistory(input, this, WebContentsAdapterClient::SoftwareRenderingMode); + QExplicitlySharedDataPointer<WebContentsAdapter> newWebContents = WebContentsAdapter::createFromSerializedNavigationHistory(input, this, WebContentsAdapterClient::HardwareAccelerationMode); if (newWebContents) { adapter = newWebContents.data(); adapter->initialize(this); diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp index 71d6e235ef0bea062d848f5257b03edd5f144896..308735f708c6a2df76daa13c9d72ababc95363ea 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp @@ -41,19 +41,21 @@ #include "render_widget_host_view_qt_delegate_widget.h" -#include "qwebengineview.h" #include "qwebenginepage_p.h" -#include <QtGlobal> +#include "qwebengineview.h" #include <QLayout> -#include <QResizeEvent> -#include <QPainter> -#include <QPaintEvent> -#include <QWindow> -#include <QtWidgets/QApplication> +#include <QSGNode> +#include <private/qsgadaptationlayer_p.h> +#include <private/qsgcontext_p.h> +#include <private/qsgrenderer_p.h> +#include <private/qwidget_p.h> RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent) - : QWidget(parent) + : QOpenGLWidget(parent) , m_client(client) + , sgContext(QSGContext::createDefaultContext()) + , sgRenderContext(new QSGRenderContext(sgContext.data())) + , rootNode(new QSGRootNode) , m_isPopup(false) { setFocusPolicy(Qt::ClickFocus); @@ -68,7 +70,7 @@ void RenderWidgetHostViewQtDelegateWidget::initAsChild(WebContentsAdapterClient* QWebEnginePagePrivate *pagePrivate = static_cast<QWebEnginePagePrivate *>(container); if (pagePrivate->view) { pagePrivate->view->layout()->addWidget(this); - QWidget::show(); + QOpenGLWidget::show(); } else setParent(0); } @@ -108,38 +110,38 @@ void RenderWidgetHostViewQtDelegateWidget::show() // Check if we're attached to a QWebEngineView, we don't // want to show anything else than popups as top-level. if (parent() || m_isPopup) - QWidget::show(); + QOpenGLWidget::show(); } void RenderWidgetHostViewQtDelegateWidget::hide() { - QWidget::hide(); + QOpenGLWidget::hide(); } bool RenderWidgetHostViewQtDelegateWidget::isVisible() const { - return QWidget::isVisible(); + return QOpenGLWidget::isVisible(); } QWindow* RenderWidgetHostViewQtDelegateWidget::window() const { - const QWidget* root = QWidget::window(); + const QWidget* root = QOpenGLWidget::window(); return root ? root->windowHandle() : 0; } -void RenderWidgetHostViewQtDelegateWidget::update(const QRect& rect) +void RenderWidgetHostViewQtDelegateWidget::update(const QRect&) { - QWidget::update(rect); + updateGL(); } void RenderWidgetHostViewQtDelegateWidget::updateCursor(const QCursor &cursor) { - QWidget::setCursor(cursor); + QOpenGLWidget::setCursor(cursor); } void RenderWidgetHostViewQtDelegateWidget::resize(int width, int height) { - QWidget::resize(width, height); + QOpenGLWidget::resize(width, height); } void RenderWidgetHostViewQtDelegateWidget::move(const QPoint &screenPos) @@ -153,7 +155,7 @@ void RenderWidgetHostViewQtDelegateWidget::inputMethodStateChanged(bool editorVi if (qApp->inputMethod()->isVisible() == editorVisible) return; - QWidget::setAttribute(Qt::WA_InputMethodEnabled, editorVisible); + QOpenGLWidget::setAttribute(Qt::WA_InputMethodEnabled, editorVisible); qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); qApp->inputMethod()->setVisible(editorVisible); } @@ -170,25 +172,44 @@ QVariant RenderWidgetHostViewQtDelegateWidget::inputMethodQuery(Qt::InputMethodQ bool RenderWidgetHostViewQtDelegateWidget::supportsHardwareAcceleration() const { - return false; -} - -void RenderWidgetHostViewQtDelegateWidget::paintEvent(QPaintEvent * event) -{ - QPainter painter(this); - m_client->fetchBackingStore(); - m_client->paint(&painter, event->rect()); + return true; } void RenderWidgetHostViewQtDelegateWidget::resizeEvent(QResizeEvent *resizeEvent) { - Q_UNUSED(resizeEvent); + QOpenGLWidget::resizeEvent(resizeEvent); m_client->notifyResize(); } bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event) { if (!m_client->forwardEvent(event)) - return QWidget::event(event); + return QOpenGLWidget::event(event); return true; } + +void RenderWidgetHostViewQtDelegateWidget::initializeGL() +{ + sgRenderContext->initialize(QOpenGLContext::currentContext()); + sgRenderer.reset(sgRenderContext->createRenderer()); + sgRenderer->setRootNode(rootNode.data()); +} + +void RenderWidgetHostViewQtDelegateWidget::paintGL() +{ + QSGNode *paintNode = m_client->updatePaintNode(rootNode->firstChild(), sgRenderContext.data()); + if (paintNode != rootNode->firstChild()) { + delete rootNode->firstChild(); + rootNode->appendChildNode(paintNode); + } + + rootNode->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update. + sgRenderer->nodeChanged(rootNode.data(), QSGNode::DirtyForceUpdate); // Force render list update. + + sgRenderer->setDeviceRect(size()); + sgRenderer->setViewportRect(size()); + sgRenderer->setProjectionMatrixToRect(QRectF(QPointF(), size())); + sgRenderer->setClearColor(Qt::transparent); + + sgRenderContext->renderNextFrame(sgRenderer.data(), defaultFramebufferObject()); +} diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h index 77a594d61264ba6bf67633357a7d943167c2d00d..6a77d8321e4de3b01416a6fd5db84accfc14c13f 100644 --- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h +++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h @@ -45,15 +45,17 @@ #include "render_widget_host_view_qt_delegate.h" #include "web_contents_adapter_client.h" -#include <QWidget> - -class BackingStoreQt; +#include <private/qopenglwidget_p.h> QT_BEGIN_NAMESPACE +class QSGContext; +class QSGRenderContext; +class QSGRenderer; +class QSGRootNode; class QWindow; QT_END_NAMESPACE -class RenderWidgetHostViewQtDelegateWidget : public QWidget, public RenderWidgetHostViewQtDelegate +class RenderWidgetHostViewQtDelegateWidget : public QOpenGLWidget, public RenderWidgetHostViewQtDelegate { public: RenderWidgetHostViewQtDelegateWidget(RenderWidgetHostViewQtDelegateClient *client, QWidget *parent = 0); @@ -76,14 +78,19 @@ public: virtual void setTooltip(const QString &tooltip) Q_DECL_OVERRIDE; protected: - void paintEvent(QPaintEvent * event); bool event(QEvent *event); void resizeEvent(QResizeEvent *resizeEvent); + void initializeGL() Q_DECL_OVERRIDE; + void paintGL() Q_DECL_OVERRIDE; QVariant inputMethodQuery(Qt::InputMethodQuery query) const; private: RenderWidgetHostViewQtDelegateClient *m_client; + QScopedPointer<QSGContext> sgContext; + QScopedPointer<QSGRenderContext> sgRenderContext; + QScopedPointer<QSGRootNode> rootNode; + QScopedPointer<QSGRenderer> sgRenderer; bool m_isPopup; }; diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro index 182cb5500d9c26ab89cfbc8b3004995a55623b6e..1f2eb84b39a12fd021d8603923048b5d13d9d488 100644 --- a/src/webenginewidgets/webenginewidgets.pro +++ b/src/webenginewidgets/webenginewidgets.pro @@ -3,14 +3,15 @@ TARGET = QtWebEngineWidgets # For our export macros DEFINES += QT_BUILD_WEBENGINEWIDGETS_LIB -QT += widgets network -QT_PRIVATE += webenginecore widgets-private gui-private network-private core-private +QT += webengine widgets network quick +QT_PRIVATE += webenginecore widgets-private quick-private gui-private network-private core-private QMAKE_DOCS = $$PWD/doc/qtwebenginewidgets.qdocconf INCLUDEPATH += $$PWD api ../core SOURCES = \ + api/qtwebenginewidgetsglobal.cpp \ api/qwebenginehistory.cpp \ api/qwebenginepage.cpp \ api/qwebengineview.cpp\ diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 359bc31455503480427380f38c456b3c231bbf77..4d9f789175af76dfb6c37f09ba007ca65d1eac99 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,5 +1,7 @@ TEMPLATE = subdirs SUBDIRS = quick -qtHaveModule(widgets): SUBDIRS += widgets +qtHaveModule(widgets):equals(QT_MAJOR_VERSION, 5):greaterThan(QT_MINOR_VERSION, 2) { + SUBDIRS += widgets +} diff --git a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp index 448f488f67c8a4d6b4f44fe1744bcdb093f1a29f..608b093963af49893260e7cf349d29c78514ca23 100644 --- a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp +++ b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp @@ -45,6 +45,7 @@ public: bool eventFilter(QObject* watched, QEvent* event); public Q_SLOTS: + void initTestCase(); void init(); void cleanup(); @@ -115,6 +116,11 @@ bool tst_QWebEngineFrame::eventFilter(QObject* watched, QEvent* event) return QObject::eventFilter(watched, event); } +void tst_QWebEngineFrame::initTestCase() +{ + QWebEngineWidgets::initialize(); +} + void tst_QWebEngineFrame::init() { m_view = new QWebEngineView(); diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index a5cbc6103debd67076e5c0eac456b83a6363661a..14008d075b96ca46f115aef16bf15ab3eec31884 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -42,6 +42,7 @@ protected : } public Q_SLOTS: + void initTestCase(); void init(); void cleanup(); @@ -86,6 +87,11 @@ tst_QWebEngineHistory::~tst_QWebEngineHistory() { } +void tst_QWebEngineHistory::initTestCase() +{ + QWebEngineWidgets::initialize(); +} + void tst_QWebEngineHistory::init() { page = new QWebEnginePage(this); diff --git a/tests/auto/widgets/qwebenginehistoryinterface/tst_qwebenginehistoryinterface.cpp b/tests/auto/widgets/qwebenginehistoryinterface/tst_qwebenginehistoryinterface.cpp index 60c54e93e080b675d7fa4deb6b430cf581991425..180a0f2fefd1f2e478454862edcdea0e7c9a7f37 100644 --- a/tests/auto/widgets/qwebenginehistoryinterface/tst_qwebenginehistoryinterface.cpp +++ b/tests/auto/widgets/qwebenginehistoryinterface/tst_qwebenginehistoryinterface.cpp @@ -34,6 +34,7 @@ public: virtual ~tst_QWebEngineHistoryInterface(); public Q_SLOTS: + void initTestCase(); void init(); void cleanup(); @@ -56,6 +57,11 @@ tst_QWebEngineHistoryInterface::~tst_QWebEngineHistoryInterface() { } +void tst_QWebEngineHistoryInterface::initTestCase() +{ + QWebEngineWidgets::initialize(); +} + void tst_QWebEngineHistoryInterface::init() { m_view = new QWebEngineView(); diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 9abc3ad0baeb1e9e72a814f49390b017a497f6f5..3c2bbb67b459538e61e5f14fff6dc2b10661af7a 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -228,6 +228,7 @@ void tst_QWebEnginePage::cleanupFiles() void tst_QWebEnginePage::initTestCase() { + QWebEngineWidgets::initialize(); cleanupFiles(); // In case there are old files from previous runs } diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 4c238a074fc352eb8895d603761d6711dc13452b..a0bf36f60d3b7472ebec72e17725dce274441525 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -63,6 +63,7 @@ private Q_SLOTS: // It is only called once. void tst_QWebEngineView::initTestCase() { + QWebEngineWidgets::initialize(); } // This will be called after the last test function is executed.