@@ -60,6 +60,17 @@ void LogLastEGLError() {
6060 FML_LOG (ERROR) << " Unknown EGL Error" ;
6161}
6262
63+ namespace {
64+
65+ static bool HasExtension (const char * extensions, const char * name) {
66+ const char * r = strstr (extensions, name);
67+ auto len = strlen (name);
68+ // check that the extension name is terminated by space or null terminator
69+ return r != nullptr && (r[len] == ' ' || r[len] == 0 );
70+ }
71+
72+ } // namespace
73+
6374class AndroidEGLSurfaceDamage {
6475 public:
6576 void init (EGLDisplay display, EGLContext context) {
@@ -170,13 +181,6 @@ class AndroidEGLSurfaceDamage {
170181
171182 bool partial_redraw_supported_;
172183
173- bool HasExtension (const char * extensions, const char * name) {
174- const char * r = strstr (extensions, name);
175- auto len = strlen (name);
176- // check that the extension name is terminated by space or null terminator
177- return r != nullptr && (r[len] == ' ' || r[len] == 0 );
178- }
179-
180184 std::list<SkIRect> damage_history_;
181185};
182186
@@ -188,6 +192,14 @@ AndroidEGLSurface::AndroidEGLSurface(EGLSurface surface,
188192 context_(context),
189193 damage_(std::make_unique<AndroidEGLSurfaceDamage>()) {
190194 damage_->init (display_, context);
195+
196+ const char * extensions = eglQueryString (display, EGL_EXTENSIONS);
197+
198+ if (HasExtension (extensions, " EGL_ANDROID_presentation_time" )) {
199+ presentation_time_proc_ =
200+ reinterpret_cast <PFNEGLPRESENTATIONTIMEANDROIDPROC>(
201+ eglGetProcAddress (" eglPresentationTimeANDROID" ));
202+ }
191203}
192204
193205AndroidEGLSurface::~AndroidEGLSurface () {
@@ -240,6 +252,16 @@ void AndroidEGLSurface::SetDamageRegion(
240252 damage_->SetDamageRegion (display_, surface_, buffer_damage);
241253}
242254
255+ bool AndroidEGLSurface::SetPresentationTime (
256+ const fml::TimePoint& presentation_time) {
257+ if (presentation_time_proc_) {
258+ const auto time_ns = presentation_time.ToEpochDelta ().ToNanoseconds ();
259+ return presentation_time_proc_ (display_, surface_, time_ns);
260+ } else {
261+ return false ;
262+ }
263+ }
264+
243265bool AndroidEGLSurface::SwapBuffers (
244266 const std::optional<SkIRect>& surface_damage) {
245267 TRACE_EVENT0 (" flutter" , " AndroidContextGL::SwapBuffers" );
0 commit comments