[retro-gtk] Replace Video interface by Core.video_output()



commit cd1eb4cb649357bc91ed5b3f5fbf8f536de15958
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Jan 20 16:40:35 2017 +0100

    Replace Video interface by Core.video_output()
    
    Remove the Video interface, add the Core.video_output() signal and adapt
    CairoDisplay accordingly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777489

 retro-gobject/core.vala            |   25 ++++--------------
 retro-gobject/retro-environment.c  |   49 +++++++++--------------------------
 retro-gobject/video.vala           |   41 ------------------------------
 retro-gtk/video/cairo-display.vala |   39 ++++++++++------------------
 4 files changed, 33 insertions(+), 121 deletions(-)
---
diff --git a/retro-gobject/core.vala b/retro-gobject/core.vala
index a78391f..005b588 100644
--- a/retro-gobject/core.vala
+++ b/retro-gobject/core.vala
@@ -11,6 +11,8 @@ public class Core : Object {
        private static (unowned Core)[] objects = new (unowned Core)[32];
        private static int i = 0;
 
+       public signal void video_output (uint8[] data, uint width, uint height, size_t pitch, PixelFormat 
pixel_format, float aspect_ratio);
+
        /**
         * Stores the current Core instance in a stack.
         *
@@ -155,25 +157,6 @@ public class Core : Object {
         */
        public DiskControl disk_control_interface { internal set; get; }
 
-       private weak Video _video_interface;
-       /**
-        * The video interface.
-        *
-        * It must be set before {@link init} is called.
-        */
-       public weak Video video_interface {
-               get { return _video_interface; }
-               construct set {
-                       if (_video_interface != null)
-                               _video_interface.core = null;
-
-                       _video_interface = value;
-
-                       if (_video_interface != null && _video_interface.core != this)
-                               _video_interface.core = this;
-               }
-       }
-
        private weak Audio _audio_interface;
        /**
         * The audio interface.
@@ -279,6 +262,10 @@ public class Core : Object {
 
        internal Module module;
 
+       internal bool overscan;
+       internal PixelFormat pixel_format;
+       internal Rotation rotation;
+
        /**
         * Creates a Core from the file name of a Libretro implementation.
         *
diff --git a/retro-gobject/retro-environment.c b/retro-gobject/retro-environment.c
index 7d1b440..9baa1c1 100644
--- a/retro-gobject/retro-environment.c
+++ b/retro-gobject/retro-environment.c
@@ -47,13 +47,7 @@ static void log_callback_log (guint level, const char *format, ...) {
 }
 
 static gboolean get_can_dupe (RetroCore *self, gboolean *can_dupe) {
-       RetroVideo *video;
-
-       video = retro_core_get_video_interface (self);
-
-       g_return_val_if_fail (video != NULL, FALSE);
-
-       *can_dupe = retro_video_get_can_dupe (video);
+       *can_dupe = TRUE;
 
        return TRUE;
 }
@@ -92,14 +86,8 @@ static gboolean get_log_callback (RetroCore *self, RetroLogCallback *cb) {
        return TRUE;
 }
 
-static gboolean get_overscan (RetroCore *self, gboolean *overcan) {
-       RetroVideo *video;
-
-       video = retro_core_get_video_interface (self);
-
-       g_return_val_if_fail (video != NULL, FALSE);
-
-       *overcan = retro_video_get_overscan (video);
+static gboolean get_overscan (RetroCore *self, gboolean *overscan) {
+       *overscan = FALSE;
 
        return TRUE;
 }
@@ -180,25 +168,13 @@ static gboolean set_message (RetroCore *self, const RetroMessage *message) {
 }
 
 static gboolean set_pixel_format (RetroCore *self, const RetroPixelFormat *pixel_format) {
-       RetroVideo *video;
-
-       video = retro_core_get_video_interface (self);
-
-       g_return_val_if_fail (video != NULL, FALSE);
-
-       retro_video_set_pixel_format (video, *pixel_format);
+       self->pixel_format = *pixel_format;
 
        return TRUE;
 }
 
 static gboolean set_rotation (RetroCore *self, const RetroRotation *rotation) {
-       RetroVideo *video;
-
-       video = retro_core_get_video_interface (self);
-
-       g_return_val_if_fail (video != NULL, FALSE);
-
-       retro_video_set_rotation (video, *rotation);
+       self->rotation = *rotation;
 
        return TRUE;
 }
@@ -335,19 +311,20 @@ static gboolean on_environment_interface (unsigned cmd, gpointer data) {
 
 static void on_video_refresh (guint8* data, guint width, guint height, gsize pitch) {
        RetroCore *self;
-       RetroVideo *video;
+       RetroAvInfo *av_info;
+       gfloat aspect_ratio;
+
+       if (data == NULL)
+               return;
 
        self = retro_core_get_cb_data ();
 
        if (self == NULL)
                g_return_if_reached ();
 
-       video = retro_core_get_video_interface (self);
-
-       if (video == NULL)
-               g_return_if_reached ();
-
-       retro_video_render (video, data, pitch * height, width, height, pitch);
+       av_info = retro_core_get_av_info (self);
+       aspect_ratio = retro_av_info_get_aspect_ratio (av_info);
+       g_signal_emit_by_name (self, "video_output", data, pitch * height, width, height, pitch, 
self->pixel_format, aspect_ratio);
 }
 
 gpointer retro_core_get_module_video_refresh_cb (RetroCore *self) {
diff --git a/retro-gobject/video.vala b/retro-gobject/video.vala
index 2eea082..a6da3cb 100644
--- a/retro-gobject/video.vala
+++ b/retro-gobject/video.vala
@@ -45,45 +45,4 @@ public enum PixelFormat {
        UNKNOWN = -1;
 }
 
-/**
- * An interface to render a {@link Core}'s video.
- */
-public interface Video : Object {
-       /**
-        * The core to handle video from.
-        */
-       public abstract Core core { get; set; }
-
-       /**
-        * Ask to render video.
-        */
-       public abstract void render (uint8[] data, uint width, uint height, size_t pitch);
-
-       /**
-        * The rotation of the image sent to {@link render}.
-        *
-        * It will be set by the {@link core}.
-        */
-       public abstract Rotation rotation { get; set; }
-
-       /**
-        * Ask the core to render with overscan or not.
-        */
-       public abstract bool overscan { get; set; }
-
-       /**
-        * Warn the {@link core} that it can dupe frames.
-        *
-        * If it does so, the data passed to {@link render} may be //null//.
-        */
-       public abstract bool can_dupe { get; set; }
-
-       /**
-        * The pixel format of the data sent to {@link render}.
-        *
-        * It will be set by the {@link core}.
-        */
-       public abstract PixelFormat pixel_format { get; set; }
-}
-
 }
