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

Support preferredFrameRateRange on macOS #349

Open
OskarGroth opened this issue Dec 2, 2024 · 2 comments
Open

Support preferredFrameRateRange on macOS #349

OskarGroth opened this issue Dec 2, 2024 · 2 comments

Comments

@OskarGroth
Copy link

OskarGroth commented Dec 2, 2024

Description

RiveView is using the deprecated CVDisplayLink to manage refresh rates on macOS. Because CVDisplayLink lacks support for a preferredFrameRate, Rive cannot set this on macOS and is stuck animating in constant 120hz, consuming 2-4x the amount of necessary resources.

You can also see that the parameter is simply not used:

preferredFramesPerSecond: Int? = nil,

CVDisplayLink is deprecated in macOS 15.0:
https://developer.apple.com/documentation/corevideo/cvdisplaylink-k0k

Provide a Repro

    func setupWindow() {
        var frame = NSScreen.main!.frame
        let window = WallpaperWindow(frame: frame)
        model = RiveViewModel(fileName: "follow_path_strength_demo", preferredFramesPerSecond: 30)
        let v = NSView()
        v.wantsLayer = true
        v.layer?.backgroundColor = .black
        let vv = model!.createRiveView()
        window.contentView = vv
        window.setFrame(frame, display: true)
        window.makeKeyAndOrderFront(nil)
        model?.autoPlay = true
        model?.play()
        self.window = window
    }

Source .riv/.rev file

Expected behavior

Rive should render according to the preferredFrameRate.

Screenshots

Device & Versions (please complete the following information)

  • Device: M1 MBP
  • macOS 15.1

Additional context

First, Rive should add support for CAMetalDisplayLink on Mac which is available since macOS 14.0:
https://developer.apple.com/documentation/quartzcore/cametaldisplaylink

You can hook it up straight to the CAMetalLayer used by the RiveView. You can still fallback to CVDisplayLink on older versions.

Second, Rive should add support for the new preferredFrameRateRange property:
https://developer.apple.com/documentation/quartzcore/cametaldisplaylink/4210308-preferredframeraterange

This would modernise Rive Metal API usage on macOS, and improve performance/decrease resource usage by up to 4x or more for majority of desktop use cases.

@dskuza
Copy link
Collaborator

dskuza commented Dec 3, 2024

Thanks for the write up! I hope to be able to look into this soon.

@dskuza
Copy link
Collaborator

dskuza commented Jan 17, 2025

@OskarGroth I've been looking into this - CAMetalDisplayLink is currently causing crashes on some iOS devices. In order to ensure consistency across all platforms, I'm looking into updating macOS to use CADisplayLink on >= macOS 14. This should still give you the APIs you're looking for in the mean time. Is that correct?

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

No branches or pull requests

2 participants