Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace top renderers with top layers #551

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Macaw.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@
58944BDA20AC8A9A00657640 /* logo_base64.txt in Resources */ = {isa = PBXBuildFile; fileRef = 57B7A4E01EE70DA5009D78D7 /* logo_base64.txt */; };
58944BDB20AC8A9A00657640 /* clip.svg in Resources */ = {isa = PBXBuildFile; fileRef = C43B064C1F9738EF00787A35 /* clip.svg */; };
58B0523920E10E7100D45008 /* ColorMatrix.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5874CCB620DA8A860090DBD5 /* ColorMatrix.swift */; };
5B0AEEEC223FAE0E00318A39 /* WeakThing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B0AEEEB223FAE0E00318A39 /* WeakThing.swift */; };
5B0AEEEF223FC17800318A39 /* WeakThing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B0AEEEB223FAE0E00318A39 /* WeakThing.swift */; };
5B1A8C7620A15F7300E5FFAE /* SVGNodeLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B1A8C7520A15F7300E5FFAE /* SVGNodeLayout.swift */; };
5B1A8C7720A15F7300E5FFAE /* SVGNodeLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B1A8C7520A15F7300E5FFAE /* SVGNodeLayout.swift */; };
5B1AE23220B6A669007EECCB /* text-align-01-b-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = 5B1AE18420B6A669007EECCB /* text-align-01-b-manual.svg */; };
Expand Down Expand Up @@ -674,7 +672,6 @@
585288F320AD96A2003E51D1 /* ContentLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentLayout.swift; sourceTree = "<group>"; };
5852891520B29D67003E51D1 /* TransformedLocus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransformedLocus.swift; sourceTree = "<group>"; };
5874CCB620DA8A860090DBD5 /* ColorMatrix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorMatrix.swift; sourceTree = "<group>"; };
5B0AEEEB223FAE0E00318A39 /* WeakThing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeakThing.swift; sourceTree = "<group>"; };
5B1A8C7520A15F7300E5FFAE /* SVGNodeLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SVGNodeLayout.swift; sourceTree = "<group>"; };
5B1AE18420B6A669007EECCB /* text-align-01-b-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "text-align-01-b-manual.svg"; sourceTree = "<group>"; };
5B1AE18520B6A669007EECCB /* paths-data-06-t-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "paths-data-06-t-manual.reference"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1006,7 +1003,6 @@
57900FF81EA0DEBF00809FFB /* UIImage2Image.swift */,
3081E77C20DB58B100640F96 /* DescriptionExtensions.swift */,
3002331B20CC0BDD00EFD92D /* BoundsUtils.swift */,
5B0AEEEB223FAE0E00318A39 /* WeakThing.swift */,
);
path = utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -2077,7 +2073,6 @@
57614B3A1F83D15600875933 /* AnimationProducer.swift in Sources */,
585288F620AD96A2003E51D1 /* ContentLayout.swift in Sources */,
57614B3C1F83D15600875933 /* ShapeInterpolation.swift in Sources */,
5B0AEEEF223FC17800318A39 /* WeakThing.swift in Sources */,
57614B3D1F83D15600875933 /* Graphics_iOS.swift in Sources */,
57614BDB1F8739EE00875933 /* MacawView+PDF.swift in Sources */,
57614B411F83D15600875933 /* Text.swift in Sources */,
Expand Down Expand Up @@ -2218,7 +2213,6 @@
57A27BD51E44C5840057BD3A /* ShapeInterpolation.swift in Sources */,
A718CD471F45C28700966E06 /* Graphics_iOS.swift in Sources */,
57614BDA1F8739EE00875933 /* MacawView+PDF.swift in Sources */,
5B0AEEEC223FAE0E00318A39 /* WeakThing.swift in Sources */,
57E5E1A21E3B393900D1CB28 /* Text.swift in Sources */,
57F1087C1F53CA7E00DC365B /* MDisplayLink_iOS.swift in Sources */,
57E5E1A61E3B393900D1CB28 /* RenderContext.swift in Sources */,
Expand Down
22 changes: 12 additions & 10 deletions Source/animation/AnimationProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnimationProducer {
let animation: ContentsAnimation
let layer: CALayer
weak var cache: AnimationCache?
let topRenderers: [WeakThing<NodeRenderer>]
let topLayers: [ShapeLayer]
let startDate: Date
let finishDate: Date
let completion: (() -> Void)?
Expand Down Expand Up @@ -272,18 +272,20 @@ class AnimationProducer {
}
let bottomRenderer = animationRenderers.min { $0.zPosition < $1.zPosition }

var topRenderers = [WeakThing<NodeRenderer>]()
var topLayers = [ShapeLayer]()
if let bottomRenderer = bottomRenderer, let allRenderers = allRenderers {
for renderer in allRenderers where !(renderer is GroupRenderer) && renderer.zPosition > bottomRenderer.zPosition {
topRenderers.append(WeakThing(renderer))
if let layer = cache?.layerForNodeRenderer(renderer, context, animation: contentsAnimation) {
topLayers.append(layer)
}
}
}

let animationDesc = ContentAnimationDesc(
animation: contentsAnimation,
layer: layer,
cache: cache,
topRenderers: topRenderers,
topLayers: topLayers,
startDate: Date(),
finishDate: Date(timeInterval: contentsAnimation.duration, since: startDate),
completion: completion
Expand Down Expand Up @@ -340,6 +342,9 @@ class AnimationProducer {
contentsAnimations.remove(at: count - 1 - index)
animationDesc.cache?.freeLayer(renderer)
animationDesc.completion?()
for layer in animationDesc.topLayers {
animationDesc.cache?.freeLayer(layer: layer)
}
continue
}

Expand All @@ -362,12 +367,9 @@ class AnimationProducer {
}
}

for weakRenderer in animationDesc.topRenderers {
if let renderer = weakRenderer.value {
let layer = animationDesc.cache?.layerForNodeRenderer(renderer, context, animation: animationDesc.animation)
layer?.setNeedsDisplay()
layer?.displayIfNeeded()
}
for layer in animationDesc.topLayers {
layer.setNeedsDisplay()
layer.displayIfNeeded()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ class AnimationCache {
layer.removeFromSuperlayer()
}

func freeLayer(layer: ShapeLayer) {
var cached: CachedLayer?
var renderer: NodeRenderer?
layerCache.forEach { key, value in
if value.layer === layer {
cached = value
renderer = key
}
}
guard let cachedLayer = cached, let nodeRenderer = renderer else {
return
}

cachedLayer.linksCounter -= 1

if cachedLayer.linksCounter != 0 {
return
}

let layer = cachedLayer.layer
layerCache.removeValue(forKey: nodeRenderer)
sceneLayer?.setNeedsDisplay()
layer.removeFromSuperlayer()
}

func freeLayer(_ renderer: NodeRenderer) {
guard let cachedLayer = layerCache[renderer] else {
return
Expand Down
8 changes: 0 additions & 8 deletions Source/utils/WeakThing.swift

This file was deleted.