| Flutter iOS Embedder |

Instance Methods | List of all members
FlutterClippingMaskView Class Reference

`#import <FlutterPlatformViews_Internal.h>`

Inheritance diagram for FlutterClippingMaskView:

## Instance Methods
(instancetype) | - initWithFrame:screenScale:
(void) | - reset
(void) | - clipRect:matrix:
(void) | - clipRRect:matrix:
(void) | - clipPath:matrix:

## Detailed Description

Definition at line 31 of file FlutterPlatformViews_Internal.h.

## Method Documentation

## ◆ clipPath:matrix:

- (void) clipPath: |  | (const SkPath&) | path
matrix: |  | (const SkMatrix&) | matrix

Definition at line 408 of file FlutterPlatformViews_Internal.mm.

408 :(const SkPath&)path matrix:(const SkMatrix&)matrix {
409 if (!path.isValid()) {
410 return;
411 }
412 if (path.isEmpty()) {
413 return;
414 }
415 containsNonRectPath_ = YES;
416 CGMutablePathRef pathRef = CGPathCreateMutable();
417
418 // Loop through all verbs and translate them into CGPath
419 SkPath::Iter iter(path, true);
420 SkPoint pts[kMaxPointsInVerb];
421 SkPath::Verb verb = iter.next(pts);
422 SkPoint last_pt_from_last_verb = SkPoint::Make(0, 0);
423 while (verb != SkPath::kDone_Verb) {
424 if (verb == SkPath::kLine_Verb || verb == SkPath::kQuad_Verb || verb == SkPath::kConic_Verb ||
425 verb == SkPath::kCubic_Verb) {
426 FML_DCHECK(last_pt_from_last_verb == pts[0]);
427 }
428 switch (verb) {
429 case SkPath::kMove_Verb: {
430 CGPathMoveToPoint(pathRef, nil, pts[0].x(), pts[0].y());
431 last_pt_from_last_verb = pts[0];
432 break;
433 }
434 case SkPath::kLine_Verb: {
435 CGPathAddLineToPoint(pathRef, nil, pts[1].x(), pts[1].y());
436 last_pt_from_last_verb = pts[1];
437 break;
438 }
439 case SkPath::kQuad_Verb: {
440 CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
441 last_pt_from_last_verb = pts[2];
442 break;
443 }
444 case SkPath::kConic_Verb: {
445 // Conic is not available in quartz, we use quad to approximate.
446 // TODO(cyanglaz): Better approximate the conic path.
447 // https://github.com/flutter/flutter/issues/35062
448 CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
449 last_pt_from_last_verb = pts[2];
450 break;
451 }
452 case SkPath::kCubic_Verb: {
453 CGPathAddCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y(),
454 pts[3].x(), pts[3].y());
455 last_pt_from_last_verb = pts[3];
456 break;
457 }
458 case SkPath::kClose_Verb: {
459 CGPathCloseSubpath(pathRef);
460 break;
461 }
462 case SkPath::kDone_Verb: {
463 break;
464 }
465 }
466 verb = iter.next(pts);
467 }
468 // The `matrix` is based on the physical pixels, convert it to UIKit points.
469 CATransform3D matrixInPoints =
470 CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
471 paths_.push_back([self getTransformedPath:pathRef matrix:matrixInPoints]);
472 }

References containsNonRectPath_, and flutter::GetCATransform3DFromSkMatrix().

## ◆ clipRect:matrix:

- (void) clipRect: |  | (const SkRect&) | clipSkRect
matrix: |  | (const SkMatrix&) | matrix

Definition at line 322 of file FlutterPlatformViews_Internal.mm.

322 :(const SkRect&)clipSkRect matrix:(const SkMatrix&)matrix {
323 CGRect clipRect = flutter::GetCGRectFromSkRect(clipSkRect);
324 CGPathRef path = CGPathCreateWithRect(clipRect, nil);
325 // The `matrix` is based on the physical pixels, convert it to UIKit points.
326 CATransform3D matrixInPoints =
327 CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
328 paths_.push_back([self getTransformedPath:path matrix:matrixInPoints]);
329 CGAffineTransform affine = [self affineWithMatrix:matrixInPoints];
330 // Make sure the rect is not rotated (only translated or scaled).
331 if (affine.b == 0 && affine.c == 0) {
332 rectSoFar_ = CGRectIntersection(rectSoFar_, CGRectApplyAffineTransform(clipRect, affine));
333 } else {
334 containsNonRectPath_ = YES;
335 }
336 }

References containsNonRectPath_, flutter::GetCATransform3DFromSkMatrix(), flutter::GetCGRectFromSkRect(), and rectSoFar_.

Referenced by clipRRect:matrix:.

## ◆ clipRRect:matrix:

- (void) clipRRect: |  | (const SkRRect&) | clipSkRRect
matrix: |  | (const SkMatrix&) | matrix

Definition at line 338 of file FlutterPlatformViews_Internal.mm.

