From 75976ea07dba9b97186667524d0a76603de416af Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 7 Aug 2011 12:53:12 +0200 Subject: Rewrite NRArena -> Inkscape::Drawing. Call render and update methods on the Drawing rather than on the root DrawingItem. (bzr r10347.1.25) --- src/display/drawing.cpp | 159 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 src/display/drawing.cpp (limited to 'src/display/drawing.cpp') diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp new file mode 100644 index 000000000..22bd84587 --- /dev/null +++ b/src/display/drawing.cpp @@ -0,0 +1,159 @@ +/** + * @file + * @brief SVG drawing for display + *//* + * Authors: + * Krzysztof KosiƄski + * + * Copyright (C) 2011 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/drawing.h" +#include "nr-filter-gaussian.h" +#include "nr-filter-types.h" + +namespace Inkscape { + +Drawing::Drawing(SPCanvasArena *arena) + : _root(NULL) + , outlinecolor(0x000000ff) + , delta(0) + , _exact(false) + , _rendermode(RENDERMODE_NORMAL) + , _colormode(COLORMODE_NORMAL) + , _blur_quality(BLUR_QUALITY_BEST) + , _filter_quality(Filters::FILTER_QUALITY_BEST) + , _canvasarena(arena) +{ + +} + +Drawing::~Drawing() +{ + delete _root; +} + +void +Drawing::setRoot(DrawingItem *item) +{ + delete _root; + _root = item; + _root->_drawing_root = true; +} + +RenderMode +Drawing::renderMode() const +{ + return _exact ? RENDERMODE_NORMAL : _rendermode; +} +ColorMode +Drawing::colorMode() const +{ + return (outline() || _exact) ? COLORMODE_NORMAL : _colormode; +} +bool +Drawing::outline() const +{ + return renderMode() == RENDERMODE_OUTLINE; +} +bool +Drawing::renderFilters() const +{ + return renderMode() == RENDERMODE_NORMAL; +} +int +Drawing::blurQuality() const +{ + if (renderMode() == RENDERMODE_NORMAL) { + return _exact ? BLUR_QUALITY_BEST : _blur_quality; + } else { + return BLUR_QUALITY_WORST; + } +} +int +Drawing::filterQuality() const +{ + if (renderMode() == RENDERMODE_NORMAL) { + return _exact ? Filters::FILTER_QUALITY_BEST : _filter_quality; + } else { + return Filters::FILTER_QUALITY_WORST; + } +} + +void +Drawing::setRenderMode(RenderMode mode) +{ + _rendermode = mode; +} +void +Drawing::setColorMode(ColorMode mode) +{ + _colormode = mode; +} +void +Drawing::setBlurQuality(int q) +{ + _blur_quality = q; +} +void +Drawing::setFilterQuality(int q) +{ + _filter_quality = q; +} +void +Drawing::setExact(bool e) +{ + _exact = e; +} + +Geom::OptIntRect const & +Drawing::cacheLimit() const +{ + return _cache_limit; +} +void +Drawing::setCacheLimit(Geom::OptIntRect const &r) +{ + _cache_limit = r; + for (std::set::iterator i = _cached_items.begin(); + i != _cached_items.end(); ++i) + { + (*i)->_markForUpdate(DrawingItem::STATE_CACHE, false); + } +} + +void +Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset) +{ + // TODO add autocache + if (!_root) return; + _root->update(area, ctx, flags, reset); +} + +void +Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) +{ + if (!_root) return; + _root->render(ct, area, flags); +} + +DrawingItem * +Drawing::pick(Geom::Point const &p, double delta, bool sticky) +{ + if (!_root) return NULL; + return _root->pick(p, delta, sticky); +} + +} // end namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From f336c94939e9740501835b2584ad9a3160ac6d51 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 9 Aug 2011 03:14:07 +0200 Subject: Initial autocache work (bzr r10347.1.26) --- src/display/drawing.cpp | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'src/display/drawing.cpp') diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 22bd84587..5881c84ed 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -9,6 +9,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "display/drawing.h" #include "nr-filter-gaussian.h" #include "nr-filter-types.h" @@ -24,6 +25,8 @@ Drawing::Drawing(SPCanvasArena *arena) , _colormode(COLORMODE_NORMAL) , _blur_quality(BLUR_QUALITY_BEST) , _filter_quality(Filters::FILTER_QUALITY_BEST) + , _cache_score_threshold(50000.0) + , _cache_budget(128 << 20) // 128 MiB , _canvasarena(arena) { @@ -126,23 +129,51 @@ Drawing::setCacheLimit(Geom::OptIntRect const &r) void Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset) { - // TODO add autocache - if (!_root) return; - _root->update(area, ctx, flags, reset); + if (_root) { + _root->update(area, ctx, flags, reset); + } + // process the updated cache scores + // we cache the objects with the highest score until the budget is exhausted + _candidate_items.sort(std::greater()); + size_t used = 0; + CandidateList::iterator i; + for (i = _candidate_items.begin(); i != _candidate_items.end(); ++i) { + if (used + i->cache_size > _cache_budget) break; + used += i->cache_size; + } + + std::set to_cache; + for (i = _candidate_items.begin(); i != _candidate_items.end(); ++i) { + i->item->setCached(true); + to_cache.insert(i->item); + } + // Everything which is now in _cached_items but not in to_cache must be uncached + // Note that calling setCached on an item modifies _cached_items + // TODO: find a way to avoid the set copy + std::set to_uncache; + std::set_difference(_cached_items.begin(), _cached_items.end(), + to_cache.begin(), to_cache.end(), + std::inserter(to_uncache, to_uncache.end())); + for (std::set::iterator j = to_uncache.begin(); j != to_uncache.end(); ++j) { + (*j)->setCached(false); + } } void Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) { - if (!_root) return; - _root->render(ct, area, flags); + if (_root) { + _root->render(ct, area, flags); + } } DrawingItem * Drawing::pick(Geom::Point const &p, double delta, bool sticky) { - if (!_root) return NULL; - return _root->pick(p, delta, sticky); + if (_root) { + return _root->pick(p, delta, sticky); + } + return NULL; } } // end namespace Inkscape -- cgit v1.2.3 From caa510445fc091c63e1ca0ff8f44f2e81ae0638d Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 13 Aug 2011 20:30:30 +0200 Subject: More generic handling of child type in DrawingItem. Fix clip object selection bug (LP #365458). Fixed bugs: - https://launchpad.net/bugs/365458 (bzr r10347.1.31) --- src/display/drawing.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/display/drawing.cpp') diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 5881c84ed..e1a17edf1 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -42,7 +42,10 @@ Drawing::setRoot(DrawingItem *item) { delete _root; _root = item; - _root->_drawing_root = true; + if (item) { + assert(item->_child_type == DrawingItem::CHILD_ORPHAN); + item->_child_type = DrawingItem::CHILD_ROOT; + } } RenderMode @@ -168,10 +171,10 @@ Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) } DrawingItem * -Drawing::pick(Geom::Point const &p, double delta, bool sticky) +Drawing::pick(Geom::Point const &p, double delta, unsigned flags) { if (_root) { - return _root->pick(p, delta, sticky); + return _root->pick(p, delta, flags); } return NULL; } -- cgit v1.2.3 From dc713ea50efc5fd3f041db05ff92d31a3a54dc5b Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 16 Aug 2011 06:04:53 +0200 Subject: Add user preference for rendering cache size (bzr r10347.1.34) --- src/display/drawing.cpp | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'src/display/drawing.cpp') diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index e1a17edf1..06183fed2 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -26,7 +26,7 @@ Drawing::Drawing(SPCanvasArena *arena) , _blur_quality(BLUR_QUALITY_BEST) , _filter_quality(Filters::FILTER_QUALITY_BEST) , _cache_score_threshold(50000.0) - , _cache_budget(128 << 20) // 128 MiB + , _cache_budget(0) , _canvasarena(arena) { @@ -128,6 +128,12 @@ Drawing::setCacheLimit(Geom::OptIntRect const &r) (*i)->_markForUpdate(DrawingItem::STATE_CACHE, false); } } +void +Drawing::setCacheBudget(size_t bytes) +{ + _cache_budget = bytes; + _pickItemsForCaching(); +} void Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset) @@ -136,6 +142,29 @@ Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned fl _root->update(area, ctx, flags, reset); } // process the updated cache scores + _pickItemsForCaching(); +} + +void +Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) +{ + if (_root) { + _root->render(ct, area, flags); + } +} + +DrawingItem * +Drawing::pick(Geom::Point const &p, double delta, unsigned flags) +{ + if (_root) { + return _root->pick(p, delta, flags); + } + return NULL; +} + +void +Drawing::_pickItemsForCaching() +{ // we cache the objects with the highest score until the budget is exhausted _candidate_items.sort(std::greater()); size_t used = 0; @@ -162,23 +191,6 @@ Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned fl } } -void -Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) -{ - if (_root) { - _root->render(ct, area, flags); - } -} - -DrawingItem * -Drawing::pick(Geom::Point const &p, double delta, unsigned flags) -{ - if (_root) { - return _root->pick(p, delta, flags); - } - return NULL; -} - } // end namespace Inkscape /* -- cgit v1.2.3