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

Experiment with AvaloniaRenderingFrameProvider #19

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

maxkatz6
Copy link
Contributor

Hello!
This library looks very interesting, thank you for your work :).

Noticed that Avalonia FrameProvider version used DispatcherTimer, which isn't necessary the best implementation conceptually for frames. As well as WPF version actually uses render timer callbacks.

Starting with 11.0 version we also have an equivalent APIs - TopLevel.RequestAnimationFrame(Action) where callback is synchronized with render timer and display framerate.

There is a big problem though. In WPF similar API is static and can be accessed from anywhere. In Avalonia, since we support multiple platforms, it gets more complicated, and this API is only accessible from the specific TopLevel. Where TopLevel can be an any Window, or a single root on mobile/browser. Obviously, it's quite hard to access from the framework initialization.

@maxkatz6
Copy link
Contributor Author

While I was writing this description, I found that all frame-specific methods in R3 also accept custom FrameProvider. Which makes this integration quite a bit easier. It's still hard to setup proper render timer globally though.

@neuecc
Copy link
Member

neuecc commented Jan 10, 2024

Thank you!
I had been looking for a method other than polling but couldn't find one, so I had no choice but to use DispatcherTimer.
I'm very happy that it's resolved.

I'm not particularly insistent on having the rendering as one frame, so if there's some kind of message loop, it would be great if I could hook into that.
Preferably without allocations each time.

@maxkatz6
Copy link
Contributor Author

so if there's some kind of message loop

That's Dispatcher basically. As it was.

@neuecc
Copy link
Member

neuecc commented Jan 11, 2024

Yes, it's the Dispatcher.
However, even in WPF, repeatedly using Dispatcher.BeginInvoke involves allocations, and I was looking for a lighter method.
And I came to the conclusion that the CompositionTarget event would be the lightest approach.

I will go ahead and merge this!
If you notice anything else, I would be happy to receive contributions!
By the way, among cross-platform UIs, I am most hopeful about Avalonia.

@neuecc neuecc merged commit 4161ca1 into Cysharp:main Jan 11, 2024
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

Successfully merging this pull request may close these issues.

2 participants