Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
comments
  • Loading branch information
Chris Yang committed Jan 18, 2023
commit afa4f42a191c4c070e00de4ea746012707729bbd
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,9 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,

CGFloat screenScale = [UIScreen mainScreen].scale;
// The UIKit frame is set based on the logical resolution (points) instead of physical.
//
// (https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html).
// However, flow is based on the physical resolution. For example, 1000 pixels in flow equals
// 500 points in UIKit for devices that has screenScale of 2. We need to scale the
// transformMatrix
// 500 points in UIKit for devices that has screenScale of 2. We need to scale the transformMatrix
// down to the logical resoltion before applying it to the layer of PlatformView.
transformMatrix.postScale(1 / screenScale, 1 / screenScale);

Expand All @@ -579,13 +577,11 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
// Thus, this translate needs to be reversed so the platform view can layout at the correct
// offset.
//
// Note that the transforms are not applied to the clipping paths because clipping paths happen
// on
// Note that the transforms are not applied to the clipping paths because clipping paths happen on
// the mask view, whose origin is always (0,0) to the flutter_view.
transformMatrix.postTranslate(-clipView.frame.origin.x, -clipView.frame.origin.y);

embedded_view.layer.transform = flutter::GetCATransform3DFromSkMatrix(transformMatrix);
// embedded_view.frame = clipView.bounds;
}

void FlutterPlatformViewsController::CompositeWithParams(int view_id,
Expand Down Expand Up @@ -911,7 +907,6 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
if (catransaction_added_) {
FML_DCHECK([[NSThread currentThread] isMainThread]);
[CATransaction commit];

catransaction_added_ = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,22 @@

// A pool that provides |FlutterClippingMaskView|s.
//
// Allocation and deallocation of |FlutterClippingMaskView| is minimized while using the pool.
// The pool has a capacity that can be set in the initializer.
// When requesting a FlutterClippingMaskView, the pool will first try to reuse an available maskView
// in the pool. If there are none available, a new FlutterClippingMaskView is constructed. If the
// capacity is reached, the newly constructed FlutterClippingMaskView is not added to the pool.
//
// Call |recycleMaskViews| to mark all the FlutterClippingMaskViews in the pool available.
@interface FlutterClippingMaskViewPool : NSObject

// Initialize the pool with `capacity`. When the `capacity` is reached, a FlutterClippingMaskView is
// constructed when requested, and it is not added to the pool.
- (instancetype)initWithCapacity:(NSInteger)capacity;

// Reuse a maskView from the pool, or allocate a new one.
- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame;

// Mark all the maskViews available.
- (void)recycleMaskViews;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ @interface FlutterClippingMaskViewPool ()

@property(assign, nonatomic) NSUInteger capacity;
@property(retain, nonatomic) NSMutableArray<FlutterClippingMaskView*>* pool;
Copy link
Member

@jmagman jmagman Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this retain the FlutterClippingMaskView even after the ChildClippingView is dealloc'd?
Would NSPointerArray with NSPointerFunctionsWeakMemory (I think zeroes it out with MRC but worth testing) work better here? If you could reliably know the mask views in the pool are used (because they are retained by a ChildClippingView), then you could get rid of recycleMaskViews and during insert compact, then insert at count if there was capacity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well never mind, retaining it after the ChildClippingView is dealloc'd is the whole point of this PR...
Can you confirm that deallocating FlutterPlatformViewsController releases the pool and the mask views?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a test for it!

// The index points to the first available FlutterClippingMaskView in the `pool`.
@property(assign, nonatomic) NSUInteger availableIndex;

@end
Expand All @@ -471,7 +472,6 @@ - (instancetype)initWithCapacity:(NSInteger)capacity {
return self;
}

// Reuse a maskView from the pool, or allocate a new one.
- (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame {
FML_DCHECK(self.availableIndex <= self.capacity);
FlutterClippingMaskView* maskView;
Expand Down