SVGFESpecularLightingElement.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/SVGFESpecularLightingElement.h"
  6. #include "mozilla/dom/SVGFESpecularLightingElementBinding.h"
  7. #include "nsSVGUtils.h"
  8. #include "nsSVGFilterInstance.h"
  9. NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FESpecularLighting)
  10. using namespace mozilla::gfx;
  11. namespace mozilla {
  12. namespace dom {
  13. JSObject*
  14. SVGFESpecularLightingElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  15. {
  16. return SVGFESpecularLightingElementBinding::Wrap(aCx, this, aGivenProto);
  17. }
  18. //----------------------------------------------------------------------
  19. // nsIDOMNode methods
  20. NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFESpecularLightingElement)
  21. already_AddRefed<SVGAnimatedString>
  22. SVGFESpecularLightingElement::In1()
  23. {
  24. return mStringAttributes[IN1].ToDOMAnimatedString(this);
  25. }
  26. already_AddRefed<SVGAnimatedNumber>
  27. SVGFESpecularLightingElement::SurfaceScale()
  28. {
  29. return mNumberAttributes[SURFACE_SCALE].ToDOMAnimatedNumber(this);
  30. }
  31. already_AddRefed<SVGAnimatedNumber>
  32. SVGFESpecularLightingElement::SpecularConstant()
  33. {
  34. return mNumberAttributes[SPECULAR_CONSTANT].ToDOMAnimatedNumber(this);
  35. }
  36. already_AddRefed<SVGAnimatedNumber>
  37. SVGFESpecularLightingElement::SpecularExponent()
  38. {
  39. return mNumberAttributes[SPECULAR_EXPONENT].ToDOMAnimatedNumber(this);
  40. }
  41. already_AddRefed<SVGAnimatedNumber>
  42. SVGFESpecularLightingElement::KernelUnitLengthX()
  43. {
  44. return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
  45. nsSVGNumberPair::eFirst, this);
  46. }
  47. already_AddRefed<SVGAnimatedNumber>
  48. SVGFESpecularLightingElement::KernelUnitLengthY()
  49. {
  50. return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
  51. nsSVGNumberPair::eSecond, this);
  52. }
  53. //----------------------------------------------------------------------
  54. // nsSVGElement methods
  55. FilterPrimitiveDescription
  56. SVGFESpecularLightingElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
  57. const IntRect& aFilterSubregion,
  58. const nsTArray<bool>& aInputsAreTainted,
  59. nsTArray<RefPtr<SourceSurface>>& aInputImages)
  60. {
  61. float specularExponent = mNumberAttributes[SPECULAR_EXPONENT].GetAnimValue();
  62. float specularConstant = mNumberAttributes[SPECULAR_CONSTANT].GetAnimValue();
  63. // specification defined range (15.22)
  64. if (specularExponent < 1 || specularExponent > 128) {
  65. return FilterPrimitiveDescription(PrimitiveType::Empty);
  66. }
  67. FilterPrimitiveDescription descr(PrimitiveType::SpecularLighting);
  68. descr.Attributes().Set(eSpecularLightingSpecularConstant, specularConstant);
  69. descr.Attributes().Set(eSpecularLightingSpecularExponent, specularExponent);
  70. return AddLightingAttributes(descr, aInstance);
  71. }
  72. bool
  73. SVGFESpecularLightingElement::AttributeAffectsRendering(int32_t aNameSpaceID,
  74. nsIAtom* aAttribute) const
  75. {
  76. return SVGFESpecularLightingElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
  77. (aNameSpaceID == kNameSpaceID_None &&
  78. (aAttribute == nsGkAtoms::specularConstant ||
  79. aAttribute == nsGkAtoms::specularExponent));
  80. }
  81. } // namespace dom
  82. } // namespace mozilla