1From d799502fe7622c6515af60033685be456976ee7c 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 09/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 1bfdcd2d5..0d95037ed 100644
15--- a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
16+++ b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
17@@ -31,6 +31,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@@ -231,8 +237,9 @@ 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& config : frame->configs) {
39     if (!config.access_fence_handle.is_null()) {
40       fences.push_back(std::make_unique<gfx::GpuFence>(
41@@ -241,7 +248,17 @@ void GbmSurfacelessWayland::SwapBuffersAsync(
42     }
43   }
44
45-  fence_wait_task = base::BindOnce(&WaitForGpuFences, std::move(fences));
46+  base::OnceClosure fence_wait_task;
47+  if (!fences.empty()) {
48+    fence_wait_task = base::BindOnce(&WaitForGpuFences, std::move(fences));
49+  } else {
50+    // TODO(fangzhoug): the following should be replaced by a per surface flush
51+    // as it gets implemented in GL drivers.
52+    EGLSyncKHR fence = InsertFence(has_implicit_external_sync_);
53+    CHECK_NE(fence, EGL_NO_SYNC_KHR) << "eglCreateSyncKHR failed";
54+
55+    fence_wait_task = base::BindOnce(&WaitForEGLFence, GetDisplay(), fence);
56+  }
57
58   base::OnceClosure fence_retired_callback = base::BindOnce(
59       &GbmSurfacelessWayland::FenceRetired, weak_factory_.GetWeakPtr(), frame);
60--
612.20.1
62
63