| 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 366 of file FlutterPlatformViews_Internal.mm.

366 :(const SkPath&)path matrix:(const SkMatrix&)matrix {
367 if (!path.isValid()) {
368 return;
369 }
370 if (path.isEmpty()) {
371 return;
372 }
373 CGMutablePathRef pathRef = CGPathCreateMutable();
374
375 // Loop through all verbs and translate them into CGPath
376 SkPath::Iter iter(path, true);
377 SkPoint pts[kMaxPointsInVerb];
378 SkPath::Verb verb = iter.next(pts);
379 SkPoint last_pt_from_last_verb = SkPoint::Make(0, 0);
380 while (verb != SkPath::kDone_Verb) {
381 if (verb == SkPath::kLine_Verb || verb == SkPath::kQuad_Verb || verb == SkPath::kConic_Verb ||
382 verb == SkPath::kCubic_Verb) {
383 FML_DCHECK(last_pt_from_last_verb == pts[0]);
384 }
385 switch (verb) {
386 case SkPath::kMove_Verb: {
387 CGPathMoveToPoint(pathRef, nil, pts[0].x(), pts[0].y());
388 last_pt_from_last_verb = pts[0];
389 break;
390 }
391 case SkPath::kLine_Verb: {
392 CGPathAddLineToPoint(pathRef, nil, pts[1].x(), pts[1].y());
393 last_pt_from_last_verb = pts[1];
394 break;
395 }
396 case SkPath::kQuad_Verb: {
397 CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
398 last_pt_from_last_verb = pts[2];
399 break;
400 }
401 case SkPath::kConic_Verb: {
402 // Conic is not available in quartz, we use quad to approximate.
403 // TODO(cyanglaz): Better approximate the conic path.
404 // https://github.com/flutter/flutter/issues/35062
405 CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
406 last_pt_from_last_verb = pts[2];
407 break;
408 }
409 case SkPath::kCubic_Verb: {
410 CGPathAddCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y(),
411 pts[3].x(), pts[3].y());
412 last_pt_from_last_verb = pts[3];
413 break;
414 }
415 case SkPath::kClose_Verb: {
416 CGPathCloseSubpath(pathRef);
417 break;
418 }
419 case SkPath::kDone_Verb: {
420 break;
421 }
422 }
423 verb = iter.next(pts);
424 }
425 // The `matrix` is based on the physical pixels, convert it to UIKit points.
426 CATransform3D matrixInPoints =
427 CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
428 [self addTransformedPath:pathRef matrix:matrixInPoints];
429 }

References flutter::GetCATransform3DFromSkMatrix().

## ◆ clipRect:matrix:

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

Definition at line 288 of file FlutterPlatformViews_Internal.mm.

288 :(const SkRect&)clipSkRect matrix:(const SkMatrix&)matrix {
289 CGRect clipRect = flutter::GetCGRectFromSkRect(clipSkRect);
290 CGPathRef path = CGPathCreateWithRect(clipRect, nil);
291 // The `matrix` is based on the physical pixels, convert it to UIKit points.
292 CATransform3D matrixInPoints =
293 CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
294 [self addTransformedPath:path matrix:matrixInPoints];
295 }

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

Referenced by clipRRect:matrix:.

## ◆ clipRRect:matrix:

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

Definition at line 297 of file FlutterPlatformViews_Internal.mm.

