summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte.benjamin@googlemail.com>2023-04-09 00:07:16 +0000
committerBenjamin Otte <otte.benjamin@googlemail.com>2023-04-09 00:07:16 +0000
commit3907711a499cb20214b050750d7a872e9c6be7da (patch)
tree6b4031b25aaa290870e455d6c4abc51c6b958d4d
parent99251c0c8fd98ba7ffb36999a374327b67f27fc3 (diff)
parent496c8f4a116aa05f95df32355843cce032921d56 (diff)
downloadgtk+-3907711a499cb20214b050750d7a872e9c6be7da.tar.gz
Merge branch 'gbsneto/vulkan-glyph-fixes' into 'main'
Vulkan glyph fixes See merge request GNOME/gtk!5802
-rw-r--r--gsk/vulkan/gskvulkancolortextpipeline.c13
-rw-r--r--gsk/vulkan/gskvulkanglyphcache.c52
-rw-r--r--gsk/vulkan/gskvulkanpipeline.c22
-rw-r--r--gsk/vulkan/gskvulkanpipelineprivate.h8
-rw-r--r--gsk/vulkan/gskvulkanrendererprivate.h3
-rw-r--r--gsk/vulkan/gskvulkantextpipeline.c13
6 files changed, 53 insertions, 58 deletions
diff --git a/gsk/vulkan/gskvulkancolortextpipeline.c b/gsk/vulkan/gskvulkancolortextpipeline.c
index 5ffe62adcc..4a4aded9d7 100644
--- a/gsk/vulkan/gskvulkancolortextpipeline.c
+++ b/gsk/vulkan/gskvulkancolortextpipeline.c
@@ -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;
diff --git a/gsk/vulkan/gskvulkanglyphcache.c b/gsk/vulkan/gskvulkanglyphcache.c
index ab623b9445..0bb3c55b63 100644
--- a/gsk/vulkan/gskvulkanglyphcache.c
+++ b/gsk/vulkan/gskvulkanglyphcache.c
@@ -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_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,
- ceil (value->draw_width * key->scale / 1024.0),
- ceil (value->draw_height * key->scale / 1024.0));
+ 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
diff --git a/gsk/vulkan/gskvulkanpipeline.c b/gsk/vulkan/gskvulkanpipeline.c
index 38d5a5795f..7158bf837c 100644
--- a/gsk/vulkan/gskvulkanpipeline.c
+++ b/gsk/vulkan/gskvulkanpipeline.c
@@ -60,20 +60,6 @@ gsk_vulkan_pipeline_new (GType pipeline_type,
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;
VkDevice device;
@@ -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
diff --git a/gsk/vulkan/gskvulkanpipelineprivate.h b/gsk/vulkan/gskvulkanpipelineprivate.h
index 3deeee978f..39df45b885 100644
--- a/gsk/vulkan/gskvulkanpipelineprivate.h
+++ b/gsk/vulkan/gskvulkanpipelineprivate.h
@@ -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);
diff --git a/gsk/vulkan/gskvulkanrendererprivate.h b/gsk/vulkan/gskvulkanrendererprivate.h
index bbd43064d9..fd7d2c19f0 100644
--- a/gsk/vulkan/gskvulkanrendererprivate.h
+++ b/gsk/vulkan/gskvulkanrendererprivate.h
@@ -23,6 +23,9 @@ typedef struct
int draw_width;
int draw_height;
+ int atlas_x;
+ int atlas_y;
+
guint64 timestamp;
} GskVulkanCachedGlyph;
diff --git a/gsk/vulkan/gskvulkantextpipeline.c b/gsk/vulkan/gskvulkantextpipeline.c
index 9544c6a7c7..e9551f458b 100644
--- a/gsk/vulkan/gskvulkantextpipeline.c
+++ b/gsk/vulkan/gskvulkantextpipeline.c
@@ -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;