diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2016-08-31 18:13:28 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2016-08-31 18:13:28 +0200 |
commit | 3cc148853f0f7468526df9dd2397a70a8eeeedae (patch) | |
tree | 64abd86c07654a52ee44ba9ace28ca0455721704 /src/core | |
parent | 74b324b8f328e9d241984de6a9c43825fa298aff (diff) | |
parent | 44f41d30ed3efce2f1970dcd158555b41b38014d (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: Ic739ab9db0851cc13467168840ea2549996432f8
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/delegated_frame_node.cpp | 83 | ||||
-rw-r--r-- | src/core/delegated_frame_node.h | 5 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 1 |
3 files changed, 69 insertions, 20 deletions
diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index d5fc459f5..8d0b8166a 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -76,7 +76,6 @@ #include <QSGSimpleRectNode> #include <QSGSimpleTextureNode> #include <QSGTexture> -#include <QtGui/QOffscreenSurface> #include <private/qsgadaptationlayer_p.h> #if !defined(QT_NO_EGL) @@ -97,6 +96,7 @@ namespace QtWebEngineCore { class MailboxTexture : public QSGTexture, protected QOpenGLFunctions { public: MailboxTexture(const gpu::MailboxHolder &mailboxHolder, const QSize textureSize); + ~MailboxTexture(); virtual int textureId() const Q_DECL_OVERRIDE { return m_textureId; } virtual QSize textureSize() const Q_DECL_OVERRIDE { return m_textureSize; } virtual bool hasAlphaChannel() const Q_DECL_OVERRIDE { return m_hasAlpha; } @@ -114,6 +114,9 @@ private: QSize m_textureSize; bool m_hasAlpha; GLenum m_target; +#if defined(USE_X11) + bool m_ownsTexture; +#endif #ifdef Q_OS_QNX EGLStreamData m_eglStreamData; #endif @@ -286,6 +289,9 @@ MailboxTexture::MailboxTexture(const gpu::MailboxHolder &mailboxHolder, const QS , m_textureSize(textureSize) , m_hasAlpha(false) , m_target(GL_TEXTURE_2D) +#if defined(USE_X11) + , m_ownsTexture(false) +#endif { initializeOpenGLFunctions(); @@ -296,6 +302,21 @@ MailboxTexture::MailboxTexture(const gpu::MailboxHolder &mailboxHolder, const QS m_textureSize = QSize(1, 1); } +MailboxTexture::~MailboxTexture() +{ +#if defined(USE_X11) + // This is rare case, where context is not shared + // we created extra texture in current context, so + // delete it now + if (m_ownsTexture) { + QOpenGLContext *currentContext = QOpenGLContext::currentContext() ; + QOpenGLFunctions *funcs = currentContext->functions(); + GLuint id(m_textureId); + funcs->glDeleteTextures(1, &id); + } +#endif +} + void MailboxTexture::bind() { glBindTexture(m_target, m_textureId); @@ -395,8 +416,25 @@ RectClipNode::RectClipNode(const QRectF &rect) DelegatedFrameNode::DelegatedFrameNode() : m_numPendingSyncPoints(0) +#if defined(USE_X11) + , m_contextShared(true) +#endif { setFlag(UsePreprocess); +#if defined(USE_X11) + QOpenGLContext *currentContext = QOpenGLContext::currentContext() ; + QOpenGLContext *sharedContext = qt_gl_global_share_context(); + if (!QOpenGLContext::areSharing(currentContext, sharedContext)) { + static bool allowNotSharedContextWarningShown = true; + if (allowNotSharedContextWarningShown) { + allowNotSharedContextWarningShown = false; + qWarning("Context is not shared, textures will be copied between contexts."); + } + m_offsurface.reset(new QOffscreenSurface); + m_offsurface->create(); + m_contextShared = false; + } +#endif } DelegatedFrameNode::~DelegatedFrameNode() @@ -728,29 +766,28 @@ void DelegatedFrameNode::fetchAndSyncMailboxes(QList<MailboxTexture *> &mailboxe waitChromiumSync(&sync); deleteChromiumSync(&sync); } + #if defined(USE_X11) // Workaround when context is not shared QTBUG-48969 // Make slow copy between two contexts. - QOpenGLContext *currentContext = QOpenGLContext::currentContext() ; - QOpenGLContext *sharedContext = qt_gl_global_share_context(); - if (!QOpenGLContext::areSharing(currentContext,sharedContext)) { - static bool allowNotSharedContextWarningShown = true; - if (allowNotSharedContextWarningShown) { - allowNotSharedContextWarningShown = false; - qWarning("Context is not shared, textures will be copied between contexts."); - } + if (!m_contextShared) { + QOpenGLContext *currentContext = QOpenGLContext::currentContext() ; + QOpenGLContext *sharedContext = qt_gl_global_share_context(); + + QSurface *surface = currentContext->surface(); + Q_ASSERT(m_offsurface); + sharedContext->makeCurrent(m_offsurface.data()); + QOpenGLFunctions *funcs = sharedContext->functions(); + + GLuint fbo = 0; + funcs->glGenFramebuffers(1, &fbo); Q_FOREACH (MailboxTexture *mailboxTexture, mailboxesToFetch) { - QSurface *surface = currentContext->surface(); // Read texture into QImage from shared context. // Switch to shared context. - QOffscreenSurface offsurface; - offsurface.create(); - sharedContext->makeCurrent(&offsurface); - QOpenGLFunctions *funcs = sharedContext->functions(); + sharedContext->makeCurrent(m_offsurface.data()); + funcs = sharedContext->functions(); QImage img(mailboxTexture->textureSize(), QImage::Format_RGBA8888_Premultiplied); - GLuint fbo = 0; - funcs->glGenFramebuffers(1, &fbo); funcs->glBindFramebuffer(GL_FRAMEBUFFER, fbo); funcs->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mailboxTexture->m_textureId, 0); GLenum status = funcs->glCheckFramebufferStatus(GL_FRAMEBUFFER); @@ -758,13 +795,12 @@ void DelegatedFrameNode::fetchAndSyncMailboxes(QList<MailboxTexture *> &mailboxe qWarning("fbo error, skipping slow copy..."); continue; } - - funcs->glReadPixels(0, 0, mailboxTexture->textureSize().width(), mailboxTexture->textureSize().height(), GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); - funcs->glBindFramebuffer(GL_FRAMEBUFFER, 0); + funcs->glReadPixels(0, 0, mailboxTexture->textureSize().width(), mailboxTexture->textureSize().height(), + GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); // Restore current context. - currentContext->makeCurrent(surface); // Create texture from QImage in current context. + currentContext->makeCurrent(surface); GLuint texture = 0; funcs = currentContext->functions(); funcs->glGenTextures(1, &texture); @@ -776,7 +812,14 @@ void DelegatedFrameNode::fetchAndSyncMailboxes(QList<MailboxTexture *> &mailboxe funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mailboxTexture->textureSize().width(), mailboxTexture->textureSize().height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); mailboxTexture->m_textureId = texture; + mailboxTexture->m_ownsTexture = true; } + // Cleanup allocated resources + sharedContext->makeCurrent(m_offsurface.data()); + funcs = sharedContext->functions(); + funcs->glBindFramebuffer(GL_FRAMEBUFFER, 0); + funcs->glDeleteFramebuffers(1, &fbo); + currentContext->makeCurrent(surface); } #endif } diff --git a/src/core/delegated_frame_node.h b/src/core/delegated_frame_node.h index 8a37f6b4c..005f4c768 100644 --- a/src/core/delegated_frame_node.h +++ b/src/core/delegated_frame_node.h @@ -50,6 +50,7 @@ #include <QSharedData> #include <QSharedPointer> #include <QWaitCondition> +#include <QtGui/QOffscreenSurface> #include "chromium_gpu_helper.h" #include "render_widget_host_view_qt_delegate.h" @@ -105,6 +106,10 @@ private: QMutex m_mutex; QList<gfx::TransferableFence> m_textureFences; scoped_ptr<gpu::SyncPointClient> m_syncPointClient; +#if defined(USE_X11) + bool m_contextShared; + QScopedPointer<QOffscreenSurface> m_offsurface; +#endif }; } // namespace QtWebEngineCore diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index b96452093..3ade0d0f6 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -104,6 +104,7 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents if (targetAdapter) target = targetAdapter->webContents(); } + Q_ASSERT(target); content::NavigationController::LoadURLParams load_url_params(params.url); load_url_params.referrer = params.referrer; |