[gtk+] wayland: Add support for Vulkan renderer



commit 3887548d554e3151a5997f81f8657e97b5a2a34d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jan 3 21:14:31 2017 -0200

    wayland: Add support for Vulkan renderer
    
    Mirror what's done with the X11 Vulkan renderer implementation,
    with the addition of the extra Wayland window synchronization on
    end_paint() override.

 gdk/wayland/Makefile.am                |    2 +
 gdk/wayland/gdkdisplay-wayland.c       |    9 +++
 gdk/wayland/gdkvulkancontext-wayland.c |   90 ++++++++++++++++++++++++++++++++
 gdk/wayland/gdkvulkancontext-wayland.h |   61 +++++++++++++++++++++
 4 files changed, 162 insertions(+), 0 deletions(-)
---
diff --git a/gdk/wayland/Makefile.am b/gdk/wayland/Makefile.am
index 127e091..d4983cf 100644
--- a/gdk/wayland/Makefile.am
+++ b/gdk/wayland/Makefile.am
@@ -56,6 +56,8 @@ libgdk_wayland_la_SOURCES =                   \
        gdkscreen-wayland.c                     \
        gdkseat-wayland.h                       \
        gdkselection-wayland.c                  \
+       gdkvulkancontext-wayland.c              \
+       gdkvulkancontext-wayland.h              \
        gdkwindow-wayland.c                     \
        gdkwayland.h                            \
        gdkprivate-wayland.h                    \
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 3486748..d1f6e4e 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -17,6 +17,8 @@
 
 #include "config.h"
 
+#define VK_USE_PLATFORM_WAYLAND_KHR
+
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -41,6 +43,7 @@
 #include "gdkkeysprivate.h"
 #include "gdkprivate-wayland.h"
 #include "gdkglcontext-wayland.h"
+#include "gdkvulkancontext-wayland.h"
 #include "gdkwaylandmonitor.h"
 #include "pointer-gestures-unstable-v1-client-protocol.h"
 #include "tablet-unstable-v2-client-protocol.h"
@@ -918,6 +921,12 @@ gdk_wayland_display_class_init (GdkWaylandDisplayClass *class)
   object_class->finalize = gdk_wayland_display_finalize;
 
   display_class->window_type = gdk_wayland_window_get_type ();
+
+#ifdef GDK_RENDERING_VULKAN
+  display_class->vk_context_type = GDK_TYPE_WAYLAND_VULKAN_CONTEXT;
+  display_class->vk_extension_name = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
+#endif
+
   display_class->get_name = gdk_wayland_display_get_name;
   display_class->get_default_screen = gdk_wayland_display_get_default_screen;
   display_class->beep = gdk_wayland_display_beep;
