xref: /aosp_15_r20/external/skia/modules/svg/include/SkSVGFeColorMatrix.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2020 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 #ifndef SkSVGFeColorMatrix_DEFINED
9 #define SkSVGFeColorMatrix_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/effects/SkColorMatrix.h"
13 #include "include/private/base/SkAPI.h"
14 #include "modules/svg/include/SkSVGFe.h"
15 #include "modules/svg/include/SkSVGNode.h"
16 #include "modules/svg/include/SkSVGTypes.h"
17 
18 #include <vector>
19 
20 class SkImageFilter;
21 class SkSVGFilterContext;
22 class SkSVGRenderContext;
23 
24 class SK_API SkSVGFeColorMatrix final : public SkSVGFe {
25 public:
Make()26     static sk_sp<SkSVGFeColorMatrix> Make() {
27         return sk_sp<SkSVGFeColorMatrix>(new SkSVGFeColorMatrix());
28     }
29 
30     SVG_ATTR(Type, SkSVGFeColorMatrixType, SkSVGFeColorMatrixType(SkSVGFeColorMatrixType::kMatrix))
31     SVG_ATTR(Values, SkSVGFeColorMatrixValues, SkSVGFeColorMatrixValues())
32 
33 protected:
34     sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
35                                            const SkSVGFilterContext&) const override;
36 
getInputs()37     std::vector<SkSVGFeInputType> getInputs() const override { return {this->getIn()}; }
38 
39     bool parseAndSetAttribute(const char*, const char*) override;
40 
41 private:
SkSVGFeColorMatrix()42     SkSVGFeColorMatrix() : INHERITED(SkSVGTag::kFeColorMatrix) {}
43 
44     SkColorMatrix makeMatrixForType() const;
45 
46     static SkColorMatrix MakeSaturate(SkSVGNumberType s);
47 
48     static SkColorMatrix MakeHueRotate(SkSVGNumberType degrees);
49 
50     static SkColorMatrix MakeLuminanceToAlpha();
51 
52     using INHERITED = SkSVGFe;
53 };
54 
55 #endif  // SkSVGFeColorMatrix_DEFINED
56