KDE/kdelibs/plasma

Aaron J. Seigo aseigo at kde.org
Thu Oct 14 14:09:23 CEST 2010


SVN commit 1185856 by aseigo:

handle the caching case in setImagePath properly; this is a significant increase in complexity in this rather fundamental method. in combination with the change in Svg::setImagePath to call FrameSvg::setImagePath directly (due to an API wart i only today noticed), this has the potential to cause new issues, though it is running quite nicely on my system. needs extensive testing, but should also hopefully take care of the remaining crash being seen related to the FrameData cache
CCMAIL:plasma-devel at kde.org


 M  +50 -6     framesvg.cpp  
 M  +1 -0      svg.h  


--- trunk/KDE/kdelibs/plasma/framesvg.cpp #1185855:1185856
@@ -1,6 +1,6 @@
 /*
- *   Copyright 2008 by Aaron Seigo <aseigo at kde.org>
- *   Copyright 2008 Marco Martin <notmart at gmail.com>
+ *   Copyright 2008-2010 by Aaron Seigo <aseigo at kde.org>
+ *   Copyright 2008-2010 Marco Martin <notmart at gmail.com>
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU Library General Public License as
@@ -32,8 +32,9 @@
 
 #include <kdebug.h>
 
-#include <plasma/theme.h>
-#include <plasma/applet.h>
+#include <applet.h>
+#include <theme.h>
+#include <private/svg_p.h>
 
 namespace Plasma
 {
@@ -64,12 +65,55 @@
         return;
     }
 
-    Svg::setImagePath(path);
+    bool updateNeeded = true;
+    clearCache();
+
+    FrameData *fd = d->frames[d->prefix];
+    if (fd->refcount() == 1) {
+        // we're the only user of it, let's remove it from the shared keys
+        // we don't want to deref it, however, as we'll still be using it
+        const QString oldKey = d->cacheId(fd, d->prefix);
+        FrameSvgPrivate::s_sharedFrames.remove(oldKey);
+    } else {
+        // others are using this frame, so deref it for ourselves
+        fd->deref(this);
+        fd = 0;
+    }
+
+    Svg::d->setImagePath(path);
+
+    if (!fd) {
+        // we need to replace our frame, start by looking in the frame cache
+        const QString key = d->cacheId(fd, d->prefix);
+        fd = FrameSvgPrivate::s_sharedFrames.value(key);
+
+        if (fd) {
+            // we found one, so ref it and use it; we also don't need to (or want to!)
+            // trigger a full update of the frame since it is already the one we want
+            // and likely already rendered just fine
+            fd->ref(this);
+            updateNeeded = false;
+        } else {
+            // nothing exists for us in the cache, so create a new FrameData based
+            // on the old one
+            fd = new FrameData(*d->frames[d->prefix], this);
+        }
+
+        d->frames.insert(d->prefix, fd);
+    }
+
     setContainsMultipleImages(true);
+    if (updateNeeded) {
+        // ensure our frame is in the cache
+        const QString key = d->cacheId(fd, d->prefix);
+        FrameSvgPrivate::s_sharedFrames.insert(key, fd);
 
-    clearCache();
+        // this will emit repaintNeeded() as well when it is done
     d->updateAndSignalSizes();
+    } else {
+        emit repaintNeeded();
 }
+}
 
 void FrameSvg::setEnabledBorders(const EnabledBorders borders)
 {
--- trunk/KDE/kdelibs/plasma/svg.h #1185855:1185856
@@ -264,6 +264,7 @@
 
         friend class SvgPrivate;
         friend class FrameSvgPrivate;
+        friend class FrameSvg;
 };
 
 } // Plasma namespace


More information about the Plasma-devel mailing list