[gtk+/wip/otte/vulkan: 5/21] vulkan: Turn GdkVulkanContext into a GdkDrawContext



commit 2496628ce0381769d2265d5161762b73b96f25b5
Author: Benjamin Otte <otte redhat com>
Date:   Mon Nov 28 17:55:46 2016 +0100

    vulkan: Turn GdkVulkanContext into a GdkDrawContext

 gdk/gdkvulkancontext.c         |  151 ++++------------------------------------
 gdk/gdkvulkancontext.h         |    5 --
 gdk/gdkvulkancontextprivate.h  |    5 +-
 gdk/x11/gdkvulkancontext-x11.c |    4 +-
 4 files changed, 19 insertions(+), 146 deletions(-)
---
diff --git a/gdk/gdkvulkancontext.c b/gdk/gdkvulkancontext.c
index 04cad65..3ae9b79 100644
--- a/gdk/gdkvulkancontext.c
+++ b/gdk/gdkvulkancontext.c
@@ -31,27 +31,14 @@
 typedef struct _GdkVulkanContextPrivate GdkVulkanContextPrivate;
 
 struct _GdkVulkanContextPrivate {
-  GdkWindow *window;
-
   VkSurfaceKHR surface;
 };
 
-enum {
-  PROP_0,
-
-  PROP_DISPLAY,
-  PROP_WINDOW,
-
-  LAST_PROP
-};
-
-static GParamSpec *pspecs[LAST_PROP] = { NULL, };
-
 G_DEFINE_QUARK (gdk-vulkan-error-quark, gdk_vulkan_error)
 
 static void gdk_vulkan_context_initable_init (GInitableIface *iface);
 
-G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkVulkanContext, gdk_vulkan_context, G_TYPE_OBJECT,
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkVulkanContext, gdk_vulkan_context, GDK_TYPE_DRAW_CONTEXT,
                                   G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, gdk_vulkan_context_initable_init)
                                   G_ADD_PRIVATE (GdkVulkanContext))
 
@@ -60,57 +47,22 @@ gdk_vulkan_context_dispose (GObject *gobject)
 {
   GdkVulkanContext *context = GDK_VULKAN_CONTEXT (gobject);
   GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
+  GdkDisplay *display;
 
-  gdk_display_unref_vulkan (gdk_vulkan_context_get_display (context));
-
-  g_clear_object (&priv->window);
-
-  G_OBJECT_CLASS (gdk_vulkan_context_parent_class)->dispose (gobject);
-}
-
-static void
-gdk_vulkan_context_set_property (GObject      *gobject,
-                                 guint         prop_id,
-                                 const GValue *value,
-                                 GParamSpec   *pspec)
-{
-  GdkVulkanContext *context = GDK_VULKAN_CONTEXT (gobject);
-  GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
-
-  switch (prop_id)
+  if (priv->surface != VK_NULL_HANDLE)
     {
-    case PROP_WINDOW:
-      priv->window = g_value_dup_object (value);
-      g_assert (priv->window != NULL);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+      vkDestroySurfaceKHR (gdk_vulkan_context_get_instance (context),
+                           priv->surface,
+                           NULL);
+      priv->surface = VK_NULL_HANDLE;
     }
-}
-
-static void
-gdk_vulkan_context_get_property (GObject    *gobject,
-                                 guint       prop_id,
-                                 GValue     *value,
-                                 GParamSpec *pspec)
-{
-  GdkVulkanContext *context = GDK_VULKAN_CONTEXT (gobject);
-  GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
-
-  switch (prop_id)
-    {
-    case PROP_DISPLAY:
-      g_value_set_object (value, gdk_vulkan_context_get_display (context));
-      break;
 
-    case PROP_WINDOW:
-      g_value_set_object (value, priv->window);
-      break;
+  /* display will be unset in gdk_draw_context_dispose() */
+  display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
+  if (display)
+    gdk_display_unref_vulkan (display);
 
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
-    }
+  G_OBJECT_CLASS (gdk_vulkan_context_parent_class)->dispose (gobject);
 }
 
 static void
@@ -118,42 +70,7 @@ gdk_vulkan_context_class_init (GdkVulkanContextClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
-  gobject_class->set_property = gdk_vulkan_context_set_property;
-  gobject_class->get_property = gdk_vulkan_context_get_property;
   gobject_class->dispose = gdk_vulkan_context_dispose;
-
-  /**
-   * GdkVulkanContext:display:
-   *
-   * The #GdkDisplay used to create the #GdkVulkanContext.
-   *
-   * Since: 3.16
-   */
-  pspecs[PROP_DISPLAY] =
-    g_param_spec_object ("display",
-                         P_("Display"),
-                         P_("The GDK display used to create the Vulkan context"),
-                         GDK_TYPE_DISPLAY,
-                         G_PARAM_READABLE |
-                         G_PARAM_STATIC_STRINGS);
-
-  /**
-   * GdkVulkanContext:window:
-   *
-   * The #GdkWindow the gl context is bound to.
-   *
-   * Since: 3.16
-   */
-  pspecs[PROP_WINDOW] =
-    g_param_spec_object ("window",
-                         P_("Window"),
-                         P_("The GDK window bound to the Vulkan context"),
-                         GDK_TYPE_WINDOW,
-                         G_PARAM_READWRITE |
-                         G_PARAM_CONSTRUCT_ONLY |
-                         G_PARAM_STATIC_STRINGS);
-
-  g_object_class_install_properties (gobject_class, LAST_PROP, pspecs);
 }
 
 static void
