This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
iOS PlatformView only sets a maskView when necessary #37434
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,6 +241,16 @@ - (NSMutableArray*)backdropFilterSubviews { | |
|
|
||
| @interface FlutterClippingMaskView () | ||
|
|
||
| // A `CATransform3D` matrix represnts a scale transform that revese UIScreen.scale. | ||
| // | ||
| // The transform matrix passed in clipRect/clipRRect/clipPath methods are in device coordinate | ||
| // space. The transfrom matrix concats `reverseScreenScale` to create a transform matrix in the iOS | ||
| // logical coordinates (points). | ||
| // | ||
| // See https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale?language=objc for | ||
| // information about screen scale. | ||
| @property(nonatomic) CATransform3D reverseScreenScale; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a declaration comment, per style guide.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| - (fml::CFRef<CGPathRef>)getTransformedPath:(CGPathRef)path matrix:(CATransform3D)matrix; | ||
|
|
||
| @end | ||
|
|
@@ -250,8 +260,13 @@ @implementation FlutterClippingMaskView { | |
| } | ||
|
|
||
| - (instancetype)initWithFrame:(CGRect)frame { | ||
| return [self initWithFrame:frame screenScale:[UIScreen mainScreen].scale]; | ||
| } | ||
|
|
||
| - (instancetype)initWithFrame:(CGRect)frame screenScale:(CGFloat)screenScale { | ||
| if (self = [super initWithFrame:frame]) { | ||
| self.backgroundColor = UIColor.clearColor; | ||
| _reverseScreenScale = CATransform3DMakeScale(1 / screenScale, 1 / screenScale, 1); | ||
| } | ||
| return self; | ||
| } | ||
|
|
@@ -280,13 +295,16 @@ - (void)drawRect:(CGRect)rect { | |
| CGContextRestoreGState(context); | ||
| } | ||
|
|
||
| - (void)clipRect:(const SkRect&)clipSkRect matrix:(const CATransform3D&)matrix { | ||
| - (void)clipRect:(const SkRect&)clipSkRect matrix:(const SkMatrix&)matrix { | ||
| CGRect clipRect = flutter::GetCGRectFromSkRect(clipSkRect); | ||
| CGPathRef path = CGPathCreateWithRect(clipRect, nil); | ||
| paths_.push_back([self getTransformedPath:path matrix:matrix]); | ||
| // The `matrix` is based on the physical pixels, convert it to UIKit points. | ||
| CATransform3D matrixInPoints = | ||
| CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale); | ||
| paths_.push_back([self getTransformedPath:path matrix:matrixInPoints]); | ||
| } | ||
|
|
||
| - (void)clipRRect:(const SkRRect&)clipSkRRect matrix:(const CATransform3D&)matrix { | ||
| - (void)clipRRect:(const SkRRect&)clipSkRRect matrix:(const SkMatrix&)matrix { | ||
| CGPathRef pathRef = nullptr; | ||
| switch (clipSkRRect.getType()) { | ||
| case SkRRect::kEmpty_Type: { | ||
|
|
@@ -346,13 +364,16 @@ - (void)clipRRect:(const SkRRect&)clipSkRRect matrix:(const CATransform3D&)matri | |
| break; | ||
| } | ||
| } | ||
| // The `matrix` is based on the physical pixels, convert it to UIKit points. | ||
| CATransform3D matrixInPoints = | ||
| CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale); | ||
| // TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated that | ||
| // the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard edge | ||
| // clipping on iOS. | ||
| paths_.push_back([self getTransformedPath:pathRef matrix:matrix]); | ||
| paths_.push_back([self getTransformedPath:pathRef matrix:matrixInPoints]); | ||
| } | ||
|
|
||
| - (void)clipPath:(const SkPath&)path matrix:(const CATransform3D&)matrix { | ||
| - (void)clipPath:(const SkPath&)path matrix:(const SkMatrix&)matrix { | ||
| if (!path.isValid()) { | ||
| return; | ||
| } | ||
|
|
@@ -411,7 +432,10 @@ - (void)clipPath:(const SkPath&)path matrix:(const CATransform3D&)matrix { | |
| } | ||
| verb = iter.next(pts); | ||
| } | ||
| paths_.push_back([self getTransformedPath:pathRef matrix:matrix]); | ||
| // The `matrix` is based on the physical pixels, convert it to UIKit points. | ||
| CATransform3D matrixInPoints = | ||
| CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale); | ||
| paths_.push_back([self getTransformedPath:pathRef matrix:matrixInPoints]); | ||
| } | ||
|
|
||
| - (fml::CFRef<CGPathRef>)getTransformedPath:(CGPathRef)path matrix:(CATransform3D)matrix { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the comment here to explain
bounding_rect? It's not clear from immediate context what exactly it is the bounds of.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done