SVGFEComponentTransferElement.cpp (3477B)
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/SVGFEComponentTransferElement.h" 8 9 #include "mozilla/dom/BindContext.h" 10 #include "mozilla/dom/Document.h" 11 #include "mozilla/dom/SVGComponentTransferFunctionElement.h" 12 #include "mozilla/dom/SVGFEComponentTransferElementBinding.h" 13 #include "mozilla/gfx/2D.h" 14 15 NS_IMPL_NS_NEW_SVG_ELEMENT(FEComponentTransfer) 16 17 using namespace mozilla::gfx; 18 ; 19 20 namespace mozilla::dom { 21 22 JSObject* SVGFEComponentTransferElement::WrapNode( 23 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 24 return SVGFEComponentTransferElement_Binding::Wrap(aCx, this, aGivenProto); 25 } 26 27 SVGElement::StringInfo SVGFEComponentTransferElement::sStringInfo[2] = { 28 {nsGkAtoms::result, kNameSpaceID_None, true}, 29 {nsGkAtoms::in, kNameSpaceID_None, true}}; 30 31 //---------------------------------------------------------------------- 32 // nsINode methods 33 34 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEComponentTransferElement) 35 36 already_AddRefed<DOMSVGAnimatedString> SVGFEComponentTransferElement::In1() { 37 return mStringAttributes[IN1].ToDOMAnimatedString(this); 38 } 39 40 //---------------------------------------------------------------------- 41 // SVGElement methods 42 43 SVGElement::StringAttributesInfo 44 SVGFEComponentTransferElement::GetStringInfo() { 45 return StringAttributesInfo(mStringAttributes, sStringInfo, 46 std::size(sStringInfo)); 47 } 48 49 //-------------------------------------------- 50 51 FilterPrimitiveDescription 52 SVGFEComponentTransferElement::GetPrimitiveDescription( 53 SVGFilterInstance* aInstance, const IntRect& aFilterSubregion, 54 const nsTArray<bool>& aInputsAreTainted, 55 nsTArray<RefPtr<SourceSurface>>& aInputImages) { 56 RefPtr<SVGComponentTransferFunctionElement> childForChannel[4]; 57 58 for (nsIContent* childContent = nsINode::GetFirstChild(); childContent; 59 childContent = childContent->GetNextSibling()) { 60 if (auto* child = 61 SVGComponentTransferFunctionElement::FromNode(childContent)) { 62 childForChannel[child->GetChannel()] = child; 63 } 64 } 65 66 ComponentTransferAttributes atts; 67 for (int32_t i = 0; i < 4; i++) { 68 if (childForChannel[i]) { 69 childForChannel[i]->ComputeAttributes(i, atts); 70 } else { 71 atts.mTypes[i] = (uint8_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY; 72 } 73 } 74 return FilterPrimitiveDescription(AsVariant(std::move(atts))); 75 } 76 77 bool SVGFEComponentTransferElement::AttributeAffectsRendering( 78 int32_t aNameSpaceID, nsAtom* aAttribute) const { 79 return SVGFEComponentTransferElementBase::AttributeAffectsRendering( 80 aNameSpaceID, aAttribute) || 81 (aNameSpaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::in); 82 } 83 84 void SVGFEComponentTransferElement::GetSourceImageNames( 85 nsTArray<SVGStringInfo>& aSources) { 86 aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this)); 87 } 88 89 nsresult SVGFEComponentTransferElement::BindToTree(BindContext& aCtx, 90 nsINode& aParent) { 91 if (aCtx.InComposedDoc()) { 92 aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feComponentTransfer); 93 } 94 95 return SVGFEComponentTransferElementBase::BindToTree(aCtx, aParent); 96 } 97 98 } // namespace mozilla::dom