summaryrefslogtreecommitdiffstats
path: root/src/widgets/icon.cpp
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2011-08-07 10:53:12 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2011-08-07 10:53:12 +0000
commit75976ea07dba9b97186667524d0a76603de416af (patch)
tree4cb68dabb3cb7d5219e6ed6b660f0ded13fc25d3 /src/widgets/icon.cpp
parentFix compilation (oops). (diff)
downloadinkscape-75976ea07dba9b97186667524d0a76603de416af.tar.gz
inkscape-75976ea07dba9b97186667524d0a76603de416af.zip
Rewrite NRArena -> Inkscape::Drawing. Call render and update
methods on the Drawing rather than on the root DrawingItem. (bzr r10347.1.25)
Diffstat (limited to '')
-rw-r--r--src/widgets/icon.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp
index fea825444..a57b56b5c 100644
--- a/src/widgets/icon.cpp
+++ b/src/widgets/icon.cpp
@@ -33,7 +33,7 @@
#include "display/cairo-utils.h"
#include "display/drawing-context.h"
#include "display/drawing-item.h"
-#include "display/nr-arena.h"
+#include "display/drawing.h"
#include "io/sys.h"
#include "sp-root.h"
@@ -1088,9 +1088,9 @@ static Geom::IntRect round_rect(Geom::Rect const &r)
return ret;
}
-// takes doc, root, icon, and icon name to produce pixels
+// takes doc, drawing, icon, and icon name to produce pixels
extern "C" guchar *
-sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root,
+sp_icon_doc_icon( SPDocument *doc, Inkscape::Drawing &drawing,
gchar const *name, unsigned psize,
unsigned &stride)
{
@@ -1115,8 +1115,8 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root,
if ( dbox ) {
/* Update to renderable state */
double sf = 1.0;
- root->setTransform(Geom::Scale(sf));
- root->update();
+ drawing.root()->setTransform(Geom::Scale(sf));
+ drawing.update();
/* Item integer bbox in points */
// NOTE: previously, each rect coordinate was rounded using floor(c + 0.5)
Geom::IntRect ibox = round_rect(*dbox);
@@ -1141,8 +1141,8 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root,
}
sf = (double)psize / (double)block;
- root->setTransform(Geom::Scale(sf));
- root->update();
+ drawing.root()->setTransform(Geom::Scale(sf));
+ drawing.update();
ibox = round_rect(*dbox * Geom::Scale(sf));
if ( dump ) {
@@ -1185,7 +1185,7 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root,
CAIRO_FORMAT_ARGB32, psize, psize, stride);
Inkscape::DrawingContext ct(s, ua.min());
- root->render(ct, ua, Inkscape::DrawingItem::RENDER_BYPASS_CACHE);
+ drawing.render(ct, ua);
cairo_surface_destroy(s);
// convert to GdkPixbuf format
@@ -1206,9 +1206,21 @@ sp_icon_doc_icon( SPDocument *doc, Inkscape::DrawingItem *root,
class SVGDocCache
{
public:
- SVGDocCache( SPDocument *doc, Inkscape::DrawingItem *root ) : doc(doc), root(root) {}
+ SVGDocCache( SPDocument *doc )
+ : doc(doc)
+ , visionkey(SPItem::display_key_new(1))
+ {
+ doc->doRef();
+ doc->ensureUpToDate();
+ drawing.setRoot(doc->getRoot()->invoke_show(drawing, visionkey, SP_ITEM_SHOW_DISPLAY ));
+ }
+ ~SVGDocCache() {
+ doc->getRoot()->invoke_hide(visionkey);
+ doc->doUnref();
+ }
SPDocument *doc;
- Inkscape::DrawingItem *root;
+ Inkscape::Drawing drawing;
+ unsigned visionkey;
};
static std::map<Glib::ustring, SVGDocCache *> doc_cache;
@@ -1275,27 +1287,14 @@ guchar *IconImpl::load_svg_pixels(std::list<Glib::ustring> const &names,
if ( dump ) {
g_message("Loaded icon file %s", doc_filename);
}
- // prep the document
- doc->ensureUpToDate();
-
- // Create new arena
- NRArena *arena = NRArena::create();
-
- // Create ArenaItem and set transform
- unsigned visionkey = SPItem::display_key_new(1);
- // fixme: Memory manage root if needed (Lauris)
- // This needs to be fixed indeed; this leads to a memory leak of a few megabytes these days
- // because shapes are being rendered which are not being freed
- Inkscape::DrawingItem *root = doc->getRoot()->invoke_show( arena, visionkey, SP_ITEM_SHOW_DISPLAY );
-
// store into the cache
- info = new SVGDocCache(doc, root);
+ info = new SVGDocCache(doc);
doc_cache[key] = info;
}
}
if (info) {
for (std::list<Glib::ustring>::const_iterator it = names.begin(); !px && (it != names.end()); ++it ) {
- px = sp_icon_doc_icon( info->doc, info->root, it->c_str(), psize, stride );
+ px = sp_icon_doc_icon( info->doc, info->drawing, it->c_str(), psize, stride );
}
}
}