[gtk/wip/chergert/glproto: 385/493] inline some cache lookups




commit 0b39d424481142cd00302c3d96e7c1aabfd89bef
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 3 22:05:05 2021 -0800

    inline some cache lookups

 gsk/next/gskgldriver.c        | 64 ++++++++++---------------------------------
 gsk/next/gskgldriverprivate.h | 55 ++++++++++++++++++++++++++++++++++---
 2 files changed, 66 insertions(+), 53 deletions(-)
---
diff --git a/gsk/next/gskgldriver.c b/gsk/next/gskgldriver.c
index 0dc776849d..0be5863f76 100644
--- a/gsk/next/gskgldriver.c
+++ b/gsk/next/gskgldriver.c
@@ -24,7 +24,6 @@
 #include "config.h"
 
 #include <gdk/gdkglcontextprivate.h>
-#include <gdk/gdkgltextureprivate.h>
 #include <gdk/gdktextureprivate.h>
 #include <gsk/gskdebugprivate.h>
 #include <gsk/gskglshaderprivate.h>
@@ -625,39 +624,6 @@ gsk_next_driver_get_context (GskNextDriver *self)
   return gsk_gl_command_queue_get_context (self->command_queue);
 }
 
-/**
- * gsk_next_driver_lookup_texture:
- * @self: a #GskNextDriver
- * @key: the key for the texture
- *
- * Looks up a texture in the texture cache by @key.
- *
- * If the texture could not be found, then zero is returned.
- *
- * Returns: a positive integer if the texture was found; otherwise 0.
- */
-guint
-gsk_next_driver_lookup_texture (GskNextDriver       *self,
-                                const GskTextureKey *key)
-{
-  gpointer id;
-
-  g_return_val_if_fail (GSK_IS_NEXT_DRIVER (self), FALSE);
-  g_return_val_if_fail (key != NULL, FALSE);
-
-  if (g_hash_table_lookup_extended (self->key_to_texture_id, key, NULL, &id))
-    {
-      GskGLTexture *texture = g_hash_table_lookup (self->textures, id);
-
-      if (texture != NULL)
-        texture->last_used_in_frame = self->current_frame_id;
-
-      return GPOINTER_TO_UINT (id);
-    }
-
-  return 0;
-}
-
 /**
  * gsk_next_driver_cache_texture:
  * @self: a #GskNextDriver
@@ -679,10 +645,10 @@ gsk_next_driver_cache_texture (GskNextDriver       *self,
 {
   GskTextureKey *k;
 
-  g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
-  g_return_if_fail (key != NULL);
-  g_return_if_fail (texture_id > 0);
-  g_return_if_fail (g_hash_table_contains (self->textures, GUINT_TO_POINTER (texture_id)));
+  g_assert (GSK_IS_NEXT_DRIVER (self));
+  g_assert (key != NULL);
+  g_assert (texture_id > 0);
+  g_assert (g_hash_table_contains (self->textures, GUINT_TO_POINTER (texture_id)));
 
   k = g_memdup (key, sizeof *key);
 
@@ -878,7 +844,7 @@ gsk_next_driver_acquire_texture (GskNextDriver *self,
 {
   GskGLTexture *texture;
 
-  g_return_val_if_fail (GSK_IS_NEXT_DRIVER (self), NULL);
+  g_assert (GSK_IS_NEXT_DRIVER (self));
 
   texture = gsk_gl_texture_pool_get (&self->texture_pool,
                                      width, height,
@@ -908,8 +874,8 @@ gsk_next_driver_release_texture (GskNextDriver *self,
 {
   guint texture_id;
 
-  g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
-  g_return_if_fail (texture != NULL);
+  g_assert (GSK_IS_NEXT_DRIVER (self));
+  g_assert (texture != NULL);
 
   texture_id = texture->texture_id;
 
@@ -1205,10 +1171,10 @@ gsk_next_driver_create_command_queue (GskNextDriver *self,
 }
 
 void
-gsk_next_driver_slice_texture (GskNextDriver      *self,
-                               GdkTexture         *texture,
-                               GskGLTextureSlice **out_slices,
-                               guint              *out_n_slices)
+gsk_next_driver_add_texture_slices (GskNextDriver      *self,
+                                    GdkTexture         *texture,
+                                    GskGLTextureSlice **out_slices,
+                                    guint              *out_n_slices)
 {
   int max_texture_size;
   GskGLTextureSlice *slices;
@@ -1220,10 +1186,10 @@ gsk_next_driver_slice_texture (GskNextDriver      *self,
   int tex_height;
   int x = 0, y = 0;
 
-  g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
-  g_return_if_fail (GDK_IS_TEXTURE (texture));
-  g_return_if_fail (out_slices != NULL);
-  g_return_if_fail (out_n_slices != NULL);
+  g_assert (GSK_IS_NEXT_DRIVER (self));
+  g_assert (GDK_IS_TEXTURE (texture));
+  g_assert (out_slices != NULL);
+  g_assert (out_n_slices != NULL);
 
   /* XXX: Too much? */
   max_texture_size = self->command_queue->max_texture_size / 4;