@@ -169,7 +86,7 @@ gdk_vulkan_context_real_init (GInitable     *initable,
   GdkVulkanContext *context = GDK_VULKAN_CONTEXT (initable);
   GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
 
-  if (!gdk_display_ref_vulkan (gdk_vulkan_context_get_display (context), error))
+  if (!gdk_display_ref_vulkan (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)), error))
     return FALSE;
 
   if (GDK_VULKAN_CONTEXT_GET_CLASS (context)->create_surface (context, &priv->surface) != VK_SUCCESS)
@@ -188,46 +105,6 @@ gdk_vulkan_context_initable_init (GInitableIface *iface)
   iface->init = gdk_vulkan_context_real_init;
 }
 
-/**
- * gdk_vulkan_context_get_display:
- * @context: a #GdkVulkanContext
- *
- * Retrieves the #GdkDisplay the @context is created for
- *
- * Returns: (nullable) (transfer none): a #GdkDisplay or %NULL
- *
- * Since: 3.90
- */
-GdkDisplay *
-gdk_vulkan_context_get_display (GdkVulkanContext *context)
-{
-  GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
-
-  g_return_val_if_fail (GDK_IS_VULKAN_CONTEXT (context), NULL);
-
-  return priv->window ? gdk_window_get_display (priv->window) : NULL;
-}
-
-/**
- * gdk_vulkan_context_get_window:
- * @context: a #GdkVulkanContext
- *
- * Retrieves the #GdkWindow used by the @context.
- *
- * Returns: (nullable) (transfer none): a #GdkWindow or %NULL
- *
- * Since: 3.90
- */
-GdkWindow *
-gdk_vulkan_context_get_window (GdkVulkanContext *context)
-{
-  GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
-
-  g_return_val_if_fail (GDK_IS_VULKAN_CONTEXT (context), NULL);
-
-  return priv->window;
-}
-
 #ifdef GDK_WINDOWING_VULKAN
 
 VkInstance
@@ -235,7 +112,7 @@ gdk_vulkan_context_get_instance (GdkVulkanContext *context)
 {
   g_return_val_if_fail (GDK_IS_VULKAN_CONTEXT (context), NULL);
 
-  return gdk_vulkan_context_get_display (context)->vk_instance;
+  return gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context))->vk_instance;
 }
 
 static gboolean
diff --git a/gdk/gdkvulkancontext.h b/gdk/gdkvulkancontext.h
index ce85903..9441d5f 100644
--- a/gdk/gdkvulkancontext.h
+++ b/gdk/gdkvulkancontext.h
@@ -46,11 +46,6 @@ GQuark gdk_vulkan_error_quark (void);
 GDK_AVAILABLE_IN_3_90
 GType gdk_vulkan_context_get_type (void) G_GNUC_CONST;
 
-GDK_AVAILABLE_IN_3_90
-GdkDisplay *            gdk_vulkan_context_get_display              (GdkVulkanContext  *context);
-GDK_AVAILABLE_IN_3_90
-GdkWindow *             gdk_vulkan_context_get_window               (GdkVulkanContext  *context);
-
 #ifdef GDK_WINDOWING_VULKAN
 
 GDK_AVAILABLE_IN_3_90
diff --git a/gdk/gdkvulkancontextprivate.h b/gdk/gdkvulkancontextprivate.h
index de4ba2f..696295c 100644
--- a/gdk/gdkvulkancontextprivate.h
+++ b/gdk/gdkvulkancontextprivate.h
@@ -23,6 +23,7 @@
 
 #include "gdkvulkancontext.h"
 
+#include "gdkdrawcontextprivate.h"
 #include "gdkinternals.h"
 
 #include <vulkan/vulkan.h>
@@ -37,12 +38,12 @@ typedef struct _GdkVulkanContextClass GdkVulkanContextClass;
 
 struct _GdkVulkanContext
 {
-  GObject parent_instance;
+  GdkDrawContext parent_instance;
 };
 
 struct _GdkVulkanContextClass
 {
-  GObjectClass parent_class;
+  GdkDrawContextClass parent_class;
 
   VkResult     (* create_surface)       (GdkVulkanContext       *context,
                                          VkSurfaceKHR           *surface);
diff --git a/gdk/x11/gdkvulkancontext-x11.c b/gdk/x11/gdkvulkancontext-x11.c
index dc42306..71f27e3 100644
--- a/gdk/x11/gdkvulkancontext-x11.c
+++ b/gdk/x11/gdkvulkancontext-x11.c
@@ -36,8 +36,8 @@ static VkResult
 gdk_x11_vulkan_context_create_surface (GdkVulkanContext *context,
                                        VkSurfaceKHR     *surface)
 {
-  GdkWindow *window = gdk_vulkan_context_get_window (context);
-  GdkDisplay *display = gdk_vulkan_context_get_display (context);
+  GdkWindow *window = gdk_draw_context_get_window (GDK_DRAW_CONTEXT (context));
+  GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
 
   return GDK_VK_CHECK (vkCreateXlibSurfaceKHR, gdk_vulkan_context_get_instance (context),
                                                &(VkXlibSurfaceCreateInfoKHR) {


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