blob: 3a0da6718ecb31681eed283636d9497486a4c410 [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;
16
17class SkSVGFeLighting : public SkSVGFe {
18public:
19 struct KernelUnitLength {
20 SkSVGNumberType fDx;
21 SkSVGNumberType fDy;
22 };
23
24 SVG_ATTR(SurfaceScale, SkSVGNumberType, 1)
25 SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength)
26
27protected:
28 explicit SkSVGFeLighting(SkSVGTag t) : INHERITED(t) {}
29
30 std::vector<SkSVGFeInputType> getInputs() const final { return {this->getIn()}; }
31
32 bool parseAndSetAttribute(const char*, const char*) override;
33
34 sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
35 const SkSVGFilterContext&) const final;
36
Tyler Dennistonf208f812021-04-29 11:20:06 -040037 virtual sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
38 const SkSVGFilterContext&,
39 const SkSVGFeDistantLight*) const = 0;
40
Tyler Denniston8eedcd22021-01-27 09:18:06 -050041 virtual sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
42 const SkSVGFilterContext&,
43 const SkSVGFePointLight*) const = 0;
44
45 SkColor resolveLightingColor(const SkSVGRenderContext&) const;
46
47 SkPoint3 resolveXYZ(const SkSVGRenderContext&,
48 const SkSVGFilterContext&,
49 SkSVGNumberType,
50 SkSVGNumberType,
51 SkSVGNumberType) const;
52
53private:
54 using INHERITED = SkSVGFe;
55};
56
57class SkSVGFeSpecularLighting final : public SkSVGFeLighting {
58public:
59 static sk_sp<SkSVGFeSpecularLighting> Make() {
60 return sk_sp<SkSVGFeSpecularLighting>(new SkSVGFeSpecularLighting());
61 }
62
63 SVG_ATTR(SpecularConstant, SkSVGNumberType, 1)
64 SVG_ATTR(SpecularExponent, SkSVGNumberType, 1)
65
66protected:
67 bool parseAndSetAttribute(const char*, const char*) override;
68
Tyler Dennistonf208f812021-04-29 11:20:06 -040069 sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
70 const SkSVGFilterContext&,
71 const SkSVGFeDistantLight*) const final;
72
Tyler Denniston8eedcd22021-01-27 09:18:06 -050073 sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
74 const SkSVGFilterContext&,
75 const SkSVGFePointLight*) const final;
76
77private:
78 SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {}
79
80 using INHERITED = SkSVGFeLighting;
81};
82
83#endif // SkSVGFeLighting_DEFINED