[gtk+/wip/matthiasc/text-node] Per-glyph instance for color text as well



commit 5e87f96aaf818140c6e5ae27dc8006678db06910
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 10 13:44:43 2017 -0400

    Per-glyph instance for color text as well

 gsk/gskvulkancolortextpipeline.c        |   61 ++++++++++++++++++++++++-------
 gsk/gskvulkancolortextpipelineprivate.h |   11 +++++-
 gsk/gskvulkanrenderpass.c               |   12 +++++--
 3 files changed, 66 insertions(+), 18 deletions(-)
---
diff --git a/gsk/gskvulkancolortextpipeline.c b/gsk/gskvulkancolortextpipeline.c
index 43ce7eb..c2614bd 100644
--- a/gsk/gskvulkancolortextpipeline.c
+++ b/gsk/gskvulkancolortextpipeline.c
@@ -85,26 +85,61 @@ gsk_vulkan_color_text_pipeline_new (GskVulkanPipelineLayout *layout,
 }
 
 gsize
-gsk_vulkan_color_text_pipeline_count_vertex_data (GskVulkanColorTextPipeline *pipeline)
+gsk_vulkan_color_text_pipeline_count_vertex_data (GskVulkanColorTextPipeline *pipeline,
+                                                  int                         num_instances)
 {
-  return sizeof (GskVulkanColorTextInstance);
+  return sizeof (GskVulkanColorTextInstance) * num_instances;
 }
 
 void
 gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *pipeline,
                                                     guchar                     *data,
-                                                    const graphene_rect_t      *rect)
+                                                    GskVulkanRenderer          *renderer,
+                                                    const graphene_rect_t      *rect,
+                                                    PangoFont                  *font,
+                                                    PangoGlyphString           *glyphs,
+                                                    float                       x,
+                                                    float                       y)
 {
-  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;
+  GskVulkanColorTextInstance *instances = (GskVulkanColorTextInstance *) data;
+  int i, count;
+  int x_position = 0;
+  float ink_rect_y;
+  float ink_rect_height;
+
+  /* XXX */
+  ink_rect_y = rect->origin.y - y;
+  ink_rect_height = rect->size.height;
+
+  count = 0;
+  for (i = 0; i < glyphs->num_glyphs; i++)
+    {
+      PangoGlyphInfo *gi = &glyphs->glyphs[i];
+
+      if (gi->glyph != PANGO_GLYPH_EMPTY)
+        {
+          double cx = (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
+          double cy = (double)(gi->geometry.y_offset) / PANGO_SCALE;
+
+          if (!(gi->glyph & PANGO_GLYPH_UNKNOWN_FLAG))
+            {
+              GskVulkanColorTextInstance *instance = &instances[count];
+
+              instance->rect[0] = x + cx;
+              instance->rect[1] = y + ink_rect_y + cy;
+              instance->rect[2] = (float)gi->geometry.width / PANGO_SCALE;
+              instance->rect[3] = ink_rect_height;
+              gsk_vulkan_renderer_get_glyph_coords (renderer, font, glyphs,
+                                                    gi->glyph,
+                                                    &instance->tex_rect[0],
+                                                    &instance->tex_rect[1],
+                                                    &instance->tex_rect[2],
+                                                    &instance->tex_rect[3]);
+              count++;
+           }
+       }
+     x_position += gi->geometry.width;
+   }
 }
 
 gsize
diff --git a/gsk/gskvulkancolortextpipelineprivate.h b/gsk/gskvulkancolortextpipelineprivate.h
index c8a381b..b341abd 100644
--- a/gsk/gskvulkancolortextpipelineprivate.h
+++ b/gsk/gskvulkancolortextpipelineprivate.h
@@ -4,6 +4,7 @@
 #include <graphene.h>
 
 #include "gskvulkanpipelineprivate.h"
+#include "gskvulkanrendererprivate.h"
 
 G_BEGIN_DECLS
 
@@ -17,10 +18,16 @@ GskVulkanPipeline *     gsk_vulkan_color_text_pipeline_new                   (Gs
                                                                               const char                     
*shader_name,
                                                                               VkRenderPass                   
 render_pass);
 
-gsize                   gsk_vulkan_color_text_pipeline_count_vertex_data     (GskVulkanColorTextPipeline     
*pipeline);
+gsize                   gsk_vulkan_color_text_pipeline_count_vertex_data     (GskVulkanColorTextPipeline     
*pipeline,
+                                                                              int                            
 num_instances);
 void                    gsk_vulkan_color_text_pipeline_collect_vertex_data   (GskVulkanColorTextPipeline     
*pipeline,
                                                                               guchar                         
*data,
-                                                                              const graphene_rect_t          
*rect);
+                                                                              GskVulkanRenderer              
*renderer,
+                                                                              const graphene_rect_t          
*rect,
+                                                                              PangoFont                      
*font,
+                                                                              PangoGlyphString               
*glyphs,
+                                                                              float                          
 x,
+                                                                              float                          
 y);
 gsize                   gsk_vulkan_color_text_pipeline_draw                  (GskVulkanColorTextPipeline     
*pipeline,
                                                                               VkCommandBuffer                
 command_buffer,
                                                                               gsize                          
 offset,
diff --git a/gsk/gskvulkanrenderpass.c b/gsk/gskvulkanrenderpass.c
index ab8b668..0752b85 100644
--- a/gsk/gskvulkanrenderpass.c
+++ b/gsk/gskvulkanrenderpass.c
@@ -692,7 +692,8 @@ gsk_vulkan_render_pass_count_vertex_data (GskVulkanRenderPass *self)
           break;
 
         case GSK_VULKAN_OP_COLOR_TEXT:
-          op->render.vertex_count = gsk_vulkan_color_text_pipeline_count_vertex_data 
(GSK_VULKAN_COLOR_TEXT_PIPELINE (op->render.pipeline));
+          op->render.vertex_count = gsk_vulkan_color_text_pipeline_count_vertex_data 
(GSK_VULKAN_COLOR_TEXT_PIPELINE (op->render.pipeline),
+                                                                                      
pango_glyph_string_num_glyphs (gsk_text_node_get_glyphs (op->render.node)));
           n_bytes += op->render.vertex_count;
           break;
 
@@ -791,7 +792,12 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
             op->render.vertex_offset = offset + n_bytes;
             gsk_vulkan_color_text_pipeline_collect_vertex_data (GSK_VULKAN_COLOR_TEXT_PIPELINE 
(op->render.pipeline),
                                                                 data + n_bytes + offset,
-                                                                &op->render.node->bounds);
+                                                                GSK_VULKAN_RENDERER 
(gsk_vulkan_render_get_renderer (render)),
+                                                                &op->render.node->bounds,
+                                                                gsk_text_node_get_font (op->render.node),
+                                                                gsk_text_node_get_glyphs (op->render.node),
+                                                                gsk_text_node_get_x (op->render.node),
+                                                                gsk_text_node_get_y (op->render.node));
             n_bytes += op->render.vertex_count;
           }
           break;
@@ -1079,7 +1085,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
 
           current_draw_index += gsk_vulkan_color_text_pipeline_draw (GSK_VULKAN_COLOR_TEXT_PIPELINE 
(current_pipeline),
                                                                      command_buffer,
-                                                                     current_draw_index, 1);
+                                                                     current_draw_index, 
pango_glyph_string_num_glyphs (gsk_text_node_get_glyphs (op->render.node)));
           break;
 
         case GSK_VULKAN_OP_OPACITY:


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