diff --git a/gdk/wayland/gdkvulkancontext-wayland.c b/gdk/wayland/gdkvulkancontext-wayland.c
new file mode 100644
index 0000000..050debf
--- /dev/null
+++ b/gdk/wayland/gdkvulkancontext-wayland.c
@@ -0,0 +1,90 @@
+/* gdkvulkancontext-wayland.c
+ *
+ * gdkvulkancontext-wayland.c: Wayland specific Vulkan wrappers
+ *
+ * Copyright (C) 2017 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gdkconfig.h"
+
+#ifdef GDK_RENDERING_VULKAN
+
+#include "gdkvulkancontext-wayland.h"
+
+#include "gdkinternals.h"
+#include "gdkwaylanddisplay.h"
+#include "gdkwaylandwindow.h"
+#include "gdkprivate-wayland.h"
+
+G_DEFINE_TYPE (GdkWaylandVulkanContext, gdk_wayland_vulkan_context, GDK_TYPE_VULKAN_CONTEXT)
+
+static VkResult
+gdk_wayland_vulkan_context_create_surface (GdkVulkanContext *context,
+                                           VkSurfaceKHR     *surface)
+{
+  GdkWindow *window = gdk_draw_context_get_window (GDK_DRAW_CONTEXT (context));
+  GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
+
+  /* This is necessary so that Vulkan sees the Window.
+   * Usually, vkCreateXlibSurfaceKHR() will not cause a problem to happen as
+   * it just creates resources, but futher calls with the resulting surface
+   * do cause issues.
+   */
+  gdk_display_sync (display);
+
+  return GDK_VK_CHECK (vkCreateWaylandSurfaceKHR, gdk_vulkan_context_get_instance (context),
+                                                   &(VkWaylandSurfaceCreateInfoKHR) {
+                                                       VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
+                                                       NULL,
+                                                       0,
+                                                       gdk_wayland_display_get_wl_display (display),
+                                                       gdk_wayland_window_get_wl_surface (window)
+                                                   },
+                                                   NULL,
+                                                   surface);
+}
+
+static void
+gdk_vulkan_context_wayland_end_frame (GdkDrawContext *context,
+                                      cairo_region_t *painted,
+                                      cairo_region_t *damage)
+{
+  GdkWindow *window = gdk_draw_context_get_window (GDK_DRAW_CONTEXT (context));
+
+  GDK_DRAW_CONTEXT_CLASS (gdk_wayland_vulkan_context_parent_class)->end_frame (context, painted, damage);
+
+  gdk_wayland_window_sync (window);
+}
+
+static void
+gdk_wayland_vulkan_context_class_init (GdkWaylandVulkanContextClass *klass)
+{
+  GdkVulkanContextClass *vulkan_context_class = GDK_VULKAN_CONTEXT_CLASS (klass);
+  GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass);
+
+  vulkan_context_class->create_surface = gdk_wayland_vulkan_context_create_surface;
+  draw_context_class->end_frame = gdk_vulkan_context_wayland_end_frame;
+}
+
+static void
+gdk_wayland_vulkan_context_init (GdkWaylandVulkanContext *self)
+{
+}
+
+#endif /* GDK_RENDERING_VULKAN */
+
diff --git a/gdk/wayland/gdkvulkancontext-wayland.h b/gdk/wayland/gdkvulkancontext-wayland.h
new file mode 100644
index 0000000..c9a0d9d
--- /dev/null
+++ b/gdk/wayland/gdkvulkancontext-wayland.h
@@ -0,0 +1,61 @@
+/* gdkvulkancontext-wayland.h
+ *
+ * gdkvulkancontext-wayland.h: Wayland specific Vulkan wrappers
+ *
+ * Copyright (C) 2017 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GDK_WAYLAND_VULKAN_CONTEXT__
+#define __GDK_WAYLAND_VULKAN_CONTEXT__
+
+#include "gdkconfig.h"
+
+#ifdef GDK_RENDERING_VULKAN
+
+#define VK_USE_PLATFORM_WAYLAND_KHR
+
+#include "gdkvulkancontextprivate.h"
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_WAYLAND_VULKAN_CONTEXT                (gdk_wayland_vulkan_context_get_type ())
+#define GDK_WAYLAND_VULKAN_CONTEXT(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GDK_TYPE_WAYLAND_VULKAN_CONTEXT, GdkWaylandVulkanContext))
+#define GDK_IS_WAYLAND_VULKAN_CONTEXT(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GDK_TYPE_WAYLAND_VULKAN_CONTEXT))
+#define GDK_WAYLAND_VULKAN_CONTEXT_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), 
GDK_TYPE_WAYLAND_VULKAN_CONTEXT, GdkWaylandVulkanContextClass))
+#define GDK_IS_WAYLAND_VULKAN_CONTEXT_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GDK_TYPE_WAYLAND_VULKAN_CONTEXT))
+#define GDK_WAYLAND_VULKAN_CONTEXT_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GDK_TYPE_WAYLAND_VULKAN_CONTEXT, GdkWaylandVulkanContextClass))
+
+typedef struct _GdkWaylandVulkanContext GdkWaylandVulkanContext;
+typedef struct _GdkWaylandVulkanContextClass GdkWaylandVulkanContextClass;
+
+struct _GdkWaylandVulkanContext
+{
+  GdkVulkanContext parent_instance;
+};
+
+struct _GdkWaylandVulkanContextClass
+{
+  GdkVulkanContextClass parent_class;
+};
+
+GDK_AVAILABLE_IN_3_90
+GType gdk_wayland_vulkan_context_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* !GDK_RENDERING_VULKAN */
+
+#endif /* __GDK_WAYLAND_VULKAN_CONTEXT__ */


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