Commit a9cfb2f7 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

[ozone/wayland] Prepare WaylandCanvasSurface for completion callbacks

This is a prerequisite CL to make WaylandCanvasSurface listen
to OnSubmission and OnPresentation callbacks.

The following changes have been made to avoid code duplicates:
* Added WaylandSurfaceGpu interface, which has two methods:
  OnSubmission and OnPresentation.
* Moved RegisterSurface, UnregisterSurface, GetSurface from
  WaylandSurfaceFactory to WaylandBufferManagerGpu
* Overrode WaylandSurfaceGpu methods in:
  ** GbmSurfacelessWayland and removed usage of WaylandSurfaceFactory. Now, everything
     is managed by the WaylandBufferManagerGpu instead.
  ** WaylandCanvasSurface and added NOTIMPLEMENTED. The idea
     is to propagate the results to a VSyncProvider and avoid
     tearing when submitting new frames.

Bug: 963854
Change-Id: Ia91b359e505c152512db244b540d175ce1eeb0aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640977Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#665830}
parent f797f143
...@@ -30,6 +30,7 @@ source_set("wayland") { ...@@ -30,6 +30,7 @@ source_set("wayland") {
"gpu/wayland_canvas_surface.h", "gpu/wayland_canvas_surface.h",
"gpu/wayland_surface_factory.cc", "gpu/wayland_surface_factory.cc",
"gpu/wayland_surface_factory.h", "gpu/wayland_surface_factory.h",
"gpu/wayland_surface_gpu.h",
"host/wayland_buffer_manager_connector.cc", "host/wayland_buffer_manager_connector.cc",
"host/wayland_buffer_manager_connector.h", "host/wayland_buffer_manager_connector.h",
"host/wayland_buffer_manager_host.cc", "host/wayland_buffer_manager_host.cc",
......
...@@ -22,18 +22,14 @@ ...@@ -22,18 +22,14 @@
#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_buffer_manager_gpu.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/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"
namespace ui { namespace ui {
GbmPixmapWayland::GbmPixmapWayland(WaylandSurfaceFactory* surface_manager, GbmPixmapWayland::GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager,
WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget) gfx::AcceleratedWidget widget)
: surface_manager_(surface_manager), : buffer_manager_(buffer_manager), widget_(widget) {}
buffer_manager_(buffer_manager),
widget_(widget) {}
GbmPixmapWayland::~GbmPixmapWayland() { GbmPixmapWayland::~GbmPixmapWayland() {
if (gbm_bo_ && widget_ != gfx::kNullAcceleratedWidget) if (gbm_bo_ && widget_ != gfx::kNullAcceleratedWidget)
...@@ -130,8 +126,12 @@ bool GbmPixmapWayland::ScheduleOverlayPlane( ...@@ -130,8 +126,12 @@ bool GbmPixmapWayland::ScheduleOverlayPlane(
const gfx::RectF& crop_rect, const gfx::RectF& crop_rect,
bool enable_blend, bool enable_blend,
std::unique_ptr<gfx::GpuFence> gpu_fence) { std::unique_ptr<gfx::GpuFence> gpu_fence) {
GbmSurfacelessWayland* surfaceless = surface_manager_->GetSurface(widget); auto* surface = buffer_manager_->GetSurface(widget);
DCHECK(surface);
GbmSurfacelessWayland* surfaceless =
static_cast<GbmSurfacelessWayland*>(surface);
DCHECK(surfaceless); DCHECK(surfaceless);
surfaceless->QueueOverlayPlane( surfaceless->QueueOverlayPlane(
OverlayPlane(this, std::move(gpu_fence), plane_z_order, plane_transform, OverlayPlane(this, std::move(gpu_fence), plane_z_order, plane_transform,
display_bounds, crop_rect, enable_blend)); display_bounds, crop_rect, enable_blend));
......
...@@ -17,13 +17,11 @@ ...@@ -17,13 +17,11 @@
namespace ui { namespace ui {
class WaylandSurfaceFactory;
class WaylandBufferManagerGpu; class WaylandBufferManagerGpu;
class GbmPixmapWayland : public gfx::NativePixmap { class GbmPixmapWayland : public gfx::NativePixmap {
public: public:
GbmPixmapWayland(WaylandSurfaceFactory* surface_manager, GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager,
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.
...@@ -58,8 +56,6 @@ class GbmPixmapWayland : public gfx::NativePixmap { ...@@ -58,8 +56,6 @@ class GbmPixmapWayland : public gfx::NativePixmap {
// gbm_bo wrapper for struct gbm_bo. // gbm_bo wrapper for struct gbm_bo.
std::unique_ptr<GbmBuffer> gbm_bo_; std::unique_ptr<GbmBuffer> gbm_bo_;
WaylandSurfaceFactory* const surface_manager_;
// Represents a connection to Wayland. // Represents a connection to Wayland.
WaylandBufferManagerGpu* const buffer_manager_; WaylandBufferManagerGpu* const buffer_manager_;
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#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_buffer_manager_gpu.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h"
namespace ui { namespace ui {
...@@ -27,17 +26,15 @@ void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { ...@@ -27,17 +26,15 @@ void WaitForFence(EGLDisplay display, EGLSyncKHR fence) {
} // namespace } // namespace
GbmSurfacelessWayland::GbmSurfacelessWayland( GbmSurfacelessWayland::GbmSurfacelessWayland(
WaylandSurfaceFactory* surface_factory,
WaylandBufferManagerGpu* buffer_manager, WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget) gfx::AcceleratedWidget widget)
: SurfacelessEGL(gfx::Size()), : SurfacelessEGL(gfx::Size()),
surface_factory_(surface_factory),
buffer_manager_(buffer_manager), 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")),
weak_factory_(this) { weak_factory_(this) {
surface_factory_->RegisterSurface(widget_, this); buffer_manager_->RegisterSurface(widget_, this);
unsubmitted_frames_.push_back(std::make_unique<PendingFrame>()); unsubmitted_frames_.push_back(std::make_unique<PendingFrame>());
} }
...@@ -168,7 +165,7 @@ void GbmSurfacelessWayland::SetRelyOnImplicitSync() { ...@@ -168,7 +165,7 @@ void GbmSurfacelessWayland::SetRelyOnImplicitSync() {
} }
GbmSurfacelessWayland::~GbmSurfacelessWayland() { GbmSurfacelessWayland::~GbmSurfacelessWayland() {
surface_factory_->UnregisterSurface(widget_); buffer_manager_->UnregisterSurface(widget_);
} }
GbmSurfacelessWayland::PendingFrame::PendingFrame() {} GbmSurfacelessWayland::PendingFrame::PendingFrame() {}
......
...@@ -11,22 +11,22 @@ ...@@ -11,22 +11,22 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_surface_egl.h" #include "ui/gl/gl_surface_egl.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
#include "ui/ozone/public/overlay_plane.h" #include "ui/ozone/public/overlay_plane.h"
#include "ui/ozone/public/swap_completion_callback.h" #include "ui/ozone/public/swap_completion_callback.h"
namespace ui { namespace ui {
class WaylandBufferManagerGpu; class WaylandBufferManagerGpu;
class WaylandSurfaceFactory;
// A GLSurface for Wayland Ozone platform that uses surfaceless drawing. Drawing // A GLSurface for Wayland Ozone platform that uses surfaceless drawing. Drawing
// and displaying happens directly through NativePixmap buffers. CC would call // and displaying happens directly through NativePixmap buffers. CC would call
// into SurfaceFactoryOzone to allocate the buffers and then call // into SurfaceFactoryOzone to allocate the buffers and then call
// ScheduleOverlayPlane(..) to schedule the buffer for presentation. // ScheduleOverlayPlane(..) to schedule the buffer for presentation.
class GbmSurfacelessWayland : public gl::SurfacelessEGL { class GbmSurfacelessWayland : public gl::SurfacelessEGL,
public WaylandSurfaceGpu {
public: public:
GbmSurfacelessWayland(WaylandSurfaceFactory* surface_factory, GbmSurfacelessWayland(WaylandBufferManagerGpu* buffer_manager,
WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget); gfx::AcceleratedWidget widget);
void QueueOverlayPlane(OverlayPlane plane); void QueueOverlayPlane(OverlayPlane plane);
...@@ -58,13 +58,15 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL { ...@@ -58,13 +58,15 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL {
EGLConfig GetConfig() override; EGLConfig GetConfig() override;
void SetRelyOnImplicitSync() override; void SetRelyOnImplicitSync() override;
void OnSubmission(uint32_t buffer_id, const gfx::SwapResult& swap_result);
void OnPresentation(uint32_t buffer_id,
const gfx::PresentationFeedback& feedback);
private: private:
~GbmSurfacelessWayland() override; ~GbmSurfacelessWayland() override;
// WaylandSurfaceGpu overrides:
void OnSubmission(uint32_t buffer_id,
const gfx::SwapResult& swap_result) override;
void OnPresentation(uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) override;
struct PendingFrame { struct PendingFrame {
PendingFrame(); PendingFrame();
~PendingFrame(); ~PendingFrame();
...@@ -91,7 +93,6 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL { ...@@ -91,7 +93,6 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL {
EGLSyncKHR InsertFence(bool implicit); EGLSyncKHR InsertFence(bool implicit);
void FenceRetired(PendingFrame* frame); void FenceRetired(PendingFrame* frame);
WaylandSurfaceFactory* const surface_factory_;
WaylandBufferManagerGpu* const buffer_manager_; WaylandBufferManagerGpu* const buffer_manager_;
std::vector<OverlayPlane> planes_; std::vector<OverlayPlane> planes_;
......
...@@ -12,13 +12,12 @@ ...@@ -12,13 +12,12 @@
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
#include "ui/ozone/common/linux/drm_util_linux.h" #include "ui/ozone/common/linux/drm_util_linux.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_surface_factory.h" #include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
namespace ui { namespace ui {
WaylandBufferManagerGpu::WaylandBufferManagerGpu(WaylandSurfaceFactory* factory) WaylandBufferManagerGpu::WaylandBufferManagerGpu()
: factory_(factory), : associated_binding_(this),
associated_binding_(this),
gpu_thread_runner_(base::ThreadTaskRunnerHandle::Get()) {} gpu_thread_runner_(base::ThreadTaskRunnerHandle::Get()) {}
WaylandBufferManagerGpu::~WaylandBufferManagerGpu() = default; WaylandBufferManagerGpu::~WaylandBufferManagerGpu() = default;
...@@ -43,7 +42,7 @@ void WaylandBufferManagerGpu::OnSubmission(gfx::AcceleratedWidget widget, ...@@ -43,7 +42,7 @@ void WaylandBufferManagerGpu::OnSubmission(gfx::AcceleratedWidget widget,
gfx::SwapResult swap_result) { gfx::SwapResult swap_result) {
DCHECK(gpu_thread_runner_->BelongsToCurrentThread()); DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
DCHECK_NE(widget, gfx::kNullAcceleratedWidget); DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
auto* surface = factory_->GetSurface(widget); auto* surface = GetSurface(widget);
// There can be a race between destruction and submitting the last frames. The // There can be a race between destruction and submitting the last frames. The
// surface can be destroyed by the time the host receives a request to destroy // surface can be destroyed by the time the host receives a request to destroy
// a buffer, and is able to call the OnSubmission for that specific buffer. // a buffer, and is able to call the OnSubmission for that specific buffer.
...@@ -57,7 +56,7 @@ void WaylandBufferManagerGpu::OnPresentation( ...@@ -57,7 +56,7 @@ void WaylandBufferManagerGpu::OnPresentation(
const gfx::PresentationFeedback& feedback) { const gfx::PresentationFeedback& feedback) {
DCHECK(gpu_thread_runner_->BelongsToCurrentThread()); DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
DCHECK_NE(widget, gfx::kNullAcceleratedWidget); DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
auto* surface = factory_->GetSurface(widget); auto* surface = GetSurface(widget);
// There can be a race between destruction and presenting the last frames. The // There can be a race between destruction and presenting the last frames. The
// surface can be destroyed by the time the host receives a request to destroy // surface can be destroyed by the time the host receives a request to destroy
// a buffer, and is able to call the OnPresentation for that specific buffer. // a buffer, and is able to call the OnPresentation for that specific buffer.
...@@ -65,6 +64,24 @@ void WaylandBufferManagerGpu::OnPresentation( ...@@ -65,6 +64,24 @@ void WaylandBufferManagerGpu::OnPresentation(
surface->OnPresentation(buffer_id, feedback); surface->OnPresentation(buffer_id, feedback);
} }
void WaylandBufferManagerGpu::RegisterSurface(gfx::AcceleratedWidget widget,
WaylandSurfaceGpu* surface) {
widget_to_surface_map_.insert(std::make_pair(widget, surface));
}
void WaylandBufferManagerGpu::UnregisterSurface(gfx::AcceleratedWidget widget) {
widget_to_surface_map_.erase(widget);
}
WaylandSurfaceGpu* WaylandBufferManagerGpu::GetSurface(
gfx::AcceleratedWidget widget) const {
WaylandSurfaceGpu* surface = nullptr;
auto it = widget_to_surface_map_.find(widget);
if (it != widget_to_surface_map_.end())
surface = it->second;
return surface;
}
void WaylandBufferManagerGpu::CreateDmabufBasedBuffer( void WaylandBufferManagerGpu::CreateDmabufBasedBuffer(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
base::ScopedFD dmabuf_fd, base::ScopedFD dmabuf_fd,
......
...@@ -28,7 +28,7 @@ class Rect; ...@@ -28,7 +28,7 @@ class Rect;
namespace ui { namespace ui {
class WaylandConnection; class WaylandConnection;
class WaylandSurfaceFactory; class WaylandSurfaceGpu;
class WaylandWindow; class WaylandWindow;
// Forwards calls through an associated mojo connection to WaylandBufferManager // Forwards calls through an associated mojo connection to WaylandBufferManager
...@@ -40,7 +40,7 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -40,7 +40,7 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
public: public:
using BufferManagerHostPtr = ozone::mojom::WaylandBufferManagerHostPtr; using BufferManagerHostPtr = ozone::mojom::WaylandBufferManagerHostPtr;
explicit WaylandBufferManagerGpu(WaylandSurfaceFactory* factory); WaylandBufferManagerGpu();
~WaylandBufferManagerGpu() override; ~WaylandBufferManagerGpu() override;
// WaylandBufferManagerGpu overrides: // WaylandBufferManagerGpu overrides:
...@@ -59,6 +59,15 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -59,6 +59,15 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
uint32_t buffer_id, uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) override; const gfx::PresentationFeedback& feedback) override;
// If the client, which uses this manager and implements WaylandSurfaceGpu,
// wants to receive OnSubmission and OnPresentation callbacks and know the
// result of the below operations, they must register themselves with the
// below APIs.
void RegisterSurface(gfx::AcceleratedWidget widget,
WaylandSurfaceGpu* surface);
void UnregisterSurface(gfx::AcceleratedWidget widget);
WaylandSurfaceGpu* GetSurface(gfx::AcceleratedWidget widget) const;
// Methods, which can be used when in both in-process-gpu and out of process // Methods, which can be used when in both in-process-gpu and out of process
// modes. These calls are forwarded to the browser process through the // modes. These calls are forwarded to the browser process through the
// WaylandConnection mojo interface. See more in // WaylandConnection mojo interface. See more in
...@@ -133,10 +142,6 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -133,10 +142,6 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
void BindHostInterface(); void BindHostInterface();
// Non-owned. Only used to get registered surfaces and notify them about
// submission and presentation of buffers.
WaylandSurfaceFactory* const factory_;
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
// A DRM render node based gbm device. // A DRM render node based gbm device.
std::unique_ptr<GbmDevice> gbm_device_; std::unique_ptr<GbmDevice> gbm_device_;
...@@ -160,6 +165,8 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu { ...@@ -160,6 +165,8 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
// CommitBuffer call. // CommitBuffer call.
scoped_refptr<base::SingleThreadTaskRunner> gpu_thread_runner_; scoped_refptr<base::SingleThreadTaskRunner> gpu_thread_runner_;
std::map<gfx::AcceleratedWidget, WaylandSurfaceGpu*> widget_to_surface_map_;
DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerGpu); DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerGpu);
}; };
......
...@@ -28,9 +28,13 @@ void DeleteSharedMemoryMapping(void* pixels, void* context) { ...@@ -28,9 +28,13 @@ void DeleteSharedMemoryMapping(void* pixels, void* context) {
WaylandCanvasSurface::WaylandCanvasSurface( WaylandCanvasSurface::WaylandCanvasSurface(
WaylandBufferManagerGpu* buffer_manager, WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget) gfx::AcceleratedWidget widget)
: buffer_manager_(buffer_manager), widget_(widget) {} : buffer_manager_(buffer_manager), widget_(widget) {
buffer_manager_->RegisterSurface(widget_, this);
}
WaylandCanvasSurface::~WaylandCanvasSurface() { WaylandCanvasSurface::~WaylandCanvasSurface() {
buffer_manager_->UnregisterSurface(widget_);
if (sk_surface_) if (sk_surface_)
buffer_manager_->DestroyBuffer(widget_, buffer_id_); buffer_manager_->DestroyBuffer(widget_, buffer_id_);
} }
...@@ -86,17 +90,27 @@ void WaylandCanvasSurface::ResizeCanvas(const gfx::Size& viewport_size) { ...@@ -86,17 +90,27 @@ 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
// callbacks.
buffer_manager_->CommitBuffer(widget_, buffer_id_, damage); buffer_manager_->CommitBuffer(widget_, buffer_id_, damage);
} }
std::unique_ptr<gfx::VSyncProvider> std::unique_ptr<gfx::VSyncProvider>
WaylandCanvasSurface::CreateVSyncProvider() { WaylandCanvasSurface::CreateVSyncProvider() {
// TODO(https://crbug.com/930662): This can be implemented with information // TODO(https://crbug.com/930662): This can be implemented with information
// from frame callbacks, and possibly output refresh rate. // from presentation feedback.
NOTIMPLEMENTED_LOG_ONCE(); NOTIMPLEMENTED_LOG_ONCE();
return nullptr; return nullptr;
} }
void WaylandCanvasSurface::OnSubmission(uint32_t buffer_id,
const gfx::SwapResult& swap_result) {
NOTIMPLEMENTED_LOG_ONCE();
}
void WaylandCanvasSurface::OnPresentation(
uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) {
// TODO(https://crbug.com/930662): this can be used for the vsync provider.
NOTIMPLEMENTED_LOG_ONCE();
}
} // namespace ui } // namespace ui
...@@ -12,13 +12,15 @@ ...@@ -12,13 +12,15 @@
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
#include "ui/ozone/public/surface_ozone_canvas.h" #include "ui/ozone/public/surface_ozone_canvas.h"
namespace ui { namespace ui {
class WaylandBufferManagerGpu; class WaylandBufferManagerGpu;
class WaylandCanvasSurface : public SurfaceOzoneCanvas { class WaylandCanvasSurface : public SurfaceOzoneCanvas,
public WaylandSurfaceGpu {
public: public:
WaylandCanvasSurface(WaylandBufferManagerGpu* buffer_manager, WaylandCanvasSurface(WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget); gfx::AcceleratedWidget widget);
...@@ -31,6 +33,12 @@ class WaylandCanvasSurface : public SurfaceOzoneCanvas { ...@@ -31,6 +33,12 @@ class WaylandCanvasSurface : public SurfaceOzoneCanvas {
std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override; std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override;
private: private:
// WaylandSurfaceGpu overrides:
void OnSubmission(uint32_t buffer_id,
const gfx::SwapResult& swap_result) override;
void OnPresentation(uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) override;
void OnGetSizeForWidget(const gfx::Size& widget_size) { size_ = widget_size; } void OnGetSizeForWidget(const gfx::Size& widget_size) { size_ = widget_size; }
WaylandBufferManagerGpu* const buffer_manager_; WaylandBufferManagerGpu* const buffer_manager_;
......
...@@ -30,11 +30,8 @@ namespace { ...@@ -30,11 +30,8 @@ namespace {
class GLOzoneEGLWayland : public GLOzoneEGL { class GLOzoneEGLWayland : public GLOzoneEGL {
public: public:
GLOzoneEGLWayland(WaylandConnection* connection, GLOzoneEGLWayland(WaylandConnection* connection,
WaylandBufferManagerGpu* buffer_manager, WaylandBufferManagerGpu* buffer_manager)
WaylandSurfaceFactory* factory) : connection_(connection), buffer_manager_(buffer_manager) {}
: connection_(connection),
buffer_manager_(buffer_manager),
factory_(factory) {}
~GLOzoneEGLWayland() override {} ~GLOzoneEGLWayland() override {}
scoped_refptr<gl::GLSurface> CreateViewGLSurface( scoped_refptr<gl::GLSurface> CreateViewGLSurface(
...@@ -53,7 +50,6 @@ class GLOzoneEGLWayland : public GLOzoneEGL { ...@@ -53,7 +50,6 @@ class GLOzoneEGLWayland : public GLOzoneEGL {
private: private:
WaylandConnection* const connection_; WaylandConnection* const connection_;
WaylandBufferManagerGpu* const buffer_manager_; WaylandBufferManagerGpu* const buffer_manager_;
WaylandSurfaceFactory* const factory_;
DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLWayland); DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLWayland);
}; };
...@@ -79,8 +75,6 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateViewGLSurface( ...@@ -79,8 +75,6 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateViewGLSurface(
scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface( scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface(
gfx::AcceleratedWidget window) { gfx::AcceleratedWidget window) {
DCHECK(factory_);
// Only EGLGLES2 is supported with surfaceless view gl. // Only EGLGLES2 is supported with surfaceless view gl.
if (gl::GetGLImplementation() != gl::kGLImplementationEGLGLES2) if (gl::GetGLImplementation() != gl::kGLImplementationEGLGLES2)
return nullptr; return nullptr;
...@@ -90,7 +84,7 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface( ...@@ -90,7 +84,7 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface(
if (!buffer_manager_->gbm_device()) if (!buffer_manager_->gbm_device())
return nullptr; return nullptr;
return gl::InitializeGLSurface( return gl::InitializeGLSurface(
new GbmSurfacelessWayland(factory_, buffer_manager_, window)); new GbmSurfacelessWayland(buffer_manager_, window));
#else #else
return nullptr; return nullptr;
#endif #endif
...@@ -121,38 +115,15 @@ bool GLOzoneEGLWayland::LoadGLES2Bindings(gl::GLImplementation impl) { ...@@ -121,38 +115,15 @@ bool GLOzoneEGLWayland::LoadGLES2Bindings(gl::GLImplementation impl) {
} // namespace } // namespace
WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection) WaylandSurfaceFactory::WaylandSurfaceFactory(
: connection_(connection) {} WaylandConnection* connection,
WaylandBufferManagerGpu* buffer_manager)
WaylandSurfaceFactory::~WaylandSurfaceFactory() = default; : connection_(connection), buffer_manager_(buffer_manager) {
void WaylandSurfaceFactory::SetBufferManager(
WaylandBufferManagerGpu* buffer_manager) {
DCHECK(!buffer_manager_ && buffer_manager);
buffer_manager_ = buffer_manager;
egl_implementation_ = egl_implementation_ =
std::make_unique<GLOzoneEGLWayland>(connection_, buffer_manager_, this); std::make_unique<GLOzoneEGLWayland>(connection_, buffer_manager_);
}
void WaylandSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget,
GbmSurfacelessWayland* surface) {
widget_to_surface_map_.insert(std::make_pair(widget, surface));
}
void WaylandSurfaceFactory::UnregisterSurface(gfx::AcceleratedWidget widget) {
widget_to_surface_map_.erase(widget);
}
GbmSurfacelessWayland* WaylandSurfaceFactory::GetSurface(
gfx::AcceleratedWidget widget) const {
GbmSurfacelessWayland* surface = nullptr;
auto it = widget_to_surface_map_.find(widget);
if (it != widget_to_surface_map_.end())
surface = it->second;
return surface;
} }
WaylandSurfaceFactory::~WaylandSurfaceFactory() = default;
std::unique_ptr<SurfaceOzoneCanvas> std::unique_ptr<SurfaceOzoneCanvas>
WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) {
...@@ -188,7 +159,7 @@ scoped_refptr<gfx::NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( ...@@ -188,7 +159,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, buffer_manager_, widget); base::MakeRefCounted<GbmPixmapWayland>(buffer_manager_, widget);
if (!pixmap->InitializeBuffer(size, format, usage)) if (!pixmap->InitializeBuffer(size, format, usage))
return nullptr; return nullptr;
return pixmap; return pixmap;
......
...@@ -17,23 +17,15 @@ ...@@ -17,23 +17,15 @@
namespace ui { namespace ui {
class GbmSurfacelessWayland;
class WaylandConnection; class WaylandConnection;
class WaylandBufferManagerGpu; class WaylandBufferManagerGpu;
class WaylandSurfaceFactory : public SurfaceFactoryOzone { class WaylandSurfaceFactory : public SurfaceFactoryOzone {
public: public:
explicit WaylandSurfaceFactory(WaylandConnection* connection); WaylandSurfaceFactory(WaylandConnection* connection,
WaylandBufferManagerGpu* buffer_manager);
~WaylandSurfaceFactory() override; ~WaylandSurfaceFactory() override;
void SetBufferManager(WaylandBufferManagerGpu* buffer_manager);
// These methods are used, when a dmabuf based approach is used.
void RegisterSurface(gfx::AcceleratedWidget widget,
GbmSurfacelessWayland* surface);
void UnregisterSurface(gfx::AcceleratedWidget widget);
GbmSurfacelessWayland* GetSurface(gfx::AcceleratedWidget widget) const;
// SurfaceFactoryOzone overrides: // SurfaceFactoryOzone overrides:
std::vector<gl::GLImplementation> GetAllowedGLImplementations() override; std::vector<gl::GLImplementation> GetAllowedGLImplementations() override;
GLOzone* GetGLOzone(gl::GLImplementation implementation) override; GLOzone* GetGLOzone(gl::GLImplementation implementation) override;
...@@ -53,12 +45,9 @@ class WaylandSurfaceFactory : public SurfaceFactoryOzone { ...@@ -53,12 +45,9 @@ class WaylandSurfaceFactory : public SurfaceFactoryOzone {
private: private:
WaylandConnection* const connection_; WaylandConnection* const connection_;
WaylandBufferManagerGpu* buffer_manager_ = nullptr; WaylandBufferManagerGpu* const buffer_manager_;
std::unique_ptr<GLOzone> egl_implementation_; std::unique_ptr<GLOzone> egl_implementation_;
std::map<gfx::AcceleratedWidget, GbmSurfacelessWayland*>
widget_to_surface_map_;
DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactory); DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactory);
}; };
......
// 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.
#ifndef UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_SURFACE_GPU_H_
#define UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_SURFACE_GPU_H_
#include <memory>
#include "base/macros.h"
namespace gfx {
enum class SwapResult;
struct PresentationFeedback;
} // namespace gfx
namespace ui {
// This is a common interface for surfaces created in the GPU process. The
// purpose of this is receiving submission and presentation callbacks from the
// WaylandBufferManagerGpu whenever the browser process has completed presenting
// the buffer.
class WaylandSurfaceGpu {
public:
// Tells the surface the result of the last swap of buffer with the
// |buffer_id|.
virtual void OnSubmission(uint32_t buffer_id,
const gfx::SwapResult& swap_result) = 0;
// Tells the surface the result of the last presentation of buffer with the
// |buffer_id|.
virtual void OnPresentation(uint32_t buffer_id,
const gfx::PresentationFeedback& feedback) = 0;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_GPU_WAYLAND_SURFACE_GPU_H_
...@@ -169,11 +169,9 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -169,11 +169,9 @@ class OzonePlatformWayland : public OzonePlatform {
} }
void InitializeGPU(const InitParams& args) override { void InitializeGPU(const InitParams& args) override {
surface_factory_ = buffer_manager_ = std::make_unique<WaylandBufferManagerGpu>();
std::make_unique<WaylandSurfaceFactory>(connection_.get()); surface_factory_ = std::make_unique<WaylandSurfaceFactory>(
buffer_manager_ = connection_.get(), buffer_manager_.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()) {
......
...@@ -31,10 +31,9 @@ WaylandTest::WaylandTest() ...@@ -31,10 +31,9 @@ WaylandTest::WaylandTest()
std::make_unique<StubKeyboardLayoutEngine>()); std::make_unique<StubKeyboardLayoutEngine>());
#endif #endif
connection_ = std::make_unique<WaylandConnection>(); connection_ = std::make_unique<WaylandConnection>();
surface_factory_ = std::make_unique<WaylandSurfaceFactory>(connection_.get()); buffer_manager_gpu_ = std::make_unique<WaylandBufferManagerGpu>();
buffer_manager_gpu_ = surface_factory_ = std::make_unique<WaylandSurfaceFactory>(
std::make_unique<WaylandBufferManagerGpu>(surface_factory_.get()); connection_.get(), buffer_manager_gpu_.get());
surface_factory_->SetBufferManager(buffer_manager_gpu_.get());
window_ = std::make_unique<WaylandWindow>(&delegate_, connection_.get()); window_ = std::make_unique<WaylandWindow>(&delegate_, connection_.get());
} }
......
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