diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index dcf970b377a92b96c23189f06c32be08b14d7648..d5bd70e0b44462242ffa0ac17639122e437cace8 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/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/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 7c980896bfceff3d01a86c36b51ce21ec4dcdcfc..87aa5a36263436ae706612e28410579116c747e6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/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); };