Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit faf1f50

Browse files
author
Chris Yang
committed
fixes
1 parent 299173b commit faf1f50

File tree

4 files changed

+52
-57
lines changed

4 files changed

+52
-57
lines changed

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

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,14 @@ static bool ClipBoundsContainsPlatformViewBoundingRect(const SkRect& clip_bounds
420420
}
421421

422422
void FlutterPlatformViewsController::ClipViewAddMaskView(UIView* clipView) {
423-
// if (clipView.maskView) {
424-
// return;
425-
// }
426-
// UIView* flutterView = flutter_view_.get();
427-
// CGRect frame = CGRectMake(-clipView.frame.origin.x, -clipView.frame.origin.y,
428-
// CGRectGetWidth(flutterView.bounds),
429-
// CGRectGetHeight(flutterView.bounds));
430-
// clipView.maskView = [mask_view_pool_.get() getMaskViewWithFrame:frame];
423+
if (clipView.maskView) {
424+
return;
425+
}
426+
UIView* flutterView = flutter_view_.get();
427+
CGRect frame =
428+
CGRectMake(-clipView.frame.origin.x, -clipView.frame.origin.y,
429+
CGRectGetWidth(flutterView.bounds), CGRectGetHeight(flutterView.bounds));
430+
clipView.maskView = [mask_view_pool_.get() getMaskViewWithFrame:frame];
431431
}
432432

