blob: 1de1e4c4ed6a384d124d546baaa56b07b2b76681 [file] [log] [blame]
Tyler Denniston8eedcd22021-01-27 09:18:06 -05001/*
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 "modules/svg/include/SkSVGFe.h"
12#include "modules/svg/include/SkSVGTypes.h"
13
Tyler Dennistonf208f812021-04-29 11:20:06 -040014class SkSVGFeDistantLight;
Tyler Denniston8eedcd22021-01-27 09:18:06 -050015class SkSVGFePointLight;
Tyler Dennistoncdcd9a72021-04-30 11:55:07 -040016class SkSVGFeSpotLight;
Tyler Denniston8eedcd22021-01-27 09:18:06 -050017
18class SkSVGFeLighting : public SkSVGFe {
19public:
20 struct KernelUnitLength {
21 SkSVGNumberType fDx;
22 SkSVGNumberType fDy;
23 };
24
25 SVG_ATTR(SurfaceScale, SkSVGNumberType, 1)
26 SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength)
27
28protected:
29 explicit SkSVGFeLighting(SkSVGTag t) : INHERITED(t) {}
30
31 std::vector<SkSVGFeInputType> getInputs() const final { return {this->getIn()}; }
32
33 bool parseAndSetAttribute(const char*, const char*) override;
34
35 sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
36 const SkSVGFilterContext&) const final;
37
Tyler Dennistonf208f812021-04-29 11:20:06 -040038 virtual sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
39 const SkSVGFilterContext&,
40 const SkSVGFeDistantLight*) const = 0;
41
Tyler Denniston8eedcd22021-01-27 09:18:06 -050042 virtual sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
43 const SkSVGFilterContext&,
44 const SkSVGFePointLight*) const = 0;
45
Tyler Dennistoncdcd9a72021-04-30 11:55:07 -040046 virtual sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&,
47 const SkSVGFilterContext&,
48 const SkSVGFeSpotLight*) const = 0;
49
Tyler Denniston8eedcd22021-01-27 09:18:06 -050050 SkColor resolveLightingColor(const SkSVGRenderContext&) const;
51
52 SkPoint3 resolveXYZ(const SkSVGRenderContext&,
53 const SkSVGFilterContext&,
54 SkSVGNumberType,
55 SkSVGNumberType,
56 SkSVGNumberType) const;
57
58private:
59 using INHERITED = SkSVGFe;
60};
61
62class SkSVGFeSpecularLighting final : public SkSVGFeLighting {
63public:
64 static sk_sp<SkSVGFeSpecularLighting> Make() {
65 return sk_sp<SkSVGFeSpecularLighting>(new SkSVGFeSpecularLighting());
66 }
67
68 SVG_ATTR(SpecularConstant, SkSVGNumberType, 1)
69 SVG_ATTR(SpecularExponent, SkSVGNumberType, 1)
70
71protected:
72 bool parseAndSetAttribute(const char*, const char*) override;
73
Tyler Dennistonf208f812021-04-29 11:20:06 -040074 sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
75 const SkSVGFilterContext&,
76 const SkSVGFeDistantLight*) const final;
77
Tyler Denniston8eedcd22021-01-27 09:18:06 -050078 sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
79 const SkSVGFilterContext&,
80 const SkSVGFePointLight*) const final;
81
Tyler Dennistoncdcd9a72021-04-30 11:55:07 -040082 sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&,
83 const SkSVGFilterContext&,
84 const SkSVGFeSpotLight*) const final;
85
Tyler Denniston8eedcd22021-01-27 09:18:06 -050086private:
87 SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {}
88
89 using INHERITED = SkSVGFeLighting;
90};
91
Tyler Denniston8cfe7182021-04-29 14:54:25 -040092class SkSVGFeDiffuseLighting final : public SkSVGFeLighting {
93public:
94 static sk_sp<SkSVGFeDiffuseLighting> Make() {
95 return sk_sp<SkSVGFeDiffuseLighting>(new SkSVGFeDiffuseLighting());
96 }
97
98 SVG_ATTR(DiffuseConstant, SkSVGNumberType, 1)
99
100protected:
101 bool parseAndSetAttribute(const char*, const char*) override;
102
103 sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
104 const SkSVGFilterContext&,
105 const SkSVGFeDistantLight*) const final;
106
107 sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
108 const SkSVGFilterContext&,
109 const SkSVGFePointLight*) const final;
110
Tyler Dennistoncdcd9a72021-04-30 11:55:07 -0400111 sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&,
112 const SkSVGFilterContext&,
113 const SkSVGFeSpotLight*) const final;
114
Tyler Denniston8cfe7182021-04-29 14:54:25 -0400115private:
116 SkSVGFeDiffuseLighting() : INHERITED(SkSVGTag::kFeDiffuseLighting) {}
117
118 using INHERITED = SkSVGFeLighting;
119};
120
Tyler Denniston8eedcd22021-01-27 09:18:06 -0500121#endif // SkSVGFeLighting_DEFINED