SVGFEGaussianBlurElement.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/dom/SVGFEGaussianBlurElement.h"
  6. #include "mozilla/dom/SVGFEGaussianBlurElementBinding.h"
  7. #include "nsSVGFilterInstance.h"
  8. #include "nsSVGUtils.h"
  9. NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEGaussianBlur)
  10. using namespace mozilla::gfx;
  11. namespace mozilla {
  12. namespace dom {
  13. JSObject*
  14. SVGFEGaussianBlurElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  15. {
  16. return SVGFEGaussianBlurElementBinding::Wrap(aCx, this, aGivenProto);
  17. }
  18. nsSVGElement::NumberPairInfo SVGFEGaussianBlurElement::sNumberPairInfo[1] =
  19. {
  20. { &nsGkAtoms::stdDeviation, 0, 0 }
  21. };
  22. nsSVGElement::StringInfo SVGFEGaussianBlurElement::sStringInfo[2] =
  23. {
  24. { &nsGkAtoms::result, kNameSpaceID_None, true },
  25. { &nsGkAtoms::in, kNameSpaceID_None, true }
  26. };
  27. //----------------------------------------------------------------------
  28. // nsIDOMNode methods
  29. NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEGaussianBlurElement)
  30. //----------------------------------------------------------------------
  31. already_AddRefed<SVGAnimatedString>
  32. SVGFEGaussianBlurElement::In1()
  33. {
  34. return mStringAttributes[IN1].ToDOMAnimatedString(this);
  35. }
  36. already_AddRefed<SVGAnimatedNumber>
  37. SVGFEGaussianBlurElement::StdDeviationX()
  38. {
  39. return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
  40. }
  41. already_AddRefed<SVGAnimatedNumber>
  42. SVGFEGaussianBlurElement::StdDeviationY()
  43. {
  44. return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
  45. }
  46. void
  47. SVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, float stdDeviationY)
  48. {
  49. mNumberPairAttributes[STD_DEV].SetBaseValues(stdDeviationX, stdDeviationY, this);
  50. }
  51. FilterPrimitiveDescription
  52. SVGFEGaussianBlurElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
  53. const IntRect& aFilterSubregion,
  54. const nsTArray<bool>& aInputsAreTainted,
  55. nsTArray<RefPtr<SourceSurface>>& aInputImages)
  56. {
  57. float stdX = aInstance->GetPrimitiveNumber(SVGContentUtils::X,
  58. &mNumberPairAttributes[STD_DEV],
  59. nsSVGNumberPair::eFirst);
  60. float stdY = aInstance->GetPrimitiveNumber(SVGContentUtils::Y,
  61. &mNumberPairAttributes[STD_DEV],
  62. nsSVGNumberPair::eSecond);
  63. if (stdX < 0 || stdY < 0) {
  64. return FilterPrimitiveDescription(PrimitiveType::Empty);
  65. }
  66. FilterPrimitiveDescription descr(PrimitiveType::GaussianBlur);
  67. descr.Attributes().Set(eGaussianBlurStdDeviation, Size(stdX, stdY));
  68. return descr;
  69. }
  70. bool
  71. SVGFEGaussianBlurElement::AttributeAffectsRendering(int32_t aNameSpaceID,
  72. nsIAtom* aAttribute) const
  73. {
  74. return SVGFEGaussianBlurElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
  75. (aNameSpaceID == kNameSpaceID_None &&
  76. (aAttribute == nsGkAtoms::in ||
  77. aAttribute == nsGkAtoms::stdDeviation));
  78. }
  79. void
  80. SVGFEGaussianBlurElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
  81. {
  82. aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
  83. }
  84. //----------------------------------------------------------------------
  85. // nsSVGElement methods
  86. nsSVGElement::NumberPairAttributesInfo
  87. SVGFEGaussianBlurElement::GetNumberPairInfo()
  88. {
  89. return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
  90. ArrayLength(sNumberPairInfo));
  91. }
  92. nsSVGElement::StringAttributesInfo
  93. SVGFEGaussianBlurElement::GetStringInfo()
  94. {
  95. return StringAttributesInfo(mStringAttributes, sStringInfo,
  96. ArrayLength(sStringInfo));
  97. }
  98. } // namespace dom
  99. } // namespace mozilla