[retro-gtk/wip/aplazas/gl-display: 10/12] gl-display: Save the RetroPixdata



commit fb1f90cf185cf3df6d7e003f0edcde875354acbd
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat Nov 18 10:25:11 2017 +0100

    gl-display: Save the RetroPixdata
    
    Save the RetroPixdata and convert it into a pixbuf on demand.
    
    This causes more work for the moment as it just adds a copy, but in the
    next commit it will allow to directly load the texture from the pixdata,
    saving work.

 retro-gtk/retro-gl-display.c |   39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index 39061f9..9bf340e 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -10,6 +10,7 @@ struct _RetroGLDisplay
 {
   GtkGLArea parent_instance;
   RetroCore *core;
+  RetroPixdata *pixdata;
   GdkPixbuf *pixbuf;
   RetroVideoFilter filter;
   gfloat aspect_ratio;
@@ -52,6 +53,26 @@ static const gchar *filter_uris[] = {
 /* Private */
 
 static void
+retro_gl_display_set_pixdata (RetroGLDisplay *self,
+                              RetroPixdata   *pixdata)
+{
+  if (self->pixdata == pixdata)
+    return;
+
+  g_clear_object (&self->pixbuf);
+  if (self->pixdata != NULL) {
+    retro_pixdata_free (self->pixdata);
+    self->pixdata = NULL;
+  }
+
+  if (pixdata != NULL) {
+    self->pixdata = retro_pixdata_copy (pixdata);
+  }
+
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
 retro_gl_display_get_video_box (RetroGLDisplay *self,
                                 gdouble        *width,
                                 gdouble        *height,
@@ -382,16 +403,10 @@ retro_gl_display_on_video_output (RetroCore    *sender,
 {
   RetroGLDisplay *self = RETRO_GL_DISPLAY (user_data);
 
-  GdkPixbuf *pixbuf;
-
   g_return_if_fail (RETRO_IS_GL_DISPLAY (self));
 
   self->aspect_ratio = retro_pixdata_get_aspect_ratio (pixdata);
-  pixbuf = retro_pixdata_to_pixbuf (pixdata);
-  retro_gl_display_set_pixbuf (self, pixbuf);
-
-  if (pixbuf != NULL)
-    g_object_unref (pixbuf);
+  retro_gl_display_set_pixdata (self, pixdata);
 }
 
 /* Public */
@@ -436,6 +451,12 @@ retro_gl_display_get_pixbuf (RetroGLDisplay *self)
 {
   g_return_val_if_fail (RETRO_IS_GL_DISPLAY (self), NULL);
 
+  if (self->pixbuf != NULL)
+    return self->pixbuf;
+
+  if (self->pixdata != NULL)
+    self->pixbuf = retro_pixdata_to_pixbuf (self->pixdata);
+
   return self->pixbuf;
 }
 
@@ -456,6 +477,10 @@ retro_gl_display_set_pixbuf (RetroGLDisplay *self,
     return;
 
   g_clear_object (&self->pixbuf);
+  if (self->pixdata != NULL) {
+    retro_pixdata_free (self->pixdata);
+    self->pixdata = NULL;
+  }
 
   if (pixbuf != NULL)
     self->pixbuf = g_object_ref (pixbuf);


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