vulkan/window: add property for the parent display
authorMatthew Waters <matthew@centricular.com>
Fri, 5 Jul 2019 06:20:05 +0000 (16:20 +1000)
committerMatthew Waters <matthew@centricular.com>
Fri, 5 Jul 2019 06:20:05 +0000 (16:20 +1000)
gst-libs/gst/vulkan/gstvkwindow.c
tests/check/libs/vkwindow.c [new file with mode: 0644]
tests/check/meson.build

index 3eb0361..b7264bb 100644 (file)
@@ -84,6 +84,12 @@ GstVulkanDummyWindow *gst_vulkan_dummy_window_new (void);
 
 enum
 {
+  PROP_0,
+  PROP_DISPLAY,
+};
+
+enum
+{
   SIGNAL_0,
   SIGNAL_CLOSE,
   SIGNAL_DRAW,
@@ -134,6 +140,38 @@ _init_debug (void)
 }
 
 static void
+gst_vulkan_window_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstVulkanWindow *window = GST_VULKAN_WINDOW (object);
+
+  switch (prop_id) {
+    case PROP_DISPLAY:
+      window->display = g_value_dup_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_vulkan_window_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstVulkanWindow *window = GST_VULKAN_WINDOW (object);
+
+  switch (prop_id) {
+    case PROP_DISPLAY:
+      g_value_set_object (value, window->display);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
 gst_vulkan_window_init (GstVulkanWindow * window)
 {
   window->priv = gst_vulkan_window_get_instance_private (window);
@@ -142,6 +180,8 @@ gst_vulkan_window_init (GstVulkanWindow * window)
 static void
 gst_vulkan_window_class_init (GstVulkanWindowClass * klass)
 {
+  GObjectClass *gobject_class = (GObjectClass *) klass;
+
   klass->open = GST_DEBUG_FUNCPTR (gst_vulkan_window_default_open);
   klass->close = GST_DEBUG_FUNCPTR (gst_vulkan_window_default_close);
 
@@ -153,7 +193,14 @@ gst_vulkan_window_class_init (GstVulkanWindowClass * klass)
       g_signal_new ("draw", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
       NULL, NULL, NULL, G_TYPE_NONE, 0);
 
-  G_OBJECT_CLASS (klass)->finalize = gst_vulkan_window_finalize;
+  gobject_class->set_property = gst_vulkan_window_set_property;
+  gobject_class->get_property = gst_vulkan_window_get_property;
+  gobject_class->finalize = gst_vulkan_window_finalize;
+
+  g_object_class_install_property (gobject_class, PROP_DISPLAY,
+      g_param_spec_object ("display", "Display",
+          "Associated Vulkan Display",
+          GST_TYPE_VULKAN_DISPLAY, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
   _init_debug ();
 }
diff --git a/tests/check/libs/vkwindow.c b/tests/check/libs/vkwindow.c
new file mode 100644 (file)
index 0000000..d1012d7
--- /dev/null
@@ -0,0 +1,83 @@
+/* GStreamer
+ *
+ * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gst/check/gstcheck.h>
+#include <gst/vulkan/vulkan.h>
+
+static GstVulkanDisplay *display;
+static GstVulkanInstance *instance;
+
+static void
+setup (void)
+{
+  instance = gst_vulkan_instance_new ();
+  fail_unless (gst_vulkan_instance_open (instance, NULL));
+  display = gst_vulkan_display_new (instance);
+}
+
+static void
+teardown (void)
+{
+  gst_object_unref (display);
+  gst_object_unref (instance);
+}
+
+GST_START_TEST (test_window_new)
+{
+  GstVulkanWindow *window;
+  GstVulkanDisplay *win_display;
+
+  window = gst_vulkan_window_new (display);
+  g_object_get (window, "display", &win_display, NULL);
+  fail_unless (win_display == display);
+  gst_object_unref (win_display);
+  gst_object_unref (window);
+}
+
+GST_END_TEST;
+
+static Suite *
+vkwindow_suite (void)
+{
+  Suite *s = suite_create ("vkwindow");
+  TCase *tc_basic = tcase_create ("general");
+  gboolean have_instance;
+
+  suite_add_tcase (s, tc_basic);
+  tcase_add_checked_fixture (tc_basic, setup, teardown);
+
+  /* FIXME: CI doesn't have a software vulkan renderer (and none exists currently) */
+  instance = gst_vulkan_instance_new ();
+  have_instance = gst_vulkan_instance_open (instance, NULL);
+  gst_object_unref (instance);
+  if (have_instance) {
+    tcase_add_test (tc_basic, test_window_new);
+  }
+
+  return s;
+}
+
+
+GST_CHECK_MAIN (vkwindow);
index 4b001d7..25606df 100644 (file)
@@ -64,6 +64,7 @@ base_tests = [
   [['libs/vp8parser.c'], false, [gstcodecparsers_dep]],
   [['libs/vkmemory.c'], not gstvulkan_dep.found(), [gstvulkan_dep]],
   [['elements/vkcolorconvert.c'], not gstvulkan_dep.found(), [gstvulkan_dep]],
+  [['libs/vkwindow.c'], not gstvulkan_dep.found(), [gstvulkan_dep]],
   [['libs/vkdevice.c'], not gstvulkan_dep.found(), [gstvulkan_dep]],
 ]