Rename PollType to PollStrategy (#3089)

This commit is contained in:
daxpedda 2023-09-08 18:39:23 +02:00 committed by GitHub
parent c00c1e9eb7
commit 0caba93b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 27 deletions

View file

@ -22,7 +22,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- Fix a bug where Wayland would be chosen on Linux even if the user specified `with_x11`. (#3058) - Fix a bug where Wayland would be chosen on Linux even if the user specified `with_x11`. (#3058)
- **Breaking:** Moved `ControlFlow` to `EventLoopWindowTarget::set_control_flow()` and `EventLoopWindowTarget::control_flow()`. - **Breaking:** Moved `ControlFlow` to `EventLoopWindowTarget::set_control_flow()` and `EventLoopWindowTarget::control_flow()`.
- **Breaking:** Moved `ControlFlow::Exit` to `EventLoopWindowTarget::exit()` and `EventLoopWindowTarget::exiting()` and removed `ControlFlow::ExitWithCode(_)` entirely. - **Breaking:** Moved `ControlFlow::Exit` to `EventLoopWindowTarget::exit()` and `EventLoopWindowTarget::exiting()` and removed `ControlFlow::ExitWithCode(_)` entirely.
- On Web, add `EventLoopWindowTargetExtWebSys` and `PollType`, which allows to set different strategies for `ControlFlow::Poll`. By default the Prioritized Task Scheduling API is used, but an option to use `Window.requestIdleCallback` is available as well. Both use `setTimeout()`, with a trick to circumvent throttling to 4ms, as a fallback. - On Web, add `EventLoopWindowTargetExtWebSys` and `PollStrategy`, which allows to set different strategies for `ControlFlow::Poll`. By default the Prioritized Task Scheduling API is used, but an option to use `Window.requestIdleCallback` is available as well. Both use `setTimeout()`, with a trick to circumvent throttling to 4ms, as a fallback.
# 0.29.1-beta # 0.29.1-beta

View file

@ -138,34 +138,34 @@ impl<T> EventLoopExtWebSys for EventLoop<T> {
pub trait EventLoopWindowTargetExtWebSys { pub trait EventLoopWindowTargetExtWebSys {
/// Sets the strategy for [`ControlFlow::Poll`]. /// Sets the strategy for [`ControlFlow::Poll`].
/// ///
/// See [`PollType`]. /// See [`PollStrategy`].
/// ///
/// [`ControlFlow::Poll`]: crate::event_loop::ControlFlow::Poll /// [`ControlFlow::Poll`]: crate::event_loop::ControlFlow::Poll
fn set_poll_type(&self, poll_type: PollType); fn set_poll_strategy(&self, strategy: PollStrategy);
/// Gets the strategy for [`ControlFlow::Poll`]. /// Gets the strategy for [`ControlFlow::Poll`].
/// ///
/// See [`PollType`]. /// See [`PollStrategy`].
/// ///
/// [`ControlFlow::Poll`]: crate::event_loop::ControlFlow::Poll /// [`ControlFlow::Poll`]: crate::event_loop::ControlFlow::Poll
fn poll_type(&self) -> PollType; fn poll_strategy(&self) -> PollStrategy;
} }
impl<T> EventLoopWindowTargetExtWebSys for EventLoopWindowTarget<T> { impl<T> EventLoopWindowTargetExtWebSys for EventLoopWindowTarget<T> {
#[inline] #[inline]
fn set_poll_type(&self, poll_type: PollType) { fn set_poll_strategy(&self, strategy: PollStrategy) {
self.p.set_poll_type(poll_type); self.p.set_poll_strategy(strategy);
} }
#[inline] #[inline]
fn poll_type(&self) -> PollType { fn poll_strategy(&self) -> PollStrategy {
self.p.poll_type() self.p.poll_strategy()
} }
} }
/// Strategy used for [`ControlFlow::Poll`](crate::event_loop::ControlFlow::Poll). /// Strategy used for [`ControlFlow::Poll`](crate::event_loop::ControlFlow::Poll).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum PollType { pub enum PollStrategy {
/// Uses [`Window.requestIdleCallback()`] to queue the next event loop. If not available /// Uses [`Window.requestIdleCallback()`] to queue the next event loop. If not available
/// this will fallback to [`setTimeout()`]. /// this will fallback to [`setTimeout()`].
/// ///

View file

@ -6,7 +6,7 @@ use crate::event::{
WindowEvent, WindowEvent,
}; };
use crate::event_loop::{ControlFlow, DeviceEvents}; use crate::event_loop::{ControlFlow, DeviceEvents};
use crate::platform::web::PollType; use crate::platform::web::PollStrategy;
use crate::platform_impl::platform::backend::EventListenerHandle; use crate::platform_impl::platform::backend::EventListenerHandle;
use crate::window::WindowId; use crate::window::WindowId;
@ -37,7 +37,7 @@ type OnEventHandle<T> = RefCell<Option<EventListenerHandle<dyn FnMut(T)>>>;
pub struct Execution { pub struct Execution {
control_flow: Cell<ControlFlow>, control_flow: Cell<ControlFlow>,
poll_type: Cell<PollType>, poll_strategy: Cell<PollStrategy>,
exit: Cell<bool>, exit: Cell<bool>,
runner: RefCell<RunnerEnum>, runner: RefCell<RunnerEnum>,
suspended: Cell<bool>, suspended: Cell<bool>,
@ -142,7 +142,7 @@ impl Shared {
Shared(Rc::new(Execution { Shared(Rc::new(Execution {
control_flow: Cell::new(ControlFlow::default()), control_flow: Cell::new(ControlFlow::default()),
poll_type: Cell::new(PollType::default()), poll_strategy: Cell::new(PollStrategy::default()),
exit: Cell::new(false), exit: Cell::new(false),
runner: RefCell::new(RunnerEnum::Pending), runner: RefCell::new(RunnerEnum::Pending),
suspended: Cell::new(false), suspended: Cell::new(false),
@ -638,7 +638,7 @@ impl Shared {
let cloned = self.clone(); let cloned = self.clone();
State::Poll { State::Poll {
request: backend::Schedule::new( request: backend::Schedule::new(
self.poll_type(), self.poll_strategy(),
self.window(), self.window(),
move || cloned.poll(), move || cloned.poll(),
), ),
@ -773,12 +773,12 @@ impl Shared {
self.0.exit.get() self.0.exit.get()
} }
pub(crate) fn set_poll_type(&self, poll_type: PollType) { pub(crate) fn set_poll_strategy(&self, strategy: PollStrategy) {
self.0.poll_type.set(poll_type) self.0.poll_strategy.set(strategy)
} }
pub(crate) fn poll_type(&self) -> PollType { pub(crate) fn poll_strategy(&self) -> PollStrategy {
self.0.poll_type.get() self.0.poll_strategy.get()
} }
} }

View file

@ -21,7 +21,7 @@ use crate::event::{
}; };
use crate::event_loop::{ControlFlow, DeviceEvents}; use crate::event_loop::{ControlFlow, DeviceEvents};
use crate::keyboard::ModifiersState; use crate::keyboard::ModifiersState;
use crate::platform::web::PollType; use crate::platform::web::PollStrategy;
use crate::window::{Theme, WindowId as RootWindowId}; use crate::window::{Theme, WindowId as RootWindowId};
#[derive(Default)] #[derive(Default)]
@ -696,11 +696,11 @@ impl<T> EventLoopWindowTarget<T> {
self.runner.exiting() self.runner.exiting()
} }
pub(crate) fn set_poll_type(&self, poll_type: PollType) { pub(crate) fn set_poll_strategy(&self, strategy: PollStrategy) {
self.runner.set_poll_type(poll_type) self.runner.set_poll_strategy(strategy)
} }
pub(crate) fn poll_type(&self) -> PollType { pub(crate) fn poll_strategy(&self) -> PollStrategy {
self.runner.poll_type() self.runner.poll_strategy()
} }
} }

View file

@ -6,7 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::{JsCast, JsValue}; use wasm_bindgen::{JsCast, JsValue};
use web_sys::{AbortController, AbortSignal, MessageChannel, MessagePort}; use web_sys::{AbortController, AbortSignal, MessageChannel, MessagePort};
use crate::platform::web::PollType; use crate::platform::web::PollStrategy;
#[derive(Debug)] #[derive(Debug)]
pub struct Schedule { pub struct Schedule {
@ -32,13 +32,13 @@ enum Inner {
} }
impl Schedule { impl Schedule {
pub fn new<F>(poll_type: PollType, window: &web_sys::Window, f: F) -> Schedule pub fn new<F>(strategy: PollStrategy, window: &web_sys::Window, f: F) -> Schedule
where where
F: 'static + FnMut(), F: 'static + FnMut(),
{ {
if poll_type == PollType::Scheduler && has_scheduler_support(window) { if strategy == PollStrategy::Scheduler && has_scheduler_support(window) {
Self::new_scheduler(window, f, None) Self::new_scheduler(window, f, None)
} else if poll_type == PollType::IdleCallback && has_idle_callback_support(window) { } else if strategy == PollStrategy::IdleCallback && has_idle_callback_support(window) {
Self::new_idle_callback(window.clone(), f) Self::new_idle_callback(window.clone(), f)
} else { } else {
Self::new_timeout(window.clone(), f, None) Self::new_timeout(window.clone(), f, None)