Commit 9dc131d6 authored by Biao She's avatar Biao She Committed by Commit Bot

Introduces GetStatusChangeTime

This provides a best-effort interface to retrieve the time at which
a GLFence changed state. This is useful for getting a render time
estimate without having to poll the fence or actively waiting for it
to signal.

Bug: none
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I4df20684fdaeb0f39b36fb72bd1d65a2766952fd
Reviewed-on: https://chromium-review.googlesource.com/1030049Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Biao She <bshe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554831}
parent 2691be98
......@@ -216,12 +216,17 @@ component("gl") {
}
}
if (is_posix || is_fuchsia) {
if (is_posix && !is_fuchsia) {
# Windows has USE_EGL but doesn't support base::FileDescriptor
# Fuchsia is excluded due to a libsync dependency and because it's
# unknown if the required EGL_ANDROID_native_fence_sync extension works
# there. If it does and there's a use case, this could be revisited.
sources += [
"gl_fence_android_native_fence_sync.cc",
"gl_fence_android_native_fence_sync.h",
]
deps += [ "//third_party/libsync" ]
}
}
if (is_mac || use_egl) {
......
include_rules = [
"+components/crash/core/common/crash_key.h", # Remove after fixing crbug.com/724999.
"+third_party/khronos",
"+third_party/libsync",
"+third_party/skia",
"+ui/events",
"+ui/base/x",
......
......@@ -18,7 +18,7 @@
#include "ui/gl/gl_fence_apple.h"
#endif
#if defined(USE_EGL) && defined(OS_POSIX)
#if defined(USE_EGL) && defined(OS_POSIX) && !defined(OS_FUCHSIA)
#include "ui/gl/gl_fence_android_native_fence_sync.h"
#include "ui/gl/gl_surface_egl.h"
#endif
......@@ -92,7 +92,7 @@ void GLFence::Invalidate() {
}
bool GLFence::IsGpuFenceSupported() {
#if defined(USE_EGL) && defined(OS_POSIX)
#if defined(USE_EGL) && defined(OS_POSIX) && !defined(OS_FUCHSIA)
return gl::GLSurfaceEGL::IsAndroidNativeFenceSyncSupported();
#else
return false;
......@@ -105,7 +105,7 @@ std::unique_ptr<GLFence> GLFence::CreateFromGpuFence(
DCHECK(IsGpuFenceSupported());
switch (gpu_fence.GetGpuFenceHandle().type) {
case gfx::GpuFenceHandleType::kAndroidNativeFenceSync:
#if defined(USE_EGL) && defined(OS_POSIX)
#if defined(USE_EGL) && defined(OS_POSIX) && !defined(OS_FUCHSIA)
return GLFenceAndroidNativeFenceSync::CreateFromGpuFence(gpu_fence);
#else
NOTREACHED();
......@@ -120,7 +120,7 @@ std::unique_ptr<GLFence> GLFence::CreateFromGpuFence(
// static
std::unique_ptr<GLFence> GLFence::CreateForGpuFence() {
DCHECK(IsGpuFenceSupported());
#if defined(USE_EGL) && defined(OS_POSIX)
#if defined(USE_EGL) && defined(OS_POSIX) && !defined(OS_FUCHSIA)
return GLFenceAndroidNativeFenceSync::CreateForGpuFence();
#endif
NOTREACHED();
......
......@@ -4,7 +4,12 @@
#include "ui/gl/gl_fence_android_native_fence_sync.h"
#include <sync/sync.h>
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "ui/gfx/gpu_fence_handle.h"
#include "ui/gl/gl_surface_egl.h"
......@@ -65,4 +70,37 @@ std::unique_ptr<gfx::GpuFence> GLFenceAndroidNativeFenceSync::GetGpuFence() {
return std::make_unique<gfx::GpuFence>(handle);
}
base::TimeTicks GLFenceAndroidNativeFenceSync::GetStatusChangeTime() {
EGLint sync_fd = eglDupNativeFenceFDANDROID(display_, sync_);
if (sync_fd < 0)
return base::TimeTicks();
base::ScopedFD scoped_fd(sync_fd);
struct sync_fence_info_data* info;
info = sync_fence_info(scoped_fd.get());
if (!info)
return base::TimeTicks();
struct sync_pt_info* pt_info = nullptr;
pt_info = sync_pt_info(info, pt_info);
if (!pt_info)
return base::TimeTicks();
base::TimeTicks t = base::TimeTicks() +
base::TimeDelta::FromNanoseconds(pt_info->timestamp_ns);
if (!sync_pt_info(info, pt_info)) {
// It is possible that multiple sync_pt_info could be extracted from
// sync_fence_info_data. We currently only handle one.
DLOG(WARNING) << "Ambiguous status change time. More than one result "
"could be extracted";
return base::TimeTicks();
}
sync_fence_info_free(info);
return t;
}
} // namespace gl
......@@ -24,6 +24,10 @@ class GL_EXPORT GLFenceAndroidNativeFenceSync : public GLFenceEGL {
std::unique_ptr<gfx::GpuFence> GetGpuFence() override;
// This is a best effort to get status change time. It might fail and a null
// TimeTicks will be returned in that case.
base::TimeTicks GetStatusChangeTime();
private:
GLFenceAndroidNativeFenceSync();
static std::unique_ptr<GLFenceAndroidNativeFenceSync> CreateInternal(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment