1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/SVGFESpecularLightingElement.h"
8 #include "mozilla/dom/SVGFESpecularLightingElementBinding.h"
9 #include "mozilla/SVGFilterInstance.h"
10 #include "mozilla/dom/Document.h"
11 #include "mozilla/dom/BindContext.h"
13 NS_IMPL_NS_NEW_SVG_ELEMENT(FESpecularLighting
)
15 using namespace mozilla::gfx
;
17 namespace mozilla::dom
{
19 JSObject
* SVGFESpecularLightingElement::WrapNode(
20 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
21 return SVGFESpecularLightingElement_Binding::Wrap(aCx
, this, aGivenProto
);
24 //----------------------------------------------------------------------
27 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFESpecularLightingElement
)
29 already_AddRefed
<DOMSVGAnimatedString
> SVGFESpecularLightingElement::In1() {
30 return mStringAttributes
[IN1
].ToDOMAnimatedString(this);
33 already_AddRefed
<DOMSVGAnimatedNumber
>
34 SVGFESpecularLightingElement::SurfaceScale() {
35 return mNumberAttributes
[SURFACE_SCALE
].ToDOMAnimatedNumber(this);
38 already_AddRefed
<DOMSVGAnimatedNumber
>
39 SVGFESpecularLightingElement::SpecularConstant() {
40 return mNumberAttributes
[SPECULAR_CONSTANT
].ToDOMAnimatedNumber(this);
43 already_AddRefed
<DOMSVGAnimatedNumber
>
44 SVGFESpecularLightingElement::SpecularExponent() {
45 return mNumberAttributes
[SPECULAR_EXPONENT
].ToDOMAnimatedNumber(this);
48 already_AddRefed
<DOMSVGAnimatedNumber
>
49 SVGFESpecularLightingElement::KernelUnitLengthX() {
50 return mNumberPairAttributes
[KERNEL_UNIT_LENGTH
].ToDOMAnimatedNumber(
51 SVGAnimatedNumberPair::eFirst
, this);
54 already_AddRefed
<DOMSVGAnimatedNumber
>
55 SVGFESpecularLightingElement::KernelUnitLengthY() {
56 return mNumberPairAttributes
[KERNEL_UNIT_LENGTH
].ToDOMAnimatedNumber(
57 SVGAnimatedNumberPair::eSecond
, this);
60 //----------------------------------------------------------------------
63 FilterPrimitiveDescription
64 SVGFESpecularLightingElement::GetPrimitiveDescription(
65 SVGFilterInstance
* aInstance
, const IntRect
& aFilterSubregion
,
66 const nsTArray
<bool>& aInputsAreTainted
,
67 nsTArray
<RefPtr
<SourceSurface
>>& aInputImages
) {
68 float specularExponent
= mNumberAttributes
[SPECULAR_EXPONENT
].GetAnimValue();
69 float specularConstant
= mNumberAttributes
[SPECULAR_CONSTANT
].GetAnimValue();
71 // specification defined range (15.22)
72 if (specularExponent
< 1 || specularExponent
> 128) {
73 return FilterPrimitiveDescription();
76 SpecularLightingAttributes atts
;
77 atts
.mLightingConstant
= specularConstant
;
78 atts
.mSpecularExponent
= specularExponent
;
79 if (!AddLightingAttributes(static_cast<DiffuseLightingAttributes
*>(&atts
),
81 return FilterPrimitiveDescription();
84 return FilterPrimitiveDescription(AsVariant(std::move(atts
)));
87 bool SVGFESpecularLightingElement::AttributeAffectsRendering(
88 int32_t aNameSpaceID
, nsAtom
* aAttribute
) const {
89 return SVGFESpecularLightingElementBase::AttributeAffectsRendering(
90 aNameSpaceID
, aAttribute
) ||
91 (aNameSpaceID
== kNameSpaceID_None
&&
92 (aAttribute
== nsGkAtoms::specularConstant
||
93 aAttribute
== nsGkAtoms::specularExponent
));
96 nsresult
SVGFESpecularLightingElement::BindToTree(BindContext
& aCtx
,
98 if (aCtx
.InComposedDoc()) {
99 aCtx
.OwnerDoc().SetUseCounter(eUseCounter_custom_feSpecularLighting
);
102 return SVGFESpecularLightingElementBase::BindToTree(aCtx
, aParent
);
105 } // namespace mozilla::dom