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 250 of file FlutterPlatformViews.mm.

Method Documentation

◆ clipPath:matrix:

- (void) clipPath: (const flutter::DlPath&)  path
matrix: (const flutter::DlMatrix&)  matrix 

Definition at line 253 of file FlutterPlatformViews.mm.

422  :(const flutter::DlPath&)dlPath matrix:(const flutter::DlMatrix&)matrix {
423  containsNonRectPath_ = YES;
424 
425  CGPathReceiver receiver;
426 
427  // TODO(flar): https://github.com/flutter/flutter/issues/164826
428  // CGPaths do not have an inherit fill type, we would need to remember
429  // the fill type and employ it when we use the path.
430  dlPath.Dispatch(receiver);
431 
432  // The `matrix` is based on the physical pixels, convert it to UIKit points.
433  CATransform3D matrixInPoints =
434  CATransform3DConcat(GetCATransform3DFromDlMatrix(matrix), _reverseScreenScale);
435  paths_.push_back([self getTransformedPath:receiver.TakePath() matrix:matrixInPoints]);
436 }
BOOL containsNonRectPath_
static CATransform3D GetCATransform3DFromDlMatrix(const DlMatrix &matrix)

◆ clipRect:matrix:

- (void) clipRect: (const flutter::DlRect&)  clipDlRect
matrix: (const flutter::DlMatrix&)  matrix 

Definition at line 253 of file FlutterPlatformViews.mm.

329  :(const flutter::DlRect&)clipDlRect matrix:(const flutter::DlMatrix&)matrix {
330  CGRect clipRect = GetCGRectFromDlRect(clipDlRect);
331  CGPathRef path = CGPathCreateWithRect(clipRect, nil);
332  // The `matrix` is based on the physical pixels, convert it to UIKit points.
333  CATransform3D matrixInPoints =
334  CATransform3DConcat(GetCATransform3DFromDlMatrix(matrix), _reverseScreenScale);
335  paths_.push_back([self getTransformedPath:path matrix:matrixInPoints]);
336  CGAffineTransform affine = [self affineWithMatrix:matrixInPoints];
337  // Make sure the rect is not rotated (only translated or scaled).
338  if (affine.b == 0 && affine.c == 0) {
339  rectSoFar_ = CGRectIntersection(rectSoFar_, CGRectApplyAffineTransform(clipRect, affine));
340  } else {
341  containsNonRectPath_ = YES;
342  }
343 }
CGRect rectSoFar_
static CGRect GetCGRectFromDlRect(const DlRect &clipDlRect)

◆ clipRRect:matrix:

- (void) clipRRect: (const flutter::DlRoundRect&)  clipDlRRect
matrix: (const flutter::DlMatrix&)  matrix 

Definition at line 253 of file FlutterPlatformViews.mm.

345  :(const flutter::DlRoundRect&)clipDlRRect matrix:(const flutter::DlMatrix&)matrix {
346  if (clipDlRRect.IsEmpty()) {
347  return;
348  } else if (clipDlRRect.IsRect()) {
349  [self clipRect:clipDlRRect.GetBounds() matrix:matrix];
350  return;
351  } else {
352  CGPathRef pathRef = nullptr;
353  containsNonRectPath_ = YES;
354 
355  if (clipDlRRect.GetRadii().AreAllCornersSame()) {
356  CGRect clipRect = GetCGRectFromDlRect(clipDlRRect.GetBounds());
357  auto radii = clipDlRRect.GetRadii();
358  pathRef =
359  CGPathCreateWithRoundedRect(clipRect, radii.top_left.width, radii.top_left.height, nil);
360  } else {
361  CGMutablePathRef mutablePathRef = CGPathCreateMutable();
362  // Complex types, we manually add each corner.
363  flutter::DlRect clipDlRect = clipDlRRect.GetBounds();
364  auto left = clipDlRect.GetLeft();
365  auto top = clipDlRect.GetTop();
366  auto right = clipDlRect.GetRight();
367  auto bottom = clipDlRect.GetBottom();
368  flutter::DlRoundingRadii radii = clipDlRRect.GetRadii();
369  auto& top_left = radii.top_left;
370  auto& top_right = radii.top_right;
371  auto& bottom_left = radii.bottom_left;
372  auto& bottom_right = radii.bottom_right;
373 
374  // Start drawing RRect
375  // These calculations are off, the AddCurve methods add a Bezier curve
376  // which, for round rects should be a "magic distance" from the end
377  // point of the horizontal/vertical section to the corner.
378  // Move point to the top left corner adding the top left radii's x.
379  CGPathMoveToPoint(mutablePathRef, nil, //
380  left + top_left.width, top);
381  // Move point horizontally right to the top right corner and add the top right curve.
382  CGPathAddLineToPoint(mutablePathRef, nil, //
383  right - top_right.width, top);
384  CGPathAddCurveToPoint(mutablePathRef, nil, //
385  right, top, //
386  right, top + top_right.height, //
387  right, top + top_right.height);
388  // Move point vertically down to the bottom right corner and add the bottom right curve.
389  CGPathAddLineToPoint(mutablePathRef, nil, //
390  right, bottom - bottom_right.height);
391  CGPathAddCurveToPoint(mutablePathRef, nil, //
392  right, bottom, //
393  right - bottom_right.width, bottom, //
394  right - bottom_right.width, bottom);
395  // Move point horizontally left to the bottom left corner and add the bottom left curve.
396  CGPathAddLineToPoint(mutablePathRef, nil, //
397  left + bottom_left.width, bottom);
398  CGPathAddCurveToPoint(mutablePathRef, nil, //
399  left, bottom, //
400  left, bottom - bottom_left.height, //
401  left, bottom - bottom_left.height);
402  // Move point vertically up to the top left corner and add the top left curve.
403  CGPathAddLineToPoint(mutablePathRef, nil, //
404  left, top + top_left.height);
405  CGPathAddCurveToPoint(mutablePathRef, nil, //
406  left, top, //
407  left + top_left.width, top, //
408  left + top_left.width, top);
409  CGPathCloseSubpath(mutablePathRef);
410  pathRef = mutablePathRef;
411  }
412  // The `matrix` is based on the physical pixels, convert it to UIKit points.
413  CATransform3D matrixInPoints =
414  CATransform3DConcat(GetCATransform3DFromDlMatrix(matrix), _reverseScreenScale);
415  // TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated
416  // that the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard
417  // edge clipping on iOS.
418  paths_.push_back([self getTransformedPath:pathRef matrix:matrixInPoints]);
419  }
420 }

◆ initWithFrame:screenScale:

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

Definition at line 253 of file FlutterPlatformViews.mm.

260  :(CGRect)frame screenScale:(CGFloat)screenScale {
261  if (self = [super initWithFrame:frame]) {
262  self.backgroundColor = UIColor.clearColor;
263  _reverseScreenScale = CATransform3DMakeScale(1 / screenScale, 1 / screenScale, 1);
264  rectSoFar_ = self.bounds;
266  }
267  return self;
268 }
instancetype initWithFrame

◆ reset

- (void) reset

Definition at line 253 of file FlutterPlatformViews.mm.

278  {
279  paths_.clear();
280  rectSoFar_ = self.bounds;
282  [self shapeLayer].path = nil;
283  [self setNeedsDisplay];
284 }

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