]> Pileus Git - ~andy/gtk/blobdiff - tests/animated-resizing.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / animated-resizing.c
index f2bbc1013c9a43378e57ce080f5a0dd86cdcbe13..8a34d9fc38201aaa45661b2b99fff4517d8c7bf9 100644 (file)
@@ -16,6 +16,7 @@
 static GtkWidget *window;
 static int window_width = WIDTH, window_height = HEIGHT;
 
+gint64 start_frame_time;
 static double angle;
 
 static int max_stats = -1;
@@ -147,7 +148,7 @@ print_variable (const char *description,
 }
 
 static void
-handle_frame_stats (GdkFrameHistory *frame_history)
+handle_frame_stats (GdkFrameClock *frame_clock)
 {
   static int num_stats = 0;
   static double last_print_time = 0;
@@ -191,11 +192,11 @@ handle_frame_stats (GdkFrameHistory *frame_history)
   frames_since_last_print++;
 
   for (frame_counter = last_handled_frame;
-       frame_counter < gdk_frame_history_get_frame_counter (frame_history);
+       frame_counter < gdk_frame_clock_get_frame_counter (frame_clock);
        frame_counter++)
     {
-      GdkFrameTimings *timings = gdk_frame_history_get_timings (frame_history, frame_counter);
-      GdkFrameTimings *previous_timings = gdk_frame_history_get_timings (frame_history, frame_counter - 1);
+      GdkFrameTimings *timings = gdk_frame_clock_get_timings (frame_clock, frame_counter);
+      GdkFrameTimings *previous_timings = gdk_frame_clock_get_timings (frame_clock, frame_counter - 1);
 
       if (!timings || gdk_frame_timings_get_complete (timings))
         last_handled_frame = frame_counter;
@@ -213,17 +214,13 @@ handle_frame_stats (GdkFrameHistory *frame_history)
 }
 
 static void
-on_frame (GtkTimeline *timeline,
-          double       progress)
+on_frame (double progress)
 {
   GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (window);
   int jitter;
 
   if (frame_clock)
-    {
-      GdkFrameHistory *history = gdk_frame_clock_get_history (frame_clock);
-      handle_frame_stats (history);
-    }
+    handle_frame_stats (frame_clock);
 
   angle = 2 * M_PI * progress;
   jitter = WINDOW_SIZE_JITTER * sin(angle);
@@ -240,12 +237,28 @@ on_frame (GtkTimeline *timeline,
   gtk_widget_queue_draw (window);
 }
 
+static gboolean
+tick_callback (GtkWidget     *widget,
+               GdkFrameClock *frame_clock,
+               gpointer       user_data)
+{
+  gint64 frame_time = gdk_frame_clock_get_frame_time (frame_clock);
+  double scaled_time;
+
+  if (start_frame_time == 0)
+    start_frame_time = frame_time;
+
+  scaled_time = (frame_time - start_frame_time) / (CYCLE_TIME * 1000000);
+  on_frame (scaled_time - floor (scaled_time));
+
+  return G_SOURCE_CONTINUE;
+}
+
 static gboolean
 on_map_event (GtkWidget          *widget,
-              GdkEventAny *event,
-              GtkTimeline *timeline)
+              GdkEventAny *event)
 {
-  gtk_timeline_start (timeline);
+  gtk_widget_add_tick_callback (window, tick_callback, NULL, NULL);
 
   return FALSE;
 }
@@ -265,7 +278,6 @@ main(int argc, char **argv)
   GError *error = NULL;
   GdkScreen *screen;
   GdkRectangle monitor_bounds;
-  GtkTimeline *timeline;
 
   if (!gtk_init_with_args (&argc, &argv, "",
                            options, NULL, &error))
@@ -291,15 +303,9 @@ main(int argc, char **argv)
   g_signal_connect (window, "destroy",
                     G_CALLBACK (gtk_main_quit), NULL);
 
-  timeline = gtk_timeline_new (window, CYCLE_TIME * 1000);
-  gtk_timeline_set_loop (timeline, TRUE);
-  gtk_timeline_set_progress_type (timeline, GTK_TIMELINE_PROGRESS_LINEAR);
-
-  g_signal_connect (timeline, "frame",
-                    G_CALLBACK (on_frame), NULL);
   g_signal_connect (window, "map-event",
-                    G_CALLBACK (on_map_event), timeline);
-  on_frame (timeline, 0.);
+                    G_CALLBACK (on_map_event), NULL);
+  on_frame (0.);
 
   screen = gtk_widget_get_screen (window);
   gdk_screen_get_monitor_geometry (screen,