Fix memory issue with ClipPath

Fix memory issue with ClipPath.
This commit is contained in:
Horcrux
2016-11-11 13:25:16 +08:00
parent aae482236d
commit 0434cddc8b
15 changed files with 77 additions and 80 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
- (void)saveDefinition
{
[[self getSvgView] defineClipPath:self clipPathRef:self.name];
[[self getSvgView] defineClipPath:self clipPathName:self.name];
}
+7 -2
View File
@@ -46,7 +46,7 @@
- (CGPathRef)getPath:(CGContextRef)context
{
CGMutablePathRef path = CGPathCreateMutable();
CGMutablePathRef __block path = CGPathCreateMutable();
[self traverseSubviews:^(RNSVGNode *node) {
CGAffineTransform transform = node.matrix;
CGPathAddPath(path, &transform, [node getPath:context]);
@@ -60,6 +60,11 @@
{
CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, transform);
CGPathRef clip = [self getComputedClipPath];
if (clip && !CGPathContainsPoint(clip, nil, point, NO)) {
return nil;
}
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
if ([node isKindOfClass:[RNSVGNode class]]) {
if (event) {
@@ -87,7 +92,7 @@
{
if (self.name) {
RNSVGSvgView* svg = [self getSvgView];
[svg defineTemplate:self templateRef:self.name];
[svg defineTemplate:self templateName:self.name];
}
[self traverseSubviews:^(RNSVGNode *node) {
+2 -2
View File
@@ -94,7 +94,7 @@
{
CGRect rect = [self getRect:context];
// add hit area
self.hitArea = CFAutorelease(CGPathCreateWithRect(rect, nil));
self.hitArea = CGPathCreateWithRect(rect, nil);
[self clip:context];
CGContextSaveGState(context);
@@ -152,7 +152,7 @@
- (CGPathRef)getPath:(CGContextRef)context
{
return CGPathCreateWithRect([self getRect:context], nil);
return (CGPathRef)CFAutorelease(CGPathCreateWithRect([self getRect:context], nil));
}
@end
+1 -1
View File
@@ -32,7 +32,7 @@
converter.colors = self.gradient;
converter.points = @[self.x1, self.y1, self.x2, self.y2];
converter.type = kRNSVGLinearGradient;
[[self getSvgView] defineBrushConverter:converter brushConverterRef:self.name];
[[self getSvgView] defineBrushConverter:converter brushConverterName:self.name];
}
@end
+5 -5
View File
@@ -40,17 +40,17 @@
if ([self getSvgView].responsible) {
// Add path to hitArea
CGMutablePathRef hitArea = CGPathCreateMutableCopy(path);
CGMutablePathRef hitAreaPath = CGPathCreateMutableCopy(path);
if (self.stroke) {
// Add stroke to hitArea
CGPathRef strokePath = CGPathCreateCopyByStrokingPath(hitArea, nil, self.strokeWidth, self.strokeLinecap, self.strokeLinejoin, self.strokeMiterlimit);
CGPathAddPath(hitArea, nil, strokePath);
CGPathRef strokePath = CGPathCreateCopyByStrokingPath(hitAreaPath, nil, self.strokeWidth, self.strokeLinecap, self.strokeLinejoin, self.strokeMiterlimit);
CGPathAddPath(hitAreaPath, nil, strokePath);
CGPathRelease(strokePath);
}
CGAffineTransform transform = self.matrix;
self.hitArea = CFAutorelease(CGPathCreateCopyByTransformingPath(hitArea, &transform));
CGPathRelease(hitArea);
self.hitArea = CGPathCreateCopyByTransformingPath(hitAreaPath, &transform);
CGPathRelease(hitAreaPath);
}
if (self.opacity == 0) {
+1 -1
View File
@@ -30,7 +30,7 @@
converter.colors = self.gradient;
converter.points = @[self.fx, self.fy, self.rx, self.ry, self.cx, self.cy];
converter.type = kRNSVGRadialGradient;
[[self getSvgView] defineBrushConverter:converter brushConverterRef:self.name];
[[self getSvgView] defineBrushConverter:converter brushConverterName:self.name];
}
@end
+6 -6
View File
@@ -19,12 +19,12 @@
/**
* define <ClipPath></ClipPath> content as clipPath template.
*/
- (void)defineClipPath:(__kindof RNSVGNode *)clipPath clipPathRef:(NSString *)clipPathRef;
- (RNSVGNode *)getDefinedClipPath:(NSString *)clipPathRef;
- (void)defineTemplate:(__kindof RNSVGNode *)template templateRef:(NSString *)templateRef;
- (RNSVGNode *)getDefinedTemplate:(NSString *)tempalteRef;
- (void)defineBrushConverter:(RNSVGBrushConverter *)brushConverter brushConverterRef:(NSString *)brushConverterRef;
- (RNSVGBrushConverter *)getDefinedBrushConverter:(NSString *)brushConverterRef;
- (void)defineClipPath:(__kindof RNSVGNode *)clipPath clipPathName:(NSString *)clipPathName;
- (RNSVGNode *)getDefinedClipPath:(NSString *)clipPathName;
- (void)defineTemplate:(__kindof RNSVGNode *)template templateName:(NSString *)templateName;
- (RNSVGNode *)getDefinedTemplate:(NSString *)templateName;
- (void)defineBrushConverter:(RNSVGBrushConverter *)brushConverter brushConverterName:(NSString *)brushConverterName;
- (RNSVGBrushConverter *)getDefinedBrushConverter:(NSString *)brushConverterName;
- (NSString *)getDataURL;
@end
+12 -12
View File
@@ -83,44 +83,44 @@
self.backgroundColor = inheritedBackgroundColor;
}
- (void)defineClipPath:(__kindof RNSVGNode *)clipPath clipPathRef:(NSString *)clipPathRef
- (void)defineClipPath:(__kindof RNSVGNode *)clipPath clipPathName:(NSString *)clipPathName
{
if (!clipPaths) {
clipPaths = [[NSMutableDictionary alloc] init];
}
[clipPaths setObject:clipPath forKey:clipPathRef];
[clipPaths setObject:clipPath forKey:clipPathName];
}
- (RNSVGNode *)getDefinedClipPath:(NSString *)clipPathRef
- (RNSVGNode *)getDefinedClipPath:(NSString *)clipPathName
{
return clipPaths ? [clipPaths objectForKey:clipPathRef] : nil;
return clipPaths ? [clipPaths objectForKey:clipPathName] : nil;
}
- (void)defineTemplate:(RNSVGNode *)template templateRef:(NSString *)templateRef
- (void)defineTemplate:(RNSVGNode *)template templateName:(NSString *)templateName
{
if (!templates) {
templates = [[NSMutableDictionary alloc] init];
}
[templates setObject:template forKey:templateRef];
[templates setObject:template forKey:templateName];
}
- (RNSVGNode *)getDefinedTemplate:(NSString *)tempalteRef
- (RNSVGNode *)getDefinedTemplate:(NSString *)templateName
{
return templates ? [templates objectForKey:tempalteRef] : nil;
return templates ? [templates objectForKey:templateName] : nil;
}
- (void)defineBrushConverter:(RNSVGBrushConverter *)brushConverter brushConverterRef:(NSString *)brushConverterRef
- (void)defineBrushConverter:(RNSVGBrushConverter *)brushConverter brushConverterName:(NSString *)brushConverterName
{
if (!brushConverters) {
brushConverters = [[NSMutableDictionary alloc] init];
}
[brushConverters setObject:brushConverter forKey:brushConverterRef];
[brushConverters setObject:brushConverter forKey:brushConverterName];
}
- (RNSVGBrushConverter *)getDefinedBrushConverter:(NSString *)brushConverterRef
- (RNSVGBrushConverter *)getDefinedBrushConverter:(NSString *)brushConverterName
{
return brushConverters ? [brushConverters objectForKey:brushConverterRef] : nil;
return brushConverters ? [brushConverters objectForKey:brushConverterName] : nil;
}
@end