Improve path caching on ios

This commit is contained in:
Mikael Sand
2018-02-22 03:48:39 +02:00
parent 149f460108
commit db8f1da46b
3 changed files with 29 additions and 11 deletions
+1
View File
@@ -33,6 +33,7 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
@property (nonatomic, assign) BOOL responsible;
@property (nonatomic, assign) CGAffineTransform matrix;
@property (nonatomic, assign) BOOL active;
@property (nonatomic, assign) CGPathRef path;
- (void)invalidate;
+7 -3
View File
@@ -54,6 +54,10 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
{
id<RNSVGContainer> container = (id<RNSVGContainer>)self.superview;
[container invalidate];
if (_path) {
CGPathRelease(_path);
_path = nil;
}
}
- (RNSVGGroup *)getTextRoot
@@ -130,8 +134,9 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
if (CGAffineTransformEqualToTransform(matrix, _matrix)) {
return;
}
[self invalidate];
_matrix = matrix;
id<RNSVGContainer> container = (id<RNSVGContainer>)self.superview;
[container invalidate];
}
- (void)setClipPath:(NSString *)clipPath
@@ -171,8 +176,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
- (CGPathRef)getClipPath:(CGContextRef)context
{
if (self.clipPath) {
CGPathRelease(_cachedClipPath);
if (self.clipPath && !_cachedClipPath) {
_cachedClipPath = CGPathRetain([[[self getSvgView] getDefinedClipPath:self.clipPath] getPath:context]);
}
+21 -8
View File
@@ -14,6 +14,16 @@
NSArray<NSString *> *_lastMergedList;
NSArray<NSString *> *_attributeList;
CGPathRef _hitArea;
CGPathRef _path;
}
- (void)invalidate
{
[super invalidate];
if (_path) {
CGPathRelease(_path);
_path = nil;
}
}
- (id)init
@@ -151,6 +161,7 @@
- (void)dealloc
{
CGPathRelease(_path);
CGPathRelease(_hitArea);
if (_strokeDasharrayData.array) {
free(_strokeDasharrayData.array);
@@ -178,13 +189,15 @@
return;
}
CGPathRef path = [self getPath:context];
[self setHitArea:path];
if (self.opacity == 0) {
return;
}
if (!_path) {
_path = [self getPath:context];
[self setHitArea:_path];
}
CGPathDrawingMode mode = kCGPathStroke;
BOOL fillColor = NO;
[self clip:context];
@@ -198,7 +211,7 @@
mode = evenodd ? kCGPathEOFill : kCGPathFill;
} else {
CGContextSaveGState(context);
CGContextAddPath(context, path);
CGContextAddPath(context, _path);
CGContextClip(context);
[self.fill paint:context
opacity:self.fillOpacity
@@ -224,7 +237,7 @@
}
if (!fillColor) {
CGContextAddPath(context, path);
CGContextAddPath(context, _path);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
}
@@ -236,12 +249,12 @@
} else if (!strokeColor) {
// draw fill
if (fillColor) {
CGContextAddPath(context, path);
CGContextAddPath(context, _path);
CGContextDrawPath(context, mode);
}
// draw stroke
CGContextAddPath(context, path);
CGContextAddPath(context, _path);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
@@ -253,7 +266,7 @@
}
}
CGContextAddPath(context, path);
CGContextAddPath(context, _path);
CGContextDrawPath(context, mode);
}