Flutter iOS Embedder
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 29 of file FlutterPlatformViews_Internal.h.

Method Documentation

◆ clipPath:matrix:

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

Definition at line 385 of file FlutterPlatformViews_Internal.mm.

385  :(const SkPath&)path matrix:(const SkMatrix&)matrix {
386  if (!path.isValid()) {
387  return;
388  }
389  if (path.isEmpty()) {
390  return;
391  }
392  CGMutablePathRef pathRef = CGPathCreateMutable();
393 
394  // Loop through all verbs and translate them into CGPath
395  SkPath::Iter iter(path, true);
396  SkPoint pts[kMaxPointsInVerb];
397  SkPath::Verb verb = iter.next(pts);
398  SkPoint last_pt_from_last_verb = SkPoint::Make(0, 0);
399  while (verb != SkPath::kDone_Verb) {
400  if (verb == SkPath::kLine_Verb || verb == SkPath::kQuad_Verb || verb == SkPath::kConic_Verb ||
401  verb == SkPath::kCubic_Verb) {
402  FML_DCHECK(last_pt_from_last_verb == pts[0]);
403  }
404  switch (verb) {
405  case SkPath::kMove_Verb: {
406  CGPathMoveToPoint(pathRef, nil, pts[0].x(), pts[0].y());
407  last_pt_from_last_verb = pts[0];
408  break;
409  }
410  case SkPath::kLine_Verb: {
411  CGPathAddLineToPoint(pathRef, nil, pts[1].x(), pts[1].y());
412  last_pt_from_last_verb = pts[1];
413  break;
414  }
415  case SkPath::kQuad_Verb: {
416  CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
417  last_pt_from_last_verb = pts[2];
418  break;
419  }
420  case SkPath::kConic_Verb: {
421  // Conic is not available in quartz, we use quad to approximate.
422  // TODO(cyanglaz): Better approximate the conic path.
423  // https://github.com/flutter/flutter/issues/35062
424  CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
425  last_pt_from_last_verb = pts[2];
426  break;
427  }
428  case SkPath::kCubic_Verb: {
429  CGPathAddCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y(),
430  pts[3].x(), pts[3].y());
431  last_pt_from_last_verb = pts[3];
432  break;
433  }
434  case SkPath::kClose_Verb: {
435  CGPathCloseSubpath(pathRef);
436  break;
437  }
438  case SkPath::kDone_Verb: {
439  break;
440  }
441  }
442  verb = iter.next(pts);
443  }
444  // The `matrix` is based on the physical pixels, convert it to UIKit points.
445  CATransform3D matrixInPoints =
446  CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
447  paths_.push_back([self getTransformedPath:pathRef matrix:matrixInPoints]);
448 }

References flutter::GetCATransform3DFromSkMatrix().

◆ clipRect:matrix:

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

Definition at line 307 of file FlutterPlatformViews_Internal.mm.

307  :(const SkRect&)clipSkRect matrix:(const SkMatrix&)matrix {
308  CGRect clipRect = flutter::GetCGRectFromSkRect(clipSkRect);
309  CGPathRef path = CGPathCreateWithRect(clipRect, nil);
310  // The `matrix` is based on the physical pixels, convert it to UIKit points.
311  CATransform3D matrixInPoints =
312  CATransform3DConcat(flutter::GetCATransform3DFromSkMatrix(matrix), _reverseScreenScale);
313  paths_.push_back([self getTransformedPath:path matrix:matrixInPoints]);
314 }

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

Referenced by clipRRect:matrix:.

◆ clipRRect:matrix:

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

Definition at line 316 of file FlutterPlatformViews_Internal.mm.

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

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

◆ initWithFrame:screenScale:

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

Definition at line 270 of file FlutterPlatformViews_Internal.mm.

270  :(CGRect)frame screenScale:(CGFloat)screenScale {
271  if (self = [super initWithFrame:frame]) {
272  self.backgroundColor = UIColor.clearColor;
273  _reverseScreenScale = CATransform3DMakeScale(1 / screenScale, 1 / screenScale, 1);
274  }
275  return self;
276 }

References initWithFrame.

◆ reset

- (void) reset

Definition at line 278 of file FlutterPlatformViews_Internal.mm.

278  {
279  paths_.clear();
280  [self setNeedsDisplay];
281 }

The documentation for this class was generated from the following files:
initWithFrame
instancetype initWithFrame
Definition: FlutterTextInputPlugin.h:167
flutter::GetCATransform3DFromSkMatrix
CATransform3D GetCATransform3DFromSkMatrix(const SkMatrix &matrix)
Definition: FlutterPlatformViews_Internal.mm:41
flutter::GetCGRectFromSkRect
CGRect GetCGRectFromSkRect(const SkRect &clipSkRect)
Definition: FlutterPlatformViews_Internal.mm:62