SVGFEDiffuseLightingElement.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/SVGFEDiffuseLightingElement.h"
  6. #include "mozilla/dom/SVGFEDiffuseLightingElementBinding.h"
  7. #include "nsSVGUtils.h"
  8. #include "nsSVGFilterInstance.h"
  9. NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEDiffuseLighting)
  10. using namespace mozilla::gfx;
  11. namespace mozilla {
  12. namespace dom {
  13. JSObject*
  14. SVGFEDiffuseLightingElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  15. {
  16. return SVGFEDiffuseLightingElementBinding::Wrap(aCx, this, aGivenProto);
  17. }
  18. //----------------------------------------------------------------------
  19. // nsIDOMNode methods
  20. NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDiffuseLightingElement)
  21. //----------------------------------------------------------------------
  22. already_AddRefed<SVGAnimatedString>
  23. SVGFEDiffuseLightingElement::In1()
  24. {
  25. return mStringAttributes[IN1].ToDOMAnimatedString(this);
  26. }
  27. already_AddRefed<SVGAnimatedNumber>
  28. SVGFEDiffuseLightingElement::SurfaceScale()
  29. {
  30. return mNumberAttributes[SURFACE_SCALE].ToDOMAnimatedNumber(this);
  31. }
  32. already_AddRefed<SVGAnimatedNumber>
  33. SVGFEDiffuseLightingElement::DiffuseConstant()
  34. {
  35. return mNumberAttributes[DIFFUSE_CONSTANT].ToDOMAnimatedNumber(this);
  36. }
  37. already_AddRefed<SVGAnimatedNumber>
  38. SVGFEDiffuseLightingElement::KernelUnitLengthX()
  39. {
  40. return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
  41. nsSVGNumberPair::eFirst, this);
  42. }
  43. already_AddRefed<SVGAnimatedNumber>
  44. SVGFEDiffuseLightingElement::KernelUnitLengthY()
  45. {
  46. return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
  47. nsSVGNumberPair::eSecond, this);
  48. }
  49. FilterPrimitiveDescription
  50. SVGFEDiffuseLightingElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
  51. const IntRect& aFilterSubregion,
  52. const nsTArray<bool>& aInputsAreTainted,
  53. nsTArray<RefPtr<SourceSurface>>& aInputImages)
  54. {
  55. float diffuseConstant = mNumberAttributes[DIFFUSE_CONSTANT].GetAnimValue();
  56. FilterPrimitiveDescription descr(PrimitiveType::DiffuseLighting);
  57. descr.Attributes().Set(eDiffuseLightingDiffuseConstant, diffuseConstant);
  58. return AddLightingAttributes(descr, aInstance);
  59. }
  60. bool
  61. SVGFEDiffuseLightingElement::AttributeAffectsRendering(int32_t aNameSpaceID,
  62. nsIAtom* aAttribute) const
  63. {
  64. return SVGFEDiffuseLightingElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
  65. (aNameSpaceID == kNameSpaceID_None &&
  66. aAttribute == nsGkAtoms::diffuseConstant);
  67. }
  68. } // namespace dom
  69. } // namespace mozilla