433433
void FlutterPlatformViewsController::ApplyMutators(const MutatorsStack& mutators_stack,
@@ -444,13 +444,10 @@ static bool ClipBoundsContainsPlatformViewBoundingRect(const SkRect& clip_bounds
444444
NSMutableArray* blurFilters = [[[NSMutableArray alloc] init] autorelease];
445445
FML_DCHECK(!clipView.maskView ||
446446
[clipView.maskView isKindOfClass:[FlutterClippingMaskView class]]);
447-
FlutterClippingMaskView* maskView = (FlutterClippingMaskView*)clipView.maskView;
448447
if (mask_view_pool_.get() == nil) {
449448
mask_view_pool_.reset([[FlutterClippingMaskViewPool alloc] initWithCapacity:5]);
450449
}
451-
if (maskView) {
452-
[mask_view_pool_.get() markAvailable:maskView];
453-
}
450+
[mask_view_pool_.get() recycleMaskViews];
454451
clipView.maskView = nil;
455452
auto iter = mutators_stack.Begin();
456453
while (iter != mutators_stack.End()) {
@@ -533,28 +530,28 @@ static bool ClipBoundsContainsPlatformViewBoundingRect(const SkRect& clip_bounds
533530
[clipView applyBlurBackdropFilters:blurFilters];
534531
}
535532

536-
// CGFloat screenScale = [UIScreen mainScreen].scale;
537-
// // The UIKit frame is set based on the logical resolution (points) instead of physical.
538-
// //
533+
CGFloat screenScale = [UIScreen mainScreen].scale;
534+
// The UIKit frame is set based on the logical resolution (points) instead of physical.
535+
//
539536
// (https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html).
540-
// // However, flow is based on the physical resolution. For example, 1000 pixels in flow equals
541-
// // 500 points in UIKit for devices that has screenScale of 2. We need to scale the
537+
// However, flow is based on the physical resolution. For example, 1000 pixels in flow equals
538+
// 500 points in UIKit for devices that has screenScale of 2. We need to scale the
542539
// transformMatrix
543-
// // down to the logical resoltion before applying it to the layer of PlatformView.
544-
// transformMatrix.postScale(1 / screenScale, 1 / screenScale);
545-
546-
// // Reverse the offset of the clipView.
547-
// // The clipView's frame includes the final translate of the final transform matrix.
548-
// // Thus, this translate needs to be reversed so the platform view can layout at the correct
549-
// // offset.
550-
// //
551-
// // Note that the transforms are not applied to the clipping paths because clipping paths happen
540+
// down to the logical resoltion before applying it to the layer of PlatformView.
541+
transformMatrix.postScale(1 / screenScale, 1 / screenScale);
542+
543+
// Reverse the offset of the clipView.
544+
// The clipView's frame includes the final translate of the final transform matrix.
545+
// Thus, this translate needs to be reversed so the platform view can layout at the correct
546+
// offset.
547+
//
548+
// Note that the transforms are not applied to the clipping paths because clipping paths happen
552549
// on
553-
// // the mask view, whose origin is always (0,0) to the flutter_view.
554-
// transformMatrix.postTranslate(-clipView.frame.origin.x, -clipView.frame.origin.y);
550+
// the mask view, whose origin is always (0,0) to the flutter_view.
551+
transformMatrix.postTranslate(-clipView.frame.origin.x, -clipView.frame.origin.y);
555552

556-
// embedded_view.layer.transform = flutter::GetCATransform3DFromSkMatrix(transformMatrix);
557-
embedded_view.frame = clipView.bounds;
553+
embedded_view.layer.transform = flutter::GetCATransform3DFromSkMatrix(transformMatrix);
554+
// embedded_view.frame = clipView.bounds;
558555
}
559556

560557
void FlutterPlatformViewsController::CompositeWithParams(int view_id,
@@ -880,6 +877,7 @@ static bool ClipBoundsContainsPlatformViewBoundingRect(const SkRect& clip_bounds
880877
if (catransaction_added_) {
881878
FML_DCHECK([[NSThread currentThread] isMainThread]);
882879
[CATransaction commit];
880+
883881
catransaction_added_ = false;
884882
}
885883
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
// Reuse a maskView from the pool, or allocate a new one.
6060
- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame;
6161

62-
- (void)markAvailable:(FlutterClippingMaskView*)maskView;
62+
- (void)recycleMaskViews;
6363

6464
@end
6565

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ @interface FlutterClippingMaskViewPool ()
456456

457457
@property(assign, nonatomic) NSUInteger capacity;
458458
@property(retain, nonatomic) NSMutableArray<FlutterClippingMaskView*>* pool;
459-
@property(retain, nonatomic) NSMutableSet<NSNumber*>* availableViews;
459+
@property(assign, nonatomic) NSUInteger availableIndex;
460460

461461
@end
462462

@@ -465,47 +465,45 @@ @implementation FlutterClippingMaskViewPool : NSObject
465465
- (instancetype)initWithCapacity:(NSInteger)capacity {
466466
if (self = [super init]) {
467467
_pool = [[NSMutableArray alloc] initWithCapacity:capacity];
468-
_availableViews = [[NSMutableSet alloc] initWithCapacity:capacity];
469468
_capacity = capacity;
469+
_availableIndex = 0;
470470
}
471471
return self;
472472
}
473473

474474
// Reuse a maskView from the pool, or allocate a new one.
475475
- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame {
476-
if (self.availableViews.count == 0) {
477-
// No avaialble views in the pool, alloc a new one.
478-
FlutterClippingMaskView* maskView =
476+
FML_DCHECK(self.availableIndex <= self.capacity);
477+
FlutterClippingMaskView* maskView;
478+
if (self.availableIndex == self.capacity) {
479+
// The pool is full, alloc a new one.
480+
maskView =
479481
[[[FlutterClippingMaskView alloc] initWithFrame:frame
480482
screenScale:[UIScreen mainScreen].scale] autorelease];
481-
if (self.pool.count < self.capacity) {
482-
[self.pool addObject:maskView];
483-
}
484483
return maskView;
485484
}
486-
NSNumber* nextAvailable = [self.availableViews anyObject];
487-
FlutterClippingMaskView* maskView = [self.pool objectAtIndex:nextAvailable.unsignedIntegerValue];
488-
maskView.frame = frame;
489-
[maskView reset];
490-
[self.availableViews removeObject:nextAvailable];
485+
486+
if (self.availableIndex >= self.pool.count) {
487+
// The pool doesn't have enough maskViews, alloc a new one and add to the pool.
488+
maskView =
489+
[[[FlutterClippingMaskView alloc] initWithFrame:frame
490+
screenScale:[UIScreen mainScreen].scale] autorelease];
491+
[self.pool addObject:maskView];
492+
FML_DCHECK(self.pool.count <= self.capacity);
493+
} else {
494+
maskView = [self.pool objectAtIndex:self.availableIndex];
495+
maskView.frame = frame;
496+
[maskView reset];
497+
}
498+
self.availableIndex++;
491499
return maskView;
492500
}
493501

494-
- (void)markAvailable:(FlutterClippingMaskView*)maskView {
495-
FML_DCHECK(maskView != nil);
496-
// O(_size)
497-
NSUInteger index = [self.pool indexOfObject:maskView];
498-
if (index == NSNotFound) {
499-
return;
500-
}
501-
FML_DCHECK(index < self.capacity);
502-
[self.availableViews addObject:@(index)];
503-
FML_DCHECK(self.availableViews.count <= self.capacity);
502+
- (void)recycleMaskViews {
503+
self.availableIndex = 0;
504504
}
505505

506506
- (void)dealloc {
507-
[_availableViews release];
508-
_availableViews = nil;
509507
[_pool release];
510508
_pool = nil;
511509

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ - (void)setMaxRefreshRateIfEnabled {
8383
return;
8484
}
8585
double maxFrameRate = fmax([DisplayLinkManager displayRefreshRate], 60);
86-
// double maxFrameRate = 60;
8786
double minFrameRate = fmax(maxFrameRate / 2, 60);
8887

8988
if (@available(iOS 15.0, *)) {

0 commit comments

Comments
 (0)