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

index 73ac408..2ffa915 100644 (file)
 GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
 GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
 
+enum
+{
+  PROP_0,
+  PROP_INSTANCE,
+};
+
 static void gst_vulkan_device_finalize (GObject * object);
 
 struct _GstVulkanDevicePrivate
@@ -75,11 +81,13 @@ G_DEFINE_TYPE_WITH_CODE (GstVulkanDevice, gst_vulkan_device, GST_TYPE_OBJECT,
 GstVulkanDevice *
 gst_vulkan_device_new (GstVulkanInstance * instance)
 {
-  GstVulkanDevice *device = g_object_new (GST_TYPE_VULKAN_DEVICE, NULL);
+  GstVulkanDevice *device;
+
+  g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), NULL);
 
+  device = g_object_new (GST_TYPE_VULKAN_DEVICE, "instance", instance, NULL);
   gst_object_ref_sink (device);
 
-  device->instance = gst_object_ref (instance);
   /* FIXME: select this externally */
   device->device_index = 0;
 
@@ -87,6 +95,38 @@ gst_vulkan_device_new (GstVulkanInstance * instance)
 }
 
 static void
+gst_vulkan_device_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstVulkanDevice *device = GST_VULKAN_DEVICE (object);
+
+  switch (prop_id) {
+    case PROP_INSTANCE:
+      device->instance = g_value_dup_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_vulkan_device_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstVulkanDevice *device = GST_VULKAN_DEVICE (object);
+
+  switch (prop_id) {
+    case PROP_INSTANCE:
+      g_value_set_object (value, device->instance);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
 gst_vulkan_device_init (GstVulkanDevice * device)
 {
   device->priv = gst_vulkan_device_get_instance_private (device);
@@ -97,7 +137,15 @@ gst_vulkan_device_class_init (GstVulkanDeviceClass * device_class)
 {
   GObjectClass *gobject_class = (GObjectClass *) device_class;
 
+  gobject_class->set_property = gst_vulkan_device_set_property;
+  gobject_class->get_property = gst_vulkan_device_get_property;
   gobject_class->finalize = gst_vulkan_device_finalize;
+
+  g_object_class_install_property (gobject_class, PROP_INSTANCE,
+      g_param_spec_object ("instance", "Instance",
+          "Associated Vulkan Instance",
+          GST_TYPE_VULKAN_INSTANCE,
+          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 }
 
 static void
diff --git a/tests/check/libs/vkdevice.c b/tests/check/libs/vkdevice.c
new file mode 100644 (file)
index 0000000..9433536
--- /dev/null
@@ -0,0 +1,80 @@
+/* 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 GstVulkanInstance *instance;
+
+static void
+setup (void)
+{
+  instance = gst_vulkan_instance_new ();
+  fail_unless (gst_vulkan_instance_open (instance, NULL));
+}
+
+static void
+teardown (void)
+{
+  gst_object_unref (instance);
+}
+
+GST_START_TEST (test_device_new)
+{
+  GstVulkanDevice *device;
+  GstVulkanInstance *dev_instance;
+
+  device = gst_vulkan_device_new (instance);
+  g_object_get (device, "instance", &dev_instance, NULL);
+  fail_unless (dev_instance == instance);
+  gst_object_unref (dev_instance);
+  gst_object_unref (device);
+}
+
+GST_END_TEST;
+
+static Suite *
+vkdevice_suite (void)
+{
+  Suite *s = suite_create ("vkdevice");
+  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_device_new);
+  }
+
+  return s;
+}
+
+
+GST_CHECK_MAIN (vkdevice);
index 91d1bc8..4b001d7 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/vkdevice.c'], not gstvulkan_dep.found(), [gstvulkan_dep]],
 ]
 
 # FIXME: unistd dependency, unstable or not tested yet on windows