diff --git a/gsk/next/gskgldriverprivate.h b/gsk/next/gskgldriverprivate.h
index fe6e247bf2..f09b42e69f 100644
--- a/gsk/next/gskgldriverprivate.h
+++ b/gsk/next/gskgldriverprivate.h
@@ -21,8 +21,9 @@
 #ifndef __GSK_GL_DRIVER_PRIVATE_H__
 #define __GSK_GL_DRIVER_PRIVATE_H__
 
-#include "gskgltypesprivate.h"
+#include <gdk/gdkgltextureprivate.h>
 
+#include "gskgltypesprivate.h"
 #include "gskgltexturepoolprivate.h"
 
 G_BEGIN_DECLS
@@ -141,8 +142,6 @@ void               gsk_next_driver_end_frame             (GskNextDriver        *
 void               gsk_next_driver_after_frame           (GskNextDriver        *self);
 GdkTexture        *gsk_next_driver_create_gdk_texture    (GskNextDriver        *self,
                                                           guint                 texture_id);
-guint              gsk_next_driver_lookup_texture        (GskNextDriver        *self,
-                                                          const GskTextureKey  *key);
 void               gsk_next_driver_cache_texture         (GskNextDriver        *self,
                                                           const GskTextureKey  *key,
                                                           guint                 texture_id);
@@ -166,7 +165,7 @@ void               gsk_next_driver_release_texture_by_id (GskNextDriver        *
                                                           guint                 texture_id);
 GskGLTexture      *gsk_next_driver_mark_texture_permanent(GskNextDriver        *self,
                                                           guint                 texture_id);
-void               gsk_next_driver_slice_texture         (GskNextDriver        *self,
+void               gsk_next_driver_add_texture_slices    (GskNextDriver        *self,
                                                           GdkTexture           *texture,
                                                           GskGLTextureSlice   **out_slices,
                                                           guint                *out_n_slices);
@@ -184,6 +183,54 @@ gsk_next_driver_get_texture_by_id (GskNextDriver *self,
   return g_hash_table_lookup (self->textures, GUINT_TO_POINTER (texture_id));
 }
 
+/**
+ * gsk_next_driver_lookup_texture:
+ * @self: a #GskNextDriver
+ * @key: the key for the texture
+ *
+ * Looks up a texture in the texture cache by @key.
+ *
+ * If the texture could not be found, then zero is returned.
+ *
+ * Returns: a positive integer if the texture was found; otherwise 0.
+ */
+static inline guint
+gsk_next_driver_lookup_texture (GskNextDriver       *self,
+                                const GskTextureKey *key)
+{
+  gpointer id;
+
+  if (g_hash_table_lookup_extended (self->key_to_texture_id, key, NULL, &id))
+    {
+      GskGLTexture *texture = g_hash_table_lookup (self->textures, id);
+
+      if (texture != NULL)
+        texture->last_used_in_frame = self->current_frame_id;
+
+      return GPOINTER_TO_UINT (id);
+    }
+
+  return 0;
+}
+
+static inline void
+gsk_next_driver_slice_texture (GskNextDriver      *self,
+                               GdkTexture         *texture,
+                               GskGLTextureSlice **out_slices,
+                               guint              *out_n_slices)
+{
+  GskGLTexture *t;
+
+  if ((t = gdk_texture_get_render_data (texture, self)))
+    {
+      *out_slices = t->slices;
+      *out_n_slices = t->n_slices;
+      return;
+    }
+
+  gsk_next_driver_add_texture_slices (self, texture, out_slices, out_n_slices);
+}
+
 G_END_DECLS
 
 #endif /* __GSK_GL_DRIVER_PRIVATE_H__ */


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