[gtk/wip/chergert/glproto: 143/493] stub out some more texture interactions




commit d75f58e3ae6c0abdc2f6b0bf8b9ad77fb713c429
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 8 10:17:04 2021 -0800

    stub out some more texture interactions

 gsk/next/gskgldriver.c                | 44 +++++++++++++++++++++++++++++++----
 gsk/next/gskglrenderjob.c             | 43 +++++++++++++++++++++++++---------
 gsk/next/gskgltexturelibraryprivate.h | 43 ++++++++++++++++++++--------------
 3 files changed, 97 insertions(+), 33 deletions(-)
---
diff --git a/gsk/next/gskgldriver.c b/gsk/next/gskgldriver.c
index 9d11350c46..bf3111bd3c 100644
--- a/gsk/next/gskgldriver.c
+++ b/gsk/next/gskgldriver.c
@@ -42,6 +42,13 @@
 
 G_DEFINE_TYPE (GskNextDriver, gsk_next_driver, G_TYPE_OBJECT)
 
+static inline gboolean
+size_can_be_atlased (float width,
+                     float height)
+{
+  return width < 128 && height < 128;
+}
+
 static guint
 texture_key_hash (gconstpointer v)
 {
@@ -479,6 +486,8 @@ gsk_next_driver_cache_texture (GskNextDriver       *self,
  * @texture: a #GdkTexture
  * @min_filter: GL_NEAREST or GL_LINEAR
  * @mag_filter: GL_NEAREST or GL_LINEAR
+ * @area: (out): a #graphene_rect_t containing the area within the texture
+ *   containing the contents that were uploaded.
  *
  * Loads a #GdkTexture by uploading the contents to the GPU when
  * necessary. If @texture is a #GdkGLTexture, it can be used without
@@ -497,19 +506,23 @@ gsk_next_driver_cache_texture (GskNextDriver       *self,
  * Returns: a texture identifier
  */
 guint
-gsk_next_driver_load_texture (GskNextDriver *self,
-                              GdkTexture    *texture,
-                              int            min_filter,
-                              int            mag_filter)
+gsk_next_driver_load_texture (GskNextDriver   *self,
+                              GdkTexture      *texture,
+                              int              min_filter,
+                              int              mag_filter,
+                              graphene_rect_t *area)
 {
   GdkGLContext *context;
   GdkTexture *downloaded_texture = NULL;
   GdkTexture *source_texture;
   GskGLTexture *t;
+  float width;
+  float height;
 
   g_return_val_if_fail (GSK_IS_NEXT_DRIVER (self), 0);
   g_return_val_if_fail (GDK_IS_TEXTURE (texture), 0);
   g_return_val_if_fail (GSK_IS_GL_COMMAND_QUEUE (self->command_queue), 0);
+  g_return_val_if_fail (area != NULL, 0);
 
   context = self->command_queue->context;
 
@@ -556,6 +569,29 @@ gsk_next_driver_load_texture (GskNextDriver *self,
       source_texture = texture;
     }
 
+  width = gdk_texture_get_width (texture);
+  height = gdk_texture_get_height (texture);
+
+  if (size_can_be_atlased (width, height))
+    {
+      GskGLTextureAtlas *atlas;
+      float x, y;
+
+      if (gsk_gl_texture_library_lookup (GSK_GL_TEXTURE_LIBRARY (self->icons),
+                                         texture, &atlas, area))
+        return atlas->texture_id;
+
+      if (gsk_gl_texture_library_pack (GSK_GL_TEXTURE_LIBRARY (self->icons),
+                                       texture, sizeof (void *),
+                                       width, height,
+                                       &atlas, area))
+        {
+          gsk_gl_texture_library_upload (GSK_GL_TEXTURE_LIBRARY (self->icons),
+                                         atlas, area, texture);
+          return atlas->texture_id;
+        }
+    }
+
   t = g_slice_new0 (GskGLTexture);
   t->width = gdk_texture_get_width (texture);
   t->height = gdk_texture_get_height (texture);
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index 3171cd2567..a990148929 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -110,11 +110,11 @@ typedef struct _GskGLRenderOffscreen
   guint autorelease : 1;
 } GskGLRenderOffscreen;
 
-static void     gsk_gl_render_job_visit_node       (GskGLRenderJob       *job,
-                                                    GskRenderNode        *node);
-static gboolean gsk_gl_render_job_render_offscreen (GskGLRenderJob       *job,
-                                                    GskRenderNode        *node,
-                                                    GskGLRenderOffscreen *offscreen);
+static void     gsk_gl_render_job_visit_node                (GskGLRenderJob       *job,
+                                                             GskRenderNode        *node);
+static gboolean gsk_gl_render_job_visit_node_with_offscreen (GskGLRenderJob       *job,
+                                                             GskRenderNode        *node,
+                                                             GskGLRenderOffscreen *offscreen);
 
 static inline gboolean G_GNUC_PURE
 node_is_invisible (const GskRenderNode *node)
@@ -1499,13 +1499,13 @@ gsk_gl_render_job_visit_cross_fade_node (GskGLRenderJob *job,
   offscreen_end.bounds = &node->bounds;
   offscreen_end.autorelease = TRUE;
 
-  if (!gsk_gl_render_job_render_offscreen (job, start_node, &offscreen_start))
+  if (!gsk_gl_render_job_visit_node_with_offscreen (job, start_node, &offscreen_start))
     {
       gsk_gl_render_job_visit_node (job, end_node);
       return;
     }
 
-  if (!gsk_gl_render_job_render_offscreen (job, end_node, &offscreen_end))
+  if (!gsk_gl_render_job_visit_node_with_offscreen (job, end_node, &offscreen_end))
     {
       float prev_alpha = job->alpha;
       gsk_gl_render_job_visit_node (job, start_node);
@@ -1554,7 +1554,7 @@ gsk_gl_render_job_visit_opacity_node (GskGLRenderJob *job,
       offscreen.reset_clip = TRUE;
       offscreen.autorelease = TRUE;
 
-      gsk_gl_render_job_render_offscreen (job, child, &offscreen);
+      gsk_gl_render_job_visit_node_with_offscreen (job, child, &offscreen);
 
       gsk_gl_program_begin_draw (job->driver->blit,
                                  &job->viewport,
@@ -1831,13 +1831,34 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
 }
 
 static gboolean
-gsk_gl_render_job_render_offscreen (GskGLRenderJob       *job,
-                                    GskRenderNode        *node,
-                                    GskGLRenderOffscreen *offscreen)
+gsk_gl_render_job_visit_node_with_offscreen (GskGLRenderJob       *job,
+                                             GskRenderNode        *node,
+                                             GskGLRenderOffscreen *offscreen)
 {
   g_assert (job != NULL);
   g_assert (node != NULL);
   g_assert (offscreen != NULL);
+  g_assert (offscreen->texture_id == 0);
+
+  if (node_is_invisible (node))
+    {
+      /* Just to be safe. */
+      offscreen->texture_id = 0;
+      offscreen->x = 0;
+      offscreen->x2 = 1;
+      offscreen->y = 0;
+      offscreen->y2 = 1;
+      return FALSE;
+    }
+
+  if (gsk_render_node_get_node_type (node) == GSK_TEXTURE_NODE &&
+      offscreen->force_offscreen == FALSE)
+    {
+      GdkTexture *texture = gsk_texture_node_get_texture (node);
+
+      offscreen->texture_id =
+        gsk_next_driver_load_texture (job->driver, texture, GL_LINEAR, GL_LINEAR);
+    }
 
   return FALSE;
 }
diff --git a/gsk/next/gskgltexturelibraryprivate.h b/gsk/next/gskgltexturelibraryprivate.h
index 9f8d002e58..4a0b92f4cf 100644
--- a/gsk/next/gskgltexturelibraryprivate.h
+++ b/gsk/next/gskgltexturelibraryprivate.h
@@ -29,6 +29,11 @@ G_BEGIN_DECLS
 
 G_DECLARE_DERIVABLE_TYPE (GskGLTextureLibrary, gsk_gl_texture_library, GSK, GL_TEXTURE_LIBRARY, GObject)
 
+struct _GskGLTextureAtlas
+{
+  guint texture_id;
+};
+
 struct _GskGLTextureLibraryClass
 {
   GObjectClass parent_class;
@@ -37,24 +42,26 @@ struct _GskGLTextureLibraryClass
   void (*end_frame)   (GskGLTextureLibrary *library);
 };
 
-GdkGLContext *gsk_gl_texture_library_get_context (GskGLTextureLibrary  *self);
-void          gsk_gl_texture_library_set_funcs   (GHashFunc             hash_func,
-                                                  GEqualFunc            equal_func);
-void          gsk_gl_texture_library_begin_frame (GskGLTextureLibrary  *self);
-void          gsk_gl_texture_library_end_frame   (GskGLTextureLibrary  *self);
-gboolean      gsk_gl_texture_library_pack        (GskGLTextureLibrary  *self,
-                                                  gconstpointer         key,
-                                                  gsize                 keylen,
-                                                  int                   width,
-                                                  int                   height,
-                                                  GskGLTextureAtlas   **atlas,
-                                                  int                  *atlas_x,
-                                                  int                  *atlas_y);
-gboolean      gsk_gl_texture_library_lookup      (GskGLTextureLibrary  *library,
-                                                  gconstpointer         key,
-                                                  GskGLTextureAtlas   **atlas,
-                                                  int                  *atlas_x,
-                                                  int                  *atlas_y);
+GdkGLContext *gsk_gl_texture_library_get_context (GskGLTextureLibrary    *self);
+void          gsk_gl_texture_library_set_funcs   (GHashFunc               hash_func,
+                                                  GEqualFunc              equal_func);
+void          gsk_gl_texture_library_begin_frame (GskGLTextureLibrary    *self);
+void          gsk_gl_texture_library_end_frame   (GskGLTextureLibrary    *self);
+gboolean      gsk_gl_texture_library_pack        (GskGLTextureLibrary    *self,
+                                                  gconstpointer           key,
+                                                  gsize                   keylen,
+                                                  float                   width,
+                                                  float                   height,
+                                                  GskGLTextureAtlas     **atlas,
+                                                  graphene_rect_t        *area);
+gboolean      gsk_gl_texture_library_lookup      (GskGLTextureLibrary    *library,
+                                                  gconstpointer           key,
+                                                  GskGLTextureAtlas     **atlas,
+                                                  graphene_rect_t        *area);
+void          gsk_gl_texture_library_upload      (GskGLTextureLibrary    *self,
+                                                  GskGLTextureAtlas      *atlas,
+                                                  const graphene_rect_t  *area,
+                                                  GdkTexture             *texture);
 
 G_END_DECLS
 


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