gdk/auto/frame_clock.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{FrameClockPhase, FrameTimings};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 /// A [`FrameClock`][crate::FrameClock] tells the application when to update and repaint a
15 /// window. This may be synced to the vertical refresh rate of the
16 /// monitor, for example. Even when the frame clock uses a simple timer
17 /// rather than a hardware-based vertical sync, the frame clock helps
18 /// because it ensures everything paints at the same time (reducing the
19 /// total number of frames). The frame clock can also automatically
20 /// stop painting when it knows the frames will not be visible, or
21 /// scale back animation framerates.
22 ///
23 /// [`FrameClock`][crate::FrameClock] is designed to be compatible with an OpenGL-based
24 /// implementation or with mozRequestAnimationFrame in Firefox,
25 /// for example.
26 ///
27 /// A frame clock is idle until someone requests a frame with
28 /// [`request_phase()`][Self::request_phase()]. At some later point that makes
29 /// sense for the synchronization being implemented, the clock will
30 /// process a frame and emit signals for each phase that has been
31 /// requested. (See the signals of the [`FrameClock`][crate::FrameClock] class for
32 /// documentation of the phases. [`FrameClockPhase::UPDATE`][crate::FrameClockPhase::UPDATE] and the
33 /// [`update`][struct@crate::FrameClock#update] signal are most interesting for application
34 /// writers, and are used to update the animations, using the frame time
35 /// given by [`frame_time()`][Self::frame_time()].
36 ///
37 /// The frame time is reported in microseconds and generally in the same
38 /// timescale as `g_get_monotonic_time()`, however, it is not the same
39 /// as `g_get_monotonic_time()`. The frame time does not advance during
40 /// the time a frame is being painted, and outside of a frame, an attempt
41 /// is made so that all calls to [`frame_time()`][Self::frame_time()] that
42 /// are called at a “similar” time get the same value. This means that
43 /// if different animations are timed by looking at the difference in
44 /// time between an initial value from [`frame_time()`][Self::frame_time()]
45 /// and the value inside the [`update`][struct@crate::FrameClock#update] signal of the clock,
46 /// they will stay exactly synchronized.
47 ///
48 /// This is an Abstract Base Class, you cannot instantiate it.
49 ///
50 /// ## Signals
51 ///
52 ///
53 /// #### `after-paint`
54 /// This signal ends processing of the frame. Applications
55 /// should generally not handle this signal.
56 ///
57 ///
58 ///
59 ///
60 /// #### `before-paint`
61 /// This signal begins processing of the frame. Applications
62 /// should generally not handle this signal.
63 ///
64 ///
65 ///
66 ///
67 /// #### `flush-events`
68 /// This signal is used to flush pending motion events that
69 /// are being batched up and compressed together. Applications
70 /// should not handle this signal.
71 ///
72 ///
73 ///
74 ///
75 /// #### `layout`
76 /// This signal is emitted as the second step of toolkit and
77 /// application processing of the frame. Any work to update
78 /// sizes and positions of application elements should be
79 /// performed. GTK+ normally handles this internally.
80 ///
81 ///
82 ///
83 ///
84 /// #### `paint`
85 /// This signal is emitted as the third step of toolkit and
86 /// application processing of the frame. The frame is
87 /// repainted. GDK normally handles this internally and
88 /// produces expose events, which are turned into GTK+
89 /// `GtkWidget::draw` signals.
90 ///
91 ///
92 ///
93 ///
94 /// #### `resume-events`
95 /// This signal is emitted after processing of the frame is
96 /// finished, and is handled internally by GTK+ to resume normal
97 /// event processing. Applications should not handle this signal.
98 ///
99 ///
100 ///
101 ///
102 /// #### `update`
103 /// This signal is emitted as the first step of toolkit and
104 /// application processing of the frame. Animations should
105 /// be updated using [`FrameClock::frame_time()`][crate::FrameClock::frame_time()].
106 /// Applications can connect directly to this signal, or
107 /// use `gtk_widget_add_tick_callback()` as a more convenient
108 /// interface.
109 ///
110 ///
111 #[doc(alias = "GdkFrameClock")]
112 pub struct FrameClock(Object<ffi::GdkFrameClock, ffi::GdkFrameClockClass>);
113
114 match fn {
115 type_ => || ffi::gdk_frame_clock_get_type(),
116 }
117}
118
119impl FrameClock {
120 /// Starts updates for an animation. Until a matching call to
121 /// [`end_updating()`][Self::end_updating()] is made, the frame clock will continually
122 /// request a new frame with the [`FrameClockPhase::UPDATE`][crate::FrameClockPhase::UPDATE] phase.
123 /// This function may be called multiple times and frames will be
124 /// requested until [`end_updating()`][Self::end_updating()] is called the same
125 /// number of times.
126 #[doc(alias = "gdk_frame_clock_begin_updating")]
127 pub fn begin_updating(&self) {
128 unsafe {
129 ffi::gdk_frame_clock_begin_updating(self.to_glib_none().0);
130 }
131 }
132
133 /// Stops updates for an animation. See the documentation for
134 /// [`begin_updating()`][Self::begin_updating()].
135 #[doc(alias = "gdk_frame_clock_end_updating")]
136 pub fn end_updating(&self) {
137 unsafe {
138 ffi::gdk_frame_clock_end_updating(self.to_glib_none().0);
139 }
140 }
141
142 /// Gets the frame timings for the current frame.
143 ///
144 /// # Returns
145 ///
146 /// the [`FrameTimings`][crate::FrameTimings] for the
147 /// frame currently being processed, or even no frame is being
148 /// processed, for the previous frame. Before any frames have been
149 /// processed, returns [`None`].
150 #[doc(alias = "gdk_frame_clock_get_current_timings")]
151 #[doc(alias = "get_current_timings")]
152 pub fn current_timings(&self) -> Option<FrameTimings> {
153 unsafe {
154 from_glib_none(ffi::gdk_frame_clock_get_current_timings(
155 self.to_glib_none().0,
156 ))
157 }
158 }
159
160 /// A [`FrameClock`][crate::FrameClock] maintains a 64-bit counter that increments for
161 /// each frame drawn.
162 ///
163 /// # Returns
164 ///
165 /// inside frame processing, the value of the frame counter
166 /// for the current frame. Outside of frame processing, the frame
167 /// counter for the last frame.
168 #[doc(alias = "gdk_frame_clock_get_frame_counter")]
169 #[doc(alias = "get_frame_counter")]
170 pub fn frame_counter(&self) -> i64 {
171 unsafe { ffi::gdk_frame_clock_get_frame_counter(self.to_glib_none().0) }
172 }
173
174 /// Gets the time that should currently be used for animations. Inside
175 /// the processing of a frame, it’s the time used to compute the
176 /// animation position of everything in a frame. Outside of a frame, it's
177 /// the time of the conceptual “previous frame,” which may be either
178 /// the actual previous frame time, or if that’s too old, an updated
179 /// time.
180 ///
181 /// # Returns
182 ///
183 /// a timestamp in microseconds, in the timescale of
184 /// of `g_get_monotonic_time()`.
185 #[doc(alias = "gdk_frame_clock_get_frame_time")]
186 #[doc(alias = "get_frame_time")]
187 pub fn frame_time(&self) -> i64 {
188 unsafe { ffi::gdk_frame_clock_get_frame_time(self.to_glib_none().0) }
189 }
190
191 /// [`FrameClock`][crate::FrameClock] internally keeps a history of [`FrameTimings`][crate::FrameTimings]
192 /// objects for recent frames that can be retrieved with
193 /// [`timings()`][Self::timings()]. The set of stored frames
194 /// is the set from the counter values given by
195 /// [`history_start()`][Self::history_start()] and
196 /// [`frame_counter()`][Self::frame_counter()], inclusive.
197 ///
198 /// # Returns
199 ///
200 /// the frame counter value for the oldest frame
201 /// that is available in the internal frame history of the
202 /// [`FrameClock`][crate::FrameClock].
203 #[doc(alias = "gdk_frame_clock_get_history_start")]
204 #[doc(alias = "get_history_start")]
205 pub fn history_start(&self) -> i64 {
206 unsafe { ffi::gdk_frame_clock_get_history_start(self.to_glib_none().0) }
207 }
208
209 /// Retrieves a [`FrameTimings`][crate::FrameTimings] object holding timing information
210 /// for the current frame or a recent frame. The [`FrameTimings`][crate::FrameTimings]
211 /// object may not yet be complete: see [`FrameTimings::is_complete()`][crate::FrameTimings::is_complete()].
212 /// ## `frame_counter`
213 /// the frame counter value identifying the frame to
214 /// be received.
215 ///
216 /// # Returns
217 ///
218 /// the [`FrameTimings`][crate::FrameTimings] object for
219 /// the specified frame, or [`None`] if it is not available. See
220 /// [`history_start()`][Self::history_start()].
221 #[doc(alias = "gdk_frame_clock_get_timings")]
222 #[doc(alias = "get_timings")]
223 pub fn timings(&self, frame_counter: i64) -> Option<FrameTimings> {
224 unsafe {
225 from_glib_none(ffi::gdk_frame_clock_get_timings(
226 self.to_glib_none().0,
227 frame_counter,
228 ))
229 }
230 }
231
232 /// Asks the frame clock to run a particular phase. The signal
233 /// corresponding the requested phase will be emitted the next
234 /// time the frame clock processes. Multiple calls to
235 /// [`request_phase()`][Self::request_phase()] will be combined together
236 /// and only one frame processed. If you are displaying animated
237 /// content and want to continually request the
238 /// [`FrameClockPhase::UPDATE`][crate::FrameClockPhase::UPDATE] phase for a period of time,
239 /// you should use [`begin_updating()`][Self::begin_updating()] instead, since
240 /// this allows GTK+ to adjust system parameters to get maximally
241 /// smooth animations.
242 /// ## `phase`
243 /// the phase that is requested
244 #[doc(alias = "gdk_frame_clock_request_phase")]
245 pub fn request_phase(&self, phase: FrameClockPhase) {
246 unsafe {
247 ffi::gdk_frame_clock_request_phase(self.to_glib_none().0, phase.into_glib());
248 }
249 }
250
251 /// This signal ends processing of the frame. Applications
252 /// should generally not handle this signal.
253 #[doc(alias = "after-paint")]
254 pub fn connect_after_paint<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
255 unsafe extern "C" fn after_paint_trampoline<F: Fn(&FrameClock) + 'static>(
256 this: *mut ffi::GdkFrameClock,
257 f: glib::ffi::gpointer,
258 ) {
259 let f: &F = &*(f as *const F);
260 f(&from_glib_borrow(this))
261 }
262 unsafe {
263 let f: Box_<F> = Box_::new(f);
264 connect_raw(
265 self.as_ptr() as *mut _,
266 b"after-paint\0".as_ptr() as *const _,
267 Some(transmute::<_, unsafe extern "C" fn()>(
268 after_paint_trampoline::<F> as *const (),
269 )),
270 Box_::into_raw(f),
271 )
272 }
273 }
274
275 /// This signal begins processing of the frame. Applications
276 /// should generally not handle this signal.
277 #[doc(alias = "before-paint")]
278 pub fn connect_before_paint<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
279 unsafe extern "C" fn before_paint_trampoline<F: Fn(&FrameClock) + 'static>(
280 this: *mut ffi::GdkFrameClock,
281 f: glib::ffi::gpointer,
282 ) {
283 let f: &F = &*(f as *const F);
284 f(&from_glib_borrow(this))
285 }
286 unsafe {
287 let f: Box_<F> = Box_::new(f);
288 connect_raw(
289 self.as_ptr() as *mut _,
290 b"before-paint\0".as_ptr() as *const _,
291 Some(transmute::<_, unsafe extern "C" fn()>(
292 before_paint_trampoline::<F> as *const (),
293 )),
294 Box_::into_raw(f),
295 )
296 }
297 }
298
299 /// This signal is used to flush pending motion events that
300 /// are being batched up and compressed together. Applications
301 /// should not handle this signal.
302 #[doc(alias = "flush-events")]
303 pub fn connect_flush_events<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
304 unsafe extern "C" fn flush_events_trampoline<F: Fn(&FrameClock) + 'static>(
305 this: *mut ffi::GdkFrameClock,
306 f: glib::ffi::gpointer,
307 ) {
308 let f: &F = &*(f as *const F);
309 f(&from_glib_borrow(this))
310 }
311 unsafe {
312 let f: Box_<F> = Box_::new(f);
313 connect_raw(
314 self.as_ptr() as *mut _,
315 b"flush-events\0".as_ptr() as *const _,
316 Some(transmute::<_, unsafe extern "C" fn()>(
317 flush_events_trampoline::<F> as *const (),
318 )),
319 Box_::into_raw(f),
320 )
321 }
322 }
323
324 /// This signal is emitted as the second step of toolkit and
325 /// application processing of the frame. Any work to update
326 /// sizes and positions of application elements should be
327 /// performed. GTK+ normally handles this internally.
328 #[doc(alias = "layout")]
329 pub fn connect_layout<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
330 unsafe extern "C" fn layout_trampoline<F: Fn(&FrameClock) + 'static>(
331 this: *mut ffi::GdkFrameClock,
332 f: glib::ffi::gpointer,
333 ) {
334 let f: &F = &*(f as *const F);
335 f(&from_glib_borrow(this))
336 }
337 unsafe {
338 let f: Box_<F> = Box_::new(f);
339 connect_raw(
340 self.as_ptr() as *mut _,
341 b"layout\0".as_ptr() as *const _,
342 Some(transmute::<_, unsafe extern "C" fn()>(
343 layout_trampoline::<F> as *const (),
344 )),
345 Box_::into_raw(f),
346 )
347 }
348 }
349
350 /// This signal is emitted as the third step of toolkit and
351 /// application processing of the frame. The frame is
352 /// repainted. GDK normally handles this internally and
353 /// produces expose events, which are turned into GTK+
354 /// `GtkWidget::draw` signals.
355 #[doc(alias = "paint")]
356 pub fn connect_paint<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
357 unsafe extern "C" fn paint_trampoline<F: Fn(&FrameClock) + 'static>(
358 this: *mut ffi::GdkFrameClock,
359 f: glib::ffi::gpointer,
360 ) {
361 let f: &F = &*(f as *const F);
362 f(&from_glib_borrow(this))
363 }
364 unsafe {
365 let f: Box_<F> = Box_::new(f);
366 connect_raw(
367 self.as_ptr() as *mut _,
368 b"paint\0".as_ptr() as *const _,
369 Some(transmute::<_, unsafe extern "C" fn()>(
370 paint_trampoline::<F> as *const (),
371 )),
372 Box_::into_raw(f),
373 )
374 }
375 }
376
377 /// This signal is emitted after processing of the frame is
378 /// finished, and is handled internally by GTK+ to resume normal
379 /// event processing. Applications should not handle this signal.
380 #[doc(alias = "resume-events")]
381 pub fn connect_resume_events<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
382 unsafe extern "C" fn resume_events_trampoline<F: Fn(&FrameClock) + 'static>(
383 this: *mut ffi::GdkFrameClock,
384 f: glib::ffi::gpointer,
385 ) {
386 let f: &F = &*(f as *const F);
387 f(&from_glib_borrow(this))
388 }
389 unsafe {
390 let f: Box_<F> = Box_::new(f);
391 connect_raw(
392 self.as_ptr() as *mut _,
393 b"resume-events\0".as_ptr() as *const _,
394 Some(transmute::<_, unsafe extern "C" fn()>(
395 resume_events_trampoline::<F> as *const (),
396 )),
397 Box_::into_raw(f),
398 )
399 }
400 }
401
402 /// This signal is emitted as the first step of toolkit and
403 /// application processing of the frame. Animations should
404 /// be updated using [`frame_time()`][Self::frame_time()].
405 /// Applications can connect directly to this signal, or
406 /// use `gtk_widget_add_tick_callback()` as a more convenient
407 /// interface.
408 #[doc(alias = "update")]
409 pub fn connect_update<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
410 unsafe extern "C" fn update_trampoline<F: Fn(&FrameClock) + 'static>(
411 this: *mut ffi::GdkFrameClock,
412 f: glib::ffi::gpointer,
413 ) {
414 let f: &F = &*(f as *const F);
415 f(&from_glib_borrow(this))
416 }
417 unsafe {
418 let f: Box_<F> = Box_::new(f);
419 connect_raw(
420 self.as_ptr() as *mut _,
421 b"update\0".as_ptr() as *const _,
422 Some(transmute::<_, unsafe extern "C" fn()>(
423 update_trampoline::<F> as *const (),
424 )),
425 Box_::into_raw(f),
426 )
427 }
428 }
429}
430
431impl fmt::Display for FrameClock {
432 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
433 f.write_str("FrameClock")
434 }
435}