22#if ENABLE(SVG) && ENABLE(SVG_FILTERS)
31#include "SVGRenderStyle.h"
37SVGFEDiffuseLightingElement::SVGFEDiffuseLightingElement(
const QualifiedName& tagName, Document* doc)
38 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
39 , m_diffuseConstant(1.0f)
40 , m_surfaceScale(1.0f)
41 , m_kernelUnitLengthX(0.0f)
42 , m_kernelUnitLengthY(0.0f)
47SVGFEDiffuseLightingElement::~SVGFEDiffuseLightingElement()
49 delete m_filterEffect;
52ANIMATED_PROPERTY_DEFINITIONS(SVGFEDiffuseLightingElement, String, String,
string, In1, in1, SVGNames::inAttr, m_in1)
53ANIMATED_PROPERTY_DEFINITIONS(SVGFEDiffuseLightingElement,
float, Number, number, DiffuseConstant, diffuseConstant, SVGNames::diffuseConstantAttr, m_diffuseConstant)
54ANIMATED_PROPERTY_DEFINITIONS(SVGFEDiffuseLightingElement,
float, Number, number, SurfaceScale, surfaceScale, SVGNames::surfaceScaleAttr, m_surfaceScale)
55ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFEDiffuseLightingElement,
float, Number, number, KernelUnitLengthX, kernelUnitLengthX, SVGNames::kernelUnitLengthAttr,
"kernelUnitLengthX", m_kernelUnitLengthX)
56ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFEDiffuseLightingElement,
float, Number, number, KernelUnitLengthY, kernelUnitLengthY, SVGNames::kernelUnitLengthAttr,
"kernelUnitLengthY", m_kernelUnitLengthY)
58void SVGFEDiffuseLightingElement::parseMappedAttribute(MappedAttribute *attr)
60 const String& value = attr->value();
61 if (attr->name() == SVGNames::inAttr)
62 setIn1BaseValue(value);
63 else if (attr->name() == SVGNames::surfaceScaleAttr)
64 setSurfaceScaleBaseValue(value.toFloat());
65 else if (attr->name() == SVGNames::diffuseConstantAttr)
66 setDiffuseConstantBaseValue(value.toInt());
67 else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
69 if (parseNumberOptionalNumber(value, x, y)) {
70 setKernelUnitLengthXBaseValue(x);
71 setKernelUnitLengthYBaseValue(y);
74 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
77SVGFilterEffect* SVGFEDiffuseLightingElement::filterEffect(SVGResourceFilter* filter)
const
80 m_filterEffect =
new SVGFEDiffuseLighting(filter);
82 m_filterEffect->setIn(in1());
83 m_filterEffect->setDiffuseConstant(diffuseConstant());
84 m_filterEffect->setSurfaceScale(surfaceScale());
85 m_filterEffect->setKernelUnitLengthX(kernelUnitLengthX());
86 m_filterEffect->setKernelUnitLengthY(kernelUnitLengthY());
88 SVGFEDiffuseLightingElement* nonConstThis =
const_cast<SVGFEDiffuseLightingElement*
>(
this);
90 RenderStyle* parentStyle = nonConstThis->styleForRenderer(parent()->renderer());
91 RenderStyle* filterStyle = nonConstThis->resolveStyle(parentStyle);
93 m_filterEffect->setLightingColor(filterStyle->svgStyle()->lightingColor());
94 setStandardAttributes(m_filterEffect);
96 parentStyle->deref(document()->renderArena());
97 filterStyle->deref(document()->renderArena());
100 return m_filterEffect;
103void SVGFEDiffuseLightingElement::updateLights()
const
108 SVGLightSource* light = 0;
109 for (Node* n = firstChild(); n; n = n->nextSibling()) {
110 if (n->hasTagName(SVGNames::feDistantLightTag) ||
111 n->hasTagName(SVGNames::fePointLightTag) ||
112 n->hasTagName(SVGNames::feSpotLightTag)) {
113 SVGFELightElement* lightNode =
static_cast<SVGFELightElement*
>(n);
114 light = lightNode->lightSource();
119 m_filterEffect->setLightSource(light);