Skip to content

Commit

Permalink
Recreate the overlay rendering surfaces if the GrContext was changed. (
Browse files Browse the repository at this point in the history
…flutter#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
  • Loading branch information
amirh authored Dec 28, 2018
1 parent 245317a commit f0dd643
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 12 additions & 2 deletions shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@
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);
}
Expand All @@ -220,6 +221,7 @@
canvas->flush();
did_submit &= frame->Submit();
}
overlays_gr_context_ = gr_context;
picture_recorders_.clear();
if (composition_order_ == active_composition_order_) {
composition_order_.clear();
Expand Down Expand Up @@ -265,8 +267,16 @@
void FlutterPlatformViewsController::EnsureGLOverlayInitialized(
int64_t overlay_id,
std::shared_ptr<IOSGLContext> 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> surface = ios_surface_gl->CreateSecondaryGPUSurface(gr_context);
overlays_[overlay_id]->surface = std::move(surface);
}
return;
}
FlutterOverlayView* overlay_view = [[FlutterOverlayView alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class FlutterPlatformViewsController {
std::map<int64_t, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;
std::map<int64_t, fml::scoped_nsobject<FlutterTouchInterceptingView>> touch_interceptors_;
std::map<int64_t, std::unique_ptr<FlutterPlatformViewLayer>> 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.
Expand All @@ -97,7 +101,8 @@ class FlutterPlatformViewsController {
void EnsureOverlayInitialized(int64_t overlay_id);
void EnsureGLOverlayInitialized(int64_t overlay_id,
std::shared_ptr<IOSGLContext> gl_context,
GrContext* gr_context);
GrContext* gr_context,
bool update_gr_context);

FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewsController);
};
Expand Down

0 comments on commit f0dd643

Please sign in to comment.