[retro-gtk] core: Make 'video-output' signal send a RetroPixdata



commit 44b5a914f2bf1e1d2b07c5087177d2cb45ef832a
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Oct 12 12:35:27 2017 +0200

    core: Make 'video-output' signal send a RetroPixdata
    
    Also adapts RetroCairoDisplay to this change.

 retro-gtk/retro-cairo-display.c |   46 +++++---------------------------------
 retro-gtk/retro-core.c          |   24 +++++++------------
 retro-gtk/retro-environment.c   |   14 ++++++++---
 3 files changed, 25 insertions(+), 59 deletions(-)
---
diff --git a/retro-gtk/retro-cairo-display.c b/retro-gtk/retro-cairo-display.c
index 951e0f1..087dc57 100644
--- a/retro-gtk/retro-cairo-display.c
+++ b/retro-gtk/retro-cairo-display.c
@@ -2,21 +2,7 @@
 
 #include "retro-cairo-display.h"
 
-#include "retro-pixel-format.h"
-
-// FIXME Remove as soon as possible.
-GdkPixbuf *
-gdk_pixbuf_new_from_video (gconstpointer src,
-                           guint         width,
-                           guint         height,
-                           gsize         pitch,
-                           gint          pixel_format);
-
-/*
- * Because gdk-pixbuf saves dpi as integer we have to multiply it by big enough
- * number to represent aspect ratio precisely.
- */
-#define RETRO_CAIRO_DISPLAY_Y_DPI (1000000.0f)
+#include "retro-pixdata.h"
 
 struct _RetroCairoDisplay
 {
@@ -259,42 +245,22 @@ retro_cairo_display_init (RetroCairoDisplay *self)
 }
 
 static void
-retro_cairo_display_on_video_output (RetroCore        *sender,
-                                     guint8           *data,
-                                     gsize             length,
-                                     guint             width,
-                                     guint             height,
-                                     gsize             pitch,
-                                     RetroPixelFormat  pixel_format,
-                                     gfloat            aspect_ratio,
-                                     gpointer          user_data)
+retro_cairo_display_on_video_output (RetroCore    *sender,
+                                     RetroPixdata *pixdata,
+                                     gpointer      user_data)
 {
   RetroCairoDisplay *self = RETRO_CAIRO_DISPLAY (user_data);
 
   GdkPixbuf *pixbuf;
-  gfloat x_dpi;
-  gchar *x_dpi_string;
-  gchar *y_dpi_string;
 
   g_return_if_fail (self != NULL);
 
-  self->aspect_ratio = aspect_ratio;
-  pixbuf = gdk_pixbuf_new_from_video (data, width, height, pitch, pixel_format);
+  self->aspect_ratio = retro_pixdata_get_aspect_ratio (pixdata);
+  pixbuf = retro_pixdata_to_pixbuf (pixdata);
   retro_cairo_display_set_pixbuf (self, pixbuf);
 
   if (pixbuf != NULL)
     g_object_unref (pixbuf);
-
-  if (self->pixbuf == NULL)
-    return;
-
-  x_dpi = aspect_ratio * RETRO_CAIRO_DISPLAY_Y_DPI;
-  x_dpi_string = g_strdup_printf ("%g", x_dpi);
-  y_dpi_string = g_strdup_printf ("%g", RETRO_CAIRO_DISPLAY_Y_DPI);
-  gdk_pixbuf_set_option (self->pixbuf, "x-dpi", x_dpi_string);
-  gdk_pixbuf_set_option (self->pixbuf, "y-dpi", y_dpi_string);
-  g_free (y_dpi_string);
-  g_free (x_dpi_string);
 }
 
 /* Public */
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index da24854..d271e86 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -5,6 +5,7 @@
 #include <string.h>
 #include "retro-controller-iterator-private.h"
 #include "retro-keyboard-key.h"
+#include "retro-pixdata.h"
 
 #define RETRO_CORE_ERROR (retro_core_error_quark ())
 
@@ -396,30 +397,23 @@ retro_core_class_init (RetroCoreClass *klass)
   /**
    * RetroCore::video-output:
    * @self: the #RetroCore
-   * @data: (array length=length) (element-type guint8): the video frame data
-   * @length: the lentgh of @data
-   * @width: the width of the video frame
-   * @height: the height of the video frame
-   * @pitch: the distance in bytes between rows
-   * @pixel_format: the pixel format
-   * @aspect_ratio: the aspect ratio to render the frame
+   * @pixdata: (type RetroPixdata): the #RetroPixdata
    *
    * The ::video-output signal is emitted each time a new video frame is emitted
    * by the core.
+   *
+   * @pixdata will be invalid after the signal emission, copy it in some way if
+   * you want to keep it.
    */
   signals[SIG_VIDEO_OUTPUT_SIGNAL] =
     g_signal_new ("video-output", RETRO_TYPE_CORE, G_SIGNAL_RUN_LAST,
                   0, NULL, NULL,
                   NULL,
                   G_TYPE_NONE,
-                  7,
-                  G_TYPE_POINTER,
-                  G_TYPE_ULONG,
-                  G_TYPE_UINT,
-                  G_TYPE_UINT,
-                  G_TYPE_ULONG,
-                  RETRO_TYPE_PIXEL_FORMAT,
-                  G_TYPE_FLOAT);
+                  1,
+                  // G_TYPE_POINTER instead of RETRO_TYPE_PIXDATA to implicit
+                  // copy when sending the RetroPixdata.
+                  G_TYPE_POINTER);
 
   /**
    * RetroCore::audio-output:
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index fd809a1..b294b23 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -1,8 +1,10 @@
 // This file is part of retro-gtk. License: GPL-3.0+.
 
-#include "libretro-environment.h"
 #include "retro-core-private.h"
 
+#include "libretro-environment.h"
+#include "retro-pixdata-private.h"
+
 void retro_core_set_system_av_info (RetroCore         *self,
                                     RetroSystemAvInfo *system_av_info);
 
@@ -415,6 +417,7 @@ on_video_refresh (guint8 *data,
                   gsize   pitch)
 {
   RetroCore *self;
+  RetroPixdata pixdata;
 
   if (data == NULL)
     return;
@@ -424,9 +427,12 @@ on_video_refresh (guint8 *data,
   if (self == NULL)
     g_return_if_reached ();
 
-  g_signal_emit_by_name (self, "video_output", data, pitch * height,
-                         width, height, pitch, self->pixel_format,
-                         self->aspect_ratio);
+  retro_pixdata_init (&pixdata,
+                      data, self->pixel_format,
+                      pitch, width, height,
+                      self->aspect_ratio);
+
+  g_signal_emit_by_name (self, "video-output", &pixdata);
 }
 
 // TODO This is internal, make it private as soon as possible.


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