vulkan: Make glyphs use new node ops
authorBenjamin Otte <otte@redhat.com>
Mon, 3 Jul 2023 07:15:04 +0000 (09:15 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 16 Jul 2023 10:13:00 +0000 (12:13 +0200)
This is a rudimentary - but working - port.
Glyph uploads are still using the old machinery, a bunch of functions
still exist that probably aren't necessary anymore and each glyph emits
its own node.

This will need to be improved in further commits.

12 files changed:
gsk/meson.build
gsk/vulkan/gskvulkancolortextpipeline.c [deleted file]
gsk/vulkan/gskvulkancolortextpipelineprivate.h [deleted file]
gsk/vulkan/gskvulkanglyphcache.c
gsk/vulkan/gskvulkanglyphcacheprivate.h
gsk/vulkan/gskvulkanrender.c
gsk/vulkan/gskvulkanrenderer.c
gsk/vulkan/gskvulkanrendererprivate.h
gsk/vulkan/gskvulkanrenderpass.c
gsk/vulkan/gskvulkanrenderprivate.h
gsk/vulkan/gskvulkantextpipeline.c [deleted file]
gsk/vulkan/gskvulkantextpipelineprivate.h [deleted file]

index bfb09d7d0b5ff99aaa97f8b9418b9f3a9b6ac368..c468ff0a15a54bb1bf1c0aae49da964c1f560101 100644 (file)
@@ -114,7 +114,6 @@ if have_vulkan
     'vulkan/gskvulkanclip.c',
     'vulkan/gskvulkancolormatrixop.c',
     'vulkan/gskvulkancolorop.c',
-    'vulkan/gskvulkancolortextpipeline.c',
     'vulkan/gskvulkancommandpool.c',
     'vulkan/gskvulkancrossfadeop.c',
     'vulkan/gskvulkanglyphcache.c',
@@ -132,7 +131,6 @@ if have_vulkan
     'vulkan/gskvulkanrenderer.c',
     'vulkan/gskvulkanrenderpass.c',
     'vulkan/gskvulkanscissorop.c',
-    'vulkan/gskvulkantextpipeline.c',
     'vulkan/gskvulkantextureop.c',
     'vulkan/gskvulkanuploadcairoop.c',
     'vulkan/gskvulkanuploadop.c',
diff --git a/gsk/vulkan/gskvulkancolortextpipeline.c b/gsk/vulkan/gskvulkancolortextpipeline.c
deleted file mode 100644 (file)
index 26b102f..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-#include "config.h"
-
-#include "gskvulkancolortextpipelineprivate.h"
-
-#include "vulkan/resources/texture.vert.h"
-
-struct _GskVulkanColorTextPipeline
-{
-  GObject parent_instance;
-};
-
-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)
-{
-  return &gsk_vulkan_texture_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 (GdkVulkanContext        *context,
-                                    VkPipelineLayout         layout,
-                                    const char              *shader_name,
-                                    VkRenderPass             render_pass)
-{
-  return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_COLOR_TEXT_PIPELINE, context, layout, shader_name, render_pass);
-}
-
-void
-gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *pipeline,
-                                                    guchar                     *data,
-                                                    GskVulkanRenderer          *renderer,
-                                                    const graphene_rect_t      *rect,
-                                                    guint                       tex_id,
-                                                    PangoFont                  *font,
-                                                    guint                       total_glyphs,
-                                                    const PangoGlyphInfo       *glyphs,
-                                                    const graphene_point_t     *offset,
-                                                    guint                       start_glyph,
-                                                    guint                       num_glyphs,
-                                                    float                       scale)
-{
-  GskVulkanTextureInstance *instances = (GskVulkanTextureInstance *) data;
-  int i;
-  int count = 0;
-  int x_position = 0;
-
-  for (i = 0; i < start_glyph; i++)
-    x_position += glyphs[i].geometry.width;
-
-  for (; i < total_glyphs && count < num_glyphs; i++)
-    {
-      const PangoGlyphInfo *gi = &glyphs[i];
-
-      if (gi->glyph != PANGO_GLYPH_EMPTY)
-        {
-          double cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE;
-          double cy = gi->geometry.y_offset / PANGO_SCALE;
-          GskVulkanTextureInstance *instance = &instances[count];
-          GskVulkanCachedGlyph *glyph;
-
-          glyph = gsk_vulkan_renderer_get_cached_glyph (renderer,
-                                                        font,
-                                                        gi->glyph,
-                                                        x_position + gi->geometry.x_offset,
-                                                        gi->geometry.y_offset,
-                                                        scale);
-
-          instance->rect[0] = offset->x + cx + glyph->draw_x;
-          instance->rect[1] = offset->y + cy + glyph->draw_y;
-          instance->rect[2] = glyph->draw_width;
-          instance->rect[3] = glyph->draw_height;
-
-          instance->tex_rect[0] = glyph->tx;
-          instance->tex_rect[1] = glyph->ty;
-          instance->tex_rect[2] = glyph->tw;
-          instance->tex_rect[3] = glyph->th;
-
-          instance->tex_id = tex_id;
-
-          count++;
-       }
-     x_position += gi->geometry.width;
-   }
-}
-
-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/vulkan/gskvulkancolortextpipelineprivate.h b/gsk/vulkan/gskvulkancolortextpipelineprivate.h
deleted file mode 100644 (file)
index 0094398..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include <graphene.h>
-
-#include "gskvulkanpipelineprivate.h"
-#include "gskvulkanrendererprivate.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                   (GdkVulkanContext               *context,
-                                                                              VkPipelineLayout                layout,
-                                                                              const char                     *shader_name,
-                                                                              VkRenderPass                    render_pass);
-
-void                    gsk_vulkan_color_text_pipeline_collect_vertex_data   (GskVulkanColorTextPipeline     *pipeline,
-                                                                              guchar                         *data,
-                                                                              GskVulkanRenderer              *renderer,
-                                                                              const graphene_rect_t          *rect,
-                                                                              guint                           tex_id,
-                                                                              PangoFont                      *font,
-                                                                              guint                           total_glyphs,
-                                                                              const PangoGlyphInfo           *glyphs,
-                                                                              const graphene_point_t         *offset,
-                                                                              guint                           start_glyph,
-                                                                              guint                           num_glyphs,
-                                                                              float                           scale);
-gsize                   gsk_vulkan_color_text_pipeline_draw                  (GskVulkanColorTextPipeline     *pipeline,
-                                                                              VkCommandBuffer                 command_buffer,
-                                                                              gsize                           offset,
-                                                                              gsize                           n_commands);
-
-G_END_DECLS
-
index e2e00912b2feb919635df5609632af75afb072a0..1b5b916f119c608399acff5d4d46e3d3be108d77 100644 (file)
@@ -73,6 +73,8 @@ create_atlas (GskVulkanGlyphCache *cache)
   atlas->num_glyphs = 0;
   atlas->dirty_glyphs = NULL;
 
