gdk/
frame_timings.rs

1// Copyright 2018, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use gdk_sys;
6use glib::translate::*;
7use std::num::NonZeroU64;
8use FrameTimings;
9
10impl FrameTimings {
11    pub fn get_predicted_presentation_time(&self) -> Option<NonZeroU64> {
12        let predicted_presentation_time = unsafe {
13            gdk_sys::gdk_frame_timings_get_predicted_presentation_time(self.to_glib_none().0)
14        };
15        // assuming presentation time is always positive
16        assert!(predicted_presentation_time >= 0);
17        // `0` means the value is not available
18        NonZeroU64::new(predicted_presentation_time as u64)
19    }
20
21    pub fn get_presentation_time(&self) -> Option<NonZeroU64> {
22        let presentation_time =
23            unsafe { gdk_sys::gdk_frame_timings_get_presentation_time(self.to_glib_none().0) };
24        // assuming presentation time is always positive
25        assert!(presentation_time >= 0);
26        // `0` means the value is not available
27        NonZeroU64::new(presentation_time as u64)
28    }
29
30    pub fn get_refresh_interval(&self) -> Option<NonZeroU64> {
31        let refresh_interval =
32            unsafe { gdk_sys::gdk_frame_timings_get_refresh_interval(self.to_glib_none().0) };
33        // assuming refresh interval is always positive
34        assert!(refresh_interval >= 0);
35        // `0` means the value is not available
36        NonZeroU64::new(refresh_interval as u64)
37    }
38}