Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Back out 939f0488b0f7:46e4373d6d95 (bug 847120) and 13443c4586a4:e7f4…

…8e9b8bd7 (bug 853692) on suspicion of causing bug 854225 Linux32 PGO build failures

CLOSED TREE
  • Loading branch information...
commit e9467669ce88e1669ef92c7efe9853e0afd1a4b7 1 parent 4241f43
@philor philor authored
Showing with 2,418 additions and 2,812 deletions.
  1. +0 −14 content/svg/content/src/Makefile.in
  2. +0 −451 content/svg/content/src/SVGFEConvolveMatrixElement.cpp
  3. +0 −135 content/svg/content/src/SVGFEConvolveMatrixElement.h
  4. +0 −102 content/svg/content/src/SVGFEDiffuseLightingElement.cpp
  5. +0 −63 content/svg/content/src/SVGFEDiffuseLightingElement.h
  6. +0 −250 content/svg/content/src/SVGFEDisplacementMapElement.cpp
  7. +0 −107 content/svg/content/src/SVGFEDisplacementMapElement.h
  8. +0 −260 content/svg/content/src/SVGFEMorphologyElement.cpp
  9. +0 −95 content/svg/content/src/SVGFEMorphologyElement.h
  10. +0 −137 content/svg/content/src/SVGFESpecularLightingElement.cpp
  11. +0 −70 content/svg/content/src/SVGFESpecularLightingElement.h
  12. +0 −127 content/svg/content/src/SVGFESpotLightElement.cpp
  13. +0 −73 content/svg/content/src/SVGFESpotLightElement.h
  14. +0 −435 content/svg/content/src/SVGFETurbulenceElement.cpp
  15. +0 −163 content/svg/content/src/SVGFETurbulenceElement.h
  16. +5 −3 content/svg/content/src/nsSVGBoolean.cpp
  17. +2 −4 content/svg/content/src/nsSVGBoolean.h
  18. +2,236 −19 content/svg/content/src/nsSVGFilters.cpp
  19. +0 −73 content/svg/content/src/nsSVGFilters.h
  20. +2 −8 content/svg/content/src/nsSVGInteger.cpp
  21. +1 −3 content/svg/content/src/nsSVGInteger.h
  22. +55 −0 dom/base/nsDOMClassInfo.cpp
  23. +7 −0 dom/base/nsDOMClassInfoClasses.h
  24. +110 −0 dom/interfaces/svg/nsIDOMSVGFilters.idl
  25. +0 −39 dom/webidl/SVGFEConvolveMatrixElement.webidl
  26. +0 −24 dom/webidl/SVGFEDiffuseLightingElement.webidl
  27. +0 −33 dom/webidl/SVGFEDisplacementMapElement.webidl
  28. +0 −30 dom/webidl/SVGFEMorphologyElement.webidl
  29. +0 −25 dom/webidl/SVGFESpecularLightingElement.webidl
  30. +0 −24 dom/webidl/SVGFESpotLightElement.webidl
  31. +0 −38 dom/webidl/SVGFETurbulenceElement.webidl
  32. +0 −7 dom/webidl/WebIDL.mk
