[gtk+/wip/otte/vulkan: 38/42] gsk: Add skeleton for Vulkan renderer
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/vulkan: 38/42] gsk: Add skeleton for Vulkan renderer
- Date: Wed, 30 Nov 2016 18:16:37 +0000 (UTC)
commit e60282e21bb6bb4dff27bdd9f11522fc068fb821
Author: Benjamin Otte <otte redhat com>
Date: Tue Nov 29 16:33:14 2016 +0100
gsk: Add skeleton for Vulkan renderer
The renderer itself obviously doesn't do anything.
gsk/Makefile.am | 10 ++++
gsk/gskrenderer.c | 7 +++
gsk/gskvulkanrenderer.c | 98 ++++++++++++++++++++++++++++++++++++++++
gsk/gskvulkanrendererprivate.h | 24 ++++++++++
4 files changed, 139 insertions(+), 0 deletions(-)
---
diff --git a/gsk/Makefile.am b/gsk/Makefile.am
index b4cf4f6..8a44f87 100644
--- a/gsk/Makefile.am
+++ b/gsk/Makefile.am
@@ -22,6 +22,13 @@ DISTCLEANFILES =
noinst_LTLIBRARIES =
+if HAVE_VULKAN
+gsk_private_vulan_source_h = \
+ gskvulkanrendererprivate.h
+gsk_private_vulkan_source_c = \
+ gskvulkanrenderer.c
+endif
+
gsk_public_source_h = \
gskenums.h \
gskrenderer.h \
@@ -30,6 +37,7 @@ gsk_public_source_h = \
gsktexture.h \
gsktypes.h
gsk_private_source_h = \
+ $(gsk_private_vulkan_source_h) \
gskcairorendererprivate.h \
gskdebugprivate.h \
gskgldriverprivate.h \
@@ -40,6 +48,7 @@ gsk_private_source_h = \
gskrendererprivate.h \
gskrendernodeprivate.h \
gskshaderbuilderprivate.h \
+ gskvulkanrendererprivate.h \
gsktextureprivate.h
gsk_public_source_c = \
gskrenderer.c \
@@ -47,6 +56,7 @@ gsk_public_source_c = \
gskrendernodeiter.c \
gsktexture.c
gsk_private_source_c = \
+ $(gsk_private_vulkan_source_c) \
gskcairorenderer.c \
gskdebug.c \
gskgldriver.c \
diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c
index d6d8b2d..947133f 100644
--- a/gsk/gskrenderer.c
+++ b/gsk/gskrenderer.c
@@ -56,6 +56,9 @@
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/wayland/gdkwayland.h>
#endif
+#ifdef GDK_WINDOWING_VULKAN
+#include "gskvulkanrendererprivate.h"
+#endif
typedef struct
{
@@ -710,6 +713,10 @@ get_renderer_for_env_var (GdkWindow *window)
env_var_type = GSK_TYPE_CAIRO_RENDERER;
else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0)
env_var_type = GSK_TYPE_GL_RENDERER;
+#ifdef GDK_WINDOWING_VULKAN
+ else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0)
+ env_var_type = GSK_TYPE_VULKAN_RENDERER;
+#endif
else
env_var_type = G_TYPE_INVALID;
}
diff --git a/gsk/gskvulkanrenderer.c b/gsk/gskvulkanrenderer.c
new file mode 100644
index 0000000..32fefcd
--- /dev/null
+++ b/gsk/gskvulkanrenderer.c
@@ -0,0 +1,98 @@
+#include "config.h"
+
+#include "gskvulkanrendererprivate.h"
+
+#include "gskdebugprivate.h"
+#include "gskrendererprivate.h"
+#include "gskrendernodeiter.h"
+#include "gskrendernodeprivate.h"
+#include "gsktextureprivate.h"
+
+#ifdef G_ENABLE_DEBUG
+typedef struct {
+ GQuark cpu_time;
+ GQuark gpu_time;
+} ProfileTimers;
+#endif
+
+struct _GskVulkanRenderer
+{
+ GskRenderer parent_instance;
+
+ GdkVulkanContext *vulkan;
+#ifdef G_ENABLE_DEBUG
+ ProfileTimers profile_timers;
+#endif
+};
+
+struct _GskVulkanRendererClass
+{
+ GskRendererClass parent_class;
+};
+
+G_DEFINE_TYPE (GskVulkanRenderer, gsk_vulkan_renderer, GSK_TYPE_RENDERER)
+
+static gboolean
+gsk_vulkan_renderer_realize (GskRenderer *renderer,
+ GdkWindow *window,
+ GError **error)
+{
+ GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
+
+ self->vulkan = gdk_window_create_vulkan_context (window, error);
+ if (self->vulkan == NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void
+gsk_vulkan_renderer_unrealize (GskRenderer *renderer)
+{
+ GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
+
+ g_clear_object (&self->vulkan);
+}
+
+static void
+gsk_vulkan_renderer_render (GskRenderer *renderer,
+ GskRenderNode *root)
+{
+ GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
+#ifdef G_ENABLE_DEBUG
+ GskProfiler *profiler;
+ gint64 cpu_time;
+#endif
+
+#ifdef G_ENABLE_DEBUG
+ profiler = gsk_renderer_get_profiler (renderer);
+ gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
+#endif
+
+#ifdef G_ENABLE_DEBUG
+ cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
+ gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);
+
+ gsk_profiler_push_samples (profiler);
+#endif
+}
+
+static void
+gsk_vulkan_renderer_class_init (GskVulkanRendererClass *klass)
+{
+ GskRendererClass *renderer_class = GSK_RENDERER_CLASS (klass);
+
+ renderer_class->realize = gsk_vulkan_renderer_realize;
+ renderer_class->unrealize = gsk_vulkan_renderer_unrealize;
+ renderer_class->render = gsk_vulkan_renderer_render;
+}
+
+static void
+gsk_vulkan_renderer_init (GskVulkanRenderer *self)
+{
+#ifdef G_ENABLE_DEBUG
+ GskProfiler *profiler = gsk_renderer_get_profiler (GSK_RENDERER (self));
+
+ self->profile_timers.cpu_time = gsk_profiler_add_timer (profiler, "cpu-time", "CPU time", FALSE, TRUE);
+#endif
+}
diff --git a/gsk/gskvulkanrendererprivate.h b/gsk/gskvulkanrendererprivate.h
new file mode 100644
index 0000000..a4a07f4
--- /dev/null
+++ b/gsk/gskvulkanrendererprivate.h
@@ -0,0 +1,24 @@
+#ifndef __GSK_VULKAN_RENDERER_PRIVATE_H__
+#define __GSK_VULKAN_RENDERER_PRIVATE_H__
+
+#include <vulkan/vulkan.h>
+#include <gsk/gskrenderer.h>
+
+G_BEGIN_DECLS
+
+#define GSK_TYPE_VULKAN_RENDERER (gsk_vulkan_renderer_get_type ())
+
+#define GSK_VULKAN_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GSK_TYPE_VULKAN_RENDERER, GskVulkanRenderer))
+#define GSK_IS_VULKAN_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GSK_TYPE_VULKAN_RENDERER))
+#define GSK_VULKAN_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GSK_TYPE_VULKAN_RENDERER, GskVulkanRendererClass))
+#define GSK_IS_VULKAN_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GSK_TYPE_VULKAN_RENDERER))
+#define GSK_VULKAN_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GSK_TYPE_VULKAN_RENDERER, GskVulkanRendererClass))
+
+typedef struct _GskVulkanRenderer GskVulkanRenderer;
+typedef struct _GskVulkanRendererClass GskVulkanRendererClass;
+
+GType gsk_vulkan_renderer_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GSK_VULKAN_RENDERER_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]