Skip to main content

gdk/
frame_timings.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::FrameTimings;
4use glib::translate::*;
5use std::num::NonZeroU64;
6
7impl FrameTimings {
8    /// Gets the predicted time at which this frame will be displayed. Although
9    /// no predicted time may be available, if one is available, it will
10    /// be available while the frame is being generated, in contrast to
11    /// [`presentation_time()`][Self::presentation_time()], which is only available
12    /// after the frame has been presented. In general, if you are simply
13    /// animating, you should use [`FrameClock::frame_time()`][crate::FrameClock::frame_time()] rather
14    /// than this function, but this function is useful for applications
15    /// that want exact control over latency. For example, a movie player
16    /// may want this information for Audio/Video synchronization.
17    ///
18    /// # Returns
19    ///
20    /// The predicted time at which the frame will be presented,
21    ///  in the timescale of `g_get_monotonic_time()`, or 0 if no predicted
22    ///  presentation time is available.
23    #[doc(alias = "gdk_frame_timings_get_predicted_presentation_time")]
24    #[doc(alias = "get_predicted_presentation_time")]
25    pub fn predicted_presentation_time(&self) -> Option<NonZeroU64> {
26        let predicted_presentation_time = unsafe {
27            ffi::gdk_frame_timings_get_predicted_presentation_time(self.to_glib_none().0)
28        };
29        // assuming presentation time is always positive
30        assert!(predicted_presentation_time >= 0);
31        // `0` means the value is not available
32        NonZeroU64::new(predicted_presentation_time as u64)
33    }
34
35    /// Reurns the presentation time. This is the time at which the frame
36    /// became visible to the user.
37    ///
38    /// # Returns
39    ///
40    /// the time the frame was displayed to the user, in the
41    ///  timescale of `g_get_monotonic_time()`, or 0 if no presentation
42    ///  time is available. See [`is_complete()`][Self::is_complete()]
43    #[doc(alias = "gdk_frame_timings_get_presentation_time")]
44    #[doc(alias = "get_presentation_time")]
45    pub fn presentation_time(&self) -> Option<NonZeroU64> {
46        let presentation_time =
47            unsafe { ffi::gdk_frame_timings_get_presentation_time(self.to_glib_none().0) };
48        // assuming presentation time is always positive
49        assert!(presentation_time >= 0);
50        // `0` means the value is not available
51        NonZeroU64::new(presentation_time as u64)
52    }
53
54    /// Gets the natural interval between presentation times for
55    /// the display that this frame was displayed on. Frame presentation
56    /// usually happens during the “vertical blanking interval”.
57    ///
58    /// # Returns
59    ///
60    /// the refresh interval of the display, in microseconds,
61    ///  or 0 if the refresh interval is not available.
62    ///  See [`is_complete()`][Self::is_complete()].
63    #[doc(alias = "gdk_frame_timings_get_refresh_interval")]
64    #[doc(alias = "get_refresh_interval")]
65    pub fn refresh_interval(&self) -> Option<NonZeroU64> {
66        let refresh_interval =
67            unsafe { ffi::gdk_frame_timings_get_refresh_interval(self.to_glib_none().0) };
68        // assuming refresh interval is always positive
69        assert!(refresh_interval >= 0);
70        // `0` means the value is not available
71        NonZeroU64::new(refresh_interval as u64)
72    }
73}