Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGFEMorphologyElement.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "mozilla/dom/SVGFEMorphologyElement.h"
8
#include "mozilla/dom/SVGFEMorphologyElementBinding.h"
9
#include "nsSVGFilterInstance.h"
10
11
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEMorphology)
12
13
using namespace mozilla::gfx;
14
15
namespace mozilla {
16
namespace dom {
17
18
JSObject*
19
SVGFEMorphologyElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
20
0
{
21
0
  return SVGFEMorphologyElement_Binding::Wrap(aCx, this, aGivenProto);
22
0
}
23
24
nsSVGElement::NumberPairInfo SVGFEMorphologyElement::sNumberPairInfo[1] =
25
{
26
  { &nsGkAtoms::radius, 0, 0 }
27
};
28
29
nsSVGEnumMapping SVGFEMorphologyElement::sOperatorMap[] = {
30
  {&nsGkAtoms::erode, SVG_OPERATOR_ERODE},
31
  {&nsGkAtoms::dilate, SVG_OPERATOR_DILATE},
32
  {nullptr, 0}
33
};
34
35
nsSVGElement::EnumInfo SVGFEMorphologyElement::sEnumInfo[1] =
36
{
37
  { &nsGkAtoms::_operator,
38
    sOperatorMap,
39
    SVG_OPERATOR_ERODE
40
  }
41
};
42
43
nsSVGElement::StringInfo SVGFEMorphologyElement::sStringInfo[2] =
44
{
45
  { &nsGkAtoms::result, kNameSpaceID_None, true },
46
  { &nsGkAtoms::in, kNameSpaceID_None, true }
47
};
48
49
//----------------------------------------------------------------------
50
// nsINode methods
51
52
53
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEMorphologyElement)
54
55
56
//----------------------------------------------------------------------
57
// SVGFEMorphologyElement methods
58
59
already_AddRefed<SVGAnimatedString>
60
SVGFEMorphologyElement::In1()
61
0
{
62
0
  return mStringAttributes[IN1].ToDOMAnimatedString(this);
63
0
}
64
65
already_AddRefed<SVGAnimatedEnumeration>
66
SVGFEMorphologyElement::Operator()
67
0
{
68
0
  return mEnumAttributes[OPERATOR].ToDOMAnimatedEnum(this);
69
0
}
70
71
already_AddRefed<SVGAnimatedNumber>
72
SVGFEMorphologyElement::RadiusX()
73
0
{
74
0
  return mNumberPairAttributes[RADIUS].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
75
0
}
76
77
already_AddRefed<SVGAnimatedNumber>
78
SVGFEMorphologyElement::RadiusY()
79
0
{
80
0
  return mNumberPairAttributes[RADIUS].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
81
0
}
82
83
void
84
SVGFEMorphologyElement::SetRadius(float rx, float ry)
85
0
{
86
0
  mNumberPairAttributes[RADIUS].SetBaseValues(rx, ry, this);
87
0
}
88
89
void
90
SVGFEMorphologyElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
91
0
{
92
0
  aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
93
0
}
94
95
0
#define MORPHOLOGY_EPSILON 0.0001
96
97
void
98
SVGFEMorphologyElement::GetRXY(int32_t *aRX, int32_t *aRY,
99
                               const nsSVGFilterInstance& aInstance)
100
0
{
101
0
  // Subtract an epsilon here because we don't want a value that's just
102
0
  // slightly larger than an integer to round up to the next integer; it's
103
0
  // probably meant to be the integer it's close to, modulo machine precision
104
0
  // issues.
105
0
  *aRX = NSToIntCeil(aInstance.GetPrimitiveNumber(SVGContentUtils::X,
106
0
                                                  &mNumberPairAttributes[RADIUS],
107
0
                                                  nsSVGNumberPair::eFirst) -
108
0
                     MORPHOLOGY_EPSILON);
109
0
  *aRY = NSToIntCeil(aInstance.GetPrimitiveNumber(SVGContentUtils::Y,
110
0
                                                  &mNumberPairAttributes[RADIUS],
111
0
                                                  nsSVGNumberPair::eSecond) -
112
0
                     MORPHOLOGY_EPSILON);
113
0
}
114
115
FilterPrimitiveDescription
116
SVGFEMorphologyElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
117
                                                const IntRect& aFilterSubregion,
118
                                                const nsTArray<bool>& aInputsAreTainted,
119
                                                nsTArray<RefPtr<SourceSurface>>& aInputImages)
120
0
{
121
0
  int32_t rx, ry;
122
0
  GetRXY(&rx, &ry, *aInstance);
123
0
  MorphologyAttributes atts;
124
0
  atts.mRadii = Size(rx, ry);
125
0
  atts.mOperator = (uint32_t)mEnumAttributes[OPERATOR].GetAnimValue();
126
0
  return FilterPrimitiveDescription(AsVariant(std::move(atts)));
127
0
}
128
129
bool
130
SVGFEMorphologyElement::AttributeAffectsRendering(int32_t aNameSpaceID,
131
                                                  nsAtom* aAttribute) const
132
0
{
133
0
  return SVGFEMorphologyElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
134
0
         (aNameSpaceID == kNameSpaceID_None &&
135
0
          (aAttribute == nsGkAtoms::in ||
136
0
           aAttribute == nsGkAtoms::radius ||
137
0
           aAttribute == nsGkAtoms::_operator));
138
0
}
139
140
//----------------------------------------------------------------------
141
// nsSVGElement methods
142
143
nsSVGElement::NumberPairAttributesInfo
144
SVGFEMorphologyElement::GetNumberPairInfo()
145
0
{
146
0
  return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
147
0
                                  ArrayLength(sNumberPairInfo));
148
0
}
149
150
nsSVGElement::EnumAttributesInfo
151
SVGFEMorphologyElement::GetEnumInfo()
152
0
{
153
0
  return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
154
0
                            ArrayLength(sEnumInfo));
155
0
}
156
157
nsSVGElement::StringAttributesInfo
158
SVGFEMorphologyElement::GetStringInfo()
159
0
{
160
0
  return StringAttributesInfo(mStringAttributes, sStringInfo,
161
0
                              ArrayLength(sStringInfo));
162
0
}
163
164
} // namespace dom
165
} // namespace mozilla