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

[web backend] Make sure we only request animation once per frame #1790

Merged
merged 1 commit into from
May 19, 2021
Merged
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
14 changes: 10 additions & 4 deletions druid-shell/src/platform/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct WindowState {
invalid: RefCell<Region>,
click_counter: ClickCounter,
active_text_input: Cell<Option<TextFieldToken>>,
rendering_soon: Cell<bool>,
}

// TODO: support custom cursors
Expand Down Expand Up @@ -444,6 +445,7 @@ impl WindowBuilder {
invalid: RefCell::new(Region::EMPTY),
click_counter: ClickCounter::default(),
active_text_input: Cell::new(None),
rendering_soon: Cell::new(false),
});

setup_web_callbacks(&window);
Expand Down Expand Up @@ -632,10 +634,14 @@ impl WindowHandle {
fn render_soon(&self) {
if let Some(s) = self.0.upgrade() {
let state = s.clone();
s.request_animation_frame(move || {
state.render();
})
.expect("Failed to request animation frame");
if !state.rendering_soon.get() {
state.rendering_soon.set(true);
s.request_animation_frame(move || {
state.rendering_soon.set(false);
state.render();
})
.expect("Failed to request animation frame");
}
}
}

Expand Down