/src/skia/modules/svg/include/SkSVGFeLighting.h
Line | Count | Source (jump to first uncovered line) |
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 SkSVGFeLighting_DEFINED |
9 | | #define SkSVGFeLighting_DEFINED |
10 | | |
11 | | #include "include/core/SkColor.h" |
12 | | #include "include/core/SkPoint3.h" |
13 | | #include "include/core/SkRefCnt.h" |
14 | | #include "include/private/base/SkAPI.h" |
15 | | #include "modules/svg/include/SkSVGFe.h" |
16 | | #include "modules/svg/include/SkSVGNode.h" |
17 | | #include "modules/svg/include/SkSVGTypes.h" |
18 | | #include "src/base/SkTLazy.h" |
19 | | |
20 | | #include <vector> |
21 | | |
22 | | class SkImageFilter; |
23 | | class SkSVGFeDistantLight; |
24 | | class SkSVGFePointLight; |
25 | | class SkSVGFeSpotLight; |
26 | | class SkSVGFilterContext; |
27 | | class SkSVGRenderContext; |
28 | | |
29 | | class SK_API SkSVGFeLighting : public SkSVGFe { |
30 | | public: |
31 | | struct KernelUnitLength { |
32 | | SkSVGNumberType fDx; |
33 | | SkSVGNumberType fDy; |
34 | | }; |
35 | | |
36 | | SVG_ATTR(SurfaceScale, SkSVGNumberType, 1) |
37 | | SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength) |
38 | | |
39 | | protected: |
40 | 0 | explicit SkSVGFeLighting(SkSVGTag t) : INHERITED(t) {} |
41 | | |
42 | 0 | std::vector<SkSVGFeInputType> getInputs() const final { return {this->getIn()}; } |
43 | | |
44 | | bool parseAndSetAttribute(const char*, const char*) override; |
45 | | |
46 | | sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&, |
47 | | const SkSVGFilterContext&) const final; |
48 | | |
49 | | virtual sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
50 | | const SkSVGFilterContext&, |
51 | | const SkSVGFeDistantLight*) const = 0; |
52 | | |
53 | | virtual sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
54 | | const SkSVGFilterContext&, |
55 | | const SkSVGFePointLight*) const = 0; |
56 | | |
57 | | virtual sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
58 | | const SkSVGFilterContext&, |
59 | | const SkSVGFeSpotLight*) const = 0; |
60 | | |
61 | | SkColor resolveLightingColor(const SkSVGRenderContext&) const; |
62 | | |
63 | | SkPoint3 resolveXYZ(const SkSVGRenderContext&, |
64 | | const SkSVGFilterContext&, |
65 | | SkSVGNumberType, |
66 | | SkSVGNumberType, |
67 | | SkSVGNumberType) const; |
68 | | |
69 | | private: |
70 | | using INHERITED = SkSVGFe; |
71 | | }; |
72 | | |
73 | | class SkSVGFeSpecularLighting final : public SkSVGFeLighting { |
74 | | public: |
75 | 0 | static sk_sp<SkSVGFeSpecularLighting> Make() { |
76 | 0 | return sk_sp<SkSVGFeSpecularLighting>(new SkSVGFeSpecularLighting()); |
77 | 0 | } |
78 | | |
79 | | SVG_ATTR(SpecularConstant, SkSVGNumberType, 1) |
80 | | SVG_ATTR(SpecularExponent, SkSVGNumberType, 1) |
81 | | |
82 | | protected: |
83 | | bool parseAndSetAttribute(const char*, const char*) override; |
84 | | |
85 | | sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
86 | | const SkSVGFilterContext&, |
87 | | const SkSVGFeDistantLight*) const final; |
88 | | |
89 | | sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
90 | | const SkSVGFilterContext&, |
91 | | const SkSVGFePointLight*) const final; |
92 | | |
93 | | sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
94 | | const SkSVGFilterContext&, |
95 | | const SkSVGFeSpotLight*) const final; |
96 | | |
97 | | private: |
98 | 0 | SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {} |
99 | | |
100 | | using INHERITED = SkSVGFeLighting; |
101 | | }; |
102 | | |
103 | | class SkSVGFeDiffuseLighting final : public SkSVGFeLighting { |
104 | | public: |
105 | 0 | static sk_sp<SkSVGFeDiffuseLighting> Make() { |
106 | 0 | return sk_sp<SkSVGFeDiffuseLighting>(new SkSVGFeDiffuseLighting()); |
107 | 0 | } |
108 | | |
109 | | SVG_ATTR(DiffuseConstant, SkSVGNumberType, 1) |
110 | | |
111 | | protected: |
112 | | bool parseAndSetAttribute(const char*, const char*) override; |
113 | | |
114 | | sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
115 | | const SkSVGFilterContext&, |
116 | | const SkSVGFeDistantLight*) const final; |
117 | | |
118 | | sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
119 | | const SkSVGFilterContext&, |
120 | | const SkSVGFePointLight*) const final; |
121 | | |
122 | | sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
123 | | const SkSVGFilterContext&, |
124 | | const SkSVGFeSpotLight*) const final; |
125 | | |
126 | | private: |
127 | 0 | SkSVGFeDiffuseLighting() : INHERITED(SkSVGTag::kFeDiffuseLighting) {} |
128 | | |
129 | | using INHERITED = SkSVGFeLighting; |
130 | | }; |
131 | | |
132 | | #endif // SkSVGFeLighting_DEFINED |