2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
#ifndef __NS_SVGFILTERSELEMENT_H__
|
|
|
|
#define __NS_SVGFILTERSELEMENT_H__
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2019-01-06 11:22:55 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
|
|
|
#include "FilterSupport.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsImageLoadingContent.h"
|
|
|
|
#include "nsSVGLength2.h"
|
2019-01-06 20:52:55 +03:00
|
|
|
#include "SVGString.h"
|
2013-03-25 10:26:05 +04:00
|
|
|
#include "nsSVGNumber2.h"
|
2019-01-06 11:22:55 +03:00
|
|
|
#include "SVGNumberPair.h"
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2012-01-26 13:57:21 +04:00
|
|
|
class nsSVGFilterInstance;
|
2007-07-26 10:57:42 +04:00
|
|
|
|
2018-12-21 19:24:17 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct SVGStringInfo {
|
2019-01-06 20:52:55 +03:00
|
|
|
SVGStringInfo(const SVGString* aString, SVGElement* aElement)
|
2009-01-22 03:56:51 +03:00
|
|
|
: mString(aString), mElement(aElement) {}
|
|
|
|
|
2019-01-06 20:52:55 +03:00
|
|
|
const SVGString* mString;
|
2018-12-21 19:24:17 +03:00
|
|
|
SVGElement* mElement;
|
2009-01-22 03:56:51 +03:00
|
|
|
};
|
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
typedef SVGElement SVGFEBase;
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2008-02-18 10:29:00 +03:00
|
|
|
#define NS_SVG_FE_CID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2008-02-18 10:29:00 +03:00
|
|
|
0x60483958, 0xd229, 0x4a77, { \
|
|
|
|
0x96, 0xb2, 0x62, 0x3e, 0x69, 0x95, 0x1e, 0x0e \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2011-11-19 21:53:52 +04:00
|
|
|
/**
|
|
|
|
* Base class for filter primitive elements
|
|
|
|
* Children of those elements e.g. feMergeNode
|
|
|
|
* derive from SVGFEUnstyledElement instead
|
|
|
|
*/
|
2018-12-21 15:32:35 +03:00
|
|
|
class SVGFE : public SVGFEBase {
|
|
|
|
friend class ::nsSVGFilterInstance;
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
protected:
|
2013-11-28 18:38:43 +04:00
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
2013-11-27 15:25:29 +04:00
|
|
|
typedef mozilla::gfx::Size Size;
|
|
|
|
typedef mozilla::gfx::IntRect IntRect;
|
|
|
|
typedef mozilla::gfx::ColorSpace ColorSpace;
|
|
|
|
typedef mozilla::gfx::FilterPrimitiveDescription FilterPrimitiveDescription;
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
explicit SVGFE(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGFEBase(std::move(aNodeInfo)) {}
|
|
|
|
virtual ~SVGFE() {}
|
2007-07-26 10:57:42 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
public:
|
2018-09-19 20:18:16 +03:00
|
|
|
typedef mozilla::gfx::PrimitiveAttributes PrimitiveAttributes;
|
2013-11-27 15:25:29 +04:00
|
|
|
|
|
|
|
ColorSpace GetInputColorSpace(int32_t aInputIndex,
|
|
|
|
ColorSpace aUnchangedInputColorSpace) {
|
2014-03-20 06:12:43 +04:00
|
|
|
return OperatesOnSRGB(aInputIndex,
|
|
|
|
aUnchangedInputColorSpace == ColorSpace::SRGB)
|
|
|
|
? ColorSpace::SRGB
|
|
|
|
: ColorSpace::LinearRGB;
|
2008-07-14 05:21:25 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
// This is only called for filter primitives without inputs. For primitives
|
|
|
|
// with inputs, the output color model is the same as of the first input.
|
|
|
|
ColorSpace GetOutputColorSpace() {
|
2014-03-20 06:12:43 +04:00
|
|
|
return ProducesSRGB() ? ColorSpace::SRGB : ColorSpace::LinearRGB;
|
2007-08-31 18:44:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See http://www.w3.org/TR/SVG/filters.html#FilterPrimitiveSubRegion
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SubregionIsUnionOfRegions() { return true; }
|
2007-08-31 18:44:28 +04:00
|
|
|
|
2008-02-18 10:29:00 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SVG_FE_CID)
|
2013-03-28 05:23:09 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
// interfaces:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2011-08-20 17:02:41 +04:00
|
|
|
// nsIContent interface
|
2017-10-03 01:05:19 +03:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
|
2011-08-20 17:02:41 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement interface
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo*,
|
|
|
|
nsINode** aResult) const override = 0;
|
2013-03-31 06:27:27 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool HasValidDimensions() const override;
|
2012-03-03 13:21:09 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool IsNodeOfType(uint32_t aFlags) const override {
|
2017-10-25 18:19:11 +03:00
|
|
|
return !(aFlags & ~eFILTER);
|
|
|
|
}
|
2013-03-07 11:12:32 +04:00
|
|
|
|
2019-01-06 20:52:55 +03:00
|
|
|
virtual SVGString& GetResultImageName() = 0;
|
2008-02-18 10:29:00 +03:00
|
|
|
// Return a list of all image names used as sources. Default is to
|
|
|
|
// return no sources.
|
2018-12-21 19:24:17 +03:00
|
|
|
virtual void GetSourceImageNames(nsTArray<SVGStringInfo>& aSources);
|
2013-11-27 15:25:29 +04:00
|
|
|
|
|
|
|
virtual FilterPrimitiveDescription GetPrimitiveDescription(
|
|
|
|
nsSVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
|
2014-01-08 13:30:03 +04:00
|
|
|
const nsTArray<bool>& aInputsAreTainted,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<SourceSurface>>& aInputImages) = 0;
|
2008-07-14 05:21:25 +04:00
|
|
|
|
2011-11-19 21:53:52 +04:00
|
|
|
// returns true if changes to the attribute should cause us to
|
|
|
|
// repaint the filter
|
|
|
|
virtual bool AttributeAffectsRendering(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute) const;
|
2011-11-19 21:53:52 +04:00
|
|
|
|
2014-01-08 13:30:03 +04:00
|
|
|
// Return whether this filter primitive has tainted output. A filter's
|
|
|
|
// output is tainted if it depends on things that the web page is not
|
|
|
|
// allowed to read from, e.g. the source graphic or cross-origin images.
|
|
|
|
// aReferencePrincipal is the node principal of the filtered frame's element.
|
|
|
|
virtual bool OutputIsTainted(const nsTArray<bool>& aInputsAreTainted,
|
|
|
|
nsIPrincipal* aReferencePrincipal);
|
|
|
|
|
2008-07-14 05:21:25 +04:00
|
|
|
static nsIntRect GetMaxRect() {
|
2008-02-18 10:29:00 +03:00
|
|
|
// Try to avoid overflow errors dealing with this rect. It will
|
|
|
|
// be intersected with some other reasonable-sized rect eventually.
|
2012-09-28 10:57:33 +04:00
|
|
|
return nsIntRect(INT32_MIN / 2, INT32_MIN / 2, INT32_MAX, INT32_MAX);
|
2008-02-18 10:29:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
operator nsISupports*() { return static_cast<nsIContent*>(this); }
|
2013-03-07 11:17:00 +04:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedLength> X();
|
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedLength> Y();
|
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedLength> Width();
|
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedLength> Height();
|
2013-06-15 02:37:27 +04:00
|
|
|
already_AddRefed<mozilla::dom::SVGAnimatedString> Result();
|
2013-03-07 11:17:00 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
protected:
|
2013-11-27 15:25:29 +04:00
|
|
|
virtual bool OperatesOnSRGB(int32_t aInputIndex, bool aInputIsAlreadySRGB) {
|
|
|
|
return StyleIsSetToSRGB();
|
2007-08-31 18:44:28 +04:00
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
// Only called for filter primitives without inputs.
|
|
|
|
virtual bool ProducesSRGB() { return StyleIsSetToSRGB(); }
|
|
|
|
|
|
|
|
bool StyleIsSetToSRGB();
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement specializations:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual LengthAttributesInfo GetLengthInfo() override;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
Size GetKernelUnitLength(nsSVGFilterInstance* aInstance,
|
2019-01-06 11:22:55 +03:00
|
|
|
SVGNumberPair* aKernelUnitLength);
|
2013-11-27 15:25:29 +04:00
|
|
|
|
2013-03-07 11:17:00 +04:00
|
|
|
enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
|
2006-04-14 19:09:39 +04:00
|
|
|
nsSVGLength2 mLengthAttributes[4];
|
|
|
|
static LengthInfo sLengthInfo[4];
|
|
|
|
};
|
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(SVGFE, NS_SVG_FE_CID)
|
2014-03-28 12:45:02 +04:00
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
typedef SVGElement SVGFEUnstyledElementBase;
|
2011-11-19 21:53:52 +04:00
|
|
|
|
|
|
|
class SVGFEUnstyledElement : public SVGFEUnstyledElementBase {
|
|
|
|
protected:
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit SVGFEUnstyledElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGFEUnstyledElementBase(std::move(aNodeInfo)) {}
|
2011-11-19 21:53:52 +04:00
|
|
|
|
|
|
|
public:
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(mozilla::dom::NodeInfo*,
|
|
|
|
nsINode** aResult) const override = 0;
|
2013-03-31 06:27:27 +04:00
|
|
|
|
2011-11-19 21:53:52 +04:00
|
|
|
// returns true if changes to the attribute should cause us to
|
|
|
|
// repaint the filter
|
|
|
|
virtual bool AttributeAffectsRendering(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute) const = 0;
|
2011-11-19 21:53:52 +04:00
|
|
|
};
|
|
|
|
|
2013-03-25 10:26:05 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
typedef SVGFE SVGFELightingElementBase;
|
2013-03-25 10:26:05 +04:00
|
|
|
|
2018-12-20 11:01:54 +03:00
|
|
|
class SVGFELightingElement : public SVGFELightingElementBase {
|
2013-03-25 10:26:05 +04:00
|
|
|
protected:
|
2018-12-20 11:01:54 +03:00
|
|
|
explicit SVGFELightingElement(
|
2018-09-21 23:45:49 +03:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
2018-12-20 11:01:54 +03:00
|
|
|
: SVGFELightingElementBase(std::move(aNodeInfo)) {}
|
2013-03-25 10:26:05 +04:00
|
|
|
|
2018-12-20 11:01:54 +03:00
|
|
|
virtual ~SVGFELightingElement() {}
|
2014-07-09 01:23:16 +04:00
|
|
|
|
2013-03-25 10:26:05 +04:00
|
|
|
public:
|
|
|
|
// interfaces:
|
2018-12-20 11:01:54 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(SVGFELightingElement,
|
|
|
|
SVGFELightingElementBase)
|
2013-03-25 10:26:05 +04:00
|
|
|
|
|
|
|
virtual bool AttributeAffectsRendering(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute) const override;
|
2019-01-06 20:52:55 +03:00
|
|
|
virtual SVGString& GetResultImageName() override {
|
2015-03-21 19:28:04 +03:00
|
|
|
return mStringAttributes[RESULT];
|
|
|
|
}
|
2018-12-21 19:24:17 +03:00
|
|
|
virtual void GetSourceImageNames(nsTArray<SVGStringInfo>& aSources) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
|
2013-03-25 10:26:05 +04:00
|
|
|
|
|
|
|
protected:
|
2013-11-27 15:25:29 +04:00
|
|
|
virtual bool OperatesOnSRGB(int32_t aInputIndex,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aInputIsAlreadySRGB) override {
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-25 10:26:05 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual NumberAttributesInfo GetNumberInfo() override;
|
|
|
|
virtual NumberPairAttributesInfo GetNumberPairInfo() override;
|
|
|
|
virtual StringAttributesInfo GetStringInfo() override;
|
2013-03-25 10:26:05 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
mozilla::gfx::LightType ComputeLightAttributes(
|
|
|
|
nsSVGFilterInstance* aInstance, nsTArray<float>& aFloatAttributes);
|
2013-11-27 15:25:29 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
bool AddLightingAttributes(
|
|
|
|
mozilla::gfx::DiffuseLightingAttributes* aAttributes,
|
|
|
|
nsSVGFilterInstance* aInstance);
|
2013-11-27 15:25:29 +04:00
|
|
|
|
2013-03-25 10:26:05 +04:00
|
|
|
enum {
|
|
|
|
SURFACE_SCALE,
|
|
|
|
DIFFUSE_CONSTANT,
|
|
|
|
SPECULAR_CONSTANT,
|
|
|
|
SPECULAR_EXPONENT
|
|
|
|
};
|
|
|
|
nsSVGNumber2 mNumberAttributes[4];
|
|
|
|
static NumberInfo sNumberInfo[4];
|
|
|
|
|
|
|
|
enum { KERNEL_UNIT_LENGTH };
|
2019-01-06 11:22:55 +03:00
|
|
|
SVGNumberPair mNumberPairAttributes[1];
|
2013-03-25 10:26:05 +04:00
|
|
|
static NumberPairInfo sNumberPairInfo[1];
|
|
|
|
|
|
|
|
enum { RESULT, IN1 };
|
2019-01-06 20:52:55 +03:00
|
|
|
SVGString mStringAttributes[2];
|
2013-03-25 10:26:05 +04:00
|
|
|
static StringInfo sStringInfo[2];
|
|
|
|
};
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
typedef SVGFEUnstyledElement SVGFELightElementBase;
|
2013-03-07 11:17:00 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
class SVGFELightElement : public SVGFELightElementBase {
|
|
|
|
protected:
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit SVGFELightElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGFELightElementBase(std::move(aNodeInfo)) {}
|
2013-11-27 15:25:29 +04:00
|
|
|
|
|
|
|
public:
|
2018-09-19 20:18:16 +03:00
|
|
|
typedef gfx::PrimitiveAttributes PrimitiveAttributes;
|
2013-03-07 11:17:00 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
virtual mozilla::gfx::LightType ComputeLightAttributes(
|
|
|
|
nsSVGFilterInstance* aInstance, nsTArray<float>& aFloatAttributes) = 0;
|
2013-11-27 15:25:29 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-03-07 11:17:00 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
#endif
|