cogl/auto/
frame_info.rs

1use crate::{Object, Output};
2
3use glib::translate::*;
4use std::fmt;
5
6glib_wrapper! {
7    pub struct FrameInfo(Object<ffi::CoglFrameInfo, FrameInfoClass>) @extends Object;
8
9    match fn {
10        get_type => || ffi::cogl_frame_info_get_gtype(),
11    }
12}
13
14impl FrameInfo {
15    /// Gets the frame counter for the `Onscreen` that corresponds
16    /// to this frame.
17    ///
18    /// # Returns
19    ///
20    /// The frame counter value
21    pub fn get_frame_counter(&self) -> i64 {
22        unsafe { ffi::cogl_frame_info_get_frame_counter(self.to_glib_none().0) }
23    }
24
25    /// Gets the `Output` that the swapped frame was presented to.
26    ///
27    /// # Returns
28    ///
29    /// The `Output` that the frame was
30    ///  presented to, or `None` if this could not be determined.
31    pub fn get_output(&self) -> Option<Output> {
32        unsafe { from_glib_none(ffi::cogl_frame_info_get_output(self.to_glib_none().0)) }
33    }
34
35    /// Gets the presentation time for the frame. This is the time at which
36    /// the frame became visible to the user.
37    ///
38    /// The presentation time measured in nanoseconds is based on a
39    /// monotonic time source. The time source is not necessarily
40    /// correlated with system/wall clock time and may represent the time
41    /// elapsed since some undefined system event such as when the system
42    /// last booted.
43    ///
44    /// `<note>`Linux kernel version less that 3.8 can result in
45    /// non-monotonic timestamps being reported when using a drm based
46    /// OpenGL driver. Also some buggy Mesa drivers up to 9.0.1 may also
47    /// incorrectly report non-monotonic timestamps.`</note>`
48    ///
49    /// # Returns
50    ///
51    /// the presentation time for the frame
52    pub fn get_presentation_time(&self) -> i64 {
53        unsafe { ffi::cogl_frame_info_get_presentation_time(self.to_glib_none().0) }
54    }
55
56    /// Gets the refresh rate in Hertz for the output that the frame was on
57    /// at the time the frame was presented.
58    ///
59    /// `<note>`Some platforms can't associate a `Output` with a
60    /// `FrameInfo` object but are able to report a refresh rate via
61    /// this api. Therefore if you need this information then this api is
62    /// more reliable than using `FrameInfo::get_output` followed by
63    /// `Output::get_refresh_rate`.`</note>`
64    ///
65    /// # Returns
66    ///
67    /// the refresh rate in Hertz
68    pub fn get_refresh_rate(&self) -> f32 {
69        unsafe { ffi::cogl_frame_info_get_refresh_rate(self.to_glib_none().0) }
70    }
71}
72
73impl fmt::Display for FrameInfo {
74    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
75        write!(f, "FrameInfo")
76    }
77}