[gtk/glyphy2: 32/32] wip: Use glyphy for line drawing
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/glyphy2: 32/32] wip: Use glyphy for line drawing
- Date: Wed, 6 Apr 2022 21:23:28 +0000 (UTC)
commit 72e498e2386cb09492bd81d6c06f0cf0a434ce59
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Apr 6 17:10:53 2022 -0400
wip: Use glyphy for line drawing
This doesn't quite work right yet - our quads are very
assymmetrical, which causes antialiasing mishaps.
gsk/gl/gskglglyphylibrary.c | 33 ++++----
gsk/gl/gskglglyphylibraryprivate.h | 1 +
gsk/gl/gskglrenderjob.c | 160 ++++++++++++++++++++++++-------------
tests/simple.c | 12 +--
4 files changed, 126 insertions(+), 80 deletions(-)
---
diff --git a/gsk/gl/gskglglyphylibrary.c b/gsk/gl/gskglglyphylibrary.c
index 5d9277f44f..c32e723fab 100644
--- a/gsk/gl/gskglglyphylibrary.c
+++ b/gsk/gl/gskglglyphylibrary.c
@@ -346,6 +346,7 @@ encode_path (GskGLGlyphyLibrary *self,
double enlighten_max = (double) upem * ENLIGHTEN_MAX;
double embolden_max = (double) upem * EMBOLDEN_MAX;
double avg_fetch_achieved;
+ graphene_rect_t bounds;
self->acc_endpoints->len = 0;
@@ -358,7 +359,10 @@ encode_path (GskGLGlyphyLibrary *self,
gsk_path_foreach (path, GSK_PATH_FOREACH_ALLOW_CURVE, acc_callback, self->acc);
if (!glyphy_arc_accumulator_successful (self->acc))
- return FALSE;
+ {
+ g_print ("failed to accumulate\n");
+ return FALSE;
+ }
g_assert (glyphy_arc_accumulator_get_error (self->acc) <= tolerance);
@@ -380,7 +384,10 @@ encode_path (GskGLGlyphyLibrary *self,
nominal_width,
nominal_height,
extents))
- return FALSE;
+ {
+ g_print ("failed to encode\n");
+ return FALSE;
+ }
glyphy_extents_scale (extents, 1./upem, 1./upem);
@@ -538,7 +545,7 @@ gsk_gl_glyphy_library_add (GskGLGlyphyLibrary *self,
return TRUE;
}
-static glyphy_rgba_t buffer[128];
+static glyphy_rgba_t buffer[1024];
static guint output_len = 0;
static guint nominal_w;
static guint nominal_h;
@@ -566,7 +573,7 @@ gsk_gl_glyphy_library_init_atlas (GskGLTextureLibrary *library,
GskPath *path;
builder = gsk_path_builder_new ();
- gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (0, 0, 1, 1));
+ gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (0, 0, 1000, 1000));
path = gsk_path_builder_free_to_path (builder);
if (!encode_path (self, path, 1000, TOLERANCE,
@@ -588,15 +595,13 @@ gsk_gl_glyphy_library_init_atlas (GskGLTextureLibrary *library,
glBindTexture (GL_TEXTURE_2D, atlas->texture_id);
upload_buffer (0, 0, width, height, buffer, output_len);
-#if 0
- value->extents.min_x = extents.min_x;
- value->extents.min_y = extents.min_y;
- value->extents.max_x = extents.max_x;
- value->extents.max_y = extents.max_y;
- value->nominal_w = nominal_w;
- value->nominal_h = nominal_h;
- value->atlas_x = 0;
- value->atlas_y = 0;
-#endif
+ self->value0.extents.min_x = extents.min_x;
+ self->value0.extents.min_y = extents.min_y;
+ self->value0.extents.max_x = extents.max_x;
+ self->value0.extents.max_y = extents.max_y;
+ self->value0.nominal_w = nominal_w;
+ self->value0.nominal_h = nominal_h;
+ self->value0.atlas_x = 0;
+ self->value0.atlas_y = 0;
}
diff --git a/gsk/gl/gskglglyphylibraryprivate.h b/gsk/gl/gskglglyphylibraryprivate.h
index fece808bcd..1dbb859842 100644
--- a/gsk/gl/gskglglyphylibraryprivate.h
+++ b/gsk/gl/gskglglyphylibraryprivate.h
@@ -99,6 +99,7 @@ struct _GskGLGlyphyLibrary
GskGLGlyphyKey key;
const GskGLGlyphyValue *value;
} front[256];
+ GskGLGlyphyValue value0;
};
GskGLGlyphyLibrary *gsk_gl_glyphy_library_new (GskGLDriver *driver);
diff --git a/gsk/gl/gskglrenderjob.c b/gsk/gl/gskglrenderjob.c
index b1f58b0e89..78cec00598 100644
--- a/gsk/gl/gskglrenderjob.c
+++ b/gsk/gl/gskglrenderjob.c
@@ -1420,6 +1420,61 @@ blur_node (GskGLRenderJob *job,
#define ATLAS_SIZE 512
+typedef struct
+{
+ float x;
+ float y;
+ float g16hi;
+ float g16lo;
+} EncodedGlyph;
+
+static inline unsigned int
+glyph_encode (guint atlas_x , /* 7 bits */
+ guint atlas_y, /* 7 bits */
+ guint corner_x, /* 1 bit */
+ guint corner_y, /* 1 bit */
+ guint nominal_w, /* 6 bits */
+ guint nominal_h) /* 6 bits */
+{
+ guint x, y;
+
+ g_assert (0 == (atlas_x & ~0x7F));
+ g_assert (0 == (atlas_y & ~0x7F));
+ g_assert (0 == (corner_x & ~1));
+ g_assert (0 == (corner_y & ~1));
+ g_assert (0 == (nominal_w & ~0x3F));
+ g_assert (0 == (nominal_h & ~0x3F));
+
+ x = (((atlas_x << 6) | nominal_w) << 1) | corner_x;
+ y = (((atlas_y << 6) | nominal_h) << 1) | corner_y;
+
+ return (x << 16) | y;
+}
+
+static inline void
+encoded_glyph_init (EncodedGlyph *eg,
+ float x,
+ float y,
+ guint corner_x,
+ guint corner_y,
+ const GskGLGlyphyValue *gi)
+{
+ guint encoded = glyph_encode (gi->atlas_x, gi->atlas_y, corner_x, corner_y, gi->nominal_w, gi->nominal_h);
+
+ eg->x = x;
+ eg->y = y;
+ eg->g16hi = encoded >> 16;
+ eg->g16lo = encoded & 0xFFFF;
+}
+
+static inline void
+add_encoded_glyph (GskGLDrawVertex *vertices,
+ const EncodedGlyph *eg,
+ const guint16 c[4])
+{
+ *vertices = (GskGLDrawVertex) { .position = { eg->x, eg->y}, .uv = { eg->g16hi, eg->g16lo}, .color = {
c[0], c[1], c[2], c[3] } };
+}
+
static inline void
gsk_gl_render_job_visit_color_node (GskGLRenderJob *job,
const GskRenderNode *node)
@@ -1427,7 +1482,9 @@ gsk_gl_render_job_visit_color_node (GskGLRenderJob *job,
const GdkRGBA *rgba;
guint16 color[4];
GskGLProgram *program;
+ GskGLProgram *program1;
GskGLCommandBatch *batch;
+ GskGLGlyphyLibrary *library;
rgba = gsk_color_node_get_color (node);
if (RGBA_IS_CLEAR (rgba))
@@ -1439,13 +1496,57 @@ gsk_gl_render_job_visit_color_node (GskGLRenderJob *job,
* rendering a solid color.
*/
program = CHOOSE_PROGRAM (job, coloring);
+ program1 = CHOOSE_PROGRAM (job, glyphy);
batch = gsk_gl_command_queue_get_batch (job->command_queue);
+ library = job->driver->glyphy_library;
/* Limit the size, or we end up with a coordinate overflow somwhere. */
- if (node->bounds.size.width < 300 &&
+ if (0 && node->bounds.size.width < 300 &&
node->bounds.size.height < 300 &&
batch->any.kind == GSK_GL_COMMAND_KIND_DRAW &&
- batch->any.program == program->id)
+ batch->any.program == program1->id)
+ {
+ EncodedGlyph encoded[4];
+ GskGLDrawVertex *vertices;
+ graphene_point_t min, max;
+ graphene_rect_get_top_left (&node->bounds, &min);
+ graphene_rect_get_bottom_right (&node->bounds, &max);
+
+#define ENCODE_CORNER(_cx, _cy) \
+ G_STMT_START { \
+ encoded_glyph_init (&encoded[_cx * 2 + _cy], \
+ job->offset_x + (_cx ? max.x : min.x), \
+ job->offset_y + (_cy ? max.y : min.y), \
+ _cx, _cy, &library->value0); \
+ } G_STMT_END
+ ENCODE_CORNER (0, 0);
+ ENCODE_CORNER (0, 1);
+ ENCODE_CORNER (1, 0);
+ ENCODE_CORNER (1, 1);
+#undef ENCODE_CORNER
+
+ gsk_gl_render_job_begin_draw (job, program1);
+
+ gsk_gl_program_set_uniform1f (job->current_program,
+ UNIFORM_GLYPHY_BOLDNESS, 0,
+ 0.0);
+
+ vertices = gsk_gl_command_queue_add_vertices (job->command_queue);
+
+ add_encoded_glyph (vertices++, &encoded[0], color);
+ add_encoded_glyph (vertices++, &encoded[1], color);
+ add_encoded_glyph (vertices++, &encoded[2], color);
+
+ add_encoded_glyph (vertices++, &encoded[1], color);
+ add_encoded_glyph (vertices++, &encoded[2], color);
+ add_encoded_glyph (vertices++, &encoded[3], color);
+
+ gsk_gl_render_job_end_draw (job);
+ }
+ else if (node->bounds.size.width < 300 &&
+ node->bounds.size.height < 300 &&
+ batch->any.kind == GSK_GL_COMMAND_KIND_DRAW &&
+ batch->any.program == program->id)
{
GskGLRenderOffscreen offscreen = {0};
@@ -3069,61 +3170,6 @@ gsk_gl_render_job_visit_text_node_legacy (GskGLRenderJob *job,
gsk_gl_render_job_end_draw (job);
}
-typedef struct
-{
- float x;
- float y;
- float g16hi;
- float g16lo;
-} EncodedGlyph;
-
-static inline unsigned int
-glyph_encode (guint atlas_x , /* 7 bits */
- guint atlas_y, /* 7 bits */
- guint corner_x, /* 1 bit */
- guint corner_y, /* 1 bit */
- guint nominal_w, /* 6 bits */
- guint nominal_h) /* 6 bits */
-{
- guint x, y;
-
- g_assert (0 == (atlas_x & ~0x7F));
- g_assert (0 == (atlas_y & ~0x7F));
- g_assert (0 == (corner_x & ~1));
- g_assert (0 == (corner_y & ~1));
- g_assert (0 == (nominal_w & ~0x3F));
- g_assert (0 == (nominal_h & ~0x3F));
-
- x = (((atlas_x << 6) | nominal_w) << 1) | corner_x;
- y = (((atlas_y << 6) | nominal_h) << 1) | corner_y;
-
- return (x << 16) | y;
-}
-
-static inline void
-encoded_glyph_init (EncodedGlyph *eg,
- float x,
- float y,
- guint corner_x,
- guint corner_y,
- const GskGLGlyphyValue *gi)
-{
- guint encoded = glyph_encode (gi->atlas_x, gi->atlas_y, corner_x, corner_y, gi->nominal_w, gi->nominal_h);
-
- eg->x = x;
- eg->y = y;
- eg->g16hi = encoded >> 16;
- eg->g16lo = encoded & 0xFFFF;
-}
-
-static inline void
-add_encoded_glyph (GskGLDrawVertex *vertices,
- const EncodedGlyph *eg,
- const guint16 c[4])
-{
- *vertices = (GskGLDrawVertex) { .position = { eg->x, eg->y}, .uv = { eg->g16hi, eg->g16lo}, .color = {
c[0], c[1], c[2], c[3] } };
-}
-
static void
get_synthetic_font_params (PangoFont *font,
gboolean *embolden,
diff --git a/tests/simple.c b/tests/simple.c
index 062afdc9fa..1434334415 100644
--- a/tests/simple.c
+++ b/tests/simple.c
@@ -45,17 +45,11 @@ main (int argc, char *argv[])
gtk_init ();
window = gtk_window_new ();
- gtk_window_set_title (GTK_WINDOW (window), "hello world");
- gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+ gtk_window_set_title (GTK_WINDOW (window), "");
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
- button = gtk_button_new ();
- gtk_button_set_label (GTK_BUTTON (button), "hello world");
- gtk_widget_set_margin_top (button, 10);
- gtk_widget_set_margin_bottom (button, 10);
- gtk_widget_set_margin_start (button, 10);
- gtk_widget_set_margin_end (button, 10);
- g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
+ button = gtk_label_new ("");
+ gtk_label_set_markup (GTK_LABEL (button), "<s>XYZ</s>");
gtk_window_set_child (GTK_WINDOW (window), button);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]