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