diff --git a/retro-gtk/video/cairo-display.vala b/retro-gtk/video/cairo-display.vala
index d8f11fd..c8a7843 100644
--- a/retro-gtk/video/cairo-display.vala
+++ b/retro-gtk/video/cairo-display.vala
@@ -1,28 +1,11 @@
 // This file is part of RetroGtk. License: GPLv3
 
-public class RetroGtk.CairoDisplay : Gtk.DrawingArea, Retro.Video {
-       private Retro.Core _core;
-       public Retro.Core core {
-               get { return _core; }
-               set {
-                       if (value == core)
-                               return;
-
-                       _core = value;
-                       pixel_format = Retro.PixelFormat.ORGB1555;
-
-                       if (core != null && core.video_interface != this)
-                               core.video_interface = this;
-               }
-       }
-
+public class RetroGtk.CairoDisplay : Gtk.DrawingArea {
        public Gdk.Pixbuf pixbuf { set; get; }
 
-       public Retro.Rotation rotation { get; set; default = Retro.Rotation.NONE; }
-       public bool overscan { get; set; default = false; }
-       public bool can_dupe { get; set; default = true; }
-       public Retro.PixelFormat pixel_format { get; set; default = Retro.PixelFormat.ORGB1555; }
-
+       private Retro.Core core;
+       private ulong on_video_output_id;
+       private float aspect_ratio;
        private bool show_surface;
 
        construct {
@@ -35,10 +18,16 @@ public class RetroGtk.CairoDisplay : Gtk.DrawingArea, Retro.Video {
        [CCode (cname = "video_to_pixbuf", cheader_filename="video-converter.h")]
        static extern Gdk.Pixbuf video_to_pixbuf ([CCode (array_length = false)] uint8[] data, uint width, 
uint height, size_t pitch, Retro.PixelFormat pixel_format);
 
-       public void render (uint8[] data, uint width, uint height, size_t pitch) {
-               if (data == null)
-                       return; // Dupe a frame
+       public void set_core (Retro.Core core) {
+               if (this.core != null)
+                       this.core.disconnect (on_video_output_id);
+
+               this.core = core;
+               on_video_output_id = core.video_output.connect (on_video_output);
+       }
 
+       private void on_video_output (uint8[] data, uint width, uint height, size_t pitch, Retro.PixelFormat 
pixel_format, float aspect_ratio) {
+               this.aspect_ratio = aspect_ratio;
                pixbuf = video_to_pixbuf (data, width, height, pitch, pixel_format);
        }
 
@@ -91,7 +80,7 @@ public class RetroGtk.CairoDisplay : Gtk.DrawingArea, Retro.Video {
                var h = (double) get_allocated_height ();
 
                // Set the size of the display
-               double display_ratio = (double) core.av_info.aspect_ratio;
+               double display_ratio = (double) aspect_ratio;
                double allocated_ratio = w / h;
 
                // If the screen is wider than the video...


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