From 0d7ba05d3456807e7e24353fe911738952a02888 Mon Sep 17 00:00:00 2001 From: MiracleSoul Date: Sat, 11 Dec 2021 03:05:25 +0800 Subject: [PATCH] Fix eglPresentationTimeANDROID is no effective (flutter/engine#30182) * Fix eglPresentationTimeANDROID is no effective * Update android_environment_gl.cc Co-authored-by: Dan Field --- .../platform/android/android_environment_gl.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/android/android_environment_gl.cc b/engine/src/flutter/shell/platform/android/android_environment_gl.cc index cd04e9afe1..e84ee88d56 100644 --- a/engine/src/flutter/shell/platform/android/android_environment_gl.cc +++ b/engine/src/flutter/shell/platform/android/android_environment_gl.cc @@ -20,11 +20,24 @@ AndroidEnvironmentGL::AndroidEnvironmentGL() return; } + // See if we can use the EGL_ANDROID_presentation_time extension. This + // extension may be available from API18 onward. + // If this extension is available, it will be invoked with the target vsync + // for the current frame before calling eglSwapBuffers. This helps when the + // engine over-stuffs the buffer queue. This can happen when a frame goes over + // budget into the next vsync period, and a subsequent frame is quickly + // submitted in the same vsync period. Dequeuing buffers will then be slow + // until the engine stops submitting frames and lets the GPU catch up. + // However, using this extension means the SurfaceFlinger will only use the + // newest buffer for the current vsync, and the GPU and CPU will stay more + // in sync. + // See https://developer.android.com/games/sdk/frame-pacing for more + // details and diagrams. auto* extensions = eglQueryString(display_, EGL_EXTENSIONS); if (strstr(extensions, "EGL_ANDROID_presentation_time")) { presentation_time_proc_ = reinterpret_cast( - eglGetProcAddress("sEGL_ANDROID_presentation_time")); + eglGetProcAddress("eglPresentationTimeANDROID")); } valid_ = true;