[gtk+/wip/matthiasc/text-node] Add a color text pipeline



commit 0152a4b30990e8b93a0a383e1e6c9431cc919954
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 10 08:01:03 2017 -0400

    Add a color text pipeline
    
    For now, this will be just the same as the blend pipeline,
    but it will eventually do per-glyph instances.

 gsk/gskvulkancolortextpipeline.c        |  121 +++++++++++++++++++++++++++++++
 gsk/gskvulkancolortextpipelineprivate.h |   31 ++++++++
 gsk/gskvulkanrender.c                   |    3 +
 gsk/gskvulkanrenderprivate.h            |    3 +
 gsk/meson.build                         |    1 +
 5 files changed, 159 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskvulkancolortextpipeline.c b/gsk/gskvulkancolortextpipeline.c
new file mode 100644
index 0000000..43ce7eb
--- /dev/null
+++ b/gsk/gskvulkancolortextpipeline.c
@@ -0,0 +1,121 @@
+#include "config.h"
+
+#include "gskvulkancolortextpipelineprivate.h"
+
+struct _GskVulkanColorTextPipeline
+{
+  GObject parent_instance;
+};
+
+typedef struct _GskVulkanColorTextInstance GskVulkanColorTextInstance;
+
+struct _GskVulkanColorTextInstance
+{
+  float rect[4];
+  float tex_rect[4];
+};
+
+G_DEFINE_TYPE (GskVulkanColorTextPipeline, gsk_vulkan_color_text_pipeline, GSK_TYPE_VULKAN_PIPELINE)
+
+static const VkPipelineVertexInputStateCreateInfo *
+gsk_vulkan_color_text_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
+{
+  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
+      {
+          .binding = 0,
+          .stride = sizeof (GskVulkanColorTextInstance),
+          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
+      }
+  };
+  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
+      {
+          .location = 0,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanColorTextInstance, rect),
+      },
+      {
+          .location = 1,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanColorTextInstance, tex_rect),
+      },
+  };
+  static const VkPipelineVertexInputStateCreateInfo info = {
+      .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+      .vertexBindingDescriptionCount = G_N_ELEMENTS (vertexBindingDescriptions),
+      .pVertexBindingDescriptions = vertexBindingDescriptions,
+      .vertexAttributeDescriptionCount = G_N_ELEMENTS (vertexInputAttributeDescription),
+      .pVertexAttributeDescriptions = vertexInputAttributeDescription
+  };
+
+  return &info;
+}
+
+static void
+gsk_vulkan_color_text_pipeline_finalize (GObject *gobject)
+{
+  //GskVulkanColorTextPipeline *self = GSK_VULKAN_COLOR_TEXT_PIPELINE (gobject);
+
+  G_OBJECT_CLASS (gsk_vulkan_color_text_pipeline_parent_class)->finalize (gobject);
+}
+
+static void
+gsk_vulkan_color_text_pipeline_class_init (GskVulkanColorTextPipelineClass *klass)
+{
+  GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
+
+  G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_color_text_pipeline_finalize;
+
+  pipeline_class->get_input_state_create_info = gsk_vulkan_color_text_pipeline_get_input_state_create_info;
+}
+
+static void
+gsk_vulkan_color_text_pipeline_init (GskVulkanColorTextPipeline *self)
+{
+}
+
+GskVulkanPipeline *
+gsk_vulkan_color_text_pipeline_new (GskVulkanPipelineLayout *layout,
+                                    const char              *shader_name,
+                                    VkRenderPass             render_pass)
+{
+  return gsk_vulkan_pipeline_new_full (GSK_TYPE_VULKAN_COLOR_TEXT_PIPELINE, layout, shader_name, render_pass,
+                                       VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
+}
+
+gsize
+gsk_vulkan_color_text_pipeline_count_vertex_data (GskVulkanColorTextPipeline *pipeline)
+{
+  return sizeof (GskVulkanColorTextInstance);
+}
+
+void
+gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *pipeline,
+                                                    guchar                     *data,
+                                                    const graphene_rect_t      *rect)
+{
+  GskVulkanColorTextInstance *instance = (GskVulkanColorTextInstance *) data;
+
+  instance->rect[0] = rect->origin.x;
+  instance->rect[1] = rect->origin.y;
+  instance->rect[2] = rect->size.width;
+  instance->rect[3] = rect->size.height;
+  instance->tex_rect[0] = 0.0;
+  instance->tex_rect[1] = 0.0;
+  instance->tex_rect[2] = 1.0;
+  instance->tex_rect[3] = 1.0;
+}
+
+gsize
+gsk_vulkan_color_text_pipeline_draw (GskVulkanColorTextPipeline *pipeline,
+                                     VkCommandBuffer             command_buffer,
+                                     gsize                       offset,
+                                     gsize                       n_commands)
+{
+  vkCmdDraw (command_buffer,
+             6, n_commands,
+             0, offset);
+
+  return n_commands;
+}
diff --git a/gsk/gskvulkancolortextpipelineprivate.h b/gsk/gskvulkancolortextpipelineprivate.h
new file mode 100644
index 0000000..c8a381b
--- /dev/null
+++ b/gsk/gskvulkancolortextpipelineprivate.h
@@ -0,0 +1,31 @@
+#ifndef __GSK_VULKAN_COLOR_TEXT_PIPELINE_PRIVATE_H__
+#define __GSK_VULKAN_COLOR_TEXT_PIPELINE_PRIVATE_H__
+
+#include <graphene.h>
+
+#include "gskvulkanpipelineprivate.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GskVulkanColorTextPipelineLayout GskVulkanColorTextPipelineLayout;
+
+#define GSK_TYPE_VULKAN_COLOR_TEXT_PIPELINE (gsk_vulkan_color_text_pipeline_get_type ())
+
+G_DECLARE_FINAL_TYPE (GskVulkanColorTextPipeline, gsk_vulkan_color_text_pipeline, GSK, 
VULKAN_COLOR_TEXT_PIPELINE, GskVulkanPipeline)
+
+GskVulkanPipeline *     gsk_vulkan_color_text_pipeline_new                   (GskVulkanPipelineLayout        
*layout,
+                                                                              const char                     
*shader_name,
+                                                                              VkRenderPass                   
 render_pass);
