flatland_frame_scheduling_lib/
lib.rsmod throughput_scheduler;
pub use throughput_scheduler::ThroughputScheduler;
use async_trait::async_trait;
use std::cell::RefCell;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll, Waker};
use {fidl_fuchsia_scenic_scheduling as frame_scheduling, fidl_fuchsia_ui_composition as flatland};
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct PresentationInfo {
pub latch_point: zx::MonotonicInstant,
pub presentation_time: zx::MonotonicInstant,
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct PresentedInfo {
pub present_received_time: zx::MonotonicInstant,
pub actual_latch_point: zx::MonotonicInstant,
}
impl From<frame_scheduling::PresentReceivedInfo> for PresentedInfo {
fn from(item: frame_scheduling::PresentReceivedInfo) -> PresentedInfo {
PresentedInfo {
present_received_time: zx::MonotonicInstant::from_nanos(
item.present_received_time.unwrap(),
),
actual_latch_point: zx::MonotonicInstant::from_nanos(item.latched_time.unwrap()),
}
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct PresentParameters {
pub expected_latch_point: zx::MonotonicInstant,
pub expected_presentation_time: zx::MonotonicInstant,
pub requested_presentation_time: zx::MonotonicInstant,
pub unsquashable: bool,
}
impl From<PresentParameters> for flatland::PresentArgs {
fn from(item: PresentParameters) -> flatland::PresentArgs {
flatland::PresentArgs {
requested_presentation_time: Some(item.requested_presentation_time.into_nanos()),
unsquashable: Some(item.unsquashable),
..Default::default()
}
}
}
#[async_trait(?Send)]
pub trait SchedulingLib {
fn request_present(&self) {}
fn on_frame_presented(
&self,
_actual_presentation_time: zx::MonotonicInstant,
_presented_infos: Vec<PresentedInfo>,
) {
}
fn on_next_frame_begin(
&self,
additional_present_credits: u32,
future_presentation_infos: Vec<PresentationInfo>,
);
async fn wait_to_update(&self) -> PresentParameters;
}
struct SchedulingFuture<'a> {
sched: &'a RefCell<dyn SchedulingFutureState>,
}
impl Future for SchedulingFuture<'_> {
type Output = ();
fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<()> {
let mut sched = self.sched.borrow_mut();
if sched.ready_to_wake_up() {
Poll::Ready(())
} else {
sched.set_waker(ctx.waker().clone());
Poll::Pending
}
}
}
trait SchedulingFutureState {
fn ready_to_wake_up(&self) -> bool;
fn set_waker(&mut self, waker: Waker);
fn get_waker(&self) -> &Option<Waker>;
fn maybe_wakeup(&self) {
if let Some(waker) = &self.get_waker() {
if self.ready_to_wake_up() {
waker.wake_by_ref();
}
}
}
}