Skip to content

Commit 125c4eb

Browse files
iskakaushikRBogie
authored andcommitted
[ios] Set contentsScale before we commit CATransaction (flutter#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 flutter#8175. This manifests as jank as seen in: flutter/flutter#29573
1 parent 551a726 commit 125c4eb

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
2424

2525
- (instancetype)init NS_DESIGNATED_INITIALIZER;
26+
- (instancetype)initWithContentsScale:(CGFloat)contentsScale;
2627
- (std::unique_ptr<shell::IOSSurface>)createSoftwareSurface;
2728
- (std::unique_ptr<shell::IOSSurfaceGL>)createGLSurfaceWithContext:
2829
(std::shared_ptr<shell::IOSGLContext>)gl_context;

shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
@implementation FlutterOverlayView
2222

2323
- (instancetype)initWithFrame:(CGRect)frame {
24-
@throw([NSException exceptionWithName:@"FlutterOverlayView must initWithDelegate"
24+
@throw([NSException exceptionWithName:@"FlutterOverlayView must init or initWithContentsScale"
2525
reason:nil
2626
userInfo:nil]);
2727
}
2828

2929
- (instancetype)initWithCoder:(NSCoder*)aDecoder {
30-
@throw([NSException exceptionWithName:@"FlutterOverlayView must initWithDelegate"
30+
@throw([NSException exceptionWithName:@"FlutterOverlayView must init or initWithContentsScale"
3131
reason:nil
3232
userInfo:nil]);
3333
}
@@ -43,16 +43,17 @@ - (instancetype)init {
4343
return self;
4444
}
4545

46-
- (void)layoutSubviews {
46+
- (instancetype)initWithContentsScale:(CGFloat)contentsScale {
47+
self = [self init];
48+
4749
if ([self.layer isKindOfClass:[CAEAGLLayer class]]) {
4850
CAEAGLLayer* layer = reinterpret_cast<CAEAGLLayer*>(self.layer);
4951
layer.allowsGroupOpacity = NO;
50-
CGFloat screenScale = [UIScreen mainScreen].scale;
51-
layer.contentsScale = screenScale;
52-
layer.rasterizationScale = screenScale;
52+
layer.contentsScale = contentsScale;
53+
layer.rasterizationScale = contentsScale;
5354
}
5455

55-
[super layoutSubviews];
56+
return self;
5657
}
5758

5859
+ (Class)layerClass {

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@
245245

246246
active_composition_order_.push_back(view_id);
247247
}
248-
249248
composition_order_.clear();
250249
return did_submit;
251250
}
@@ -294,7 +293,9 @@
294293
}
295294
return;
296295
}
297-
FlutterOverlayView* overlay_view = [[FlutterOverlayView alloc] init];
296+
auto contentsScale = flutter_view_.get().layer.contentsScale;
297+
FlutterOverlayView* overlay_view =
298+
[[FlutterOverlayView alloc] initWithContentsScale:contentsScale];
298299
overlay_view.frame = flutter_view_.get().bounds;
299300
overlay_view.autoresizingMask =
300301
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
@@ -303,6 +304,7 @@
303304
std::unique_ptr<Surface> surface = ios_surface->CreateSecondaryGPUSurface(gr_context);
304305
overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>(
305306
fml::scoped_nsobject<UIView>(overlay_view), std::move(ios_surface), std::move(surface));
307+
overlays_gr_context_ = gr_context;
306308
}
307309

308310
} // namespace shell

0 commit comments

Comments
 (0)