diff options
| author | Niko Kiirala <niko@kiirala.com> | 2007-05-21 09:39:52 +0000 |
|---|---|---|
| committer | kiirala <kiirala@users.sourceforge.net> | 2007-05-21 09:39:52 +0000 |
| commit | 2ac98237319c51ceb2a25d5a4821ef6afc0beb6e (patch) | |
| tree | 8ff0e8ad21cae00d3ff85127285f6279d2872dfe /src/display | |
| parent | committed patch 1629798 (diff) | |
| download | inkscape-2ac98237319c51ceb2a25d5a4821ef6afc0beb6e.tar.gz inkscape-2ac98237319c51ceb2a25d5a4821ef6afc0beb6e.zip | |
Refactoring work for filter effects renderer initialization
(bzr r3035)
Diffstat (limited to 'src/display')
| -rw-r--r-- | src/display/nr-arena-group.cpp | 80 | ||||
| -rw-r--r-- | src/display/nr-arena-image.cpp | 80 | ||||
| -rw-r--r-- | src/display/nr-arena-shape.cpp | 49 | ||||
| -rw-r--r-- | src/display/nr-filter.cpp | 37 | ||||
| -rw-r--r-- | src/display/nr-filter.h | 19 |
5 files changed, 100 insertions, 165 deletions
diff --git a/src/display/nr-arena-group.cpp b/src/display/nr-arena-group.cpp index 697ef6a05..da3a240a6 100644 --- a/src/display/nr-arena-group.cpp +++ b/src/display/nr-arena-group.cpp @@ -187,59 +187,30 @@ nr_arena_group_update (NRArenaItem *item, NRRectL *area, NRGC *gc, unsigned int void nr_arena_group_set_style (NRArenaGroup *group, SPStyle *style) { - g_return_if_fail(group != NULL); - g_return_if_fail(NR_IS_ARENA_GROUP(group)); - - if (style) sp_style_ref(style); - if (group->style) sp_style_unref(group->style); - group->style = style; - - //if there is a filter set for this group - if (style && style->filter.set && style->filter.filter) { - - group->filter = new NR::Filter(); - group->filter->set_x(style->filter.filter->x); - group->filter->set_y(style->filter.filter->y); - group->filter->set_width(style->filter.filter->width); - group->filter->set_height(style->filter.filter->height); - - //go through all SP filter primitives - for(int i=0; i<style->filter.filter->_primitive_count; i++) - { - SPFilterPrimitive *primitive = style->filter.filter->_primitives[i]; - //if primitive is gaussianblur - if(SP_IS_GAUSSIANBLUR(primitive)) - { - NR::FilterGaussian * gaussian = (NR::FilterGaussian *) group->filter->add_primitive(NR::NR_FILTER_GAUSSIANBLUR); - SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive); - float num = spblur->stdDeviation.getNumber(); - if( num>=0.0 ) - { - float optnum = spblur->stdDeviation.getOptNumber(); - if( optnum>=0.0 ) - gaussian->set_deviation((double) num, (double) optnum); - else - gaussian->set_deviation((double) num); - } - } else if(SP_IS_FEBLEND(primitive)) { - // TODO: this is just a test. Besides this whole filter - // creation needs to be redone - NR::FilterBlend *nrblend = (NR::FilterBlend *) group->filter->add_primitive(NR::NR_FILTER_BLEND); - SPFeBlend *spblend = SP_FEBLEND(primitive); - nrblend->set_mode(spblend->blend_mode); - } + g_return_if_fail(group != NULL); + g_return_if_fail(NR_IS_ARENA_GROUP(group)); + + if (style) sp_style_ref(style); + if (group->style) sp_style_unref(group->style); + group->style = style; + + //if group has a filter + if (style->filter.set && style->filter.filter) { + if (!group->filter) { + int primitives = sp_filter_primitive_count(style->filter.filter); + group->filter = new NR::Filter(primitives); } - } - else - { + sp_filter_build_renderer(style->filter.filter, group->filter); + } else { //no filter set for this group + delete group->filter; group->filter = NULL; } - - if (style && style->enable_background.set - && style->enable_background.value == SP_CSS_BACKGROUND_NEW) { - group->background_new = true; - } + + if (style && style->enable_background.set + && style->enable_background.value == SP_CSS_BACKGROUND_NEW) { + group->background_new = true; + } } static unsigned int @@ -314,4 +285,13 @@ void nr_arena_group_set_child_transform(NRArenaGroup *group, NRMatrix const *t) } } - +/* + 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:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena-image.cpp b/src/display/nr-arena-image.cpp index 964f7e86f..5f22dc5cd 100644 --- a/src/display/nr-arena-image.cpp +++ b/src/display/nr-arena-image.cpp @@ -360,57 +360,39 @@ nr_arena_image_set_geometry (NRArenaImage *image, double x, double y, double wid void nr_arena_image_set_style (NRArenaImage *image, SPStyle *style) { - g_return_if_fail(image != NULL); - g_return_if_fail(NR_IS_ARENA_IMAGE(image)); - - if (style) sp_style_ref(style); - if (image->style) sp_style_unref(image->style); - image->style = style; - - //if there is a filter set for this group - if (style && style->filter.set && style->filter.filter) { - - image->filter = new NR::Filter(); - image->filter->set_x(style->filter.filter->x); - image->filter->set_y(style->filter.filter->y); - image->filter->set_width(style->filter.filter->width); - image->filter->set_height(style->filter.filter->height); - - //go through all SP filter primitives - for(int i=0; i<style->filter.filter->_primitive_count; i++) - { - SPFilterPrimitive *primitive = style->filter.filter->_primitives[i]; - //if primitive is gaussianblur - if(SP_IS_GAUSSIANBLUR(primitive)) - { - NR::FilterGaussian * gaussian = (NR::FilterGaussian *) image->filter->add_primitive(NR::NR_FILTER_GAUSSIANBLUR); - SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive); - float num = spblur->stdDeviation.getNumber(); - if( num>=0.0 ) - { - float optnum = spblur->stdDeviation.getOptNumber(); - if( optnum>=0.0 ) - gaussian->set_deviation((double) num, (double) optnum); - else - gaussian->set_deviation((double) num); - } - } else if(SP_IS_FEBLEND(primitive)) { - // TODO: this is just a test. Besides this whole filter - // creation needs to be redone - NR::FilterBlend *nrblend = (NR::FilterBlend *) image->filter->add_primitive(NR::NR_FILTER_BLEND); - SPFeBlend *spblend = SP_FEBLEND(primitive); - nrblend->set_mode(spblend->blend_mode); - } + g_return_if_fail(image != NULL); + g_return_if_fail(NR_IS_ARENA_IMAGE(image)); + + if (style) sp_style_ref(style); + if (image->style) sp_style_unref(image->style); + image->style = style; + + //if image has a filter + if (style->filter.set && style->filter.filter) { + if (!image->filter) { + int primitives = sp_filter_primitive_count(style->filter.filter); + image->filter = new NR::Filter(primitives); } - } - else - { - //no filter set for this group + sp_filter_build_renderer(style->filter.filter, image->filter); + } else { + //no filter set for this image + delete image->filter; image->filter = NULL; } - if (style && style->enable_background.set - && style->enable_background.value == SP_CSS_BACKGROUND_NEW) { - image->background_new = true; - } + if (style && style->enable_background.set + && style->enable_background.value == SP_CSS_BACKGROUND_NEW) { + image->background_new = true; + } } + +/* + 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:encoding=utf-8:textwidth=99 : diff --git a/src/display/nr-arena-shape.cpp b/src/display/nr-arena-shape.cpp index 421627309..c09bdb9dd 100644 --- a/src/display/nr-arena-shape.cpp +++ b/src/display/nr-arena-shape.cpp @@ -28,15 +28,10 @@ #include <livarot/int-line.h> #include <style.h> #include "prefs-utils.h" -#include "sp-filter.h" #include "inkscape-cairo.h" +#include "sp-filter.h" #include "display/nr-filter.h" -#include "display/nr-filter-gaussian.h" -#include "display/nr-filter-types.h" -#include "sp-gaussian-blur.h" -#include "sp-feblend.h" -#include "display/nr-filter-blend.h" #include <cairo.h> @@ -1364,43 +1359,15 @@ nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style) shape->setMitreLimit(style->stroke_miterlimit.value); //if shape has a filter - if (style->filter.set && style->filter.filter) - { - shape->filter = new NR::Filter(); - shape->filter->set_x(style->filter.filter->x); - shape->filter->set_y(style->filter.filter->y); - shape->filter->set_width(style->filter.filter->width); - shape->filter->set_height(style->filter.filter->height); - - //go through all SP filter primitives - for(int i=0; i<style->filter.filter->_primitive_count; i++) - { - SPFilterPrimitive *primitive = style->filter.filter->_primitives[i]; - //if primitive is gaussianblur - if(SP_IS_GAUSSIANBLUR(primitive)) { - NR::FilterGaussian * gaussian = (NR::FilterGaussian *) shape->filter->add_primitive(NR::NR_FILTER_GAUSSIANBLUR); - SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive); - float num = spblur->stdDeviation.getNumber(); - if( num>=0.0 ) - { - float optnum = spblur->stdDeviation.getOptNumber(); - if( optnum>=0.0 ) - gaussian->set_deviation((double) num, (double) optnum); - else - gaussian->set_deviation((double) num); - } - } else if(SP_IS_FEBLEND(primitive)) { - // TODO: this is just a test. Besides this whole filter - // creation needs to be redone - NR::FilterBlend *nrblend = (NR::FilterBlend *) shape->filter->add_primitive(NR::NR_FILTER_BLEND); - SPFeBlend *spblend = SP_FEBLEND(primitive); - nrblend->set_mode(spblend->blend_mode); - } + if (style->filter.set && style->filter.filter) { + if (!shape->filter) { + int primitives = sp_filter_primitive_count(style->filter.filter); + shape->filter = new NR::Filter(primitives); } - } - else - { + sp_filter_build_renderer(style->filter.filter, shape->filter); + } else { //no filter set for this shape + delete shape->filter; shape->filter = NULL; } diff --git a/src/display/nr-filter.cpp b/src/display/nr-filter.cpp index fe33afff0..515d5961f 100644 --- a/src/display/nr-filter.cpp +++ b/src/display/nr-filter.cpp @@ -348,14 +348,14 @@ void Filter::_enlarge_primitive_table() { _primitive = new_tbl; } -FilterPrimitive *Filter::add_primitive(FilterPrimitiveType type) +int Filter::add_primitive(FilterPrimitiveType type) { _create_constructor_table(); // Check that we can create a new filter of specified type if (type < 0 || type >= NR_FILTER_ENDPRIMITIVETYPE) - return NULL; - if (!_constructor[type]) return NULL; + return -1; + if (!_constructor[type]) return -1; FilterPrimitive *created = _constructor[type](); // If there is no space for new filter primitive, enlarge the table @@ -364,28 +364,24 @@ FilterPrimitive *Filter::add_primitive(FilterPrimitiveType type) } _primitive[_primitive_count] = created; + int handle = _primitive_count; _primitive_count++; - return created; + return handle; } -FilterPrimitive *Filter::replace_primitive(FilterPrimitive *target, FilterPrimitiveType type) +int Filter::replace_primitive(int target, FilterPrimitiveType type) { _create_constructor_table(); // Check that target is valid primitive inside this filter - int place = -1; - for (int i = 0 ; i < _primitive_count ; i++) { - if (target == _primitive[i]) { - place = i; - break; - } - } - if (place < 0) return NULL; + if (target < 0) return -1; + if (target >= _primitive_count) return -1; + if (!_primitive[target]) return -1; // Check that we can create a new filter of specified type if (type < 0 || type >= NR_FILTER_ENDPRIMITIVETYPE) - return NULL; - if (!_constructor[type]) return NULL; + return -1; + if (!_constructor[type]) return -1; FilterPrimitive *created = _constructor[type](); // If there is no space for new filter primitive, enlarge the table @@ -393,9 +389,14 @@ FilterPrimitive *Filter::replace_primitive(FilterPrimitive *target, FilterPrimit _enlarge_primitive_table(); } - delete target; - _primitive[place] = created; - return created; + delete _primitive[target]; + _primitive[target] = created; + return target; +} + +FilterPrimitive *Filter::get_primitive(int handle) { + if (handle < 0 || handle >= _primitive_count) return NULL; + return _primitive[handle]; } void Filter::clear_primitives() diff --git a/src/display/nr-filter.h b/src/display/nr-filter.h index c1012475c..a6f71b9a5 100644 --- a/src/display/nr-filter.h +++ b/src/display/nr-filter.h @@ -37,11 +37,11 @@ public: * Should this filter not have enough space for a new primitive, the filter * is enlarged to accomodate the new filter element. It may be enlarged by * more that one element. - * Returns a pointer to the filter primitive created. - * Returns NULL, if type is not valid filter primitive type or filter + * Returns a handle (non-negative integer) to the filter primitive created. + * Returns -1, if type is not valid filter primitive type or filter * primitive of such type cannot be created. */ - FilterPrimitive *add_primitive(FilterPrimitiveType type); + int add_primitive(FilterPrimitiveType type); /** * Removes all filter primitives from this filter. * All pointers to filter primitives inside this filter should be @@ -54,14 +54,19 @@ public: * If 'target' does not correspond to any primitive inside this filter OR * 'type' is not a valid filter primitive type OR * filter primitive of such type cannot be created, - * this function returns NULL and doesn't change the internal state of this + * this function returns -1 and doesn't change the internal state of this * filter. * Otherwise, a new filter primitive is created. Any pointers to filter - * primitive 'target' should be considered invalid. A pointer to the + * primitive 'target' should be considered invalid. A handle to the * newly created primitive is returned. */ - FilterPrimitive *replace_primitive(FilterPrimitive *primitive, - FilterPrimitiveType type); + int replace_primitive(int primitive, FilterPrimitiveType type); + + /** + * Returns a pointer to the primitive, which the handle corrensponds to. + * If the handle is not valid, returns NULL. + */ + FilterPrimitive *get_primitive(int handle); /** * Sets the slot number 'slot' to be used as result from this filter. |
