1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2020 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SkSVGFeLighting_DEFINED
9cb93a386Sopenharmony_ci#define SkSVGFeLighting_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "modules/svg/include/SkSVGFe.h"
12cb93a386Sopenharmony_ci#include "modules/svg/include/SkSVGTypes.h"
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ciclass SkSVGFeDistantLight;
15cb93a386Sopenharmony_ciclass SkSVGFePointLight;
16cb93a386Sopenharmony_ciclass SkSVGFeSpotLight;
17cb93a386Sopenharmony_ci
18cb93a386Sopenharmony_ciclass SkSVGFeLighting : public SkSVGFe {
19cb93a386Sopenharmony_cipublic:
20cb93a386Sopenharmony_ci    struct KernelUnitLength {
21cb93a386Sopenharmony_ci        SkSVGNumberType fDx;
22cb93a386Sopenharmony_ci        SkSVGNumberType fDy;
23cb93a386Sopenharmony_ci    };
24cb93a386Sopenharmony_ci
25cb93a386Sopenharmony_ci    SVG_ATTR(SurfaceScale, SkSVGNumberType, 1)
26cb93a386Sopenharmony_ci    SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength)
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_ciprotected:
29cb93a386Sopenharmony_ci    explicit SkSVGFeLighting(SkSVGTag t) : INHERITED(t) {}
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_ci    std::vector<SkSVGFeInputType> getInputs() const final { return {this->getIn()}; }
32cb93a386Sopenharmony_ci
33cb93a386Sopenharmony_ci    bool parseAndSetAttribute(const char*, const char*) override;
34cb93a386Sopenharmony_ci
35cb93a386Sopenharmony_ci    sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
36cb93a386Sopenharmony_ci                                           const SkSVGFilterContext&) const final;
37cb93a386Sopenharmony_ci
38cb93a386Sopenharmony_ci    virtual sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
39cb93a386Sopenharmony_ci                                                  const SkSVGFilterContext&,
40cb93a386Sopenharmony_ci                                                  const SkSVGFeDistantLight*) const = 0;
41cb93a386Sopenharmony_ci
42cb93a386Sopenharmony_ci    virtual sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
43cb93a386Sopenharmony_ci                                                const SkSVGFilterContext&,
44cb93a386Sopenharmony_ci                                                const SkSVGFePointLight*) const = 0;
45cb93a386Sopenharmony_ci
46cb93a386Sopenharmony_ci    virtual sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&,
47cb93a386Sopenharmony_ci                                               const SkSVGFilterContext&,
48cb93a386Sopenharmony_ci                                               const SkSVGFeSpotLight*) const = 0;
49cb93a386Sopenharmony_ci
50cb93a386Sopenharmony_ci    SkColor resolveLightingColor(const SkSVGRenderContext&) const;
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_ci    SkPoint3 resolveXYZ(const SkSVGRenderContext&,
53cb93a386Sopenharmony_ci                        const SkSVGFilterContext&,
54cb93a386Sopenharmony_ci                        SkSVGNumberType,
55cb93a386Sopenharmony_ci                        SkSVGNumberType,
56cb93a386Sopenharmony_ci                        SkSVGNumberType) const;
57cb93a386Sopenharmony_ci
58cb93a386Sopenharmony_ciprivate:
59cb93a386Sopenharmony_ci    using INHERITED = SkSVGFe;
60cb93a386Sopenharmony_ci};
61cb93a386Sopenharmony_ci
62cb93a386Sopenharmony_ciclass SkSVGFeSpecularLighting final : public SkSVGFeLighting {
63cb93a386Sopenharmony_cipublic:
64cb93a386Sopenharmony_ci    static sk_sp<SkSVGFeSpecularLighting> Make() {
65cb93a386Sopenharmony_ci        return sk_sp<SkSVGFeSpecularLighting>(new SkSVGFeSpecularLighting());
66cb93a386Sopenharmony_ci    }
67cb93a386Sopenharmony_ci
68cb93a386Sopenharmony_ci    SVG_ATTR(SpecularConstant, SkSVGNumberType, 1)
69cb93a386Sopenharmony_ci    SVG_ATTR(SpecularExponent, SkSVGNumberType, 1)
70cb93a386Sopenharmony_ci
71cb93a386Sopenharmony_ciprotected:
72cb93a386Sopenharmony_ci    bool parseAndSetAttribute(const char*, const char*) override;
73cb93a386Sopenharmony_ci
74cb93a386Sopenharmony_ci    sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
75cb93a386Sopenharmony_ci                                          const SkSVGFilterContext&,
76cb93a386Sopenharmony_ci                                          const SkSVGFeDistantLight*) const final;
77cb93a386Sopenharmony_ci
78cb93a386Sopenharmony_ci    sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
79cb93a386Sopenharmony_ci                                        const SkSVGFilterContext&,
80cb93a386Sopenharmony_ci                                        const SkSVGFePointLight*) const final;
81cb93a386Sopenharmony_ci
82cb93a386Sopenharmony_ci    sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&,
83cb93a386Sopenharmony_ci                                       const SkSVGFilterContext&,
84cb93a386Sopenharmony_ci                                       const SkSVGFeSpotLight*) const final;
85cb93a386Sopenharmony_ci
86cb93a386Sopenharmony_ciprivate:
87cb93a386Sopenharmony_ci    SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {}
88cb93a386Sopenharmony_ci
89cb93a386Sopenharmony_ci    using INHERITED = SkSVGFeLighting;
90cb93a386Sopenharmony_ci};
91cb93a386Sopenharmony_ci
92cb93a386Sopenharmony_ciclass SkSVGFeDiffuseLighting final : public SkSVGFeLighting {
93cb93a386Sopenharmony_cipublic:
94cb93a386Sopenharmony_ci    static sk_sp<SkSVGFeDiffuseLighting> Make() {
95cb93a386Sopenharmony_ci        return sk_sp<SkSVGFeDiffuseLighting>(new SkSVGFeDiffuseLighting());
96cb93a386Sopenharmony_ci    }
97cb93a386Sopenharmony_ci
98cb93a386Sopenharmony_ci    SVG_ATTR(DiffuseConstant, SkSVGNumberType, 1)
99cb93a386Sopenharmony_ci
100cb93a386Sopenharmony_ciprotected:
101cb93a386Sopenharmony_ci    bool parseAndSetAttribute(const char*, const char*) override;
102cb93a386Sopenharmony_ci
103cb93a386Sopenharmony_ci    sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&,
104cb93a386Sopenharmony_ci                                          const SkSVGFilterContext&,
105cb93a386Sopenharmony_ci                                          const SkSVGFeDistantLight*) const final;
106cb93a386Sopenharmony_ci
107cb93a386Sopenharmony_ci    sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
108cb93a386Sopenharmony_ci                                        const SkSVGFilterContext&,
109cb93a386Sopenharmony_ci                                        const SkSVGFePointLight*) const final;
110cb93a386Sopenharmony_ci
111cb93a386Sopenharmony_ci    sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&,
112cb93a386Sopenharmony_ci                                       const SkSVGFilterContext&,
113cb93a386Sopenharmony_ci                                       const SkSVGFeSpotLight*) const final;
114cb93a386Sopenharmony_ci
115cb93a386Sopenharmony_ciprivate:
116cb93a386Sopenharmony_ci    SkSVGFeDiffuseLighting() : INHERITED(SkSVGTag::kFeDiffuseLighting) {}
117cb93a386Sopenharmony_ci
118cb93a386Sopenharmony_ci    using INHERITED = SkSVGFeLighting;
119cb93a386Sopenharmony_ci};
120cb93a386Sopenharmony_ci
121cb93a386Sopenharmony_ci#endif  // SkSVGFeLighting_DEFINED
122