Merge branch 'gbsneto/vulkan-glyph-fixes' into 'main'

Vulkan glyph fixes

See merge request GNOME/gtk!5802
This commit is contained in:
Benjamin Otte
2023-04-09 00:07:16 +00:00
6 changed files with 53 additions and 58 deletions

View File

@@ -81,8 +81,7 @@ gsk_vulkan_color_text_pipeline_new (GdkVulkanContext *context,
const char *shader_name,
VkRenderPass render_pass)
{
return gsk_vulkan_pipeline_new_full (GSK_TYPE_VULKAN_COLOR_TEXT_PIPELINE, context, layout, shader_name, render_pass,
VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_COLOR_TEXT_PIPELINE, context, layout, shader_name, render_pass);
}
gsize
@@ -131,16 +130,16 @@ gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *
gi->geometry.y_offset,
scale);
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->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;
count++;
}
x_position += gi->geometry.width;

View File

@@ -22,6 +22,7 @@
#define CHECK_INTERVAL 10
#define MAX_OLD 0.333
#define PADDING 1
typedef struct {
GskVulkanImage *image;
@@ -65,9 +66,9 @@ create_atlas (GskVulkanGlyphCache *cache)
atlas = g_new0 (Atlas, 1);
atlas->width = 512;
atlas->height = 512;
atlas->y0 = 1;
atlas->y = 1;
atlas->x = 1;
atlas->y0 = 0;
atlas->y = 0;
atlas->x = 0;
atlas->image = NULL;
atlas->num_glyphs = 0;
atlas->dirty_glyphs = NULL;
@@ -180,8 +181,10 @@ add_to_cache (GskVulkanGlyphCache *cache,
Atlas *atlas;
int i;
DirtyGlyph *dirty;
int width = value->draw_width * key->scale / 1024;
int height = value->draw_height * key->scale / 1024;
int width = ceil (value->draw_width * key->scale / 1024.0);
int height = ceil (value->draw_height * key->scale / 1024.0);
int width_with_padding = width + 2 * PADDING;
int height_with_padding = height + 2 * PADDING;
for (i = 0; i < cache->atlases->len; i++)
{
@@ -192,14 +195,14 @@ add_to_cache (GskVulkanGlyphCache *cache,
y = atlas->y;
y0 = atlas->y0;
if (atlas->x + width + 1 >= atlas->width)
if (atlas->x + width_with_padding >= atlas->width)
{
/* start a new row */
y0 = y + 1;
x = 1;
y0 = y + PADDING;
x = PADDING;
}
if (y0 + height + 1 >= atlas->height)
if (y0 + height_with_padding >= atlas->height)
continue;
atlas->y0 = y0;
@@ -214,8 +217,11 @@ add_to_cache (GskVulkanGlyphCache *cache,
g_ptr_array_add (cache->atlases, atlas);
}
value->tx = (float)atlas->x / atlas->width;
value->ty = (float)atlas->y0 / atlas->height;
value->atlas_x = atlas->x;
value->atlas_y = atlas->y0;
value->tx = (float)(atlas->x + PADDING) / atlas->width;
value->ty = (float)(atlas->y0 + PADDING) / atlas->height;
value->tw = (float)width / atlas->width;
value->th = (float)height / atlas->height;
@@ -226,8 +232,8 @@ add_to_cache (GskVulkanGlyphCache *cache,
dirty->value = value;
atlas->dirty_glyphs = g_list_prepend (atlas->dirty_glyphs, dirty);
atlas->x = atlas->x + width + 1;
atlas->y = MAX (atlas->y, atlas->y0 + height + 1);
atlas->x = atlas->x + width_with_padding;
atlas->y = MAX (atlas->y, atlas->y0 + height_with_padding);
atlas->num_glyphs++;
@@ -259,13 +265,23 @@ render_glyph (Atlas *atlas,
cairo_t *cr;
PangoGlyphString glyphs;
PangoGlyphInfo gi;
int surface_height;
int surface_width;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
ceil (value->draw_width * key->scale / 1024.0),
ceil (value->draw_height * key->scale / 1024.0));
surface_width = ceil (value->draw_width * key->scale / 1024.0) + 2 * PADDING;
surface_height = ceil (value->draw_height * key->scale / 1024.0) + 2 * PADDING;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface_width, surface_height);
cairo_surface_set_device_scale (surface, key->scale / 1024.0, key->scale / 1024.0);
cr = cairo_create (surface);
/* Make sure the entire surface is initialized to black */
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_rectangle (cr, 0.0, 0.0, surface_width, surface_width);
cairo_fill (cr);
/* Draw glyph */
cairo_set_source_rgba (cr, 1, 1, 1, 1);
gi.glyph = key->glyph;
@@ -286,8 +302,8 @@ render_glyph (Atlas *atlas,
region->width = cairo_image_surface_get_width (surface);
region->height = cairo_image_surface_get_height (surface);
region->stride = cairo_image_surface_get_stride (surface);
region->x = (gsize)(value->tx * atlas->width);
region->y = (gsize)(value->ty * atlas->height);
region->x = value->atlas_x;
region->y = value->atlas_y;
}
static void

View File

@@ -59,20 +59,6 @@ gsk_vulkan_pipeline_new (GType pipeline_type,
VkPipelineLayout layout,
const char *shader_name,
VkRenderPass render_pass)
{
return gsk_vulkan_pipeline_new_full (pipeline_type, context, layout, shader_name, render_pass,
VK_BLEND_FACTOR_ONE,
VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
}
GskVulkanPipeline *
gsk_vulkan_pipeline_new_full (GType pipeline_type,
GdkVulkanContext *context,
VkPipelineLayout layout,
const char *shader_name,
VkRenderPass render_pass,
VkBlendFactor srcBlendFactor,
VkBlendFactor dstBlendFactor)
{
GskVulkanPipelinePrivate *priv;
GskVulkanPipeline *self;
@@ -140,11 +126,11 @@ gsk_vulkan_pipeline_new_full (GType pipeline_type,
{
.blendEnable = VK_TRUE,
.colorBlendOp = VK_BLEND_OP_ADD,
.srcColorBlendFactor = srcBlendFactor,
.dstColorBlendFactor = dstBlendFactor,
.srcColorBlendFactor = VK_BLEND_FACTOR_ONE,
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.alphaBlendOp = VK_BLEND_OP_ADD,
.srcAlphaBlendFactor = srcBlendFactor,
.dstAlphaBlendFactor = dstBlendFactor,
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.colorWriteMask = VK_COLOR_COMPONENT_A_BIT
| VK_COLOR_COMPONENT_R_BIT
| VK_COLOR_COMPONENT_G_BIT

View File

@@ -36,14 +36,6 @@ GskVulkanPipeline * gsk_vulkan_pipeline_new (GType
VkPipelineLayout layout,
const char *shader_name,
VkRenderPass render_pass);
GskVulkanPipeline * gsk_vulkan_pipeline_new_full (GType pipeline_type,
GdkVulkanContext *context,
VkPipelineLayout layout,
const char *shader_name,
VkRenderPass render_pass,
VkBlendFactor srcBlendFactor,
VkBlendFactor dstBlendFactor);
VkPipeline gsk_vulkan_pipeline_get_pipeline (GskVulkanPipeline *self);
VkPipelineLayout gsk_vulkan_pipeline_get_pipeline_layout (GskVulkanPipeline *self);

View File

@@ -23,6 +23,9 @@ typedef struct
int draw_width;
int draw_height;
int atlas_x;
int atlas_y;
guint64 timestamp;
} GskVulkanCachedGlyph;

View File

@@ -88,8 +88,7 @@ gsk_vulkan_text_pipeline_new (GdkVulkanContext *context,
const char *shader_name,
VkRenderPass render_pass)
{
return gsk_vulkan_pipeline_new_full (GSK_TYPE_VULKAN_TEXT_PIPELINE, context, layout, shader_name, render_pass,
VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_TEXT_PIPELINE, context, layout, shader_name, render_pass);
}
gsize
@@ -139,16 +138,16 @@ gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline *pipeline,
gi->geometry.y_offset,
scale);
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->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;