+  atlas->image = gsk_vulkan_image_new_for_atlas (cache->vulkan, atlas->width, atlas->height);
+
   return atlas;
 }
 
@@ -217,6 +219,7 @@ add_to_cache (GskVulkanGlyphCache  *cache,
       g_ptr_array_add (cache->atlases, atlas);
     }
 
+  value->atlas_image = atlas->image;
   value->atlas_x = atlas->x;
   value->atlas_y = atlas->y0;
 
@@ -225,8 +228,6 @@ add_to_cache (GskVulkanGlyphCache  *cache,
   value->tw = (float)width / atlas->width;
   value->th = (float)height / atlas->height;
 
-  value->texture_index = i;
-
   dirty = g_new (DirtyGlyph, 1);
   dirty->key = key;
   dirty->value = value;
@@ -238,7 +239,7 @@ add_to_cache (GskVulkanGlyphCache  *cache,
   atlas->num_glyphs++;
 
 #ifdef G_ENABLE_DEBUG
-  if (GSK_RENDERER_DEBUG_CHECK (cache->renderer, GLYPH_CACHE))
+  if (GSK_DEBUG_CHECK (GLYPH_CACHE))
     {
       g_print ("Glyph cache:\n");
       for (i = 0; i < cache->atlases->len; i++)
@@ -322,8 +323,7 @@ upload_dirty_glyphs (GskVulkanGlyphCache *cache,
   for (l = atlas->dirty_glyphs, i = 0; l; l = l->next, i++)
     render_glyph (atlas, (DirtyGlyph *)l->data, &regions[i]);
 
-  GSK_RENDERER_DEBUG (cache->renderer, GLYPH_CACHE,
-                      "uploading %d glyphs to cache", num_regions);
+  GSK_DEBUG (GLYPH_CACHE, "uploading %d glyphs to cache", num_regions);
 
   gsk_vulkan_image_upload_regions (atlas->image, uploader, num_regions, regions);
 
@@ -332,13 +332,11 @@ upload_dirty_glyphs (GskVulkanGlyphCache *cache,
 }
 
 GskVulkanGlyphCache *
-gsk_vulkan_glyph_cache_new (GskRenderer      *renderer,
-                            GdkVulkanContext *vulkan)
+gsk_vulkan_glyph_cache_new (GdkVulkanContext *vulkan)
 {
   GskVulkanGlyphCache *cache;
 
   cache = GSK_VULKAN_GLYPH_CACHE (g_object_new (GSK_TYPE_VULKAN_GLYPH_CACHE, NULL));
-  cache->renderer = renderer;
   cache->vulkan = vulkan;
   g_ptr_array_add (cache->atlases, create_atlas (cache));
 
@@ -420,24 +418,20 @@ gsk_vulkan_glyph_cache_lookup (GskVulkanGlyphCache *cache,
   return value;
 }
 
-GskVulkanImage *
-gsk_vulkan_glyph_cache_get_glyph_image (GskVulkanGlyphCache *cache,
-                                        GskVulkanUploader   *uploader,
-                                        guint                index)
+void
+gsk_vulkan_glyph_cache_upload (GskVulkanGlyphCache *cache,
+                               GskVulkanUploader   *uploader)
 {
   Atlas *atlas;
+  guint i;
 
-  g_return_val_if_fail (index < cache->atlases->len, NULL);
-
-  atlas = g_ptr_array_index (cache->atlases, index);
-
-  if (atlas->image == NULL)
-    atlas->image = gsk_vulkan_image_new_for_atlas (cache->vulkan, atlas->width, atlas->height);
-
-  if (atlas->dirty_glyphs)
-    upload_dirty_glyphs (cache, atlas, uploader);
+  for (i = 0; i < cache->atlases->len; i++)
+    {
+      atlas = g_ptr_array_index (cache->atlases, i);
 
-  return atlas->image;
+      if (atlas->dirty_glyphs)
+        upload_dirty_glyphs (cache, atlas, uploader);
+    }
 }
 
 void
@@ -489,9 +483,9 @@ gsk_vulkan_glyph_cache_begin_frame (GskVulkanGlyphCache *cache)
 
       if (atlas->old_pixels > MAX_OLD * atlas->width * atlas->height)
         {
-          GSK_RENDERER_DEBUG (cache->renderer, GLYPH_CACHE,
-                              "Dropping atlas %d (%g.2%% old)",
-                              i, 100.0 * (double)atlas->old_pixels / (double)(atlas->width * atlas->height));
+          GSK_DEBUG (GLYPH_CACHE,
+                     "Dropping atlas %d (%g.2%% old)",
+                     i, 100.0 * (double)atlas->old_pixels / (double)(atlas->width * atlas->height));
           g_ptr_array_remove_index (cache->atlases, i);
 
           drops[i] = 1;
@@ -520,5 +514,5 @@ gsk_vulkan_glyph_cache_begin_frame (GskVulkanGlyphCache *cache)
         }
     }
 
-  GSK_RENDERER_DEBUG (cache->renderer, GLYPH_CACHE, "Dropped %d glyphs", dropped);
+  GSK_DEBUG (GLYPH_CACHE, "Dropped %d glyphs", dropped);
 }
index e7520937b761831aebab82782449e01fc554432c..4d845a6295389ff5b7b44352c7ed6912345322bd 100644 (file)
@@ -1,7 +1,6 @@
 #pragma once
 
 #include <pango/pango.h>
-#include "gskvulkanrendererprivate.h"
 #include "gskvulkanimageprivate.h"
 
 G_BEGIN_DECLS
@@ -10,12 +9,31 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE(GskVulkanGlyphCache, gsk_vulkan_glyph_cache, GSK, VULKAN_GLYPH_CACHE, GObject)
 
-GskVulkanGlyphCache  *gsk_vulkan_glyph_cache_new            (GskRenderer         *renderer,
-                                                             GdkVulkanContext    *vulkan);
+typedef struct
+{
+  guint texture_index;
 
-GskVulkanImage *     gsk_vulkan_glyph_cache_get_glyph_image (GskVulkanGlyphCache *cache,
-                                                             GskVulkanUploader   *uploader,
-                                                             guint                index);
+  float tx;
+  float ty;
+  float tw;
+  float th;
+
+  int draw_x;
+  int draw_y;
+  int draw_width;
+  int draw_height;
+
+  GskVulkanImage *atlas_image;
+  int atlas_x;
+  int atlas_y;
+
+  guint64 timestamp;
+} GskVulkanCachedGlyph;
+
+GskVulkanGlyphCache  *gsk_vulkan_glyph_cache_new            (GdkVulkanContext    *vulkan);
+
+void                  gsk_vulkan_glyph_cache_upload         (GskVulkanGlyphCache *cache,
+                                                             GskVulkanUploader   *uploader);
 
 GskVulkanCachedGlyph *gsk_vulkan_glyph_cache_lookup         (GskVulkanGlyphCache *cache,
                                                              gboolean             create,
index e39d0122bd43c6e2e5b1ca6449fa6515afce248c..9c414db02997b78462a858f15146700baebe98e7 100644 (file)
@@ -7,11 +7,11 @@
 #include "gskrendererprivate.h"
 #include "gskvulkanbufferprivate.h"
 #include "gskvulkancommandpoolprivate.h"
+#include "gskvulkanglyphcacheprivate.h"
 #include "gskvulkanpipelineprivate.h"
+#include "gskvulkanrendererprivate.h"
 #include "gskvulkanrenderpassprivate.h"
 
-#include "gskvulkancolortextpipelineprivate.h"
-#include "gskvulkantextpipelineprivate.h"
 #include "gskvulkanpushconstantsprivate.h"
 
 #include "gdk/gdkvulkancontextprivate.h"
@@ -55,7 +55,6 @@ struct _GskVulkanRender
   GskDescriptorBufferInfos descriptor_buffers;
   VkDescriptorPool descriptor_pool;
   VkDescriptorSet descriptor_sets[N_DESCRIPTOR_SETS];
-  GskVulkanPipeline *pipelines[GSK_VULKAN_N_PIPELINES];
   GHashTable *pipeline_cache;
 
   GskVulkanImage *target;
@@ -354,6 +353,9 @@ gsk_vulkan_render_upload (GskVulkanRender *self)
 {
   GList *l;
 
+  gsk_vulkan_glyph_cache_upload (gsk_vulkan_renderer_get_glyph_cache (GSK_VULKAN_RENDERER (self->renderer)),
+                                 self->uploader);
+
   /* gsk_vulkan_render_pass_upload may call gsk_vulkan_render_add_node_for_texture,
    * prepending new render passes to the list. Therefore, we walk the list from
    * the end.
@@ -486,35 +488,6 @@ gsk_vulkan_render_create_pipeline (GskVulkanRender                            *s
   return pipeline;
 }
 
-GskVulkanPipeline *
-gsk_vulkan_render_get_pipeline (GskVulkanRender       *self,
-                                GskVulkanPipelineType  type,
-                                VkRenderPass           render_pass)
-{
-  static const struct {
-    const char *name;
-    guint num_textures;
-    GskVulkanPipeline * (* create_func) (GdkVulkanContext *context, VkPipelineLayout layout, const char *name, VkRenderPass render_pass);
-  } pipeline_info[GSK_VULKAN_N_PIPELINES] = {
-    { "mask",                       1, gsk_vulkan_text_pipeline_new },
-    { "mask-clip",                  1, gsk_vulkan_text_pipeline_new },
-    { "mask-clip-rounded",          1, gsk_vulkan_text_pipeline_new },
-    { "texture",                    1, gsk_vulkan_color_text_pipeline_new },
-    { "texture-clip",               1, gsk_vulkan_color_text_pipeline_new },
-    { "texture-clip-rounded",       1, gsk_vulkan_color_text_pipeline_new },
-  };
-
-  g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL);
-
-  if (self->pipelines[type] == NULL)
-    self->pipelines[type] = pipeline_info[type].create_func (self->vulkan,
-                                                             self->pipeline_layout,
-                                                             pipeline_info[type].name,
-                                                             render_pass);
-
-  return self->pipelines[type];
-}
-
 void
 gsk_vulkan_render_bind_descriptor_sets (GskVulkanRender *self,
                                         VkCommandBuffer  command_buffer)
@@ -821,9 +794,6 @@ gsk_vulkan_render_free (GskVulkanRender *self)
     }
   g_hash_table_unref (self->pipeline_cache);
 
-  for (i = 0; i < GSK_VULKAN_N_PIPELINES; i++)
-    g_clear_object (&self->pipelines[i]);
-
   g_clear_pointer (&self->uploader, gsk_vulkan_uploader_free);
 
 
index 1de96bbfad5809538a65defbeb65613628eda4be..e7dac98bb58ca4cdc5b023c9d4f0e1e257effe0a 100644 (file)
@@ -222,7 +222,7 @@ gsk_vulkan_renderer_realize (GskRenderer  *renderer,
                     self);
   gsk_vulkan_renderer_update_images_cb (self->vulkan, self);
 
-  self->glyph_cache = gsk_vulkan_glyph_cache_new (renderer, self->vulkan);
+  self->glyph_cache = gsk_vulkan_glyph_cache_new (self->vulkan);
 
   return TRUE;
 }
@@ -477,15 +477,13 @@ gsk_vulkan_renderer_ref_texture_image (GskVulkanRenderer *self,
   return image;
 }
 
-GskVulkanImage *
-gsk_vulkan_renderer_ref_glyph_image (GskVulkanRenderer  *self,
-                                     GskVulkanUploader  *uploader,
-                                     guint               index)
+GskVulkanGlyphCache *
+gsk_vulkan_renderer_get_glyph_cache (GskVulkanRenderer  *self)
 {
-  return g_object_ref (gsk_vulkan_glyph_cache_get_glyph_image (self->glyph_cache, uploader, index));
+  return self->glyph_cache;
 }
 
-guint
+GskVulkanCachedGlyph *
 gsk_vulkan_renderer_cache_glyph (GskVulkanRenderer *self,
                                  PangoFont         *font,
                                  PangoGlyph         glyph,
@@ -493,18 +491,7 @@ gsk_vulkan_renderer_cache_glyph (GskVulkanRenderer *self,
                                  int                y,
                                  float              scale)
 {
-  return gsk_vulkan_glyph_cache_lookup (self->glyph_cache, TRUE, font, glyph, x, y, scale)->texture_index;
-}
-
-GskVulkanCachedGlyph *
-gsk_vulkan_renderer_get_cached_glyph (GskVulkanRenderer *self,
-                                      PangoFont         *font,
-                                      PangoGlyph         glyph,
-                                      int                x,
-                                      int                y,
-                                      float              scale)
-{
-  return gsk_vulkan_glyph_cache_lookup (self->glyph_cache, FALSE, font, glyph, x, y, scale);
+  return gsk_vulkan_glyph_cache_lookup (self->glyph_cache, TRUE, font, glyph, x, y, scale);
 }
 
 /**
index fdebb49235399f122801b450769f8a962e3e0174..dc17f14e8a7303394076561393f725fc95f10dc6 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "gskvulkanrenderer.h"
+#include "gskvulkanglyphcacheprivate.h"
 #include "gskvulkanimageprivate.h"
 
 G_BEGIN_DECLS
@@ -14,43 +15,14 @@ GskVulkanImage *        gsk_vulkan_renderer_ref_texture_image           (GskVulk
                                                                          GdkTexture             *texture,
                                                                          GskVulkanUploader      *uploader);
 
-typedef struct
-{
-  guint texture_index;
-
-  float tx;
-  float ty;
-  float tw;
-  float th;
-
-  int draw_x;
-  int draw_y;
-  int draw_width;
-  int draw_height;
-
-  int atlas_x;
-  int atlas_y;
-
-  guint64 timestamp;
-} GskVulkanCachedGlyph;
-
-guint                  gsk_vulkan_renderer_cache_glyph      (GskVulkanRenderer *renderer,
+GskVulkanCachedGlyph  *gsk_vulkan_renderer_cache_glyph      (GskVulkanRenderer *renderer,
                                                              PangoFont         *font,
                                                              PangoGlyph         glyph,
                                                              int                x,
                                                              int                y,
                                                              float              scale);
 
-GskVulkanImage *       gsk_vulkan_renderer_ref_glyph_image  (GskVulkanRenderer *self,
-                                                             GskVulkanUploader *uploader,
-                                                             guint              index);
-
-GskVulkanCachedGlyph * gsk_vulkan_renderer_get_cached_glyph (GskVulkanRenderer *self,
-                                                             PangoFont         *font,
-                                                             PangoGlyph         glyph,
-                                                             int                x,
-                                                             int                y,
-                                                             float              scale);
+GskVulkanGlyphCache *   gsk_vulkan_renderer_get_glyph_cache             (GskVulkanRenderer      *self);
 
 
 G_END_DECLS
index 4a33d21fd25ce454701695725d45145696f52dcb..74437c13635117616a69a2f2c07eb234debbb135 100644 (file)
 #include "gskvulkanclipprivate.h"
 #include "gskvulkancolormatrixopprivate.h"
 #include "gskvulkancoloropprivate.h"
-#include "gskvulkancolortextpipelineprivate.h"
 #include "gskvulkancrossfadeopprivate.h"
 #include "gskvulkanglyphopprivate.h"
 #include "gskvulkaninsetshadowopprivate.h"
 #include "gskvulkanlineargradientopprivate.h"
 #include "gskvulkanopprivate.h"
 #include "gskvulkanrendererprivate.h"
-#include "gskvulkantextpipelineprivate.h"
 #include "gskvulkanimageprivate.h"
 #include "gskvulkanoffscreenopprivate.h"
 #include "gskvulkanoutsetshadowopprivate.h"
@@ -48,33 +46,13 @@ typedef struct _GskVulkanParseState GskVulkanParseState;
 
 typedef struct _GskVulkanOpAny GskVulkanOpAny;
 typedef union  _GskVulkanOpAll GskVulkanOpAll;
-typedef struct _GskVulkanOpText GskVulkanOpText;
 typedef struct _GskVulkanOpPushConstants GskVulkanOpPushConstants;
 
 typedef enum {
-  /* GskVulkanOpText */
-  GSK_VULKAN_OP_TEXT,
-  GSK_VULKAN_OP_COLOR_TEXT,
   /* GskVulkanOpPushConstants */
   GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS,
 } GskVulkanOpType;
 
-struct _GskVulkanOpText
-{
-  GskVulkanOp          base;
-  GskVulkanOpType      type;
-  GskRenderNode       *node; /* node that's the source of this op */
-  graphene_point_t     offset; /* offset of the node */
-  GskVulkanPipeline   *pipeline; /* pipeline to use */
-  GskVulkanImage      *source; /* source image to render */
-  gsize                vertex_offset; /* offset into vertex buffer */
-  guint32              image_descriptor; /* index into descriptor for the (image, sampler) */
-  guint                texture_index; /* index of the texture in the glyph cache */
-  guint                start_glyph; /* the first glyph in nodes glyphstring that we render */
-  guint                num_glyphs; /* number of *non-empty* glyphs (== instances) we render */
-  float                scale;
-};
-
 struct _GskVulkanOpPushConstants
 {
   GskVulkanOp             base;
@@ -95,7 +73,6 @@ struct _GskVulkanOpAny
 union _GskVulkanOpAll
 {
   GskVulkanOpAny          any;
-  GskVulkanOpText          text;
   GskVulkanOpPushConstants constants;
 };
 
@@ -320,16 +297,6 @@ gsk_vulkan_render_pass_append_push_constants (GskVulkanRenderPass       *self,
   return FALSE; \
 }G_STMT_END
 
-static GskVulkanPipeline *
-gsk_vulkan_render_pass_get_pipeline (GskVulkanRenderPass   *self,
-                                     GskVulkanRender       *render,
-                                     GskVulkanPipelineType  pipeline_type)
-{
-  return gsk_vulkan_render_get_pipeline (render,
-                                         pipeline_type,
-                                         self->render_pass);
-}
-
 static GskVulkanImage *
 gsk_vulkan_render_pass_get_node_as_image (GskVulkanRenderPass       *self,
                                           GskVulkanRender           *render,
@@ -1179,86 +1146,67 @@ gsk_vulkan_render_pass_add_text_node (GskVulkanRenderPass       *self,
                                       const GskVulkanParseState *state,
                                       GskRenderNode             *node)
 {
-  GskVulkanOpText op = {
-    .node = node,
-    .offset = state->offset,
-  };
-  GskVulkanPipelineType pipeline_type;
   const PangoGlyphInfo *glyphs;
   GskVulkanRenderer *renderer;
+  const graphene_point_t *node_offset;
   const PangoFont *font;
-  guint texture_index;
   guint num_glyphs;
-  guint count;
   int x_position;
   int i;
+  float scale;
 
   renderer = GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render));
   num_glyphs = gsk_text_node_get_num_glyphs (node);
   glyphs = gsk_text_node_get_glyphs (node, NULL);
   font = gsk_text_node_get_font (node);
 
-  if (gsk_text_node_has_color_glyphs (node))
-    {
-      if (gsk_vulkan_clip_contains_rect (&state->clip, &state->offset, &node->bounds))
-        pipeline_type = GSK_VULKAN_PIPELINE_COLOR_TEXT;
-      else if (state->clip.type == GSK_VULKAN_CLIP_RECT)
-        pipeline_type = GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP;
-      else
-        pipeline_type = GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP_ROUNDED;
-      op.type = GSK_VULKAN_OP_COLOR_TEXT;
-    }
-  else
-    {
-      if (gsk_vulkan_clip_contains_rect (&state->clip, &state->offset, &node->bounds))
-        pipeline_type = GSK_VULKAN_PIPELINE_TEXT;
-      else if (state->clip.type == GSK_VULKAN_CLIP_RECT)
-        pipeline_type = GSK_VULKAN_PIPELINE_TEXT_CLIP;
-      else
-        pipeline_type = GSK_VULKAN_PIPELINE_TEXT_CLIP_ROUNDED;
-      op.type = GSK_VULKAN_OP_TEXT;
-    }
-  op.pipeline = gsk_vulkan_render_pass_get_pipeline (self, render, pipeline_type);
 
-  op.start_glyph = 0;
-  op.texture_index = G_MAXUINT;
-  op.scale = MAX (graphene_vec2_get_x (&state->scale), graphene_vec2_get_y (&state->scale));
+  scale = MAX (graphene_vec2_get_x (&state->scale), graphene_vec2_get_y (&state->scale));
+  node_offset = gsk_text_node_get_offset (node);
 
   x_position = 0;
-  for (i = 0, count = 0; i < num_glyphs; i++)
+  for (i = 0; i < num_glyphs; i++)
     {
+      GskVulkanCachedGlyph *glyph;
       const PangoGlyphInfo *gi = &glyphs[i];
-
-      texture_index = gsk_vulkan_renderer_cache_glyph (renderer,
-                                                       (PangoFont *)font,
-                                                       gi->glyph,
-                                                       x_position + gi->geometry.x_offset,
-                                                       gi->geometry.y_offset,
-                                                       op.scale);
-      if (op.texture_index == G_MAXUINT)
-        op.texture_index = texture_index;
-      if (texture_index != op.texture_index)
-        {
-          op.num_glyphs = count;
-
-          gsk_vulkan_render_pass_add_op (self, (GskVulkanOp *) &op);
-
-          count = 1;
-          op.start_glyph = i;
-          op.texture_index = texture_index;
-        }
+      graphene_rect_t glyph_bounds, glyph_tex_rect;
+
+      glyph = gsk_vulkan_renderer_cache_glyph (renderer,
+                                               (PangoFont *)font,
+                                               gi->glyph,
+                                               x_position + gi->geometry.x_offset,
+                                               gi->geometry.y_offset,
+                                               scale);
+
+      glyph_bounds = GRAPHENE_RECT_INIT (glyph->draw_x + node_offset->x + (float) (x_position + gi->geometry.x_offset) / PANGO_SCALE,
+                                         glyph->draw_y + node_offset->y + (float) (gi->geometry.y_offset) / PANGO_SCALE,
+                                         glyph->draw_width,
+                                         glyph->draw_height);
+      graphene_rect_init (&glyph_tex_rect,
+                          glyph_bounds.origin.x - glyph->draw_width * glyph->tx / glyph->tw,
+                          glyph_bounds.origin.y - glyph->draw_height * glyph->ty / glyph->th,
+                          glyph->draw_width / glyph->tw,
+                          glyph->draw_height / glyph->th);
+      if (gsk_text_node_has_color_glyphs (node))
+        gsk_vulkan_texture_op (self,
+                               gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &glyph_bounds),
+                               glyph->atlas_image,
+                               GSK_VULKAN_SAMPLER_DEFAULT,
+                               &glyph_bounds,
+                               &state->offset,
+                               &glyph_tex_rect);
       else
-        count++;
+        gsk_vulkan_glyph_op (self,
+                             gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &glyph_bounds),
+                             glyph->atlas_image,
+                             &glyph_bounds,
+                             &state->offset,
+                             &glyph_tex_rect,
+                             gsk_text_node_get_color (node));
 
       x_position += gi->geometry.width;
     }
 
-  if (op.texture_index != G_MAXUINT && count != 0)
-    {
-      op.num_glyphs = count;
-      gsk_vulkan_render_pass_add_op (self, (GskVulkanOp *) &op);
-    }
-
   return TRUE;
 }
 
@@ -1490,16 +1438,6 @@ gsk_vulkan_render_op_upload (GskVulkanOp           *op_,
 
       switch (op->any.type)
         {
-        case GSK_VULKAN_OP_TEXT:
-        case GSK_VULKAN_OP_COLOR_TEXT:
-          {
-            op->text.source = gsk_vulkan_renderer_ref_glyph_image (GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render)),
-                                                                   uploader,
-                                                                   op->text.texture_index);
-            gsk_vulkan_render_add_cleanup_image (render, op->text.source);
-          }
-          break;
-
         default:
           g_assert_not_reached ();
         case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
@@ -1530,18 +1468,9 @@ gsk_vulkan_render_op_count_vertex_data (GskVulkanOp *op_,
                                         gsize        n_bytes)
 {
   GskVulkanOpAll *op = (GskVulkanOpAll *) op_;
-  gsize vertex_stride;
 
       switch (op->any.type)
         {
-        case GSK_VULKAN_OP_TEXT:
-        case GSK_VULKAN_OP_COLOR_TEXT:
-          vertex_stride = gsk_vulkan_pipeline_get_vertex_stride (op->text.pipeline);
-          n_bytes = round_up (n_bytes, vertex_stride);
-          op->text.vertex_offset = n_bytes;
-          n_bytes += vertex_stride * op->text.num_glyphs;
-          break;
-
         default:
           g_assert_not_reached ();
 
@@ -1578,43 +1507,6 @@ gsk_vulkan_render_op_collect_vertex_data (GskVulkanOp         *op_,
 
       switch (op->any.type)
         {
-        case GSK_VULKAN_OP_TEXT:
-          gsk_vulkan_text_pipeline_collect_vertex_data (GSK_VULKAN_TEXT_PIPELINE (op->text.pipeline),
-                                                        data + op->text.vertex_offset,
-                                                        GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render)),
-                                                        &op->text.node->bounds,
-                                                        op->text.image_descriptor,
-                                                        (PangoFont *)gsk_text_node_get_font (op->text.node),
-                                                        gsk_text_node_get_num_glyphs (op->text.node),
-                                                        gsk_text_node_get_glyphs (op->text.node, NULL),
-                                                        gsk_text_node_get_color (op->text.node),
-                                                        &GRAPHENE_POINT_INIT (
-                                                          gsk_text_node_get_offset (op->text.node)->x + op->text.offset.x,
-                                                          gsk_text_node_get_offset (op->text.node)->y + op->text.offset.y
-                                                        ),
-                                                        op->text.start_glyph,
-                                                        op->text.num_glyphs,
-                                                        op->text.scale);
-          break;
-
-        case GSK_VULKAN_OP_COLOR_TEXT:
-          gsk_vulkan_color_text_pipeline_collect_vertex_data (GSK_VULKAN_COLOR_TEXT_PIPELINE (op->text.pipeline),
-                                                              data + op->text.vertex_offset,
-                                                              GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render)),
-                                                              &op->text.node->bounds,
-                                                              op->text.image_descriptor,
-                                                              (PangoFont *)gsk_text_node_get_font (op->text.node),
-                                                              gsk_text_node_get_num_glyphs (op->text.node),
-                                                              gsk_text_node_get_glyphs (op->text.node, NULL),
-                                                              &GRAPHENE_POINT_INIT (
-                                                                gsk_text_node_get_offset (op->text.node)->x + op->text.offset.x,
-                                                                gsk_text_node_get_offset (op->text.node)->y + op->text.offset.y
-                                                              ),
-                                                              op->text.start_glyph,
-                                                              op->text.num_glyphs,
-                                                              op->text.scale);
-          break;
-
         default:
           g_assert_not_reached ();
         case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
@@ -1683,13 +1575,6 @@ gsk_vulkan_render_op_reserve_descriptor_sets (GskVulkanOp     *op_,
 
       switch (op->any.type)
         {
-        case GSK_VULKAN_OP_TEXT:
-        case GSK_VULKAN_OP_COLOR_TEXT:
-          op->text.image_descriptor = gsk_vulkan_render_get_image_descriptor (render,
-                                                                              op->text.source,
-                                                                              GSK_VULKAN_SAMPLER_DEFAULT);
-          break;
-
         default:
           g_assert_not_reached ();
 
@@ -1756,10 +1641,6 @@ gsk_vulkan_render_op_get_pipeline (GskVulkanOp *op_)
 
   switch (op->any.type)
     {
-    case GSK_VULKAN_OP_TEXT:
-    case GSK_VULKAN_OP_COLOR_TEXT:
-      return gsk_vulkan_pipeline_get_pipeline (op->text.pipeline);
-
     case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
       return NULL;
 
@@ -1779,20 +1660,6 @@ gsk_vulkan_render_op_command (GskVulkanOp      *op_,
 
       switch (op->any.type)
         {
-        case GSK_VULKAN_OP_TEXT:
-          gsk_vulkan_text_pipeline_draw (GSK_VULKAN_TEXT_PIPELINE (op->text.pipeline),
-                                         command_buffer,
-                                         op->text.vertex_offset / gsk_vulkan_pipeline_get_vertex_stride (op->text.pipeline),
-                                         op->text.num_glyphs);
-          break;
-
-        case GSK_VULKAN_OP_COLOR_TEXT:
-          gsk_vulkan_color_text_pipeline_draw (GSK_VULKAN_COLOR_TEXT_PIPELINE (op->text.pipeline),
-                                               command_buffer,
-                                               op->text.vertex_offset / gsk_vulkan_pipeline_get_vertex_stride (op->text.pipeline),
-                                               op->text.num_glyphs);
-          break;
-
         case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
           gsk_vulkan_push_constants_push (command_buffer,
                                           pipeline_layout,
index 7e605a1933263c35b53561daa9b9c06ac947d876..41023d5ad823167f7bd74a0062bb87a5e27046b4 100644 (file)
 
 G_BEGIN_DECLS
 
-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;
-
 typedef enum {
   GSK_VULKAN_SAMPLER_DEFAULT,
   GSK_VULKAN_SAMPLER_REPEAT,
@@ -56,9 +45,6 @@ VkPipeline              gsk_vulkan_render_create_pipeline               (GskVulk
                                                                          const VkPipelineVertexInputStateCreateInfo *vertex_input_state,
                                                                          VkFormat                format,
                                                                          VkRenderPass            render_pass);
-GskVulkanPipeline *     gsk_vulkan_render_get_pipeline                  (GskVulkanRender        *self,
-                                                                         GskVulkanPipelineType   pipeline_type,
-                                                                         VkRenderPass            render_pass);
 gsize                   gsk_vulkan_render_get_image_descriptor          (GskVulkanRender        *self,
                                                                          GskVulkanImage         *source,
                                                                          GskVulkanRenderSampler  render_sampler);
diff --git a/gsk/vulkan/gskvulkantextpipeline.c b/gsk/vulkan/gskvulkantextpipeline.c
deleted file mode 100644 (file)
index 80b9200..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-#include "config.h"
-
-#include "gskvulkantextpipelineprivate.h"
-
-#include "vulkan/resources/mask.vert.h"
-
-struct _GskVulkanTextPipeline
-{
-  GObject parent_instance;
-};
-
-G_DEFINE_TYPE (GskVulkanTextPipeline, gsk_vulkan_text_pipeline, GSK_TYPE_VULKAN_PIPELINE)
-
-static const VkPipelineVertexInputStateCreateInfo *
-gsk_vulkan_text_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
-{
-  return &gsk_vulkan_mask_info;
-}
-
-static void
-gsk_vulkan_text_pipeline_finalize (GObject *gobject)
-{
-  //GskVulkanTextPipeline *self = GSK_VULKAN_TEXT_PIPELINE (gobject);
-
-  G_OBJECT_CLASS (gsk_vulkan_text_pipeline_parent_class)->finalize (gobject);
-}
-
-static void
-gsk_vulkan_text_pipeline_class_init (GskVulkanTextPipelineClass *klass)
-{
-  GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
-
-  G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_text_pipeline_finalize;
-
-  pipeline_class->get_input_state_create_info = gsk_vulkan_text_pipeline_get_input_state_create_info;
-}
-
-static void
-gsk_vulkan_text_pipeline_init (GskVulkanTextPipeline *self)
-{
-}
-
-GskVulkanPipeline *
-gsk_vulkan_text_pipeline_new (GdkVulkanContext        *context,
-                              VkPipelineLayout         layout,
-                              const char              *shader_name,
-                              VkRenderPass             render_pass)
-{
-  return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_TEXT_PIPELINE, context, layout, shader_name, render_pass);
-}
-
-void
-gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline  *pipeline,
-                                              guchar                 *data,
-                                              GskVulkanRenderer      *renderer,
-                                              const graphene_rect_t  *rect,
-                                              guint                   tex_id,
-                                              PangoFont              *font,
-                                              guint                   total_glyphs,
-                                              const PangoGlyphInfo   *glyphs,
-                                              const GdkRGBA          *color,
-                                              const graphene_point_t *offset,
-                                              guint                   start_glyph,
-                                              guint                   num_glyphs,
-                                              float                   scale)
-{
-  GskVulkanMaskInstance *instances = (GskVulkanMaskInstance *) data;
-  int i;
-  int count = 0;
-  int x_position = 0;
-
-  for (i = 0; i < start_glyph; i++)
-    x_position += glyphs[i].geometry.width;
-
-  for (; i < total_glyphs && count < num_glyphs; i++)
-    {
-      const PangoGlyphInfo *gi = &glyphs[i];
-
-      if (gi->glyph != PANGO_GLYPH_EMPTY)
-        {
-          double cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE;
-          double cy = gi->geometry.y_offset / PANGO_SCALE;
-          GskVulkanMaskInstance *instance = &instances[count];
-          GskVulkanCachedGlyph *glyph;
-
-          glyph = gsk_vulkan_renderer_get_cached_glyph (renderer,
-                                                        font,
-                                                        gi->glyph,
-                                                        x_position + gi->geometry.x_offset,
-                                                        gi->geometry.y_offset,
-                                                        scale);
-
-          instance->rect[0] = offset->x + cx + glyph->draw_x;
-          instance->rect[1] = offset->y + cy + glyph->draw_y;
-          instance->rect[2] = glyph->draw_width;
-          instance->rect[3] = glyph->draw_height;
-
-          instance->tex_rect[0] = glyph->tx;
-          instance->tex_rect[1] = glyph->ty;
-          instance->tex_rect[2] = glyph->tw;
-          instance->tex_rect[3] = glyph->th;
-
-          instance->color[0] = color->red;
-          instance->color[1] = color->green;
-          instance->color[2] = color->blue;
-          instance->color[3] = color->alpha;
-
-          instance->tex_id = tex_id;
-
-          count++;
-        }
-      x_position += gi->geometry.width;
-    }
-}
-
-gsize
-gsk_vulkan_text_pipeline_draw (GskVulkanTextPipeline *pipeline,
-                               VkCommandBuffer        command_buffer,
-                               gsize                  offset,
-                               gsize                  n_commands)
-{
-  vkCmdDraw (command_buffer,
-             6, n_commands,
-             0, offset);
-
-  return n_commands;
-}
diff --git a/gsk/vulkan/gskvulkantextpipelineprivate.h b/gsk/vulkan/gskvulkantextpipelineprivate.h
deleted file mode 100644 (file)
index 8f05e43..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#pragma once
-
-#include <graphene.h>
-
-#include "gskvulkanpipelineprivate.h"
-#include "gskvulkanrendererprivate.h"
-
-G_BEGIN_DECLS
-
-typedef struct _GskVulkanTextPipelineLayout GskVulkanTextPipelineLayout;
-
-#define GSK_TYPE_VULKAN_TEXT_PIPELINE (gsk_vulkan_text_pipeline_get_type ())
-
-G_DECLARE_FINAL_TYPE (GskVulkanTextPipeline, gsk_vulkan_text_pipeline, GSK, VULKAN_TEXT_PIPELINE, GskVulkanPipeline)
-
-GskVulkanPipeline *     gsk_vulkan_text_pipeline_new                   (GdkVulkanContext              *context,
-                                                                        VkPipelineLayout               layout,
-                                                                        const char                    *shader_name,
-                                                                        VkRenderPass                   render_pass);
-
-void                    gsk_vulkan_text_pipeline_collect_vertex_data   (GskVulkanTextPipeline         *pipeline,
-                                                                        guchar                        *data,
-                                                                        GskVulkanRenderer             *renderer,
-                                                                        const graphene_rect_t         *rect,
-                                                                        guint32                        tex_id,
-                                                                        PangoFont                     *font,
-                                                                        guint                          total_glyphs,
-                                                                        const PangoGlyphInfo          *glyphs,
-                                                                        const GdkRGBA                 *color,
-                                                                        const graphene_point_t        *offset,
-                                                                        guint                          start_glyph,
-                                                                        guint                          num_glyphs,
-                                                                        float                          scale);
-gsize                   gsk_vulkan_text_pipeline_draw                  (GskVulkanTextPipeline         *pipeline,
-                                                                        VkCommandBuffer                command_buffer,
-                                                                        gsize                          offset,
-                                                                        gsize                          n_commands);
-
-G_END_DECLS
-