1From 3947bece937676c35af779d52e7d6a160b428aef Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Mon, 31 May 2021 01:29:11 +0800
4Subject: [PATCH 11/17] Create new fence when there's no in-fences
5
6There're cases that in-fences are not provided.
7
8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9---
10 .../wayland/gpu/gbm_surfaceless_wayland.cc    | 21 +++++++++++++++++--
11 1 file changed, 19 insertions(+), 2 deletions(-)
12
13diff --git a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
14index db7037fc..f2c14328 100644
15--- a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
16+++ b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
17@@ -30,6 +30,12 @@ static constexpr size_t kMaxSolidColorBuffers = 12;
18
19 static constexpr gfx::Size kSolidColorBufferSize{4, 4};
20
21+void WaitForEGLFence(EGLDisplay display, EGLSyncKHR fence) {
22+  eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
23+                       EGL_FOREVER_KHR);
24+  eglDestroySyncKHR(display, fence);
25+}
26+
27 void WaitForGpuFences(std::vector<std::unique_ptr<gfx::GpuFence>> fences) {
28   for (auto& fence : fences)
29     fence->Wait();
30@@ -211,14 +217,25 @@ void GbmSurfacelessWayland::SwapBuffersAsync(
31     return;
32   }
33
34-  base::OnceClosure fence_wait_task;
35   std::vector<std::unique_ptr<gfx::GpuFence>> fences;
36+  // Uset in-fences provided in the overlays. If there are none, we insert our
37+  // own fence and wait.
38   for (auto& plane : frame->planes) {
39     if (plane.second.gpu_fence)
40       fences.push_back(std::move(plane.second.gpu_fence));
41   }
42
43-  fence_wait_task = base::BindOnce(&WaitForGpuFences, std::move(fences));
44+  base::OnceClosure fence_wait_task;
45+  if (!fences.empty()) {
46+    fence_wait_task = base::BindOnce(&WaitForGpuFences, std::move(fences));
47+  } else {
48+    // TODO(fangzhoug): the following should be replaced by a per surface flush
49+    // as it gets implemented in GL drivers.
50+    EGLSyncKHR fence = InsertFence(has_implicit_external_sync_);
51+    CHECK_NE(fence, EGL_NO_SYNC_KHR) << "eglCreateSyncKHR failed";
52+
53+    fence_wait_task = base::BindOnce(&WaitForEGLFence, GetDisplay(), fence);
54+  }
55
56   base::OnceClosure fence_retired_callback = base::BindOnce(
57       &GbmSurfacelessWayland::FenceRetired, weak_factory_.GetWeakPtr(), frame);
58--
592.17.1
60
61