+
+gsize                   gsk_vulkan_color_text_pipeline_count_vertex_data     (GskVulkanColorTextPipeline     
*pipeline);
+void                    gsk_vulkan_color_text_pipeline_collect_vertex_data   (GskVulkanColorTextPipeline     
*pipeline,
+                                                                              guchar                         
*data,
+                                                                              const graphene_rect_t          
*rect);
+gsize                   gsk_vulkan_color_text_pipeline_draw                  (GskVulkanColorTextPipeline     
*pipeline,
+                                                                              VkCommandBuffer                
 command_buffer,
+                                                                              gsize                          
 offset,
+                                                                              gsize                          
 n_commands);
+
+G_END_DECLS
+
+#endif /* __GSK_VULKAN_COLOR_TEXT_PIPELINE_PRIVATE_H__ */
diff --git a/gsk/gskvulkanrender.c b/gsk/gskvulkanrender.c
index 2f2ec4a..83d1f14 100644
--- a/gsk/gskvulkanrender.c
+++ b/gsk/gskvulkanrender.c
@@ -348,6 +348,9 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender       *self,
     { "mask", gsk_vulkan_text_pipeline_new },
     { "mask-clip", gsk_vulkan_text_pipeline_new },
     { "mask-clip-rounded", gsk_vulkan_text_pipeline_new },
+    { "blend", gsk_vulkan_color_text_pipeline_new },
+    { "blend-clip", gsk_vulkan_color_text_pipeline_new },
+    { "blend-clip-rounded", gsk_vulkan_color_text_pipeline_new },
   };
 
   g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL);
diff --git a/gsk/gskvulkanrenderprivate.h b/gsk/gskvulkanrenderprivate.h
index 7900d13..f372282 100644
--- a/gsk/gskvulkanrenderprivate.h
+++ b/gsk/gskvulkanrenderprivate.h
@@ -37,6 +37,9 @@ typedef enum {
   GSK_VULKAN_PIPELINE_TEXT,
   GSK_VULKAN_PIPELINE_TEXT_CLIP,
   GSK_VULKAN_PIPELINE_TEXT_CLIP_ROUNDED,
+  GSK_VULKAN_PIPELINE_COLOR_TEXT,
+  GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP,
+  GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP_ROUNDED,
   /* add more */
   GSK_VULKAN_N_PIPELINES
 } GskVulkanPipelineType;
diff --git a/gsk/meson.build b/gsk/meson.build
index ff69b71..6353615 100644
--- a/gsk/meson.build
+++ b/gsk/meson.build
@@ -61,6 +61,7 @@ if have_vulkan
     'gskvulkanbuffer.c',
     'gskvulkanclip.c',
     'gskvulkancolorpipeline.c',
+    'gskvulkancolortextpipeline.c',
     'gskvulkancommandpool.c',
     'gskvulkaneffectpipeline.c',
     'gskvulkanlineargradientpipeline.c',


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