Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / dom / svg / SVGFilters.h
blob5d239cf397f8314ac0fc3a7318f962e9d4a33db6
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 #ifndef DOM_SVG_SVGFILTERS_H_
8 #define DOM_SVG_SVGFILTERS_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/SVGElement.h"
12 #include "FilterDescription.h"
13 #include "nsImageLoadingContent.h"
14 #include "SVGAnimatedLength.h"
15 #include "SVGAnimatedNumber.h"
16 #include "SVGAnimatedNumberPair.h"
17 #include "SVGAnimatedString.h"
19 namespace mozilla {
20 class SVGFilterInstance;
22 namespace dom {
24 struct SVGStringInfo {
25 SVGStringInfo(const SVGAnimatedString* aString, SVGElement* aElement)
26 : mString(aString), mElement(aElement) {}
28 const SVGAnimatedString* mString;
29 SVGElement* mElement;
32 using SVGFilterPrimitiveElementBase = SVGElement;
34 /**
35 * Base class for filter primitive elements
36 * Children of those elements e.g. feMergeNode
37 * derive from SVGFilterPrimitiveChildElement instead
39 class SVGFilterPrimitiveElement : public SVGFilterPrimitiveElementBase {
40 friend class mozilla::SVGFilterInstance;
42 protected:
43 using SourceSurface = mozilla::gfx::SourceSurface;
44 using Size = mozilla::gfx::Size;
45 using IntRect = mozilla::gfx::IntRect;
46 using ColorSpace = mozilla::gfx::ColorSpace;
47 using FilterPrimitiveDescription = mozilla::gfx::FilterPrimitiveDescription;
49 explicit SVGFilterPrimitiveElement(
50 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
51 : SVGFilterPrimitiveElementBase(std::move(aNodeInfo)) {}
52 virtual ~SVGFilterPrimitiveElement() = default;
54 public:
55 using PrimitiveAttributes = mozilla::gfx::PrimitiveAttributes;
57 NS_IMPL_FROMNODE_HELPER(SVGFilterPrimitiveElement,
58 IsSVGFilterPrimitiveElement())
60 ColorSpace GetInputColorSpace(int32_t aInputIndex,
61 ColorSpace aUnchangedInputColorSpace) {
62 return OperatesOnSRGB(aInputIndex,
63 aUnchangedInputColorSpace == ColorSpace::SRGB)
64 ? ColorSpace::SRGB
65 : ColorSpace::LinearRGB;
68 // This is only called for filter primitives without inputs. For primitives
69 // with inputs, the output color model is the same as of the first input.
70 ColorSpace GetOutputColorSpace() {
71 return ProducesSRGB() ? ColorSpace::SRGB : ColorSpace::LinearRGB;
74 // See http://www.w3.org/TR/SVG/filters.html#FilterPrimitiveSubRegion
75 virtual bool SubregionIsUnionOfRegions() { return true; }
77 bool IsSVGFilterPrimitiveElement() const final { return true; }
79 // SVGElement interface
80 nsresult Clone(mozilla::dom::NodeInfo*, nsINode** aResult) const override = 0;
82 bool HasValidDimensions() const override;
84 virtual SVGAnimatedString& GetResultImageName() = 0;
85 // Return a list of all image names used as sources. Default is to
86 // return no sources.
87 virtual void GetSourceImageNames(nsTArray<SVGStringInfo>& aSources);
89 virtual FilterPrimitiveDescription GetPrimitiveDescription(
90 SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
91 const nsTArray<bool>& aInputsAreTainted,
92 nsTArray<RefPtr<SourceSurface>>& aInputImages) = 0;
94 // returns true if changes to the attribute should cause us to
95 // repaint the filter
96 virtual bool AttributeAffectsRendering(int32_t aNameSpaceID,
97 nsAtom* aAttribute) const;
99 // Return whether this filter primitive has tainted output. A filter's
100 // output is tainted if it depends on things that the web page is not
101 // allowed to read from, e.g. the source graphic or cross-origin images.
102 // aReferencePrincipal is the node principal of the filtered frame's element.
103 virtual bool OutputIsTainted(const nsTArray<bool>& aInputsAreTainted,
104 nsIPrincipal* aReferencePrincipal);
106 static nsIntRect GetMaxRect() {
107 // Try to avoid overflow errors dealing with this rect. It will
108 // be intersected with some other reasonable-sized rect eventually.
109 return nsIntRect(INT32_MIN / 2, INT32_MIN / 2, INT32_MAX, INT32_MAX);
112 operator nsISupports*() { return static_cast<nsIContent*>(this); }
114 // WebIDL
115 already_AddRefed<DOMSVGAnimatedLength> X();
116 already_AddRefed<DOMSVGAnimatedLength> Y();
117 already_AddRefed<DOMSVGAnimatedLength> Width();
118 already_AddRefed<DOMSVGAnimatedLength> Height();
119 already_AddRefed<DOMSVGAnimatedString> Result();
121 protected:
122 virtual bool OperatesOnSRGB(int32_t aInputIndex, bool aInputIsAlreadySRGB) {
123 return StyleIsSetToSRGB();
126 // Only called for filter primitives without inputs.
127 virtual bool ProducesSRGB() { return StyleIsSetToSRGB(); }
129 bool StyleIsSetToSRGB();
131 // SVGElement specializations:
132 LengthAttributesInfo GetLengthInfo() override;
134 Size GetKernelUnitLength(SVGFilterInstance* aInstance,
135 SVGAnimatedNumberPair* aKernelUnitLength);
137 enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
138 SVGAnimatedLength mLengthAttributes[4];
139 static LengthInfo sLengthInfo[4];
142 using SVGFilterPrimitiveChildElementBase = SVGElement;
144 class SVGFilterPrimitiveChildElement
145 : public SVGFilterPrimitiveChildElementBase {
146 protected:
147 explicit SVGFilterPrimitiveChildElement(
148 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
149 : SVGFilterPrimitiveChildElementBase(std::move(aNodeInfo)) {}
151 public:
152 NS_IMPL_FROMNODE_HELPER(SVGFilterPrimitiveChildElement,
153 IsSVGFilterPrimitiveChildElement())
155 bool IsSVGFilterPrimitiveChildElement() const final { return true; }
157 nsresult Clone(mozilla::dom::NodeInfo*, nsINode** aResult) const override = 0;
159 // returns true if changes to the attribute should cause us to
160 // repaint the filter
161 virtual bool AttributeAffectsRendering(int32_t aNameSpaceID,
162 nsAtom* aAttribute) const = 0;
165 //------------------------------------------------------------
167 using SVGFELightingElementBase = SVGFilterPrimitiveElement;
169 class SVGFELightingElement : public SVGFELightingElementBase {
170 protected:
171 explicit SVGFELightingElement(
172 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
173 : SVGFELightingElementBase(std::move(aNodeInfo)) {}
175 virtual ~SVGFELightingElement() = default;
177 public:
178 // interfaces:
179 NS_INLINE_DECL_REFCOUNTING_INHERITED(SVGFELightingElement,
180 SVGFELightingElementBase)
182 bool AttributeAffectsRendering(int32_t aNameSpaceID,
183 nsAtom* aAttribute) const override;
184 SVGAnimatedString& GetResultImageName() override {
185 return mStringAttributes[RESULT];
188 bool OutputIsTainted(const nsTArray<bool>& aInputsAreTainted,
189 nsIPrincipal* aReferencePrincipal) override;
191 void GetSourceImageNames(nsTArray<SVGStringInfo>& aSources) override;
193 protected:
194 bool OperatesOnSRGB(int32_t aInputIndex, bool aInputIsAlreadySRGB) override {
195 return true;
198 NumberAttributesInfo GetNumberInfo() override;
199 NumberPairAttributesInfo GetNumberPairInfo() override;
200 StringAttributesInfo GetStringInfo() override;
202 mozilla::gfx::LightType ComputeLightAttributes(
203 SVGFilterInstance* aInstance, nsTArray<float>& aFloatAttributes);
205 bool AddLightingAttributes(
206 mozilla::gfx::DiffuseLightingAttributes* aAttributes,
207 SVGFilterInstance* aInstance);
209 enum {
210 SURFACE_SCALE,
211 DIFFUSE_CONSTANT,
212 SPECULAR_CONSTANT,
213 SPECULAR_EXPONENT
215 SVGAnimatedNumber mNumberAttributes[4];
216 static NumberInfo sNumberInfo[4];
218 enum { KERNEL_UNIT_LENGTH };
219 SVGAnimatedNumberPair mNumberPairAttributes[1];
220 static NumberPairInfo sNumberPairInfo[1];
222 enum { RESULT, IN1 };
223 SVGAnimatedString mStringAttributes[2];
224 static StringInfo sStringInfo[2];
227 using SVGFELightElementBase = SVGFilterPrimitiveChildElement;
229 class SVGFELightElement : public SVGFELightElementBase {
230 protected:
231 explicit SVGFELightElement(
232 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
233 : SVGFELightElementBase(std::move(aNodeInfo)) {}
235 public:
236 using PrimitiveAttributes = gfx::PrimitiveAttributes;
238 virtual mozilla::gfx::LightType ComputeLightAttributes(
239 SVGFilterInstance* aInstance, nsTArray<float>& aFloatAttributes) = 0;
242 } // namespace dom
243 } // namespace mozilla
245 #endif // DOM_SVG_SVGFILTERS_H_