[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
This commit is contained in:
Kaushik Iska
2019-03-19 16:36:11 -07:00
committed by GitHub
parent e6f480f74b
commit b8a2953d4c
3 changed files with 13 additions and 9 deletions

View File

@@ -23,6 +23,7 @@
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithContentsScale:(CGFloat)contentsScale;
- (std::unique_ptr<shell::IOSSurface>)createSoftwareSurface;
- (std::unique_ptr<shell::IOSSurfaceGL>)createGLSurfaceWithContext:
(std::shared_ptr<shell::IOSGLContext>)gl_context;

View File

@@ -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<CAEAGLLayer*>(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 {

View File

@@ -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> surface = ios_surface->CreateSecondaryGPUSurface(gr_context);
overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>(
fml::scoped_nsobject<UIView>(overlay_view), std::move(ios_surface), std::move(surface));
overlays_gr_context_ = gr_context;
}
} // namespace shell