[gtk/wip/chergert/glproto: 330/493] avoid float conversion for x, y coords




commit d20db53b149c664fe8e6f77db6573964609dfb83
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 1 15:12:33 2021 -0800

    avoid float conversion for x,y coords
    
    we don't want to risk getting the wrong value back here, so give the
    integer values back to the caller.

 gsk/next/gskglglyphlibrary.c          |  6 +++++-
 gsk/next/gskgliconlibrary.c           | 22 ++++------------------
 gsk/next/gskgltexturelibrary.c        | 24 +++++++++++++++++++-----
 gsk/next/gskgltexturelibraryprivate.h |  5 ++++-
 4 files changed, 32 insertions(+), 25 deletions(-)
---
diff --git a/gsk/next/gskglglyphlibrary.c b/gsk/next/gskglglyphlibrary.c
index 0a4dcf8747..ef0ded5690 100644
--- a/gsk/next/gskglglyphlibrary.c
+++ b/gsk/next/gskglglyphlibrary.c
@@ -277,6 +277,8 @@ gsk_gl_glyph_library_add (GskGLGlyphLibrary      *self,
   GskGLGlyphValue *value;
   int width;
   int height;
+  guint packed_x;
+  guint packed_y;
 
   g_assert (GSK_IS_GL_GLYPH_LIBRARY (self));
   g_assert (key != NULL);
@@ -297,7 +299,9 @@ gsk_gl_glyph_library_add (GskGLGlyphLibrary      *self,
                                        key,
                                        sizeof *value,
                                        width,
-                                       height);
+                                       height,
+                                       0,
+                                       &packed_x, &packed_y);
 
   memcpy (&value->ink_rect, &ink_rect, sizeof ink_rect);
 
diff --git a/gsk/next/gskgliconlibrary.c b/gsk/next/gskgliconlibrary.c
index 62e193002b..6fd27a0b1e 100644
--- a/gsk/next/gskgliconlibrary.c
+++ b/gsk/next/gskgliconlibrary.c
@@ -73,7 +73,6 @@ gsk_gl_icon_library_add (GskGLIconLibrary     *self,
                          GdkTexture           *key,
                          const GskGLIconData **out_value)
 {
-  GskGLTextureAtlas *atlas;
   cairo_surface_t *surface;
   GskGLIconData *icon_data;
   GdkGLContext *context;
@@ -82,8 +81,8 @@ gsk_gl_icon_library_add (GskGLIconLibrary     *self,
   guint8 *free_data = NULL;
   guint gl_format;
   guint gl_type;
-  int packed_x = 0;
-  int packed_y = 0;
+  guint packed_x;
+  guint packed_y;
   int width;
   int height;
   guint texture_id;
@@ -100,23 +99,10 @@ gsk_gl_icon_library_add (GskGLIconLibrary     *self,
   icon_data = gsk_gl_texture_library_pack (GSK_GL_TEXTURE_LIBRARY (self),
                                            key,
                                            sizeof (GskGLIconData),
-                                           width + 2,
-                                           height + 2);
+                                           width, height, 1,
+                                           &packed_x, &packed_y);
   icon_data->source_texture = g_object_ref (key);
 
-  atlas = icon_data->entry.is_atlased ? icon_data->entry.atlas : NULL;
-
-  if G_LIKELY (atlas != NULL)
-    {
-      packed_x = atlas->width * icon_data->entry.area.x;
-      packed_y = atlas->width * icon_data->entry.area.y;
-    }
-  else
-    {
-      packed_x = 0;
-      packed_y = 0;
-    }
-
   /* actually upload the texture */
   surface = gdk_texture_download_surface (key);
   surface_data = cairo_image_surface_get_data (surface);
diff --git a/gsk/next/gskgltexturelibrary.c b/gsk/next/gskgltexturelibrary.c
index cf57f837cb..b6185a0302 100644
--- a/gsk/next/gskgltexturelibrary.c
+++ b/gsk/next/gskgltexturelibrary.c
@@ -235,7 +235,10 @@ gsk_gl_texture_library_pack (GskGLTextureLibrary *self,
                              gpointer             key,
                              gsize                valuelen,
                              guint                width,
-                             guint                height)
+                             guint                height,
+                             int                  padding,
+                             guint               *out_packed_x,
+                             guint               *out_packed_y)
 {
   GskGLTextureAtlasEntry *entry;
   GskGLTextureAtlas *atlas = NULL;
@@ -243,6 +246,8 @@ gsk_gl_texture_library_pack (GskGLTextureLibrary *self,
   g_assert (GSK_IS_GL_TEXTURE_LIBRARY (self));
   g_assert (key != NULL);
   g_assert (valuelen > sizeof (GskGLTextureAtlasEntry));
+  g_assert (out_packed_x != NULL);
+  g_assert (out_packed_y != NULL);
 
   entry = g_slice_alloc0 (valuelen);
   entry->n_pixels = width * height;
@@ -260,6 +265,9 @@ gsk_gl_texture_library_pack (GskGLTextureLibrary *self,
       entry->area.y = 0.0f;
       entry->area.x2 = 0.0f;
       entry->area.y2 = 0.0f;
+
+      *out_packed_x = 0;
+      *out_packed_y = 0;
     }
   else if (width <= self->max_entry_size && height <= self->max_entry_size)
     {
@@ -267,18 +275,21 @@ gsk_gl_texture_library_pack (GskGLTextureLibrary *self,
       int packed_y;
 
       gsk_gl_texture_atlases_pack (self->driver,
-                                   width + 2,
-                                   height + 2,
+                                   width + padding,
+                                   height + padding,
                                    &atlas,
                                    &packed_x,
                                    &packed_y);
 
       entry->atlas = atlas;
       entry->is_atlased = TRUE;
-      entry->area.x = (float)(packed_x + 1) / atlas->width;
-      entry->area.y = (float)(packed_y + 1) / atlas->height;
+      entry->area.x = (float)(packed_x + padding) / atlas->width;
+      entry->area.y = (float)(packed_y + padding) / atlas->height;
       entry->area.x2 = entry->area.x + (float)width / atlas->width;
       entry->area.y2 = entry->area.y + (float)height / atlas->height;
+
+      *out_packed_x = packed_x;
+      *out_packed_y = packed_y;
     }
   else
     {
@@ -290,6 +301,9 @@ gsk_gl_texture_library_pack (GskGLTextureLibrary *self,
       entry->area.y = 0.0f;
       entry->area.x2 = 1.0f;
       entry->area.y2 = 1.0f;
+
+      *out_packed_x = 0;
+      *out_packed_y = 0;
     }
 
   g_hash_table_insert (self->hash_table, key, entry);
diff --git a/gsk/next/gskgltexturelibraryprivate.h b/gsk/next/gskgltexturelibraryprivate.h
index 6b415a1da3..3a63ebbc07 100644
--- a/gsk/next/gskgltexturelibraryprivate.h
+++ b/gsk/next/gskgltexturelibraryprivate.h
@@ -121,7 +121,10 @@ gpointer gsk_gl_texture_library_pack        (GskGLTextureLibrary    *self,
                                              gpointer                key,
                                              gsize                   valuelen,
                                              guint                   width,
-                                             guint                   height);
+                                             guint                   height,
+                                             int                     padding,
+                                             guint                  *out_packed_x,
+                                             guint                  *out_packed_y);
 
 static inline void
 gsk_gl_texture_atlas_mark_unused (GskGLTextureAtlas *self,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]