Commit 9a5e3bea authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

egl: Improve presentation-timestamps.

If getting the timestamp for EGL_DISPLAY_PRESENT_TIME_ANDROID fails,
then instead of using Now() as the timestamp, attempt to get the
timestamp of EGL_FIRST_COMPOSITION_START_TIME_ANDROID.

BUG=none

Change-Id: Ie410943dc0eb6a1ae0c2510cb1cb0171967962eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1607261
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660580}
parent 033a2bb2
......@@ -1121,6 +1121,8 @@ void NativeViewGLSurfaceEGL::SetEnableSwapTimestamps() {
// called twice.
supported_egl_timestamps_.clear();
supported_event_names_.clear();
presentation_feedback_index_ = -1;
composition_start_index_ = -1;
eglSurfaceAttrib(GetDisplay(), surface_, EGL_TIMESTAMPS_ANDROID, EGL_TRUE);
......@@ -1162,6 +1164,8 @@ void NativeViewGLSurfaceEGL::SetEnableSwapTimestamps() {
// all_timestamps.
presentation_feedback_index_ =
static_cast<int>(supported_egl_timestamps_.size());
composition_start_index_ =
static_cast<int>(supported_egl_timestamps_.size());
presentation_flags_ = 0;
break;
case EGL_DISPLAY_PRESENT_TIME_ANDROID:
......@@ -1177,6 +1181,8 @@ void NativeViewGLSurfaceEGL::SetEnableSwapTimestamps() {
supported_egl_timestamps_.push_back(ts.egl_name);
supported_event_names_.push_back(ts.name);
}
DCHECK_GE(presentation_feedback_index_, 0);
DCHECK_GE(composition_start_index_, 0);
use_egl_timestamps_ = !supported_egl_timestamps_.empty();
}
......@@ -1486,6 +1492,7 @@ bool NativeViewGLSurfaceEGL::GetFrameTimestampInfoIfAvailable(
return true;
}
DCHECK_GE(presentation_feedback_index_, 0);
DCHECK_GE(composition_start_index_, 0);
// Get the presentation time.
EGLnsecsANDROID presentation_time_ns =
......@@ -1496,7 +1503,14 @@ bool NativeViewGLSurfaceEGL::GetFrameTimestampInfoIfAvailable(
return false;
}
if (presentation_time_ns == EGL_TIMESTAMP_INVALID_ANDROID) {
*presentation_time = base::TimeTicks::Now();
presentation_time_ns = egl_timestamps[composition_start_index_];
if (presentation_time_ns == EGL_TIMESTAMP_INVALID_ANDROID ||
presentation_time_ns == EGL_TIMESTAMP_PENDING_ANDROID) {
*presentation_time = base::TimeTicks::Now();
} else {
*presentation_time = base::TimeTicks() + base::TimeDelta::FromNanoseconds(
presentation_time_ns);
}
} else {
*presentation_time = base::TimeTicks() +
base::TimeDelta::FromNanoseconds(presentation_time_ns);
......
......@@ -202,6 +202,7 @@ class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL,
// PresentationFeedback support.
int presentation_feedback_index_ = -1;
int composition_start_index_ = -1;
uint32_t presentation_flags_ = 0;
base::queue<SwapInfo> swap_info_queue_;
......
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