Commit 468b6b18 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

ozone/wayland: allow to run Wayland without mojo.

Even though we set require_mojo to true in the PlatformProperties,
in certain scenarios Ozone might be initialized without mojo, but in
a single process mode (for example, unittests, ozone_demo).

In this case, we should instantiate a direct connection between
buffer managers without mojo. I could use base::TaskEnvironment, but
it will require too much changes to how different tests are initialized.

For example, binding an interface and sending a mojo call requires a
a task runner handle (installed in WaylandBufferManagerGpu). And
that fails with compositor_unittests - some tests create
TaskEnvironment, and some don't.

Initializing the TaskEnvironment in CompositorTestSuite won't help,
because (as I said) some tests do that. This results in crashing when
tls delegate is set.

Bug: 1067156
Change-Id: If3236f9604c692b4ed6efc5dbaf9cc67ce36d62e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128111Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#756173}
parent c1c2abea
...@@ -29,6 +29,10 @@ source_set("wayland") { ...@@ -29,6 +29,10 @@ source_set("wayland") {
"gpu/gl_surface_wayland.h", "gpu/gl_surface_wayland.h",
"gpu/wayland_buffer_manager_gpu.cc", "gpu/wayland_buffer_manager_gpu.cc",
"gpu/wayland_buffer_manager_gpu.h", "gpu/wayland_buffer_manager_gpu.h",
"gpu/wayland_buffer_manager_gpu_impl.cc",
"gpu/wayland_buffer_manager_gpu_impl.h",
"gpu/wayland_buffer_manager_gpu_single_process.cc",
"gpu/wayland_buffer_manager_gpu_single_process.h",
"gpu/wayland_canvas_surface.cc", "gpu/wayland_canvas_surface.cc",
"gpu/wayland_canvas_surface.h", "gpu/wayland_canvas_surface.h",
"gpu/wayland_surface_factory.cc", "gpu/wayland_surface_factory.cc",
...@@ -58,6 +62,10 @@ source_set("wayland") { ...@@ -58,6 +62,10 @@ source_set("wayland") {
"host/wayland_buffer_manager_connector.h", "host/wayland_buffer_manager_connector.h",
"host/wayland_buffer_manager_host.cc", "host/wayland_buffer_manager_host.cc",
"host/wayland_buffer_manager_host.h", "host/wayland_buffer_manager_host.h",
"host/wayland_buffer_manager_host_impl.cc",
"host/wayland_buffer_manager_host_impl.h",
"host/wayland_buffer_manager_host_single_process.cc",
"host/wayland_buffer_manager_host_single_process.h",
"host/wayland_clipboard.cc", "host/wayland_clipboard.cc",
"host/wayland_clipboard.h", "host/wayland_clipboard.h",
"host/wayland_connection.cc", "host/wayland_connection.cc",
......
...@@ -17,8 +17,7 @@ namespace ui { ...@@ -17,8 +17,7 @@ namespace ui {
WaylandBufferManagerGpu::WaylandBufferManagerGpu() = default; WaylandBufferManagerGpu::WaylandBufferManagerGpu() = default;
WaylandBufferManagerGpu::~WaylandBufferManagerGpu() = default; WaylandBufferManagerGpu::~WaylandBufferManagerGpu() = default;
void WaylandBufferManagerGpu::Initialize( void WaylandBufferManagerGpu::StoreBufferFormatsWithModifiers(
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host,
const base::flat_map<::gfx::BufferFormat, std::vector<uint64_t>>& const base::flat_map<::gfx::BufferFormat, std::vector<uint64_t>>&
buffer_formats_with_modifiers, buffer_formats_with_modifiers,
bool supports_dma_buf) { bool supports_dma_buf) {
...@@ -29,34 +28,28 @@ void WaylandBufferManagerGpu::Initialize( ...@@ -29,34 +28,28 @@ void WaylandBufferManagerGpu::Initialize(
if (!supports_dma_buf) if (!supports_dma_buf)
set_gbm_device(nullptr); set_gbm_device(nullptr);
#endif #endif
BindHostInterface(std::move(remote_host));
io_thread_runner_ = base::ThreadTaskRunnerHandle::Get();
} }
void WaylandBufferManagerGpu::OnSubmission(gfx::AcceleratedWidget widget, void WaylandBufferManagerGpu::OnBufferSubmitted(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
gfx::SwapResult swap_result) { gfx::SwapResult swap_result) {
DCHECK(io_thread_runner_->BelongsToCurrentThread()); DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
// Return back to the same thread where the commit request came from. auto* surface = GetSurface(widget);
commit_thread_runner_->PostTask( // The surface might be destroyed by the time the swap result is provided.
FROM_HERE, if (surface)
base::BindOnce(&WaylandBufferManagerGpu::SubmitSwapResultOnOriginThread, surface->OnSubmission(buffer_id, swap_result);
base::Unretained(this), widget, buffer_id, swap_result));
} }
void WaylandBufferManagerGpu::OnPresentation( void WaylandBufferManagerGpu::OnBufferPresented(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) { const gfx::PresentationFeedback& feedback) {
DCHECK(io_thread_runner_->BelongsToCurrentThread()); DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
// Return back to the same thread where the commit request came from. auto* surface = GetSurface(widget);
commit_thread_runner_->PostTask( // The surface might be destroyed by the time the presentation feedback is
FROM_HERE, // provided.
base::BindOnce( if (surface)
&WaylandBufferManagerGpu::SubmitPresentationtOnOriginThread, surface->OnPresentation(buffer_id, feedback);
base::Unretained(this), widget, buffer_id, feedback));
} }
void WaylandBufferManagerGpu::RegisterSurface(gfx::AcceleratedWidget widget, void WaylandBufferManagerGpu::RegisterSurface(gfx::AcceleratedWidget widget,
...@@ -80,72 +73,6 @@ WaylandSurfaceGpu* WaylandBufferManagerGpu::GetSurface( ...@@ -80,72 +73,6 @@ WaylandSurfaceGpu* WaylandBufferManagerGpu::GetSurface(
return nullptr; return nullptr;
} }
void WaylandBufferManagerGpu::CreateDmabufBasedBuffer(
base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id) {
DCHECK(io_thread_runner_);
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpu::CreateDmabufBasedBufferInternal,
base::Unretained(this), std::move(dmabuf_fd),
std::move(size), std::move(strides), std::move(offsets),
std::move(modifiers), current_format, planes_count,
buffer_id));
}
void WaylandBufferManagerGpu::CreateShmBasedBuffer(
base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id) {
DCHECK(io_thread_runner_);
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpu::CreateShmBasedBufferInternal,
base::Unretained(this), std::move(shm_fd), length,
std::move(size), buffer_id));
}
void WaylandBufferManagerGpu::CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) {
DCHECK(io_thread_runner_);
if (!commit_thread_runner_)
commit_thread_runner_ = base::ThreadTaskRunnerHandle::Get();
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpu::CommitBufferInternal,
base::Unretained(this), widget, buffer_id, damage_region));
}
void WaylandBufferManagerGpu::DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) {
DCHECK(io_thread_runner_);
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE, base::BindOnce(&WaylandBufferManagerGpu::DestroyBufferInternal,
base::Unretained(this), widget, buffer_id));
}
void WaylandBufferManagerGpu::AddBindingWaylandBufferManagerGpu(
mojo::PendingReceiver<ozone::mojom::WaylandBufferManagerGpu> receiver) {
receiver_.Bind(std::move(receiver));
}
const std::vector<uint64_t>& const std::vector<uint64_t>&
WaylandBufferManagerGpu::GetModifiersForBufferFormat( WaylandBufferManagerGpu::GetModifiersForBufferFormat(
gfx::BufferFormat buffer_format) const { gfx::BufferFormat buffer_format) const {
...@@ -161,87 +88,4 @@ uint32_t WaylandBufferManagerGpu::AllocateBufferID() { ...@@ -161,87 +88,4 @@ uint32_t WaylandBufferManagerGpu::AllocateBufferID() {
return ++next_buffer_id_; return ++next_buffer_id_;
} }
void WaylandBufferManagerGpu::CreateDmabufBasedBufferInternal(
base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->CreateDmabufBasedBuffer(
mojo::PlatformHandle(std::move(dmabuf_fd)), size, strides, offsets,
modifiers, current_format, planes_count, buffer_id);
}
void WaylandBufferManagerGpu::CreateShmBasedBufferInternal(
base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->CreateShmBasedBuffer(mojo::PlatformHandle(std::move(shm_fd)),
length, size, buffer_id);
}
void WaylandBufferManagerGpu::CommitBufferInternal(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->CommitBuffer(widget, buffer_id, damage_region);
}
void WaylandBufferManagerGpu::DestroyBufferInternal(
gfx::AcceleratedWidget widget,
uint32_t buffer_id) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->DestroyBuffer(widget, buffer_id);
}
void WaylandBufferManagerGpu::BindHostInterface(
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host) {
remote_host_.Bind(std::move(remote_host));
// Setup associated interface.
mojo::PendingAssociatedRemote<ozone::mojom::WaylandBufferManagerGpu>
client_remote;
associated_receiver_.Bind(client_remote.InitWithNewEndpointAndPassReceiver());
DCHECK(remote_host_);
remote_host_->SetWaylandBufferManagerGpu(std::move(client_remote));
}
void WaylandBufferManagerGpu::SubmitSwapResultOnOriginThread(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
gfx::SwapResult swap_result) {
DCHECK(commit_thread_runner_->BelongsToCurrentThread());
DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
auto* surface = GetSurface(widget);
// The surface might be destroyed by the time the swap result is provided.
if (surface)
surface->OnSubmission(buffer_id, swap_result);
}
void WaylandBufferManagerGpu::SubmitPresentationtOnOriginThread(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) {
DCHECK(commit_thread_runner_->BelongsToCurrentThread());
DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
auto* surface = GetSurface(widget);
// The surface might be destroyed by the time the presentation feedback is
// provided.
if (surface)
surface->OnPresentation(buffer_id, feedback);
}
} // namespace ui } // namespace ui
...@@ -29,36 +29,32 @@ class Rect; ...@@ -29,36 +29,32 @@ class Rect;
namespace ui { namespace ui {
class WaylandConnection;
class WaylandSurfaceGpu; class WaylandSurfaceGpu;
class WaylandWindow; class WaylandWindow;
// Forwards calls through an associated mojo connection to WaylandBufferManager // Base implementation of WaylandBufferManagerGpu.
// on the browser process side. class WaylandBufferManagerGpu {
//
// It's guaranteed that WaylandBufferManagerGpu makes mojo calls on the right
// sequence.
class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
public: public:
WaylandBufferManagerGpu(); WaylandBufferManagerGpu();
~WaylandBufferManagerGpu() override; virtual ~WaylandBufferManagerGpu();
// WaylandBufferManagerGpu overrides: // Stores supported buffer formats with modifiers. If |supports_dma_buf|,
void Initialize( // |gbm_device_| will be reset, which means dmabuf based buffers can't be
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host, // created.
void StoreBufferFormatsWithModifiers(
const base::flat_map<::gfx::BufferFormat, std::vector<uint64_t>>& const base::flat_map<::gfx::BufferFormat, std::vector<uint64_t>>&
buffer_formats_with_modifiers, buffer_formats_with_modifiers,
bool supports_dma_buf) override; bool supports_dma_buf);
// These two calls get the surface, which backs the |widget| and notifies it // These two calls get the surface, which backs the |widget| and notifies it
// about the submission and the presentation. After the surface receives the // about the submission and the presentation. After the surface receives the
// OnSubmission call, it can schedule a new buffer for swap. // OnSubmission call, it can schedule a new buffer for swap.
void OnSubmission(gfx::AcceleratedWidget widget, void OnBufferSubmitted(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
gfx::SwapResult swap_result) override; gfx::SwapResult swap_result);
void OnPresentation(gfx::AcceleratedWidget widget, void OnBufferPresented(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) override; const gfx::PresentationFeedback& feedback);
// If the client, which uses this manager and implements WaylandSurfaceGpu, // If the client, which uses this manager and implements WaylandSurfaceGpu,
// wants to receive OnSubmission and OnPresentation callbacks and know the // wants to receive OnSubmission and OnPresentation callbacks and know the
...@@ -69,26 +65,21 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -69,26 +65,21 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
void UnregisterSurface(gfx::AcceleratedWidget widget); void UnregisterSurface(gfx::AcceleratedWidget widget);
WaylandSurfaceGpu* GetSurface(gfx::AcceleratedWidget widget); WaylandSurfaceGpu* GetSurface(gfx::AcceleratedWidget widget);
// Methods, which can be used when in both in-process-gpu and out of process
// modes. These calls are forwarded to the browser process through the
// WaylandConnection mojo interface. See more in
// ui/ozone/public/mojom/wayland/wayland_connection.mojom.
//
// Asks Wayland to create generic dmabuf-based wl_buffer. // Asks Wayland to create generic dmabuf-based wl_buffer.
void CreateDmabufBasedBuffer(base::ScopedFD dmabuf_fd, virtual void CreateDmabufBasedBuffer(base::ScopedFD dmabuf_fd,
gfx::Size size, gfx::Size size,
const std::vector<uint32_t>& strides, const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets, const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers, const std::vector<uint64_t>& modifiers,
uint32_t current_format, uint32_t current_format,
uint32_t planes_count, uint32_t planes_count,
uint32_t buffer_id); uint32_t buffer_id) = 0;
// Asks Wayland to create a shared memory based wl_buffer. // Asks Wayland to create a shared memory based wl_buffer.
void CreateShmBasedBuffer(base::ScopedFD shm_fd, virtual void CreateShmBasedBuffer(base::ScopedFD shm_fd,
size_t length, size_t length,
gfx::Size size, gfx::Size size,
uint32_t buffer_id); uint32_t buffer_id) = 0;
// Asks Wayland to find a wl_buffer with the |buffer_id| and attach the // Asks Wayland to find a wl_buffer with the |buffer_id| and attach the
// buffer to the WaylandWindow's surface, which backs the following |widget|. // buffer to the WaylandWindow's surface, which backs the following |widget|.
...@@ -100,12 +91,13 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -100,12 +91,13 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
// logic as well. This call must not be done twice for the same |widget| until // logic as well. This call must not be done twice for the same |widget| until
// the OnSubmission is called (which actually means the client can continue // the OnSubmission is called (which actually means the client can continue
// sending buffer swap requests). // sending buffer swap requests).
void CommitBuffer(gfx::AcceleratedWidget widget, virtual void CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::Rect& damage_region); const gfx::Rect& damage_region) = 0;
// Asks Wayland to destroy a wl_buffer. // Asks Wayland to destroy a wl_buffer.
void DestroyBuffer(gfx::AcceleratedWidget widget, uint32_t buffer_id); virtual void DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) = 0;
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
// Returns a gbm_device based on a DRM render node. // Returns a gbm_device based on a DRM render node.
...@@ -115,10 +107,6 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -115,10 +107,6 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
} }
#endif #endif
// Adds a WaylandBufferManagerGpu binding.
void AddBindingWaylandBufferManagerGpu(
mojo::PendingReceiver<ozone::mojom::WaylandBufferManagerGpu> receiver);
// Returns supported modifiers for the supplied |buffer_format|. // Returns supported modifiers for the supplied |buffer_format|.
const std::vector<uint64_t>& GetModifiersForBufferFormat( const std::vector<uint64_t>& GetModifiersForBufferFormat(
gfx::BufferFormat buffer_format) const; gfx::BufferFormat buffer_format) const;
...@@ -127,50 +115,11 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -127,50 +115,11 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
uint32_t AllocateBufferID(); uint32_t AllocateBufferID();
private: private:
void CreateDmabufBasedBufferInternal(base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id);
void CreateShmBasedBufferInternal(base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id);
void CommitBufferInternal(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region);
void DestroyBufferInternal(gfx::AcceleratedWidget widget, uint32_t buffer_id);
void BindHostInterface(
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host);
// Provides the WaylandSurfaceGpu, which backs the |widget|, with swap and
// presentation results.
void SubmitSwapResultOnOriginThread(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
gfx::SwapResult swap_result);
void SubmitPresentationtOnOriginThread(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback);
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
// A DRM render node based gbm device. // A DRM render node based gbm device.
std::unique_ptr<GbmDevice> gbm_device_; std::unique_ptr<GbmDevice> gbm_device_;
#endif #endif
mojo::Receiver<ozone::mojom::WaylandBufferManagerGpu> receiver_{this};
// A pointer to a WaylandBufferManagerHost object, which always lives on a
// browser process side. It's used for a multi-process mode.
mojo::Remote<ozone::mojom::WaylandBufferManagerHost> remote_host_;
mojo::AssociatedReceiver<ozone::mojom::WaylandBufferManagerGpu>
associated_receiver_{this};
std::map<gfx::AcceleratedWidget, WaylandSurfaceGpu*> std::map<gfx::AcceleratedWidget, WaylandSurfaceGpu*>
widget_to_surface_map_; // Guarded by |lock_|. widget_to_surface_map_; // Guarded by |lock_|.
...@@ -180,26 +129,11 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -180,26 +129,11 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
base::flat_map<gfx::BufferFormat, std::vector<uint64_t>> base::flat_map<gfx::BufferFormat, std::vector<uint64_t>>
supported_buffer_formats_with_modifiers_; supported_buffer_formats_with_modifiers_;
// This task runner can be used to pass messages back to the same thread,
// where the commit buffer request came from. For example, swap requests come
// from the GpuMainThread, but rerouted to the IOChildThread and then mojo
// calls happen. However, when the manager receives mojo calls, it has to
// reroute calls back to the same thread where the calls came from to ensure
// correct sequence.
scoped_refptr<base::SingleThreadTaskRunner> commit_thread_runner_;
// A task runner, which is initialized in a multi-process mode. It is used to
// ensure all the methods of this class are run on IOChildThread. This is
// needed to ensure mojo calls happen on a right sequence.
scoped_refptr<base::SingleThreadTaskRunner> io_thread_runner_;
// Protects access to |widget_to_surface_map_|. // Protects access to |widget_to_surface_map_|.
base::Lock lock_; base::Lock lock_;
// Keeps track of the next unique buffer ID. // Keeps track of the next unique buffer ID.
uint32_t next_buffer_id_ = 0; uint32_t next_buffer_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerGpu);
}; };
} // namespace ui } // namespace ui
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu_impl.h"
#include <utility>
#include "base/bind.h"
#include "base/message_loop/message_loop_current.h"
#include "base/process/process.h"
#include "ui/gfx/linux/drm_util_linux.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
namespace ui {
WaylandBufferManagerGpuImpl::WaylandBufferManagerGpuImpl()
: receiver_(this), associated_receiver_(this) {}
WaylandBufferManagerGpuImpl::~WaylandBufferManagerGpuImpl() = default;
void WaylandBufferManagerGpuImpl::Initialize(
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host,
const base::flat_map<::gfx::BufferFormat, std::vector<uint64_t>>&
buffer_formats_with_modifiers,
bool supports_dma_buf) {
StoreBufferFormatsWithModifiers(buffer_formats_with_modifiers,
supports_dma_buf);
BindHostInterface(std::move(remote_host));
io_thread_runner_ = base::ThreadTaskRunnerHandle::Get();
}
void WaylandBufferManagerGpuImpl::OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
gfx::SwapResult swap_result) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
// Return back to the same thread where the commit request came from.
commit_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpuImpl::OnBufferSubmitted,
base::Unretained(this), widget, buffer_id, swap_result));
}
void WaylandBufferManagerGpuImpl::OnPresentation(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
// Return back to the same thread where the commit request came from.
commit_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpuImpl::OnBufferPresented,
base::Unretained(this), widget, buffer_id, feedback));
}
void WaylandBufferManagerGpuImpl::CreateDmabufBasedBuffer(
base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id) {
DCHECK(io_thread_runner_);
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&WaylandBufferManagerGpuImpl::CreateDmabufBasedBufferInternal,
base::Unretained(this), std::move(dmabuf_fd), std::move(size),
std::move(strides), std::move(offsets), std::move(modifiers),
current_format, planes_count, buffer_id));
}
void WaylandBufferManagerGpuImpl::CreateShmBasedBuffer(base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id) {
DCHECK(io_thread_runner_);
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpuImpl::CreateShmBasedBufferInternal,
base::Unretained(this), std::move(shm_fd), length,
std::move(size), buffer_id));
}
void WaylandBufferManagerGpuImpl::CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) {
DCHECK(io_thread_runner_);
if (!commit_thread_runner_)
commit_thread_runner_ = base::ThreadTaskRunnerHandle::Get();
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpuImpl::CommitBufferInternal,
base::Unretained(this), widget, buffer_id, damage_region));
}
void WaylandBufferManagerGpuImpl::DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) {
DCHECK(io_thread_runner_);
// Do the mojo call on the IO child thread.
io_thread_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WaylandBufferManagerGpuImpl::DestroyBufferInternal,
base::Unretained(this), widget, buffer_id));
}
void WaylandBufferManagerGpuImpl::AddBindingWaylandBufferManagerGpu(
mojo::PendingReceiver<ozone::mojom::WaylandBufferManagerGpu> receiver) {
receiver_.Bind(std::move(receiver));
}
void WaylandBufferManagerGpuImpl::CreateDmabufBasedBufferInternal(
base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->CreateDmabufBasedBuffer(
mojo::PlatformHandle(std::move(dmabuf_fd)), size, strides, offsets,
modifiers, current_format, planes_count, buffer_id);
}
void WaylandBufferManagerGpuImpl::CreateShmBasedBufferInternal(
base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->CreateShmBasedBuffer(mojo::PlatformHandle(std::move(shm_fd)),
length, size, buffer_id);
}
void WaylandBufferManagerGpuImpl::CommitBufferInternal(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->CommitBuffer(widget, buffer_id, damage_region);
}
void WaylandBufferManagerGpuImpl::DestroyBufferInternal(
gfx::AcceleratedWidget widget,
uint32_t buffer_id) {
DCHECK(io_thread_runner_->BelongsToCurrentThread());
DCHECK(remote_host_);
remote_host_->DestroyBuffer(widget, buffer_id);
}
void WaylandBufferManagerGpuImpl::BindHostInterface(
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host) {
remote_host_.Bind(std::move(remote_host));
// Setup associated interface.
mojo::PendingAssociatedRemote<ozone::mojom::WaylandBufferManagerGpu>
client_remote;
associated_receiver_.Bind(client_remote.InitWithNewEndpointAndPassReceiver());
DCHECK(remote_host_);
remote_host_->SetWaylandBufferManagerGpu(std::move(client_remote));
}
} // namespace ui
\ No newline at end of file
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_IMPL_H_
#define UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_IMPL_H_
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/public/mojom/wayland/wayland_buffer_manager.mojom.h"
namespace ui {
// Forwards calls through an associated mojo connection to WaylandBufferManager
// on the browser process side.
//
// It's guaranteed that WaylandBufferManagerGpuImpl makes mojo calls on the
// right sequence.
class WaylandBufferManagerGpuImpl
: public ozone::mojom::WaylandBufferManagerGpu,
public WaylandBufferManagerGpu {
public:
WaylandBufferManagerGpuImpl();
~WaylandBufferManagerGpuImpl() override;
WaylandBufferManagerGpuImpl(const WaylandBufferManagerGpuImpl& manager) =
delete;
WaylandBufferManagerGpuImpl& operator=(
const WaylandBufferManagerGpuImpl& manager) = delete;
// ozone::mojom::WaylandBufferManagerGpu overrides:
void Initialize(
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host,
const base::flat_map<::gfx::BufferFormat, std::vector<uint64_t>>&
buffer_formats_with_modifiers,
bool supports_dma_buf) override;
void OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
gfx::SwapResult swap_result) override;
void OnPresentation(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) override;
// Methods, which can be used when in both in-process-gpu and out of process
// modes. These calls are forwarded to the browser process through the
// WaylandBufferManagerHost mojo interface. See more in
// ui/ozone/public/mojom/wayland/wayland_connection.mojom.
void CreateDmabufBasedBuffer(base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id) override;
void CreateShmBasedBuffer(base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id) override;
void CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) override;
void DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) override;
// Adds a WaylandBufferManagerGpu binding.
void AddBindingWaylandBufferManagerGpu(
mojo::PendingReceiver<ozone::mojom::WaylandBufferManagerGpu> receiver);
private:
void CreateDmabufBasedBufferInternal(base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id);
void CreateShmBasedBufferInternal(base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id);
void CommitBufferInternal(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region);
void DestroyBufferInternal(gfx::AcceleratedWidget widget, uint32_t buffer_id);
void BindHostInterface(
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> remote_host);
mojo::Receiver<ozone::mojom::WaylandBufferManagerGpu> receiver_;
// A pointer to a WaylandBufferManagerHost object, which always lives on a
// browser process side. It's used for a multi-process mode.
mojo::Remote<ozone::mojom::WaylandBufferManagerHost> remote_host_;
mojo::AssociatedReceiver<ozone::mojom::WaylandBufferManagerGpu>
associated_receiver_;
// This task runner can be used to pass messages back to the same thread,
// where the commit buffer request came from. For example, swap requests come
// from the GpuMainThread, but rerouted to the IOChildThread and then mojo
// calls happen. However, when the manager receives mojo calls, it has to
// reroute calls back to the same thread where the calls came from to ensure
// correct sequence.
scoped_refptr<base::SingleThreadTaskRunner> commit_thread_runner_;
// A task runner, which is initialized in a multi-process mode. It is used to
// ensure all the methods of this class are run on IOChildThread. This is
// needed to ensure mojo calls happen on a right sequence.
scoped_refptr<base::SingleThreadTaskRunner> io_thread_runner_;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_IMPL_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu_single_process.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
namespace ui {
WaylandBufferManagerGpuSingleProcess::WaylandBufferManagerGpuSingleProcess(
WaylandBufferManagerHost* single_proc_host)
: single_proc_host_(single_proc_host) {
DCHECK(single_proc_host_);
}
WaylandBufferManagerGpuSingleProcess::~WaylandBufferManagerGpuSingleProcess() =
default;
void WaylandBufferManagerGpuSingleProcess::CreateDmabufBasedBuffer(
base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id) {
single_proc_host_->CreateBufferDmabuf(std::move(dmabuf_fd), size, strides,
offsets, modifiers, current_format,
planes_count, buffer_id);
}
void WaylandBufferManagerGpuSingleProcess::CreateShmBasedBuffer(
base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id) {
single_proc_host_->CreateBufferShm(std::move(shm_fd), length, size,
buffer_id);
}
void WaylandBufferManagerGpuSingleProcess::CommitBuffer(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) {
single_proc_host_->CommitBufferWithId(widget, buffer_id, damage_region);
}
void WaylandBufferManagerGpuSingleProcess::DestroyBuffer(
gfx::AcceleratedWidget widget,
uint32_t buffer_id) {
single_proc_host_->DestroyBufferWithId(widget, buffer_id);
}
} // namespace ui
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_SINGLE_PROCESS_H_
#define UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_SINGLE_PROCESS_H_
#include <memory>
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
namespace ui {
class WaylandBufferManagerHost;
// Same as WaylandBufferManagerGpuImpl, but uses direct connection with the
// WaylandBufferManagerHost if mojo is not available.
class WaylandBufferManagerGpuSingleProcess : public WaylandBufferManagerGpu {
public:
explicit WaylandBufferManagerGpuSingleProcess(
WaylandBufferManagerHost* single_proc_host);
~WaylandBufferManagerGpuSingleProcess() override;
WaylandBufferManagerGpuSingleProcess(
const WaylandBufferManagerGpuSingleProcess& manager) = delete;
WaylandBufferManagerGpuSingleProcess& operator=(
const WaylandBufferManagerGpuSingleProcess& manager) = delete;
// WaylandBufferManagerGpu overrides:
void CreateDmabufBasedBuffer(base::ScopedFD dmabuf_fd,
gfx::Size size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t current_format,
uint32_t planes_count,
uint32_t buffer_id) override;
void CreateShmBasedBuffer(base::ScopedFD shm_fd,
size_t length,
gfx::Size size,
uint32_t buffer_id) override;
void CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) override;
void DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) override;
private:
WaylandBufferManagerHost* const single_proc_host_;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_SINGLE_PROCESS_H_
...@@ -166,16 +166,6 @@ class WaylandSurfaceFactoryTest : public WaylandTest { ...@@ -166,16 +166,6 @@ class WaylandSurfaceFactoryTest : public WaylandTest {
WaylandSurfaceFactoryTest() = default; WaylandSurfaceFactoryTest() = default;
~WaylandSurfaceFactoryTest() override = default; ~WaylandSurfaceFactoryTest() override = default;
void SetUp() override {
WaylandTest::SetUp();
auto manager_ptr = connection_->buffer_manager_host()->BindInterface();
buffer_manager_gpu_->Initialize(std::move(manager_ptr), {}, false);
// Wait until initialization and mojo calls go through.
base::RunLoop().RunUntilIdle();
}
void TearDown() override { void TearDown() override {
// The mojo call to destroy shared buffer goes after surfaces are destroyed. // The mojo call to destroy shared buffer goes after surfaces are destroyed.
// Wait until it's done. // Wait until it's done.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_impl.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h"
namespace ui { namespace ui {
...@@ -33,7 +33,7 @@ void BindInterfaceInGpuProcess(mojo::PendingReceiver<Interface> request, ...@@ -33,7 +33,7 @@ void BindInterfaceInGpuProcess(mojo::PendingReceiver<Interface> request,
} // namespace } // namespace
WaylandBufferManagerConnector::WaylandBufferManagerConnector( WaylandBufferManagerConnector::WaylandBufferManagerConnector(
WaylandBufferManagerHost* buffer_manager_host) WaylandBufferManagerHostImpl* buffer_manager_host)
: buffer_manager_host_(buffer_manager_host) {} : buffer_manager_host_(buffer_manager_host) {}
WaylandBufferManagerConnector::~WaylandBufferManagerConnector() = default; WaylandBufferManagerConnector::~WaylandBufferManagerConnector() = default;
...@@ -71,7 +71,7 @@ void WaylandBufferManagerConnector::OnGpuServiceLaunched( ...@@ -71,7 +71,7 @@ void WaylandBufferManagerConnector::OnGpuServiceLaunched(
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
ui_runner.get(), FROM_HERE, ui_runner.get(), FROM_HERE,
base::BindOnce(&WaylandBufferManagerHost::BindInterface, base::BindOnce(&WaylandBufferManagerHostImpl::BindInterface,
base::Unretained(buffer_manager_host_)), base::Unretained(buffer_manager_host_)),
base::BindOnce( base::BindOnce(
&WaylandBufferManagerConnector::OnBufferManagerHostPtrBinded, &WaylandBufferManagerConnector::OnBufferManagerHostPtrBinded,
......
...@@ -12,15 +12,15 @@ ...@@ -12,15 +12,15 @@
namespace ui { namespace ui {
class WaylandBufferManagerHost; class WaylandBufferManagerHostImpl;
// A connector class which instantiates a connection between // A connector class which instantiates a connection between
// WaylandBufferManagerGpu on the GPU side and the WaylandBufferManagerHost // WaylandBufferManagerGpuImpl on the GPU side and the
// object on the browser process side. // WaylandBufferManagerHostImpl object on the browser process side.
class WaylandBufferManagerConnector : public GpuPlatformSupportHost { class WaylandBufferManagerConnector : public GpuPlatformSupportHost {
public: public:
explicit WaylandBufferManagerConnector( explicit WaylandBufferManagerConnector(
WaylandBufferManagerHost* buffer_manager_host); WaylandBufferManagerHostImpl* buffer_manager_host);
~WaylandBufferManagerConnector() override; ~WaylandBufferManagerConnector() override;
// GpuPlatformSupportHost: // GpuPlatformSupportHost:
...@@ -46,8 +46,8 @@ class WaylandBufferManagerConnector : public GpuPlatformSupportHost { ...@@ -46,8 +46,8 @@ class WaylandBufferManagerConnector : public GpuPlatformSupportHost {
void OnTerminateGpuProcess(std::string message); void OnTerminateGpuProcess(std::string message);
// Non-owned pointer, which is used to bind a mojo pointer to the // Non-owned pointer, which is used to bind a mojo pointer to the
// WaylandBufferManagerHost. // WaylandBufferManagerHostImpl.
WaylandBufferManagerHost* const buffer_manager_host_; WaylandBufferManagerHostImpl* const buffer_manager_host_;
GpuHostBindInterfaceCallback binder_; GpuHostBindInterfaceCallback binder_;
GpuHostTerminateCallback terminate_callback_; GpuHostTerminateCallback terminate_callback_;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <memory> #include <memory>
#include "base/i18n/number_formatting.h" #include "base/i18n/number_formatting.h"
#include "base/message_loop/message_loop_current.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
...@@ -605,17 +604,19 @@ WaylandBuffer::WaylandBuffer(const gfx::Size& size, uint32_t buffer_id) ...@@ -605,17 +604,19 @@ WaylandBuffer::WaylandBuffer(const gfx::Size& size, uint32_t buffer_id)
: size(size), buffer_id(buffer_id) {} : size(size), buffer_id(buffer_id) {}
WaylandBuffer::~WaylandBuffer() = default; WaylandBuffer::~WaylandBuffer() = default;
WaylandBufferManagerHost::WaylandBufferManagerHost( WaylandBufferManagerHost::WaylandBufferManagerHost() : weak_factory_(this) {}
WaylandConnection* connection)
: connection_(connection), receiver_(this), weak_factory_(this) {
connection_->wayland_window_manager()->AddObserver(this);
}
WaylandBufferManagerHost::~WaylandBufferManagerHost() { WaylandBufferManagerHost::~WaylandBufferManagerHost() {
DCHECK(surfaces_.empty()); DCHECK(surfaces_.empty());
DCHECK(anonymous_buffers_.empty()); DCHECK(anonymous_buffers_.empty());
} }
void WaylandBufferManagerHost::SetWaylandConnection(
WaylandConnection* connection) {
connection_ = connection;
connection_->wayland_window_manager()->AddObserver(this);
}
void WaylandBufferManagerHost::OnWindowAdded(WaylandWindow* window) { void WaylandBufferManagerHost::OnWindowAdded(WaylandWindow* window) {
DCHECK(window); DCHECK(window);
surfaces_[window->GetWidget()] = surfaces_[window->GetWidget()] =
...@@ -632,24 +633,7 @@ void WaylandBufferManagerHost::OnWindowRemoved(WaylandWindow* window) { ...@@ -632,24 +633,7 @@ void WaylandBufferManagerHost::OnWindowRemoved(WaylandWindow* window) {
surfaces_.erase(it); surfaces_.erase(it);
} }
void WaylandBufferManagerHost::SetTerminateGpuCallback( void WaylandBufferManagerHost::ClearInternalState() {
base::OnceCallback<void(std::string)> terminate_callback) {
terminate_gpu_cb_ = std::move(terminate_callback);
}
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost>
WaylandBufferManagerHost::BindInterface() {
DCHECK(!receiver_.is_bound());
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost>
buffer_manager_host;
receiver_.Bind(buffer_manager_host.InitWithNewPipeAndPassReceiver());
return buffer_manager_host;
}
void WaylandBufferManagerHost::OnChannelDestroyed() {
buffer_manager_gpu_associated_.reset();
receiver_.reset();
for (auto& surface_pair : surfaces_) for (auto& surface_pair : surfaces_)
surface_pair.second->ClearState(); surface_pair.second->ClearState();
...@@ -671,14 +655,8 @@ bool WaylandBufferManagerHost::SupportsDmabuf() const { ...@@ -671,14 +655,8 @@ bool WaylandBufferManagerHost::SupportsDmabuf() const {
(connection_->drm() && connection_->drm()->SupportsDrmPrime()); (connection_->drm() && connection_->drm()->SupportsDrmPrime());
} }
void WaylandBufferManagerHost::SetWaylandBufferManagerGpu( void WaylandBufferManagerHost::CreateBufferDmabuf(
mojo::PendingAssociatedRemote<ozone::mojom::WaylandBufferManagerGpu> base::ScopedFD dmabuf_fd,
buffer_manager_gpu_associated) {
buffer_manager_gpu_associated_.Bind(std::move(buffer_manager_gpu_associated));
}
void WaylandBufferManagerHost::CreateDmabufBasedBuffer(
mojo::PlatformHandle dmabuf_fd,
const gfx::Size& size, const gfx::Size& size,
const std::vector<uint32_t>& strides, const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets, const std::vector<uint32_t>& offsets,
...@@ -686,20 +664,17 @@ void WaylandBufferManagerHost::CreateDmabufBasedBuffer( ...@@ -686,20 +664,17 @@ void WaylandBufferManagerHost::CreateDmabufBasedBuffer(
uint32_t format, uint32_t format,
uint32_t planes_count, uint32_t planes_count,
uint32_t buffer_id) { uint32_t buffer_id) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DCHECK(error_message_.empty()); DCHECK(error_message_.empty());
TRACE_EVENT2("wayland", "WaylandBufferManagerHost::CreateDmabufBasedBuffer", TRACE_EVENT2("wayland", "WaylandBufferManagerHost::CreateDmabufBasedBuffer",
"Format", format, "Buffer id", buffer_id); "Format", format, "Buffer id", buffer_id);
base::ScopedFD fd = dmabuf_fd.TakeFD();
// Validate data and ask surface to create a buffer associated with the // Validate data and ask surface to create a buffer associated with the
// |buffer_id|. // |buffer_id|.
if (!ValidateDataFromGpu(fd, size, strides, offsets, modifiers, format, if (!ValidateDataFromGpu(dmabuf_fd, size, strides, offsets, modifiers, format,
planes_count, buffer_id) || planes_count, buffer_id) ||
!CreateBuffer(size, buffer_id)) { !CreateBuffer(size, buffer_id)) {
TerminateGpuProcess(); OnError(std::move(error_message_));
return; return;
} }
...@@ -708,12 +683,12 @@ void WaylandBufferManagerHost::CreateDmabufBasedBuffer( ...@@ -708,12 +683,12 @@ void WaylandBufferManagerHost::CreateDmabufBasedBuffer(
base::BindOnce(&WaylandBufferManagerHost::OnCreateBufferComplete, base::BindOnce(&WaylandBufferManagerHost::OnCreateBufferComplete,
weak_factory_.GetWeakPtr(), buffer_id); weak_factory_.GetWeakPtr(), buffer_id);
if (connection_->zwp_dmabuf()) { if (connection_->zwp_dmabuf()) {
connection_->zwp_dmabuf()->CreateBuffer(std::move(fd), size, strides, connection_->zwp_dmabuf()->CreateBuffer(std::move(dmabuf_fd), size, strides,
offsets, modifiers, format, offsets, modifiers, format,
planes_count, std::move(callback)); planes_count, std::move(callback));
} else if (connection_->drm()) { } else if (connection_->drm()) {
connection_->drm()->CreateBuffer(std::move(fd), size, strides, offsets, connection_->drm()->CreateBuffer(std::move(dmabuf_fd), size, strides,
modifiers, format, planes_count, offsets, modifiers, format, planes_count,
std::move(callback)); std::move(callback));
} else { } else {
// This method must never be called if neither zwp_linux_dmabuf or wl_drm // This method must never be called if neither zwp_linux_dmabuf or wl_drm
...@@ -722,36 +697,34 @@ void WaylandBufferManagerHost::CreateDmabufBasedBuffer( ...@@ -722,36 +697,34 @@ void WaylandBufferManagerHost::CreateDmabufBasedBuffer(
} }
} }
void WaylandBufferManagerHost::CreateShmBasedBuffer(mojo::PlatformHandle shm_fd, void WaylandBufferManagerHost::CreateBufferShm(base::ScopedFD shm_fd,
uint64_t length, uint64_t length,
const gfx::Size& size, const gfx::Size& size,
uint32_t buffer_id) { uint32_t buffer_id) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DCHECK(error_message_.empty()); DCHECK(error_message_.empty());
TRACE_EVENT1("wayland", "WaylandBufferManagerHost::CreateShmBasedBuffer", TRACE_EVENT1("wayland", "WaylandBufferManagerHost::CreateShmBasedBuffer",
"Buffer id", buffer_id); "Buffer id", buffer_id);
base::ScopedFD fd = shm_fd.TakeFD();
// Validate data and create a buffer associated with the |buffer_id|. // Validate data and create a buffer associated with the |buffer_id|.
if (!ValidateDataFromGpu(fd, length, size, buffer_id) || if (!ValidateDataFromGpu(shm_fd, length, size, buffer_id) ||
!CreateBuffer(size, buffer_id)) { !CreateBuffer(size, buffer_id)) {
TerminateGpuProcess(); OnError(std::move(error_message_));
return; return;
} }
// Create a shm based wl_buffer and attach it to the created buffer. // Create a shm based wl_buffer and attach it to the created buffer.
auto buffer = connection_->shm()->CreateBuffer(std::move(fd), length, size); auto buffer =
connection_->shm()->CreateBuffer(std::move(shm_fd), length, size);
OnCreateBufferComplete(buffer_id, std::move(buffer)); OnCreateBufferComplete(buffer_id, std::move(buffer));
connection_->ScheduleFlush(); connection_->ScheduleFlush();
} }
void WaylandBufferManagerHost::CommitBuffer(gfx::AcceleratedWidget widget, void WaylandBufferManagerHost::CommitBufferWithId(
uint32_t buffer_id, gfx::AcceleratedWidget widget,
const gfx::Rect& damage_region) { uint32_t buffer_id,
DCHECK(base::MessageLoopCurrentForUI::IsSet()); const gfx::Rect& damage_region) {
TRACE_EVENT1("wayland", "WaylandBufferManagerHost::CommitBuffer", "Buffer id", TRACE_EVENT1("wayland", "WaylandBufferManagerHost::CommitBuffer", "Buffer id",
buffer_id); buffer_id);
...@@ -772,19 +745,18 @@ void WaylandBufferManagerHost::CommitBuffer(gfx::AcceleratedWidget widget, ...@@ -772,19 +745,18 @@ void WaylandBufferManagerHost::CommitBuffer(gfx::AcceleratedWidget widget,
} }
if (!error_message_.empty()) if (!error_message_.empty())
TerminateGpuProcess(); OnError(std::move(error_message_));
} }
void WaylandBufferManagerHost::DestroyBuffer(gfx::AcceleratedWidget widget, void WaylandBufferManagerHost::DestroyBufferWithId(
uint32_t buffer_id) { gfx::AcceleratedWidget widget,
DCHECK(base::MessageLoopCurrentForUI::IsSet()); uint32_t buffer_id) {
TRACE_EVENT1("wayland", "WaylandBufferManagerHost::DestroyBuffer", TRACE_EVENT1("wayland", "WaylandBufferManagerHost::DestroyBuffer",
"Buffer id", buffer_id); "Buffer id", buffer_id);
DCHECK(error_message_.empty()); DCHECK(error_message_.empty());
if (!ValidateBufferIdFromGpu(buffer_id)) { if (!ValidateBufferIdFromGpu(buffer_id)) {
TerminateGpuProcess(); OnError(std::move(error_message_));
return; return;
} }
...@@ -815,7 +787,7 @@ void WaylandBufferManagerHost::DestroyBuffer(gfx::AcceleratedWidget widget, ...@@ -815,7 +787,7 @@ void WaylandBufferManagerHost::DestroyBuffer(gfx::AcceleratedWidget widget,
error_message_ = base::StrCat( error_message_ = base::StrCat(
{"Buffer with ", NumberToString(buffer_id), " id does not exist"}); {"Buffer with ", NumberToString(buffer_id), " id does not exist"});
TerminateGpuProcess(); OnError(std::move(error_message_));
} }
void WaylandBufferManagerHost::ResetSurfaceContents( void WaylandBufferManagerHost::ResetSurfaceContents(
...@@ -966,32 +938,6 @@ void WaylandBufferManagerHost::OnCreateBufferComplete( ...@@ -966,32 +938,6 @@ void WaylandBufferManagerHost::OnCreateBufferComplete(
// be destroyed. // be destroyed.
} }
void WaylandBufferManagerHost::OnSubmission(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DCHECK(buffer_manager_gpu_associated_);
buffer_manager_gpu_associated_->OnSubmission(widget, buffer_id, swap_result);
}
void WaylandBufferManagerHost::OnPresentation(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DCHECK(buffer_manager_gpu_associated_);
buffer_manager_gpu_associated_->OnPresentation(widget, buffer_id, feedback);
}
void WaylandBufferManagerHost::TerminateGpuProcess() {
DCHECK(!error_message_.empty());
std::move(terminate_gpu_cb_).Run(std::move(error_message_));
// The GPU process' failure results in calling ::OnChannelDestroyed.
}
bool WaylandBufferManagerHost::DestroyAnonymousBuffer(uint32_t buffer_id) { bool WaylandBufferManagerHost::DestroyAnonymousBuffer(uint32_t buffer_id) {
auto it = anonymous_buffers_.find(buffer_id); auto it = anonymous_buffers_.find(buffer_id);
if (it == anonymous_buffers_.end()) if (it == anonymous_buffers_.end())
......
...@@ -72,68 +72,50 @@ struct WaylandBuffer { ...@@ -72,68 +72,50 @@ struct WaylandBuffer {
// accelerated compositing) or shared memory (software compositing) and uses // accelerated compositing) or shared memory (software compositing) and uses
// internal representation of surfaces, which are used to store buffers // internal representation of surfaces, which are used to store buffers
// associated with the WaylandWindow. // associated with the WaylandWindow.
class WaylandBufferManagerHost : public ozone::mojom::WaylandBufferManagerHost, class WaylandBufferManagerHost : public WaylandWindowObserver {
public WaylandWindowObserver {
public: public:
explicit WaylandBufferManagerHost(WaylandConnection* connection); WaylandBufferManagerHost();
~WaylandBufferManagerHost() override; ~WaylandBufferManagerHost() override;
void SetWaylandConnection(WaylandConnection* connection);
// WaylandWindowObserver implements: // WaylandWindowObserver implements:
void OnWindowAdded(WaylandWindow* window) override; void OnWindowAdded(WaylandWindow* window) override;
void OnWindowRemoved(WaylandWindow* window) override; void OnWindowRemoved(WaylandWindow* window) override;
void SetTerminateGpuCallback(
base::OnceCallback<void(std::string)> terminate_gpu_cb);
// Returns bound pointer to own mojo interface.
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> BindInterface();
// Unbinds the interface and clears the state of the |buffer_manager_|. Used
// only when the GPU channel, which uses the mojo pipe to this interface, is
// destroyed.
void OnChannelDestroyed();
// Returns supported buffer formats either from zwp_linux_dmabuf or wl_drm. // Returns supported buffer formats either from zwp_linux_dmabuf or wl_drm.
wl::BufferFormatsWithModifiersMap GetSupportedBufferFormats() const; wl::BufferFormatsWithModifiersMap GetSupportedBufferFormats() const;
bool SupportsDmabuf() const; bool SupportsDmabuf() const;
// ozone::mojom::WaylandBufferManagerHost overrides: // Creates a wl_buffer based on a gbm file descriptor using zwp_linux_dmabuf
// // protocol.
// These overridden methods below are invoked by the GPU when hardware void CreateBufferDmabuf(base::ScopedFD dmabuf_fd,
// accelerated rendering is used. const gfx::Size& size,
void SetWaylandBufferManagerGpu( const std::vector<uint32_t>& strides,
mojo::PendingAssociatedRemote<ozone::mojom::WaylandBufferManagerGpu> const std::vector<uint32_t>& offsets,
buffer_manager_gpu_associated) override; const std::vector<uint64_t>& modifiers,
// uint32_t format,
// Called by the GPU and asks to import a wl_buffer based on a gbm file uint32_t planes_count,
// descriptor using zwp_linux_dmabuf protocol. Check comments in the uint32_t buffer_id);
// ui/ozone/public/mojom/wayland/wayland_connection.mojom.
void CreateDmabufBasedBuffer(mojo::PlatformHandle dmabuf_fd, // Creates a wl_buffer based on a shared memory file descriptor using wl_shm
const gfx::Size& size, // protocol.
const std::vector<uint32_t>& strides, void CreateBufferShm(base::ScopedFD shm_fd,
const std::vector<uint32_t>& offsets, uint64_t length,
const std::vector<uint64_t>& modifiers, const gfx::Size& size,
uint32_t format, uint32_t buffer_id);
uint32_t planes_count,
uint32_t buffer_id) override;
// Called by the GPU and asks to import a wl_buffer based on a shared memory
// file descriptor using wl_shm protocol. Check comments in the
// ui/ozone/public/mojom/wayland/wayland_connection.mojom.
void CreateShmBasedBuffer(mojo::PlatformHandle shm_fd,
uint64_t length,
const gfx::Size& size,
uint32_t buffer_id) override;
// Called by the GPU to destroy the imported wl_buffer with a |buffer_id|. // Called by the GPU to destroy the imported wl_buffer with a |buffer_id|.
void DestroyBuffer(gfx::AcceleratedWidget widget, void DestroyBufferWithId(gfx::AcceleratedWidget widget, uint32_t buffer_id);
uint32_t buffer_id) override;
// Called by the GPU and asks to attach a wl_buffer with a |buffer_id| to a // Attaches a wl_buffer with a |buffer_id| to a
// WaylandWindow with the specified |widget|. // WaylandWindow with the specified |widget|.
// Calls OnSubmission and OnPresentation on successful swap and pixels // Calls OnSubmission and OnPresentation on successful swap and pixels
// presented. // presented.
void CommitBuffer(gfx::AcceleratedWidget widget, void CommitBufferWithId(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::Rect& damage_region) override; const gfx::Rect& damage_region);
// When a surface is hidden, the client may want to detach the buffer attached // When a surface is hidden, the client may want to detach the buffer attached
// to the surface backed by |widget| to ensure Wayland does not present those // to the surface backed by |widget| to ensure Wayland does not present those
...@@ -144,6 +126,10 @@ class WaylandBufferManagerHost : public ozone::mojom::WaylandBufferManagerHost, ...@@ -144,6 +126,10 @@ class WaylandBufferManagerHost : public ozone::mojom::WaylandBufferManagerHost,
// Returns the anonymously created WaylandBuffer. // Returns the anonymously created WaylandBuffer.
std::unique_ptr<WaylandBuffer> PassAnonymousWlBuffer(uint32_t buffer_id); std::unique_ptr<WaylandBuffer> PassAnonymousWlBuffer(uint32_t buffer_id);
protected:
// Clears the state of the |buffer_manager_|.
void ClearInternalState();
private: private:
// This is an internal representation of a real surface, which holds a pointer // This is an internal representation of a real surface, which holds a pointer
// to WaylandWindow. Also, this object holds buffers, frame callbacks and // to WaylandWindow. Also, this object holds buffers, frame callbacks and
...@@ -175,17 +161,16 @@ class WaylandBufferManagerHost : public ozone::mojom::WaylandBufferManagerHost, ...@@ -175,17 +161,16 @@ class WaylandBufferManagerHost : public ozone::mojom::WaylandBufferManagerHost,
void OnCreateBufferComplete(uint32_t buffer_id, void OnCreateBufferComplete(uint32_t buffer_id,
wl::Object<struct wl_buffer> new_buffer); wl::Object<struct wl_buffer> new_buffer);
// Tells the |buffer_manager_gpu_ptr_| the result of a swap call and provides // Notifies about the swap result and the presentation feedback.
// it with the presentation feedback. virtual void OnSubmission(gfx::AcceleratedWidget widget,
void OnSubmission(gfx::AcceleratedWidget widget, uint32_t buffer_id,
uint32_t buffer_id, const gfx::SwapResult& swap_result) = 0;
const gfx::SwapResult& swap_result); virtual void OnPresentation(gfx::AcceleratedWidget widget,
void OnPresentation(gfx::AcceleratedWidget widget, uint32_t buffer_id,
uint32_t buffer_id, const gfx::PresentationFeedback& feedback) = 0;
const gfx::PresentationFeedback& feedback);
// Terminates the GPU process on invalid data received // Notifies invalid data has been received.
void TerminateGpuProcess(); virtual void OnError(std::string error_message) = 0;
bool DestroyAnonymousBuffer(uint32_t buffer_id); bool DestroyAnonymousBuffer(uint32_t buffer_id);
...@@ -195,15 +180,7 @@ class WaylandBufferManagerHost : public ozone::mojom::WaylandBufferManagerHost, ...@@ -195,15 +180,7 @@ class WaylandBufferManagerHost : public ozone::mojom::WaylandBufferManagerHost,
std::string error_message_; std::string error_message_;
// Non-owned pointer to the main connection. // Non-owned pointer to the main connection.
WaylandConnection* const connection_; WaylandConnection* connection_ = nullptr;
mojo::AssociatedRemote<ozone::mojom::WaylandBufferManagerGpu>
buffer_manager_gpu_associated_;
mojo::Receiver<ozone::mojom::WaylandBufferManagerHost> receiver_;
// A callback, which is used to terminate a GPU process in case of invalid
// data sent by the GPU to the browser process.
base::OnceCallback<void(std::string)> terminate_gpu_cb_;
// Contains anonymous buffers aka buffers that are not attached to any of the // Contains anonymous buffers aka buffers that are not attached to any of the
// existing surfaces and that will be mapped to surfaces later. Typically // existing surfaces and that will be mapped to surfaces later. Typically
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_impl.h"
#include "base/message_loop/message_loop_current.h"
namespace ui {
WaylandBufferManagerHostImpl::WaylandBufferManagerHostImpl()
: receiver_(this) {}
WaylandBufferManagerHostImpl::~WaylandBufferManagerHostImpl() = default;
void WaylandBufferManagerHostImpl::SetTerminateGpuCallback(
base::OnceCallback<void(std::string)> terminate_callback) {
terminate_gpu_cb_ = std::move(terminate_callback);
}
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost>
WaylandBufferManagerHostImpl::BindInterface() {
DCHECK(!receiver_.is_bound());
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost>
buffer_manager_host;
receiver_.Bind(buffer_manager_host.InitWithNewPipeAndPassReceiver());
return buffer_manager_host;
}
void WaylandBufferManagerHostImpl::OnChannelDestroyed() {
buffer_manager_gpu_associated_.reset();
receiver_.reset();
ClearInternalState();
}
void WaylandBufferManagerHostImpl::SetWaylandBufferManagerGpu(
mojo::PendingAssociatedRemote<ozone::mojom::WaylandBufferManagerGpu>
buffer_manager_gpu_associated) {
buffer_manager_gpu_associated_.Bind(std::move(buffer_manager_gpu_associated));
}
void WaylandBufferManagerHostImpl::CreateDmabufBasedBuffer(
mojo::PlatformHandle dmabuf_fd,
const gfx::Size& size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t format,
uint32_t planes_count,
uint32_t buffer_id) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
CreateBufferDmabuf(dmabuf_fd.TakeFD(), size, strides, offsets, modifiers,
format, planes_count, buffer_id);
}
void WaylandBufferManagerHostImpl::CreateShmBasedBuffer(
mojo::PlatformHandle shm_fd,
uint64_t length,
const gfx::Size& size,
uint32_t buffer_id) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
CreateBufferShm(shm_fd.TakeFD(), length, size, buffer_id);
}
void WaylandBufferManagerHostImpl::CommitBuffer(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
CommitBufferWithId(widget, buffer_id, damage_region);
}
void WaylandBufferManagerHostImpl::DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DestroyBufferWithId(widget, buffer_id);
}
void WaylandBufferManagerHostImpl::OnSubmission(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DCHECK(buffer_manager_gpu_associated_);
buffer_manager_gpu_associated_->OnSubmission(widget, buffer_id, swap_result);
}
void WaylandBufferManagerHostImpl::OnPresentation(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DCHECK(buffer_manager_gpu_associated_);
buffer_manager_gpu_associated_->OnPresentation(widget, buffer_id, feedback);
}
void WaylandBufferManagerHostImpl::OnError(std::string error_message) {
DCHECK(!error_message.empty());
std::move(terminate_gpu_cb_).Run(std::move(error_message));
// The GPU process' failure results in calling ::OnChannelDestroyed.
}
} // namespace ui
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_IMPL_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_IMPL_H_
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/public/mojom/wayland/wayland_buffer_manager.mojom.h"
namespace ui {
// Implementation of WaylandBufferManagerHost that communicates with
// WaylandBufferManagerGpu through mojo. Can be used in both single and multi
// process mode.
class WaylandBufferManagerHostImpl
: public ozone::mojom::WaylandBufferManagerHost,
public WaylandBufferManagerHost {
public:
WaylandBufferManagerHostImpl();
~WaylandBufferManagerHostImpl() override;
WaylandBufferManagerHostImpl(const WaylandBufferManagerHostImpl& host) =
delete;
WaylandBufferManagerHostImpl& operator=(
const WaylandBufferManagerHostImpl& host) = delete;
void SetTerminateGpuCallback(
base::OnceCallback<void(std::string)> terminate_gpu_cb);
// Returns bound pointer to own mojo interface.
mojo::PendingRemote<ozone::mojom::WaylandBufferManagerHost> BindInterface();
// Unbinds the interface and clears the state of the |buffer_manager_|. Used
// only when the GPU channel, which uses the mojo pipe to this interface, is
// destroyed.
void OnChannelDestroyed();
// ozone::mojom::WaylandBufferManagerHost overrides:
//
// These overridden methods below are invoked by the GPU when hardware
// accelerated rendering is used.
void SetWaylandBufferManagerGpu(
mojo::PendingAssociatedRemote<ozone::mojom::WaylandBufferManagerGpu>
buffer_manager_gpu_associated) override;
//
// Check comments in the
// ui/ozone/public/mojom/wayland/wayland_connection.mojom.
void CreateDmabufBasedBuffer(mojo::PlatformHandle dmabuf_fd,
const gfx::Size& size,
const std::vector<uint32_t>& strides,
const std::vector<uint32_t>& offsets,
const std::vector<uint64_t>& modifiers,
uint32_t format,
uint32_t planes_count,
uint32_t buffer_id) override;
void CreateShmBasedBuffer(mojo::PlatformHandle shm_fd,
uint64_t length,
const gfx::Size& size,
uint32_t buffer_id) override;
void DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) override;
void CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) override;
private:
// WaylandBufferManagerHost overrides:
void OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result) override;
void OnPresentation(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) override;
void OnError(std::string error_message) override;
mojo::AssociatedRemote<ozone::mojom::WaylandBufferManagerGpu>
buffer_manager_gpu_associated_;
mojo::Receiver<ozone::mojom::WaylandBufferManagerHost> receiver_;
// A callback, which is used to terminate a GPU process in case of invalid
// data sent by the GPU to the browser process.
base::OnceCallback<void(std::string)> terminate_gpu_cb_;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_IMPL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_single_process.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
namespace ui {
WaylandBufferManagerHostSingleProcess::WaylandBufferManagerHostSingleProcess() =
default;
WaylandBufferManagerHostSingleProcess::
~WaylandBufferManagerHostSingleProcess() = default;
void WaylandBufferManagerHostSingleProcess::
SetWaylandBufferManagerGpuSingleProcess(
WaylandBufferManagerGpu* manager_gpu) {
single_proc_manager_gpu_ = manager_gpu;
}
void WaylandBufferManagerHostSingleProcess::OnSubmission(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result) {
DCHECK(single_proc_manager_gpu_);
single_proc_manager_gpu_->OnBufferSubmitted(widget, buffer_id, swap_result);
}
void WaylandBufferManagerHostSingleProcess::OnPresentation(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) {
DCHECK(single_proc_manager_gpu_);
single_proc_manager_gpu_->OnBufferPresented(widget, buffer_id, feedback);
}
void WaylandBufferManagerHostSingleProcess::OnError(std::string error_message) {
LOG(FATAL) << error_message;
}
} // namespace ui
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_SINGLE_PROCESS_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_SINGLE_PROCESS_H_
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
namespace ui {
class WaylandBufferManagerGpu;
// Same as WaylandBufferManagerHostImpl, but that uses direct connection with
// the WaylandBufferManagerGpu if mojo is not available.
class WaylandBufferManagerHostSingleProcess : public WaylandBufferManagerHost {
public:
WaylandBufferManagerHostSingleProcess();
~WaylandBufferManagerHostSingleProcess() override;
WaylandBufferManagerHostSingleProcess(
const WaylandBufferManagerHostSingleProcess& host) = delete;
WaylandBufferManagerHostSingleProcess& operator=(
const WaylandBufferManagerHostSingleProcess& host) = delete;
// Sets a pointer to WaylandBufferManagerGpu, which is an instance of
// WaylandBufferManagerGpuSingleProcess.
void SetWaylandBufferManagerGpuSingleProcess(
WaylandBufferManagerGpu* manager_gpu);
private:
// WaylandBufferManagerHost overrides:
void OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result) override;
void OnPresentation(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) override;
void OnError(std::string error_message) override;
WaylandBufferManagerGpu* single_proc_manager_gpu_ = nullptr;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_SINGLE_PROCESS_H_
...@@ -45,7 +45,9 @@ constexpr uint32_t kMinWlDrmVersion = 2; ...@@ -45,7 +45,9 @@ constexpr uint32_t kMinWlDrmVersion = 2;
constexpr uint32_t kMinWlOutputVersion = 2; constexpr uint32_t kMinWlOutputVersion = 2;
} // namespace } // namespace
WaylandConnection::WaylandConnection() : controller_(FROM_HERE) {} WaylandConnection::WaylandConnection(
WaylandBufferManagerHost* buffer_manager_host)
: buffer_manager_host_(buffer_manager_host), controller_(FROM_HERE) {}
WaylandConnection::~WaylandConnection() = default; WaylandConnection::~WaylandConnection() = default;
...@@ -73,8 +75,6 @@ bool WaylandConnection::Initialize() { ...@@ -73,8 +75,6 @@ bool WaylandConnection::Initialize() {
wl_display_roundtrip(display_.get()); wl_display_roundtrip(display_.get());
} }
buffer_manager_host_ = std::make_unique<WaylandBufferManagerHost>(this);
if (!compositor_) { if (!compositor_) {
LOG(ERROR) << "No wl_compositor object"; LOG(ERROR) << "No wl_compositor object";
return false; return false;
......
...@@ -41,7 +41,7 @@ class WaylandShm; ...@@ -41,7 +41,7 @@ class WaylandShm;
class WaylandConnection : public PlatformEventSource, class WaylandConnection : public PlatformEventSource,
public base::MessagePumpForUI::FdWatcher { public base::MessagePumpForUI::FdWatcher {
public: public:
WaylandConnection(); explicit WaylandConnection(WaylandBufferManagerHost* buffer_manager_host);
~WaylandConnection() override; ~WaylandConnection() override;
bool Initialize(); bool Initialize();
...@@ -96,7 +96,7 @@ class WaylandConnection : public PlatformEventSource, ...@@ -96,7 +96,7 @@ class WaylandConnection : public PlatformEventSource,
} }
WaylandBufferManagerHost* buffer_manager_host() const { WaylandBufferManagerHost* buffer_manager_host() const {
return buffer_manager_host_.get(); return buffer_manager_host_;
} }
WaylandZwpLinuxDmabuf* zwp_dmabuf() const { return zwp_dmabuf_.get(); } WaylandZwpLinuxDmabuf* zwp_dmabuf() const { return zwp_dmabuf_.get(); }
...@@ -200,7 +200,8 @@ class WaylandConnection : public PlatformEventSource, ...@@ -200,7 +200,8 @@ class WaylandConnection : public PlatformEventSource,
std::unique_ptr<WaylandZwpLinuxDmabuf> zwp_dmabuf_; std::unique_ptr<WaylandZwpLinuxDmabuf> zwp_dmabuf_;
std::unique_ptr<WaylandDrm> drm_; std::unique_ptr<WaylandDrm> drm_;
std::unique_ptr<WaylandShm> shm_; std::unique_ptr<WaylandShm> shm_;
std::unique_ptr<WaylandBufferManagerHost> buffer_manager_host_;
WaylandBufferManagerHost* const buffer_manager_host_;
std::unique_ptr<GtkPrimarySelectionDeviceManager> std::unique_ptr<GtkPrimarySelectionDeviceManager>
primary_selection_device_manager_; primary_selection_device_manager_;
......
...@@ -22,7 +22,7 @@ TEST(WaylandConnectionTest, Ping) { ...@@ -22,7 +22,7 @@ TEST(WaylandConnectionTest, Ping) {
base::test::SingleThreadTaskEnvironment::MainThreadType::UI); base::test::SingleThreadTaskEnvironment::MainThreadType::UI);
wl::TestWaylandServerThread server; wl::TestWaylandServerThread server;
ASSERT_TRUE(server.Start(kXdgVersionStable)); ASSERT_TRUE(server.Start(kXdgVersionStable));
WaylandConnection connection; WaylandConnection connection(nullptr);
ASSERT_TRUE(connection.Initialize()); ASSERT_TRUE(connection.Initialize());
connection.StartProcessingEvents(); connection.StartProcessingEvents();
......
...@@ -22,10 +22,13 @@ ...@@ -22,10 +22,13 @@
#include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/common/stub_overlay_manager.h"
#include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/common/wayland_util.h"
#include "ui/ozone/platform/wayland/gpu/drm_render_node_path_finder.h" #include "ui/ozone/platform/wayland/gpu/drm_render_node_path_finder.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu_impl.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu_single_process.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h" #include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_connector.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_connector.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_impl.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_single_process.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_input_method_context_factory.h" #include "ui/ozone/platform/wayland/host/wayland_input_method_context_factory.h"
#include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h"
...@@ -176,19 +179,37 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -176,19 +179,37 @@ class OzonePlatformWayland : public OzonePlatform {
#endif #endif
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
keyboard_layout_engine_.get()); keyboard_layout_engine_.get());
connection_ = std::make_unique<WaylandConnection>();
if (args.single_process && !args.using_mojo) {
using_mojo_ = false;
buffer_manager_host_ =
std::make_unique<WaylandBufferManagerHostSingleProcess>();
} else if (args.using_mojo) {
auto buffer_manager_host_impl =
std::make_unique<WaylandBufferManagerHostImpl>();
buffer_manager_connector_ =
std::make_unique<WaylandBufferManagerConnector>(
buffer_manager_host_impl.get());
buffer_manager_host_ = std::move(buffer_manager_host_impl);
} else {
NOTREACHED() << "Not supported configuration: single_process="
<< args.single_process << "; using_mojo=" << args.using_mojo;
}
connection_ =
std::make_unique<WaylandConnection>(buffer_manager_host_.get());
if (!connection_->Initialize()) if (!connection_->Initialize())
LOG(FATAL) << "Failed to initialize Wayland platform"; LOG(FATAL) << "Failed to initialize Wayland platform";
buffer_manager_connector_ = std::make_unique<WaylandBufferManagerConnector>( buffer_manager_host_->SetWaylandConnection(connection_.get());
connection_->buffer_manager_host()); supported_buffer_formats_ =
buffer_manager_host_->GetSupportedBufferFormats();
cursor_factory_ = std::make_unique<BitmapCursorFactoryOzone>(); cursor_factory_ = std::make_unique<BitmapCursorFactoryOzone>();
overlay_manager_ = std::make_unique<StubOverlayManager>(); overlay_manager_ = std::make_unique<StubOverlayManager>();
input_controller_ = CreateStubInputController(); input_controller_ = CreateStubInputController();
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
supported_buffer_formats_ =
connection_->buffer_manager_host()->GetSupportedBufferFormats();
#if BUILDFLAG(USE_GTK) #if BUILDFLAG(USE_GTK)
DCHECK(!GtkUiDelegate::instance()); DCHECK(!GtkUiDelegate::instance());
gtk_ui_delegate_ = gtk_ui_delegate_ =
...@@ -198,7 +219,23 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -198,7 +219,23 @@ class OzonePlatformWayland : public OzonePlatform {
} }
void InitializeGPU(const InitParams& args) override { void InitializeGPU(const InitParams& args) override {
buffer_manager_ = std::make_unique<WaylandBufferManagerGpu>(); if (args.single_process && !args.using_mojo) {
// This must be set during InitializeUI call.
DCHECK(!using_mojo_);
auto buffer_manager_single_process =
std::make_unique<WaylandBufferManagerGpuSingleProcess>(
buffer_manager_host_.get());
static_cast<WaylandBufferManagerHostSingleProcess*>(
buffer_manager_host_.get())
->SetWaylandBufferManagerGpuSingleProcess(
buffer_manager_single_process.get());
buffer_manager_ = std::move(buffer_manager_single_process);
} else if (args.using_mojo) {
buffer_manager_ = std::make_unique<WaylandBufferManagerGpuImpl>();
} else {
NOTREACHED() << "Not supported configuration: single_process="
<< args.single_process << "; using_mojo=" << args.using_mojo;
}
surface_factory_ = std::make_unique<WaylandSurfaceFactory>( surface_factory_ = std::make_unique<WaylandSurfaceFactory>(
connection_.get(), buffer_manager_.get()); connection_.get(), buffer_manager_.get());
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
...@@ -224,6 +261,9 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -224,6 +261,9 @@ class OzonePlatformWayland : public OzonePlatform {
} }
void AddInterfaces(mojo::BinderMap* binders) override { void AddInterfaces(mojo::BinderMap* binders) override {
if (!using_mojo_)
return;
binders->Add<ozone::mojom::WaylandBufferManagerGpu>( binders->Add<ozone::mojom::WaylandBufferManagerGpu>(
base::BindRepeating( base::BindRepeating(
&OzonePlatformWayland::CreateWaylandBufferManagerGpuBinding, &OzonePlatformWayland::CreateWaylandBufferManagerGpuBinding,
...@@ -233,7 +273,8 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -233,7 +273,8 @@ class OzonePlatformWayland : public OzonePlatform {
void CreateWaylandBufferManagerGpuBinding( void CreateWaylandBufferManagerGpuBinding(
mojo::PendingReceiver<ozone::mojom::WaylandBufferManagerGpu> receiver) { mojo::PendingReceiver<ozone::mojom::WaylandBufferManagerGpu> receiver) {
buffer_manager_->AddBindingWaylandBufferManagerGpu(std::move(receiver)); static_cast<WaylandBufferManagerGpuImpl*>(buffer_manager_.get())
->AddBindingWaylandBufferManagerGpu(std::move(receiver));
} }
private: private:
...@@ -251,6 +292,7 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -251,6 +292,7 @@ class OzonePlatformWayland : public OzonePlatform {
std::unique_ptr<WaylandInputMethodContextFactory> std::unique_ptr<WaylandInputMethodContextFactory>
input_method_context_factory_; input_method_context_factory_;
std::unique_ptr<WaylandBufferManagerConnector> buffer_manager_connector_; std::unique_ptr<WaylandBufferManagerConnector> buffer_manager_connector_;
std::unique_ptr<WaylandBufferManagerHost> buffer_manager_host_;
// Objects, which solely live in the GPU process. // Objects, which solely live in the GPU process.
std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_; std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_;
...@@ -267,6 +309,8 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -267,6 +309,8 @@ class OzonePlatformWayland : public OzonePlatform {
std::unique_ptr<GtkUiDelegateWayland> gtk_ui_delegate_; std::unique_ptr<GtkUiDelegateWayland> gtk_ui_delegate_;
#endif #endif
bool using_mojo_ = true;
DISALLOW_COPY_AND_ASSIGN(OzonePlatformWayland); DISALLOW_COPY_AND_ASSIGN(OzonePlatformWayland);
}; };
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/scoped_keyboard_layout_engine.h" #include "ui/events/ozone/layout/scoped_keyboard_layout_engine.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu_impl.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu_single_process.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_impl.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_single_process.h"
#include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_screen.h" #include "ui/ozone/platform/wayland/host/wayland_screen.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/mock_surface.h"
...@@ -33,15 +37,30 @@ WaylandTest::WaylandTest() ...@@ -33,15 +37,30 @@ WaylandTest::WaylandTest()
#endif #endif
scoped_keyboard_layout_engine_ = std::make_unique<ScopedKeyboardLayoutEngine>( scoped_keyboard_layout_engine_ = std::make_unique<ScopedKeyboardLayoutEngine>(
std::move(keyboard_layout_engine)); std::move(keyboard_layout_engine));
connection_ = std::make_unique<WaylandConnection>();
buffer_manager_gpu_ = std::make_unique<WaylandBufferManagerGpu>();
surface_factory_ = std::make_unique<WaylandSurfaceFactory>(
connection_.get(), buffer_manager_gpu_.get());
} }
WaylandTest::~WaylandTest() {} WaylandTest::~WaylandTest() {}
void WaylandTest::SetUp() { void WaylandTest::SetUp() {
if (use_mojo_) {
buffer_manager_host_ = std::make_unique<WaylandBufferManagerHostImpl>();
buffer_manager_gpu_ = std::make_unique<WaylandBufferManagerGpuImpl>();
} else {
buffer_manager_host_ =
std::make_unique<WaylandBufferManagerHostSingleProcess>();
buffer_manager_gpu_ =
std::make_unique<WaylandBufferManagerGpuSingleProcess>(
buffer_manager_host_.get());
static_cast<WaylandBufferManagerHostSingleProcess*>(
buffer_manager_host_.get())
->SetWaylandBufferManagerGpuSingleProcess(buffer_manager_gpu_.get());
}
connection_ = std::make_unique<WaylandConnection>(buffer_manager_host_.get());
buffer_manager_host_->SetWaylandConnection(connection_.get());
surface_factory_ = std::make_unique<WaylandSurfaceFactory>(
connection_.get(), buffer_manager_gpu_.get());
ASSERT_TRUE(server_.Start(GetParam())); ASSERT_TRUE(server_.Start(GetParam()));
ASSERT_TRUE(connection_->Initialize()); ASSERT_TRUE(connection_->Initialize());
screen_ = connection_->wayland_output_manager()->CreateWaylandScreen( screen_ = connection_->wayland_output_manager()->CreateWaylandScreen(
...@@ -86,4 +105,8 @@ void WaylandTest::Sync() { ...@@ -86,4 +105,8 @@ void WaylandTest::Sync() {
server_.Pause(); server_.Pause();
} }
void WaylandTest::SetInitializeWithMojo(bool use_mojo) {
use_mojo_ = use_mojo;
}
} // namespace ui } // namespace ui
...@@ -46,6 +46,8 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> { ...@@ -46,6 +46,8 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> {
void Sync(); void Sync();
void SetInitializeWithMojo(bool use_mojo);
protected: protected:
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
...@@ -55,6 +57,7 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> { ...@@ -55,6 +57,7 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> {
MockPlatformWindowDelegate delegate_; MockPlatformWindowDelegate delegate_;
std::unique_ptr<ScopedKeyboardLayoutEngine> scoped_keyboard_layout_engine_; std::unique_ptr<ScopedKeyboardLayoutEngine> scoped_keyboard_layout_engine_;
std::unique_ptr<WaylandSurfaceFactory> surface_factory_; std::unique_ptr<WaylandSurfaceFactory> surface_factory_;
std::unique_ptr<WaylandBufferManagerHost> buffer_manager_host_;
std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_gpu_; std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_gpu_;
std::unique_ptr<WaylandConnection> connection_; std::unique_ptr<WaylandConnection> connection_;
std::unique_ptr<WaylandScreen> screen_; std::unique_ptr<WaylandScreen> screen_;
...@@ -64,6 +67,8 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> { ...@@ -64,6 +67,8 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> {
private: private:
bool initialized_ = false; bool initialized_ = false;
bool use_mojo_ = false;
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
XkbEvdevCodes xkb_evdev_code_converter_; XkbEvdevCodes xkb_evdev_code_converter_;
#endif #endif
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu_impl.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host_impl.h"
#include <drm_fourcc.h> #include <drm_fourcc.h>
#include <memory> #include <memory>
...@@ -69,22 +69,28 @@ class MockSurfaceGpu : public WaylandSurfaceGpu { ...@@ -69,22 +69,28 @@ class MockSurfaceGpu : public WaylandSurfaceGpu {
} // namespace } // namespace
// Exercises WaylandBufferManagerGpu<->Host with mojo.
class WaylandBufferManagerTest : public WaylandTest { class WaylandBufferManagerTest : public WaylandTest {
public: public:
WaylandBufferManagerTest() = default; WaylandBufferManagerTest() = default;
~WaylandBufferManagerTest() override = default; ~WaylandBufferManagerTest() override = default;
void SetUp() override { void SetUp() override {
// Instructs to create mojo based impl of buffer managers.
WaylandTest::SetInitializeWithMojo(true);
WaylandTest::SetUp(); WaylandTest::SetUp();
manager_host_ = connection_->buffer_manager_host(); manager_host_ = static_cast<WaylandBufferManagerHostImpl*>(
connection_->buffer_manager_host());
EXPECT_TRUE(manager_host_); EXPECT_TRUE(manager_host_);
// Use the helper methods below, which automatically set the termination // Use the helper methods below, which automatically set the termination
// callback and bind the interface again if the manager failed. // callback and bind the interface again if the manager failed.
manager_host_->SetTerminateGpuCallback(callback_.Get()); manager_host_->SetTerminateGpuCallback(callback_.Get());
auto interface_ptr = manager_host_->BindInterface(); auto interface_ptr = manager_host_->BindInterface();
buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, false); auto* manager_gpu_impl =
static_cast<WaylandBufferManagerGpuImpl*>(buffer_manager_gpu_.get());
manager_gpu_impl->Initialize(std::move(interface_ptr), {}, false);
} }
protected: protected:
...@@ -118,9 +124,12 @@ class WaylandBufferManagerTest : public WaylandTest { ...@@ -118,9 +124,12 @@ class WaylandBufferManagerTest : public WaylandTest {
auto interface_ptr = manager_host_->BindInterface(); auto interface_ptr = manager_host_->BindInterface();
// Recreate the gpu side manager (the production code does the // Recreate the gpu side manager (the production code does the
// same). // same).
buffer_manager_gpu_ = std::make_unique<WaylandBufferManagerGpu>(); auto buffer_manager_gpu_impl =
buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, std::make_unique<WaylandBufferManagerGpuImpl>();
false); buffer_manager_gpu_impl->Initialize(std::move(interface_ptr), {},
false);
buffer_manager_gpu_ = std::move(buffer_manager_gpu_impl);
})); }));
} }
} }
...@@ -203,7 +212,8 @@ class WaylandBufferManagerTest : public WaylandTest { ...@@ -203,7 +212,8 @@ class WaylandBufferManagerTest : public WaylandTest {
} }
MockTerminateGpuCallback callback_; MockTerminateGpuCallback callback_;
WaylandBufferManagerHost* manager_host_; WaylandBufferManagerHostImpl* manager_host_;
WaylandBufferManagerGpuImpl* manager_gpu_;
private: private:
DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerTest); DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerTest);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment