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.
'vulkan/gskvulkanclip.c',
'vulkan/gskvulkancolormatrixop.c',
'vulkan/gskvulkancolorop.c',
- 'vulkan/gskvulkancolortextpipeline.c',
'vulkan/gskvulkancommandpool.c',
'vulkan/gskvulkancrossfadeop.c',
'vulkan/gskvulkanglyphcache.c',
'vulkan/gskvulkanrenderer.c',
'vulkan/gskvulkanrenderpass.c',
'vulkan/gskvulkanscissorop.c',
- 'vulkan/gskvulkantextpipeline.c',
'vulkan/gskvulkantextureop.c',
'vulkan/gskvulkanuploadcairoop.c',
'vulkan/gskvulkanuploadop.c',
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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
-
atlas->num_glyphs = 0;
atlas->dirty_glyphs = NULL;
+ atlas->image = gsk_vulkan_image_new_for_atlas (cache->vulkan, atlas->width, atlas->height);
+
return atlas;
}
g_ptr_array_add (cache->atlases, atlas);
}
+ value->atlas_image = atlas->image;
value->atlas_x = atlas->x;
value->atlas_y = atlas->y0;
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;
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++)
for (l = atlas->dirty_glyphs, i = 0; l; l = l->next, i++)
render_glyph (atlas, (DirtyGlyph *)l->data, ®ions[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);
}
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));
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
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;
}
}
- GSK_RENDERER_DEBUG (cache->renderer, GLYPH_CACHE, "Dropped %d glyphs", dropped);
+ GSK_DEBUG (GLYPH_CACHE, "Dropped %d glyphs", dropped);
}
#pragma once
#include <pango/pango.h>
-#include "gskvulkanrendererprivate.h"
#include "gskvulkanimageprivate.h"
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,
#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"
GskDescriptorBufferInfos descriptor_buffers;
VkDescriptorPool descriptor_pool;
VkDescriptorSet descriptor_sets[N_DESCRIPTOR_SETS];
- GskVulkanPipeline *pipelines[GSK_VULKAN_N_PIPELINES];
GHashTable *pipeline_cache;
GskVulkanImage *target;
{
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.
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)
}
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);
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;
}
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,
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);
}
/**
#pragma once
#include "gskvulkanrenderer.h"
+#include "gskvulkanglyphcacheprivate.h"
#include "gskvulkanimageprivate.h"
G_BEGIN_DECLS
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
#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"
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;
union _GskVulkanOpAll
{
GskVulkanOpAny any;
- GskVulkanOpText text;
GskVulkanOpPushConstants constants;
};
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,
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;
}
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:
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 ();
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:
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 ();
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;
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,
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,
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);
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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
-