297 :(const SkRRect&)clipSkRRect matrix:(const SkMatrix&)matrix {
298 CGPathRef pathRef = nullptr;
299 switch (clipSkRRect.getType()) {
300 case SkRRect::kEmpty_Type: {
301 break;
302 }
303 case SkRRect::kRect_Type: {
304 [self clipRect:clipSkRRect.rect() matrix:matrix];
305 return;
306 }
307 case SkRRect::kOval_Type:
308 case SkRRect::kSimple_Type: {
309 CGRect clipRect = flutter::GetCGRectFromSkRect(clipSkRRect.rect());
310 pathRef = CGPathCreateWithRoundedRect(clipRect, clipSkRRect.getSimpleRadii().x(),
311 clipSkRRect.getSimpleRadii().y(), nil);
312 break;
313 }
314 case SkRRect::kNinePatch_Type:
315 case SkRRect::kComplex_Type: {
316 CGMutablePathRef mutablePathRef = CGPathCreateMutable();
317 // Complex types, we manually add each corner.
318 SkRect clipSkRect = clipSkRRect.rect();
319 SkVector topLeftRadii = clipSkRRect.radii(SkRRect::kUpperLeft_Corner);
320 SkVector topRightRadii = clipSkRRect.radii(SkRRect::kUpperRight_Corner);
321 SkVector bottomRightRadii = clipSkRRect.radii(SkRRect::kLowerRight_Corner);
322 SkVector bottomLeftRadii = clipSkRRect.radii(SkRRect::kLowerLeft_Corner);
323
324 // Start drawing RRect
325 // Move point to the top left corner adding the top left radii's x.
326 CGPathMoveToPoint(mutablePathRef, nil, clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop);
327 // Move point horizontally right to the top right corner and add the top right curve.
328 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fRight - topRightRadii.x(),
329 clipSkRect.fTop);
330 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fRight, clipSkRect.fTop,
331 clipSkRect.fRight, clipSkRect.fTop + topRightRadii.y(),
332 clipSkRect.fRight, clipSkRect.fTop + topRightRadii.y());
333 // Move point vertically down to the bottom right corner and add the bottom right curve.
334 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fRight,
335 clipSkRect.fBottom - bottomRightRadii.y());
336 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fRight, clipSkRect.fBottom,
337 clipSkRect.fRight - bottomRightRadii.x(), clipSkRect.fBottom,
338 clipSkRect.fRight - bottomRightRadii.x(), clipSkRect.fBottom);
339 // Move point horizontally left to the bottom left corner and add the bottom left curve.
340 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fLeft + bottomLeftRadii.x(),
341 clipSkRect.fBottom);
342 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fLeft, clipSkRect.fBottom,
343 clipSkRect.fLeft, clipSkRect.fBottom - bottomLeftRadii.y(),
344 clipSkRect.fLeft, clipSkRect.fBottom - bottomLeftRadii.y());
345 // Move point vertically up to the top left corner and add the top left curve.
346 CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fLeft,
347 clipSkRect.fTop + topLeftRadii.y());
348 CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fLeft, clipSkRect.fTop,
349 clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop,
350 clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop);
351 CGPathCloseSubpath(mutablePathRef);
352
353 pathRef = mutablePathRef;
354 break;
355 }
356 }
357 // The `matrix` is based on the physical pixels, convert it to UIKit points.
358 CATransform3D matrixInPoints =
359 CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
360 // TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated that
361 // the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard edge
362 // clipping on iOS.
363 [self addTransformedPath:pathRef matrix:matrixInPoints];
364 }

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

## ◆ initWithFrame:screenScale:

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

Definition at line 251 of file FlutterPlatformViews_Internal.mm.

251 :(CGRect)frame screenScale:(CGFloat)screenScale {
252 if (self = [super initWithFrame:frame]) {
253 self.backgroundColor = UIColor.clearColor;
254 _reverseScreenScale = CATransform3DMakeScale(1 / screenScale, 1 / screenScale, 1);
255 pathSoFar_ = CGPathCreateMutable();
256 }
257 return self;
258 }

References initWithFrame.

## ◆ reset

- (void) reset |  |  |

Definition at line 268 of file FlutterPlatformViews_Internal.mm.

268 {
269 CGPathRelease(pathSoFar_);
270 pathSoFar_ = CGPathCreateMutable();
271 [self shapeLayer].path = nil;
272 [self setNeedsDisplay];
273 }

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

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