[retro-gtk/wip/aplazas/gl-display: 3/3] gl-display: Sync draw queries and window clock ticks



commit c63677e2366919ea3a6faf535c890ad7cf85f358
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Nov 17 13:27:07 2017 +0100

    gl-display: Sync draw queries and window clock ticks

 retro-gtk/retro-gl-display.c |   39 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index e287948..a4e4706 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -14,6 +14,8 @@ struct _RetroGLDisplay
   RetroVideoFilter filter;
   gfloat aspect_ratio;
   gulong on_video_output_id;
+  gboolean video_changed;
+  guint tick_id;
 
   RetroGLSLFilter *glsl_filter[RETRO_VIDEO_FILTER_COUNT];
   GLuint framebuffer;
@@ -98,6 +100,20 @@ retro_gl_display_get_video_box (RetroGLDisplay *self,
   *y = (h - *height) / 2;
 }
 
+static gboolean
+retro_gl_display_on_tick (GtkWidget      *sender,
+                          GdkFrameClock  *frame_clock,
+                          RetroGLDisplay *self)
+{
+  if (!self->video_changed)
+    return G_SOURCE_CONTINUE;
+
+  self->video_changed = FALSE;
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+
+  return G_SOURCE_CONTINUE;
+}
+
 static void
 retro_gl_display_blit_texture (RetroGLDisplay *self,
                                GLenum          filter)
@@ -312,6 +328,8 @@ retro_gl_display_finalize (GObject *object)
     g_object_unref (self->core);
   if (self->pixbuf != NULL)
     g_object_unref (self->pixbuf);
+  if (self->tick_id != 0)
+    gtk_widget_remove_tick_callback (GTK_WIDGET (self), self->tick_id);
 
   G_OBJECT_CLASS (retro_gl_display_parent_class)->finalize (object);
 }
@@ -386,6 +404,14 @@ queue_draw (GObject    *sender,
 }
 
 static void
+on_pixbuf_changed (GObject        *sender,
+                   GParamSpec     *pspec,
+                   RetroGLDisplay *self)
+{
+  self->video_changed = TRUE;
+}
+
+static void
 retro_gl_display_init (RetroGLDisplay *self)
 {
   g_signal_connect_object (G_OBJECT (self),
@@ -416,7 +442,7 @@ retro_gl_display_init (RetroGLDisplay *self)
 
   g_signal_connect_object (G_OBJECT (self),
                            "notify::pixbuf",
-                           (GCallback) queue_draw,
+                           (GCallback) on_pixbuf_changed,
                            GTK_WIDGET (self),
                            0);
 }
@@ -502,9 +528,18 @@ retro_gl_display_set_pixbuf (RetroGLDisplay *self,
     return;
 
   g_clear_object (&self->pixbuf);
+  if (self->tick_id != 0) {
+    gtk_widget_remove_tick_callback (GTK_WIDGET (self), self->tick_id);
+    self->tick_id = 0;
+  }
 
-  if (pixbuf != NULL)
+  if (pixbuf != NULL) {
     self->pixbuf = g_object_ref (pixbuf);
+    self->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (self),
+                                                  retro_gl_display_on_tick,
+                                                  self,
+                                                  NULL);
+  }
 
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PIXBUF]);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]