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/SVGFECompositeElement.h"
8 #include "mozilla/dom/SVGFECompositeElementBinding.h"
9 #include "mozilla/dom/Document.h"
10 #include "mozilla/dom/BindContext.h"
12 NS_IMPL_NS_NEW_SVG_ELEMENT(FEComposite
)
14 using namespace mozilla::gfx
;
16 namespace mozilla::dom
{
18 JSObject
* SVGFECompositeElement::WrapNode(JSContext
* aCx
,
19 JS::Handle
<JSObject
*> aGivenProto
) {
20 return SVGFECompositeElement_Binding::Wrap(aCx
, this, aGivenProto
);
23 SVGElement::NumberInfo
SVGFECompositeElement::sNumberInfo
[4] = {
24 {nsGkAtoms::k1
, 0, false},
25 {nsGkAtoms::k2
, 0, false},
26 {nsGkAtoms::k3
, 0, false},
27 {nsGkAtoms::k4
, 0, false}};
29 SVGEnumMapping
SVGFECompositeElement::sOperatorMap
[] = {
30 {nsGkAtoms::over
, SVG_FECOMPOSITE_OPERATOR_OVER
},
31 {nsGkAtoms::in
, SVG_FECOMPOSITE_OPERATOR_IN
},
32 {nsGkAtoms::out
, SVG_FECOMPOSITE_OPERATOR_OUT
},
33 {nsGkAtoms::atop
, SVG_FECOMPOSITE_OPERATOR_ATOP
},
34 {nsGkAtoms::xor_
, SVG_FECOMPOSITE_OPERATOR_XOR
},
35 {nsGkAtoms::arithmetic
, SVG_FECOMPOSITE_OPERATOR_ARITHMETIC
},
36 {nsGkAtoms::lighter
, SVG_FECOMPOSITE_OPERATOR_LIGHTER
},
39 SVGElement::EnumInfo
SVGFECompositeElement::sEnumInfo
[1] = {
40 {nsGkAtoms::_operator
, sOperatorMap
, SVG_FECOMPOSITE_OPERATOR_OVER
}};
42 SVGElement::StringInfo
SVGFECompositeElement::sStringInfo
[3] = {
43 {nsGkAtoms::result
, kNameSpaceID_None
, true},
44 {nsGkAtoms::in
, kNameSpaceID_None
, true},
45 {nsGkAtoms::in2
, kNameSpaceID_None
, true}};
47 //----------------------------------------------------------------------
50 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFECompositeElement
)
52 already_AddRefed
<DOMSVGAnimatedString
> SVGFECompositeElement::In1() {
53 return mStringAttributes
[IN1
].ToDOMAnimatedString(this);
56 already_AddRefed
<DOMSVGAnimatedString
> SVGFECompositeElement::In2() {
57 return mStringAttributes
[IN2
].ToDOMAnimatedString(this);
60 already_AddRefed
<DOMSVGAnimatedEnumeration
> SVGFECompositeElement::Operator() {
61 return mEnumAttributes
[OPERATOR
].ToDOMAnimatedEnum(this);
64 already_AddRefed
<DOMSVGAnimatedNumber
> SVGFECompositeElement::K1() {
65 return mNumberAttributes
[ATTR_K1
].ToDOMAnimatedNumber(this);
68 already_AddRefed
<DOMSVGAnimatedNumber
> SVGFECompositeElement::K2() {
69 return mNumberAttributes
[ATTR_K2
].ToDOMAnimatedNumber(this);
72 already_AddRefed
<DOMSVGAnimatedNumber
> SVGFECompositeElement::K3() {
73 return mNumberAttributes
[ATTR_K3
].ToDOMAnimatedNumber(this);
76 already_AddRefed
<DOMSVGAnimatedNumber
> SVGFECompositeElement::K4() {
77 return mNumberAttributes
[ATTR_K4
].ToDOMAnimatedNumber(this);
80 void SVGFECompositeElement::SetK(float k1
, float k2
, float k3
, float k4
) {
81 mNumberAttributes
[ATTR_K1
].SetBaseValue(k1
, this);
82 mNumberAttributes
[ATTR_K2
].SetBaseValue(k2
, this);
83 mNumberAttributes
[ATTR_K3
].SetBaseValue(k3
, this);
84 mNumberAttributes
[ATTR_K4
].SetBaseValue(k4
, this);
87 FilterPrimitiveDescription
SVGFECompositeElement::GetPrimitiveDescription(
88 SVGFilterInstance
* aInstance
, const IntRect
& aFilterSubregion
,
89 const nsTArray
<bool>& aInputsAreTainted
,
90 nsTArray
<RefPtr
<SourceSurface
>>& aInputImages
) {
91 CompositeAttributes atts
;
92 uint32_t op
= mEnumAttributes
[OPERATOR
].GetAnimValue();
95 if (op
== SVG_FECOMPOSITE_OPERATOR_ARITHMETIC
) {
97 GetAnimatedNumberValues(k
, k
+ 1, k
+ 2, k
+ 3, nullptr);
98 atts
.mCoefficients
.AppendElements(k
, 4);
101 return FilterPrimitiveDescription(AsVariant(std::move(atts
)));
104 bool SVGFECompositeElement::AttributeAffectsRendering(
105 int32_t aNameSpaceID
, nsAtom
* aAttribute
) const {
106 return SVGFECompositeElementBase::AttributeAffectsRendering(aNameSpaceID
,
108 (aNameSpaceID
== kNameSpaceID_None
&&
109 (aAttribute
== nsGkAtoms::in
|| aAttribute
== nsGkAtoms::in2
||
110 aAttribute
== nsGkAtoms::k1
|| aAttribute
== nsGkAtoms::k2
||
111 aAttribute
== nsGkAtoms::k3
|| aAttribute
== nsGkAtoms::k4
||
112 aAttribute
== nsGkAtoms::_operator
));
115 void SVGFECompositeElement::GetSourceImageNames(
116 nsTArray
<SVGStringInfo
>& aSources
) {
117 aSources
.AppendElement(SVGStringInfo(&mStringAttributes
[IN1
], this));
118 aSources
.AppendElement(SVGStringInfo(&mStringAttributes
[IN2
], this));
121 nsresult
SVGFECompositeElement::BindToTree(BindContext
& aCtx
,
123 if (aCtx
.InComposedDoc()) {
124 aCtx
.OwnerDoc().SetUseCounter(eUseCounter_custom_feComposite
);
127 return SVGFE::BindToTree(aCtx
, aParent
);
130 //----------------------------------------------------------------------
131 // SVGElement methods
133 SVGElement::NumberAttributesInfo
SVGFECompositeElement::GetNumberInfo() {
134 return NumberAttributesInfo(mNumberAttributes
, sNumberInfo
,
135 ArrayLength(sNumberInfo
));
138 SVGElement::EnumAttributesInfo
SVGFECompositeElement::GetEnumInfo() {
139 return EnumAttributesInfo(mEnumAttributes
, sEnumInfo
, ArrayLength(sEnumInfo
));
142 SVGElement::StringAttributesInfo
SVGFECompositeElement::GetStringInfo() {
143 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
144 ArrayLength(sStringInfo
));
147 } // namespace mozilla::dom