338 :(const SkRRect&)clipSkRRect matrix:(const SkMatrix&)matrix {
339 containsNonRectPath_ = YES;
340 CGPathRef pathRef = nullptr;
341 switch (clipSkRRect.getType()) {
342 case SkRRect::kEmpty_Type: {
343 break;
344 }
345 case SkRRect::kRect_Type: {
346 [self clipRect:clipSkRRect.rect() matrix:matrix];
347 return;
348 }
349 case SkRRect::kOval_Type:
350 case SkRRect::kSimple_Type: {
351 CGRect clipRect = flutter::GetCGRectFromSkRect(clipSkRRect.rect());
352 pathRef = CGPathCreateWithRoundedRect(clipRect, clipSkRRect.getSimpleRadii().x(),
353 clipSkRRect.getSimpleRadii().y(), nil);
354 break;
355 }
356 case SkRRect::kNinePatch_Type:
357 case SkRRect::kComplex_Type: {
358 CGMutablePathRef mutablePathRef = CGPathCreateMutable();
359 // Complex types, we manually add each corner.
360 SkRect clipSkRect = clipSkRRect.rect();
361 SkVector topLeftRadii = clipSkRRect.radii(SkRRect::kUpperLeft_Corner);
362 SkVector topRightRadii = clipSkRRect.radii(SkRRect::kUpperRight_Corner);
363 SkVector bottomRightRadii = clipSkRRect.radii(SkRRect::kLowerRight_Corner);
364 SkVector bottomLeftRadii = clipSkRRect.radii(SkRRect::kLowerLeft_Corner);
365
366 // Start drawing RRect
367 // Move point to the top left corner adding the top left radii's x.
368 CGPathMoveToPoint(mutablePathRef, nil, clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop);
369 // Move point horizontally right to the top right corner and add the top right curve.
370 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fRight - topRightRadii.x(),
371 clipSkRect.fTop);
372 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fRight, clipSkRect.fTop,
373 clipSkRect.fRight, clipSkRect.fTop + topRightRadii.y(),
374 clipSkRect.fRight, clipSkRect.fTop + topRightRadii.y());
375 // Move point vertically down to the bottom right corner and add the bottom right curve.
376 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fRight,
377 clipSkRect.fBottom - bottomRightRadii.y());
378 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fRight, clipSkRect.fBottom,
379 clipSkRect.fRight - bottomRightRadii.x(), clipSkRect.fBottom,
380 clipSkRect.fRight - bottomRightRadii.x(), clipSkRect.fBottom);
381 // Move point horizontally left to the bottom left corner and add the bottom left curve.
382 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fLeft + bottomLeftRadii.x(),
383 clipSkRect.fBottom);
384 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fLeft, clipSkRect.fBottom,
385 clipSkRect.fLeft, clipSkRect.fBottom - bottomLeftRadii.y(),
386 clipSkRect.fLeft, clipSkRect.fBottom - bottomLeftRadii.y());
387 // Move point vertically up to the top left corner and add the top left curve.
388 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fLeft,
389 clipSkRect.fTop + topLeftRadii.y());
390 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fLeft, clipSkRect.fTop,
391 clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop,
392 clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop);
393 CGPathCloseSubpath(mutablePathRef);
394
395 pathRef = mutablePathRef;
396 break;
397 }
398 }
399 // The `matrix` is based on the physical pixels, convert it to UIKit points.
400 CATransform3D matrixInPoints =
401 CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
402 // TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated that
403 // the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard edge
404 // clipping on iOS.
405 paths_.push_back([self getTransformedPath:pathRef matrix:matrixInPoints]);
406 }

References clipRect:matrix:, containsNonRectPath_, flutter::GetCATransform3DFromSkMatrix(), and flutter::GetCGRectFromSkRect().

## ◆ initWithFrame:screenScale:

- (instancetype) initWithFrame: |  | (CGRect) | frame
screenScale: |  | (CGFloat) | screenScale

Definition at line 253 of file FlutterPlatformViews_Internal.mm.

253 :(CGRect)frame screenScale:(CGFloat)screenScale {
254 if (self = [super initWithFrame:frame]) {
255 self.backgroundColor = UIColor.clearColor;
256 _reverseScreenScale = CATransform3DMakeScale(1 / screenScale, 1 / screenScale, 1);
257 rectSoFar_ = self.bounds;
258 containsNonRectPath_ = NO;
259 }
260 return self;
261 }

References containsNonRectPath_, initWithFrame, and rectSoFar_.

## ◆ reset

- (void) reset |  |  |

Definition at line 271 of file FlutterPlatformViews_Internal.mm.

271 {
272 paths_.clear();
273 rectSoFar_ = self.bounds;
274 containsNonRectPath_ = NO;
275 [self shapeLayer].path = nil;
276 [self setNeedsDisplay];
277 }

References containsNonRectPath_, and rectSoFar_.

The documentation for this class was generated from the following files:

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

containsNonRectPath_
BOOL containsNonRectPath_
Definition: FlutterPlatformViews_Internal.mm:243
initWithFrame
instancetype initWithFrame
Definition: FlutterTextInputPlugin.h:172
rectSoFar_
CGRect rectSoFar_
Definition: FlutterPlatformViews_Internal.mm:246
flutter::GetCATransform3DFromSkMatrix
CATransform3D GetCATransform3DFromSkMatrix(const SkMatrix &matrix)
Definition: FlutterPlatformViews_Internal.mm:43
flutter::GetCGRectFromSkRect
CGRect GetCGRectFromSkRect(const SkRect &clipSkRect)
Definition: FlutterPlatformViews_Internal.mm:64