Commit 9b5e8436 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

[ozone/wayland] Establish BufferManagerGpu and BufferManagetHost pipe.

Previously, the WaylandConnection was a proxy between the
clients of the WaylandBufferManager and the manager itself.

This was a redundant functionality, and it was decided to
avoid proxying.

The following changes have been made in this cl:
Renamed:
 * WaylandBufferManager => WaylandBufferManagerHost
 * WaylandConnectionProxy => WaylandBufferManagerGpu
 * WaylandConnectionConnector => WaylandBufferManagerConnector

Code changes:

The WaylandConnection no longer forwards calls to the
WaylandBufferManager. Instead, the WaylandBufferManagerHost
and the WaylandBufferManagerGpu have an associated mojo
connection, and are able to speak to each other without
a proxy in between. This is more logical and makes
the WaylandConnection class be less overloaded with
different functionality.

The tests have also been rewritten, and helper methods
have been added.

Bug: 947411
Change-Id: I9ffd162f8459705ae22f55a9f1b1e7caa1567986
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617359Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#664678}
parent 507c502e
...@@ -25,7 +25,7 @@ const service_manager::Manifest& GetContentGpuManifest() { ...@@ -25,7 +25,7 @@ const service_manager::Manifest& GetContentGpuManifest() {
"IPC.mojom.ChannelBootstrap", "IPC.mojom.ChannelBootstrap",
"ui.ozone.mojom.DeviceCursor", "ui.ozone.mojom.DeviceCursor",
"ui.ozone.mojom.DrmDevice", "ui.ozone.mojom.DrmDevice",
"ui.ozone.mojom.WaylandConnectionClient", "ui.ozone.mojom.WaylandBufferManagerGpu",
"ui.mojom.ScenicGpuService", "ui.mojom.ScenicGpuService",
"viz.mojom.CompositingModeReporter", "viz.mojom.CompositingModeReporter",
"viz.mojom.VizMain", "viz.mojom.VizMain",
......
...@@ -24,20 +24,20 @@ source_set("wayland") { ...@@ -24,20 +24,20 @@ source_set("wayland") {
"gpu/drm_render_node_path_finder.h", "gpu/drm_render_node_path_finder.h",
"gpu/gl_surface_wayland.cc", "gpu/gl_surface_wayland.cc",
"gpu/gl_surface_wayland.h", "gpu/gl_surface_wayland.h",
"gpu/wayland_buffer_manager_gpu.cc",
"gpu/wayland_buffer_manager_gpu.h",
"gpu/wayland_canvas_surface.cc", "gpu/wayland_canvas_surface.cc",
"gpu/wayland_canvas_surface.h", "gpu/wayland_canvas_surface.h",
"gpu/wayland_connection_proxy.cc",
"gpu/wayland_connection_proxy.h",
"gpu/wayland_surface_factory.cc", "gpu/wayland_surface_factory.cc",
"gpu/wayland_surface_factory.h", "gpu/wayland_surface_factory.h",
"host/wayland_buffer_manager.cc", "host/wayland_buffer_manager_connector.cc",
"host/wayland_buffer_manager.h", "host/wayland_buffer_manager_connector.h",
"host/wayland_buffer_manager_host.cc",
"host/wayland_buffer_manager_host.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",
"host/wayland_connection.h", "host/wayland_connection.h",
"host/wayland_connection_connector.cc",
"host/wayland_connection_connector.h",
"host/wayland_cursor.cc", "host/wayland_cursor.cc",
"host/wayland_cursor.h", "host/wayland_cursor.h",
"host/wayland_cursor_position.cc", "host/wayland_cursor_position.cc",
...@@ -237,7 +237,7 @@ source_set("wayland_unittests") { ...@@ -237,7 +237,7 @@ source_set("wayland_unittests") {
sources = [ sources = [
"gpu/wayland_surface_factory_unittest.cc", "gpu/wayland_surface_factory_unittest.cc",
"host/wayland_buffer_manager_unittest.cc", "host/wayland_buffer_manager_host_unittest.cc",
"host/wayland_connection_unittest.cc", "host/wayland_connection_unittest.cc",
"host/wayland_data_device_unittest.cc", "host/wayland_data_device_unittest.cc",
"host/wayland_input_method_context_unittest.cc", "host/wayland_input_method_context_unittest.cc",
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "ui/ozone/common/linux/drm_util_linux.h" #include "ui/ozone/common/linux/drm_util_linux.h"
#include "ui/ozone/common/linux/gbm_device.h" #include "ui/ozone/common/linux/gbm_device.h"
#include "ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h" #include "ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h"
#include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h" #include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h"
#include "ui/ozone/public/overlay_plane.h" #include "ui/ozone/public/overlay_plane.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
namespace ui { namespace ui {
GbmPixmapWayland::GbmPixmapWayland(WaylandSurfaceFactory* surface_manager, GbmPixmapWayland::GbmPixmapWayland(WaylandSurfaceFactory* surface_manager,
WaylandConnectionProxy* connection, WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget) gfx::AcceleratedWidget widget)
: surface_manager_(surface_manager), : surface_manager_(surface_manager),
connection_(connection), buffer_manager_(buffer_manager),
widget_(widget) {} widget_(widget) {}
GbmPixmapWayland::~GbmPixmapWayland() { GbmPixmapWayland::~GbmPixmapWayland() {
if (gbm_bo_ && widget_ != gfx::kNullAcceleratedWidget) if (gbm_bo_ && widget_ != gfx::kNullAcceleratedWidget)
connection_->DestroyBuffer(widget_, GetUniqueId()); buffer_manager_->DestroyBuffer(widget_, GetUniqueId());
} }
bool GbmPixmapWayland::InitializeBuffer(gfx::Size size, bool GbmPixmapWayland::InitializeBuffer(gfx::Size size,
...@@ -45,7 +45,7 @@ bool GbmPixmapWayland::InitializeBuffer(gfx::Size size, ...@@ -45,7 +45,7 @@ bool GbmPixmapWayland::InitializeBuffer(gfx::Size size,
gfx::BufferUsage usage) { gfx::BufferUsage usage) {
TRACE_EVENT0("wayland", "GbmPixmapWayland::InitializeBuffer"); TRACE_EVENT0("wayland", "GbmPixmapWayland::InitializeBuffer");
if (!connection_->gbm_device()) if (!buffer_manager_->gbm_device())
return false; return false;
uint32_t flags = 0; uint32_t flags = 0;
...@@ -74,7 +74,8 @@ bool GbmPixmapWayland::InitializeBuffer(gfx::Size size, ...@@ -74,7 +74,8 @@ bool GbmPixmapWayland::InitializeBuffer(gfx::Size size,
} }
const uint32_t fourcc_format = GetFourCCFormatFromBufferFormat(format); const uint32_t fourcc_format = GetFourCCFormatFromBufferFormat(format);
gbm_bo_ = connection_->gbm_device()->CreateBuffer(fourcc_format, size, flags); gbm_bo_ =
buffer_manager_->gbm_device()->CreateBuffer(fourcc_format, size, flags);
if (!gbm_bo_) { if (!gbm_bo_) {
LOG(ERROR) << "Cannot create bo with format= " LOG(ERROR) << "Cannot create bo with format= "
<< gfx::BufferFormatToString(format) << " and usage " << gfx::BufferFormatToString(format) << " and usage "
...@@ -182,7 +183,7 @@ void GbmPixmapWayland::CreateDmabufBasedBuffer() { ...@@ -182,7 +183,7 @@ void GbmPixmapWayland::CreateDmabufBasedBuffer() {
return; return;
} }
// Asks Wayland to create a wl_buffer based on the |file| fd. // Asks Wayland to create a wl_buffer based on the |file| fd.
connection_->CreateDmabufBasedBuffer( buffer_manager_->CreateDmabufBasedBuffer(
widget_, std::move(fd), GetBufferSize(), strides, offsets, modifiers, widget_, std::move(fd), GetBufferSize(), strides, offsets, modifiers,
gbm_bo_->GetFormat(), plane_count, GetUniqueId()); gbm_bo_->GetFormat(), plane_count, GetUniqueId());
} }
......
...@@ -18,12 +18,12 @@ ...@@ -18,12 +18,12 @@
namespace ui { namespace ui {
class WaylandSurfaceFactory; class WaylandSurfaceFactory;
class WaylandConnectionProxy; class WaylandBufferManagerGpu;
class GbmPixmapWayland : public gfx::NativePixmap { class GbmPixmapWayland : public gfx::NativePixmap {
public: public:
GbmPixmapWayland(WaylandSurfaceFactory* surface_manager, GbmPixmapWayland(WaylandSurfaceFactory* surface_manager,
WaylandConnectionProxy* connection, WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget); gfx::AcceleratedWidget widget);
// Creates a buffer object and initializes the pixmap buffer. // Creates a buffer object and initializes the pixmap buffer.
...@@ -61,7 +61,7 @@ class GbmPixmapWayland : public gfx::NativePixmap { ...@@ -61,7 +61,7 @@ class GbmPixmapWayland : public gfx::NativePixmap {
WaylandSurfaceFactory* const surface_manager_; WaylandSurfaceFactory* const surface_manager_;
// Represents a connection to Wayland. // Represents a connection to Wayland.
WaylandConnectionProxy* const connection_; WaylandBufferManagerGpu* const buffer_manager_;
// Represents widget this pixmap backs. // Represents widget this pixmap backs.
const gfx::AcceleratedWidget widget_; const gfx::AcceleratedWidget widget_;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "ui/gfx/gpu_fence.h" #include "ui/gfx/gpu_fence.h"
#include "ui/ozone/common/egl_util.h" #include "ui/ozone/common/egl_util.h"
#include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h" #include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h"
namespace ui { namespace ui {
...@@ -28,11 +28,11 @@ void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { ...@@ -28,11 +28,11 @@ void WaitForFence(EGLDisplay display, EGLSyncKHR fence) {
GbmSurfacelessWayland::GbmSurfacelessWayland( GbmSurfacelessWayland::GbmSurfacelessWayland(
WaylandSurfaceFactory* surface_factory, WaylandSurfaceFactory* surface_factory,
WaylandConnectionProxy* connection, WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget) gfx::AcceleratedWidget widget)
: SurfacelessEGL(gfx::Size()), : SurfacelessEGL(gfx::Size()),
surface_factory_(surface_factory), surface_factory_(surface_factory),
connection_(connection), buffer_manager_(buffer_manager),
widget_(widget), widget_(widget),
has_implicit_external_sync_( has_implicit_external_sync_(
HasEGLExtension("EGL_ARM_implicit_external_sync")), HasEGLExtension("EGL_ARM_implicit_external_sync")),
...@@ -212,7 +212,7 @@ void GbmSurfacelessWayland::SubmitFrame() { ...@@ -212,7 +212,7 @@ void GbmSurfacelessWayland::SubmitFrame() {
} }
submitted_frame_->buffer_id = planes_.back().pixmap->GetUniqueId(); submitted_frame_->buffer_id = planes_.back().pixmap->GetUniqueId();
connection_->CommitBuffer(widget_, submitted_frame_->buffer_id, buffer_manager_->CommitBuffer(widget_, submitted_frame_->buffer_id,
submitted_frame_->damage_region_); submitted_frame_->damage_region_);
planes_.clear(); planes_.clear();
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace ui { namespace ui {
class WaylandConnectionProxy; class WaylandBufferManagerGpu;
class WaylandSurfaceFactory; class WaylandSurfaceFactory;
// A GLSurface for Wayland Ozone platform that uses surfaceless drawing. Drawing // A GLSurface for Wayland Ozone platform that uses surfaceless drawing. Drawing
...@@ -26,7 +26,7 @@ class WaylandSurfaceFactory; ...@@ -26,7 +26,7 @@ class WaylandSurfaceFactory;
class GbmSurfacelessWayland : public gl::SurfacelessEGL { class GbmSurfacelessWayland : public gl::SurfacelessEGL {
public: public:
GbmSurfacelessWayland(WaylandSurfaceFactory* surface_factory, GbmSurfacelessWayland(WaylandSurfaceFactory* surface_factory,
WaylandConnectionProxy* connection, WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget); gfx::AcceleratedWidget widget);
void QueueOverlayPlane(OverlayPlane plane); void QueueOverlayPlane(OverlayPlane plane);
...@@ -92,7 +92,7 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL { ...@@ -92,7 +92,7 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL {
void FenceRetired(PendingFrame* frame); void FenceRetired(PendingFrame* frame);
WaylandSurfaceFactory* const surface_factory_; WaylandSurfaceFactory* const surface_factory_;
WaylandConnectionProxy* const connection_; WaylandBufferManagerGpu* const buffer_manager_;
std::vector<OverlayPlane> planes_; std::vector<OverlayPlane> planes_;
// The native surface. Deleting this is allowed to free the EGLNativeWindow. // The native surface. Deleting this is allowed to free the EGLNativeWindow.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include <utility> #include <utility>
...@@ -16,21 +16,21 @@ ...@@ -16,21 +16,21 @@
namespace ui { namespace ui {
WaylandConnectionProxy::WaylandConnectionProxy(WaylandSurfaceFactory* factory) WaylandBufferManagerGpu::WaylandBufferManagerGpu(WaylandSurfaceFactory* factory)
: factory_(factory), : factory_(factory),
associated_binding_(this), associated_binding_(this),
gpu_thread_runner_(base::ThreadTaskRunnerHandle::Get()) {} gpu_thread_runner_(base::ThreadTaskRunnerHandle::Get()) {}
WaylandConnectionProxy::~WaylandConnectionProxy() = default; WaylandBufferManagerGpu::~WaylandBufferManagerGpu() = default;
void WaylandConnectionProxy::SetWaylandConnection( void WaylandBufferManagerGpu::SetWaylandBufferManagerHost(
ozone::mojom::WaylandConnectionPtr wc_ptr) { BufferManagerHostPtr buffer_manager_host_ptr) {
// This is an IO child thread. To satisfy our needs, we pass interface here // This is an IO child thread. To satisfy our needs, we pass interface here
// and bind it again on a gpu main thread, where buffer swaps happen. // and bind it again on a gpu main thread, where buffer swaps happen.
wc_ptr_info_ = wc_ptr.PassInterface(); buffer_manager_host_ptr_info_ = buffer_manager_host_ptr.PassInterface();
} }
void WaylandConnectionProxy::ResetGbmDevice() { void WaylandBufferManagerGpu::ResetGbmDevice() {
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
gbm_device_.reset(); gbm_device_.reset();
#else #else
...@@ -38,7 +38,7 @@ void WaylandConnectionProxy::ResetGbmDevice() { ...@@ -38,7 +38,7 @@ void WaylandConnectionProxy::ResetGbmDevice() {
#endif #endif
} }
void WaylandConnectionProxy::OnSubmission(gfx::AcceleratedWidget widget, void WaylandBufferManagerGpu::OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
gfx::SwapResult swap_result) { gfx::SwapResult swap_result) {
DCHECK(gpu_thread_runner_->BelongsToCurrentThread()); DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
...@@ -51,7 +51,7 @@ void WaylandConnectionProxy::OnSubmission(gfx::AcceleratedWidget widget, ...@@ -51,7 +51,7 @@ void WaylandConnectionProxy::OnSubmission(gfx::AcceleratedWidget widget,
surface->OnSubmission(buffer_id, swap_result); surface->OnSubmission(buffer_id, swap_result);
} }
void WaylandConnectionProxy::OnPresentation( void WaylandBufferManagerGpu::OnPresentation(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) { const gfx::PresentationFeedback& feedback) {
...@@ -65,7 +65,7 @@ void WaylandConnectionProxy::OnPresentation( ...@@ -65,7 +65,7 @@ void WaylandConnectionProxy::OnPresentation(
surface->OnPresentation(buffer_id, feedback); surface->OnPresentation(buffer_id, feedback);
} }
void WaylandConnectionProxy::CreateDmabufBasedBuffer( void WaylandBufferManagerGpu::CreateDmabufBasedBuffer(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
base::ScopedFD dmabuf_fd, base::ScopedFD dmabuf_fd,
gfx::Size size, gfx::Size size,
...@@ -80,29 +80,30 @@ void WaylandConnectionProxy::CreateDmabufBasedBuffer( ...@@ -80,29 +80,30 @@ void WaylandConnectionProxy::CreateDmabufBasedBuffer(
// ensure proper functionality. // ensure proper functionality.
gpu_thread_runner_->PostTask( gpu_thread_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&WaylandConnectionProxy::CreateDmabufBasedBufferInternal, base::BindOnce(&WaylandBufferManagerGpu::CreateDmabufBasedBufferInternal,
base::Unretained(this), widget, std::move(dmabuf_fd), base::Unretained(this), widget, std::move(dmabuf_fd),
std::move(size), std::move(strides), std::move(offsets), std::move(size), std::move(strides), std::move(offsets),
std::move(modifiers), current_format, planes_count, std::move(modifiers), current_format, planes_count,
buffer_id)); buffer_id));
} }
void WaylandConnectionProxy::CreateShmBasedBuffer(gfx::AcceleratedWidget widget, void WaylandBufferManagerGpu::CreateShmBasedBuffer(
gfx::AcceleratedWidget widget,
base::ScopedFD shm_fd, base::ScopedFD shm_fd,
size_t length, size_t length,
const gfx::Size size, gfx::Size size,
uint32_t buffer_id) { uint32_t buffer_id) {
DCHECK(gpu_thread_runner_); DCHECK(gpu_thread_runner_);
// Do a mojo call on the GpuMainThread instead of the io child thread to // Do a mojo call on the GpuMainThread instead of the io child thread to
// ensure proper functionality. // ensure proper functionality.
gpu_thread_runner_->PostTask( gpu_thread_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&WaylandConnectionProxy::CreateShmBasedBufferInternal, base::BindOnce(&WaylandBufferManagerGpu::CreateShmBasedBufferInternal,
base::Unretained(this), widget, std::move(shm_fd), length, base::Unretained(this), widget, std::move(shm_fd), length,
std::move(size), buffer_id)); std::move(size), buffer_id));
} }
void WaylandConnectionProxy::CommitBuffer(gfx::AcceleratedWidget widget, void WaylandBufferManagerGpu::CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::Rect& damage_region) { const gfx::Rect& damage_region) {
DCHECK(gpu_thread_runner_); DCHECK(gpu_thread_runner_);
...@@ -111,27 +112,27 @@ void WaylandConnectionProxy::CommitBuffer(gfx::AcceleratedWidget widget, ...@@ -111,27 +112,27 @@ void WaylandConnectionProxy::CommitBuffer(gfx::AcceleratedWidget widget,
// ensure proper functionality. // ensure proper functionality.
gpu_thread_runner_->PostTask( gpu_thread_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&WaylandConnectionProxy::CommitBufferInternal, base::BindOnce(&WaylandBufferManagerGpu::CommitBufferInternal,
base::Unretained(this), widget, buffer_id, damage_region)); base::Unretained(this), widget, buffer_id, damage_region));
} }
void WaylandConnectionProxy::DestroyBuffer(gfx::AcceleratedWidget widget, void WaylandBufferManagerGpu::DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) { uint32_t buffer_id) {
DCHECK(gpu_thread_runner_); DCHECK(gpu_thread_runner_);
// Do a mojo call on the GpuMainThread instead of the io child thread to // Do a mojo call on the GpuMainThread instead of the io child thread to
// ensure proper functionality. // ensure proper functionality.
gpu_thread_runner_->PostTask( gpu_thread_runner_->PostTask(
FROM_HERE, base::BindOnce(&WaylandConnectionProxy::DestroyBufferInternal, FROM_HERE, base::BindOnce(&WaylandBufferManagerGpu::DestroyBufferInternal,
base::Unretained(this), widget, buffer_id)); base::Unretained(this), widget, buffer_id));
} }
void WaylandConnectionProxy::AddBindingWaylandConnectionClient( void WaylandBufferManagerGpu::AddBindingWaylandBufferManagerGpu(
ozone::mojom::WaylandConnectionClientRequest request) { ozone::mojom::WaylandBufferManagerGpuRequest request) {
bindings_.AddBinding(this, std::move(request)); bindings_.AddBinding(this, std::move(request));
} }
void WaylandConnectionProxy::CreateDmabufBasedBufferInternal( void WaylandBufferManagerGpu::CreateDmabufBasedBufferInternal(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
base::ScopedFD dmabuf_fd, base::ScopedFD dmabuf_fd,
gfx::Size size, gfx::Size size,
...@@ -145,24 +146,23 @@ void WaylandConnectionProxy::CreateDmabufBasedBufferInternal( ...@@ -145,24 +146,23 @@ void WaylandConnectionProxy::CreateDmabufBasedBufferInternal(
// from the thread, which is used to call these methods. Thus, rebind the // from the thread, which is used to call these methods. Thus, rebind the
// interface on a first call to ensure mojo calls will always happen on a // interface on a first call to ensure mojo calls will always happen on a
// sequence we want. // sequence we want.
if (!wc_ptr_.is_bound()) if (!buffer_manager_host_ptr_.is_bound())
BindHostInterface(); BindHostInterface();
DCHECK(gpu_thread_runner_->BelongsToCurrentThread()); DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
DCHECK(wc_ptr_); DCHECK(buffer_manager_host_ptr_);
buffer_manager_host_ptr_->CreateDmabufBasedBuffer(
wc_ptr_->CreateDmabufBasedBuffer(
widget, widget,
mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(dmabuf_fd))), mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(dmabuf_fd))),
size, strides, offsets, modifiers, current_format, planes_count, size, strides, offsets, modifiers, current_format, planes_count,
buffer_id); buffer_id);
} }
void WaylandConnectionProxy::CreateShmBasedBufferInternal( void WaylandBufferManagerGpu::CreateShmBasedBufferInternal(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
base::ScopedFD shm_fd, base::ScopedFD shm_fd,
size_t length, size_t length,
const gfx::Size size, gfx::Size size,
uint32_t buffer_id) { uint32_t buffer_id) {
DCHECK(gpu_thread_runner_->BelongsToCurrentThread()); DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
...@@ -170,42 +170,44 @@ void WaylandConnectionProxy::CreateShmBasedBufferInternal( ...@@ -170,42 +170,44 @@ void WaylandConnectionProxy::CreateShmBasedBufferInternal(
// from the thread, which is used to call these methods. Thus, rebind the // from the thread, which is used to call these methods. Thus, rebind the
// interface on a first call to ensure mojo calls will always happen on a // interface on a first call to ensure mojo calls will always happen on a
// sequence we want. // sequence we want.
if (!wc_ptr_.is_bound()) if (!buffer_manager_host_ptr_.is_bound())
BindHostInterface(); BindHostInterface();
DCHECK(wc_ptr_); DCHECK(buffer_manager_host_ptr_);
wc_ptr_->CreateShmBasedBuffer( buffer_manager_host_ptr_->CreateShmBasedBuffer(
widget, mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(shm_fd))), widget, mojo::WrapPlatformHandle(mojo::PlatformHandle(std::move(shm_fd))),
length, size, buffer_id); length, size, buffer_id);
} }
void WaylandConnectionProxy::CommitBufferInternal( void WaylandBufferManagerGpu::CommitBufferInternal(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::Rect& damage_region) { const gfx::Rect& damage_region) {
DCHECK(gpu_thread_runner_->BelongsToCurrentThread()); DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
DCHECK(wc_ptr_); DCHECK(buffer_manager_host_ptr_);
wc_ptr_->CommitBuffer(widget, buffer_id, damage_region); buffer_manager_host_ptr_->CommitBuffer(widget, buffer_id, damage_region);
} }
void WaylandConnectionProxy::DestroyBufferInternal( void WaylandBufferManagerGpu::DestroyBufferInternal(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
uint32_t buffer_id) { uint32_t buffer_id) {
DCHECK(gpu_thread_runner_->BelongsToCurrentThread()); DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
DCHECK(wc_ptr_); DCHECK(buffer_manager_host_ptr_);
wc_ptr_->DestroyBuffer(widget, buffer_id); buffer_manager_host_ptr_->DestroyBuffer(widget, buffer_id);
} }
void WaylandConnectionProxy::BindHostInterface() { void WaylandBufferManagerGpu::BindHostInterface() {
DCHECK(!wc_ptr_.is_bound()); DCHECK(!buffer_manager_host_ptr_.is_bound());
wc_ptr_.Bind(std::move(wc_ptr_info_)); buffer_manager_host_ptr_.Bind(std::move(buffer_manager_host_ptr_info_));
// Setup associated interface. // Setup associated interface.
ozone::mojom::WaylandConnectionClientAssociatedPtrInfo client_ptr_info; ozone::mojom::WaylandBufferManagerGpuAssociatedPtrInfo client_ptr_info;
auto request = MakeRequest(&client_ptr_info); auto request = MakeRequest(&client_ptr_info);
wc_ptr_->SetWaylandConnectionClient(std::move(client_ptr_info)); DCHECK(buffer_manager_host_ptr_);
buffer_manager_host_ptr_->SetWaylandBufferManagerGpuPtr(
std::move(client_ptr_info));
associated_binding_.Bind(std::move(request)); associated_binding_.Bind(std::move(request));
} }
......
...@@ -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.
#ifndef UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_CONNECTION_PROXY_H_ #ifndef UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_H_
#define UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_CONNECTION_PROXY_H_ #define UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_H_
#include <memory> #include <memory>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/common/wayland_util.h"
#include "ui/ozone/public/interfaces/wayland/wayland_connection.mojom.h" #include "ui/ozone/public/interfaces/wayland/wayland_buffer_manager.mojom.h"
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
#include "ui/ozone/common/linux/gbm_device.h" // nogncheck #include "ui/ozone/common/linux/gbm_device.h" // nogncheck
...@@ -34,16 +34,21 @@ class WaylandWindow; ...@@ -34,16 +34,21 @@ class WaylandWindow;
// Forwards calls through an associated mojo connection to WaylandBufferManager // Forwards calls through an associated mojo connection to WaylandBufferManager
// on the browser process side. // on the browser process side.
// //
// It's guaranteed that WaylandConnectionProxy makes mojo calls on the right // It's guaranteed that WaylandBufferManagerGpu makes mojo calls on the right
// sequence. // sequence.
class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient { class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
public: public:
explicit WaylandConnectionProxy(WaylandSurfaceFactory* factory); using BufferManagerHostPtr = ozone::mojom::WaylandBufferManagerHostPtr;
~WaylandConnectionProxy() override;
explicit WaylandBufferManagerGpu(WaylandSurfaceFactory* factory);
~WaylandBufferManagerGpu() override;
// WaylandBufferManagerGpu overrides:
void SetWaylandBufferManagerHost(
BufferManagerHostPtr buffer_manager_host_ptr) override;
// WaylandConnectionProxy overrides:
void SetWaylandConnection(ozone::mojom::WaylandConnectionPtr wc_ptr) override;
void ResetGbmDevice() override; void ResetGbmDevice() override;
// 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.
...@@ -74,7 +79,7 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient { ...@@ -74,7 +79,7 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient {
void CreateShmBasedBuffer(gfx::AcceleratedWidget widget, void CreateShmBasedBuffer(gfx::AcceleratedWidget widget,
base::ScopedFD shm_fd, base::ScopedFD shm_fd,
size_t length, size_t length,
const gfx::Size size, gfx::Size size,
uint32_t buffer_id); uint32_t buffer_id);
// 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
...@@ -102,9 +107,9 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient { ...@@ -102,9 +107,9 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient {
} }
#endif #endif
// Adds a WaylandConnectionClient binding. // Adds a WaylandBufferManagerGpu binding.
void AddBindingWaylandConnectionClient( void AddBindingWaylandBufferManagerGpu(
ozone::mojom::WaylandConnectionClientRequest request); ozone::mojom::WaylandBufferManagerGpuRequest request);
private: private:
void CreateDmabufBasedBufferInternal(gfx::AcceleratedWidget widget, void CreateDmabufBasedBufferInternal(gfx::AcceleratedWidget widget,
...@@ -119,7 +124,7 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient { ...@@ -119,7 +124,7 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient {
void CreateShmBasedBufferInternal(gfx::AcceleratedWidget widget, void CreateShmBasedBufferInternal(gfx::AcceleratedWidget widget,
base::ScopedFD shm_fd, base::ScopedFD shm_fd,
size_t length, size_t length,
const gfx::Size size, gfx::Size size,
uint32_t buffer_id); uint32_t buffer_id);
void CommitBufferInternal(gfx::AcceleratedWidget widget, void CommitBufferInternal(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
...@@ -137,14 +142,14 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient { ...@@ -137,14 +142,14 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient {
std::unique_ptr<GbmDevice> gbm_device_; std::unique_ptr<GbmDevice> gbm_device_;
#endif #endif
mojo::BindingSet<ozone::mojom::WaylandConnectionClient> bindings_; mojo::BindingSet<ozone::mojom::WaylandBufferManagerGpu> bindings_;
// A pointer to a WaylandConnection object, which always lives on a browser // A pointer to a WaylandBufferManagerHost object, which always lives on a
// process side. It's used for a multi-process mode. // browser process side. It's used for a multi-process mode.
ozone::mojom::WaylandConnectionPtr wc_ptr_; BufferManagerHostPtr buffer_manager_host_ptr_;
ozone::mojom::WaylandConnectionPtrInfo wc_ptr_info_; ozone::mojom::WaylandBufferManagerHostPtrInfo buffer_manager_host_ptr_info_;
mojo::AssociatedBinding<ozone::mojom::WaylandConnectionClient> mojo::AssociatedBinding<ozone::mojom::WaylandBufferManagerGpu>
associated_binding_; associated_binding_;
// A task runner, which is initialized in a multi-process mode. It is used to // A task runner, which is initialized in a multi-process mode. It is used to
...@@ -155,9 +160,9 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient { ...@@ -155,9 +160,9 @@ class WaylandConnectionProxy : public ozone::mojom::WaylandConnectionClient {
// CommitBuffer call. // CommitBuffer call.
scoped_refptr<base::SingleThreadTaskRunner> gpu_thread_runner_; scoped_refptr<base::SingleThreadTaskRunner> gpu_thread_runner_;
DISALLOW_COPY_AND_ASSIGN(WaylandConnectionProxy); DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerGpu);
}; };
} // namespace ui } // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_CONNECTION_PROXY_H_ #endif // UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_BUFFER_MANAGER_GPU_H_
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/memory/unsafe_shared_memory_region.h" #include "base/memory/unsafe_shared_memory_region.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "ui/gfx/vsync_provider.h" #include "ui/gfx/vsync_provider.h"
#include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
namespace ui { namespace ui {
...@@ -25,13 +25,14 @@ void DeleteSharedMemoryMapping(void* pixels, void* context) { ...@@ -25,13 +25,14 @@ void DeleteSharedMemoryMapping(void* pixels, void* context) {
} // namespace } // namespace
WaylandCanvasSurface::WaylandCanvasSurface(WaylandConnectionProxy* connection, WaylandCanvasSurface::WaylandCanvasSurface(
WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget) gfx::AcceleratedWidget widget)
: connection_(connection), widget_(widget) {} : buffer_manager_(buffer_manager), widget_(widget) {}
WaylandCanvasSurface::~WaylandCanvasSurface() { WaylandCanvasSurface::~WaylandCanvasSurface() {
if (sk_surface_) if (sk_surface_)
connection_->DestroyBuffer(widget_, buffer_id_); buffer_manager_->DestroyBuffer(widget_, buffer_id_);
} }
sk_sp<SkSurface> WaylandCanvasSurface::GetSurface() { sk_sp<SkSurface> WaylandCanvasSurface::GetSurface() {
...@@ -53,7 +54,7 @@ sk_sp<SkSurface> WaylandCanvasSurface::GetSurface() { ...@@ -53,7 +54,7 @@ sk_sp<SkSurface> WaylandCanvasSurface::GetSurface() {
base::UnsafeSharedMemoryRegion::TakeHandleForSerialization( base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
std::move(shm_region)); std::move(shm_region));
base::subtle::ScopedFDPair fd_pair = platform_shm.PassPlatformHandle(); base::subtle::ScopedFDPair fd_pair = platform_shm.PassPlatformHandle();
connection_->CreateShmBasedBuffer(widget_, std::move(fd_pair.fd), length, buffer_manager_->CreateShmBasedBuffer(widget_, std::move(fd_pair.fd), length,
size_, ++buffer_id_); size_, ++buffer_id_);
auto shm_mapping_on_heap = auto shm_mapping_on_heap =
...@@ -79,7 +80,7 @@ void WaylandCanvasSurface::ResizeCanvas(const gfx::Size& viewport_size) { ...@@ -79,7 +80,7 @@ void WaylandCanvasSurface::ResizeCanvas(const gfx::Size& viewport_size) {
// smaller than the old size). // smaller than the old size).
if (sk_surface_) { if (sk_surface_) {
sk_surface_.reset(); sk_surface_.reset();
connection_->DestroyBuffer(widget_, buffer_id_); buffer_manager_->DestroyBuffer(widget_, buffer_id_);
} }
size_ = viewport_size; size_ = viewport_size;
} }
...@@ -87,7 +88,7 @@ void WaylandCanvasSurface::ResizeCanvas(const gfx::Size& viewport_size) { ...@@ -87,7 +88,7 @@ void WaylandCanvasSurface::ResizeCanvas(const gfx::Size& viewport_size) {
void WaylandCanvasSurface::PresentCanvas(const gfx::Rect& damage) { void WaylandCanvasSurface::PresentCanvas(const gfx::Rect& damage) {
// TODO(https://crbug.com/930664): add support for submission and presentation // TODO(https://crbug.com/930664): add support for submission and presentation
// callbacks. // callbacks.
connection_->CommitBuffer(widget_, buffer_id_, damage); buffer_manager_->CommitBuffer(widget_, buffer_id_, damage);
} }
std::unique_ptr<gfx::VSyncProvider> std::unique_ptr<gfx::VSyncProvider>
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
namespace ui { namespace ui {
class WaylandConnectionProxy; class WaylandBufferManagerGpu;
class WaylandCanvasSurface : public SurfaceOzoneCanvas { class WaylandCanvasSurface : public SurfaceOzoneCanvas {
public: public:
WaylandCanvasSurface(WaylandConnectionProxy* connection, WaylandCanvasSurface(WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget); gfx::AcceleratedWidget widget);
~WaylandCanvasSurface() override; ~WaylandCanvasSurface() override;
...@@ -33,7 +33,7 @@ class WaylandCanvasSurface : public SurfaceOzoneCanvas { ...@@ -33,7 +33,7 @@ class WaylandCanvasSurface : public SurfaceOzoneCanvas {
private: private:
void OnGetSizeForWidget(const gfx::Size& widget_size) { size_ = widget_size; } void OnGetSizeForWidget(const gfx::Size& widget_size) { size_ = widget_size; }
WaylandConnectionProxy* const connection_; WaylandBufferManagerGpu* const buffer_manager_;
const gfx::AcceleratedWidget widget_; const gfx::AcceleratedWidget widget_;
gfx::Size size_; gfx::Size size_;
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "ui/ozone/common/gl_ozone_egl.h" #include "ui/ozone/common/gl_ozone_egl.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_object.h"
#include "ui/ozone/platform/wayland/gpu/gl_surface_wayland.h" #include "ui/ozone/platform/wayland/gpu/gl_surface_wayland.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/gpu/wayland_canvas_surface.h" #include "ui/ozone/platform/wayland/gpu/wayland_canvas_surface.h"
#include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.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_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
...@@ -30,10 +30,10 @@ namespace { ...@@ -30,10 +30,10 @@ namespace {
class GLOzoneEGLWayland : public GLOzoneEGL { class GLOzoneEGLWayland : public GLOzoneEGL {
public: public:
GLOzoneEGLWayland(WaylandConnection* connection, GLOzoneEGLWayland(WaylandConnection* connection,
WaylandConnectionProxy* connection_proxy, WaylandBufferManagerGpu* buffer_manager,
WaylandSurfaceFactory* factory) WaylandSurfaceFactory* factory)
: connection_(connection), : connection_(connection),
connection_proxy_(connection_proxy), buffer_manager_(buffer_manager),
factory_(factory) {} factory_(factory) {}
~GLOzoneEGLWayland() override {} ~GLOzoneEGLWayland() override {}
...@@ -52,7 +52,7 @@ class GLOzoneEGLWayland : public GLOzoneEGL { ...@@ -52,7 +52,7 @@ class GLOzoneEGLWayland : public GLOzoneEGL {
private: private:
WaylandConnection* const connection_; WaylandConnection* const connection_;
WaylandConnectionProxy* const connection_proxy_; WaylandBufferManagerGpu* const buffer_manager_;
WaylandSurfaceFactory* const factory_; WaylandSurfaceFactory* const factory_;
DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLWayland); DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLWayland);
...@@ -87,10 +87,10 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface( ...@@ -87,10 +87,10 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface(
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
// If there is a gbm device available, use surfaceless gl surface. // If there is a gbm device available, use surfaceless gl surface.
if (!connection_proxy_->gbm_device()) if (!buffer_manager_->gbm_device())
return nullptr; return nullptr;
return gl::InitializeGLSurface( return gl::InitializeGLSurface(
new GbmSurfacelessWayland(factory_, connection_proxy_, window)); new GbmSurfacelessWayland(factory_, buffer_manager_, window));
#else #else
return nullptr; return nullptr;
#endif #endif
...@@ -126,12 +126,13 @@ WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection) ...@@ -126,12 +126,13 @@ WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection)
WaylandSurfaceFactory::~WaylandSurfaceFactory() = default; WaylandSurfaceFactory::~WaylandSurfaceFactory() = default;
void WaylandSurfaceFactory::SetProxy(WaylandConnectionProxy* proxy) { void WaylandSurfaceFactory::SetBufferManager(
DCHECK(!connection_proxy_ && proxy); WaylandBufferManagerGpu* buffer_manager) {
connection_proxy_ = proxy; DCHECK(!buffer_manager_ && buffer_manager);
buffer_manager_ = buffer_manager;
egl_implementation_ = egl_implementation_ =
std::make_unique<GLOzoneEGLWayland>(connection_, connection_proxy_, this); std::make_unique<GLOzoneEGLWayland>(connection_, buffer_manager_, this);
} }
void WaylandSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget, void WaylandSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget,
...@@ -155,7 +156,7 @@ GbmSurfacelessWayland* WaylandSurfaceFactory::GetSurface( ...@@ -155,7 +156,7 @@ GbmSurfacelessWayland* WaylandSurfaceFactory::GetSurface(
std::unique_ptr<SurfaceOzoneCanvas> std::unique_ptr<SurfaceOzoneCanvas>
WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) {
return std::make_unique<WaylandCanvasSurface>(connection_proxy_, widget); return std::make_unique<WaylandCanvasSurface>(buffer_manager_, widget);
} }
std::vector<gl::GLImplementation> std::vector<gl::GLImplementation>
...@@ -187,7 +188,7 @@ scoped_refptr<gfx::NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( ...@@ -187,7 +188,7 @@ scoped_refptr<gfx::NativePixmap> WaylandSurfaceFactory::CreateNativePixmap(
gfx::BufferUsage usage) { gfx::BufferUsage usage) {
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
scoped_refptr<GbmPixmapWayland> pixmap = scoped_refptr<GbmPixmapWayland> pixmap =
base::MakeRefCounted<GbmPixmapWayland>(this, connection_proxy_, widget); base::MakeRefCounted<GbmPixmapWayland>(this, buffer_manager_, widget);
if (!pixmap->InitializeBuffer(size, format, usage)) if (!pixmap->InitializeBuffer(size, format, usage))
return nullptr; return nullptr;
return pixmap; return pixmap;
......
...@@ -19,14 +19,14 @@ namespace ui { ...@@ -19,14 +19,14 @@ namespace ui {
class GbmSurfacelessWayland; class GbmSurfacelessWayland;
class WaylandConnection; class WaylandConnection;
class WaylandConnectionProxy; class WaylandBufferManagerGpu;
class WaylandSurfaceFactory : public SurfaceFactoryOzone { class WaylandSurfaceFactory : public SurfaceFactoryOzone {
public: public:
explicit WaylandSurfaceFactory(WaylandConnection* connection); explicit WaylandSurfaceFactory(WaylandConnection* connection);
~WaylandSurfaceFactory() override; ~WaylandSurfaceFactory() override;
void SetProxy(WaylandConnectionProxy* proxy); void SetBufferManager(WaylandBufferManagerGpu* buffer_manager);
// These methods are used, when a dmabuf based approach is used. // These methods are used, when a dmabuf based approach is used.
void RegisterSurface(gfx::AcceleratedWidget widget, void RegisterSurface(gfx::AcceleratedWidget widget,
...@@ -53,7 +53,7 @@ class WaylandSurfaceFactory : public SurfaceFactoryOzone { ...@@ -53,7 +53,7 @@ class WaylandSurfaceFactory : public SurfaceFactoryOzone {
private: private:
WaylandConnection* const connection_; WaylandConnection* const connection_;
WaylandConnectionProxy* connection_proxy_ = nullptr; WaylandBufferManagerGpu* buffer_manager_ = nullptr;
std::unique_ptr<GLOzone> egl_implementation_; std::unique_ptr<GLOzone> egl_implementation_;
std::map<gfx::AcceleratedWidget, GbmSurfacelessWayland*> std::map<gfx::AcceleratedWidget, GbmSurfacelessWayland*>
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/ozone/common/linux/gbm_buffer.h" #include "ui/ozone/common/linux/gbm_buffer.h"
#include "ui/ozone/common/linux/gbm_device.h" #include "ui/ozone/common/linux/gbm_device.h"
#include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.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_host.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h"
...@@ -95,8 +96,8 @@ class WaylandSurfaceFactoryTest : public WaylandTest { ...@@ -95,8 +96,8 @@ class WaylandSurfaceFactoryTest : public WaylandTest {
void SetUp() override { void SetUp() override {
WaylandTest::SetUp(); WaylandTest::SetUp();
auto connection_ptr = connection_->BindInterface(); auto manager_ptr = connection_->buffer_manager_host()->BindInterface();
connection_proxy_->SetWaylandConnection(std::move(connection_ptr)); buffer_manager_gpu_->SetWaylandBufferManagerHost(std::move(manager_ptr));
// Wait until initialization and mojo calls go through. // Wait until initialization and mojo calls go through.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -182,7 +183,7 @@ TEST_P(WaylandSurfaceFactoryTest, CreateSurfaceCheckGbm) { ...@@ -182,7 +183,7 @@ TEST_P(WaylandSurfaceFactoryTest, CreateSurfaceCheckGbm) {
// When gbm is not available, only canvas can be created with viz process // When gbm is not available, only canvas can be created with viz process
// used. // used.
EXPECT_FALSE(connection_proxy_->gbm_device()); EXPECT_FALSE(buffer_manager_gpu_->gbm_device());
auto* gl_ozone = surface_factory_->GetGLOzone(gl::kGLImplementationEGLGLES2); auto* gl_ozone = surface_factory_->GetGLOzone(gl::kGLImplementationEGLGLES2);
EXPECT_TRUE(gl_ozone); EXPECT_TRUE(gl_ozone);
...@@ -190,14 +191,14 @@ TEST_P(WaylandSurfaceFactoryTest, CreateSurfaceCheckGbm) { ...@@ -190,14 +191,14 @@ TEST_P(WaylandSurfaceFactoryTest, CreateSurfaceCheckGbm) {
EXPECT_FALSE(gl_surface); EXPECT_FALSE(gl_surface);
// Now, set gbm. // Now, set gbm.
connection_proxy_->set_gbm_device(std::make_unique<FakeGbmDevice>()); buffer_manager_gpu_->set_gbm_device(std::make_unique<FakeGbmDevice>());
gl_surface = gl_ozone->CreateSurfacelessViewGLSurface(widget_); gl_surface = gl_ozone->CreateSurfacelessViewGLSurface(widget_);
EXPECT_TRUE(gl_surface); EXPECT_TRUE(gl_surface);
// Reset gbm now. WaylandConnectionProxy can reset it when zwp is not // Reset gbm now. WaylandConnectionProxy can reset it when zwp is not
// available. And factory must behave the same way as previously. // available. And factory must behave the same way as previously.
connection_proxy_->ResetGbmDevice(); buffer_manager_gpu_->ResetGbmDevice();
gl_surface = gl_ozone->CreateSurfacelessViewGLSurface(widget_); gl_surface = gl_ozone->CreateSurfacelessViewGLSurface(widget_);
EXPECT_FALSE(gl_surface); EXPECT_FALSE(gl_surface);
} }
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// 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/host/wayland_connection_connector.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_connector.h"
#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_connection.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
namespace ui { namespace ui {
...@@ -31,29 +31,29 @@ void BindInterfaceInGpuProcess(mojo::InterfaceRequest<Interface> request, ...@@ -31,29 +31,29 @@ void BindInterfaceInGpuProcess(mojo::InterfaceRequest<Interface> request,
} // namespace } // namespace
WaylandConnectionConnector::WaylandConnectionConnector( WaylandBufferManagerConnector::WaylandBufferManagerConnector(
WaylandConnection* connection) WaylandBufferManagerHost* buffer_manager)
: connection_(connection) {} : buffer_manager_(buffer_manager) {}
WaylandConnectionConnector::~WaylandConnectionConnector() = default; WaylandBufferManagerConnector::~WaylandBufferManagerConnector() = default;
void WaylandConnectionConnector::OnGpuProcessLaunched( void WaylandBufferManagerConnector::OnGpuProcessLaunched(
int host_id, int host_id,
scoped_refptr<base::SingleThreadTaskRunner> ui_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_runner,
scoped_refptr<base::SingleThreadTaskRunner> send_runner, scoped_refptr<base::SingleThreadTaskRunner> send_runner,
const base::RepeatingCallback<void(IPC::Message*)>& send_callback) {} const base::RepeatingCallback<void(IPC::Message*)>& send_callback) {}
void WaylandConnectionConnector::OnChannelDestroyed(int host_id) { void WaylandBufferManagerConnector::OnChannelDestroyed(int host_id) {
connection_->OnChannelDestroyed(); buffer_manager_->OnChannelDestroyed();
} }
void WaylandConnectionConnector::OnMessageReceived( void WaylandBufferManagerConnector::OnMessageReceived(
const IPC::Message& message) { const IPC::Message& message) {
NOTREACHED() << "This class should only be used with mojo transport but here " NOTREACHED() << "This class should only be used with mojo transport but here "
"we're wrongly getting invoked to handle IPC communication."; "we're wrongly getting invoked to handle IPC communication.";
} }
void WaylandConnectionConnector::OnGpuServiceLaunched( void WaylandBufferManagerConnector::OnGpuServiceLaunched(
scoped_refptr<base::SingleThreadTaskRunner> ui_runner, scoped_refptr<base::SingleThreadTaskRunner> ui_runner,
scoped_refptr<base::SingleThreadTaskRunner> io_runner, scoped_refptr<base::SingleThreadTaskRunner> io_runner,
GpuHostBindInterfaceCallback binder, GpuHostBindInterfaceCallback binder,
...@@ -63,34 +63,37 @@ void WaylandConnectionConnector::OnGpuServiceLaunched( ...@@ -63,34 +63,37 @@ void WaylandConnectionConnector::OnGpuServiceLaunched(
io_runner_ = io_runner; io_runner_ = io_runner;
auto on_terminate_gpu_cb = auto on_terminate_gpu_cb =
base::BindOnce(&WaylandConnectionConnector::OnTerminateGpuProcess, base::BindOnce(&WaylandBufferManagerConnector::OnTerminateGpuProcess,
base::Unretained(this)); base::Unretained(this));
connection_->SetTerminateGpuCallback(std::move(on_terminate_gpu_cb)); buffer_manager_->SetTerminateGpuCallback(std::move(on_terminate_gpu_cb));
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
ui_runner.get(), FROM_HERE, ui_runner.get(), FROM_HERE,
base::BindOnce(&WaylandConnection::BindInterface, base::BindOnce(&WaylandBufferManagerHost::BindInterface,
base::Unretained(connection_)), base::Unretained(buffer_manager_)),
base::BindOnce(&WaylandConnectionConnector::OnWaylandConnectionPtrBinded, base::BindOnce(
&WaylandBufferManagerConnector::OnBufferManagerHostPtrBinded,
base::Unretained(this))); base::Unretained(this)));
} }
void WaylandConnectionConnector::OnWaylandConnectionPtrBinded( void WaylandBufferManagerConnector::OnBufferManagerHostPtrBinded(
ozone::mojom::WaylandConnectionPtr wc_ptr) const { ozone::mojom::WaylandBufferManagerHostPtr buffer_manager_host_ptr) const {
ozone::mojom::WaylandConnectionClientPtr wcp_ptr; ozone::mojom::WaylandBufferManagerGpuPtr buffer_manager_gpu_ptr;
auto request = mojo::MakeRequest(&wcp_ptr); auto request = mojo::MakeRequest(&buffer_manager_gpu_ptr);
BindInterfaceInGpuProcess(std::move(request), binder_); BindInterfaceInGpuProcess(std::move(request), binder_);
wcp_ptr->SetWaylandConnection(std::move(wc_ptr)); DCHECK(buffer_manager_host_ptr);
buffer_manager_gpu_ptr->SetWaylandBufferManagerHost(
std::move(buffer_manager_host_ptr));
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
if (!connection_->zwp_dmabuf()) { if (!buffer_manager_->CanCreateDmabufBasedBuffer()) {
LOG(WARNING) << "zwp_linux_dmabuf is not available."; LOG(WARNING) << "zwp_linux_dmabuf is not available.";
wcp_ptr->ResetGbmDevice(); buffer_manager_gpu_ptr->ResetGbmDevice();
} }
#endif #endif
} }
void WaylandConnectionConnector::OnTerminateGpuProcess(std::string message) { void WaylandBufferManagerConnector::OnTerminateGpuProcess(std::string message) {
io_runner_->PostTask(FROM_HERE, base::BindOnce(std::move(terminate_callback_), io_runner_->PostTask(FROM_HERE, base::BindOnce(std::move(terminate_callback_),
std::move(message))); std::move(message)));
} }
......
...@@ -2,24 +2,25 @@ ...@@ -2,24 +2,25 @@
// 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.
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_CONNECTION_CONNECTOR_H_ #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_CONNECTOR_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_CONNECTION_CONNECTOR_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_CONNECTOR_H_
#include "ui/ozone/public/gpu_platform_support_host.h" #include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/interfaces/wayland/wayland_connection.mojom.h" #include "ui/ozone/public/interfaces/wayland/wayland_buffer_manager.mojom.h"
namespace ui { namespace ui {
class WaylandConnection; class WaylandBufferManagerHost;
// A connector class, which instantiates a connection between // A connector class which instantiates a connection between
// WaylandConnectionProxy on the GPU side and the WaylandConnection object on // WaylandBufferManagerGpu on the GPU side and the WaylandBufferManagerHost
// the browser process side. // object on the browser process side.
class WaylandConnectionConnector : public GpuPlatformSupportHost { class WaylandBufferManagerConnector : public GpuPlatformSupportHost {
public: public:
WaylandConnectionConnector(WaylandConnection* connection); explicit WaylandBufferManagerConnector(
~WaylandConnectionConnector() override; WaylandBufferManagerHost* buffer_manager);
~WaylandBufferManagerConnector() override;
// GpuPlatformSupportHost: // GpuPlatformSupportHost:
void OnGpuProcessLaunched( void OnGpuProcessLaunched(
...@@ -37,23 +38,23 @@ class WaylandConnectionConnector : public GpuPlatformSupportHost { ...@@ -37,23 +38,23 @@ class WaylandConnectionConnector : public GpuPlatformSupportHost {
GpuHostTerminateCallback terminate_callback) override; GpuHostTerminateCallback terminate_callback) override;
private: private:
void OnWaylandConnectionPtrBinded( void OnBufferManagerHostPtrBinded(
ozone::mojom::WaylandConnectionPtr wc_ptr) const; ozone::mojom::WaylandBufferManagerHostPtr buffer_manager_host_ptr) const;
void OnTerminateGpuProcess(std::string message); void OnTerminateGpuProcess(std::string message);
// Non-owning pointer, which is used to bind a mojo pointer to the // Non-owning pointer, which is used to bind a mojo pointer to the
// WaylandConnection. // WaylandBufferManagerHost.
WaylandConnection* connection_ = nullptr; WaylandBufferManagerHost* const buffer_manager_;
GpuHostBindInterfaceCallback binder_; GpuHostBindInterfaceCallback binder_;
GpuHostTerminateCallback terminate_callback_; GpuHostTerminateCallback terminate_callback_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_; scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
DISALLOW_COPY_AND_ASSIGN(WaylandConnectionConnector); DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerConnector);
}; };
} // namespace ui } // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_CONNECTION_CONNECTOR_H_ #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_CONNECTOR_H_
...@@ -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.
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_H_ #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_H_
#include <map> #include <map>
#include <memory> #include <memory>
...@@ -14,69 +14,85 @@ ...@@ -14,69 +14,85 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/presentation_feedback.h" #include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/swap_result.h" #include "ui/gfx/swap_result.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_object.h"
#include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/common/wayland_util.h"
#include "ui/ozone/public/interfaces/wayland/wayland_buffer_manager.mojom.h"
namespace ui { namespace ui {
class WaylandConnection; class WaylandConnection;
class WaylandWindow; class WaylandWindow;
// This is the buffer manager, which creates wl_buffers based on dmabuf (hw // This is the buffer manager which creates wl_buffers based on dmabuf (hw
// 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 WaylandBufferManager { class WaylandBufferManagerHost : ozone::mojom::WaylandBufferManagerHost {
public: public:
explicit WaylandBufferManager(WaylandConnection* connection); explicit WaylandBufferManagerHost(WaylandConnection* connection);
~WaylandBufferManager(); ~WaylandBufferManagerHost() override;
std::string error_message() { return std::move(error_message_); }
void OnWindowAdded(WaylandWindow* window); void OnWindowAdded(WaylandWindow* window);
void OnWindowRemoved(WaylandWindow* window); void OnWindowRemoved(WaylandWindow* window);
// Creates a wl_buffer based on the dmabuf |file| descriptor. On error, false void SetTerminateGpuCallback(
// is returned and |error_message_| is set. base::OnceCallback<void(std::string)> terminate_gpu_cb);
bool CreateDmabufBasedBuffer(gfx::AcceleratedWidget widget,
base::ScopedFD dmabuf_fd, // Returns bound pointer to own mojo interface.
ozone::mojom::WaylandBufferManagerHostPtr 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();
// Says if zwp_linux_dmabuf interface is available, and the manager is able to
// create dmabuf based buffers.
bool CanCreateDmabufBasedBuffer() const;
// ozone::mojom::WaylandBufferManagerHost overrides:
//
// These overridden methods below are invoked by the GPU when hardware
// accelerated rendering is used.
void SetWaylandBufferManagerGpuPtr(
ozone::mojom::WaylandBufferManagerGpuAssociatedPtrInfo
buffer_manager_gpu_associated_ptr) override;
//
// Called by the GPU and asks to import a wl_buffer based on a gbm file
// descriptor using zwp_linux_dmabuf protocol. Check comments in the
// ui/ozone/public/interfaces/wayland/wayland_connection.mojom.
void CreateDmabufBasedBuffer(gfx::AcceleratedWidget widget,
mojo::ScopedHandle 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,
const std::vector<uint64_t>& modifiers, const std::vector<uint64_t>& modifiers,
uint32_t format, uint32_t format,
uint32_t planes_count, uint32_t planes_count,
uint32_t buffer_id); uint32_t buffer_id) override;
// Called by the GPU and asks to import a wl_buffer based on a shared memory
// Create a wl_buffer based on the |file| descriptor to a shared memory. On // file descriptor using wl_shm protocol. Check comments in the
// error, false is returned and |error_message_| is set. // ui/ozone/public/interfaces/wayland/wayland_connection.mojom.
bool CreateShmBasedBuffer(gfx::AcceleratedWidget widget, void CreateShmBasedBuffer(gfx::AcceleratedWidget widget,
base::ScopedFD shm_fd, mojo::ScopedHandle shm_fd,
size_t length, uint64_t length,
const gfx::Size& size, const gfx::Size& size,
uint32_t buffer_id); uint32_t buffer_id) override;
// Called by the GPU to destroy the imported wl_buffer with a |buffer_id|.
// Assigns a wl_buffer with |buffer_id| to a window with the same |widget|. On void DestroyBuffer(gfx::AcceleratedWidget widget,
// error, false is returned and |error_message_| is set. A |damage_region| uint32_t buffer_id) override;
// identifies which part of the buffer is updated. If an empty region is // Called by the GPU and asks to attach a wl_buffer with a |buffer_id| to a
// provided, the whole buffer is updated. Once a frame callback or // WaylandWindow with the specified |widget|.
// presentation callback is received, WaylandConnection::OnSubmission and // Calls OnSubmission and OnPresentation on successful swap and pixels
// WaylandConnection::OnPresentation are called. Though, it is guaranteed // presented.
// OnPresentation won't be called earlier than OnSubmission. void CommitBuffer(gfx::AcceleratedWidget widget,
bool CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id, uint32_t buffer_id,
const gfx::Rect& damage_region); const gfx::Rect& damage_region) override;
// Destroys a buffer with |buffer_id| in |buffers_|. On error, false is
// returned and |error_message_| is set.
bool DestroyBuffer(gfx::AcceleratedWidget widget, uint32_t buffer_id);
// Destroys all the data and buffers stored in own containers.
void ClearState();
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
...@@ -115,6 +131,18 @@ class WaylandBufferManager { ...@@ -115,6 +131,18 @@ class WaylandBufferManager {
uint32_t buffer_id, 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
// it with the presentation feedback.
void OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result);
void OnPresentation(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback);
// Terminates the GPU process on invalid data received
void TerminateGpuProcess();
base::flat_map<gfx::AcceleratedWidget, std::unique_ptr<Surface>> surfaces_; base::flat_map<gfx::AcceleratedWidget, std::unique_ptr<Surface>> surfaces_;
// Set when invalid data is received from the GPU process. // Set when invalid data is received from the GPU process.
...@@ -123,11 +151,19 @@ class WaylandBufferManager { ...@@ -123,11 +151,19 @@ class WaylandBufferManager {
// Non-owned pointer to the main connection. // Non-owned pointer to the main connection.
WaylandConnection* const connection_; WaylandConnection* const connection_;
base::WeakPtrFactory<WaylandBufferManager> weak_factory_; ozone::mojom::WaylandBufferManagerGpuAssociatedPtr
buffer_manager_gpu_associated_ptr_;
mojo::Binding<ozone::mojom::WaylandBufferManagerHost> binding_;
// 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_;
base::WeakPtrFactory<WaylandBufferManagerHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(WaylandBufferManager); DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerHost);
}; };
} // namespace ui } // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_H_ #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_BUFFER_MANAGER_HOST_H_
// Copyright 2019 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.h"
#include <memory>
#include <drm_fourcc.h>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
using testing::_;
namespace ui {
namespace {
constexpr gfx::Size kDefaultSize(1024, 768);
} // namespace
class WaylandBufferManagerTest : public WaylandTest {
public:
WaylandBufferManagerTest() = default;
~WaylandBufferManagerTest() override = default;
protected:
base::ScopedFD MakeFD() {
base::FilePath temp_path;
EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
auto file =
base::File(temp_path, base::File::FLAG_READ | base::File::FLAG_WRITE |
base::File::FLAG_CREATE_ALWAYS);
return base::ScopedFD(file.TakePlatformFile());
}
private:
DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerTest);
};
TEST_P(WaylandBufferManagerTest, CreateDmabufBasedBuffers) {
WaylandBufferManager* manager = connection_->buffer_manager();
ASSERT_TRUE(manager);
constexpr uint32_t kDmabufBufferId = 1;
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
const gfx::AcceleratedWidget widget = window_->GetWidget();
EXPECT_TRUE(manager->CreateDmabufBasedBuffer(widget, MakeFD(), kDefaultSize,
{1}, {2}, {3}, DRM_FORMAT_R8, 1,
kDmabufBufferId));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_TRUE(manager->DestroyBuffer(widget, kDmabufBufferId));
EXPECT_TRUE(manager->error_message().empty());
}
TEST_P(WaylandBufferManagerTest, CreateShmBasedBuffers) {
WaylandBufferManager* manager = connection_->buffer_manager();
ASSERT_TRUE(manager);
constexpr uint32_t kShmBufferId = 1;
const gfx::AcceleratedWidget widget = window_->GetWidget();
size_t length = kDefaultSize.width() * kDefaultSize.height() * 4;
EXPECT_TRUE(manager->CreateShmBasedBuffer(widget, MakeFD(), length,
kDefaultSize, kShmBufferId));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_TRUE(manager->DestroyBuffer(widget, kShmBufferId));
EXPECT_TRUE(manager->error_message().empty());
}
TEST_P(WaylandBufferManagerTest, ValidateDataFromGpu) {
struct InputData {
bool has_file = false;
gfx::Size size;
uint32_t planes_count = 0;
std::vector<uint32_t> strides;
std::vector<uint32_t> offsets;
std::vector<uint64_t> modifiers;
uint32_t format = 0;
uint32_t buffer_id = 0;
};
constexpr uint32_t kExistingBufferId = 1;
constexpr uint32_t kNonExistingBufferId = 2;
WaylandBufferManager* manager = connection_->buffer_manager();
ASSERT_TRUE(manager);
// Create a buffer so it gets registered with the given ID.
// This must be the only buffer that is asked to be created.
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
const gfx::AcceleratedWidget widget = window_->GetWidget();
manager->CreateDmabufBasedBuffer(widget, MakeFD(), kDefaultSize, {1}, {2},
{3}, DRM_FORMAT_R8, 1, kExistingBufferId);
Sync();
const InputData kBadInputs[] = {
// All zeros.
{},
// Valid file but zeros everywhereelse.
{true},
// Valid file, invalid size, zeros elsewhere.
{true, {kDefaultSize.width(), 0}},
{true, {0, kDefaultSize.height()}},
// Valid file and size but zeros in other fields.
{true, kDefaultSize},
// Vectors have different lengths.
{true, kDefaultSize, 1, {1}, {2, 3}, {4, 5, 6}},
// Vectors have same lengths but strides have a zero.
{true, kDefaultSize, 1, {0}, {2}, {6}},
// Vectors are valid but buffer format is not.
{true, kDefaultSize, 1, {1}, {2}, {6}},
// Everything is correct but the buffer ID is zero.
{true, kDefaultSize, 1, {1}, {2}, {6}, DRM_FORMAT_R8},
// Everything is correct but the buffer ID .
{true, kDefaultSize, 1, {1}, {2}, {6}, DRM_FORMAT_R8, kExistingBufferId},
};
for (const auto& bad : kBadInputs) {
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(0);
base::ScopedFD dummy;
EXPECT_FALSE(manager->CreateDmabufBasedBuffer(
widget, bad.has_file ? MakeFD() : std::move(dummy), bad.size,
bad.strides, bad.offsets, bad.modifiers, bad.format, bad.planes_count,
bad.buffer_id));
EXPECT_FALSE(manager->error_message().empty());
}
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
EXPECT_TRUE(manager->CreateDmabufBasedBuffer(widget, MakeFD(), kDefaultSize,
{1}, {2}, {3}, DRM_FORMAT_R8, 1,
kNonExistingBufferId));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_TRUE(manager->DestroyBuffer(widget, kNonExistingBufferId));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_TRUE(manager->DestroyBuffer(widget, kExistingBufferId));
EXPECT_TRUE(manager->error_message().empty());
}
TEST_P(WaylandBufferManagerTest, CreateAndDestroyBuffer) {
WaylandBufferManager* manager = connection_->buffer_manager();
ASSERT_TRUE(manager);
const uint32_t kBufferId1 = 1;
const uint32_t kBufferId2 = 2;
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2);
const gfx::AcceleratedWidget widget = window_->GetWidget();
EXPECT_TRUE(manager->CreateDmabufBasedBuffer(widget, MakeFD(), kDefaultSize,
{1}, {2}, {3}, DRM_FORMAT_R8, 1,
kBufferId1));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_FALSE(manager->CreateDmabufBasedBuffer(widget, MakeFD(), kDefaultSize,
{1}, {2}, {3}, DRM_FORMAT_R8, 1,
kBufferId1));
EXPECT_FALSE(manager->error_message().empty());
EXPECT_FALSE(manager->DestroyBuffer(widget, kBufferId2));
EXPECT_FALSE(manager->error_message().empty());
EXPECT_TRUE(manager->CreateDmabufBasedBuffer(widget, MakeFD(), kDefaultSize,
{1}, {2}, {3}, DRM_FORMAT_R8, 1,
kBufferId2));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_TRUE(manager->DestroyBuffer(widget, kBufferId1));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_FALSE(manager->DestroyBuffer(widget, kBufferId1));
EXPECT_FALSE(manager->error_message().empty());
EXPECT_TRUE(manager->DestroyBuffer(widget, kBufferId2));
EXPECT_TRUE(manager->error_message().empty());
EXPECT_FALSE(manager->DestroyBuffer(widget, kBufferId2));
EXPECT_FALSE(manager->error_message().empty());
}
INSTANTIATE_TEST_SUITE_P(XdgVersionV5Test,
WaylandBufferManagerTest,
::testing::Values(kXdgShellV5));
INSTANTIATE_TEST_SUITE_P(XdgVersionV6Test,
WaylandBufferManagerTest,
::testing::Values(kXdgShellV6));
} // namespace ui
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/gfx/swap_result.h" #include "ui/gfx/swap_result.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_object.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/host/wayland_input_method_context.h" #include "ui/ozone/platform/wayland/host/wayland_input_method_context.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_shm.h" #include "ui/ozone/platform/wayland/host/wayland_shm.h"
...@@ -45,8 +45,7 @@ constexpr uint32_t kMaxTextInputManagerVersion = 1; ...@@ -45,8 +45,7 @@ constexpr uint32_t kMaxTextInputManagerVersion = 1;
constexpr uint32_t kMinWlOutputVersion = 2; constexpr uint32_t kMinWlOutputVersion = 2;
} // namespace } // namespace
WaylandConnection::WaylandConnection() WaylandConnection::WaylandConnection() : controller_(FROM_HERE) {}
: controller_(FROM_HERE), binding_(this) {}
WaylandConnection::~WaylandConnection() = default; WaylandConnection::~WaylandConnection() = default;
...@@ -74,6 +73,8 @@ bool WaylandConnection::Initialize() { ...@@ -74,6 +73,8 @@ 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;
...@@ -161,10 +162,8 @@ WaylandWindow* WaylandConnection::GetCurrentKeyboardFocusedWindow() const { ...@@ -161,10 +162,8 @@ WaylandWindow* WaylandConnection::GetCurrentKeyboardFocusedWindow() const {
void WaylandConnection::AddWindow(gfx::AcceleratedWidget widget, void WaylandConnection::AddWindow(gfx::AcceleratedWidget widget,
WaylandWindow* window) { WaylandWindow* window) {
if (buffer_manager_) { DCHECK(buffer_manager_host_);
DCHECK(zwp_dmabuf_); buffer_manager_host_->OnWindowAdded(window);
buffer_manager_->OnWindowAdded(window);
}
window_map_[widget] = window; window_map_[widget] = window;
} }
...@@ -173,8 +172,8 @@ void WaylandConnection::RemoveWindow(gfx::AcceleratedWidget widget) { ...@@ -173,8 +172,8 @@ void WaylandConnection::RemoveWindow(gfx::AcceleratedWidget widget) {
if (touch_) if (touch_)
touch_->RemoveTouchPoints(window_map_[widget]); touch_->RemoveTouchPoints(window_map_[widget]);
if (buffer_manager_) DCHECK(buffer_manager_host_);
buffer_manager_->OnWindowRemoved(window_map_[widget]); buffer_manager_host_->OnWindowRemoved(window_map_[widget]);
window_map_.erase(widget); window_map_.erase(widget);
} }
...@@ -193,103 +192,12 @@ int WaylandConnection::GetKeyboardModifiers() const { ...@@ -193,103 +192,12 @@ int WaylandConnection::GetKeyboardModifiers() const {
return modifiers; return modifiers;
} }
void WaylandConnection::SetWaylandConnectionClient(
ozone::mojom::WaylandConnectionClientAssociatedPtrInfo client) {
client_associated_ptr_.Bind(std::move(client));
}
void WaylandConnection::CreateDmabufBasedBuffer(
gfx::AcceleratedWidget widget,
mojo::ScopedHandle 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());
DCHECK(buffer_manager_);
if (!buffer_manager_->CreateDmabufBasedBuffer(
widget, mojo::UnwrapPlatformHandle(std::move(dmabuf_fd)).TakeFD(),
size, strides, offsets, modifiers, format, planes_count, buffer_id)) {
TerminateGpuProcess(buffer_manager_->error_message());
}
}
void WaylandConnection::CreateShmBasedBuffer(gfx::AcceleratedWidget widget,
mojo::ScopedHandle shm_fd,
uint64_t length,
const gfx::Size& size,
uint32_t buffer_id) {
DCHECK(buffer_manager_);
if (!buffer_manager_->CreateShmBasedBuffer(
widget, mojo::UnwrapPlatformHandle(std::move(shm_fd)).TakeFD(),
length, size, buffer_id))
TerminateGpuProcess(buffer_manager_->error_message());
}
void WaylandConnection::DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
DCHECK(buffer_manager_);
if (!buffer_manager_->DestroyBuffer(widget, buffer_id)) {
TerminateGpuProcess(buffer_manager_->error_message());
}
}
void WaylandConnection::CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) {
DCHECK(base::MessageLoopCurrentForUI::IsSet());
CHECK(buffer_manager_);
if (!buffer_manager_->CommitBuffer(widget, buffer_id, damage_region))
TerminateGpuProcess(buffer_manager_->error_message());
}
void WaylandConnection::OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result) {
DCHECK(client_associated_ptr_);
client_associated_ptr_->OnSubmission(widget, buffer_id, swap_result);
}
void WaylandConnection::OnPresentation(
gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) {
DCHECK(client_associated_ptr_);
client_associated_ptr_->OnPresentation(widget, buffer_id, feedback);
}
ozone::mojom::WaylandConnectionPtr WaylandConnection::BindInterface() {
DCHECK(!binding_.is_bound());
ozone::mojom::WaylandConnectionPtr ptr;
binding_.Bind(MakeRequest(&ptr));
return ptr;
}
void WaylandConnection::OnChannelDestroyed() {
client_associated_ptr_.reset();
binding_.Close();
if (buffer_manager_)
buffer_manager_->ClearState();
}
std::vector<gfx::BufferFormat> WaylandConnection::GetSupportedBufferFormats() { std::vector<gfx::BufferFormat> WaylandConnection::GetSupportedBufferFormats() {
if (zwp_dmabuf_) if (zwp_dmabuf_)
return zwp_dmabuf_->supported_buffer_formats(); return zwp_dmabuf_->supported_buffer_formats();
return std::vector<gfx::BufferFormat>(); return std::vector<gfx::BufferFormat>();
} }
void WaylandConnection::SetTerminateGpuCallback(
base::OnceCallback<void(std::string)> terminate_callback) {
terminate_gpu_cb_ = std::move(terminate_callback);
}
void WaylandConnection::StartDrag(const ui::OSExchangeData& data, void WaylandConnection::StartDrag(const ui::OSExchangeData& data,
int operation) { int operation) {
if (!dragdrop_data_source_) if (!dragdrop_data_source_)
...@@ -348,12 +256,6 @@ void WaylandConnection::OnFileCanReadWithoutBlocking(int fd) { ...@@ -348,12 +256,6 @@ void WaylandConnection::OnFileCanReadWithoutBlocking(int fd) {
void WaylandConnection::OnFileCanWriteWithoutBlocking(int fd) {} void WaylandConnection::OnFileCanWriteWithoutBlocking(int fd) {}
void WaylandConnection::TerminateGpuProcess(std::string reason) {
DCHECK(!reason.empty());
std::move(terminate_gpu_cb_).Run(std::move(reason));
// The GPU process' failure results in calling ::OnChannelDestroyed.
}
void WaylandConnection::EnsureDataDevice() { void WaylandConnection::EnsureDataDevice() {
if (!data_device_manager_ || !seat_) if (!data_device_manager_ || !seat_)
return; return;
...@@ -398,10 +300,6 @@ void WaylandConnection::Global(void* data, ...@@ -398,10 +300,6 @@ void WaylandConnection::Global(void* data,
connection->shm_ = std::make_unique<WaylandShm>(shm.release(), connection); connection->shm_ = std::make_unique<WaylandShm>(shm.release(), connection);
if (!connection->shm_) if (!connection->shm_)
LOG(ERROR) << "Failed to bind to wl_shm global"; LOG(ERROR) << "Failed to bind to wl_shm global";
if (!connection->buffer_manager_) {
connection->buffer_manager_ =
std::make_unique<WaylandBufferManager>(connection);
}
} else if (!connection->seat_ && strcmp(interface, "wl_seat") == 0) { } else if (!connection->seat_ && strcmp(interface, "wl_seat") == 0) {
connection->seat_ = connection->seat_ =
wl::Bind<wl_seat>(registry, name, std::min(version, kMaxSeatVersion)); wl::Bind<wl_seat>(registry, name, std::min(version, kMaxSeatVersion));
...@@ -474,10 +372,6 @@ void WaylandConnection::Global(void* data, ...@@ -474,10 +372,6 @@ void WaylandConnection::Global(void* data,
registry, name, std::min(version, kMaxLinuxDmabufVersion)); registry, name, std::min(version, kMaxLinuxDmabufVersion));
connection->zwp_dmabuf_ = std::make_unique<WaylandZwpLinuxDmabuf>( connection->zwp_dmabuf_ = std::make_unique<WaylandZwpLinuxDmabuf>(
zwp_linux_dmabuf.release(), connection); zwp_linux_dmabuf.release(), connection);
if (!connection->buffer_manager_) {
connection->buffer_manager_ =
std::make_unique<WaylandBufferManager>(connection);
}
} else if (!connection->presentation_ && } else if (!connection->presentation_ &&
(strcmp(interface, "wp_presentation") == 0)) { (strcmp(interface, "wp_presentation") == 0)) {
connection->presentation_ = connection->presentation_ =
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/files/file.h" #include "base/files/file.h"
#include "base/message_loop/message_pump_libevent.h" #include "base/message_loop/message_pump_libevent.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
...@@ -26,18 +25,16 @@ ...@@ -26,18 +25,16 @@
#include "ui/ozone/platform/wayland/host/wayland_output.h" #include "ui/ozone/platform/wayland/host/wayland_output.h"
#include "ui/ozone/platform/wayland/host/wayland_pointer.h" #include "ui/ozone/platform/wayland/host/wayland_pointer.h"
#include "ui/ozone/platform/wayland/host/wayland_touch.h" #include "ui/ozone/platform/wayland/host/wayland_touch.h"
#include "ui/ozone/public/interfaces/wayland/wayland_connection.mojom.h"
namespace ui { namespace ui {
class WaylandBufferManager; class WaylandBufferManagerHost;
class WaylandOutputManager; class WaylandOutputManager;
class WaylandWindow; class WaylandWindow;
class WaylandZwpLinuxDmabuf; class WaylandZwpLinuxDmabuf;
class WaylandShm; class WaylandShm;
class WaylandConnection : public PlatformEventSource, class WaylandConnection : public PlatformEventSource,
public ozone::mojom::WaylandConnection,
public base::MessagePumpLibevent::FdWatcher { public base::MessagePumpLibevent::FdWatcher {
public: public:
WaylandConnection(); WaylandConnection();
...@@ -46,58 +43,6 @@ class WaylandConnection : public PlatformEventSource, ...@@ -46,58 +43,6 @@ class WaylandConnection : public PlatformEventSource,
bool Initialize(); bool Initialize();
bool StartProcessingEvents(); bool StartProcessingEvents();
// ozone::mojom::WaylandConnection overrides:
//
// These overridden methods below are invoked by the GPU when hardware
// accelerated rendering is used.
void SetWaylandConnectionClient(
ozone::mojom::WaylandConnectionClientAssociatedPtrInfo client) override;
//
// Called by the GPU and asks to import a wl_buffer based on a gbm file
// descriptor using zwp_linux_dmabuf protocol. Check comments in the
// ui/ozone/public/interfaces/wayland/wayland_connection.mojom.
void CreateDmabufBasedBuffer(gfx::AcceleratedWidget widget,
mojo::ScopedHandle 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;
// 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/interfaces/wayland/wayland_connection.mojom.
void CreateShmBasedBuffer(gfx::AcceleratedWidget widget,
mojo::ScopedHandle 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|.
void DestroyBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id) override;
// Called by the GPU and asks to attach a wl_buffer with a |buffer_id| to a
// WaylandWindow with the specified |widget|.
// Calls OnSubmission and OnPresentation on successful swap and pixels
// presented.
void CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::Rect& damage_region) override;
// These methods are exclusively used by the WaylandBufferManager to notify
// the |client_associated_ptr_| about buffer swaps' results.
// TODO(msisov): move these and the above mojo methods into the
// WaylandBufferManager and establish end-to-end communication with
// WaylandBufferManagerGpu and WaylandBufferManagerHost instead (basically, to
// avoid having the WaylandConnection as proxy in between).
// https://crbug.com/947411
void OnSubmission(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::SwapResult& swap_result);
void OnPresentation(gfx::AcceleratedWidget widget,
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback);
// Schedules a flush of the Wayland connection. // Schedules a flush of the Wayland connection.
void ScheduleFlush(); void ScheduleFlush();
...@@ -146,25 +91,16 @@ class WaylandConnection : public PlatformEventSource, ...@@ -146,25 +91,16 @@ class WaylandConnection : public PlatformEventSource,
return wayland_cursor_position_.get(); return wayland_cursor_position_.get();
} }
WaylandBufferManager* buffer_manager() const { return buffer_manager_.get(); } WaylandBufferManagerHost* buffer_manager_host() const {
return buffer_manager_host_.get();
}
WaylandZwpLinuxDmabuf* zwp_dmabuf() const { return zwp_dmabuf_.get(); } WaylandZwpLinuxDmabuf* zwp_dmabuf() const { return zwp_dmabuf_.get(); }
WaylandShm* shm() const { return shm_.get(); } WaylandShm* shm() const { return shm_.get(); }
// Returns bound pointer to own mojo interface.
ozone::mojom::WaylandConnectionPtr 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();
std::vector<gfx::BufferFormat> GetSupportedBufferFormats(); std::vector<gfx::BufferFormat> GetSupportedBufferFormats();
void SetTerminateGpuCallback(
base::OnceCallback<void(std::string)> terminate_gpu_cb);
// Starts drag with |data| to be delivered, |operation| supported by the // Starts drag with |data| to be delivered, |operation| supported by the
// source side initiated the dragging. // source side initiated the dragging.
void StartDrag(const ui::OSExchangeData& data, int operation); void StartDrag(const ui::OSExchangeData& data, int operation);
...@@ -206,9 +142,6 @@ class WaylandConnection : public PlatformEventSource, ...@@ -206,9 +142,6 @@ class WaylandConnection : public PlatformEventSource,
void OnFileCanReadWithoutBlocking(int fd) override; void OnFileCanReadWithoutBlocking(int fd) override;
void OnFileCanWriteWithoutBlocking(int fd) override; void OnFileCanWriteWithoutBlocking(int fd) override;
// Terminates the GPU process on invalid data received
void TerminateGpuProcess(std::string reason);
// Make sure data device is properly initialized // Make sure data device is properly initialized
void EnsureDataDevice(); void EnsureDataDevice();
...@@ -253,9 +186,7 @@ class WaylandConnection : public PlatformEventSource, ...@@ -253,9 +186,7 @@ class WaylandConnection : public PlatformEventSource,
std::unique_ptr<WaylandCursorPosition> wayland_cursor_position_; std::unique_ptr<WaylandCursorPosition> wayland_cursor_position_;
std::unique_ptr<WaylandZwpLinuxDmabuf> zwp_dmabuf_; std::unique_ptr<WaylandZwpLinuxDmabuf> zwp_dmabuf_;
std::unique_ptr<WaylandShm> shm_; std::unique_ptr<WaylandShm> shm_;
std::unique_ptr<WaylandBufferManagerHost> buffer_manager_host_;
// Objects that are using when GPU runs in own process.
std::unique_ptr<WaylandBufferManager> buffer_manager_;
bool scheduled_flush_ = false; bool scheduled_flush_ = false;
bool watching_ = false; bool watching_ = false;
...@@ -263,13 +194,6 @@ class WaylandConnection : public PlatformEventSource, ...@@ -263,13 +194,6 @@ class WaylandConnection : public PlatformEventSource,
uint32_t serial_ = 0; uint32_t serial_ = 0;
ozone::mojom::WaylandConnectionClientAssociatedPtr client_associated_ptr_;
mojo::Binding<ozone::mojom::WaylandConnection> binding_;
// 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_;
DISALLOW_COPY_AND_ASSIGN(WaylandConnection); DISALLOW_COPY_AND_ASSIGN(WaylandConnection);
}; };
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
#include "ui/gfx/linux/client_native_pixmap_dmabuf.h" #include "ui/gfx/linux/client_native_pixmap_dmabuf.h"
#include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/common/stub_overlay_manager.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_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.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_connection.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_connection_connector.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"
#include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
...@@ -86,7 +86,8 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -86,7 +86,8 @@ class OzonePlatformWayland : public OzonePlatform {
} }
GpuPlatformSupportHost* GetGpuPlatformSupportHost() override { GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
return connector_ ? connector_.get() : gpu_platform_support_host_.get(); return buffer_manager_connector_ ? buffer_manager_connector_.get()
: gpu_platform_support_host_.get();
} }
std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override { std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override {
...@@ -154,13 +155,14 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -154,13 +155,14 @@ class OzonePlatformWayland : public OzonePlatform {
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
std::make_unique<StubKeyboardLayoutEngine>()); std::make_unique<StubKeyboardLayoutEngine>());
#endif #endif
connection_.reset(new WaylandConnection); connection_ = std::make_unique<WaylandConnection>();
if (!connection_->Initialize()) if (!connection_->Initialize())
LOG(FATAL) << "Failed to initialize Wayland platform"; LOG(FATAL) << "Failed to initialize Wayland platform";
connector_.reset(new WaylandConnectionConnector(connection_.get())); buffer_manager_connector_ = std::make_unique<WaylandBufferManagerConnector>(
cursor_factory_.reset(new BitmapCursorFactoryOzone); connection_->buffer_manager_host());
overlay_manager_.reset(new StubOverlayManager); cursor_factory_ = std::make_unique<BitmapCursorFactoryOzone>();
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_->GetSupportedBufferFormats(); supported_buffer_formats_ = connection_->GetSupportedBufferFormats();
...@@ -169,8 +171,9 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -169,8 +171,9 @@ class OzonePlatformWayland : public OzonePlatform {
void InitializeGPU(const InitParams& args) override { void InitializeGPU(const InitParams& args) override {
surface_factory_ = surface_factory_ =
std::make_unique<WaylandSurfaceFactory>(connection_.get()); std::make_unique<WaylandSurfaceFactory>(connection_.get());
proxy_ = std::make_unique<WaylandConnectionProxy>(surface_factory_.get()); buffer_manager_ =
surface_factory_->SetProxy(proxy_.get()); std::make_unique<WaylandBufferManagerGpu>(surface_factory_.get());
surface_factory_->SetBufferManager(buffer_manager_.get());
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
const base::FilePath drm_node_path = path_finder_.GetDrmRenderNodePath(); const base::FilePath drm_node_path = path_finder_.GetDrmRenderNodePath();
if (drm_node_path.empty()) { if (drm_node_path.empty()) {
...@@ -183,7 +186,7 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -183,7 +186,7 @@ class OzonePlatformWayland : public OzonePlatform {
auto gbm = CreateGbmDevice(handle.PassFD().release()); auto gbm = CreateGbmDevice(handle.PassFD().release());
if (!gbm) if (!gbm)
LOG(WARNING) << "Failed to initialize gbm device."; LOG(WARNING) << "Failed to initialize gbm device.";
proxy_->set_gbm_device(std::move(gbm)); buffer_manager_->set_gbm_device(std::move(gbm));
} }
} }
#endif #endif
...@@ -194,15 +197,15 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -194,15 +197,15 @@ class OzonePlatformWayland : public OzonePlatform {
} }
void AddInterfaces(service_manager::BinderRegistry* registry) override { void AddInterfaces(service_manager::BinderRegistry* registry) override {
registry->AddInterface<ozone::mojom::WaylandConnectionClient>( registry->AddInterface<ozone::mojom::WaylandBufferManagerGpu>(
base::BindRepeating( base::BindRepeating(
&OzonePlatformWayland::CreateWaylandConnectionClientBinding, &OzonePlatformWayland::CreateWaylandBufferManagerGpuBinding,
base::Unretained(this))); base::Unretained(this)));
} }
void CreateWaylandConnectionClientBinding( void CreateWaylandBufferManagerGpuBinding(
ozone::mojom::WaylandConnectionClientRequest request) { ozone::mojom::WaylandBufferManagerGpuRequest request) {
proxy_->AddBindingWaylandConnectionClient(std::move(request)); buffer_manager_->AddBindingWaylandBufferManagerGpu(std::move(request));
} }
private: private:
...@@ -214,14 +217,16 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -214,14 +217,16 @@ class OzonePlatformWayland : public OzonePlatform {
std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
std::unique_ptr<WaylandInputMethodContextFactory> std::unique_ptr<WaylandInputMethodContextFactory>
wayland_input_method_context_factory_; wayland_input_method_context_factory_;
std::unique_ptr<WaylandBufferManagerConnector> buffer_manager_connector_;
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
XkbEvdevCodes xkb_evdev_code_converter_; XkbEvdevCodes xkb_evdev_code_converter_;
#endif #endif
std::unique_ptr<WaylandConnectionProxy> proxy_; // Objects, which solely live in the GPU process.
std::unique_ptr<WaylandConnectionConnector> connector_; std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_;
// Provides supported buffer formats for native gpu memory buffers framework.
std::vector<gfx::BufferFormat> supported_buffer_formats_; std::vector<gfx::BufferFormat> supported_buffer_formats_;
// This is used both in the gpu and browser processes to find out if a drm // This is used both in the gpu and browser processes to find out if a drm
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#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/ozone/platform/wayland/gpu/wayland_surface_factory.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/platform_window/platform_window_init_properties.h" #include "ui/platform_window/platform_window_init_properties.h"
...@@ -33,9 +32,9 @@ WaylandTest::WaylandTest() ...@@ -33,9 +32,9 @@ WaylandTest::WaylandTest()
#endif #endif
connection_ = std::make_unique<WaylandConnection>(); connection_ = std::make_unique<WaylandConnection>();
surface_factory_ = std::make_unique<WaylandSurfaceFactory>(connection_.get()); surface_factory_ = std::make_unique<WaylandSurfaceFactory>(connection_.get());
connection_proxy_ = buffer_manager_gpu_ =
std::make_unique<WaylandConnectionProxy>(surface_factory_.get()); std::make_unique<WaylandBufferManagerGpu>(surface_factory_.get());
surface_factory_->SetProxy(connection_proxy_.get()); surface_factory_->SetBufferManager(buffer_manager_gpu_.get());
window_ = std::make_unique<WaylandWindow>(&delegate_, connection_.get()); window_ = std::make_unique<WaylandWindow>(&delegate_, connection_.get());
} }
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/buildflags.h" #include "ui/base/buildflags.h"
#include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.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_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h"
...@@ -30,8 +31,6 @@ namespace ui { ...@@ -30,8 +31,6 @@ namespace ui {
const uint32_t kXdgShellV5 = 5; const uint32_t kXdgShellV5 = 5;
const uint32_t kXdgShellV6 = 6; const uint32_t kXdgShellV6 = 6;
class WaylandSurfaceFactory;
// WaylandTest is a base class that sets up a display, window, and test server, // WaylandTest is a base class that sets up a display, window, and test server,
// and allows easy synchronization between them. // and allows easy synchronization between them.
class WaylandTest : public ::testing::TestWithParam<uint32_t> { class WaylandTest : public ::testing::TestWithParam<uint32_t> {
...@@ -52,7 +51,7 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> { ...@@ -52,7 +51,7 @@ class WaylandTest : public ::testing::TestWithParam<uint32_t> {
MockPlatformWindowDelegate delegate_; MockPlatformWindowDelegate delegate_;
std::unique_ptr<WaylandSurfaceFactory> surface_factory_; std::unique_ptr<WaylandSurfaceFactory> surface_factory_;
std::unique_ptr<WaylandConnectionProxy> connection_proxy_; std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_gpu_;
std::unique_ptr<WaylandConnection> connection_; std::unique_ptr<WaylandConnection> connection_;
std::unique_ptr<WaylandWindow> window_; std::unique_ptr<WaylandWindow> window_;
gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
......
...@@ -6,7 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -6,7 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("wayland_interfaces") { mojom("wayland_interfaces") {
sources = [ sources = [
"wayland_connection.mojom", "wayland_buffer_manager.mojom",
] ]
public_deps = [ public_deps = [
......
...@@ -10,11 +10,12 @@ import "ui/gfx/mojo/accelerated_widget.mojom"; ...@@ -10,11 +10,12 @@ import "ui/gfx/mojo/accelerated_widget.mojom";
import "ui/gfx/mojo/presentation_feedback.mojom"; import "ui/gfx/mojo/presentation_feedback.mojom";
import "ui/gfx/mojo/swap_result.mojom"; import "ui/gfx/mojo/swap_result.mojom";
// Used by the GPU for communication with a WaylandConnection on the browser // Used by the GPU for communication with the WaylandBufferManagerHost in
// process. // the browser process.
interface WaylandConnection { interface WaylandBufferManagerHost {
// Sets up an associated pipe between the Client and Host. // Sets up an associated pipe between the Gpu and Host.
SetWaylandConnectionClient(associated WaylandConnectionClient client); SetWaylandBufferManagerGpuPtr(
associated WaylandBufferManagerGpu buffer_manager_gpu_associated_ptr);
// The following two methods are used either for hardware accelerated // The following two methods are used either for hardware accelerated
// rendering or for the software rendering. // rendering or for the software rendering.
...@@ -67,10 +68,10 @@ interface WaylandConnection { ...@@ -67,10 +68,10 @@ interface WaylandConnection {
}; };
interface WaylandConnectionClient { interface WaylandBufferManagerGpu {
// Used by the browser process to provide the GPU process with a mojo ptr to a // Used by the browser process to provide the GPU process with a mojo ptr to a
// WaylandConnection, which lives on the browser process. // WaylandBufferManagerHost, which lives in the browser process.
SetWaylandConnection(WaylandConnection wc_ptr); SetWaylandBufferManagerHost(WaylandBufferManagerHost buffer_manager_host_ptr);
// The browser process may request the client to reset gbm device instance to // The browser process may request the client to reset gbm device instance to
// avoid using zwp_linux_dmabuf protocol, which means using wl_egl_surface in // avoid using zwp_linux_dmabuf protocol, which means using wl_egl_surface in
......
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