From 0c8d9c87c506c6759a02ae2f79c7dbec4fc89848 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 3 Apr 2023 15:02:51 -0700 Subject: [PATCH 1/3] Disable partial repaint on Android --- shell/platform/android/android_egl_surface.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/android_egl_surface.cc b/shell/platform/android/android_egl_surface.cc index ed03ced47d2a7..5c5607a9501c9 100644 --- a/shell/platform/android/android_egl_surface.cc +++ b/shell/platform/android/android_egl_surface.cc @@ -123,7 +123,9 @@ class AndroidEGLSurfaceDamage { // last two frames; Some Android devices (Pixel 4) use quad buffering. static const int kMaxHistorySize = 10; - bool SupportsPartialRepaint() const { return partial_redraw_supported_; } + /// This was disabled after discussion in + /// https://github.com/flutter/flutter/issues/123353 + bool SupportsPartialRepaint() const { return false; } std::optional InitialDamage(EGLDisplay display, EGLSurface surface) { if (!partial_redraw_supported_) { From 921a21a397166e1388b7045578e8d9483e436677 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 3 Apr 2023 15:36:01 -0700 Subject: [PATCH 2/3] moar --- shell/platform/android/android_egl_surface.cc | 111 +----------------- 1 file changed, 5 insertions(+), 106 deletions(-) diff --git a/shell/platform/android/android_egl_surface.cc b/shell/platform/android/android_egl_surface.cc index 5c5607a9501c9..9ca7875c26fd6 100644 --- a/shell/platform/android/android_egl_surface.cc +++ b/shell/platform/android/android_egl_surface.cc @@ -58,130 +58,29 @@ void LogLastEGLError() { FML_LOG(ERROR) << "Unknown EGL Error"; } -namespace { - -static bool HasExtension(const char* extensions, const char* name) { - const char* r = strstr(extensions, name); - auto len = strlen(name); - // check that the extension name is terminated by space or null terminator - return r != nullptr && (r[len] == ' ' || r[len] == 0); -} - -} // namespace +namespace {} // namespace class AndroidEGLSurfaceDamage { public: - void init(EGLDisplay display, EGLContext context) { - if (GetAPILevel() < 29) { - // Disable partial repaint for devices older than Android 10. There - // are old devices that have extensions below available but the - // implementation causes glitches (i.e. Xperia Z3 with Android 6). - partial_redraw_supported_ = false; - return; - } - - const char* extensions = eglQueryString(display, EGL_EXTENSIONS); - - if (HasExtension(extensions, "EGL_KHR_partial_update")) { - set_damage_region_ = reinterpret_cast( - eglGetProcAddress("eglSetDamageRegionKHR")); - } - - if (HasExtension(extensions, "EGL_EXT_swap_buffers_with_damage")) { - swap_buffers_with_damage_ = - reinterpret_cast( - eglGetProcAddress("eglSwapBuffersWithDamageEXT")); - } else if (HasExtension(extensions, "EGL_KHR_swap_buffers_with_damage")) { - swap_buffers_with_damage_ = - reinterpret_cast( - eglGetProcAddress("eglSwapBuffersWithDamageKHR")); - } - - partial_redraw_supported_ = - set_damage_region_ != nullptr && swap_buffers_with_damage_ != nullptr; - } - - static int GetAPILevel() { - char sdk_version_string[PROP_VALUE_MAX]; - if (__system_property_get("ro.build.version.sdk", sdk_version_string)) { - return atoi(sdk_version_string); - } else { - return -1; - } - } + void init(EGLDisplay display, EGLContext context) {} void SetDamageRegion(EGLDisplay display, EGLSurface surface, - const std::optional& region) { - if (set_damage_region_ && region) { - auto rects = RectToInts(display, surface, *region); - set_damage_region_(display, surface, rects.data(), 1); - } - } - - // Maximum damage history - for triple buffering we need to store damage for - // last two frames; Some Android devices (Pixel 4) use quad buffering. - static const int kMaxHistorySize = 10; + const std::optional& region) {} /// This was disabled after discussion in /// https://github.com/flutter/flutter/issues/123353 bool SupportsPartialRepaint() const { return false; } std::optional InitialDamage(EGLDisplay display, EGLSurface surface) { - if (!partial_redraw_supported_) { - return std::nullopt; - } - - EGLint age; - eglQuerySurface(display, surface, EGL_BUFFER_AGE_EXT, &age); - - if (age == 0) { // full repaint - return std::nullopt; - } else { - // join up to (age - 1) last rects from damage history - --age; - auto res = SkIRect::MakeEmpty(); - for (auto i = damage_history_.rbegin(); - i != damage_history_.rend() && age > 0; ++i, --age) { - res.join(*i); - } - return res; - } + return std::nullopt; } bool SwapBuffersWithDamage(EGLDisplay display, EGLSurface surface, const std::optional& damage) { - if (swap_buffers_with_damage_ && damage) { - damage_history_.push_back(*damage); - if (damage_history_.size() > kMaxHistorySize) { - damage_history_.pop_front(); - } - auto rects = RectToInts(display, surface, *damage); - return swap_buffers_with_damage_(display, surface, rects.data(), 1); - } else { - return eglSwapBuffers(display, surface); - } - } - - private: - std::array static RectToInts(EGLDisplay display, - EGLSurface surface, - const SkIRect& rect) { - EGLint height; - eglQuerySurface(display, surface, EGL_HEIGHT, &height); - - std::array res{rect.left(), height - rect.bottom(), rect.width(), - rect.height()}; - return res; + return eglSwapBuffers(display, surface); } - - PFNEGLSETDAMAGEREGIONKHRPROC set_damage_region_ = nullptr; - PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage_ = nullptr; - - bool partial_redraw_supported_; - - std::list damage_history_; }; AndroidEGLSurface::AndroidEGLSurface(EGLSurface surface, From 0304344d2a2fc481395ef21ad88a0e548e40d2cb Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 3 Apr 2023 15:49:31 -0700 Subject: [PATCH 3/3] Update android_egl_surface.cc --- shell/platform/android/android_egl_surface.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/shell/platform/android/android_egl_surface.cc b/shell/platform/android/android_egl_surface.cc index 9ca7875c26fd6..de36a92ebd522 100644 --- a/shell/platform/android/android_egl_surface.cc +++ b/shell/platform/android/android_egl_surface.cc @@ -58,8 +58,6 @@ void LogLastEGLError() { FML_LOG(ERROR) << "Unknown EGL Error"; } -namespace {} // namespace - class AndroidEGLSurfaceDamage { public: void init(EGLDisplay display, EGLContext context) {}