1use gdk_sys;
6use glib::object::ObjectType as ObjectType_;
7use glib::signal::connect_raw;
8use glib::signal::SignalHandlerId;
9use glib::translate::*;
10use glib_sys;
11use std::boxed::Box as Box_;
12use std::fmt;
13use std::mem::transmute;
14use FrameClockPhase;
15use FrameTimings;
16
17glib_wrapper! {
18 pub struct FrameClock(Object<gdk_sys::GdkFrameClock, gdk_sys::GdkFrameClockClass, FrameClockClass>);
19
20 match fn {
21 get_type => || gdk_sys::gdk_frame_clock_get_type(),
22 }
23}
24
25impl FrameClock {
26 pub fn begin_updating(&self) {
27 unsafe {
28 gdk_sys::gdk_frame_clock_begin_updating(self.to_glib_none().0);
29 }
30 }
31
32 pub fn end_updating(&self) {
33 unsafe {
34 gdk_sys::gdk_frame_clock_end_updating(self.to_glib_none().0);
35 }
36 }
37
38 pub fn get_current_timings(&self) -> Option<FrameTimings> {
39 unsafe {
40 from_glib_none(gdk_sys::gdk_frame_clock_get_current_timings(
41 self.to_glib_none().0,
42 ))
43 }
44 }
45
46 pub fn get_frame_counter(&self) -> i64 {
47 unsafe { gdk_sys::gdk_frame_clock_get_frame_counter(self.to_glib_none().0) }
48 }
49
50 pub fn get_frame_time(&self) -> i64 {
51 unsafe { gdk_sys::gdk_frame_clock_get_frame_time(self.to_glib_none().0) }
52 }
53
54 pub fn get_history_start(&self) -> i64 {
55 unsafe { gdk_sys::gdk_frame_clock_get_history_start(self.to_glib_none().0) }
56 }
57
58 pub fn get_timings(&self, frame_counter: i64) -> Option<FrameTimings> {
59 unsafe {
60 from_glib_none(gdk_sys::gdk_frame_clock_get_timings(
61 self.to_glib_none().0,
62 frame_counter,
63 ))
64 }
65 }
66
67 pub fn request_phase(&self, phase: FrameClockPhase) {
68 unsafe {
69 gdk_sys::gdk_frame_clock_request_phase(self.to_glib_none().0, phase.to_glib());
70 }
71 }
72
73 pub fn connect_after_paint<F: Fn(&FrameClock) + 'static>(&self, f: F) -> SignalHandlerId {
74 unsafe extern "C" fn after_paint_trampoline<F: Fn(&FrameClock) + 'static>(
75 this: *mut gdk_sys::GdkFrameClock,
76 f: glib_sys::gpointer,
77 ) {
78 let f: &F = &*(f as *const F);
79 f(&from_glib_borrow(this))
80 }
81 unsafe {
82 let f: Box_<F> = Box_::new(f);
83 connect_raw(
84 self.as_ptr() as *mut _,
85 b"after-paint\0".as_ptr() as *const _,
86 Some(transmute(after_paint_trampoline::<F> as usize)),
87 Box_::into_raw(f),
88 )
89 }
90 }
91
92 pub fn connect_before_paint<F: Fn(&FrameClock) + 'static>(&self, f: F) -> SignalHandlerId {
93 unsafe extern "C" fn before_paint_trampoline<F: Fn(&FrameClock) + 'static>(
94 this: *mut gdk_sys::GdkFrameClock,
95 f: glib_sys::gpointer,
96 ) {
97 let f: &F = &*(f as *const F);
98 f(&from_glib_borrow(this))
99 }
100 unsafe {
101 let f: Box_<F> = Box_::new(f);
102 connect_raw(
103 self.as_ptr() as *mut _,
104 b"before-paint\0".as_ptr() as *const _,
105 Some(transmute(before_paint_trampoline::<F> as usize)),
106 Box_::into_raw(f),
107 )
108 }
109 }
110
111 pub fn connect_flush_events<F: Fn(&FrameClock) + 'static>(&self, f: F) -> SignalHandlerId {
112 unsafe extern "C" fn flush_events_trampoline<F: Fn(&FrameClock) + 'static>(
113 this: *mut gdk_sys::GdkFrameClock,
114 f: glib_sys::gpointer,
115 ) {
116 let f: &F = &*(f as *const F);
117 f(&from_glib_borrow(this))
118 }
119 unsafe {
120 let f: Box_<F> = Box_::new(f);
121 connect_raw(
122 self.as_ptr() as *mut _,
123 b"flush-events\0".as_ptr() as *const _,
124 Some(transmute(flush_events_trampoline::<F> as usize)),
125 Box_::into_raw(f),
126 )
127 }
128 }
129
130 pub fn connect_layout<F: Fn(&FrameClock) + 'static>(&self, f: F) -> SignalHandlerId {
131 unsafe extern "C" fn layout_trampoline<F: Fn(&FrameClock) + 'static>(
132 this: *mut gdk_sys::GdkFrameClock,
133 f: glib_sys::gpointer,
134 ) {
135 let f: &F = &*(f as *const F);
136 f(&from_glib_borrow(this))
137 }
138 unsafe {
139 let f: Box_<F> = Box_::new(f);
140 connect_raw(
141 self.as_ptr() as *mut _,
142 b"layout\0".as_ptr() as *const _,
143 Some(transmute(layout_trampoline::<F> as usize)),
144 Box_::into_raw(f),
145 )
146 }
147 }
148
149 pub fn connect_paint<F: Fn(&FrameClock) + 'static>(&self, f: F) -> SignalHandlerId {
150 unsafe extern "C" fn paint_trampoline<F: Fn(&FrameClock) + 'static>(
151 this: *mut gdk_sys::GdkFrameClock,
152 f: glib_sys::gpointer,
153 ) {
154 let f: &F = &*(f as *const F);
155 f(&from_glib_borrow(this))
156 }
157 unsafe {
158 let f: Box_<F> = Box_::new(f);
159 connect_raw(
160 self.as_ptr() as *mut _,
161 b"paint\0".as_ptr() as *const _,
162 Some(transmute(paint_trampoline::<F> as usize)),
163 Box_::into_raw(f),
164 )
165 }
166 }
167
168 pub fn connect_resume_events<F: Fn(&FrameClock) + 'static>(&self, f: F) -> SignalHandlerId {
169 unsafe extern "C" fn resume_events_trampoline<F: Fn(&FrameClock) + 'static>(
170 this: *mut gdk_sys::GdkFrameClock,
171 f: glib_sys::gpointer,
172 ) {
173 let f: &F = &*(f as *const F);
174 f(&from_glib_borrow(this))
175 }
176 unsafe {
177 let f: Box_<F> = Box_::new(f);
178 connect_raw(
179 self.as_ptr() as *mut _,
180 b"resume-events\0".as_ptr() as *const _,
181 Some(transmute(resume_events_trampoline::<F> as usize)),
182 Box_::into_raw(f),
183 )
184 }
185 }
186
187 pub fn connect_update<F: Fn(&FrameClock) + 'static>(&self, f: F) -> SignalHandlerId {
188 unsafe extern "C" fn update_trampoline<F: Fn(&FrameClock) + 'static>(
189 this: *mut gdk_sys::GdkFrameClock,
190 f: glib_sys::gpointer,
191 ) {
192 let f: &F = &*(f as *const F);
193 f(&from_glib_borrow(this))
194 }
195 unsafe {
196 let f: Box_<F> = Box_::new(f);
197 connect_raw(
198 self.as_ptr() as *mut _,
199 b"update\0".as_ptr() as *const _,
200 Some(transmute(update_trampoline::<F> as usize)),
201 Box_::into_raw(f),
202 )
203 }
204 }
205}
206
207impl fmt::Display for FrameClock {
208 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
209 write!(f, "FrameClock")
210 }
211}