diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2019-08-13 14:57:05 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2019-08-22 12:24:38 +0200 |
commit | f0c471d9e2f3e9808cbf8c57bee533e8254ad1c5 (patch) | |
tree | fb22f4c4713c728821f051be644c2ec898ed7608 /src/core/compositor | |
parent | e9ed235b9f2cd5987ea24575234fb0ce2b58f753 (diff) |
Use ui::Compositor
Needs corresponding 3rdparty change.
Fixes: QTBUG-71885
Change-Id: I791bc3da5a7a66e03470e9e05bf25a997101b018
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/compositor')
-rw-r--r-- | src/core/compositor/compositor_resource_fence.cpp | 8 | ||||
-rw-r--r-- | src/core/compositor/compositor_resource_fence.h | 2 | ||||
-rw-r--r-- | src/core/compositor/display_consumer.h | 62 | ||||
-rw-r--r-- | src/core/compositor/display_frame_sink.cpp | 140 | ||||
-rw-r--r-- | src/core/compositor/display_frame_sink.h | 77 | ||||
-rw-r--r-- | src/core/compositor/display_gl_output_surface.cpp | 292 | ||||
-rw-r--r-- | src/core/compositor/display_gl_output_surface.h | 148 | ||||
-rw-r--r-- | src/core/compositor/display_gl_output_surface_qsg.cpp | 121 | ||||
-rw-r--r-- | src/core/compositor/display_overrides.cpp | 80 | ||||
-rw-r--r-- | src/core/compositor/display_producer.h | 69 | ||||
-rw-r--r-- | src/core/compositor/display_software_output_surface.cpp | 173 | ||||
-rw-r--r-- | src/core/compositor/display_software_output_surface.h | 62 |
12 files changed, 1229 insertions, 5 deletions
diff --git a/src/core/compositor/compositor_resource_fence.cpp b/src/core/compositor/compositor_resource_fence.cpp index 7fc5fbfb2..4179395d6 100644 --- a/src/core/compositor/compositor_resource_fence.cpp +++ b/src/core/compositor/compositor_resource_fence.cpp @@ -146,12 +146,12 @@ void CompositorResourceFence::release() } // static -scoped_refptr<CompositorResourceFence> CompositorResourceFence::create() +scoped_refptr<CompositorResourceFence> CompositorResourceFence::create(std::unique_ptr<gl::GLFence> glFence) { - if (gl::GLContext::GetCurrent() && gl::GLFence::IsSupported()) { - std::unique_ptr<gl::GLFence> glFence{gl::GLFence::Create()}; + if (!glFence && gl::GLContext::GetCurrent() && gl::GLFence::IsSupported()) + glFence = gl::GLFence::Create(); + if (glFence) return base::MakeRefCounted<CompositorResourceFence>(glFence->Transfer()); - } return nullptr; } diff --git a/src/core/compositor/compositor_resource_fence.h b/src/core/compositor/compositor_resource_fence.h index 1c2ea3695..196297f78 100644 --- a/src/core/compositor/compositor_resource_fence.h +++ b/src/core/compositor/compositor_resource_fence.h @@ -60,7 +60,7 @@ public: void release(); // May be used only by GPU thread. - static scoped_refptr<CompositorResourceFence> create(); + static scoped_refptr<CompositorResourceFence> create(std::unique_ptr<gl::GLFence> glFence = nullptr); private: gl::TransferableFence m_sync; diff --git a/src/core/compositor/display_consumer.h b/src/core/compositor/display_consumer.h new file mode 100644 index 000000000..d220088ad --- /dev/null +++ b/src/core/compositor/display_consumer.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DISPLAY_CONSUMER_H +#define DISPLAY_CONSUMER_H + +#include "qtwebenginecoreglobal_p.h" + +namespace QtWebEngineCore { + +// Receives composited frames for display. +class DisplayConsumer +{ +public: + // Schedule a call to updatePaintNode soon. + // + // Called on the consumer thread. + virtual void scheduleUpdate() = 0; + +protected: + ~DisplayConsumer() {} +}; + +} // namespace QtWebEngineCore + +#endif // !DISPLAY_CONSUMER_H diff --git a/src/core/compositor/display_frame_sink.cpp b/src/core/compositor/display_frame_sink.cpp new file mode 100644 index 000000000..945600299 --- /dev/null +++ b/src/core/compositor/display_frame_sink.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "display_frame_sink.h" + +#include <QMap> + +namespace QtWebEngineCore { + +namespace { + +class DisplayFrameSinkMap +{ +public: + static DisplayFrameSinkMap *instance() + { + static DisplayFrameSinkMap map; + return ↦ + } + + scoped_refptr<DisplayFrameSink> findOrCreate(viz::FrameSinkId frameSinkId) + { + QMutexLocker locker(&m_mutex); + auto it = m_map.find(frameSinkId); + if (it == m_map.end()) + it = m_map.insert(frameSinkId, new DisplayFrameSink(frameSinkId)); + return *it; + } + + void remove(viz::FrameSinkId frameSinkId) + { + QMutexLocker locker(&m_mutex); + m_map.remove(frameSinkId); + } + +private: + mutable QMutex m_mutex; + QMap<viz::FrameSinkId, DisplayFrameSink *> m_map; +}; + +} // namespace + +// static +scoped_refptr<DisplayFrameSink> DisplayFrameSink::findOrCreate(viz::FrameSinkId frameSinkId) +{ + return DisplayFrameSinkMap::instance()->findOrCreate(frameSinkId); +} + +DisplayFrameSink::DisplayFrameSink(viz::FrameSinkId frameSinkId) + : m_frameSinkId(frameSinkId) +{ + DCHECK(m_frameSinkId.is_valid()); +} + +DisplayFrameSink::~DisplayFrameSink() +{ + DisplayFrameSinkMap::instance()->remove(m_frameSinkId); +} + +void DisplayFrameSink::connect(DisplayConsumer *consumer) +{ + QMutexLocker locker(&m_mutex); + DCHECK(m_consumer == nullptr); + m_consumer = consumer; +} + +void DisplayFrameSink::connect(DisplayProducer *producer) +{ + QMutexLocker locker(&m_mutex); + DCHECK(m_producer == nullptr); + m_producer = producer; +} + +void DisplayFrameSink::disconnect(DisplayConsumer *consumer) +{ + QMutexLocker locker(&m_mutex); + DCHECK(m_consumer == consumer); + m_consumer = nullptr; +} + +void DisplayFrameSink::disconnect(DisplayProducer *producer) +{ + QMutexLocker locker(&m_mutex); + DCHECK(m_producer == producer); + m_producer = nullptr; +} + +void DisplayFrameSink::scheduleUpdate() +{ + QMutexLocker locker(&m_mutex); + if (m_consumer) + m_consumer->scheduleUpdate(); +} + +QSGNode *DisplayFrameSink::updatePaintNode(QSGNode *oldNode, RenderWidgetHostViewQtDelegate *delegate) +{ + QMutexLocker locker(&m_mutex); + QSGNode *newNode = oldNode; + if (m_producer) + newNode = m_producer->updatePaintNode(oldNode, delegate); + return newNode; +} + +} // namespace QtWebEngineCore diff --git a/src/core/compositor/display_frame_sink.h b/src/core/compositor/display_frame_sink.h new file mode 100644 index 000000000..f620dc4f2 --- /dev/null +++ b/src/core/compositor/display_frame_sink.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DISPLAY_FRAME_SINK_H +#define DISPLAY_FRAME_SINK_H + +#include "display_consumer.h" +#include "display_producer.h" + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_refptr.h" +#include "components/viz/common/surfaces/frame_sink_id.h" + +#include <QMutex> + +namespace QtWebEngineCore { + +// Connects a DisplayConsumer with a DisplayProducer. +class DisplayFrameSink final : public base::RefCountedThreadSafe<DisplayFrameSink> +{ +public: + static scoped_refptr<DisplayFrameSink> findOrCreate(viz::FrameSinkId frameSinkId); + DisplayFrameSink(viz::FrameSinkId frameSinkId); + ~DisplayFrameSink(); + void connect(DisplayConsumer *consumer); + void connect(DisplayProducer *producer); + void disconnect(DisplayConsumer *consumer); + void disconnect(DisplayProducer *producer); + void scheduleUpdate(); + QSGNode *updatePaintNode(QSGNode *oldNode, RenderWidgetHostViewQtDelegate *delegate); + +private: + const viz::FrameSinkId m_frameSinkId; + mutable QMutex m_mutex; + DisplayProducer *m_producer = nullptr; + DisplayConsumer *m_consumer = nullptr; +}; + +} // namespace QtWebEngineCore + +#endif // !DISPLAY_FRAME_SINK_H diff --git a/src/core/compositor/display_gl_output_surface.cpp b/src/core/compositor/display_gl_output_surface.cpp new file mode 100644 index 000000000..5a78b8322 --- /dev/null +++ b/src/core/compositor/display_gl_output_surface.cpp @@ -0,0 +1,292 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "display_gl_output_surface.h" + +#include "chromium_gpu_helper.h" + +#include "base/threading/thread_task_runner_handle.h" +#include "components/viz/service/display/display.h" +#include "components/viz/service/display/output_surface_frame.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "gpu/command_buffer/client/gles2_interface.h" +#include "gpu/command_buffer/service/mailbox_manager.h" +#include "gpu/command_buffer/service/texture_base.h" +#include "gpu/ipc/in_process_command_buffer.h" +#include "ui/gl/color_space_utils.h" + +namespace QtWebEngineCore { + +DisplayGLOutputSurface::DisplayGLOutputSurface( + scoped_refptr<viz::VizProcessContextProvider> contextProvider, + viz::UpdateVSyncParametersCallback callback) + : OutputSurface(contextProvider) + , m_commandBuffer(contextProvider->command_buffer()) + , m_gl(contextProvider->ContextGL()) +{ + capabilities_.uses_default_gl_framebuffer = false; + m_gl->GenFramebuffers(1, &m_fboId); + contextProvider->SetUpdateVSyncParametersCallback(std::move(callback)); +} + +DisplayGLOutputSurface::~DisplayGLOutputSurface() +{ + m_gl->DeleteFramebuffers(1, &m_fboId); + if (m_sink) + m_sink->disconnect(this); +} + +// Called from viz::Display::Initialize. +void DisplayGLOutputSurface::BindToClient(viz::OutputSurfaceClient *client) +{ + m_display = static_cast<viz::Display *>(client); + m_sink = DisplayFrameSink::findOrCreate(m_display->frame_sink_id()); + m_sink->connect(this); +} + +// Triggered by ui::Compositor::SetVisible(true). +void DisplayGLOutputSurface::EnsureBackbuffer() +{ +} + +// Triggered by ui::Compositor::SetVisible(false). Framebuffer must be cleared. +void DisplayGLOutputSurface::DiscardBackbuffer() +{ + NOTIMPLEMENTED(); + // m_gl->DiscardBackbufferCHROMIUM(); +} + +// Called from viz::DirectRenderer::DrawFrame before rendering starts, but only +// if the parameters differ from the previous Reshape call. +// +// Parameters: +// +// - sizeInPixels comes from ui::Compositor::SetScaleAndSize via +// viz::HostContextFactoryPrivate::ResizeDisplay. +// +// - devicePixelRatio comes from viz::CompositorFrame::device_scale_factor() +// via viz::RootCompositorFrameSinkImpl::SubmitCompositorFrame and +// viz::Display::SetLocalSurfaceId. +// +// - colorSpace and hasAlpha correspond to the color_space and +// has_transparent_background properties of the root viz::RenderPass. +// +// - useStencil should create a stencil buffer, but this is only needed for +// overdraw feedback (--show-overdraw-feedback), so it's safe to ignore. +// Accordingly, capabilities_.supports_stencil should be set to false. +// +void DisplayGLOutputSurface::Reshape(const gfx::Size &sizeInPixels, + float devicePixelRatio, + const gfx::ColorSpace &colorSpace, + bool hasAlpha, + bool /*useStencil*/) +{ + m_currentShape = Shape{sizeInPixels, devicePixelRatio, colorSpace, hasAlpha}; + m_gl->ResizeCHROMIUM(sizeInPixels.width(), sizeInPixels.height(), devicePixelRatio, + gl::ColorSpaceUtils::GetGLColorSpace(colorSpace), hasAlpha); +} + +std::unique_ptr<DisplayGLOutputSurface::Buffer> DisplayGLOutputSurface::makeBuffer(const Shape &shape) +{ + std::unique_ptr<Buffer> buffer = std::make_unique<Buffer>(this); + buffer->shape = shape; + m_gl->GenTextures(1, &buffer->clientId); + m_gl->BindTexture(GL_TEXTURE_2D, buffer->clientId); + m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + m_gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + uint32_t width = shape.sizeInPixels.width(); + uint32_t height = shape.sizeInPixels.height(); + uint32_t format = shape.hasAlpha ? GL_RGBA : GL_RGB; + m_gl->TexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, nullptr); + return buffer; +} + +void DisplayGLOutputSurface::deleteBufferResources(Buffer *buffer) +{ + m_gl->DeleteTextures(1, &buffer->clientId); +} + +// Called by viz::GLRenderer during rendering whenever it switches to the root +// render pass. +void DisplayGLOutputSurface::BindFramebuffer() +{ + if (!m_backBuffer || m_backBuffer->shape != m_currentShape) + m_backBuffer = makeBuffer(m_currentShape); + + m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fboId); + m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_backBuffer->clientId, 0); +} + +// Called from viz::Display::DrawAndSwap after rendering. +// +// Parameters: +// +// - frame.size is the same as the size given to Reshape. +// +// - frame.sub_buffer_rect and frame.content_bounds are never used since these +// are only enabled if gl::GLSurface::SupportsPostSubBuffer() or +// gl::GLSurface::SupportsSwapBuffersWithBounds() are true, respectively, +// but this not the case for any offscreen gl::GLSurface. +// +// - frame.latency_info is viz::CompositorFrame::metadata.latency_info. +void DisplayGLOutputSurface::SwapBuffers(viz::OutputSurfaceFrame frame) +{ + DCHECK(frame.size == m_currentShape.sizeInPixels); + DCHECK(!frame.sub_buffer_rect.has_value()); + DCHECK(frame.content_bounds.empty()); + DCHECK(m_backBuffer); + + m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fboId); + m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); + gpu::SyncToken syncToken; + m_gl->GenSyncTokenCHROMIUM(syncToken.GetData()); + + unsigned int clientId = m_backBuffer->clientId; + + // Now some thread-hopping: + // + // - We start here on the viz thread (client side of command buffer). + // + // - Then we'll jump to the gpu thread (service side of command buffer) to + // get the real OpenGL texture id. + // + // - Then we'll get a call from the Qt Quick Scene Graph thread (could be + // a separate thread or the main thread). + // + // - Finally we'll return to the viz thread to acknowledge the swap. + + { + QMutexLocker locker(&m_mutex); + m_taskRunner = base::ThreadTaskRunnerHandle::Get(); + m_middleBuffer = std::move(m_backBuffer); + m_middleBuffer->serviceId = 0; + } + + m_commandBuffer->GetTextureQt( + clientId, + base::BindOnce(&DisplayGLOutputSurface::swapBuffersOnGpuThread, base::Unretained(this)), + std::vector<gpu::SyncToken>{syncToken}); +} + +void DisplayGLOutputSurface::swapBuffersOnGpuThread(unsigned int id, std::unique_ptr<gl::GLFence> fence) +{ + { + QMutexLocker locker(&m_mutex); + m_middleBuffer->serviceId = id; + m_middleBuffer->fence = CompositorResourceFence::create(std::move(fence)); + } + + m_sink->scheduleUpdate(); +} + +void DisplayGLOutputSurface::swapBuffersOnVizThread() +{ + { + QMutexLocker locker(&m_mutex); + m_backBuffer = std::move(m_middleBuffer); + } + + m_display->DidReceiveSwapBuffersAck(); + m_display->DidReceivePresentationFeedback( + gfx::PresentationFeedback(base::TimeTicks::Now(), base::TimeDelta(), + gfx::PresentationFeedback::Flags::kVSync)); +} + +void DisplayGLOutputSurface::SetDrawRectangle(const gfx::Rect &) +{ +} + +// Returning nullptr here effectively disables viz::OverlayProcessor. +viz::OverlayCandidateValidator *DisplayGLOutputSurface::GetOverlayCandidateValidator() const +{ + return nullptr; +} + +// Returning true here will cause viz::GLRenderer to try to render the output +// surface as an overlay plane (see viz::DirectRenderer::DrawFrame and +// viz::GLRenderer::ScheduleOverlays). +bool DisplayGLOutputSurface::IsDisplayedAsOverlayPlane() const +{ + return false; +} + +// Only used if IsDisplayedAsOverlayPlane was true (called from +// viz::GLRenderer::ScheduleOverlays). +unsigned DisplayGLOutputSurface::GetOverlayTextureId() const +{ + return 0; +} + +// Only used if IsDisplayedAsOverlayPlane was true (called from +// viz::DirectRender::DrawFrame). +gfx::BufferFormat DisplayGLOutputSurface::GetOverlayBufferFormat() const +{ + return gfx::BufferFormat(); +} + +// Called by viz::GLRenderer but always false in all implementations except for +// android_webview::ParentOutputSurface. +bool DisplayGLOutputSurface::HasExternalStencilTest() const +{ + return false; +} + +// Only called if HasExternalStencilTest was true. Dead code? +void DisplayGLOutputSurface::ApplyExternalStencil() +{ + NOTREACHED(); +} + +// Called from GLRenderer::GetFramebufferCopyTextureFormat when using +// glCopyTexSubImage2D on our framebuffer. +uint32_t DisplayGLOutputSurface::GetFramebufferCopyTextureFormat() +{ + return GL_RGBA; +} + +// Called from viz::DirectRenderer::DrawFrame, only used for overlays. +unsigned DisplayGLOutputSurface::UpdateGpuFence() +{ + NOTREACHED(); + return 0; +} + +} // namespace QtWebEngineCore diff --git a/src/core/compositor/display_gl_output_surface.h b/src/core/compositor/display_gl_output_surface.h new file mode 100644 index 000000000..c42a6630a --- /dev/null +++ b/src/core/compositor/display_gl_output_surface.h @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DISPLAY_GL_OUTPUT_SURFACE_H +#define DISPLAY_GL_OUTPUT_SURFACE_H + +#include "compositor_resource_fence.h" +#include "display_frame_sink.h" + +#include "components/viz/common/display/update_vsync_parameters_callback.h" +#include "components/viz/service/display/output_surface.h" +#include "components/viz/service/display_embedder/viz_process_context_provider.h" +#include "gpu/command_buffer/common/mailbox.h" +#include "gpu/command_buffer/common/sync_token.h" + +namespace viz { +class Display; +class SyntheticBeginFrameSource; +} // namespace viz + +namespace QtWebEngineCore { + +// NOTE: Some methods are defined in display_gl_output_surface_qsg.cpp due +// to conflicts between Qt & Chromium OpenGL APIs. +class DisplayGLOutputSurface final : public viz::OutputSurface, public DisplayProducer +{ +public: + DisplayGLOutputSurface( + scoped_refptr<viz::VizProcessContextProvider> contextProvider, + viz::UpdateVSyncParametersCallback callback); + ~DisplayGLOutputSurface() override; + + // Overridden from viz::OutputSurface. + void BindToClient(viz::OutputSurfaceClient *client) override; + void EnsureBackbuffer() override; + void DiscardBackbuffer() override; + void BindFramebuffer() override; + void SetDrawRectangle(const gfx::Rect &drawRect) override; + viz::OverlayCandidateValidator *GetOverlayCandidateValidator() const override; + bool IsDisplayedAsOverlayPlane() const override; + unsigned GetOverlayTextureId() const override; + gfx::BufferFormat GetOverlayBufferFormat() const override; + void Reshape(const gfx::Size &size, + float devicePixelRatio, + const gfx::ColorSpace &colorSpace, + bool hasAlpha, + bool useStencil) override; + bool HasExternalStencilTest() const override; + void ApplyExternalStencil() override; + uint32_t GetFramebufferCopyTextureFormat() override; + void SwapBuffers(viz::OutputSurfaceFrame frame) override; + unsigned UpdateGpuFence() override; + + // Overridden from DisplayProducer. + QSGNode *updatePaintNode(QSGNode *oldNode, RenderWidgetHostViewQtDelegate *delegate) override; + +private: + struct Shape + { + gfx::Size sizeInPixels; + float devicePixelRatio; + gfx::ColorSpace colorSpace; + bool hasAlpha; + + bool operator==(const Shape &that) const + { + return (sizeInPixels == that.sizeInPixels && + devicePixelRatio == that.devicePixelRatio && + colorSpace == that.colorSpace && + hasAlpha == that.hasAlpha); + } + bool operator!=(const Shape &that) const { return !(*this == that); } + }; + + struct Buffer + { + DisplayGLOutputSurface *parent; + Shape shape; + uint32_t clientId = 0; + uint32_t serviceId = 0; + scoped_refptr<CompositorResourceFence> fence; + + Buffer(DisplayGLOutputSurface *parent) : parent(parent) {} + ~Buffer() { parent->deleteBufferResources(this); } + }; + + class Texture; + + void swapBuffersOnGpuThread(unsigned int id, std::unique_ptr<gl::GLFence> fence); + void swapBuffersOnVizThread(); + + std::unique_ptr<Buffer> makeBuffer(const Shape &shape); + void deleteBufferResources(Buffer *buffer); + void attachBuffer(); + void detachBuffer(); + + gpu::InProcessCommandBuffer *const m_commandBuffer; + gpu::gles2::GLES2Interface *const m_gl; + mutable QMutex m_mutex; + uint32_t m_fboId = 0; + viz::Display *m_display = nullptr; + scoped_refptr<DisplayFrameSink> m_sink; + Shape m_currentShape; + std::unique_ptr<Buffer> m_backBuffer; + std::unique_ptr<Buffer> m_middleBuffer; + std::unique_ptr<Buffer> m_frontBuffer; + scoped_refptr<base::SingleThreadTaskRunner> m_taskRunner; +}; + +} // namespace QtWebEngineCore + +#endif // !DISPLAY_GL_OUTPUT_SURFACE_H diff --git a/src/core/compositor/display_gl_output_surface_qsg.cpp b/src/core/compositor/display_gl_output_surface_qsg.cpp new file mode 100644 index 000000000..2f7b3de84 --- /dev/null +++ b/src/core/compositor/display_gl_output_surface_qsg.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "display_gl_output_surface.h" + +#include "compositor_resource_fence.h" +#include "render_widget_host_view_qt_delegate.h" +#include "type_conversion.h" + +#include <QOpenGLFunctions> +#include <QSGImageNode> +#include <QSGTexture> + +namespace QtWebEngineCore { + +class DisplayGLOutputSurface::Texture final : public QSGTexture +{ +public: + Texture(uint32_t id, QSize sizeInPixels, bool hasAlphaChannel, scoped_refptr<CompositorResourceFence> fence) + : m_id(id) + , m_sizeInPixels(sizeInPixels) + , m_hasAlphaChannel(hasAlphaChannel) + , m_fence(std::move(fence)) + { + } + + // QSGTexture: + int textureId() const override { return m_id; } + QSize textureSize() const override { return m_sizeInPixels; } + bool hasAlphaChannel() const override { return m_hasAlphaChannel; } + bool hasMipmaps() const override { return false; } + void bind() override + { + if (m_fence) { + m_fence->wait(); + m_fence.reset(); + } + + QOpenGLContext *context = QOpenGLContext::currentContext(); + QOpenGLFunctions *funcs = context->functions(); + funcs->glBindTexture(GL_TEXTURE_2D, m_id); + } + +private: + uint32_t m_id; + QSize m_sizeInPixels; + bool m_hasAlphaChannel; + scoped_refptr<CompositorResourceFence> m_fence; +}; + +QSGNode *DisplayGLOutputSurface::updatePaintNode(QSGNode *oldNode, RenderWidgetHostViewQtDelegate *delegate) +{ + { + QMutexLocker locker(&m_mutex); + if (m_middleBuffer && m_middleBuffer->serviceId) { + std::swap(m_middleBuffer, m_frontBuffer); + m_taskRunner->PostTask( + FROM_HERE, + base::BindOnce(&DisplayGLOutputSurface::swapBuffersOnVizThread, base::Unretained(this))); + m_taskRunner.reset(); + } + } + + if (!m_frontBuffer) + return oldNode; + + auto node = static_cast<QSGImageNode *>(oldNode); + if (!node) + node = delegate->createImageNode(); + + QSize sizeInPixels = toQt(m_frontBuffer->shape.sizeInPixels); + QSizeF sizeInDips = QSizeF(sizeInPixels) / m_frontBuffer->shape.devicePixelRatio; + QRectF rectInDips(QPointF(0, 0), sizeInDips); + node->setRect(rectInDips); + node->setOwnsTexture(true); + node->setTexture(new Texture(m_frontBuffer->serviceId, + sizeInPixels, + m_frontBuffer->shape.hasAlpha, + m_frontBuffer->fence)); + node->setTextureCoordinatesTransform(QSGImageNode::MirrorVertically); + + return node; +} + +} // namespace QtWebEngineCore diff --git a/src/core/compositor/display_overrides.cpp b/src/core/compositor/display_overrides.cpp new file mode 100644 index 000000000..4547bb04b --- /dev/null +++ b/src/core/compositor/display_overrides.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "display_gl_output_surface.h" +#include "display_software_output_surface.h" + +#include "components/viz/service/display_embedder/gpu_display_provider.h" +#include "gpu/ipc/in_process_command_buffer.h" + +std::unique_ptr<viz::OutputSurface> +viz::GpuDisplayProvider::CreateGLOutputSurface( + scoped_refptr<VizProcessContextProvider> context_provider, + UpdateVSyncParametersCallback update_vsync_callback) +{ + return std::make_unique<QtWebEngineCore::DisplayGLOutputSurface>( + std::move(context_provider), std::move(update_vsync_callback)); +} + +std::unique_ptr<viz::OutputSurface> +viz::GpuDisplayProvider::CreateSoftwareOutputSurface( + UpdateVSyncParametersCallback update_vsync_callback) +{ + return std::make_unique<QtWebEngineCore::DisplaySoftwareOutputSurface>(std::move(update_vsync_callback)); +} + +void gpu::InProcessCommandBuffer::GetTextureQt( + unsigned int client_id, + GetTextureCallback callback, + const std::vector<SyncToken>& sync_token_fences) +{ + ScheduleGpuTask(base::BindOnce(&InProcessCommandBuffer::GetTextureQtOnGpuThread, + gpu_thread_weak_ptr_factory_.GetWeakPtr(), + client_id, + std::move(callback)), + sync_token_fences); +} + +void gpu::InProcessCommandBuffer::GetTextureQtOnGpuThread( + unsigned int client_id, GetTextureCallback callback) +{ + MakeCurrent(); + gpu::TextureBase *texture = decoder_->GetTextureBase(client_id); + std::move(callback).Run(texture ? texture->service_id() : 0, gl::GLFence::Create()); +} diff --git a/src/core/compositor/display_producer.h b/src/core/compositor/display_producer.h new file mode 100644 index 000000000..5de09d2d2 --- /dev/null +++ b/src/core/compositor/display_producer.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DISPLAY_PRODUCER_H +#define DISPLAY_PRODUCER_H + +#include "qtwebenginecoreglobal_p.h" + +QT_BEGIN_NAMESPACE +class QSGNode; +QT_END_NAMESPACE + +namespace QtWebEngineCore { +class RenderWidgetHostViewQtDelegate; + +// Produces composited frames for display. +class DisplayProducer +{ +public: + // Generate scene graph nodes for the current frame. + // + // If this is a scheduled update (that is, scheduleUpdate was called + // earlier), then updatePaintNode will generate nodes for a new frame. + // Otherwise, it will just regenerate nodes for the old frame. + virtual QSGNode *updatePaintNode(QSGNode *oldNode, RenderWidgetHostViewQtDelegate *delegate) = 0; + +protected: + ~DisplayProducer() {} +}; + +} // namespace QtWebEngineCore + +#endif // !DISPLAY_PRODUCER_H diff --git a/src/core/compositor/display_software_output_surface.cpp b/src/core/compositor/display_software_output_surface.cpp new file mode 100644 index 000000000..13f8e8f38 --- /dev/null +++ b/src/core/compositor/display_software_output_surface.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "display_software_output_surface.h" + +#include "display_frame_sink.h" +#include "render_widget_host_view_qt_delegate.h" +#include "type_conversion.h" + +#include "base/threading/thread_task_runner_handle.h" +#include "components/viz/service/display/display.h" +#include "components/viz/service/display/output_surface_frame.h" + +#include <QMutex> +#include <QPainter> +#include <QSGImageNode> + +namespace QtWebEngineCore { + +class DisplaySoftwareOutputSurface::Device final : public viz::SoftwareOutputDevice, public DisplayProducer +{ +public: + ~Device(); + + // Called from DisplaySoftwareOutputSurface. + void bind(viz::FrameSinkId frameSinkId); + + // Overridden from viz::SoftwareOutputDevice. + void Resize(const gfx::Size &sizeInPixels, float devicePixelRatio) override; + void OnSwapBuffers(base::OnceClosure swapCompletionCallback) override; + + // Overridden from DisplayProducer. + QSGNode *updatePaintNode(QSGNode *oldNode, RenderWidgetHostViewQtDelegate *delegate) override; + +private: + mutable QMutex m_mutex; + scoped_refptr<DisplayFrameSink> m_sink; + float m_devicePixelRatio = 1.0; + scoped_refptr<base::SingleThreadTaskRunner> m_taskRunner; + base::OnceClosure m_swapCompletionCallback; + QImage m_image; + float m_imageDevicePixelRatio = 1.0; +}; + +DisplaySoftwareOutputSurface::Device::~Device() +{ + if (m_sink) + m_sink->disconnect(this); +} + +void DisplaySoftwareOutputSurface::Device::bind(viz::FrameSinkId frameSinkId) +{ + m_sink = DisplayFrameSink::findOrCreate(frameSinkId); + m_sink->connect(this); +} + +void DisplaySoftwareOutputSurface::Device::Resize(const gfx::Size &sizeInPixels, float devicePixelRatio) +{ + if (viewport_pixel_size_ == sizeInPixels && m_devicePixelRatio == devicePixelRatio) + return; + m_devicePixelRatio = devicePixelRatio; + viewport_pixel_size_ = sizeInPixels; + surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(sizeInPixels.width(), sizeInPixels.height())); +} + +void DisplaySoftwareOutputSurface::Device::OnSwapBuffers(base::OnceClosure swapCompletionCallback) +{ + QMutexLocker locker(&m_mutex); + m_taskRunner = base::ThreadTaskRunnerHandle::Get(); + m_swapCompletionCallback = std::move(swapCompletionCallback); + m_sink->scheduleUpdate(); +} + +inline QImage::Format imageFormat(SkColorType colorType) +{ + switch (colorType) { + case kBGRA_8888_SkColorType: + return QImage::Format_ARGB32_Premultiplied; + case kRGBA_8888_SkColorType: + return QImage::Format_RGBA8888_Premultiplied; + default: + Q_UNREACHABLE(); + return QImage::Format_ARGB32_Premultiplied; + } +} + +QSGNode *DisplaySoftwareOutputSurface::Device::updatePaintNode( + QSGNode *oldNode, RenderWidgetHostViewQtDelegate *delegate) +{ + QMutexLocker locker(&m_mutex); + + // Delete old node to make sure refcount of m_image is at most 1. + delete oldNode; + QSGImageNode *node = delegate->createImageNode(); + + if (m_swapCompletionCallback) { + SkPixmap skPixmap; + surface_->peekPixels(&skPixmap); + QImage image(reinterpret_cast<const uchar *>(skPixmap.addr()), + viewport_pixel_size_.width(), viewport_pixel_size_.height(), + skPixmap.rowBytes(), imageFormat(skPixmap.colorType())); + if (m_image.size() == image.size()) { + QRect damageRect = toQt(damage_rect_); + QPainter(&m_image).drawImage(damageRect, image, damageRect); + } else { + m_image = image; + m_image.detach(); + } + m_imageDevicePixelRatio = m_devicePixelRatio; + m_taskRunner->PostTask(FROM_HERE, std::move(m_swapCompletionCallback)); + m_taskRunner.reset(); + } + + QSizeF sizeInDips = QSizeF(m_image.size()) / m_imageDevicePixelRatio; + node->setRect(QRectF(QPointF(0, 0), sizeInDips)); + node->setOwnsTexture(true); + node->setTexture(delegate->createTextureFromImage(m_image)); + + return node; +} + +DisplaySoftwareOutputSurface::DisplaySoftwareOutputSurface(viz::UpdateVSyncParametersCallback callback) + : SoftwareOutputSurface(std::make_unique<Device>(), std::move(callback)) +{} + +DisplaySoftwareOutputSurface::~DisplaySoftwareOutputSurface() {} + +// Called from viz::Display::Initialize. +void DisplaySoftwareOutputSurface::BindToClient(viz::OutputSurfaceClient *client) +{ + auto display = static_cast<viz::Display *>(client); + auto device = static_cast<Device *>(software_device()); + device->bind(display->frame_sink_id()); + SoftwareOutputSurface::BindToClient(client); +} + +} // namespace QtWebEngineCore diff --git a/src/core/compositor/display_software_output_surface.h b/src/core/compositor/display_software_output_surface.h new file mode 100644 index 000000000..6707c74dc --- /dev/null +++ b/src/core/compositor/display_software_output_surface.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DISPLAY_SOFTWARE_OUTPUT_SURFACE_H +#define DISPLAY_SOFTWARE_OUTPUT_SURFACE_H + +#include "components/viz/service/display_embedder/software_output_surface.h" + +namespace QtWebEngineCore { + +class DisplaySoftwareOutputSurface final : public viz::SoftwareOutputSurface +{ +public: + DisplaySoftwareOutputSurface(viz::UpdateVSyncParametersCallback callback); + ~DisplaySoftwareOutputSurface() override; + + // Overridden from viz::SoftwareOutputSurface. + void BindToClient(viz::OutputSurfaceClient *client) override; + +private: + class Device; +}; + +} // namespace QtWebEngineCore + +#endif // !DISPLAY_SOFTWARE_OUTPUT_SURFACE_H |