mirror of
https://github.com/servo/servo.git
synced 2025-09-27 23:30:08 +01:00
libservo: Move animation tracking from WindowMethods
to delegates (#36400)
This changes removes animation tracking from the `WindowMethods` trait and moves it to `ServoDelegate` and `WebViewDelegate`. - Animation changes per-`WebView` are now triggered in the compositor only when the value is updated there, rather than right after ticking animations. - Both `WebView` and `Servo` now expose an `animation()` method, so tracking animation state actually becomes unecessary in many cases, such as that of desktop servoshell, which can just read the value when the event loop spins. Testing: No tests necessary as the API layer is still untested. Later, tests will be added for the `WebView` API and this can be tested then. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
935db71183
commit
2fe57cc2a2
15 changed files with 153 additions and 125 deletions
|
@ -13,7 +13,7 @@ use std::{env, fs};
|
|||
|
||||
use euclid::Scale;
|
||||
use log::{info, trace, warn};
|
||||
use servo::compositing::windowing::{AnimationState, WindowMethods};
|
||||
use servo::compositing::windowing::WindowMethods;
|
||||
use servo::config::opts::Opts;
|
||||
use servo::config::prefs::Preferences;
|
||||
use servo::servo_config::pref;
|
||||
|
@ -146,9 +146,6 @@ impl App {
|
|||
fn hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> {
|
||||
self.0.hidpi_factor()
|
||||
}
|
||||
fn set_animation_state(&self, state: AnimationState) {
|
||||
self.0.set_animation_state(state);
|
||||
}
|
||||
}
|
||||
|
||||
let mut user_content_manager = UserContentManager::new();
|
||||
|
@ -183,8 +180,12 @@ impl App {
|
|||
self.state = AppState::Running(running_state);
|
||||
}
|
||||
|
||||
pub fn is_animating(&self) -> bool {
|
||||
self.windows.iter().any(|(_, window)| window.is_animating())
|
||||
pub(crate) fn animating(&self) -> bool {
|
||||
match self.state {
|
||||
AppState::Initializing => false,
|
||||
AppState::Running(ref running_app_state) => running_app_state.servo().animating(),
|
||||
AppState::ShuttingDown => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle events with winit contexts
|
||||
|
@ -401,10 +402,8 @@ impl ApplicationHandler<WakerEvent> for App {
|
|||
window.handle_winit_event(state.clone(), event);
|
||||
}
|
||||
|
||||
let animating = self.is_animating();
|
||||
|
||||
// Block until the window gets an event
|
||||
if !animating || self.suspended.get() {
|
||||
if !self.animating() || self.suspended.get() {
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
} else {
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
|
@ -427,7 +426,7 @@ impl ApplicationHandler<WakerEvent> for App {
|
|||
);
|
||||
self.t = now;
|
||||
|
||||
if !matches!(self.state, AppState::Running(_)) {
|
||||
if !matches!(self.state, AppState::Running(..)) {
|
||||
return;
|
||||
};
|
||||
let Some(window) = self.windows.values().next() else {
|
||||
|
@ -435,10 +434,8 @@ impl ApplicationHandler<WakerEvent> for App {
|
|||
};
|
||||
let window = window.clone();
|
||||
|
||||
let animating = self.is_animating();
|
||||
|
||||
// Block until the window gets an event
|
||||
if !animating || self.suspended.get() {
|
||||
if !self.animating() || self.suspended.get() {
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
} else {
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue