@@ -32,6 +32,16 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
3232}
3333@end
3434
35+ static bool ClipBoundsContainsPlatformViewBoundingRect (const SkRect& clipBounds,
36+ const SkRect& platformViewBoundingRect,
37+ const SkMatrix& transformMatrix,
38+ CGFloat screenScale) {
39+ SkRect transformedClipBounds = transformMatrix.mapRect (clipBounds);
40+ SkMatrix reverseScreenScale = SkMatrix::Scale (1 / screenScale, 1 / screenScale);
41+ SkRect scaledBoundingRect = reverseScreenScale.mapRect (platformViewBoundingRect);
42+ return transformedClipBounds.contains (scaledBoundingRect);
43+ }
44+
3545namespace flutter {
3646// Becomes NO if Apple's API changes and blurred backdrop filters cannot be applied.
3747BOOL canApplyBlurBackdrop = YES ;
@@ -405,7 +415,7 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
405415
406416void FlutterPlatformViewsController::ApplyMutators (const MutatorsStack& mutators_stack,
407417 UIView* embedded_view,
408- const SkRect& boundingRect ) {
418+ const SkRect& bounding_rect ) {
409419 if (flutter_view_ == nullptr ) {
410420 return ;
411421 }
@@ -419,7 +429,7 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
419429 // 500 points in UIKit. And until this point, we did all the calculation based on the flow
420430 // resolution. So we need to scale down to match UIKit's logical resolution.
421431 CGFloat screenScale = [UIScreen mainScreen ].scale ;
422- CATransform3D finalTransform = CATransform3DMakeScale (1 / screenScale, 1 / screenScale, 1 );
432+ SkMatrix transformMatrix = SkMatrix::Scale (1 / screenScale, 1 / screenScale);
423433
424434 UIView* flutter_view = flutter_view_.get ();
425435 FlutterClippingMaskView* maskView = [[[FlutterClippingMaskView alloc ]
@@ -434,31 +444,37 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
434444 while (iter != mutators_stack.End ()) {
435445 switch ((*iter)->GetType ()) {
436446 case kTransform : {
437- CATransform3D transform = GetCATransform3DFromSkMatrix ((*iter)->GetMatrix ());
438- finalTransform = CATransform3DConcat (transform, finalTransform);
447+ transformMatrix = SkMatrix::Concat ((*iter)->GetMatrix (), transformMatrix);
439448 break ;
440449 }
441- case kClipRect :
442- if ((*iter)->GetRect ().contains (boundingRect)) {
450+ case kClipRect : {
451+ if (ClipBoundsContainsPlatformViewBoundingRect ((*iter)->GetRect (), bounding_rect,
452+ transformMatrix, screenScale)) {
443453 break ;
444454 }
445- [maskView clipRect: (*iter)->GetRect () matrix: finalTransform ];
455+ [maskView clipRect: (*iter)->GetRect () matrix: GetCATransform3DFromSkMatrix (transformMatrix) ];
446456 needMask = YES ;
447457 break ;
448- case kClipRRect :
449- if ((*iter)->GetRRect ().getBounds ().contains (boundingRect)) {
458+ }
459+ case kClipRRect : {
460+ if (ClipBoundsContainsPlatformViewBoundingRect (
461+ (*iter)->GetRRect ().getBounds (), bounding_rect, transformMatrix, screenScale)) {
450462 break ;
451463 }
452- [maskView clipRRect: (*iter)->GetRRect () matrix: finalTransform];
464+ [maskView clipRRect: (*iter)->GetRRect ()
465+ matrix: GetCATransform3DFromSkMatrix (transformMatrix)];
453466 needMask = YES ;
454467 break ;
455- case kClipPath :
456- if ((*iter)->GetPath ().getBounds ().contains (boundingRect)) {
468+ }
469+ case kClipPath : {
470+ if (ClipBoundsContainsPlatformViewBoundingRect (
471+ (*iter)->GetPath ().getBounds (), bounding_rect, transformMatrix, screenScale)) {
457472 break ;
458473 }
459- [maskView clipPath: (*iter)->GetPath () matrix: finalTransform ];
474+ [maskView clipPath: (*iter)->GetPath () matrix: GetCATransform3DFromSkMatrix (transformMatrix) ];
460475 needMask = YES ;
461476 break ;
477+ }
462478 case kOpacity :
463479 embedded_view.alpha = (*iter)->GetAlphaFloat () * embedded_view.alpha ;
464480 break ;
@@ -512,9 +528,12 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
512528 // the mask view, whose origin is always (0,0) to the flutter_view.
513529 CATransform3D reverseTranslate =
514530 CATransform3DMakeTranslation (-clipView.frame .origin .x , -clipView.frame .origin .y , 0 );
515- embedded_view.layer .transform = CATransform3DConcat (finalTransform, reverseTranslate);
531+ embedded_view.layer .transform =
532+ CATransform3DConcat (GetCATransform3DFromSkMatrix (transformMatrix), reverseTranslate);
516533 if (needMask) {
517534 clipView.maskView = maskView;
535+ } else {
536+ clipView.maskView = nil ;
518537 }
519538}
520539
0 commit comments