2 * Copyright (C) 2010 University of Szeged
3 * Copyright (C) 2010 Zoltan Herczeg
4 * Copyright (C) 2011 Renata Hodovan (reni@webkit.org)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #if ENABLE(SVG) && ENABLE(FILTERS)
31 #include "RenderSVGResourceFilterPrimitive.h"
33 #include "RenderSVGResource.h"
34 #include "SVGFEImage.h"
35 #include "SVGFilter.h"
41 void RenderSVGResourceFilterPrimitive::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
43 RenderSVGHiddenContainer::styleDidChange(diff, oldStyle);
45 RenderObject* filter = parent();
48 ASSERT(filter->isSVGResourceFilter());
50 if (diff == StyleDifferenceEqual || !oldStyle)
53 const SVGRenderStyle* newStyle = this->style()->svgStyle();
54 if (node()->hasTagName(SVGNames::feFloodTag)) {
55 if (newStyle->floodColor() != oldStyle->svgStyle()->floodColor())
56 static_cast<RenderSVGResourceFilter*>(filter)->primitiveAttributeChanged(this, SVGNames::flood_colorAttr);
57 if (newStyle->floodOpacity() != oldStyle->svgStyle()->floodOpacity())
58 static_cast<RenderSVGResourceFilter*>(filter)->primitiveAttributeChanged(this, SVGNames::flood_opacityAttr);
59 } else if (node()->hasTagName(SVGNames::feDiffuseLightingTag) || node()->hasTagName(SVGNames::feSpecularLightingTag)) {
60 if (newStyle->lightingColor() != oldStyle->svgStyle()->lightingColor())
61 static_cast<RenderSVGResourceFilter*>(filter)->primitiveAttributeChanged(this, SVGNames::lighting_colorAttr);
65 FloatRect RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(FilterEffect* effect)
68 FloatRect subregion = effect->effectBoundaries();
69 SVGFilter* filter = static_cast<SVGFilter*>(effect->filter());
72 if (effect->filterEffectType() != FilterEffectTypeTile) {
73 // FETurbulence, FEImage and FEFlood don't have input effects, take the filter region as unite rect.
74 if (unsigned numberOfInputEffects = effect->inputEffects().size()) {
75 for (unsigned i = 0; i < numberOfInputEffects; ++i)
76 uniteRect.unite(determineFilterPrimitiveSubregion(effect->inputEffect(i)));
78 uniteRect = filter->filterRegionInUserSpace();
80 determineFilterPrimitiveSubregion(effect->inputEffect(0));
81 uniteRect = filter->filterRegionInUserSpace();
85 subregion.setX(uniteRect.x());
87 subregion.setY(uniteRect.y());
88 if (!effect->hasWidth())
89 subregion.setWidth(uniteRect.width());
90 if (!effect->hasHeight())
91 subregion.setHeight(uniteRect.height());
92 effect->setFilterPrimitiveSubregion(subregion);
94 FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion);
95 FloatSize filterResolution = filter->filterResolution();
96 absoluteSubregion.scale(filterResolution.width(), filterResolution.height());
98 // FEImage needs the unclipped subregion in absolute coordinates to determine the correct
99 // destination rect in combination with preserveAspectRatio.
100 if (effect->filterEffectType() == FilterEffectTypeImage)
101 static_cast<FEImage*>(effect)->setAbsoluteSubregion(absoluteSubregion);
103 // Clip every filter effect to the filter region.
104 FloatRect absoluteScaledFilterRegion = filter->filterRegion();
105 absoluteScaledFilterRegion.scale(filterResolution.width(), filterResolution.height());
106 absoluteSubregion.intersect(absoluteScaledFilterRegion);
108 effect->setMaxEffectRect(absoluteSubregion);
112 } // namespace WebCore
114 #endif // ENABLE(SVG) && ENABLE(FILTERS)