From b98bf7c96c990e32a05bde1d28b80e1db0694cd2 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Fri, 15 Mar 2019 08:35:48 -0700 Subject: [PATCH] Update overlays_gr_context_ correctly (flutter/engine#8175) There can be cases where SubmitFrame gets called before overlays are a part of the frame, in these cases, we should not update the GRContext ahead of time. This commit makes it so we will update it only when the frame really shows the overlay. This addresses: https://github.com/flutter/flutter/issues/28920 --- engine/src/flutter/flow/embedded_views.h | 2 +- .../ios/framework/Source/FlutterPlatformViews.mm | 10 ++++------ .../framework/Source/FlutterPlatformViews_Internal.h | 3 +-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/flow/embedded_views.h b/engine/src/flutter/flow/embedded_views.h index 6f2e684c48..0fd474adb0 100644 --- a/engine/src/flutter/flow/embedded_views.h +++ b/engine/src/flutter/flow/embedded_views.h @@ -21,7 +21,7 @@ class EmbeddedViewParams { }; // This is only used on iOS when running in a non headless mode, -// in this case ViewEmbedded is a reference to the +// in this case ExternalViewEmbedder is a reference to the // FlutterPlatformViewsController which is owned by FlutterViewController. class ExternalViewEmbedder { public: 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 304ae123bc..fddc75fa54 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,8 +210,7 @@ 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, - gr_context != overlays_gr_context_); + EnsureGLOverlayInitialized(view_id, gl_context, gr_context); } else { EnsureOverlayInitialized(view_id); } @@ -221,7 +220,6 @@ 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(); @@ -267,10 +265,10 @@ void FlutterPlatformViewsController::EnsureOverlayInitialized(int64_t overlay_id void FlutterPlatformViewsController::EnsureGLOverlayInitialized( int64_t overlay_id, std::shared_ptr gl_context, - GrContext* gr_context, - bool update_gr_context) { + GrContext* gr_context) { if (overlays_.count(overlay_id) != 0) { - if (update_gr_context) { + if (gr_context != overlays_gr_context_) { + overlays_gr_context_ = 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(); 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 87aa5a3626..a89a2ff9bc 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 @@ -101,8 +101,7 @@ class FlutterPlatformViewsController { void EnsureOverlayInitialized(int64_t overlay_id); void EnsureGLOverlayInitialized(int64_t overlay_id, std::shared_ptr gl_context, - GrContext* gr_context, - bool update_gr_context); + GrContext* gr_context); FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewsController); };