Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / svg / SVGFEMorphologyElement.cpp
blob1ba882c06c064fb820e3712825d42037cbfe8eeb
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/SVGFEMorphologyElement.h"
8 #include "mozilla/dom/SVGFEMorphologyElementBinding.h"
9 #include "mozilla/SVGFilterInstance.h"
10 #include "mozilla/dom/BindContext.h"
11 #include "mozilla/dom/Document.h"
13 NS_IMPL_NS_NEW_SVG_ELEMENT(FEMorphology)
15 using namespace mozilla::gfx;
17 namespace mozilla::dom {
19 JSObject* SVGFEMorphologyElement::WrapNode(JSContext* aCx,
20 JS::Handle<JSObject*> aGivenProto) {
21 return SVGFEMorphologyElement_Binding::Wrap(aCx, this, aGivenProto);
24 SVGElement::NumberPairInfo SVGFEMorphologyElement::sNumberPairInfo[1] = {
25 {nsGkAtoms::radius, 0, 0}};
27 SVGEnumMapping SVGFEMorphologyElement::sOperatorMap[] = {
28 {nsGkAtoms::erode, SVG_OPERATOR_ERODE},
29 {nsGkAtoms::dilate, SVG_OPERATOR_DILATE},
30 {nullptr, 0}};
32 SVGElement::EnumInfo SVGFEMorphologyElement::sEnumInfo[1] = {
33 {nsGkAtoms::_operator, sOperatorMap, SVG_OPERATOR_ERODE}};
35 SVGElement::StringInfo SVGFEMorphologyElement::sStringInfo[2] = {
36 {nsGkAtoms::result, kNameSpaceID_None, true},
37 {nsGkAtoms::in, kNameSpaceID_None, true}};
39 //----------------------------------------------------------------------
40 // nsINode methods
42 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEMorphologyElement)
44 //----------------------------------------------------------------------
45 // SVGFEMorphologyElement methods
47 already_AddRefed<DOMSVGAnimatedString> SVGFEMorphologyElement::In1() {
48 return mStringAttributes[IN1].ToDOMAnimatedString(this);
51 already_AddRefed<DOMSVGAnimatedEnumeration> SVGFEMorphologyElement::Operator() {
52 return mEnumAttributes[OPERATOR].ToDOMAnimatedEnum(this);
55 already_AddRefed<DOMSVGAnimatedNumber> SVGFEMorphologyElement::RadiusX() {
56 return mNumberPairAttributes[RADIUS].ToDOMAnimatedNumber(
57 SVGAnimatedNumberPair::eFirst, this);
60 already_AddRefed<DOMSVGAnimatedNumber> SVGFEMorphologyElement::RadiusY() {
61 return mNumberPairAttributes[RADIUS].ToDOMAnimatedNumber(
62 SVGAnimatedNumberPair::eSecond, this);
65 void SVGFEMorphologyElement::SetRadius(float rx, float ry) {
66 mNumberPairAttributes[RADIUS].SetBaseValues(rx, ry, this);
69 void SVGFEMorphologyElement::GetSourceImageNames(
70 nsTArray<SVGStringInfo>& aSources) {
71 aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this));
74 #define MORPHOLOGY_EPSILON 0.0001
76 void SVGFEMorphologyElement::GetRXY(int32_t* aRX, int32_t* aRY,
77 const SVGFilterInstance& aInstance) {
78 // Subtract an epsilon here because we don't want a value that's just
79 // slightly larger than an integer to round up to the next integer; it's
80 // probably meant to be the integer it's close to, modulo machine precision
81 // issues.
82 *aRX = NSToIntCeil(aInstance.GetPrimitiveNumber(
83 SVGContentUtils::X, &mNumberPairAttributes[RADIUS],
84 SVGAnimatedNumberPair::eFirst) -
85 MORPHOLOGY_EPSILON);
86 *aRY = NSToIntCeil(aInstance.GetPrimitiveNumber(
87 SVGContentUtils::Y, &mNumberPairAttributes[RADIUS],
88 SVGAnimatedNumberPair::eSecond) -
89 MORPHOLOGY_EPSILON);
92 FilterPrimitiveDescription SVGFEMorphologyElement::GetPrimitiveDescription(
93 SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
94 const nsTArray<bool>& aInputsAreTainted,
95 nsTArray<RefPtr<SourceSurface>>& aInputImages) {
96 int32_t rx, ry;
97 GetRXY(&rx, &ry, *aInstance);
98 MorphologyAttributes atts;
99 atts.mRadii = Size(rx, ry);
100 atts.mOperator = (uint32_t)mEnumAttributes[OPERATOR].GetAnimValue();
101 return FilterPrimitiveDescription(AsVariant(std::move(atts)));
104 bool SVGFEMorphologyElement::AttributeAffectsRendering(
105 int32_t aNameSpaceID, nsAtom* aAttribute) const {
106 return SVGFEMorphologyElementBase::AttributeAffectsRendering(aNameSpaceID,
107 aAttribute) ||
108 (aNameSpaceID == kNameSpaceID_None &&
109 (aAttribute == nsGkAtoms::in || aAttribute == nsGkAtoms::radius ||
110 aAttribute == nsGkAtoms::_operator));
113 nsresult SVGFEMorphologyElement::BindToTree(BindContext& aCtx,
114 nsINode& aParent) {
115 if (aCtx.InComposedDoc()) {
116 aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feMorphology);
119 return SVGFE::BindToTree(aCtx, aParent);
122 //----------------------------------------------------------------------
123 // SVGElement methods
125 SVGElement::NumberPairAttributesInfo
126 SVGFEMorphologyElement::GetNumberPairInfo() {
127 return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
128 ArrayLength(sNumberPairInfo));
131 SVGElement::EnumAttributesInfo SVGFEMorphologyElement::GetEnumInfo() {
132 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
135 SVGElement::StringAttributesInfo SVGFEMorphologyElement::GetStringInfo() {
136 return StringAttributesInfo(mStringAttributes, sStringInfo,
137 ArrayLength(sStringInfo));
140 } // namespace mozilla::dom