From 04b9885368cc3dee47f327eaf0817aa18a98b80f Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Thu, 27 Dec 2018 16:02:00 -0800 Subject: [PATCH] Recreate the overlay rendering surfaces if the GrContext was changed. (flutter/engine#7317) When the app is sent to the background and then brought to the forward it is possible that the GrContext was changed. This resulted in overlay surfaces not being updated after being backgrounded and foregrounded. This change makes sure to re-create the overlay rendering surfaces if the GrContext for the main surface was changed. fixes flutter/flutter#24900 --- .../ios/framework/Source/FlutterPlatformViews.mm | 14 ++++++++++++-- .../Source/FlutterPlatformViews_Internal.h | 7 ++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index dcf970b377..d5bd70e0b4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -210,7 +210,8 @@ bool FlutterPlatformViewsController::SubmitFrame(bool gl_rendering, for (size_t i = 0; i < composition_order_.size(); i++) { int64_t view_id = composition_order_[i]; if (gl_rendering) { - EnsureGLOverlayInitialized(view_id, gl_context, gr_context); + EnsureGLOverlayInitialized(view_id, gl_context, gr_context, + gr_context != overlays_gr_context_); } else { EnsureOverlayInitialized(view_id); } @@ -220,6 +221,7 @@ bool FlutterPlatformViewsController::SubmitFrame(bool gl_rendering, canvas->flush(); did_submit &= frame->Submit(); } + overlays_gr_context_ = gr_context; picture_recorders_.clear(); if (composition_order_ == active_composition_order_) { composition_order_.clear(); @@ -265,8 +267,16 @@ void FlutterPlatformViewsController::EnsureOverlayInitialized(int64_t overlay_id void FlutterPlatformViewsController::EnsureGLOverlayInitialized( int64_t overlay_id, std::shared_ptr gl_context, - GrContext* gr_context) { + GrContext* gr_context, + bool update_gr_context) { if (overlays_.count(overlay_id) != 0) { + if (update_gr_context) { + // The overlay already exists, but the GrContext was changed so we need to recreate + // the rendering surface with the new GrContext. + IOSSurfaceGL* ios_surface_gl = (IOSSurfaceGL*)overlays_[overlay_id]->ios_surface.get(); + std::unique_ptr surface = ios_surface_gl->CreateSecondaryGPUSurface(gr_context); + overlays_[overlay_id]->surface = std::move(surface); + } return; } FlutterOverlayView* overlay_view = [[FlutterOverlayView alloc] init]; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 7c980896bf..87aa5a3626 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -78,6 +78,10 @@ class FlutterPlatformViewsController { std::map>> views_; std::map> touch_interceptors_; std::map> overlays_; + // The GrContext that is currently used by all of the overlay surfaces. + // We track this to know when the GrContext for the Flutter app has changed + // so we can update the overlays with the new context. + GrContext* overlays_gr_context_; SkISize frame_size_; // A vector of embedded view IDs according to their composition order. @@ -97,7 +101,8 @@ class FlutterPlatformViewsController { void EnsureOverlayInitialized(int64_t overlay_id); void EnsureGLOverlayInitialized(int64_t overlay_id, std::shared_ptr gl_context, - GrContext* gr_context); + GrContext* gr_context, + bool update_gr_context); FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewsController); };