Skip to content

Add sleep timer option for the headless platform - #21423

Merged
maxkatz6 merged 5 commits into
masterfrom
add-sleep-timer-option-for-the-headless
Jun 9, 2026
Merged

maxkatz6 merged 5 commits into
masterfrom
add-sleep-timer-option-for-the-headless

Conversation

@maxkatz6

@maxkatz6 maxkatz6 commented May 23, 2026 •

Copy link
Copy Markdown
Member

What does the pull request do?

Allows to run headless rendering more efficiently, although less controlled.

New APIs (naming copied from pre-existing linux options):

public class AvaloniaHeadlessPlatformOptions
{
+        public int Fps { get; set; } = 60;
+        public bool ShouldRenderOnUIThread { get; set; } = true;
}

@maxkatz6
maxkatz6 requested a review from kekekeks May 23, 2026 00:27
@maxkatz6 maxkatz6 added enhancement area-headless backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels May 23, 2026
{
for (var c = 0; c < count; c++)
s_renderTimer?.ForceTick();
if (s_renderTimer is not HeadlessRenderTimer timer)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sleep loop timer we can probably spin a dispatcher frame until the next tick? I. e. call Compositor.RequestCommitAsync and stop dispatcher frame once it completes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works

@maxkatz6
maxkatz6 requested a review from kekekeks June 8, 2026 11:49
@maxkatz6
maxkatz6 added this pull request to the merge queue Jun 9, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066181-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Merged via the queue into master with commit affd240 Jun 9, 2026
10 checks passed
@maxkatz6
maxkatz6 deleted the add-sleep-timer-option-for-the-headless branch June 9, 2026 05:29
MrJul pushed a commit to MrJul/Avalonia that referenced this pull request Jun 23, 2026
* Add ShouldRenderOnUIThread//Fps options to the AvaloniaHeadlessPlatformOptions, allowing SleepLoopRenderTimer to be enabled

* Don't throw from ForceRenderTimerTick

* Run DispatcherFrame on RequestCommitAsync, when HeadlessRenderTimer is not available

* This method apparently was public
@MrJul MrJul added backported-12.0.x and removed backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants