hc
2023-11-20 2e7bd41e4e8ab3d1efdabd9e263a2f7fe79bff8c
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
From 890b3afc591b71ae1e96d1a050d1958539db22b0 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/14] 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 752200e2c..7568f89ce 100644
--- a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
+++ b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
@@ -31,6 +31,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();
@@ -215,8 +221,9 @@ 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& config : frame->configs) {
     if (!config.access_fence_handle.is_null()) {
       fences.push_back(std::make_unique<gfx::GpuFence>(
@@ -225,7 +232,17 @@ void GbmSurfacelessWayland::SwapBuffersAsync(
     }
   }
 
-  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