SVGFEDiffuseLightingElement.cpp (3189B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "mozilla/dom/SVGFEDiffuseLightingElement.h" 8 9 #include "mozilla/SVGFilterInstance.h" 10 #include "mozilla/dom/BindContext.h" 11 #include "mozilla/dom/Document.h" 12 #include "mozilla/dom/SVGFEDiffuseLightingElementBinding.h" 13 14 NS_IMPL_NS_NEW_SVG_ELEMENT(FEDiffuseLighting) 15 16 using namespace mozilla::gfx; 17 18 namespace mozilla::dom { 19 20 JSObject* SVGFEDiffuseLightingElement::WrapNode( 21 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 22 return SVGFEDiffuseLightingElement_Binding::Wrap(aCx, this, aGivenProto); 23 } 24 25 //---------------------------------------------------------------------- 26 // nsINode methods 27 28 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDiffuseLightingElement) 29 30 //---------------------------------------------------------------------- 31 32 already_AddRefed<DOMSVGAnimatedString> SVGFEDiffuseLightingElement::In1() { 33 return mStringAttributes[IN1].ToDOMAnimatedString(this); 34 } 35 36 already_AddRefed<DOMSVGAnimatedNumber> 37 SVGFEDiffuseLightingElement::SurfaceScale() { 38 return mNumberAttributes[SURFACE_SCALE].ToDOMAnimatedNumber(this); 39 } 40 41 already_AddRefed<DOMSVGAnimatedNumber> 42 SVGFEDiffuseLightingElement::DiffuseConstant() { 43 return mNumberAttributes[DIFFUSE_CONSTANT].ToDOMAnimatedNumber(this); 44 } 45 46 already_AddRefed<DOMSVGAnimatedNumber> 47 SVGFEDiffuseLightingElement::KernelUnitLengthX() { 48 return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber( 49 SVGAnimatedNumberPair::eFirst, this); 50 } 51 52 already_AddRefed<DOMSVGAnimatedNumber> 53 SVGFEDiffuseLightingElement::KernelUnitLengthY() { 54 return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber( 55 SVGAnimatedNumberPair::eSecond, this); 56 } 57 58 FilterPrimitiveDescription SVGFEDiffuseLightingElement::GetPrimitiveDescription( 59 SVGFilterInstance* aInstance, const IntRect& aFilterSubregion, 60 const nsTArray<bool>& aInputsAreTainted, 61 nsTArray<RefPtr<SourceSurface>>& aInputImages) { 62 float diffuseConstant = mNumberAttributes[DIFFUSE_CONSTANT].GetAnimValue(); 63 64 DiffuseLightingAttributes atts; 65 atts.mLightingConstant = diffuseConstant; 66 if (!AddLightingAttributes(&atts, aInstance)) { 67 return FilterPrimitiveDescription(); 68 } 69 70 return FilterPrimitiveDescription(AsVariant(std::move(atts))); 71 } 72 73 bool SVGFEDiffuseLightingElement::AttributeAffectsRendering( 74 int32_t aNameSpaceID, nsAtom* aAttribute) const { 75 return SVGFEDiffuseLightingElementBase::AttributeAffectsRendering( 76 aNameSpaceID, aAttribute) || 77 (aNameSpaceID == kNameSpaceID_None && 78 aAttribute == nsGkAtoms::diffuseConstant); 79 } 80 81 nsresult SVGFEDiffuseLightingElement::BindToTree(BindContext& aCtx, 82 nsINode& aParent) { 83 if (aCtx.InComposedDoc()) { 84 aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feDiffuseLighting); 85 } 86 87 return SVGFEDiffuseLightingElementBase::BindToTree(aCtx, aParent); 88 } 89 90 } // namespace mozilla::dom