From b8a2953d4c3908e18765a25d9ce278c03811d908 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Tue, 19 Mar 2019 16:36:11 -0700 Subject: [PATCH] [ios] Set contentsScale before we commit CATransaction (flutter/engine#8218) Layout occurs after [CATransaction commit]. layoutSubviews was where we set the contentsScale on the CALayer. This meant that for one frame, we would see content on the overlay view which was did not have the correct content scale. This change makes it so that we initialize the FlutterOverlayView with the correct contentsScale. This also updates the overlay_gr_context_ when we first create the overlay_view. This is an artifact of #8175. This manifests as jank as seen in: flutter/flutter#29573 --- .../ios/framework/Source/FlutterOverlayView.h | 1 + .../ios/framework/Source/FlutterOverlayView.mm | 15 ++++++++------- .../ios/framework/Source/FlutterPlatformViews.mm | 6 ++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h index a344179057..7332e46115 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h @@ -23,6 +23,7 @@ - (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE; - (instancetype)init NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithContentsScale:(CGFloat)contentsScale; - (std::unique_ptr)createSoftwareSurface; - (std::unique_ptr)createGLSurfaceWithContext: (std::shared_ptr)gl_context; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm index 83f59d24e0..394ae89550 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm @@ -21,13 +21,13 @@ @implementation FlutterOverlayView - (instancetype)initWithFrame:(CGRect)frame { - @throw([NSException exceptionWithName:@"FlutterOverlayView must initWithDelegate" + @throw([NSException exceptionWithName:@"FlutterOverlayView must init or initWithContentsScale" reason:nil userInfo:nil]); } - (instancetype)initWithCoder:(NSCoder*)aDecoder { - @throw([NSException exceptionWithName:@"FlutterOverlayView must initWithDelegate" + @throw([NSException exceptionWithName:@"FlutterOverlayView must init or initWithContentsScale" reason:nil userInfo:nil]); } @@ -43,16 +43,17 @@ return self; } -- (void)layoutSubviews { +- (instancetype)initWithContentsScale:(CGFloat)contentsScale { + self = [self init]; + if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { CAEAGLLayer* layer = reinterpret_cast(self.layer); layer.allowsGroupOpacity = NO; - CGFloat screenScale = [UIScreen mainScreen].scale; - layer.contentsScale = screenScale; - layer.rasterizationScale = screenScale; + layer.contentsScale = contentsScale; + layer.rasterizationScale = contentsScale; } - [super layoutSubviews]; + return self; } + (Class)layerClass { 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 82659b4fe2..4eb773532a 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 @@ -245,7 +245,6 @@ bool FlutterPlatformViewsController::SubmitFrame(bool gl_rendering, active_composition_order_.push_back(view_id); } - composition_order_.clear(); return did_submit; } @@ -294,7 +293,9 @@ void FlutterPlatformViewsController::EnsureGLOverlayInitialized( } return; } - FlutterOverlayView* overlay_view = [[FlutterOverlayView alloc] init]; + auto contentsScale = flutter_view_.get().layer.contentsScale; + FlutterOverlayView* overlay_view = + [[FlutterOverlayView alloc] initWithContentsScale:contentsScale]; overlay_view.frame = flutter_view_.get().bounds; overlay_view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); @@ -303,6 +304,7 @@ void FlutterPlatformViewsController::EnsureGLOverlayInitialized( std::unique_ptr surface = ios_surface->CreateSecondaryGPUSurface(gr_context); overlays_[overlay_id] = std::make_unique( fml::scoped_nsobject(overlay_view), std::move(ios_surface), std::move(surface)); + overlays_gr_context_ = gr_context; } } // namespace shell