summarylogtreecommitdiffstats
path: root/0001-ozone-wayland-Prepare-WaylandCanvasSurface-for-compl.patch
blob: 33f83807507653c52f5641b98e688efa988c668d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
From a3ca8acd6582c0169ad3e2d94dd9fcd423810a56 Mon Sep 17 00:00:00 2001
From: Maksim Sisov <msisov@igalia.com>
Date: Tue, 4 Jun 2019 06:24:59 +0000
Subject: [PATCH 01/11] [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/+/1640977
Reviewed-by: Michael Spang <spang@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#665830}
---
 ui/ozone/platform/wayland/BUILD.gn            |  1 +
 .../wayland/gpu/gbm_pixmap_wayland.cc         | 14 +++---
 .../platform/wayland/gpu/gbm_pixmap_wayland.h |  6 +--
 .../wayland/gpu/gbm_surfaceless_wayland.cc    |  7 +--
 .../wayland/gpu/gbm_surfaceless_wayland.h     | 19 +++----
 .../wayland/gpu/wayland_buffer_manager_gpu.cc | 29 ++++++++---
 .../wayland/gpu/wayland_buffer_manager_gpu.h  | 19 ++++---
 .../wayland/gpu/wayland_canvas_surface.cc     | 22 +++++++--
 .../wayland/gpu/wayland_canvas_surface.h      | 10 +++-
 .../wayland/gpu/wayland_surface_factory.cc    | 49 ++++---------------
 .../wayland/gpu/wayland_surface_factory.h     | 17 ++-----
 .../wayland/gpu/wayland_surface_gpu.h         | 38 ++++++++++++++
 .../wayland/ozone_platform_wayland.cc         |  8 ++-
 .../platform/wayland/test/wayland_test.cc     |  7 ++-
 14 files changed, 141 insertions(+), 105 deletions(-)
 create mode 100644 ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h

diff --git a/ui/ozone/platform/wayland/BUILD.gn b/ui/ozone/platform/wayland/BUILD.gn
index 757349686e67..303173b4ba6c 100644
--- a/ui/ozone/platform/wayland/BUILD.gn
+++ b/ui/ozone/platform/wayland/BUILD.gn
@@ -30,6 +30,7 @@ source_set("wayland") {
     "gpu/wayland_canvas_surface.h",
     "gpu/wayland_surface_factory.cc",
     "gpu/wayland_surface_factory.h",
+    "gpu/wayland_surface_gpu.h",
     "host/wayland_buffer_manager_connector.cc",
     "host/wayland_buffer_manager_connector.h",
     "host/wayland_buffer_manager_host.cc",
diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
index ee088672f871..5d8167bdfd89 100644
--- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
+++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
@@ -22,18 +22,14 @@
 #include "ui/ozone/common/linux/gbm_device.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_surface_factory.h"
 #include "ui/ozone/public/overlay_plane.h"
 #include "ui/ozone/public/ozone_platform.h"
 
 namespace ui {
 
-GbmPixmapWayland::GbmPixmapWayland(WaylandSurfaceFactory* surface_manager,
-                                   WaylandBufferManagerGpu* buffer_manager,
+GbmPixmapWayland::GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager,
                                    gfx::AcceleratedWidget widget)
-    : surface_manager_(surface_manager),
-      buffer_manager_(buffer_manager),
-      widget_(widget) {}
+    : buffer_manager_(buffer_manager), widget_(widget) {}
 
 GbmPixmapWayland::~GbmPixmapWayland() {
   if (gbm_bo_ && widget_ != gfx::kNullAcceleratedWidget)
@@ -130,8 +126,12 @@ bool GbmPixmapWayland::ScheduleOverlayPlane(
     const gfx::RectF& crop_rect,
     bool enable_blend,
     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);
+
   surfaceless->QueueOverlayPlane(
       OverlayPlane(this, std::move(gpu_fence), plane_z_order, plane_transform,
                    display_bounds, crop_rect, enable_blend));
diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
index 566ffdcde4ff..b6051207d0f7 100644
--- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
+++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
@@ -17,13 +17,11 @@
 
 namespace ui {
 
-class WaylandSurfaceFactory;
 class WaylandBufferManagerGpu;
 
 class GbmPixmapWayland : public gfx::NativePixmap {
  public:
-  GbmPixmapWayland(WaylandSurfaceFactory* surface_manager,
-                   WaylandBufferManagerGpu* buffer_manager,
+  GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager,
                    gfx::AcceleratedWidget widget);
 
   // Creates a buffer object and initializes the pixmap buffer.
@@ -58,8 +56,6 @@ class GbmPixmapWayland : public gfx::NativePixmap {
   // gbm_bo wrapper for struct gbm_bo.
   std::unique_ptr<GbmBuffer> gbm_bo_;
 
-  WaylandSurfaceFactory* const surface_manager_;
-
   // Represents a connection to Wayland.
   WaylandBufferManagerGpu* const buffer_manager_;
 
diff --git a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
index 71e810c6c31c..70ea08acfa11 100644
--- a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
+++ b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
@@ -12,7 +12,6 @@
 #include "ui/gfx/gpu_fence.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_surface_factory.h"
 
 namespace ui {
 
@@ -27,17 +26,15 @@ void WaitForFence(EGLDisplay display, EGLSyncKHR fence) {
 }  // namespace
 
 GbmSurfacelessWayland::GbmSurfacelessWayland(
-    WaylandSurfaceFactory* surface_factory,
     WaylandBufferManagerGpu* buffer_manager,
     gfx::AcceleratedWidget widget)
     : SurfacelessEGL(gfx::Size()),
-      surface_factory_(surface_factory),
       buffer_manager_(buffer_manager),
       widget_(widget),
       has_implicit_external_sync_(
           HasEGLExtension("EGL_ARM_implicit_external_sync")),
       weak_factory_(this) {
-  surface_factory_->RegisterSurface(widget_, this);
+  buffer_manager_->RegisterSurface(widget_, this);
   unsubmitted_frames_.push_back(std::make_unique<PendingFrame>());
 }
 
@@ -168,7 +165,7 @@ void GbmSurfacelessWayland::SetRelyOnImplicitSync() {
 }
 
 GbmSurfacelessWayland::~GbmSurfacelessWayland() {
-  surface_factory_->UnregisterSurface(widget_);
+  buffer_manager_->UnregisterSurface(widget_);
 }
 
 GbmSurfacelessWayland::PendingFrame::PendingFrame() {}
diff --git a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h
index 69fc2c17479f..0f584991f60c 100644
--- a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h
+++ b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h
@@ -11,22 +11,22 @@
 #include "base/memory/weak_ptr.h"
 #include "ui/gfx/native_widget_types.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/swap_completion_callback.h"
 
 namespace ui {
 
 class WaylandBufferManagerGpu;
-class WaylandSurfaceFactory;
 
 // A GLSurface for Wayland Ozone platform that uses surfaceless drawing. Drawing
 // and displaying happens directly through NativePixmap buffers. CC would call
 // into SurfaceFactoryOzone to allocate the buffers and then call
 // ScheduleOverlayPlane(..) to schedule the buffer for presentation.
-class GbmSurfacelessWayland : public gl::SurfacelessEGL {
+class GbmSurfacelessWayland : public gl::SurfacelessEGL,
+                              public WaylandSurfaceGpu {
  public:
-  GbmSurfacelessWayland(WaylandSurfaceFactory* surface_factory,
-                        WaylandBufferManagerGpu* buffer_manager,
+  GbmSurfacelessWayland(WaylandBufferManagerGpu* buffer_manager,
                         gfx::AcceleratedWidget widget);
 
   void QueueOverlayPlane(OverlayPlane plane);
@@ -58,13 +58,15 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL {
   EGLConfig GetConfig() 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:
   ~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 {
     PendingFrame();
     ~PendingFrame();
@@ -91,7 +93,6 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL {
   EGLSyncKHR InsertFence(bool implicit);
   void FenceRetired(PendingFrame* frame);
 
-  WaylandSurfaceFactory* const surface_factory_;
   WaylandBufferManagerGpu* const buffer_manager_;
   std::vector<OverlayPlane> planes_;
 
diff --git a/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.cc b/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.cc
index fd619bf0a852..49c4903270bd 100644
--- a/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.cc
+++ b/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.cc
@@ -12,13 +12,12 @@
 #include "mojo/public/cpp/system/platform_handle.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/wayland_surface_factory.h"
+#include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
 
 namespace ui {
 
-WaylandBufferManagerGpu::WaylandBufferManagerGpu(WaylandSurfaceFactory* factory)
-    : factory_(factory),
-      associated_binding_(this),
+WaylandBufferManagerGpu::WaylandBufferManagerGpu()
+    : associated_binding_(this),
       gpu_thread_runner_(base::ThreadTaskRunnerHandle::Get()) {}
 
 WaylandBufferManagerGpu::~WaylandBufferManagerGpu() = default;
@@ -43,7 +42,7 @@ void WaylandBufferManagerGpu::OnSubmission(gfx::AcceleratedWidget widget,
                                            gfx::SwapResult swap_result) {
   DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
   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
   // 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.
@@ -57,7 +56,7 @@ void WaylandBufferManagerGpu::OnPresentation(
     const gfx::PresentationFeedback& feedback) {
   DCHECK(gpu_thread_runner_->BelongsToCurrentThread());
   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
   // 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.
@@ -65,6 +64,24 @@ void WaylandBufferManagerGpu::OnPresentation(
     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(
     gfx::AcceleratedWidget widget,
     base::ScopedFD dmabuf_fd,
diff --git a/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h b/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h
index 85daf467a3fe..d2185c8308fb 100644
--- a/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h
+++ b/ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h
@@ -28,7 +28,7 @@ class Rect;
 namespace ui {
 
 class WaylandConnection;
-class WaylandSurfaceFactory;
+class WaylandSurfaceGpu;
 class WaylandWindow;
 
 // Forwards calls through an associated mojo connection to WaylandBufferManager
@@ -40,7 +40,7 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
  public:
   using BufferManagerHostPtr = ozone::mojom::WaylandBufferManagerHostPtr;
 
-  explicit WaylandBufferManagerGpu(WaylandSurfaceFactory* factory);
+  WaylandBufferManagerGpu();
   ~WaylandBufferManagerGpu() override;
 
   // WaylandBufferManagerGpu overrides:
@@ -59,6 +59,15 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
                       uint32_t buffer_id,
                       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
   // modes. These calls are forwarded to the browser process through the
   // WaylandConnection mojo interface. See more in
@@ -133,10 +142,6 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
 
   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)
   // A DRM render node based gbm device.
   std::unique_ptr<GbmDevice> gbm_device_;
@@ -160,6 +165,8 @@ class WaylandBufferManagerGpu : public ozone::mojom::WaylandBufferManagerGpu {
   // CommitBuffer call.
   scoped_refptr<base::SingleThreadTaskRunner> gpu_thread_runner_;
 
+  std::map<gfx::AcceleratedWidget, WaylandSurfaceGpu*> widget_to_surface_map_;
+
   DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerGpu);
 };
 
diff --git a/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.cc b/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.cc
index c71c904ea5f6..6de24d7fd177 100644
--- a/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.cc
+++ b/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.cc
@@ -28,9 +28,13 @@ void DeleteSharedMemoryMapping(void* pixels, void* context) {
 WaylandCanvasSurface::WaylandCanvasSurface(
     WaylandBufferManagerGpu* buffer_manager,
     gfx::AcceleratedWidget widget)
-    : buffer_manager_(buffer_manager), widget_(widget) {}
+    : buffer_manager_(buffer_manager), widget_(widget) {
+  buffer_manager_->RegisterSurface(widget_, this);
+}
 
 WaylandCanvasSurface::~WaylandCanvasSurface() {
+  buffer_manager_->UnregisterSurface(widget_);
+
   if (sk_surface_)
     buffer_manager_->DestroyBuffer(widget_, buffer_id_);
 }
@@ -86,17 +90,27 @@ void WaylandCanvasSurface::ResizeCanvas(const gfx::Size& viewport_size) {
 }
 
 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);
 }
 
 std::unique_ptr<gfx::VSyncProvider>
 WaylandCanvasSurface::CreateVSyncProvider() {
   // 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();
   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
diff --git a/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.h b/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.h
index 4c73f63e0ca8..baa29a8baf65 100644
--- a/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.h
+++ b/ui/ozone/platform/wayland/gpu/wayland_canvas_surface.h
@@ -12,13 +12,15 @@
 #include "third_party/skia/include/core/SkSurface.h"
 #include "ui/gfx/geometry/size.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"
 
 namespace ui {
 
 class WaylandBufferManagerGpu;
 
-class WaylandCanvasSurface : public SurfaceOzoneCanvas {
+class WaylandCanvasSurface : public SurfaceOzoneCanvas,
+                             public WaylandSurfaceGpu {
  public:
   WaylandCanvasSurface(WaylandBufferManagerGpu* buffer_manager,
                        gfx::AcceleratedWidget widget);
@@ -31,6 +33,12 @@ class WaylandCanvasSurface : public SurfaceOzoneCanvas {
   std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override;
 
  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; }
 
   WaylandBufferManagerGpu* const buffer_manager_;
diff --git a/ui/ozone/platform/wayland/gpu/wayland_surface_factory.cc b/ui/ozone/platform/wayland/gpu/wayland_surface_factory.cc
index 2464437a46cf..b5dba5fd525b 100644
--- a/ui/ozone/platform/wayland/gpu/wayland_surface_factory.cc
+++ b/ui/ozone/platform/wayland/gpu/wayland_surface_factory.cc
@@ -30,11 +30,8 @@ namespace {
 class GLOzoneEGLWayland : public GLOzoneEGL {
  public:
   GLOzoneEGLWayland(WaylandConnection* connection,
-                    WaylandBufferManagerGpu* buffer_manager,
-                    WaylandSurfaceFactory* factory)
-      : connection_(connection),
-        buffer_manager_(buffer_manager),
-        factory_(factory) {}
+                    WaylandBufferManagerGpu* buffer_manager)
+      : connection_(connection), buffer_manager_(buffer_manager) {}
   ~GLOzoneEGLWayland() override {}
 
   scoped_refptr<gl::GLSurface> CreateViewGLSurface(
@@ -53,7 +50,6 @@ class GLOzoneEGLWayland : public GLOzoneEGL {
  private:
   WaylandConnection* const connection_;
   WaylandBufferManagerGpu* const buffer_manager_;
-  WaylandSurfaceFactory* const factory_;
 
   DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLWayland);
 };
@@ -79,8 +75,6 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateViewGLSurface(
 
 scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface(
     gfx::AcceleratedWidget window) {
-  DCHECK(factory_);
-
   // Only EGLGLES2 is supported with surfaceless view gl.
   if (gl::GetGLImplementation() != gl::kGLImplementationEGLGLES2)
     return nullptr;
@@ -90,7 +84,7 @@ scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateSurfacelessViewGLSurface(
   if (!buffer_manager_->gbm_device())
     return nullptr;
   return gl::InitializeGLSurface(
-      new GbmSurfacelessWayland(factory_, buffer_manager_, window));
+      new GbmSurfacelessWayland(buffer_manager_, window));
 #else
   return nullptr;
 #endif
@@ -121,38 +115,15 @@ bool GLOzoneEGLWayland::LoadGLES2Bindings(gl::GLImplementation impl) {
 
 }  // namespace
 
-WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection)
-    : connection_(connection) {}
-
-WaylandSurfaceFactory::~WaylandSurfaceFactory() = default;
-
-void WaylandSurfaceFactory::SetBufferManager(
-    WaylandBufferManagerGpu* buffer_manager) {
-  DCHECK(!buffer_manager_ && buffer_manager);
-  buffer_manager_ = buffer_manager;
-
+WaylandSurfaceFactory::WaylandSurfaceFactory(
+    WaylandConnection* connection,
+    WaylandBufferManagerGpu* buffer_manager)
+    : connection_(connection), buffer_manager_(buffer_manager) {
   egl_implementation_ =
-      std::make_unique<GLOzoneEGLWayland>(connection_, buffer_manager_, this);
-}
-
-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;
+      std::make_unique<GLOzoneEGLWayland>(connection_, buffer_manager_);
 }
 
+WaylandSurfaceFactory::~WaylandSurfaceFactory() = default;
 
 std::unique_ptr<SurfaceOzoneCanvas>
 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) {
@@ -188,7 +159,7 @@ scoped_refptr<gfx::NativePixmap> WaylandSurfaceFactory::CreateNativePixmap(
     gfx::BufferUsage usage) {
 #if defined(WAYLAND_GBM)
   scoped_refptr<GbmPixmapWayland> pixmap =
-      base::MakeRefCounted<GbmPixmapWayland>(this, buffer_manager_, widget);
+      base::MakeRefCounted<GbmPixmapWayland>(buffer_manager_, widget);
   if (!pixmap->InitializeBuffer(size, format, usage))
     return nullptr;
   return pixmap;
diff --git a/ui/ozone/platform/wayland/gpu/wayland_surface_factory.h b/ui/ozone/platform/wayland/gpu/wayland_surface_factory.h
index 1db6ee72d406..23f4f92a5959 100644
--- a/ui/ozone/platform/wayland/gpu/wayland_surface_factory.h
+++ b/ui/ozone/platform/wayland/gpu/wayland_surface_factory.h
@@ -17,23 +17,15 @@
 
 namespace ui {
 
-class GbmSurfacelessWayland;
 class WaylandConnection;
 class WaylandBufferManagerGpu;
 
 class WaylandSurfaceFactory : public SurfaceFactoryOzone {
  public:
-  explicit WaylandSurfaceFactory(WaylandConnection* connection);
+  WaylandSurfaceFactory(WaylandConnection* connection,
+                        WaylandBufferManagerGpu* buffer_manager);
   ~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:
   std::vector<gl::GLImplementation> GetAllowedGLImplementations() override;
   GLOzone* GetGLOzone(gl::GLImplementation implementation) override;
@@ -53,12 +45,9 @@ class WaylandSurfaceFactory : public SurfaceFactoryOzone {
 
  private:
   WaylandConnection* const connection_;
-  WaylandBufferManagerGpu* buffer_manager_ = nullptr;
+  WaylandBufferManagerGpu* const buffer_manager_;
   std::unique_ptr<GLOzone> egl_implementation_;
 
-  std::map<gfx::AcceleratedWidget, GbmSurfacelessWayland*>
-      widget_to_surface_map_;
-
   DISALLOW_COPY_AND_ASSIGN(WaylandSurfaceFactory);
 };
 
diff --git a/ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h b/ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h
new file mode 100644
index 000000000000..f3593766eed8
--- /dev/null
+++ b/ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h
@@ -0,0 +1,38 @@
+// 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_
diff --git a/ui/ozone/platform/wayland/ozone_platform_wayland.cc b/ui/ozone/platform/wayland/ozone_platform_wayland.cc
index 61a0e5b27bfc..26d8b49dab25 100644
--- a/ui/ozone/platform/wayland/ozone_platform_wayland.cc
+++ b/ui/ozone/platform/wayland/ozone_platform_wayland.cc
@@ -169,11 +169,9 @@ class OzonePlatformWayland : public OzonePlatform {
   }
 
   void InitializeGPU(const InitParams& args) override {
-    surface_factory_ =
-        std::make_unique<WaylandSurfaceFactory>(connection_.get());
-    buffer_manager_ =
-        std::make_unique<WaylandBufferManagerGpu>(surface_factory_.get());
-    surface_factory_->SetBufferManager(buffer_manager_.get());
+    buffer_manager_ = std::make_unique<WaylandBufferManagerGpu>();
+    surface_factory_ = std::make_unique<WaylandSurfaceFactory>(
+        connection_.get(), buffer_manager_.get());
 #if defined(WAYLAND_GBM)
     const base::FilePath drm_node_path = path_finder_.GetDrmRenderNodePath();
     if (drm_node_path.empty()) {
diff --git a/ui/ozone/platform/wayland/test/wayland_test.cc b/ui/ozone/platform/wayland/test/wayland_test.cc
index 7c78473a0f94..f8946442ecaa 100644
--- a/ui/ozone/platform/wayland/test/wayland_test.cc
+++ b/ui/ozone/platform/wayland/test/wayland_test.cc
@@ -31,10 +31,9 @@ WaylandTest::WaylandTest()
       std::make_unique<StubKeyboardLayoutEngine>());
 #endif
   connection_ = std::make_unique<WaylandConnection>();
-  surface_factory_ = std::make_unique<WaylandSurfaceFactory>(connection_.get());
-  buffer_manager_gpu_ =
-      std::make_unique<WaylandBufferManagerGpu>(surface_factory_.get());
-  surface_factory_->SetBufferManager(buffer_manager_gpu_.get());
+  buffer_manager_gpu_ = std::make_unique<WaylandBufferManagerGpu>();
+  surface_factory_ = std::make_unique<WaylandSurfaceFactory>(
+      connection_.get(), buffer_manager_gpu_.get());
   window_ = std::make_unique<WaylandWindow>(&delegate_, connection_.get());
 }
 
-- 
2.22.0