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"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsImageLoadingContent.h"
|
|
|
|
#include "nsSVGLength2.h"
|
|
|
|
#include "nsSVGString.h"
|
2012-12-23 12:22:22 +04:00
|
|
|
#include "nsSVGElement.h"
|
2013-03-25 10:26:05 +04:00
|
|
|
#include "nsSVGNumber2.h"
|
|
|
|
#include "nsSVGNumberPair.h"
|
2013-11-27 15:25:29 +04:00
|
|
|
#include "FilterSupport.h"
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2012-01-26 13:57:21 +04:00
|
|
|
class nsSVGFilterInstance;
|
2011-07-01 11:19:52 +04:00
|
|
|
class nsSVGNumberPair;
|
2007-07-26 10:57:42 +04:00
|
|
|
|
2009-01-22 03:56:51 +03:00
|
|
|
struct nsSVGStringInfo {
|
|
|
|
nsSVGStringInfo(const nsSVGString* aString,
|
|
|
|
nsSVGElement *aElement) :
|
|
|
|
mString(aString), mElement(aElement) {}
|
|
|
|
|
|
|
|
const nsSVGString* mString;
|
|
|
|
nsSVGElement* mElement;
|
|
|
|
};
|
|
|
|
|
2012-12-23 12:22:22 +04:00
|
|
|
typedef nsSVGElement nsSVGFEBase;
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2008-02-18 10:29:00 +03:00
|
|
|
#define NS_SVG_FE_CID \
|
|
|
|
{ 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
|
|
|
|
*/
|
2006-04-14 19:09:39 +04:00
|
|
|
class nsSVGFE : public nsSVGFEBase
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit nsSVGFE(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2014-03-15 23:00:17 +04:00
|
|
|
: nsSVGFEBase(aNodeInfo) {}
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~nsSVGFE() {}
|
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
|
|
|
|
2012-03-03 13:21:09 +04:00
|
|
|
// nsSVGElement 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
|
|
|
|
2009-01-22 03:56:51 +03:00
|
|
|
virtual nsSVGString& 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.
|
2009-01-22 03:56:51 +03:00
|
|
|
virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& 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(
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t aNameSpaceID, 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();
|
|
|
|
|
2007-02-05 23:04:17 +03:00
|
|
|
// nsSVGElement 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,
|
|
|
|
nsSVGNumberPair *aKernelUnitLength);
|
|
|
|
|
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];
|
|
|
|
};
|
|
|
|
|
2014-03-28 12:45:02 +04:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsSVGFE, NS_SVG_FE_CID)
|
|
|
|
|
2011-11-19 21:53:52 +04:00
|
|
|
typedef nsSVGElement SVGFEUnstyledElementBase;
|
|
|
|
|
|
|
|
class SVGFEUnstyledElement : public SVGFEUnstyledElementBase
|
|
|
|
{
|
|
|
|
protected:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit SVGFEUnstyledElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2011-11-19 21:53:52 +04:00
|
|
|
: SVGFEUnstyledElementBase(aNodeInfo) {}
|
|
|
|
|
|
|
|
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(
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t aNameSpaceID, nsAtom* aAttribute) const = 0;
|
2011-11-19 21:53:52 +04:00
|
|
|
};
|
|
|
|
|
2013-03-25 10:26:05 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef nsSVGFE nsSVGFELightingElementBase;
|
|
|
|
|
|
|
|
class nsSVGFELightingElement : public nsSVGFELightingElementBase
|
|
|
|
{
|
|
|
|
protected:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit nsSVGFELightingElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-03-25 10:26:05 +04:00
|
|
|
: nsSVGFELightingElementBase(aNodeInfo) {}
|
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~nsSVGFELightingElement() {}
|
|
|
|
|
2013-03-25 10:26:05 +04:00
|
|
|
public:
|
|
|
|
// interfaces:
|
2018-02-12 23:43:55 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(nsSVGFELightingElement,
|
|
|
|
nsSVGFELightingElementBase)
|
2013-03-25 10:26:05 +04:00
|
|
|
|
|
|
|
virtual bool AttributeAffectsRendering(
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t aNameSpaceID, nsAtom* aAttribute) const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsSVGString& GetResultImageName() override { return mStringAttributes[RESULT]; }
|
|
|
|
virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& 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 };
|
|
|
|
nsSVGNumberPair mNumberPairAttributes[1];
|
|
|
|
static NumberPairInfo sNumberPairInfo[1];
|
|
|
|
|
|
|
|
enum { RESULT, IN1 };
|
|
|
|
nsSVGString mStringAttributes[2];
|
|
|
|
static StringInfo sStringInfo[2];
|
|
|
|
};
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
typedef SVGFEUnstyledElement SVGFELightElementBase;
|
2013-03-07 11:17:00 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
class SVGFELightElement : public SVGFELightElementBase
|
2013-03-07 11:17:00 +04:00
|
|
|
{
|
2013-11-27 15:25:29 +04:00
|
|
|
protected:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit SVGFELightElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-11-27 15:25:29 +04:00
|
|
|
: SVGFELightElementBase(aNodeInfo) {}
|
|
|
|
|
|
|
|
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
|