From d799502fe7622c6515af60033685be456976ee7c Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Mon, 31 May 2021 01:29:11 +0800 Subject: [PATCH 09/17] Create new fence when there's no in-fences There're cases that in-fences are not provided. Signed-off-by: Jeffy Chen --- .../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 1bfdcd2d5..0d95037ed 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> fences) { for (auto& fence : fences) fence->Wait(); @@ -231,8 +237,9 @@ void GbmSurfacelessWayland::SwapBuffersAsync( return; } - base::OnceClosure fence_wait_task; std::vector> 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( @@ -241,7 +248,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