View
14 content/svg/content/src/Makefile.in
@@ -81,22 +81,15 @@ CPPSRCS = \
SVGFEColorMatrixElement.cpp \
SVGFEComponentTransferElement.cpp \
SVGFECompositeElement.cpp \
- SVGFEConvolveMatrixElement.cpp \
- SVGFEDiffuseLightingElement.cpp \
- SVGFEDisplacementMapElement.cpp \
SVGFEDistantLightElement.cpp \
SVGFEFloodElement.cpp \
SVGFEGaussianBlurElement.cpp \
SVGFEImageElement.cpp \
SVGFEMergeElement.cpp \
SVGFEMergeNodeElement.cpp \
- SVGFEMorphologyElement.cpp \
SVGFEOffsetElement.cpp \
SVGFEPointLightElement.cpp \
- SVGFESpecularLightingElement.cpp \
- SVGFESpotLightElement.cpp \
SVGFETileElement.cpp \
- SVGFETurbulenceElement.cpp \
SVGFilterElement.cpp \
SVGForeignObjectElement.cpp \
SVGFragmentIdentifier.cpp \
@@ -195,22 +188,15 @@ EXPORTS_mozilla/dom = \
SVGFEColorMatrixElement.h \
SVGFEComponentTransferElement.h \
SVGFECompositeElement.h \
- SVGFEConvolveMatrixElement.h \
- SVGFEDiffuseLightingElement.h \
- SVGFEDisplacementMapElement.h \
SVGFEDistantLightElement.h \
SVGFEFloodElement.h \
SVGFEGaussianBlurElement.h \
SVGFEImageElement.h \
SVGFEMergeElement.h \
SVGFEMergeNodeElement.h \
- SVGFEMorphologyElement.h \
SVGFEOffsetElement.h \
SVGFEPointLightElement.h \
- SVGFESpecularLightingElement.h \
- SVGFESpotLightElement.h \
SVGFETileElement.h \
- SVGFETurbulenceElement.h \
SVGFilterElement.h \
SVGForeignObjectElement.h \
SVGGElement.h \
View
451 content/svg/content/src/SVGFEConvolveMatrixElement.cpp
@@ -1,451 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/dom/SVGFEConvolveMatrixElement.h"
-#include "mozilla/dom/SVGFEConvolveMatrixElementBinding.h"
-#include "DOMSVGAnimatedNumberList.h"
-#include "nsSVGUtils.h"
-
-NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEConvolveMatrix)
-
-namespace mozilla {
-namespace dom {
-
-// Edge Mode Values
-static const unsigned short SVG_EDGEMODE_UNKNOWN = 0;
-static const unsigned short SVG_EDGEMODE_DUPLICATE = 1;
-static const unsigned short SVG_EDGEMODE_WRAP = 2;
-static const unsigned short SVG_EDGEMODE_NONE = 3;
-
-JSObject*
-SVGFEConvolveMatrixElement::WrapNode(JSContext* aCx, JSObject* aScope)
-{
- return SVGFEConvolveMatrixElementBinding::Wrap(aCx, aScope, this);
-}
-
-nsSVGElement::NumberInfo SVGFEConvolveMatrixElement::sNumberInfo[2] =
-{
- { &nsGkAtoms::divisor, 1, false },
- { &nsGkAtoms::bias, 0, false }
-};
-
-nsSVGElement::NumberPairInfo SVGFEConvolveMatrixElement::sNumberPairInfo[1] =
-{
- { &nsGkAtoms::kernelUnitLength, 0, 0 }
-};
-
-nsSVGElement::IntegerInfo SVGFEConvolveMatrixElement::sIntegerInfo[2] =
-{
- { &nsGkAtoms::targetX, 0 },
- { &nsGkAtoms::targetY, 0 }
-};
-
-nsSVGElement::IntegerPairInfo SVGFEConvolveMatrixElement::sIntegerPairInfo[1] =
-{
- { &nsGkAtoms::order, 3, 3 }
-};
-
-nsSVGElement::BooleanInfo SVGFEConvolveMatrixElement::sBooleanInfo[1] =
-{
- { &nsGkAtoms::preserveAlpha, false }
-};
-
-nsSVGEnumMapping SVGFEConvolveMatrixElement::sEdgeModeMap[] = {
- {&nsGkAtoms::duplicate, SVG_EDGEMODE_DUPLICATE},
- {&nsGkAtoms::wrap, SVG_EDGEMODE_WRAP},
- {&nsGkAtoms::none, SVG_EDGEMODE_NONE},
- {nullptr, 0}
-};
-
-nsSVGElement::EnumInfo SVGFEConvolveMatrixElement::sEnumInfo[1] =
-{
- { &nsGkAtoms::edgeMode,
- sEdgeModeMap,
- SVG_EDGEMODE_DUPLICATE
- }
-};
-
-nsSVGElement::StringInfo SVGFEConvolveMatrixElement::sStringInfo[2] =
-{
- { &nsGkAtoms::result, kNameSpaceID_None, true },
- { &nsGkAtoms::in, kNameSpaceID_None, true }
-};
-
-nsSVGElement::NumberListInfo SVGFEConvolveMatrixElement::sNumberListInfo[1] =
-{
- { &nsGkAtoms::kernelMatrix }
-};
-
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_IMPL_ADDREF_INHERITED(SVGFEConvolveMatrixElement,SVGFEConvolveMatrixElementBase)
-NS_IMPL_RELEASE_INHERITED(SVGFEConvolveMatrixElement,SVGFEConvolveMatrixElementBase)
-
-NS_INTERFACE_TABLE_HEAD(SVGFEConvolveMatrixElement)
- NS_NODE_INTERFACE_TABLE3(SVGFEConvolveMatrixElement, nsIDOMNode,
- nsIDOMElement, nsIDOMSVGElement)
-NS_INTERFACE_MAP_END_INHERITING(SVGFEConvolveMatrixElementBase)
-
-
-//----------------------------------------------------------------------
-// nsIDOMNode methods
-
-NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEConvolveMatrixElement)
-
-//----------------------------------------------------------------------
-
-already_AddRefed<nsIDOMSVGAnimatedString>
-SVGFEConvolveMatrixElement::In1()
-{
- return mStringAttributes[IN1].ToDOMAnimatedString(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedInteger>
-SVGFEConvolveMatrixElement::OrderX()
-{
- return mIntegerPairAttributes[ORDER].ToDOMAnimatedInteger(nsSVGIntegerPair::eFirst, this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedInteger>
-SVGFEConvolveMatrixElement::OrderY()
-{
- return mIntegerPairAttributes[ORDER].ToDOMAnimatedInteger(nsSVGIntegerPair::eSecond, this);
-}
-
-already_AddRefed<DOMSVGAnimatedNumberList>
-SVGFEConvolveMatrixElement::KernelMatrix()
-{
- return DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes[KERNELMATRIX],
- this, KERNELMATRIX);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedInteger>
-SVGFEConvolveMatrixElement::TargetX()
-{
- return mIntegerAttributes[TARGET_X].ToDOMAnimatedInteger(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedInteger>
-SVGFEConvolveMatrixElement::TargetY()
-{
- return mIntegerAttributes[TARGET_Y].ToDOMAnimatedInteger(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedEnumeration>
-SVGFEConvolveMatrixElement::EdgeMode()
-{
- return mEnumAttributes[EDGEMODE].ToDOMAnimatedEnum(this);
-}
-
-already_AddRefed<SVGAnimatedBoolean>
-SVGFEConvolveMatrixElement::PreserveAlpha()
-{
- return mBooleanAttributes[PRESERVEALPHA].ToDOMAnimatedBoolean(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEConvolveMatrixElement::Divisor()
-{
- return mNumberAttributes[DIVISOR].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEConvolveMatrixElement::Bias()
-{
- return mNumberAttributes[BIAS].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEConvolveMatrixElement::KernelUnitLengthX()
-{
- return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst,
- this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEConvolveMatrixElement::KernelUnitLengthY()
-{
- return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond,
- this);
-}
-
-void
-SVGFEConvolveMatrixElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
-{
- aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
-}
-
-nsIntRect
-SVGFEConvolveMatrixElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance)
-{
- // XXX A more precise box is possible when 'bias' is zero and 'edgeMode' is
- // 'none', but it requires analysis of 'kernelUnitLength', 'order' and
- // 'targetX/Y', so it's quite a lot of work. Don't do it for now.
- return GetMaxRect();
-}
-
-void
-SVGFEConvolveMatrixElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
- nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance)
-{
- // XXX Precise results are possible but we're going to skip that work
- // for now. Do nothing, which means the needed-box remains the
- // source's output bounding box.
-}
-
-nsIntRect
-SVGFEConvolveMatrixElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
- const nsSVGFilterInstance& aInstance)
-{
- // XXX Precise results are possible but we're going to skip that work
- // for now.
- return GetMaxRect();
-}
-
-static int32_t BoundInterval(int32_t aVal, int32_t aMax)
-{
- aVal = std::max(aVal, 0);
- return std::min(aVal, aMax - 1);
-}
-
-static int32_t WrapInterval(int32_t aVal, int32_t aMax)
-{
- aVal = aVal % aMax;
- return aVal < 0 ? aMax + aVal : aVal;
-}
-
-static void
-ConvolvePixel(const uint8_t *aSourceData,
- uint8_t *aTargetData,
- int32_t aWidth, int32_t aHeight,
- int32_t aStride,
- int32_t aX, int32_t aY,
- uint16_t aEdgeMode,
- const float *aKernel,
- float aDivisor, float aBias,
- bool aPreserveAlpha,
- int32_t aOrderX, int32_t aOrderY,
- int32_t aTargetX, int32_t aTargetY)
-{
- float sum[4] = {0, 0, 0, 0};
- aBias *= 255;
- int32_t offsets[4] = {GFX_ARGB32_OFFSET_R,
- GFX_ARGB32_OFFSET_G,
- GFX_ARGB32_OFFSET_B,
- GFX_ARGB32_OFFSET_A } ;
- int32_t channels = aPreserveAlpha ? 3 : 4;
-
- for (int32_t y = 0; y < aOrderY; y++) {
- int32_t sampleY = aY + y - aTargetY;
- bool overscanY = sampleY < 0 || sampleY >= aHeight;
- for (int32_t x = 0; x < aOrderX; x++) {
- int32_t sampleX = aX + x - aTargetX;
- bool overscanX = sampleX < 0 || sampleX >= aWidth;
- for (int32_t i = 0; i < channels; i++) {
- if (overscanY || overscanX) {
- switch (aEdgeMode) {
- case SVG_EDGEMODE_DUPLICATE:
- sum[i] +=
- aSourceData[BoundInterval(sampleY, aHeight) * aStride +
- BoundInterval(sampleX, aWidth) * 4 + offsets[i]] *
- aKernel[aOrderX * y + x];
- break;
- case SVG_EDGEMODE_WRAP:
- sum[i] +=
- aSourceData[WrapInterval(sampleY, aHeight) * aStride +
- WrapInterval(sampleX, aWidth) * 4 + offsets[i]] *
- aKernel[aOrderX * y + x];
- break;
- default:
- break;
- }
- } else {
- sum[i] +=
- aSourceData[sampleY * aStride + 4 * sampleX + offsets[i]] *
- aKernel[aOrderX * y + x];
- }
- }
- }
- }
- for (int32_t i = 0; i < channels; i++) {
- aTargetData[aY * aStride + 4 * aX + offsets[i]] =
- BoundInterval(static_cast<int32_t>(sum[i] / aDivisor + aBias), 256);
- }
- if (aPreserveAlpha) {
- aTargetData[aY * aStride + 4 * aX + GFX_ARGB32_OFFSET_A] =
- aSourceData[aY * aStride + 4 * aX + GFX_ARGB32_OFFSET_A];
- }
-}
-
-nsresult
-SVGFEConvolveMatrixElement::Filter(nsSVGFilterInstance* instance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& rect)
-{
- const SVGNumberList &kernelMatrix =
- mNumberListAttributes[KERNELMATRIX].GetAnimValue();
- uint32_t kmLength = kernelMatrix.Length();
-
- int32_t orderX = mIntegerPairAttributes[ORDER].GetAnimValue(nsSVGIntegerPair::eFirst);
- int32_t orderY = mIntegerPairAttributes[ORDER].GetAnimValue(nsSVGIntegerPair::eSecond);
-
- if (orderX <= 0 || orderY <= 0 ||
- static_cast<uint32_t>(orderX * orderY) != kmLength) {
- return NS_ERROR_FAILURE;
- }
-
- int32_t targetX, targetY;
- GetAnimatedIntegerValues(&targetX, &targetY, nullptr);
-
- if (mIntegerAttributes[TARGET_X].IsExplicitlySet()) {
- if (targetX < 0 || targetX >= orderX)
- return NS_ERROR_FAILURE;
- } else {
- targetX = orderX / 2;
- }
- if (mIntegerAttributes[TARGET_Y].IsExplicitlySet()) {
- if (targetY < 0 || targetY >= orderY)
- return NS_ERROR_FAILURE;
- } else {
- targetY = orderY / 2;
- }
-
- if (orderX > NS_SVG_OFFSCREEN_MAX_DIMENSION ||
- orderY > NS_SVG_OFFSCREEN_MAX_DIMENSION)
- return NS_ERROR_FAILURE;
- nsAutoArrayPtr<float> kernel(new float[orderX * orderY]);
- if (!kernel)
- return NS_ERROR_FAILURE;
- for (uint32_t i = 0; i < kmLength; i++) {
- kernel[kmLength - 1 - i] = kernelMatrix[i];
- }
-
- float divisor;
- if (mNumberAttributes[DIVISOR].IsExplicitlySet()) {
- divisor = mNumberAttributes[DIVISOR].GetAnimValue();
- if (divisor == 0)
- return NS_ERROR_FAILURE;
- } else {
- divisor = kernel[0];
- for (uint32_t i = 1; i < kmLength; i++)
- divisor += kernel[i];
- if (divisor == 0)
- divisor = 1;
- }
-
- ScaleInfo info = SetupScalingFilter(instance, aSources[0], aTarget, rect,
- &mNumberPairAttributes[KERNEL_UNIT_LENGTH]);
- if (!info.mTarget)
- return NS_ERROR_FAILURE;
-
- uint16_t edgeMode = mEnumAttributes[EDGEMODE].GetAnimValue();
- bool preserveAlpha = mBooleanAttributes[PRESERVEALPHA].GetAnimValue();
-
- float bias = mNumberAttributes[BIAS].GetAnimValue();
-
- const nsIntRect& dataRect = info.mDataRect;
- int32_t stride = info.mSource->Stride();
- int32_t width = info.mSource->GetSize().width;
- int32_t height = info.mSource->GetSize().height;
- uint8_t *sourceData = info.mSource->Data();
- uint8_t *targetData = info.mTarget->Data();
-
- for (int32_t y = dataRect.y; y < dataRect.YMost(); y++) {
- for (int32_t x = dataRect.x; x < dataRect.XMost(); x++) {
- ConvolvePixel(sourceData, targetData,
- width, height, stride,
- x, y,
- edgeMode, kernel, divisor, bias, preserveAlpha,
- orderX, orderY, targetX, targetY);
- }
- }
-
- FinishScalingFilter(&info);
-
- return NS_OK;
-}
-
-bool
-SVGFEConvolveMatrixElement::AttributeAffectsRendering(int32_t aNameSpaceID,
- nsIAtom* aAttribute) const
-{
- return SVGFEConvolveMatrixElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
- (aNameSpaceID == kNameSpaceID_None &&
- (aAttribute == nsGkAtoms::in ||
- aAttribute == nsGkAtoms::divisor ||
- aAttribute == nsGkAtoms::bias ||
- aAttribute == nsGkAtoms::kernelUnitLength ||
- aAttribute == nsGkAtoms::targetX ||
- aAttribute == nsGkAtoms::targetY ||
- aAttribute == nsGkAtoms::order ||
- aAttribute == nsGkAtoms::preserveAlpha||
- aAttribute == nsGkAtoms::edgeMode ||
- aAttribute == nsGkAtoms::kernelMatrix));
-}
-
-//----------------------------------------------------------------------
-// nsSVGElement methods
-
-nsSVGElement::NumberAttributesInfo
-SVGFEConvolveMatrixElement::GetNumberInfo()
-{
- return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
- ArrayLength(sNumberInfo));
-}
-
-nsSVGElement::NumberPairAttributesInfo
-SVGFEConvolveMatrixElement::GetNumberPairInfo()
-{
- return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
- ArrayLength(sNumberPairInfo));
-}
-
-nsSVGElement::IntegerAttributesInfo
-SVGFEConvolveMatrixElement::GetIntegerInfo()
-{
- return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
- ArrayLength(sIntegerInfo));
-}
-
-nsSVGElement::IntegerPairAttributesInfo
-SVGFEConvolveMatrixElement::GetIntegerPairInfo()
-{
- return IntegerPairAttributesInfo(mIntegerPairAttributes, sIntegerPairInfo,
- ArrayLength(sIntegerPairInfo));
-}
-
-nsSVGElement::BooleanAttributesInfo
-SVGFEConvolveMatrixElement::GetBooleanInfo()
-{
- return BooleanAttributesInfo(mBooleanAttributes, sBooleanInfo,
- ArrayLength(sBooleanInfo));
-}
-
-nsSVGElement::EnumAttributesInfo
-SVGFEConvolveMatrixElement::GetEnumInfo()
-{
- return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
- ArrayLength(sEnumInfo));
-}
-
-nsSVGElement::StringAttributesInfo
-SVGFEConvolveMatrixElement::GetStringInfo()
-{
- return StringAttributesInfo(mStringAttributes, sStringInfo,
- ArrayLength(sStringInfo));
-}
-
-nsSVGElement::NumberListAttributesInfo
-SVGFEConvolveMatrixElement::GetNumberListInfo()
-{
- return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
- ArrayLength(sNumberListInfo));
-}
-
-} // namespace dom
-} // namespace mozilla
View
135 content/svg/content/src/SVGFEConvolveMatrixElement.h
@@ -1,135 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_SVGFEConvolveMatrixElement_h
-#define mozilla_dom_SVGFEConvolveMatrixElement_h
-
-#include "nsSVGBoolean.h"
-#include "nsSVGEnum.h"
-#include "nsSVGFilters.h"
-#include "nsSVGInteger.h"
-#include "nsSVGIntegerPair.h"
-#include "nsSVGNumber2.h"
-#include "nsSVGString.h"
-#include "SVGAnimatedNumberList.h"
-
-nsresult NS_NewSVGFEConvolveMatrixElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo);
-
-namespace mozilla {
-class DOMSVGAnimatedNumberList;
-
-namespace dom {
-class SVGAnimatedBoolean;
-
-typedef nsSVGFE SVGFEConvolveMatrixElementBase;
-
-class SVGFEConvolveMatrixElement : public SVGFEConvolveMatrixElementBase,
- public nsIDOMSVGElement
-{
- friend nsresult (::NS_NewSVGFEConvolveMatrixElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo));
-protected:
- SVGFEConvolveMatrixElement(already_AddRefed<nsINodeInfo> aNodeInfo)
- : SVGFEConvolveMatrixElementBase(aNodeInfo)
- {
- SetIsDOMBinding();
- }
- virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
-
-public:
- // interfaces:
- NS_DECL_ISUPPORTS_INHERITED
-
- virtual nsresult Filter(nsSVGFilterInstance* aInstance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& aDataRect);
- virtual bool AttributeAffectsRendering(
- int32_t aNameSpaceID, nsIAtom* aAttribute) const;
- virtual nsSVGString& GetResultImageName() { return mStringAttributes[RESULT]; }
- virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
- virtual nsIntRect ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance);
- virtual void ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
- nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance);
- virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
- const nsSVGFilterInstance& aInstance);
-
- NS_FORWARD_NSIDOMSVGELEMENT(SVGFEConvolveMatrixElementBase::)
-
- NS_FORWARD_NSIDOMNODE_TO_NSINODE
- NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
-
- virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
- virtual nsIDOMNode* AsDOMNode() { return this; }
-
- // WebIDL
- already_AddRefed<nsIDOMSVGAnimatedString> In1();
- already_AddRefed<nsIDOMSVGAnimatedInteger> OrderX();
- already_AddRefed<nsIDOMSVGAnimatedInteger> OrderY();
- already_AddRefed<DOMSVGAnimatedNumberList> KernelMatrix();
- already_AddRefed<nsIDOMSVGAnimatedInteger> TargetX();
- already_AddRefed<nsIDOMSVGAnimatedInteger> TargetY();
- already_AddRefed<nsIDOMSVGAnimatedEnumeration> EdgeMode();
- already_AddRefed<SVGAnimatedBoolean> PreserveAlpha();
- already_AddRefed<nsIDOMSVGAnimatedNumber> Divisor();
- already_AddRefed<nsIDOMSVGAnimatedNumber> Bias();
- already_AddRefed<nsIDOMSVGAnimatedNumber> KernelUnitLengthX();
- already_AddRefed<nsIDOMSVGAnimatedNumber> KernelUnitLengthY();
-
-protected:
- virtual bool OperatesOnPremultipledAlpha(int32_t) {
- return !mBooleanAttributes[PRESERVEALPHA].GetAnimValue();
- }
-
- virtual NumberAttributesInfo GetNumberInfo();
- virtual NumberPairAttributesInfo GetNumberPairInfo();
- virtual IntegerAttributesInfo GetIntegerInfo();
- virtual IntegerPairAttributesInfo GetIntegerPairInfo();
- virtual BooleanAttributesInfo GetBooleanInfo();
- virtual EnumAttributesInfo GetEnumInfo();
- virtual StringAttributesInfo GetStringInfo();
- virtual NumberListAttributesInfo GetNumberListInfo();
-
- enum { DIVISOR, BIAS };
- nsSVGNumber2 mNumberAttributes[2];
- static NumberInfo sNumberInfo[2];
-
- enum { KERNEL_UNIT_LENGTH };
- nsSVGNumberPair mNumberPairAttributes[1];
- static NumberPairInfo sNumberPairInfo[1];
-
- enum { TARGET_X, TARGET_Y };
- nsSVGInteger mIntegerAttributes[2];
- static IntegerInfo sIntegerInfo[2];
-
- enum { ORDER };
- nsSVGIntegerPair mIntegerPairAttributes[1];
- static IntegerPairInfo sIntegerPairInfo[1];
-
- enum { PRESERVEALPHA };
- nsSVGBoolean mBooleanAttributes[1];
- static BooleanInfo sBooleanInfo[1];
-
- enum { EDGEMODE };
- nsSVGEnum mEnumAttributes[1];
- static nsSVGEnumMapping sEdgeModeMap[];
- static EnumInfo sEnumInfo[1];
-
- enum { RESULT, IN1 };
- nsSVGString mStringAttributes[2];
- static StringInfo sStringInfo[2];
-
- enum { KERNELMATRIX };
- SVGAnimatedNumberList mNumberListAttributes[1];
- static NumberListInfo sNumberListInfo[1];
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_SVGFEConvolveMatrixElement_h
View
102 content/svg/content/src/SVGFEDiffuseLightingElement.cpp
@@ -1,102 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/dom/SVGFEDiffuseLightingElement.h"
-#include "mozilla/dom/SVGFEDiffuseLightingElementBinding.h"
-#include "nsSVGUtils.h"
-
-NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEDiffuseLighting)
-
-namespace mozilla {
-namespace dom {
-
-JSObject*
-SVGFEDiffuseLightingElement::WrapNode(JSContext* aCx, JSObject* aScope)
-{
- return SVGFEDiffuseLightingElementBinding::Wrap(aCx, aScope, this);
-}
-
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_IMPL_ADDREF_INHERITED(SVGFEDiffuseLightingElement,SVGFEDiffuseLightingElementBase)
-NS_IMPL_RELEASE_INHERITED(SVGFEDiffuseLightingElement,SVGFEDiffuseLightingElementBase)
-
-NS_INTERFACE_TABLE_HEAD(SVGFEDiffuseLightingElement)
- NS_NODE_INTERFACE_TABLE3(SVGFEDiffuseLightingElement, nsIDOMNode,
- nsIDOMElement, nsIDOMSVGElement)
-NS_INTERFACE_MAP_END_INHERITING(SVGFEDiffuseLightingElementBase)
-
-//----------------------------------------------------------------------
-// nsIDOMNode methods
-
-NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDiffuseLightingElement)
-
-//----------------------------------------------------------------------
-
-already_AddRefed<nsIDOMSVGAnimatedString>
-SVGFEDiffuseLightingElement::In1()
-{
- return mStringAttributes[IN1].ToDOMAnimatedString(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEDiffuseLightingElement::SurfaceScale()
-{
- return mNumberAttributes[SURFACE_SCALE].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEDiffuseLightingElement::DiffuseConstant()
-{
- return mNumberAttributes[DIFFUSE_CONSTANT].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEDiffuseLightingElement::KernelUnitLengthX()
-{
- return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
- nsSVGNumberPair::eFirst, this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEDiffuseLightingElement::KernelUnitLengthY()
-{
- return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
- nsSVGNumberPair::eSecond, this);
-}
-
-bool
-SVGFEDiffuseLightingElement::AttributeAffectsRendering(int32_t aNameSpaceID,
- nsIAtom* aAttribute) const
-{
- return SVGFEDiffuseLightingElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
- (aNameSpaceID == kNameSpaceID_None &&
- aAttribute == nsGkAtoms::diffuseConstant);
-}
-
-//----------------------------------------------------------------------
-// nsSVGElement methods
-
-void
-SVGFEDiffuseLightingElement::LightPixel(const float *N, const float *L,
- nscolor color, uint8_t *targetData)
-{
- float diffuseNL =
- mNumberAttributes[DIFFUSE_CONSTANT].GetAnimValue() * DOT(N, L);
-
- if (diffuseNL < 0) diffuseNL = 0;
-
- targetData[GFX_ARGB32_OFFSET_B] =
- std::min(uint32_t(diffuseNL * NS_GET_B(color)), 255U);
- targetData[GFX_ARGB32_OFFSET_G] =
- std::min(uint32_t(diffuseNL * NS_GET_G(color)), 255U);
- targetData[GFX_ARGB32_OFFSET_R] =
- std::min(uint32_t(diffuseNL * NS_GET_R(color)), 255U);
- targetData[GFX_ARGB32_OFFSET_A] = 255;
-}
-
-} // namespace dom
-} // namespace mozilla
View
63 content/svg/content/src/SVGFEDiffuseLightingElement.h
@@ -1,63 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_SVGFEDiffuseLightingElement_h
-#define mozilla_dom_SVGFEDiffuseLightingElement_h
-
-#include "nsSVGFilters.h"
-
-nsresult NS_NewSVGFEDiffuseLightingElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo);
-
-namespace mozilla {
-namespace dom {
-
-typedef nsSVGFELightingElement SVGFEDiffuseLightingElementBase;
-
-class SVGFEDiffuseLightingElement : public SVGFEDiffuseLightingElementBase,
- public nsIDOMSVGElement
-{
- friend nsresult (::NS_NewSVGFEDiffuseLightingElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo));
-protected:
- SVGFEDiffuseLightingElement(already_AddRefed<nsINodeInfo> aNodeInfo)
- : SVGFEDiffuseLightingElementBase(aNodeInfo)
- {
- SetIsDOMBinding();
- }
- virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
-
-public:
- // interfaces:
- NS_DECL_ISUPPORTS_INHERITED
-
- NS_FORWARD_NSIDOMSVGELEMENT(SVGFEDiffuseLightingElementBase::)
- NS_FORWARD_NSIDOMNODE_TO_NSINODE
- NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
-
- virtual bool AttributeAffectsRendering(
- int32_t aNameSpaceID, nsIAtom* aAttribute) const;
-
- virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
- virtual nsIDOMNode* AsDOMNode() { return this; }
-
- // WebIDL
- already_AddRefed<nsIDOMSVGAnimatedString> In1();
- already_AddRefed<nsIDOMSVGAnimatedNumber> SurfaceScale();
- already_AddRefed<nsIDOMSVGAnimatedNumber> DiffuseConstant();
- already_AddRefed<nsIDOMSVGAnimatedNumber> KernelUnitLengthX();
- already_AddRefed<nsIDOMSVGAnimatedNumber> KernelUnitLengthY();
-
-protected:
- virtual void LightPixel(const float *N, const float *L,
- nscolor color, uint8_t *targetData);
-
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_SVGFEDiffuseLightingElement_h
View
250 content/svg/content/src/SVGFEDisplacementMapElement.cpp
@@ -1,250 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/dom/SVGFEDisplacementMapElement.h"
-#include "mozilla/dom/SVGFEDisplacementMapElementBinding.h"
-#include "nsSVGFilterInstance.h"
-#include "nsSVGUtils.h"
-
-NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEDisplacementMap)
-
-namespace mozilla {
-namespace dom {
-
-// Channel Selectors
-static const unsigned short SVG_CHANNEL_UNKNOWN = 0;
-static const unsigned short SVG_CHANNEL_R = 1;
-static const unsigned short SVG_CHANNEL_G = 2;
-static const unsigned short SVG_CHANNEL_B = 3;
-static const unsigned short SVG_CHANNEL_A = 4;
-
-JSObject*
-SVGFEDisplacementMapElement::WrapNode(JSContext* aCx, JSObject* aScope)
-{
- return SVGFEDisplacementMapElementBinding::Wrap(aCx, aScope, this);
-}
-
-nsSVGElement::NumberInfo SVGFEDisplacementMapElement::sNumberInfo[1] =
-{
- { &nsGkAtoms::scale, 0, false },
-};
-
-nsSVGEnumMapping SVGFEDisplacementMapElement::sChannelMap[] = {
- {&nsGkAtoms::R, SVG_CHANNEL_R},
- {&nsGkAtoms::G, SVG_CHANNEL_G},
- {&nsGkAtoms::B, SVG_CHANNEL_B},
- {&nsGkAtoms::A, SVG_CHANNEL_A},
- {nullptr, 0}
-};
-
-nsSVGElement::EnumInfo SVGFEDisplacementMapElement::sEnumInfo[2] =
-{
- { &nsGkAtoms::xChannelSelector,
- sChannelMap,
- SVG_CHANNEL_A
- },
- { &nsGkAtoms::yChannelSelector,
- sChannelMap,
- SVG_CHANNEL_A
- }
-};
-
-nsSVGElement::StringInfo SVGFEDisplacementMapElement::sStringInfo[3] =
-{
- { &nsGkAtoms::result, kNameSpaceID_None, true },
- { &nsGkAtoms::in, kNameSpaceID_None, true },
- { &nsGkAtoms::in2, kNameSpaceID_None, true }
-};
-
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_IMPL_ADDREF_INHERITED(SVGFEDisplacementMapElement,SVGFEDisplacementMapElementBase)
-NS_IMPL_RELEASE_INHERITED(SVGFEDisplacementMapElement,SVGFEDisplacementMapElementBase)
-
-NS_INTERFACE_TABLE_HEAD(SVGFEDisplacementMapElement)
- NS_NODE_INTERFACE_TABLE3(SVGFEDisplacementMapElement, nsIDOMNode,
- nsIDOMElement, nsIDOMSVGElement)
-NS_INTERFACE_MAP_END_INHERITING(SVGFEDisplacementMapElementBase)
-
-//----------------------------------------------------------------------
-// nsIDOMNode methods
-
-NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDisplacementMapElement)
-
-//----------------------------------------------------------------------
-
-already_AddRefed<nsIDOMSVGAnimatedString>
-SVGFEDisplacementMapElement::In1()
-{
- return mStringAttributes[IN1].ToDOMAnimatedString(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedString>
-SVGFEDisplacementMapElement::In2()
-{
- return mStringAttributes[IN2].ToDOMAnimatedString(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEDisplacementMapElement::Scale()
-{
- return mNumberAttributes[SCALE].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedEnumeration>
-SVGFEDisplacementMapElement::XChannelSelector()
-{
- return mEnumAttributes[CHANNEL_X].ToDOMAnimatedEnum(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedEnumeration>
-SVGFEDisplacementMapElement::YChannelSelector()
-{
- return mEnumAttributes[CHANNEL_Y].ToDOMAnimatedEnum(this);
-}
-
-nsresult
-SVGFEDisplacementMapElement::Filter(nsSVGFilterInstance* instance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& rect)
-{
- float scale = instance->GetPrimitiveNumber(SVGContentUtils::XY,
- &mNumberAttributes[SCALE]);
- if (scale == 0.0f) {
- CopyRect(aTarget, aSources[0], rect);
- return NS_OK;
- }
-
- int32_t width = instance->GetSurfaceWidth();
- int32_t height = instance->GetSurfaceHeight();
-
- uint8_t* sourceData = aSources[0]->mImage->Data();
- uint8_t* displacementData = aSources[1]->mImage->Data();
- uint8_t* targetData = aTarget->mImage->Data();
- uint32_t stride = aTarget->mImage->Stride();
-
- static const uint8_t dummyData[4] = { 0, 0, 0, 0 };
-
- static const uint16_t channelMap[5] = {
- 0,
- GFX_ARGB32_OFFSET_R,
- GFX_ARGB32_OFFSET_G,
- GFX_ARGB32_OFFSET_B,
- GFX_ARGB32_OFFSET_A };
- uint16_t xChannel = channelMap[mEnumAttributes[CHANNEL_X].GetAnimValue()];
- uint16_t yChannel = channelMap[mEnumAttributes[CHANNEL_Y].GetAnimValue()];
-
- double scaleOver255 = scale / 255.0;
- double scaleAdjustment = 0.5 - 0.5 * scale;
-
- for (int32_t y = rect.y; y < rect.YMost(); y++) {
- for (int32_t x = rect.x; x < rect.XMost(); x++) {
- uint32_t targIndex = y * stride + 4 * x;
- // At some point we might want to replace this with a bilinear sample.
- int32_t sourceX = x +
- NSToIntFloor(scaleOver255 * displacementData[targIndex + xChannel] +
- scaleAdjustment);
- int32_t sourceY = y +
- NSToIntFloor(scaleOver255 * displacementData[targIndex + yChannel] +
- scaleAdjustment);
-
- bool outOfBounds = sourceX < 0 || sourceX >= width ||
- sourceY < 0 || sourceY >= height;
- const uint8_t* data;
- int32_t multiplier;
- if (outOfBounds) {
- data = dummyData;
- multiplier = 0;
- } else {
- data = sourceData;
- multiplier = 1;
- }
- *(uint32_t*)(targetData + targIndex) =
- *(uint32_t*)(data + multiplier * (sourceY * stride + 4 * sourceX));
- }
- }
- return NS_OK;
-}
-
-bool
-SVGFEDisplacementMapElement::AttributeAffectsRendering(int32_t aNameSpaceID,
- nsIAtom* aAttribute) const
-{
- return SVGFEDisplacementMapElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
- (aNameSpaceID == kNameSpaceID_None &&
- (aAttribute == nsGkAtoms::in ||
- aAttribute == nsGkAtoms::in2 ||
- aAttribute == nsGkAtoms::scale ||
- aAttribute == nsGkAtoms::xChannelSelector ||
- aAttribute == nsGkAtoms::yChannelSelector));
-}
-
-void
-SVGFEDisplacementMapElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
-{
- aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
- aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN2], this));
-}
-
-nsIntRect
-SVGFEDisplacementMapElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance)
-{
- // XXX we could do something clever here involving analysis of 'scale'
- // to figure out the maximum displacement, and then return mIn1's bounds
- // adjusted for the maximum displacement
- return GetMaxRect();
-}
-
-void
-SVGFEDisplacementMapElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
- nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance)
-{
- // in2 contains the displacements, which we read for each target pixel
- aSourceBBoxes[1] = aTargetBBox;
- // XXX to figure out which parts of 'in' we might read, we could
- // do some analysis of 'scale' to figure out the maximum displacement.
- // For now, just leave aSourceBBoxes[0] alone, i.e. assume we use its
- // entire output bounding box.
- // If we change this, we need to change coordinate assumptions above
-}
-
-nsIntRect
-SVGFEDisplacementMapElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
- const nsSVGFilterInstance& aInstance)
-{
- // XXX we could do something clever here involving analysis of 'scale'
- // to figure out the maximum displacement
- return GetMaxRect();
-}
-
-//----------------------------------------------------------------------
-// nsSVGElement methods
-
-nsSVGElement::NumberAttributesInfo
-SVGFEDisplacementMapElement::GetNumberInfo()
-{
- return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
- ArrayLength(sNumberInfo));
-}
-
-nsSVGElement::EnumAttributesInfo
-SVGFEDisplacementMapElement::GetEnumInfo()
-{
- return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
- ArrayLength(sEnumInfo));
-}
-
-nsSVGElement::StringAttributesInfo
-SVGFEDisplacementMapElement::GetStringInfo()
-{
- return StringAttributesInfo(mStringAttributes, sStringInfo,
- ArrayLength(sStringInfo));
-}
-
-} // namespace dom
-} // namespace mozilla
View
107 content/svg/content/src/SVGFEDisplacementMapElement.h
@@ -1,107 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_SVGFEDisplacementMapElement_h
-#define mozilla_dom_SVGFEDisplacementMapElement_h
-
-#include "nsSVGEnum.h"
-#include "nsSVGFilters.h"
-
-nsresult NS_NewSVGFEDisplacementMapElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo);
-
-namespace mozilla {
-namespace dom {
-
-typedef nsSVGFE SVGFEDisplacementMapElementBase;
-
-class SVGFEDisplacementMapElement : public SVGFEDisplacementMapElementBase,
- public nsIDOMSVGElement
-{
-protected:
- friend nsresult (::NS_NewSVGFEDisplacementMapElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo));
- SVGFEDisplacementMapElement(already_AddRefed<nsINodeInfo> aNodeInfo)
- : SVGFEDisplacementMapElementBase(aNodeInfo)
- {
- SetIsDOMBinding();
- }
- virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
-
-public:
- // interfaces:
- NS_DECL_ISUPPORTS_INHERITED
-
- virtual nsresult Filter(nsSVGFilterInstance* aInstance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& aDataRect);
- virtual bool AttributeAffectsRendering(
- int32_t aNameSpaceID, nsIAtom* aAttribute) const;
- virtual nsSVGString& GetResultImageName() { return mStringAttributes[RESULT]; }
- virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
- virtual nsIntRect ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance);
- virtual void ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
- nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance);
- virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
- const nsSVGFilterInstance& aInstance);
-
- NS_FORWARD_NSIDOMSVGELEMENT(SVGFEDisplacementMapElementBase::)
-
- NS_FORWARD_NSIDOMNODE_TO_NSINODE
- NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
-
- virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
- virtual nsIDOMNode* AsDOMNode() { return this; }
-
- // WebIDL
- already_AddRefed<nsIDOMSVGAnimatedString> In1();
- already_AddRefed<nsIDOMSVGAnimatedString> In2();
- already_AddRefed<nsIDOMSVGAnimatedNumber> Scale();
- already_AddRefed<nsIDOMSVGAnimatedEnumeration> XChannelSelector();
- already_AddRefed<nsIDOMSVGAnimatedEnumeration> YChannelSelector();
-
-protected:
- virtual bool OperatesOnSRGB(nsSVGFilterInstance* aInstance,
- int32_t aInput, Image* aImage) {
- switch (aInput) {
- case 0:
- return aImage->mColorModel.mColorSpace == ColorModel::SRGB;
- case 1:
- return SVGFEDisplacementMapElementBase::OperatesOnSRGB(aInstance,
- aInput, aImage);
- default:
- NS_ERROR("Will not give correct output color model");
- return false;
- }
- }
- virtual bool OperatesOnPremultipledAlpha(int32_t aInput) {
- return !(aInput == 1);
- }
-
- virtual NumberAttributesInfo GetNumberInfo();
- virtual EnumAttributesInfo GetEnumInfo();
- virtual StringAttributesInfo GetStringInfo();
-
- enum { SCALE };
- nsSVGNumber2 mNumberAttributes[1];
- static NumberInfo sNumberInfo[1];
-
- enum { CHANNEL_X, CHANNEL_Y };
- nsSVGEnum mEnumAttributes[2];
- static nsSVGEnumMapping sChannelMap[];
- static EnumInfo sEnumInfo[2];
-
- enum { RESULT, IN1, IN2 };
- nsSVGString mStringAttributes[3];
- static StringInfo sStringInfo[3];
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_SVGFEDisplacementMapElement_h
View
260 content/svg/content/src/SVGFEMorphologyElement.cpp
@@ -1,260 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/dom/SVGFEMorphologyElement.h"
-#include "mozilla/dom/SVGFEMorphologyElementBinding.h"
-#include "nsSVGFilterInstance.h"
-
-NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEMorphology)
-
-namespace mozilla {
-namespace dom {
-
-JSObject*
-SVGFEMorphologyElement::WrapNode(JSContext* aCx, JSObject* aScope)
-{
- return SVGFEMorphologyElementBinding::Wrap(aCx, aScope, this);
-}
-
-// Morphology Operators
-static const unsigned short SVG_OPERATOR_UNKNOWN = 0;
-static const unsigned short SVG_OPERATOR_ERODE = 1;
-static const unsigned short SVG_OPERATOR_DILATE = 2;
-
-nsSVGElement::NumberPairInfo SVGFEMorphologyElement::sNumberPairInfo[1] =
-{
- { &nsGkAtoms::radius, 0, 0 }
-};
-
-nsSVGEnumMapping SVGFEMorphologyElement::sOperatorMap[] = {
- {&nsGkAtoms::erode, SVG_OPERATOR_ERODE},
- {&nsGkAtoms::dilate, SVG_OPERATOR_DILATE},
- {nullptr, 0}
-};
-
-nsSVGElement::EnumInfo SVGFEMorphologyElement::sEnumInfo[1] =
-{
- { &nsGkAtoms::_operator,
- sOperatorMap,
- SVG_OPERATOR_ERODE
- }
-};
-
-nsSVGElement::StringInfo SVGFEMorphologyElement::sStringInfo[2] =
-{
- { &nsGkAtoms::result, kNameSpaceID_None, true },
- { &nsGkAtoms::in, kNameSpaceID_None, true }
-};
-
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_IMPL_ADDREF_INHERITED(SVGFEMorphologyElement,SVGFEMorphologyElementBase)
-NS_IMPL_RELEASE_INHERITED(SVGFEMorphologyElement,SVGFEMorphologyElementBase)
-
-NS_INTERFACE_TABLE_HEAD(SVGFEMorphologyElement)
- NS_NODE_INTERFACE_TABLE3(SVGFEMorphologyElement, nsIDOMNode, nsIDOMElement,
- nsIDOMSVGElement)
-NS_INTERFACE_MAP_END_INHERITING(SVGFEMorphologyElementBase)
-
-//----------------------------------------------------------------------
-// nsIDOMNode methods
-
-
-NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEMorphologyElement)
-
-
-//----------------------------------------------------------------------
-// SVGFEMorphologyElement methods
-
-already_AddRefed<nsIDOMSVGAnimatedString>
-SVGFEMorphologyElement::In1()
-{
- return mStringAttributes[IN1].ToDOMAnimatedString(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedEnumeration>
-SVGFEMorphologyElement::Operator()
-{
- return mEnumAttributes[OPERATOR].ToDOMAnimatedEnum(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEMorphologyElement::RadiusX()
-{
- return mNumberPairAttributes[RADIUS].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFEMorphologyElement::RadiusY()
-{
- return mNumberPairAttributes[RADIUS].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
-}
-
-void
-SVGFEMorphologyElement::SetRadius(float rx, float ry)
-{
- mNumberPairAttributes[RADIUS].SetBaseValues(rx, ry, this);
-}
-
-void
-SVGFEMorphologyElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
-{
- aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
-}
-
-nsIntRect
-SVGFEMorphologyElement::InflateRect(const nsIntRect& aRect,
- const nsSVGFilterInstance& aInstance)
-{
- int32_t rx, ry;
- GetRXY(&rx, &ry, aInstance);
- nsIntRect result = aRect;
- result.Inflate(std::max(0, rx), std::max(0, ry));
- return result;
-}
-
-nsIntRect
-SVGFEMorphologyElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance)
-{
- return InflateRect(aSourceBBoxes[0], aInstance);
-}
-
-void
-SVGFEMorphologyElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
- nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance)
-{
- aSourceBBoxes[0] = InflateRect(aTargetBBox, aInstance);
-}
-
-nsIntRect
-SVGFEMorphologyElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
- const nsSVGFilterInstance& aInstance)
-{
- return InflateRect(aSourceChangeBoxes[0], aInstance);
-}
-
-#define MORPHOLOGY_EPSILON 0.0001
-
-void
-SVGFEMorphologyElement::GetRXY(int32_t *aRX, int32_t *aRY,
- const nsSVGFilterInstance& aInstance)
-{
- // Subtract an epsilon here because we don't want a value that's just
- // slightly larger than an integer to round up to the next integer; it's
- // probably meant to be the integer it's close to, modulo machine precision
- // issues.
- *aRX = NSToIntCeil(aInstance.GetPrimitiveNumber(SVGContentUtils::X,
- &mNumberPairAttributes[RADIUS],
- nsSVGNumberPair::eFirst) -
- MORPHOLOGY_EPSILON);
- *aRY = NSToIntCeil(aInstance.GetPrimitiveNumber(SVGContentUtils::Y,
- &mNumberPairAttributes[RADIUS],
- nsSVGNumberPair::eSecond) -
- MORPHOLOGY_EPSILON);
-}
-
-nsresult
-SVGFEMorphologyElement::Filter(nsSVGFilterInstance* instance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& rect)
-{
- int32_t rx, ry;
- GetRXY(&rx, &ry, *instance);
-
- if (rx < 0 || ry < 0) {
- // XXX SVGContentUtils::ReportToConsole()
- return NS_OK;
- }
- if (rx == 0 && ry == 0) {
- return NS_OK;
- }
-
- // Clamp radii to prevent completely insane values:
- rx = std::min(rx, 100000);
- ry = std::min(ry, 100000);
-
- uint8_t* sourceData = aSources[0]->mImage->Data();
- uint8_t* targetData = aTarget->mImage->Data();
- int32_t stride = aTarget->mImage->Stride();
- uint8_t extrema[4]; // RGBA magnitude of extrema
- uint16_t op = mEnumAttributes[OPERATOR].GetAnimValue();
-
- // Scan the kernel for each pixel to determine max/min RGBA values.
- for (int32_t y = rect.y; y < rect.YMost(); y++) {
- int32_t startY = std::max(0, y - ry);
- // We need to read pixels not just in 'rect', which is limited to
- // the dirty part of our filter primitive subregion, but all pixels in
- // the given radii from the source surface, so use the surface size here.
- int32_t endY = std::min(y + ry, instance->GetSurfaceHeight() - 1);
- for (int32_t x = rect.x; x < rect.XMost(); x++) {
- int32_t startX = std::max(0, x - rx);
- int32_t endX = std::min(x + rx, instance->GetSurfaceWidth() - 1);
- int32_t targIndex = y * stride + 4 * x;
-
- for (int32_t i = 0; i < 4; i++) {
- extrema[i] = sourceData[targIndex + i];
- }
- for (int32_t y1 = startY; y1 <= endY; y1++) {
- for (int32_t x1 = startX; x1 <= endX; x1++) {
- for (int32_t i = 0; i < 4; i++) {
- uint8_t pixel = sourceData[y1 * stride + 4 * x1 + i];
- if ((extrema[i] > pixel &&
- op == SVG_OPERATOR_ERODE) ||
- (extrema[i] < pixel &&
- op == SVG_OPERATOR_DILATE)) {
- extrema[i] = pixel;
- }
- }
- }
- }
- targetData[targIndex ] = extrema[0];
- targetData[targIndex+1] = extrema[1];
- targetData[targIndex+2] = extrema[2];
- targetData[targIndex+3] = extrema[3];
- }
- }
- return NS_OK;
-}
-
-bool
-SVGFEMorphologyElement::AttributeAffectsRendering(int32_t aNameSpaceID,
- nsIAtom* aAttribute) const
-{
- return SVGFEMorphologyElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
- (aNameSpaceID == kNameSpaceID_None &&
- (aAttribute == nsGkAtoms::in ||
- aAttribute == nsGkAtoms::radius ||
- aAttribute == nsGkAtoms::_operator));
-}
-
-//----------------------------------------------------------------------
-// nsSVGElement methods
-
-nsSVGElement::NumberPairAttributesInfo
-SVGFEMorphologyElement::GetNumberPairInfo()
-{
- return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
- ArrayLength(sNumberPairInfo));
-}
-
-nsSVGElement::EnumAttributesInfo
-SVGFEMorphologyElement::GetEnumInfo()
-{
- return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
- ArrayLength(sEnumInfo));
-}
-
-nsSVGElement::StringAttributesInfo
-SVGFEMorphologyElement::GetStringInfo()
-{
- return StringAttributesInfo(mStringAttributes, sStringInfo,
- ArrayLength(sStringInfo));
-}
-
-} // namespace dom
-} // namespace mozilla
View
95 content/svg/content/src/SVGFEMorphologyElement.h
@@ -1,95 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_SVGFEMorphologyElement_h
-#define mozilla_dom_SVGFEMorphologyElement_h
-
-#include "nsSVGEnum.h"
-#include "nsSVGFilters.h"
-#include "nsSVGNumberPair.h"
-#include "nsSVGString.h"
-
-nsresult NS_NewSVGFEMorphologyElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo);
-
-namespace mozilla {
-namespace dom {
-
-typedef nsSVGFE SVGFEMorphologyElementBase;
-
-class SVGFEMorphologyElement : public SVGFEMorphologyElementBase,
- public nsIDOMSVGElement
-{
- friend nsresult (::NS_NewSVGFEMorphologyElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo));
-protected:
- SVGFEMorphologyElement(already_AddRefed<nsINodeInfo> aNodeInfo)
- : SVGFEMorphologyElementBase(aNodeInfo)
- {
- SetIsDOMBinding();
- }
- virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
-
-public:
- // interfaces:
- NS_DECL_ISUPPORTS_INHERITED
-
- virtual nsresult Filter(nsSVGFilterInstance* aInstance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& aDataRect);
- virtual bool AttributeAffectsRendering(
- int32_t aNameSpaceID, nsIAtom* aAttribute) const;
- virtual nsSVGString& GetResultImageName() { return mStringAttributes[RESULT]; }
- virtual void GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources);
- virtual nsIntRect ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance);
- virtual void ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
- nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance);
- virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
- const nsSVGFilterInstance& aInstance);
-
- NS_FORWARD_NSIDOMSVGELEMENT(SVGFEMorphologyElementBase::)
-
- NS_FORWARD_NSIDOMNODE_TO_NSINODE
- NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
-
- virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
- virtual nsIDOMNode* AsDOMNode() { return this; }
-
- // WebIDL
- already_AddRefed<nsIDOMSVGAnimatedString> In1();
- already_AddRefed<nsIDOMSVGAnimatedEnumeration> Operator();
- already_AddRefed<nsIDOMSVGAnimatedNumber> RadiusX();
- already_AddRefed<nsIDOMSVGAnimatedNumber> RadiusY();
- void SetRadius(float rx, float ry);
-
-protected:
- void GetRXY(int32_t *aRX, int32_t *aRY, const nsSVGFilterInstance& aInstance);
- nsIntRect InflateRect(const nsIntRect& aRect, const nsSVGFilterInstance& aInstance);
-
- virtual NumberPairAttributesInfo GetNumberPairInfo();
- virtual EnumAttributesInfo GetEnumInfo();
- virtual StringAttributesInfo GetStringInfo();
-
- enum { RADIUS };
- nsSVGNumberPair mNumberPairAttributes[1];
- static NumberPairInfo sNumberPairInfo[1];
-
- enum { OPERATOR };
- nsSVGEnum mEnumAttributes[1];
- static nsSVGEnumMapping sOperatorMap[];
- static EnumInfo sEnumInfo[1];
-
- enum { RESULT, IN1 };
- nsSVGString mStringAttributes[2];
- static StringInfo sStringInfo[2];
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_SVGFEMorphologyElement_h
View
137 content/svg/content/src/SVGFESpecularLightingElement.cpp
@@ -1,137 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/dom/SVGFESpecularLightingElement.h"
-#include "mozilla/dom/SVGFESpecularLightingElementBinding.h"
-#include "nsSVGUtils.h"
-
-NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FESpecularLighting)
-
-namespace mozilla {
-namespace dom {
-
-JSObject*
-SVGFESpecularLightingElement::WrapNode(JSContext* aCx, JSObject* aScope)
-{
- return SVGFESpecularLightingElementBinding::Wrap(aCx, aScope, this);
-}
-
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_IMPL_ADDREF_INHERITED(SVGFESpecularLightingElement,SVGFESpecularLightingElementBase)
-NS_IMPL_RELEASE_INHERITED(SVGFESpecularLightingElement,SVGFESpecularLightingElementBase)
-
-NS_INTERFACE_TABLE_HEAD(SVGFESpecularLightingElement)
- NS_NODE_INTERFACE_TABLE3(SVGFESpecularLightingElement, nsIDOMNode,
- nsIDOMElement, nsIDOMSVGElement)
-NS_INTERFACE_MAP_END_INHERITING(SVGFESpecularLightingElementBase)
-
-//----------------------------------------------------------------------
-// nsIDOMNode methods
-
-NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFESpecularLightingElement)
-
-already_AddRefed<nsIDOMSVGAnimatedString>
-SVGFESpecularLightingElement::In1()
-{
- return mStringAttributes[IN1].ToDOMAnimatedString(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpecularLightingElement::SurfaceScale()
-{
- return mNumberAttributes[SURFACE_SCALE].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpecularLightingElement::SpecularConstant()
-{
- return mNumberAttributes[SPECULAR_CONSTANT].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpecularLightingElement::SpecularExponent()
-{
- return mNumberAttributes[SPECULAR_EXPONENT].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpecularLightingElement::KernelUnitLengthX()
-{
- return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
- nsSVGNumberPair::eFirst, this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpecularLightingElement::KernelUnitLengthY()
-{
- return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
- nsSVGNumberPair::eSecond, this);
-}
-
-//----------------------------------------------------------------------
-// nsSVGElement methods
-
-nsresult
-SVGFESpecularLightingElement::Filter(nsSVGFilterInstance* instance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& rect)
-{
- float specularExponent = mNumberAttributes[SPECULAR_EXPONENT].GetAnimValue();
-
- // specification defined range (15.22)
- if (specularExponent < 1 || specularExponent > 128)
- return NS_ERROR_FAILURE;
-
- return SVGFESpecularLightingElementBase::Filter(instance, aSources, aTarget, rect);
-}
-
-bool
-SVGFESpecularLightingElement::AttributeAffectsRendering(int32_t aNameSpaceID,
- nsIAtom* aAttribute) const
-{
- return SVGFESpecularLightingElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
- (aNameSpaceID == kNameSpaceID_None &&
- (aAttribute == nsGkAtoms::specularConstant ||
- aAttribute == nsGkAtoms::specularExponent));
-}
-
-void
-SVGFESpecularLightingElement::LightPixel(const float *N, const float *L,
- nscolor color, uint8_t *targetData)
-{
- float H[3];
- H[0] = L[0];
- H[1] = L[1];
- H[2] = L[2] + 1;
- NORMALIZE(H);
-
- float kS = mNumberAttributes[SPECULAR_CONSTANT].GetAnimValue();
- float dotNH = DOT(N, H);
-
- bool invalid = dotNH <= 0 || kS <= 0;
- kS *= invalid ? 0 : 1;
- uint8_t minAlpha = invalid ? 255 : 0;
-
- float specularNH =
- kS * pow(dotNH, mNumberAttributes[SPECULAR_EXPONENT].GetAnimValue());
-
- targetData[GFX_ARGB32_OFFSET_B] =
- std::min(uint32_t(specularNH * NS_GET_B(color)), 255U);
- targetData[GFX_ARGB32_OFFSET_G] =
- std::min(uint32_t(specularNH * NS_GET_G(color)), 255U);
- targetData[GFX_ARGB32_OFFSET_R] =
- std::min(uint32_t(specularNH * NS_GET_R(color)), 255U);
-
- targetData[GFX_ARGB32_OFFSET_A] =
- std::max(minAlpha, std::max(targetData[GFX_ARGB32_OFFSET_B],
- std::max(targetData[GFX_ARGB32_OFFSET_G],
- targetData[GFX_ARGB32_OFFSET_R])));
-}
-
-} // namespace dom
-} // namespace mozilla
View
70 content/svg/content/src/SVGFESpecularLightingElement.h
@@ -1,70 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_SVGFESpecularLightingElement_h
-#define mozilla_dom_SVGFESpecularLightingElement_h
-
-#include "nsSVGFilters.h"
-
-nsresult NS_NewSVGFESpecularLightingElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo);
-
-namespace mozilla {
-namespace dom {
-
-//---------------------SpecularLighting------------------------
-
-typedef nsSVGFELightingElement SVGFESpecularLightingElementBase;
-
-class SVGFESpecularLightingElement : public SVGFESpecularLightingElementBase,
- public nsIDOMSVGElement
-{
- friend nsresult (::NS_NewSVGFESpecularLightingElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo));
-protected:
- SVGFESpecularLightingElement(already_AddRefed<nsINodeInfo> aNodeInfo)
- : SVGFESpecularLightingElementBase(aNodeInfo)
- {
- SetIsDOMBinding();
- }
- virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
-
-public:
- // interfaces:
- NS_DECL_ISUPPORTS_INHERITED
-
- NS_FORWARD_NSIDOMSVGELEMENT(SVGFESpecularLightingElementBase::)
- NS_FORWARD_NSIDOMNODE_TO_NSINODE
- NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
-
- virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
- virtual nsresult Filter(nsSVGFilterInstance* aInstance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& aDataRect);
- virtual bool AttributeAffectsRendering(
- int32_t aNameSpaceID, nsIAtom* aAttribute) const;
-
- virtual nsIDOMNode* AsDOMNode() { return this; }
-
- // WebIDL
- already_AddRefed<nsIDOMSVGAnimatedString> In1();
- already_AddRefed<nsIDOMSVGAnimatedNumber> SurfaceScale();
- already_AddRefed<nsIDOMSVGAnimatedNumber> SpecularConstant();
- already_AddRefed<nsIDOMSVGAnimatedNumber> SpecularExponent();
- already_AddRefed<nsIDOMSVGAnimatedNumber> KernelUnitLengthX();
- already_AddRefed<nsIDOMSVGAnimatedNumber> KernelUnitLengthY();
-
-protected:
- virtual void LightPixel(const float *N, const float *L,
- nscolor color, uint8_t *targetData);
-
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_SVGFESpecularLightingElement_h
View
127 content/svg/content/src/SVGFESpotLightElement.cpp
@@ -1,127 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/dom/SVGFESpotLightElement.h"
-#include "mozilla/dom/SVGFESpotLightElementBinding.h"
-
-NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FESpotLight)
-
-namespace mozilla {
-namespace dom {
-
-JSObject*
-SVGFESpotLightElement::WrapNode(JSContext* aCx, JSObject* aScope)
-{
- return SVGFESpotLightElementBinding::Wrap(aCx, aScope, this);
-}
-
-nsSVGElement::NumberInfo SVGFESpotLightElement::sNumberInfo[8] =
-{
- { &nsGkAtoms::x, 0, false },
- { &nsGkAtoms::y, 0, false },
- { &nsGkAtoms::z, 0, false },
- { &nsGkAtoms::pointsAtX, 0, false },
- { &nsGkAtoms::pointsAtY, 0, false },
- { &nsGkAtoms::pointsAtZ, 0, false },
- { &nsGkAtoms::specularExponent, 1, false },
- { &nsGkAtoms::limitingConeAngle, 0, false }
-};
-
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_IMPL_ADDREF_INHERITED(SVGFESpotLightElement,SVGFESpotLightElementBase)
-NS_IMPL_RELEASE_INHERITED(SVGFESpotLightElement,SVGFESpotLightElementBase)
-
-NS_INTERFACE_TABLE_HEAD(SVGFESpotLightElement)
- NS_NODE_INTERFACE_TABLE3(SVGFESpotLightElement, nsIDOMNode,
- nsIDOMElement, nsIDOMSVGElement)
-NS_INTERFACE_MAP_END_INHERITING(SVGFESpotLightElementBase)
-
-//----------------------------------------------------------------------
-// nsIDOMNode methods
-
-NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFESpotLightElement)
-
-//----------------------------------------------------------------------
-// nsFEUnstyledElement methods
-
-bool
-SVGFESpotLightElement::AttributeAffectsRendering(int32_t aNameSpaceID,
- nsIAtom* aAttribute) const
-{
- return aNameSpaceID == kNameSpaceID_None &&
- (aAttribute == nsGkAtoms::x ||
- aAttribute == nsGkAtoms::y ||
- aAttribute == nsGkAtoms::z ||
- aAttribute == nsGkAtoms::pointsAtX ||
- aAttribute == nsGkAtoms::pointsAtY ||
- aAttribute == nsGkAtoms::pointsAtZ ||
- aAttribute == nsGkAtoms::specularExponent ||
- aAttribute == nsGkAtoms::limitingConeAngle);
-}
-
-//----------------------------------------------------------------------
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::X()
-{
- return mNumberAttributes[ATTR_X].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::Y()
-{
- return mNumberAttributes[ATTR_Y].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::Z()
-{
- return mNumberAttributes[ATTR_Z].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::PointsAtX()
-{
- return mNumberAttributes[POINTS_AT_X].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::PointsAtY()
-{
- return mNumberAttributes[POINTS_AT_Y].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::PointsAtZ()
-{
- return mNumberAttributes[POINTS_AT_Z].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::SpecularExponent()
-{
- return mNumberAttributes[SPECULAR_EXPONENT].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFESpotLightElement::LimitingConeAngle()
-{
- return mNumberAttributes[LIMITING_CONE_ANGLE].ToDOMAnimatedNumber(this);
-}
-
-//----------------------------------------------------------------------
-// nsSVGElement methods
-
-nsSVGElement::NumberAttributesInfo
-SVGFESpotLightElement::GetNumberInfo()
-{
- return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
- ArrayLength(sNumberInfo));
-}
-
-} // namespace dom
-} // namespace mozilla
View
73 content/svg/content/src/SVGFESpotLightElement.h
@@ -1,73 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_SVGFESpotLightElement_h
-#define mozilla_dom_SVGFESpotLightElement_h
-
-#include "nsSVGFilters.h"
-#include "nsSVGNumber2.h"
-
-class nsSVGFELightingElement;
-
-nsresult NS_NewSVGFESpotLightElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo);
-
-namespace mozilla {
-namespace dom {
-
-typedef SVGFEUnstyledElement SVGFESpotLightElementBase;
-
-class SVGFESpotLightElement : public SVGFESpotLightElementBase,
- public nsIDOMSVGElement
-{
- friend nsresult (::NS_NewSVGFESpotLightElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo));
- friend class ::nsSVGFELightingElement;
-protected:
- SVGFESpotLightElement(already_AddRefed<nsINodeInfo> aNodeInfo)
- : SVGFESpotLightElementBase(aNodeInfo)
- {
- SetIsDOMBinding();
- }
- virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
-
-public:
- // interfaces:
- NS_DECL_ISUPPORTS_INHERITED
-
- NS_FORWARD_NSIDOMSVGELEMENT(SVGFESpotLightElementBase::)
- NS_FORWARD_NSIDOMNODE_TO_NSINODE
- NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
-
- virtual bool AttributeAffectsRendering(
- int32_t aNameSpaceID, nsIAtom* aAttribute) const;
-
- virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
- virtual nsIDOMNode* AsDOMNode() { return this; }
-
- // WebIDL
- already_AddRefed<nsIDOMSVGAnimatedNumber> X();
- already_AddRefed<nsIDOMSVGAnimatedNumber> Y();
- already_AddRefed<nsIDOMSVGAnimatedNumber> Z();
- already_AddRefed<nsIDOMSVGAnimatedNumber> PointsAtX();
- already_AddRefed<nsIDOMSVGAnimatedNumber> PointsAtY();
- already_AddRefed<nsIDOMSVGAnimatedNumber> PointsAtZ();
- already_AddRefed<nsIDOMSVGAnimatedNumber> SpecularExponent();
- already_AddRefed<nsIDOMSVGAnimatedNumber> LimitingConeAngle();
-
-protected:
- virtual NumberAttributesInfo GetNumberInfo();
-
- enum { ATTR_X, ATTR_Y, ATTR_Z, POINTS_AT_X, POINTS_AT_Y, POINTS_AT_Z,
- SPECULAR_EXPONENT, LIMITING_CONE_ANGLE };
- nsSVGNumber2 mNumberAttributes[8];
- static NumberInfo sNumberInfo[8];
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_SVGFESpotLightElement_h
View
435 content/svg/content/src/SVGFETurbulenceElement.cpp
@@ -1,435 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/dom/SVGFETurbulenceElement.h"
-#include "mozilla/dom/SVGFETurbulenceElementBinding.h"
-#include "nsSVGFilterInstance.h"
-#include "nsSVGUtils.h"
-
-NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FETurbulence)
-
-namespace mozilla {
-namespace dom {
-
-// Turbulence Types
-static const unsigned short SVG_TURBULENCE_TYPE_UNKNOWN = 0;
-static const unsigned short SVG_TURBULENCE_TYPE_FRACTALNOISE = 1;
-static const unsigned short SVG_TURBULENCE_TYPE_TURBULENCE = 2;
-
-// Stitch Options
-static const unsigned short SVG_STITCHTYPE_UNKNOWN = 0;
-static const unsigned short SVG_STITCHTYPE_STITCH = 1;
-static const unsigned short SVG_STITCHTYPE_NOSTITCH = 2;
-
-JSObject*
-SVGFETurbulenceElement::WrapNode(JSContext* aCx, JSObject* aScope)
-{
- return SVGFETurbulenceElementBinding::Wrap(aCx, aScope, this);
-}
-
-nsSVGElement::NumberInfo SVGFETurbulenceElement::sNumberInfo[1] =
-{
- { &nsGkAtoms::seed, 0, false }
-};
-
-nsSVGElement::NumberPairInfo SVGFETurbulenceElement::sNumberPairInfo[1] =
-{
- { &nsGkAtoms::baseFrequency, 0, 0 }
-};
-
-nsSVGElement::IntegerInfo SVGFETurbulenceElement::sIntegerInfo[1] =
-{
- { &nsGkAtoms::numOctaves, 1 }
-};
-
-nsSVGEnumMapping SVGFETurbulenceElement::sTypeMap[] = {
- {&nsGkAtoms::fractalNoise,
- SVG_TURBULENCE_TYPE_FRACTALNOISE},
- {&nsGkAtoms::turbulence,
- SVG_TURBULENCE_TYPE_TURBULENCE},
- {nullptr, 0}
-};
-
-nsSVGEnumMapping SVGFETurbulenceElement::sStitchTilesMap[] = {
- {&nsGkAtoms::stitch,
- SVG_STITCHTYPE_STITCH},
- {&nsGkAtoms::noStitch,
- SVG_STITCHTYPE_NOSTITCH},
- {nullptr, 0}
-};
-
-nsSVGElement::EnumInfo SVGFETurbulenceElement::sEnumInfo[2] =
-{
- { &nsGkAtoms::type,
- sTypeMap,
- SVG_TURBULENCE_TYPE_TURBULENCE
- },
- { &nsGkAtoms::stitchTiles,
- sStitchTilesMap,
- SVG_STITCHTYPE_NOSTITCH
- }
-};
-
-nsSVGElement::StringInfo SVGFETurbulenceElement::sStringInfo[1] =
-{
- { &nsGkAtoms::result, kNameSpaceID_None, true }
-};
-
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_IMPL_ADDREF_INHERITED(SVGFETurbulenceElement,SVGFETurbulenceElementBase)
-NS_IMPL_RELEASE_INHERITED(SVGFETurbulenceElement,SVGFETurbulenceElementBase)
-
-NS_INTERFACE_TABLE_HEAD(SVGFETurbulenceElement)
- NS_NODE_INTERFACE_TABLE3(SVGFETurbulenceElement, nsIDOMNode, nsIDOMElement,
- nsIDOMSVGElement)
-NS_INTERFACE_MAP_END_INHERITING(SVGFETurbulenceElementBase)
-
-//----------------------------------------------------------------------
-// nsIDOMNode methods
-
-NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFETurbulenceElement)
-
-//----------------------------------------------------------------------
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFETurbulenceElement::BaseFrequencyX()
-{
- return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFETurbulenceElement::BaseFrequencyY()
-{
- return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedInteger>
-SVGFETurbulenceElement::NumOctaves()
-{
- return mIntegerAttributes[OCTAVES].ToDOMAnimatedInteger(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedNumber>
-SVGFETurbulenceElement::Seed()
-{
- return mNumberAttributes[SEED].ToDOMAnimatedNumber(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedEnumeration>
-SVGFETurbulenceElement::StitchTiles()
-{
- return mEnumAttributes[STITCHTILES].ToDOMAnimatedEnum(this);
-}
-
-already_AddRefed<nsIDOMSVGAnimatedEnumeration>
-SVGFETurbulenceElement::Type()
-{
- return mEnumAttributes[TYPE].ToDOMAnimatedEnum(this);
-}
-
-nsresult
-SVGFETurbulenceElement::Filter(nsSVGFilterInstance* instance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& rect)
-{
- uint8_t* targetData = aTarget->mImage->Data();
- uint32_t stride = aTarget->mImage->Stride();
-
- nsIntRect filterSubregion(int32_t(aTarget->mFilterPrimitiveSubregion.X()),
- int32_t(aTarget->mFilterPrimitiveSubregion.Y()),
- int32_t(aTarget->mFilterPrimitiveSubregion.Width()),
- int32_t(aTarget->mFilterPrimitiveSubregion.Height()));
-
- float fX = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eFirst);
- float fY = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eSecond);
- float seed = mNumberAttributes[OCTAVES].GetAnimValue();
- int32_t octaves = mIntegerAttributes[OCTAVES].GetAnimValue();
- uint16_t type = mEnumAttributes[TYPE].GetAnimValue();
- uint16_t stitch = mEnumAttributes[STITCHTILES].GetAnimValue();
-
- InitSeed((int32_t)seed);
-
- // XXXroc this makes absolutely no sense to me.
- float filterX = instance->GetFilterRegion().X();
- float filterY = instance->GetFilterRegion().Y();
- float filterWidth = instance->GetFilterRegion().Width();
- float filterHeight = instance->GetFilterRegion().Height();
-
- bool doStitch = false;
- if (stitch == SVG_STITCHTYPE_STITCH) {
- doStitch = true;
-
- float lowFreq, hiFreq;
-
- lowFreq = floor(filterWidth * fX) / filterWidth;
- hiFreq = ceil(filterWidth * fX) / filterWidth;
- if (fX / lowFreq < hiFreq / fX)
- fX = lowFreq;
- else
- fX = hiFreq;
-
- lowFreq = floor(filterHeight * fY) / filterHeight;
- hiFreq = ceil(filterHeight * fY) / filterHeight;
- if (fY / lowFreq < hiFreq / fY)
- fY = lowFreq;
- else
- fY = hiFreq;
- }
- for (int32_t y = rect.y; y < rect.YMost(); y++) {
- for (int32_t x = rect.x; x < rect.XMost(); x++) {
- int32_t targIndex = y * stride + x * 4;
- double point[2];
- point[0] = filterX + (filterWidth * (x + instance->GetSurfaceRect().x)) / (filterSubregion.width - 1);
- point[1] = filterY + (filterHeight * (y + instance->GetSurfaceRect().y)) / (filterSubregion.height - 1);
-
- float col[4];
- if (type == SVG_TURBULENCE_TYPE_TURBULENCE) {
- for (int i = 0; i < 4; i++)
- col[i] = Turbulence(i, point, fX, fY, octaves, false,
- doStitch, filterX, filterY, filterWidth, filterHeight) * 255;
- } else {
- for (int i = 0; i < 4; i++)
- col[i] = (Turbulence(i, point, fX, fY, octaves, true,
- doStitch, filterX, filterY, filterWidth, filterHeight) * 255 + 255) / 2;
- }
- for (int i = 0; i < 4; i++) {
- col[i] = std::min(col[i], 255.f);
- col[i] = std::max(col[i], 0.f);
- }
-
- uint8_t r, g, b, a;
- a = uint8_t(col[3]);
- FAST_DIVIDE_BY_255(r, unsigned(col[0]) * a);
- FAST_DIVIDE_BY_255(g, unsigned(col[1]) * a);
- FAST_DIVIDE_BY_255(b, unsigned(col[2]) * a);
-
- targetData[targIndex + GFX_ARGB32_OFFSET_B] = b;
- targetData[targIndex + GFX_ARGB32_OFFSET_G] = g;
- targetData[targIndex + GFX_ARGB32_OFFSET_R] = r;
- targetData[targIndex + GFX_ARGB32_OFFSET_A] = a;
- }
- }
-
- return NS_OK;
-}
-
-bool
-SVGFETurbulenceElement::AttributeAffectsRendering(int32_t aNameSpaceID,
- nsIAtom* aAttribute) const
-{
- return SVGFETurbulenceElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
- (aNameSpaceID == kNameSpaceID_None &&
- (aAttribute == nsGkAtoms::seed ||
- aAttribute == nsGkAtoms::baseFrequency ||
- aAttribute == nsGkAtoms::numOctaves ||
- aAttribute == nsGkAtoms::type ||
- aAttribute == nsGkAtoms::stitchTiles));
-}
-
-void
-SVGFETurbulenceElement::InitSeed(int32_t aSeed)
-{
- double s;
- int i, j, k;
- aSeed = SetupSeed(aSeed);
- for (k = 0; k < 4; k++) {
- for (i = 0; i < sBSize; i++) {
- mLatticeSelector[i] = i;
- for (j = 0; j < 2; j++) {
- mGradient[k][i][j] =
- (double) (((aSeed =
- Random(aSeed)) % (sBSize + sBSize)) - sBSize) / sBSize;
- }
- s = double (sqrt
- (mGradient[k][i][0] * mGradient[k][i][0] +
- mGradient[k][i][1] * mGradient[k][i][1]));
- mGradient[k][i][0] /= s;
- mGradient[k][i][1] /= s;
- }
- }
- while (--i) {
- k = mLatticeSelector[i];
- mLatticeSelector[i] = mLatticeSelector[j =
- (aSeed =
- Random(aSeed)) % sBSize];
- mLatticeSelector[j] = k;
- }
- for (i = 0; i < sBSize + 2; i++) {
- mLatticeSelector[sBSize + i] = mLatticeSelector[i];
- for (k = 0; k < 4; k++)
- for (j = 0; j < 2; j++)
- mGradient[k][sBSize + i][j] = mGradient[k][i][j];
- }
-}
-
-#define S_CURVE(t) ( t * t * (3. - 2. * t) )
-#define LERP(t, a, b) ( a + t * (b - a) )
-double
-SVGFETurbulenceElement::Noise2(int aColorChannel, double aVec[2],
- StitchInfo *aStitchInfo)
-{
- int bx0, bx1, by0, by1, b00, b10, b01, b11;
- double rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
- register long i, j;
- t = aVec[0] + sPerlinN;
- bx0 = (int) t;
- bx1 = bx0 + 1;
- rx0 = t - (int) t;
- rx1 = rx0 - 1.0f;
- t = aVec[1] + sPerlinN;
- by0 = (int) t;
- by1 = by0 + 1;
- ry0 = t - (int) t;
- ry1 = ry0 - 1.0f;
- // If stitching, adjust lattice points accordingly.
- if (aStitchInfo != NULL) {
- if (bx0 >= aStitchInfo->mWrapX)
- bx0 -= aStitchInfo->mWidth;
- if (bx1 >= aStitchInfo->mWrapX)
- bx1 -= aStitchInfo->mWidth;
- if (by0 >= aStitchInfo->mWrapY)
- by0 -= aStitchInfo->mHeight;
- if (by1 >= aStitchInfo->mWrapY)
- by1 -= aStitchInfo->mHeight;
- }
- bx0 &= sBM;
- bx1 &= sBM;
- by0 &= sBM;
- by1 &= sBM;
- i = mLatticeSelector[bx0];
- j = mLatticeSelector[bx1];
- b00 = mLatticeSelector[i + by0];
- b10 = mLatticeSelector[j + by0];
- b01 = mLatticeSelector[i + by1];
- b11 = mLatticeSelector[j + by1];
- sx = double (S_CURVE(rx0));
- sy = double (S_CURVE(ry0));
- q = mGradient[aColorChannel][b00];
- u = rx0 * q[0] + ry0 * q[1];
- q = mGradient[aColorChannel][b10];
- v = rx1 * q[0] + ry0 * q[1];
- a = LERP(sx, u, v);
- q = mGradient[aColorChannel][b01];
- u = rx0 * q[0] + ry1 * q[1];
- q = mGradient[aColorChannel][b11];
- v = rx1 * q[0] + ry1 * q[1];
- b = LERP(sx, u, v);
- return LERP(sy, a, b);
-}
-#undef S_CURVE
-#undef LERP
-
-double
-SVGFETurbulenceElement::Turbulence(int aColorChannel, double* aPoint,
- double aBaseFreqX, double aBaseFreqY,
- int aNumOctaves, bool aFractalSum,
- bool aDoStitching,
- double aTileX, double aTileY,
- double aTileWidth, double aTileHeight)
-{
- StitchInfo stitch;
- StitchInfo *stitchInfo = NULL; // Not stitching when NULL.
- // Adjust the base frequencies if necessary for stitching.
- if (aDoStitching) {
- // When stitching tiled turbulence, the frequencies must be adjusted
- // so that the tile borders will be continuous.
- if (aBaseFreqX != 0.0) {
- double loFreq = double (floor(aTileWidth * aBaseFreqX)) / aTileWidth;
- double hiFreq = double (ceil(aTileWidth * aBaseFreqX)) / aTileWidth;
- if (aBaseFreqX / loFreq < hiFreq / aBaseFreqX)
- aBaseFreqX = loFreq;
- else
- aBaseFreqX = hiFreq;
- }
- if (aBaseFreqY != 0.0) {
- double loFreq = double (floor(aTileHeight * aBaseFreqY)) / aTileHeight;
- double hiFreq = double (ceil(aTileHeight * aBaseFreqY)) / aTileHeight;
- if (aBaseFreqY / loFreq < hiFreq / aBaseFreqY)
- aBaseFreqY = loFreq;
- else
- aBaseFreqY = hiFreq;
- }
- // Set up initial stitch values.
- stitchInfo = &stitch;
- stitch.mWidth = int (aTileWidth * aBaseFreqX + 0.5f);
- stitch.mWrapX = int (aTileX * aBaseFreqX + sPerlinN + stitch.mWidth);
- stitch.mHeight = int (aTileHeight * aBaseFreqY + 0.5f);
- stitch.mWrapY = int (aTileY * aBaseFreqY + sPerlinN + stitch.mHeight);
- }
- double sum = 0.0f;
- double vec[2];
- vec[0] = aPoint[0] * aBaseFreqX;
- vec[1] = aPoint[1] * aBaseFreqY;
- double ratio = 1;
- for (int octave = 0; octave < aNumOctaves; octave++) {
- if (aFractalSum)
- sum += double (Noise2(aColorChannel, vec, stitchInfo) / ratio);
- else
- sum += double (fabs(Noise2(aColorChannel, vec, stitchInfo)) / ratio);
- vec[0] *= 2;
- vec[1] *= 2;
- ratio *= 2;
- if (stitchInfo != NULL) {
- // Update stitch values. Subtracting sPerlinN before the multiplication
- // and adding it afterward simplifies to subtracting it once.
- stitch.mWidth *= 2;
- stitch.mWrapX = 2 * stitch.mWrapX - sPerlinN;
- stitch.mHeight *= 2;
- stitch.mWrapY = 2 * stitch.mWrapY - sPerlinN;
- }
- }
- return sum;
-}
-
-nsIntRect
-SVGFETurbulenceElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance)
-{
- return GetMaxRect();
-}
-
-//----------------------------------------------------------------------
-// nsSVGElement methods
-
-nsSVGElement::NumberAttributesInfo
-SVGFETurbulenceElement::GetNumberInfo()
-{
- return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
- ArrayLength(sNumberInfo));
-}
-
-nsSVGElement::NumberPairAttributesInfo
-SVGFETurbulenceElement::GetNumberPairInfo()
-{
- return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
- ArrayLength(sNumberPairInfo));
-}
-
-nsSVGElement::IntegerAttributesInfo
-SVGFETurbulenceElement::GetIntegerInfo()
-{
- return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
- ArrayLength(sIntegerInfo));
-}
-
-nsSVGElement::EnumAttributesInfo
-SVGFETurbulenceElement::GetEnumInfo()
-{
- return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
- ArrayLength(sEnumInfo));
-}
-
-nsSVGElement::StringAttributesInfo
-SVGFETurbulenceElement::GetStringInfo()
-{
- return StringAttributesInfo(mStringAttributes, sStringInfo,
- ArrayLength(sStringInfo));
-}
-
-} // namespace dom
-} // namespace mozilla
View
163 content/svg/content/src/SVGFETurbulenceElement.h
@@ -1,163 +0,0 @@
-/* a*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_dom_SVGFETurbulenceElement_h
-#define mozilla_dom_SVGFETurbulenceElement_h
-
-#include "nsSVGEnum.h"
-#include "nsSVGFilters.h"
-#include "nsSVGNumber2.h"
-#include "nsSVGInteger.h"
-#include "nsSVGString.h"
-
-nsresult NS_NewSVGFETurbulenceElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo);
-
-namespace mozilla {
-namespace dom {
-
-typedef nsSVGFE SVGFETurbulenceElementBase;
-
-class SVGFETurbulenceElement : public SVGFETurbulenceElementBase,
- public nsIDOMSVGElement
-{
- friend nsresult (::NS_NewSVGFETurbulenceElement(nsIContent **aResult,
- already_AddRefed<nsINodeInfo> aNodeInfo));
-protected:
- SVGFETurbulenceElement(already_AddRefed<nsINodeInfo> aNodeInfo)
- : SVGFETurbulenceElementBase(aNodeInfo)
- {
- SetIsDOMBinding();
- }
- virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
-
-public:
- virtual bool SubregionIsUnionOfRegions() { return false; }
-
- // interfaces:
- NS_DECL_ISUPPORTS_INHERITED
-
- virtual nsresult Filter(nsSVGFilterInstance* aInstance,
- const nsTArray<const Image*>& aSources,
- const Image* aTarget,
- const nsIntRect& aDataRect);
- virtual bool AttributeAffectsRendering(
- int32_t aNameSpaceID, nsIAtom* aAttribute) const;
- virtual nsSVGString& GetResultImageName() { return mStringAttributes[RESULT]; }
- virtual nsIntRect ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
- const nsSVGFilterInstance& aInstance);
-
- NS_FORWARD_NSIDOMSVGELEMENT(SVGFETurbulenceElementBase::)
-
- NS_FORWARD_NSIDOMNODE_TO_NSINODE
- NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
-
- virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
- virtual nsIDOMNode* AsDOMNode() { return this; }
-
- // WebIDL
- already_AddRefed<nsIDOMSVGAnimatedNumber> BaseFrequencyX();
- already_AddRefed<nsIDOMSVGAnimatedNumber> BaseFrequencyY();
- already_AddRefed<nsIDOMSVGAnimatedInteger> NumOctaves();
- already_AddRefed<nsIDOMSVGAnimatedNumber> Seed();
- already_AddRefed<nsIDOMSVGAnimatedEnumeration> StitchTiles();
- already_AddRefed<nsIDOMSVGAnimatedEnumeration> Type();
-
-protected:
- virtual NumberAttributesInfo GetNumberInfo();
- virtual NumberPairAttributesInfo GetNumberPairInfo();
- virtual IntegerAttributesInfo GetIntegerInfo();
- virtual EnumAttributesInfo GetEnumInfo();
- virtual StringAttributesInfo GetStringInfo();
-
- enum { SEED }; // floating point seed?!
- nsSVGNumber2 mNumberAttributes[1];
- static NumberInfo sNumberInfo[1];
-
- enum { BASE_FREQ };
- nsSVGNumberPair mNumberPairAttributes[1];
- static NumberPairInfo sNumberPairInfo[1];
-
- enum { OCTAVES };
- nsSVGInteger mIntegerAttributes[1];
- static IntegerInfo sIntegerInfo[1];
-
- enum { TYPE, STITCHTILES };
- nsSVGEnum mEnumAttributes[2];
- static nsSVGEnumMapping sTypeMap[];
- static nsSVGEnumMapping sStitchTilesMap[];
- static EnumInfo sEnumInfo[2];
-
- enum { RESULT };
- nsSVGString mStringAttributes[1];
- static StringInfo sStringInfo[1];
-
-private:
-
- /* The turbulence calculation code is an adapted version of what
- appears in the SVG 1.1 specification:
- http://www.w3.org/TR/SVG11/filters.html#feTurbulence
- */
-
- /* Produces results in the range [1, 2**31 - 2].
- Algorithm is: r = (a * r) mod m
- where a = 16807 and m = 2**31 - 1 = 2147483647
- See [Park & Miller], CACM vol. 31 no. 10 p. 1195, Oct. 1988
- To test: the algorithm should produce the result 1043618065
- as the 10,000th generated number if the original seed is 1.
- */
-#define RAND_M 2147483647 /* 2**31 - 1 */
-#define RAND_A 16807 /* 7**5; primitive root of m */
-#define RAND_Q 127773 /* m / a */
-#define RAND_R 2836 /* m % a */
-
- int32_t SetupSeed(int32_t aSeed) {
- if (aSeed <= 0)
- aSeed = -(aSeed % (RAND_M - 1)) +