SVGFEComponentTransferElement.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/SVGComponentTransferFunctionElement.h"
  6. #include "mozilla/dom/SVGFEComponentTransferElement.h"
  7. #include "mozilla/dom/SVGFEComponentTransferElementBinding.h"
  8. #include "nsSVGUtils.h"
  9. #include "mozilla/gfx/2D.h"
  10. NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEComponentTransfer)
  11. using namespace mozilla::gfx;;
  12. namespace mozilla {
  13. namespace dom {
  14. JSObject*
  15. SVGFEComponentTransferElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  16. {
  17. return SVGFEComponentTransferElementBinding::Wrap(aCx, this, aGivenProto);
  18. }
  19. nsSVGElement::StringInfo SVGFEComponentTransferElement::sStringInfo[2] =
  20. {
  21. { &nsGkAtoms::result, kNameSpaceID_None, true },
  22. { &nsGkAtoms::in, kNameSpaceID_None, true }
  23. };
  24. //----------------------------------------------------------------------
  25. // nsIDOMNode methods
  26. NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEComponentTransferElement)
  27. already_AddRefed<SVGAnimatedString>
  28. SVGFEComponentTransferElement::In1()
  29. {
  30. return mStringAttributes[IN1].ToDOMAnimatedString(this);
  31. }
  32. //----------------------------------------------------------------------
  33. // nsSVGElement methods
  34. nsSVGElement::StringAttributesInfo
  35. SVGFEComponentTransferElement::GetStringInfo()
  36. {
  37. return StringAttributesInfo(mStringAttributes, sStringInfo,
  38. ArrayLength(sStringInfo));
  39. }
  40. //--------------------------------------------
  41. FilterPrimitiveDescription
  42. SVGFEComponentTransferElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
  43. const IntRect& aFilterSubregion,
  44. const nsTArray<bool>& aInputsAreTainted,
  45. nsTArray<RefPtr<SourceSurface>>& aInputImages)
  46. {
  47. RefPtr<SVGComponentTransferFunctionElement> childForChannel[4];
  48. for (nsIContent* childContent = nsINode::GetFirstChild();
  49. childContent;
  50. childContent = childContent->GetNextSibling()) {
  51. RefPtr<SVGComponentTransferFunctionElement> child;
  52. CallQueryInterface(childContent,
  53. (SVGComponentTransferFunctionElement**)getter_AddRefs(child));
  54. if (child) {
  55. childForChannel[child->GetChannel()] = child;
  56. }
  57. }
  58. static const AttributeName attributeNames[4] = {
  59. eComponentTransferFunctionR,
  60. eComponentTransferFunctionG,
  61. eComponentTransferFunctionB,
  62. eComponentTransferFunctionA
  63. };
  64. FilterPrimitiveDescription descr(PrimitiveType::ComponentTransfer);
  65. for (int32_t i = 0; i < 4; i++) {
  66. if (childForChannel[i]) {
  67. descr.Attributes().Set(attributeNames[i], childForChannel[i]->ComputeAttributes());
  68. } else {
  69. AttributeMap functionAttributes;
  70. functionAttributes.Set(eComponentTransferFunctionType,
  71. (uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
  72. descr.Attributes().Set(attributeNames[i], functionAttributes);
  73. }
  74. }
  75. return descr;
  76. }
  77. bool
  78. SVGFEComponentTransferElement::AttributeAffectsRendering(int32_t aNameSpaceID,
  79. nsIAtom* aAttribute) const
  80. {
  81. return SVGFEComponentTransferElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
  82. (aNameSpaceID == kNameSpaceID_None &&
  83. aAttribute == nsGkAtoms::in);
  84. }
  85. void
  86. SVGFEComponentTransferElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
  87. {
  88. aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
  89. }
  90. } // namespace dom
  91. } // namespace mozilla