Flutter Engine
FlutterClippingMaskView Class Reference

#import <FlutterPlatformViews_Internal.h>

Inheritance diagram for FlutterClippingMaskView:

Instance Methods

(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 CATransform3D&)  matrix 

Definition at line 189 of file FlutterPlatformViews_Internal.mm.

References FML_DCHECK, and flutter::path.

189  :(const SkPath&)path matrix:(const CATransform3D&)matrix {
190  if (!path.isValid()) {
191  return;
192  }
193  if (path.isEmpty()) {
194  return;
195  }
196  CGMutablePathRef pathRef = CGPathCreateMutable();
197 
198  // Loop through all verbs and translate them into CGPath
199  SkPath::Iter iter(path, true);
200  SkPoint pts[kMaxPointsInVerb];
201  SkPath::Verb verb = iter.next(pts);
202  SkPoint last_pt_from_last_verb;
203  while (verb != SkPath::kDone_Verb) {
204  if (verb == SkPath::kLine_Verb || verb == SkPath::kQuad_Verb || verb == SkPath::kConic_Verb ||
205  verb == SkPath::kCubic_Verb) {
206  FML_DCHECK(last_pt_from_last_verb == pts[0]);
207  }
208  switch (verb) {
209  case SkPath::kMove_Verb: {
210  CGPathMoveToPoint(pathRef, nil, pts[0].x(), pts[0].y());
211  last_pt_from_last_verb = pts[0];
212  break;
213  }
214  case SkPath::kLine_Verb: {
215  CGPathAddLineToPoint(pathRef, nil, pts[1].x(), pts[1].y());
216  last_pt_from_last_verb = pts[1];
217  break;
218  }
219  case SkPath::kQuad_Verb: {
220  CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
221  last_pt_from_last_verb = pts[2];
222  break;
223  }
224  case SkPath::kConic_Verb: {
225  // Conic is not available in quartz, we use quad to approximate.
226  // TODO(cyanglaz): Better approximate the conic path.
227  // https://github.com/flutter/flutter/issues/35062
228  CGPathAddQuadCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y());
229  last_pt_from_last_verb = pts[2];
230  break;
231  }
232  case SkPath::kCubic_Verb: {
233  CGPathAddCurveToPoint(pathRef, nil, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y(),
234  pts[3].x(), pts[3].y());
235  last_pt_from_last_verb = pts[3];
236  break;
237  }
238  case SkPath::kClose_Verb: {
239  CGPathCloseSubpath(pathRef);
240  break;
241  }
242  case SkPath::kDone_Verb: {
243  break;
244  }
245  }
246  verb = iter.next(pts);
247  }
248  paths_.push_back([self getTransformedPath:pathRef matrix:matrix]);
249 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ clipRect:matrix:()

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

Definition at line 117 of file FlutterPlatformViews_Internal.mm.

References flutter::path.

Referenced by clipRRect:matrix:.

117  :(const SkRect&)clipSkRect matrix:(const CATransform3D&)matrix {
118  CGRect clipRect = [self getCGRectFromSkRect:clipSkRect];
119  CGPathRef path = CGPathCreateWithRect(clipRect, nil);
120  paths_.push_back([self getTransformedPath:path matrix:matrix]);
121 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32

◆ clipRRect:matrix:()

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

Definition at line 123 of file FlutterPlatformViews_Internal.mm.

References clipRect:matrix:.

123  :(const SkRRect&)clipSkRRect matrix:(const CATransform3D&)matrix {
124  CGPathRef pathRef = nullptr;
125  switch (clipSkRRect.getType()) {
126  case SkRRect::kEmpty_Type: {
127  break;
128  }
129  case SkRRect::kRect_Type: {
130  [self clipRect:clipSkRRect.rect() matrix:matrix];
131  return;
132  }
133  case SkRRect::kOval_Type:
134  case SkRRect::kSimple_Type: {
135  CGRect clipRect = [self getCGRectFromSkRect:clipSkRRect.rect()];
136  pathRef = CGPathCreateWithRoundedRect(clipRect, clipSkRRect.getSimpleRadii().x(),
137  clipSkRRect.getSimpleRadii().y(), nil);
138  break;
139  }
140  case SkRRect::kNinePatch_Type:
141  case SkRRect::kComplex_Type: {
142  CGMutablePathRef mutablePathRef = CGPathCreateMutable();
143  // Complex types, we manually add each corner.
144  SkRect clipSkRect = clipSkRRect.rect();
145  SkVector topLeftRadii = clipSkRRect.radii(SkRRect::kUpperLeft_Corner);
146  SkVector topRightRadii = clipSkRRect.radii(SkRRect::kUpperRight_Corner);
147  SkVector bottomRightRadii = clipSkRRect.radii(SkRRect::kLowerRight_Corner);
148  SkVector bottomLeftRadii = clipSkRRect.radii(SkRRect::kLowerLeft_Corner);
149 
150  // Start drawing RRect
151  // Move point to the top left corner adding the top left radii's x.
152  CGPathMoveToPoint(mutablePathRef, nil, clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop);
153  // Move point horizontally right to the top right corner and add the top right curve.
154  CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fRight - topRightRadii.x(),
155  clipSkRect.fTop);
156  CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fRight, clipSkRect.fTop,
157  clipSkRect.fRight, clipSkRect.fTop + topRightRadii.y(),
158  clipSkRect.fRight, clipSkRect.fTop + topRightRadii.y());
159  // Move point vertically down to the bottom right corner and add the bottom right curve.
160  CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fRight,
161  clipSkRect.fBottom - bottomRightRadii.y());
162  CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fRight, clipSkRect.fBottom,
163  clipSkRect.fRight - bottomRightRadii.x(), clipSkRect.fBottom,
164  clipSkRect.fRight - bottomRightRadii.x(), clipSkRect.fBottom);
165  // Move point horizontally left to the bottom left corner and add the bottom left curve.
166  CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fLeft + bottomLeftRadii.x(),
167  clipSkRect.fBottom);
168  CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fLeft, clipSkRect.fBottom,
169  clipSkRect.fLeft, clipSkRect.fBottom - bottomLeftRadii.y(),
170  clipSkRect.fLeft, clipSkRect.fBottom - bottomLeftRadii.y());
171  // Move point vertically up to the top left corner and add the top left curve.
172  CGPathAddLineToPoint(mutablePathRef, nil, clipSkRect.fLeft,
173  clipSkRect.fTop + topLeftRadii.y());
174  CGPathAddCurveToPoint(mutablePathRef, nil, clipSkRect.fLeft, clipSkRect.fTop,
175  clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop,
176  clipSkRect.fLeft + topLeftRadii.x(), clipSkRect.fTop);
177  CGPathCloseSubpath(mutablePathRef);
178 
179  pathRef = mutablePathRef;
180  break;
181  }
182  }
183  // TODO(cyanglaz): iOS does not seem to support hard edge on CAShapeLayer. It clearly stated that
184  // the CAShaperLayer will be drawn antialiased. Need to figure out a way to do the hard edge
185  // clipping on iOS.
186  paths_.push_back([self getTransformedPath:pathRef matrix:matrix]);
187 }

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