| 1 |
/* |
| 2 |
* Copyright 2024 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "modules/svg/include/SkSVGFeMerge.h" |
| 9 |
|
| 10 |
#include "include/core/SkImageFilter.h" |
| 11 |
#include "include/effects/SkImageFilters.h" |
| 12 |
#include "include/private/base/SkTArray.h" |
| 13 |
#include "modules/svg/include/SkSVGAttributeParser.h" |
| 14 |
#include "modules/svg/include/SkSVGFilterContext.h" |
| 15 |
|
| 16 |
class SkSVGRenderContext; |
| 17 |
|
| 18 |
bool SkSVGFeMergeNode::parseAndSetAttribute(const char* name, const char* value) { |
| 19 |
return INHERITED::parseAndSetAttribute(name, value) || |
| 20 |
this->setIn(SkSVGAttributeParser::parse<SkSVGFeInputType>("in", name, value)); |
| 21 |
} |
| 22 |
|
| 23 |
sk_sp<SkImageFilter> SkSVGFeMerge::onMakeImageFilter(const SkSVGRenderContext& ctx, |
| 24 |
const SkSVGFilterContext& fctx) const { |
| 25 |
const SkSVGColorspace colorspace = this->resolveColorspace(ctx, fctx); |
| 26 |
|
| 27 |
skia_private::STArray<8, sk_sp<SkImageFilter>> merge_node_filters; |
| 28 |
merge_node_filters.reserve(fChildren.size()); |
| 29 |
|
| 30 |
this->forEachChild<SkSVGFeMergeNode>([&](const SkSVGFeMergeNode* child) { |
| 31 |
merge_node_filters.push_back(fctx.resolveInput(ctx, child->getIn(), colorspace)); |
| 32 |
}); |
| 33 |
|
| 34 |
return SkImageFilters::Merge(merge_node_filters.data(), |
| 35 |
merge_node_filters.size(), |
| 36 |
this->resolveFilterSubregion(ctx, fctx)); |
| 37 |
} |
| 38 |
|
| 39 |
std::vector<SkSVGFeInputType> SkSVGFeMerge::getInputs() const { |
| 40 |
std::vector<SkSVGFeInputType> inputs; |
| 41 |
inputs.reserve(fChildren.size()); |
| 42 |
|
| 43 |
this->forEachChild<SkSVGFeMergeNode>([&](const SkSVGFeMergeNode* child) { |
| 44 |
inputs.push_back(child->getIn()); |
| 45 |
}); |
| 46 |
|
| 47 |
return inputs; |
| 48 |
} |