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

Rendering with Core Animation #3131

Open
jjatie opened this issue Dec 24, 2017 · 6 comments
Open

Rendering with Core Animation #3131

jjatie opened this issue Dec 24, 2017 · 6 comments

Comments

@jjatie
Copy link
Collaborator

jjatie commented Dec 24, 2017

@petester42 @liuxuan30 @danielgindi

Continuing on #29, why have we not considered using Core Animation instead of Core Graphics? Core Animation is what virtually all of iOS's UI is using and was recently rewritten with a Metal backing (iOS 9/macOS 10.11 I believe).

In my experience it has been hard to match the performance of Core Animation with Core Graphics code, which is probably why Core Graphics hasn't been mentioned at WWDC in many years. Given CA heavily relies on the GPU instead of the CPU AND we are not taxing the GPU, any CPU bottlenecks should be gone, performance should improve, and energy consumption should be reduced.

I understand this would be a very big undertaking (one I'd be happy to participate in), but it seems like it would be able to provide significant benefits for consumers. Given Apple's focus on Core Animation, it is likely that it will allow us keep up with modern best practices more easily.

@liuxuan30
Copy link
Member

liuxuan30 commented Dec 25, 2017

I'm curious as well.
I guess at the first beginning, the library is just about Charts, and purely designed on CoreGraphics, not want to involve layer. And when animation comes in, it uses display link.

But can we use CA without layer? I'm not sure how we can live with layer, like for bar chart. I used to write a bar chart view, while each bar is a layer/view, the performance is not ideal than this library though (maybe because I just get started at that time). But it's great we can review back.

@jjatie
Copy link
Collaborator Author

jjatie commented Dec 25, 2017

CA is all about layers, so there's no getting around that. I think it's likely that it was because you were just getting started in CA. I've seen games written entirely in UIKit (which is all backed by CA) which run with great performance.

(I'm guessing from experience) I think that for the simple rendering there will be slightly more work for us, but for the more complex stuff there will be less work.

@iMacHumphries
Copy link

+1 this would help with #2402

@iMacHumphries
Copy link

UIView already contains a CALayer which you can override, and every chart extends from the ChartViewBase so you could have something like this:

// MARK: - Chart Layer Provider
extension ChartViewBase: ChartLayerProvider {
    override open class var layerClass: Swift.AnyClass {
        return CAShapeLayer.self
    }
    
    public var chartLayer: CAShapeLayer {
        return layer as! CAShapeLayer
    }
}

And use this "ChartLayerProvider" to pass the layer to the Renderers. Looks like this will require a lot of refactoring 🙁 But I was able to easily get the animation working with a CALayer for Cubic Bezier path! (Didn't get it to use CALayer for the fill though, so ignore that haha... Also the animation is in the draw call so that's why it is jumpy before it starts)

animation

@Ornolfr
Copy link

Ornolfr commented Aug 16, 2019

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants