hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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
From 449627f0307a095a8b7f9a732a67613ef93e2906 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Mon, 31 May 2021 01:29:11 +0800
Subject: [PATCH 09/15] Create new fence when there's no in-fences
 
There're cases that in-fences are not provided.
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 .../wayland/gpu/gbm_surfaceless_wayland.cc    | 21 +++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
 
diff --git a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
index 8c096e3dd..2a9a88cf7 100644
--- a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
+++ b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
@@ -32,6 +32,12 @@ static constexpr size_t kMaxSolidColorBuffers = 12;
 
 static constexpr gfx::Size kSolidColorBufferSize{4, 4};
 
+void WaitForEGLFence(EGLDisplay display, EGLSyncKHR fence) {
+  eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
+                       EGL_FOREVER_KHR);
+  eglDestroySyncKHR(display, fence);
+}
+
 void WaitForGpuFences(std::vector<std::unique_ptr<gfx::GpuFence>> fences) {
   for (auto& fence : fences)
     fence->Wait();
@@ -211,14 +217,25 @@ void GbmSurfacelessWayland::SwapBuffersAsync(
     return;
   }
 
-  base::OnceClosure fence_wait_task;
   std::vector<std::unique_ptr<gfx::GpuFence>> fences;
+  // Uset in-fences provided in the overlays. If there are none, we insert our
+  // own fence and wait.
   for (auto& plane : frame->planes) {
     if (plane.second.gpu_fence)
       fences.push_back(std::move(plane.second.gpu_fence));
   }
 
-  fence_wait_task = base::BindOnce(&WaitForGpuFences, std::move(fences));
+  base::OnceClosure fence_wait_task;
+  if (!fences.empty()) {
+    fence_wait_task = base::BindOnce(&WaitForGpuFences, std::move(fences));
+  } else {
+    // TODO(fangzhoug): the following should be replaced by a per surface flush
+    // as it gets implemented in GL drivers.
+    EGLSyncKHR fence = InsertFence(has_implicit_external_sync_);
+    CHECK_NE(fence, EGL_NO_SYNC_KHR) << "eglCreateSyncKHR failed";
+
+    fence_wait_task = base::BindOnce(&WaitForEGLFence, GetDisplay(), fence);
+  }
 
   base::OnceClosure fence_retired_callback = base::BindOnce(
       &GbmSurfacelessWayland::FenceRetired, weak_factory_.GetWeakPtr(), frame);
-- 
2.20.1