Add gdk_frame_clock_get_fps

We already have more than one copy of this code
in GTK, so just export this function.
This commit is contained in:
Matthias Clasen 2020-09-13 23:31:17 -04:00
parent 4b589b6afb
commit b166999683
3 changed files with 16 additions and 5 deletions

View File

@ -1036,6 +1036,7 @@ gdk_frame_clock_get_history_start
gdk_frame_clock_get_timings
gdk_frame_clock_get_current_timings
gdk_frame_clock_get_refresh_info
gdk_frame_clock_get_fps
<SUBSECTION Private>
GDK_FRAME_CLOCK

View File

@ -718,7 +718,6 @@ _gdk_frame_clock_emit_resume_events (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[RESUME_EVENTS], 0);
}
#ifdef HAVE_SYSPROF
static gint64
guess_refresh_interval (GdkFrameClock *frame_clock)
{
@ -753,8 +752,17 @@ guess_refresh_interval (GdkFrameClock *frame_clock)
return interval;
}
static double
frame_clock_get_fps (GdkFrameClock *frame_clock)
/**
* gdk_frame_clock_get_fps:
* @frame_clock: a #GdkFrameClock
*
* Calculates the current frames-per-second, based on the
* frame timings of @frame_clock.
*
* Returns: the current fps, as a double
*/
double
gdk_frame_clock_get_fps (GdkFrameClock *frame_clock)
{
GdkFrameTimings *start, *end;
gint64 start_counter, end_counter;
@ -788,7 +796,6 @@ frame_clock_get_fps (GdkFrameClock *frame_clock)
return ((double) end_counter - start_counter) * G_USEC_PER_SEC / (end_timestamp - start_timestamp);
}
#endif
void
_gdk_frame_clock_add_timings_to_profiler (GdkFrameClock *clock,
@ -804,5 +811,5 @@ _gdk_frame_clock_add_timings_to_profiler (GdkFrameClock *clock,
gdk_profiler_add_mark (1000 * timings->presentation_time, 0, "presented window", NULL);
}
gdk_profiler_set_counter (fps_counter, frame_clock_get_fps (clock));
gdk_profiler_set_counter (fps_counter, gdk_frame_clock_get_fps (clock));
}

View File

@ -103,6 +103,9 @@ void gdk_frame_clock_get_refresh_info (GdkFrameClock *frame_clock,
gint64 *refresh_interval_return,
gint64 *presentation_time_return);
GDK_AVAILABLE_IN_ALL
double gdk_frame_clock_get_fps (GdkFrameClock *frame_clock);
G_END_DECLS
#endif /* __GDK_FRAME_CLOCK_H__ */