Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | Properties | List of all members
FlutterClippingMaskView Class Reference

#include <FlutterPlatformViews_Internal.h>

Inheritance diagram for FlutterClippingMaskView:

Instance Methods

(instancetype) - initWithFrame:screenScale:
 
(void) - reset
 
(void) - clipRect:matrix:
 
(void) - clipRRect:matrix:
 
(void) - clipPath:matrix:
 
(instancetype) - initWithFrame: [implementation]
 
(BOOL- pointInside:withEvent: [implementation]
 
(void) - drawRect: [implementation]
 
(fml::CFRef< CGPathRef >) - getTransformedPath:matrix: [implementation]
 

Properties

CATransform3D reverseScreenScale [implementation]
 

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 256 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}
@ kClose_Verb
Definition SkPath.h:1463
@ kMove_Verb
Definition SkPath.h:1458
@ kConic_Verb
Definition SkPath.h:1461
@ kDone_Verb
Definition SkPath.h:1464
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459
if(end==-1)
#define FML_DCHECK(condition)
Definition logging.h:103
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
CATransform3D GetCATransform3DFromSkMatrix(const SkMatrix &matrix)
static constexpr SkPoint Make(float x, float y)

◆ clipRect:matrix:

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

Definition at line 256 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}
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
CGRect GetCGRectFromSkRect(const SkRect &clipSkRect)

◆ clipRRect:matrix:

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

Definition at line 256 of file FlutterPlatformViews_Internal.mm.

316 :(const SkRRect&)clipSkRRect matrix:(const SkMatrix&)matrix {
317 CGPathRef pathRef = nullptr;
318 switch (clipSkRRect.getType()) {
320 break;
321 }
322 case SkRRect::kRect_Type: {
323 [self clipRect:clipSkRRect.rect() matrix:matrix];
324 return;
325 }
328 CGRect clipRect = flutter::GetCGRectFromSkRect(clipSkRRect.rect());
329 pathRef = CGPathCreateWithRoundedRect(clipRect, clipSkRRect.getSimpleRadii().x(),
330 clipSkRRect.getSimpleRadii().y(), nil);
331 break;
332 }
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}
SkVector getSimpleRadii() const
Definition SkRRect.h:111
Type getType() const
Definition SkRRect.h:76
const SkRect & rect() const
Definition SkRRect.h:264
SkVector radii(Corner corner) const
Definition SkRRect.h:271
@ kOval_Type
non-zero width and height filled with radii
Definition SkRRect.h:69
@ kSimple_Type
non-zero width and height with equal radii
Definition SkRRect.h:70
@ kEmpty_Type
zero width or height
Definition SkRRect.h:67
@ kNinePatch_Type
non-zero width and height with axis-aligned radii
Definition SkRRect.h:71
@ kRect_Type
non-zero width and height, and zeroed radii
Definition SkRRect.h:68
@ kComplex_Type
non-zero width and height with arbitrary radii
Definition SkRRect.h:72
@ kUpperLeft_Corner
index of top-left corner radii
Definition SkRRect.h:252
@ kLowerRight_Corner
index of bottom-right corner radii
Definition SkRRect.h:254
@ kUpperRight_Corner
index of top-right corner radii
Definition SkRRect.h:253
@ kLowerLeft_Corner
index of bottom-left corner radii
Definition SkRRect.h:255
constexpr float y() const
constexpr float x() const
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15

◆ drawRect:

- (void) drawRect: (CGRect)  rect
implementation

Definition at line 256 of file FlutterPlatformViews_Internal.mm.

292 :(CGRect)rect {
293 CGContextRef context = UIGraphicsGetCurrentContext();
294 CGContextSaveGState(context);
295
296 // For mask view, only the alpha channel is used.
297 CGContextSetAlpha(context, 1);
298
299 for (size_t i = 0; i < paths_.size(); i++) {
300 CGContextAddPath(context, paths_.at(i));
301 CGContextClip(context);
302 }
303 CGContextFillRect(context, rect);
304 CGContextRestoreGState(context);
305}

◆ getTransformedPath:matrix:

- (CFRef< CGPathRef >) FlutterClippingMaskView: (CGPathRef)  path
matrix: (CATransform3D)  matrix 
implementation

Definition at line 256 of file FlutterPlatformViews_Internal.mm.

450 :(CGPathRef)path matrix:(CATransform3D)matrix {
451 CGAffineTransform affine =
452 CGAffineTransformMake(matrix.m11, matrix.m12, matrix.m21, matrix.m22, matrix.m41, matrix.m42);
453 CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(path, &affine);
454 CGPathRelease(path);
455 return fml::CFRef<CGPathRef>(transformedPath);
456}

◆ initWithFrame:

- (instancetype) initWithFrame: (CGRect)  frame
implementation

Definition at line 256 of file FlutterPlatformViews_Internal.mm.

266 :(CGRect)frame {
267 return [self initWithFrame:frame screenScale:[UIScreen mainScreen].scale];
268}
double frame
Definition examples.cpp:31

◆ initWithFrame:screenScale:

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

Definition at line 256 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}
instancetype initWithFrame

◆ pointInside:withEvent:

- (BOOL) pointInside: (CGPoint)  point
withEvent: (UIEvent*)  event 
implementation

Definition at line 256 of file FlutterPlatformViews_Internal.mm.

288 :(CGPoint)point withEvent:(UIEvent*)event {
289 return NO;
290}
FlKeyEvent * event

◆ reset

- (void) reset

Definition at line 256 of file FlutterPlatformViews_Internal.mm.

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

Property Documentation

◆ reverseScreenScale

- (CATransform3D) reverseScreenScale
readwritenonatomicassignimplementation

Provided by category FlutterClippingMaskView().

Definition at line 256 of file FlutterPlatformViews_Internal.mm.


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