1From 9f755da486b8568ef5a591836b23f4be3984a14b 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 10/14] 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 ae709740..c67c8bd1 100644 15--- a/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc 16+++ b/ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc 17@@ -23,6 +23,12 @@ namespace ui { 18 19 namespace { 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@@ -117,14 +123,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.20.1 60 61