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 subregionBoundingBox = effect->effectBoundaries();
69 FloatRect subregion = subregionBoundingBox;
70 SVGFilter* filter = static_cast<SVGFilter*>(effect->filter());
73 if (effect->filterEffectType() != FilterEffectTypeTile) {
74 // FETurbulence, FEImage and FEFlood don't have input effects, take the filter region as unite rect.
75 if (unsigned numberOfInputEffects = effect->inputEffects().size()) {
76 for (unsigned i = 0; i < numberOfInputEffects; ++i)
77 uniteRect.unite(determineFilterPrimitiveSubregion(effect->inputEffect(i)));
79 uniteRect = filter->filterRegionInUserSpace();
81 determineFilterPrimitiveSubregion(effect->inputEffect(0));
82 uniteRect = filter->filterRegionInUserSpace();
85 if (filter->effectBoundingBoxMode()) {
86 subregion = uniteRect;
87 // Avoid the calling of a virtual method several times.
88 FloatRect targetBoundingBox = filter->targetBoundingBox();
91 subregion.setX(targetBoundingBox.x() + subregionBoundingBox.x() * targetBoundingBox.width());
94 subregion.setY(targetBoundingBox.y() + subregionBoundingBox.y() * targetBoundingBox.height());
96 if (effect->hasWidth())
97 subregion.setWidth(subregionBoundingBox.width() * targetBoundingBox.width());
99 if (effect->hasHeight())
100 subregion.setHeight(subregionBoundingBox.height() * targetBoundingBox.height());
103 subregion.setX(uniteRect.x());
106 subregion.setY(uniteRect.y());
108 if (!effect->hasWidth())
109 subregion.setWidth(uniteRect.width());
111 if (!effect->hasHeight())
112 subregion.setHeight(uniteRect.height());
115 effect->setFilterPrimitiveSubregion(subregion);
117 FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion);
118 FloatSize filterResolution = filter->filterResolution();
119 absoluteSubregion.scale(filterResolution.width(), filterResolution.height());
121 // FEImage needs the unclipped subregion in absolute coordinates to determine the correct
122 // destination rect in combination with preserveAspectRatio.
123 if (effect->filterEffectType() == FilterEffectTypeImage)
124 static_cast<FEImage*>(effect)->setAbsoluteSubregion(absoluteSubregion);
126 // Clip every filter effect to the filter region.
127 FloatRect absoluteScaledFilterRegion = filter->filterRegion();
128 absoluteScaledFilterRegion.scale(filterResolution.width(), filterResolution.height());
129 absoluteSubregion.intersect(absoluteScaledFilterRegion);
131 effect->setMaxEffectRect(absoluteSubregion);
135 } // namespace WebCore
137 #endif // ENABLE(SVG) && ENABLE(FILTERS)