From 6d14f5ca15d9182f09416fa74f48f5526095c6cc Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 1 Jul 2024 10:50:31 +0200 Subject: [PATCH] Fix unused type warnings in i-slint-backend-linukxms build with default features When no features are enabled, the TimerBasedAnimationDriver would be unused. --- internal/backends/linuxkms/display.rs | 112 +++++++++--------- .../linuxkms/display/swdisplay/linuxfb.rs | 4 +- .../linuxkms/display/vulkandisplay.rs | 2 +- 3 files changed, 61 insertions(+), 57 deletions(-) diff --git a/internal/backends/linuxkms/display.rs b/internal/backends/linuxkms/display.rs index 403e01cac..136cb2562 100644 --- a/internal/backends/linuxkms/display.rs +++ b/internal/backends/linuxkms/display.rs @@ -1,9 +1,6 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 -use std::cell::Cell; -use std::rc::{Rc, Weak}; - use i_slint_core::api::PhysicalSize; use i_slint_core::platform::PlatformError; @@ -101,58 +98,65 @@ impl RenderingRotation { } } -struct TimerBasedAnimationDriver { - timer: i_slint_core::timers::Timer, - next_animation_frame_callback: Cell>>, -} +#[cfg(any(feature = "renderer-skia-vulkan", feature = "renderer-software"))] +pub(crate) mod timeranimations { + use i_slint_core::platform::PlatformError; + use std::cell::Cell; + use std::rc::{Rc, Weak}; -impl TimerBasedAnimationDriver { - fn new() -> Rc { - Rc::new_cyclic(|self_weak: &Weak| { - let self_weak = self_weak.clone(); - let timer = i_slint_core::timers::Timer::default(); - timer.start( - i_slint_core::timers::TimerMode::Repeated, - std::time::Duration::from_millis(16), - move || { - let Some(this) = self_weak.upgrade() else { return }; - // Stop the timer and let the callback decide if we need to continue. It will set - // `needs_redraw` to true of animations should continue, render() will be called, - // present_with_next_frame_callback() will be called and then the timer restarted. - this.timer.stop(); - if let Some(next_animation_frame_callback) = - this.next_animation_frame_callback.take() - { - next_animation_frame_callback(); - } - }, - ); - // Activate it only when we present a frame. - timer.stop(); + pub(crate) struct TimerBasedAnimationDriver { + timer: i_slint_core::timers::Timer, + next_animation_frame_callback: Cell>>, + } - Self { timer, next_animation_frame_callback: Default::default() } - }) - } -} - -impl crate::display::Presenter for TimerBasedAnimationDriver { - fn is_ready_to_present(&self) -> bool { - true - } - - fn register_page_flip_handler( - &self, - _event_loop_handle: crate::calloop_backend::EventLoopHandle, - ) -> Result<(), PlatformError> { - Ok(()) - } - - fn present_with_next_frame_callback( - &self, - ready_for_next_animation_frame: Box, - ) -> Result<(), Box> { - self.next_animation_frame_callback.set(Some(ready_for_next_animation_frame)); - self.timer.restart(); - Ok(()) + impl TimerBasedAnimationDriver { + pub(crate) fn new() -> Rc { + Rc::new_cyclic(|self_weak: &Weak| { + let self_weak = self_weak.clone(); + let timer = i_slint_core::timers::Timer::default(); + timer.start( + i_slint_core::timers::TimerMode::Repeated, + std::time::Duration::from_millis(16), + move || { + let Some(this) = self_weak.upgrade() else { return }; + // Stop the timer and let the callback decide if we need to continue. It will set + // `needs_redraw` to true of animations should continue, render() will be called, + // present_with_next_frame_callback() will be called and then the timer restarted. + this.timer.stop(); + if let Some(next_animation_frame_callback) = + this.next_animation_frame_callback.take() + { + next_animation_frame_callback(); + } + }, + ); + // Activate it only when we present a frame. + timer.stop(); + + Self { timer, next_animation_frame_callback: Default::default() } + }) + } + } + + impl crate::display::Presenter for TimerBasedAnimationDriver { + fn is_ready_to_present(&self) -> bool { + true + } + + fn register_page_flip_handler( + &self, + _event_loop_handle: crate::calloop_backend::EventLoopHandle, + ) -> Result<(), PlatformError> { + Ok(()) + } + + fn present_with_next_frame_callback( + &self, + ready_for_next_animation_frame: Box, + ) -> Result<(), Box> { + self.next_animation_frame_callback.set(Some(ready_for_next_animation_frame)); + self.timer.restart(); + Ok(()) + } } } diff --git a/internal/backends/linuxkms/display/swdisplay/linuxfb.rs b/internal/backends/linuxkms/display/swdisplay/linuxfb.rs index 6993d162c..5b852d1c1 100644 --- a/internal/backends/linuxkms/display/swdisplay/linuxfb.rs +++ b/internal/backends/linuxkms/display/swdisplay/linuxfb.rs @@ -12,7 +12,7 @@ pub struct LinuxFBDisplay { back_buffer: RefCell>, width: u32, height: u32, - presenter: Rc, + presenter: Rc, first_frame: Cell, } @@ -87,7 +87,7 @@ impl LinuxFBDisplay { back_buffer, width, height, - presenter: crate::display::TimerBasedAnimationDriver::new(), + presenter: crate::display::timeranimations::TimerBasedAnimationDriver::new(), first_frame: Cell::new(true), })) } diff --git a/internal/backends/linuxkms/display/vulkandisplay.rs b/internal/backends/linuxkms/display/vulkandisplay.rs index 7da12d302..1a2449057 100644 --- a/internal/backends/linuxkms/display/vulkandisplay.rs +++ b/internal/backends/linuxkms/display/vulkandisplay.rs @@ -173,6 +173,6 @@ pub fn create_vulkan_display() -> Result { queue_family_index, surface: vulkan_surface, size, - presenter: crate::display::TimerBasedAnimationDriver::new(), + presenter: crate::display::timeranimations::TimerBasedAnimationDriver::new(), }) }