SVGFEGaussianBlurElement.cpp (4458B)
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/SVGFEGaussianBlurElement.h" 8 9 #include "mozilla/SVGFilterInstance.h" 10 #include "mozilla/dom/BindContext.h" 11 #include "mozilla/dom/Document.h" 12 #include "mozilla/dom/SVGFEGaussianBlurElementBinding.h" 13 14 NS_IMPL_NS_NEW_SVG_ELEMENT(FEGaussianBlur) 15 16 using namespace mozilla::gfx; 17 18 namespace mozilla::dom { 19 20 JSObject* SVGFEGaussianBlurElement::WrapNode( 21 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 22 return SVGFEGaussianBlurElement_Binding::Wrap(aCx, this, aGivenProto); 23 } 24 25 SVGElement::NumberPairInfo SVGFEGaussianBlurElement::sNumberPairInfo[1] = { 26 {nsGkAtoms::stdDeviation, 0, 0}}; 27 28 SVGElement::StringInfo SVGFEGaussianBlurElement::sStringInfo[2] = { 29 {nsGkAtoms::result, kNameSpaceID_None, true}, 30 {nsGkAtoms::in, kNameSpaceID_None, true}}; 31 32 //---------------------------------------------------------------------- 33 // nsINode methods 34 35 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEGaussianBlurElement) 36 37 //---------------------------------------------------------------------- 38 39 already_AddRefed<DOMSVGAnimatedString> SVGFEGaussianBlurElement::In1() { 40 return mStringAttributes[IN1].ToDOMAnimatedString(this); 41 } 42 43 already_AddRefed<DOMSVGAnimatedNumber> 44 SVGFEGaussianBlurElement::StdDeviationX() { 45 return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber( 46 SVGAnimatedNumberPair::eFirst, this); 47 } 48 49 already_AddRefed<DOMSVGAnimatedNumber> 50 SVGFEGaussianBlurElement::StdDeviationY() { 51 return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber( 52 SVGAnimatedNumberPair::eSecond, this); 53 } 54 55 void SVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, 56 float stdDeviationY) { 57 mNumberPairAttributes[STD_DEV].SetBaseValues(stdDeviationX, stdDeviationY, 58 this); 59 } 60 61 FilterPrimitiveDescription SVGFEGaussianBlurElement::GetPrimitiveDescription( 62 SVGFilterInstance* aInstance, const IntRect& aFilterSubregion, 63 const nsTArray<bool>& aInputsAreTainted, 64 nsTArray<RefPtr<SourceSurface>>& aInputImages) { 65 float stdX = aInstance->GetPrimitiveNumber(SVGContentUtils::X, 66 &mNumberPairAttributes[STD_DEV], 67 SVGAnimatedNumberPair::eFirst); 68 float stdY = aInstance->GetPrimitiveNumber(SVGContentUtils::Y, 69 &mNumberPairAttributes[STD_DEV], 70 SVGAnimatedNumberPair::eSecond); 71 if (stdX < 0 || stdY < 0) { 72 return FilterPrimitiveDescription(); 73 } 74 75 GaussianBlurAttributes atts; 76 atts.mStdDeviation = Size(stdX, stdY); 77 return FilterPrimitiveDescription(AsVariant(std::move(atts))); 78 } 79 80 bool SVGFEGaussianBlurElement::AttributeAffectsRendering( 81 int32_t aNameSpaceID, nsAtom* aAttribute) const { 82 return SVGFEGaussianBlurElementBase::AttributeAffectsRendering(aNameSpaceID, 83 aAttribute) || 84 (aNameSpaceID == kNameSpaceID_None && 85 (aAttribute == nsGkAtoms::in || 86 aAttribute == nsGkAtoms::stdDeviation)); 87 } 88 89 void SVGFEGaussianBlurElement::GetSourceImageNames( 90 nsTArray<SVGStringInfo>& aSources) { 91 aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this)); 92 } 93 94 nsresult SVGFEGaussianBlurElement::BindToTree(BindContext& aCtx, 95 nsINode& aParent) { 96 if (aCtx.InComposedDoc()) { 97 aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feGaussianBlur); 98 } 99 100 return SVGFEGaussianBlurElementBase::BindToTree(aCtx, aParent); 101 } 102 103 //---------------------------------------------------------------------- 104 // SVGElement methods 105 106 SVGElement::NumberPairAttributesInfo 107 SVGFEGaussianBlurElement::GetNumberPairInfo() { 108 return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo, 109 std::size(sNumberPairInfo)); 110 } 111 112 SVGElement::StringAttributesInfo SVGFEGaussianBlurElement::GetStringInfo() { 113 return StringAttributesInfo(mStringAttributes, sStringInfo, 114 std::size(sStringInfo)); 115 } 116 117 } // namespace mozilla::dom