[mutter/gbsneto/content: 109/111] window-content: Track subsurfaces invalidations



commit 4687c77265cb9106888711c6fbdfb0d1f7e7e91c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Dec 27 23:30:20 2018 -0200

    window-content: Track subsurfaces invalidations
    
    WIP

 src/compositor/meta-shaped-texture-private.h |  8 ++++
 src/compositor/meta-shaped-texture.c         | 36 +++++++++++++++
 src/compositor/meta-window-content.c         | 67 ++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
---
diff --git a/src/compositor/meta-shaped-texture-private.h b/src/compositor/meta-shaped-texture-private.h
index b8b68cda1..5da3a32e5 100644
--- a/src/compositor/meta-shaped-texture-private.h
+++ b/src/compositor/meta-shaped-texture-private.h
@@ -59,4 +59,12 @@ void _meta_shaped_texture_paint_node (MetaShapedTexture *stex,
                                       double             tex_scale,
                                       guchar             opacity);
 
+typedef void (*MetaShapedTextureInvalidateFunc) (MetaShapedTexture *stex,
+                                                 gboolean           size_changed,
+                                                 gpointer           user_data);
+
+void _meta_shaped_texture_set_invalidate_func (MetaShapedTexture               *stex,
+                                               MetaShapedTextureInvalidateFunc  func,
+                                               gpointer                         user_data);
+
 #endif
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index 92bee5c2b..2d340e0a7 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -106,6 +106,9 @@ struct _MetaShapedTexture
 
   double scale;
 
+  MetaShapedTextureInvalidateFunc invalidate_func;
+  gpointer invalidate_user_data;
+
   guint create_mipmaps : 1;
 };
 
@@ -1064,11 +1067,35 @@ meta_shaped_texture_detached (ClutterContent *content,
   g_message ("%s: Detached! (%u)", G_STRFUNC, shaped_texture->attached_actors);
 }
 
+static void
+meta_shaped_texture_invalidate (ClutterContent *content)
+{
+  MetaShapedTexture *stex = META_SHAPED_TEXTURE (content);
+
+  if (!stex->invalidate_func)
+    return;
+
+  stex->invalidate_func (stex, FALSE, stex->invalidate_user_data);
+}
+
+static void
+meta_shaped_texture_invalidate_size (ClutterContent *content)
+{
+  MetaShapedTexture *stex = META_SHAPED_TEXTURE (content);
+
+  if (!stex->invalidate_func)
+    return;
+
+  stex->invalidate_func (stex, TRUE, stex->invalidate_user_data);
+}
+
 static void
 clutter_content_iface_init (ClutterContentIface *iface)
 {
   iface->paint_content = meta_shaped_texture_paint_content;
   iface->get_preferred_size = meta_shaped_texture_get_preferred_size;
+  iface->invalidate = meta_shaped_texture_invalidate;
+  iface->invalidate_size = meta_shaped_texture_invalidate_size;
   iface->attached = meta_shaped_texture_attached;
   iface->detached = meta_shaped_texture_detached;
 }
@@ -1645,3 +1672,12 @@ _meta_shaped_texture_paint_node (MetaShapedTexture *stex,
 
   do_paint_content (stex, root_node, stex->texture, box, tex_scale, opacity);
 }
+
+void
+_meta_shaped_texture_set_invalidate_func (MetaShapedTexture               *stex,
+                                          MetaShapedTextureInvalidateFunc  func,
+                                          gpointer                         user_data)
+{
+  stex->invalidate_func = func;
+  stex->invalidate_user_data = user_data;
+}
diff --git a/src/compositor/meta-window-content.c b/src/compositor/meta-window-content.c
index 1b4b9d51a..1baf0432d 100644
--- a/src/compositor/meta-window-content.c
+++ b/src/compositor/meta-window-content.c
@@ -82,6 +82,53 @@ enum
 
 static GParamSpec *properties [N_PROPS];
 
+static void
+texture_invalidate_func (MetaShapedTexture *stex,
+                         gboolean           size_changed,
+                         gpointer           user_data)
+{
+  MetaWindowContent *window_content = (MetaWindowContent*) user_data;
+
+  if (window_content->attached_actors == 0)
+    return;
+
+  if (size_changed)
+    clutter_content_invalidate_size (CLUTTER_CONTENT (user_data));
+  else
+    clutter_content_invalidate (CLUTTER_CONTENT (user_data));
+}
+
+static void
+set_surface_invalidate_func (MetaWindowContent               *window_content,
+                             MetaSurfaceActor                *surface_actor,
+                             MetaShapedTextureInvalidateFunc  func)
+{
+  MetaShapedTexture *stex =
+    meta_surface_actor_get_texture (surface_actor);
+  ClutterActorIter iter;
+  ClutterActor *child;
+
+  _meta_shaped_texture_set_invalidate_func (stex, func, window_content);
+
+  clutter_actor_iter_init (&iter, CLUTTER_ACTOR (surface_actor));
+  while (clutter_actor_iter_next (&iter, &child))
+    set_surface_invalidate_func (window_content, META_SURFACE_ACTOR (child), func);
+}
+
+static void
+ensure_shaped_textures_invalidate_func (MetaWindowContent *window_content)
+{
+  MetaSurfaceActor *surface_actor =
+    meta_window_actor_get_surface (window_content->window_actor);
+
+  if (!surface_actor)
+    return;
+
+  set_surface_invalidate_func (window_content,
+                               surface_actor,
+                               texture_invalidate_func);
+}
+
 static void
 add_surface_paint_nodes (MetaSurfaceActor     *surface_actor,
                          ClutterActor         *actor,
@@ -158,6 +205,8 @@ meta_window_content_paint_content (ClutterContent   *content,
   if (!surface_actor)
     return;
 
+  ensure_shaped_textures_invalidate_func (window_content);
+
   /* Horizontal and vertical scales */
   clutter_actor_get_size (CLUTTER_ACTOR (surface_actor),
                           &width, &height);
@@ -182,6 +231,8 @@ meta_window_content_get_preferred_size (ClutterContent *content,
   if (!surface_actor)
     return FALSE;
 
+  ensure_shaped_textures_invalidate_func (window_content);
+
   clutter_actor_get_size (CLUTTER_ACTOR (surface_actor),
                           width, height);
   return TRUE;
@@ -194,6 +245,8 @@ meta_window_content_attached (ClutterContent *content,
   MetaWindowContent *window_content = META_WINDOW_CONTENT (content);
 
   window_content->attached_actors++;
+
+  ensure_shaped_textures_invalidate_func (window_content);
 }
 
 static void
@@ -255,11 +308,25 @@ meta_window_content_set_property (GObject      *object,
     }
 }
 
+static void
+meta_window_content_dispose (GObject *object)
+{
+  MetaWindowContent *window_content = META_WINDOW_CONTENT (object);
+  MetaSurfaceActor *surface_actor =
+    meta_window_actor_get_surface (window_content->window_actor);
+
+  if (surface_actor)
+    set_surface_invalidate_func (window_content, surface_actor, NULL);
+
+  G_OBJECT_CLASS (meta_window_content_parent_class)->dispose (object);
+}
+
 static void
 meta_window_content_class_init (MetaWindowContentClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->dispose = meta_window_content_dispose;
   object_class->get_property = meta_window_content_get_property;
   object_class->set_property = meta_window_content_set_property;
 


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