gtk/gdk/gdkframetimings.c
Owen W. Taylor 15ee04c66f Add GdkFrameHistory and GdkFrameTimings, handle _NET_WM_FRAME_TIMINGS
In order to be able to track statistics about how well we are drawing,
and in order to be able to do sophisticated things with frame timing
like predicting per-frame latencies and synchronizing audio with video,
we need to be able to track exactly when previous frames were drawn
to the screen.

Information about each frame is stored in a new GdkFrameTimings object.
A new GdkFrameHistory object is added which keeps a queue of recent
GdkFrameTimings (this is added to avoid further complicating the
implementation of GdkFrameClock.)

https://bugzilla.gnome.org/show_bug.cgi?id=685460
2013-02-14 17:19:50 -05:00

181 lines
4.0 KiB
C

/* GDK - The GIMP Drawing Kit
* Copyright (C) 2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gdkframetimings.h"
struct _GdkFrameTimings
{
guint ref_count;
gboolean complete;
gint64 frame_counter;
guint64 cookie;
gint64 frame_time;
gint64 drawn_time;
gint64 presentation_time;
gint64 refresh_interval;
};
G_DEFINE_BOXED_TYPE (GdkFrameTimings, gdk_frame_timings,
gdk_frame_timings_ref,
gdk_frame_timings_unref)
GdkFrameTimings *
gdk_frame_timings_new (gint64 frame_counter)
{
GdkFrameTimings *timings;
timings = g_slice_new0 (GdkFrameTimings);
timings->ref_count = 1;
timings->frame_counter = frame_counter;
return timings;
}
GdkFrameTimings *
gdk_frame_timings_ref (GdkFrameTimings *timings)
{
g_return_val_if_fail (timings != NULL, NULL);
timings->ref_count++;
return timings;
}
void
gdk_frame_timings_unref (GdkFrameTimings *timings)
{
g_return_if_fail (timings != NULL);
g_return_if_fail (timings->ref_count > 0);
timings->ref_count--;
if (timings->ref_count == 0)
{
g_slice_free (GdkFrameTimings, timings);
}
}
gint64
gdk_frame_timings_get_frame_counter (GdkFrameTimings *timings)
{
return timings->frame_counter;
}
guint64
gdk_frame_timings_get_cookie (GdkFrameTimings *timings)
{
g_return_val_if_fail (timings != NULL, 0);
return timings->cookie;
}
void
gdk_frame_timings_set_cookie (GdkFrameTimings *timings,
guint64 cookie)
{
g_return_if_fail (timings != NULL);
timings->cookie = cookie;
}
gboolean
gdk_frame_timings_get_complete (GdkFrameTimings *timings)
{
g_return_val_if_fail (timings != NULL, FALSE);
return timings->complete;
}
void
gdk_frame_timings_set_complete (GdkFrameTimings *timings,
gboolean complete)
{
g_return_if_fail (timings != NULL);
timings->complete = complete;
}
gint64
gdk_frame_timings_get_frame_time (GdkFrameTimings *timings)
{
g_return_val_if_fail (timings != NULL, 0);
return timings->frame_time;
}
void
gdk_frame_timings_set_frame_time (GdkFrameTimings *timings,
gint64 frame_time)
{
g_return_if_fail (timings != NULL);
timings->frame_time = frame_time;
}
gint64
gdk_frame_timings_get_drawn_time (GdkFrameTimings *timings)
{
g_return_val_if_fail (timings != NULL, 0);
return timings->drawn_time;
}
void
gdk_frame_timings_set_drawn_time (GdkFrameTimings *timings,
gint64 drawn_time)
{
g_return_if_fail (timings != NULL);
timings->drawn_time = drawn_time;
}
gint64
gdk_frame_timings_get_presentation_time (GdkFrameTimings *timings)
{
g_return_val_if_fail (timings != NULL, 0);
return timings->presentation_time;
}
void
gdk_frame_timings_set_presentation_time (GdkFrameTimings *timings,
gint64 presentation_time)
{
g_return_if_fail (timings != NULL);
timings->presentation_time = presentation_time;
}
gint64
gdk_frame_timings_get_refresh_interval (GdkFrameTimings *timings)
{
g_return_val_if_fail (timings != NULL, 0);
return timings->refresh_interval;
}
void
gdk_frame_timings_set_refresh_interval (GdkFrameTimings *timings,
gint64 refresh_interval)
{
g_return_if_fail (timings != NULL);
timings->refresh_interval = refresh_interval;
}