[Xfce4-commits] [apps/xfdashboard] 01/01: Remove window content cache because since XfdashboardWindowTrackerWindow is a real object (and not a pseudo-object sharing the same GType as WnckWindow) we have a "content cache" for each object instance via private variables.
noreply at xfce.org
noreply at xfce.org
Thu May 4 07:56:17 CEST 2017
This is an automated email from the git hooks/post-receive script.
nomad pushed a commit to branch master
in repository apps/xfdashboard.
commit 796d62017edc74c92e19d61ab0e99d74f4cdd72a
Author: Stephan Haller <nomad at froevel.de>
Date: Thu May 4 07:54:50 2017 +0200
Remove window content cache because since XfdashboardWindowTrackerWindow is a real object (and not a pseudo-object sharing the same GType as WnckWindow) we have a "content cache" for each object instance via private variables.
---
libxfdashboard/x11/window-content-x11.c | 98 --------------------------
libxfdashboard/x11/window-tracker-window-x11.c | 58 +++++++++++++--
2 files changed, 54 insertions(+), 102 deletions(-)
diff --git a/libxfdashboard/x11/window-content-x11.c b/libxfdashboard/x11/window-content-x11.c
index ce40636..65e7bc4 100644
--- a/libxfdashboard/x11/window-content-x11.c
+++ b/libxfdashboard/x11/window-content-x11.c
@@ -168,9 +168,6 @@ static gboolean _xfdashboard_window_content_x11_have_composite_extension
static gboolean _xfdashboard_window_content_x11_have_damage_extension=FALSE;
static int _xfdashboard_window_content_x11_damage_event_base=0;
-static GHashTable* _xfdashboard_window_content_x11_cache=NULL;
-static guint _xfdashboard_window_content_x11_cache_shutdown_signal_id=0;
-
static GList* _xfdashboard_window_content_x11_resume_idle_queue=NULL;
static guint _xfdashboard_window_content_x11_resume_idle_id=0;
static guint _xfdashboard_window_content_x11_resume_shutdown_signal_id=0;
@@ -1472,67 +1469,6 @@ static void _xfdashboard_window_content_x11_set_window(XfdashboardWindowContentX
_xfdashboard_window_content_x11_setup_workaround(self, inWindow);
}
-/* Destroy cache hashtable */
-static void _xfdashboard_window_content_x11_destroy_cache(void)
-{
- XfdashboardApplication *application;
- gint cacheSize;
-
- /* Only an existing cache can be destroyed */
- if(!_xfdashboard_window_content_x11_cache) return;
-
- /* Disconnect application "shutdown" signal handler */
- application=xfdashboard_application_get_default();
- g_signal_handler_disconnect(application, _xfdashboard_window_content_x11_cache_shutdown_signal_id);
- _xfdashboard_window_content_x11_cache_shutdown_signal_id=0;
-
- /* Destroy cache hashtable */
- cacheSize=g_hash_table_size(_xfdashboard_window_content_x11_cache);
- if(cacheSize>0) g_warning(_("Destroying window content cache still containing %d windows."), cacheSize);
-#ifdef DEBUG
- if(cacheSize>0)
- {
- GHashTableIter iter;
- gpointer key, value;
- XfdashboardWindowContentX11 *content;
- XfdashboardWindowTrackerWindow *window;
-
- g_hash_table_iter_init(&iter, _xfdashboard_window_content_x11_cache);
- while(g_hash_table_iter_next (&iter, &key, &value))
- {
- content=XFDASHBOARD_WINDOW_CONTENT_X11(value);
- window=xfdashboard_window_content_x11_get_window(content);
- g_print("Window content in cache: Item %s@%p for window '%s'\n",
- G_OBJECT_TYPE_NAME(content), content,
- xfdashboard_window_tracker_window_get_name(window));
- }
- }
-#endif
-
- XFDASHBOARD_DEBUG(NULL, WINDOWS, "Destroying window content cache hashtable");
- g_hash_table_destroy(_xfdashboard_window_content_x11_cache);
- _xfdashboard_window_content_x11_cache=NULL;
-}
-
-/* Create cache hashtable if not already set up */
-static void _xfdashboard_window_content_x11_create_cache(void)
-{
- XfdashboardApplication *application;
-
- /* Cache was already set up */
- if(_xfdashboard_window_content_x11_cache) return;
-
- /* Create create hashtable */
- _xfdashboard_window_content_x11_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
- XFDASHBOARD_DEBUG(NULL, WINDOWS, "Created window content cache hashtable");
-
- /* Connect to "shutdown" signal of application to clean up hashtable */
- application=xfdashboard_application_get_default();
- _xfdashboard_window_content_x11_cache_shutdown_signal_id=g_signal_connect(application,
- "shutdown-final",
- G_CALLBACK(_xfdashboard_window_content_x11_destroy_cache),
- NULL);
-}
/* IMPLEMENTATION: ClutterContent */
@@ -1916,13 +1852,6 @@ static void _xfdashboard_window_content_x11_dispose(GObject *inObject)
if(priv->window)
{
- /* Remove from cache */
- XFDASHBOARD_DEBUG(self, WINDOWS,
- "Removing window content for window '%s' with ref-count %d" ,
- xfdashboard_window_tracker_window_get_name(XFDASHBOARD_WINDOW_TRACKER_WINDOW(priv->window)),
- G_OBJECT(self)->ref_count);
- g_hash_table_remove(_xfdashboard_window_content_x11_cache, priv->window);
-
/* Disconnect signals */
g_signal_handlers_disconnect_by_data(priv->window, self);
@@ -2319,37 +2248,10 @@ ClutterContent* xfdashboard_window_content_x11_new_for_window(XfdashboardWindowT
g_return_val_if_fail(XFDASHBOARD_IS_WINDOW_TRACKER_WINDOW_X11(inWindow), NULL);
- /* If we a hash table (cache) set up lookup if window content is already cached
- * and return a new reference to it
- */
- if(_xfdashboard_window_content_x11_cache &&
- g_hash_table_contains(_xfdashboard_window_content_x11_cache, inWindow))
- {
- content=CLUTTER_CONTENT(g_hash_table_lookup(_xfdashboard_window_content_x11_cache, inWindow));
- g_object_ref(content);
- XFDASHBOARD_DEBUG(content, WINDOWS,
- "Using cached window content for '%s' - ref-count is now %d" ,
- xfdashboard_window_tracker_window_get_name(XFDASHBOARD_WINDOW_TRACKER_WINDOW(XFDASHBOARD_WINDOW_CONTENT_X11(content)->priv->window)),
- G_OBJECT(content)->ref_count);
-
- return(content);
- }
-
/* Create window content */
content=CLUTTER_CONTENT(g_object_new(XFDASHBOARD_TYPE_WINDOW_CONTENT_X11,
"window", inWindow,
NULL));
- g_return_val_if_fail(content, NULL);
-
- /* Create cache if not available */
- if(!_xfdashboard_window_content_x11_cache) _xfdashboard_window_content_x11_create_cache();
-
- /* Store new window content into cache */
- g_hash_table_insert(_xfdashboard_window_content_x11_cache, inWindow, content);
- XFDASHBOARD_DEBUG(content, WINDOWS,
- "Added window content for '%s' with ref-count %d" ,
- xfdashboard_window_tracker_window_get_name(XFDASHBOARD_WINDOW_TRACKER_WINDOW(inWindow)),
- G_OBJECT(content)->ref_count);
return(content);
}
diff --git a/libxfdashboard/x11/window-tracker-window-x11.c b/libxfdashboard/x11/window-tracker-window-x11.c
index 738e936..50787fc 100644
--- a/libxfdashboard/x11/window-tracker-window-x11.c
+++ b/libxfdashboard/x11/window-tracker-window-x11.c
@@ -86,6 +86,8 @@ struct _XfdashboardWindowTrackerWindowX11Private
gint lastGeometryY;
gint lastGeometryWidth;
gint lastGeometryHeight;
+
+ ClutterContent *content;
};
@@ -728,6 +730,22 @@ static void _xfdashboard_window_tracker_window_x11_set_window(XfdashboardWindowT
/* Set value if changed */
if(priv->window!=inWindow)
{
+ /* If we have created a content for this window then remove weak reference
+ * and reset content variable to NULL. First call to get window content
+ * will recreate it. Already used contents will not be affected.
+ */
+ if(priv->content)
+ {
+ XFDASHBOARD_DEBUG(self, WINDOWS,
+ "Removing cached content with ref-count %d from %s@%p for wnck-window %p because wnck-window will change to %p",
+ G_OBJECT(priv->content)->ref_count,
+ G_OBJECT_TYPE_NAME(self), self,
+ priv->window,
+ inWindow);
+ g_object_remove_weak_pointer(G_OBJECT(priv->content), (gpointer*)&priv->content);
+ priv->content=NULL;
+ }
+
/* Disconnect signals to old window (if available) and reset states */
if(priv->window)
{
@@ -1353,7 +1371,6 @@ static ClutterContent* _xfdashboard_window_tracker_window_x11_window_tracker_win
{
XfdashboardWindowTrackerWindowX11 *self;
XfdashboardWindowTrackerWindowX11Private *priv;
- ClutterContent *content;
g_return_val_if_fail(XFDASHBOARD_IS_WINDOW_TRACKER_WINDOW_X11(inWindow), NULL);
@@ -1367,11 +1384,32 @@ static ClutterContent* _xfdashboard_window_tracker_window_x11_window_tracker_win
return(NULL);
}
- /* Create content for window */
- content=xfdashboard_window_content_x11_new_for_window(self);
+ /* Create content for window only if no content is already available. If it
+ * is available just return it with taking an extra reference on it.
+ */
+ if(!priv->content)
+ {
+ priv->content=xfdashboard_window_content_x11_new_for_window(self);
+ g_object_add_weak_pointer(G_OBJECT(priv->content), (gpointer*)&priv->content);
+ XFDASHBOARD_DEBUG(self, WINDOWS,
+ "Created content %s@%p for window %s@%p (wnck-window=%p)",
+ priv->content ? G_OBJECT_TYPE_NAME(priv->content) : "<unknown>", priv->content,
+ G_OBJECT_TYPE_NAME(self), self,
+ priv->window);
+ }
+ else
+ {
+ g_object_ref(priv->content);
+ XFDASHBOARD_DEBUG(self, WINDOWS,
+ "Using cached content %s@%p (ref-count=%d) for window %s@%p (wnck-window=%p)",
+ priv->content ? G_OBJECT_TYPE_NAME(priv->content) : "<unknown>", priv->content,
+ priv->content ? G_OBJECT(priv->content)->ref_count : 0,
+ G_OBJECT_TYPE_NAME(self), self,
+ priv->window);
+ }
/* Return content */
- return(content);
+ return(priv->content);
}
/* Get associated stage of window */
@@ -1651,6 +1689,17 @@ static void _xfdashboard_window_tracker_window_x11_dispose(GObject *inObject)
XfdashboardWindowTrackerWindowX11Private *priv=self->priv;
/* Dispose allocated resources */
+ if(priv->content)
+ {
+ XFDASHBOARD_DEBUG(self, WINDOWS,
+ "Removing cached content with ref-count %d from %s@%p for wnck-window %p",
+ G_OBJECT(priv->content)->ref_count,
+ G_OBJECT_TYPE_NAME(self), self,
+ priv->window);
+ g_object_remove_weak_pointer(G_OBJECT(priv->content), (gpointer*)&priv->content);
+ priv->content=NULL;
+ }
+
if(priv->window)
{
/* Remove weak reference at current window */
@@ -1758,6 +1807,7 @@ void xfdashboard_window_tracker_window_x11_init(XfdashboardWindowTrackerWindowX1
/* Set default values */
priv->window=NULL;
+ priv->content=NULL;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list