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/SVGFEColorMatrixElement.h"
9 #include "DOMSVGAnimatedNumberList.h"
10 #include "mozilla/dom/SVGFEColorMatrixElementBinding.h"
12 #define NUM_ENTRIES_IN_4x5_MATRIX 20
14 NS_IMPL_NS_NEW_SVG_ELEMENT(FEColorMatrix
)
16 using namespace mozilla::gfx
;
21 JSObject
* SVGFEColorMatrixElement::WrapNode(JSContext
* aCx
,
22 JS::Handle
<JSObject
*> aGivenProto
) {
23 return SVGFEColorMatrixElement_Binding::Wrap(aCx
, this, aGivenProto
);
26 SVGEnumMapping
SVGFEColorMatrixElement::sTypeMap
[] = {
27 {nsGkAtoms::matrix
, SVG_FECOLORMATRIX_TYPE_MATRIX
},
28 {nsGkAtoms::saturate
, SVG_FECOLORMATRIX_TYPE_SATURATE
},
29 {nsGkAtoms::hueRotate
, SVG_FECOLORMATRIX_TYPE_HUE_ROTATE
},
30 {nsGkAtoms::luminanceToAlpha
, SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA
},
33 SVGElement::EnumInfo
SVGFEColorMatrixElement::sEnumInfo
[1] = {
34 {nsGkAtoms::type
, sTypeMap
, SVG_FECOLORMATRIX_TYPE_MATRIX
}};
36 SVGElement::StringInfo
SVGFEColorMatrixElement::sStringInfo
[2] = {
37 {nsGkAtoms::result
, kNameSpaceID_None
, true},
38 {nsGkAtoms::in
, kNameSpaceID_None
, true}};
40 SVGElement::NumberListInfo
SVGFEColorMatrixElement::sNumberListInfo
[1] = {
43 //----------------------------------------------------------------------
46 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEColorMatrixElement
)
48 //----------------------------------------------------------------------
50 already_AddRefed
<DOMSVGAnimatedString
> SVGFEColorMatrixElement::In1() {
51 return mStringAttributes
[IN1
].ToDOMAnimatedString(this);
54 already_AddRefed
<DOMSVGAnimatedEnumeration
> SVGFEColorMatrixElement::Type() {
55 return mEnumAttributes
[TYPE
].ToDOMAnimatedEnum(this);
58 already_AddRefed
<DOMSVGAnimatedNumberList
> SVGFEColorMatrixElement::Values() {
59 return DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes
[VALUES
],
63 void SVGFEColorMatrixElement::GetSourceImageNames(
64 nsTArray
<SVGStringInfo
>& aSources
) {
65 aSources
.AppendElement(SVGStringInfo(&mStringAttributes
[IN1
], this));
68 FilterPrimitiveDescription
SVGFEColorMatrixElement::GetPrimitiveDescription(
69 SVGFilterInstance
* aInstance
, const IntRect
& aFilterSubregion
,
70 const nsTArray
<bool>& aInputsAreTainted
,
71 nsTArray
<RefPtr
<SourceSurface
>>& aInputImages
) {
72 uint32_t type
= mEnumAttributes
[TYPE
].GetAnimValue();
73 const SVGNumberList
& values
= mNumberListAttributes
[VALUES
].GetAnimValue();
75 ColorMatrixAttributes atts
;
76 if (!mNumberListAttributes
[VALUES
].IsExplicitlySet() &&
77 (type
== SVG_FECOLORMATRIX_TYPE_MATRIX
||
78 type
== SVG_FECOLORMATRIX_TYPE_SATURATE
||
79 type
== SVG_FECOLORMATRIX_TYPE_HUE_ROTATE
)) {
80 atts
.mType
= (uint32_t)SVG_FECOLORMATRIX_TYPE_MATRIX
;
81 static const float identityMatrix
[] = {
89 atts
.mValues
.AppendElements(identityMatrix
, 20);
92 if (values
.Length()) {
93 atts
.mValues
.AppendElements(&values
[0], values
.Length());
97 return FilterPrimitiveDescription(AsVariant(std::move(atts
)));
100 bool SVGFEColorMatrixElement::AttributeAffectsRendering(
101 int32_t aNameSpaceID
, nsAtom
* aAttribute
) const {
102 return SVGFEColorMatrixElementBase::AttributeAffectsRendering(aNameSpaceID
,
104 (aNameSpaceID
== kNameSpaceID_None
&&
105 (aAttribute
== nsGkAtoms::in
|| aAttribute
== nsGkAtoms::type
||
106 aAttribute
== nsGkAtoms::values
));
109 //----------------------------------------------------------------------
110 // SVGElement methods
112 SVGElement::EnumAttributesInfo
SVGFEColorMatrixElement::GetEnumInfo() {
113 return EnumAttributesInfo(mEnumAttributes
, sEnumInfo
, ArrayLength(sEnumInfo
));
116 SVGElement::StringAttributesInfo
SVGFEColorMatrixElement::GetStringInfo() {
117 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
118 ArrayLength(sStringInfo
));
121 SVGElement::NumberListAttributesInfo
122 SVGFEColorMatrixElement::GetNumberListInfo() {
123 return NumberListAttributesInfo(mNumberListAttributes
, sNumberListInfo
,
124 ArrayLength(sNumberListInfo
));
128 } // namespace mozilla