Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 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 "modules/svg/include/SkSVGFe.h" |
| 12 | #include "modules/svg/include/SkSVGTypes.h" |
| 13 | |
Tyler Denniston | f208f81 | 2021-04-29 11:20:06 -0400 | [diff] [blame] | 14 | class SkSVGFeDistantLight; |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 15 | class SkSVGFePointLight; |
Tyler Denniston | cdcd9a7 | 2021-04-30 11:55:07 -0400 | [diff] [blame] | 16 | class SkSVGFeSpotLight; |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 17 | |
| 18 | class SkSVGFeLighting : public SkSVGFe { |
| 19 | public: |
| 20 | struct KernelUnitLength { |
| 21 | SkSVGNumberType fDx; |
| 22 | SkSVGNumberType fDy; |
| 23 | }; |
| 24 | |
| 25 | SVG_ATTR(SurfaceScale, SkSVGNumberType, 1) |
| 26 | SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength) |
| 27 | |
| 28 | protected: |
| 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 Denniston | f208f81 | 2021-04-29 11:20:06 -0400 | [diff] [blame] | 38 | virtual sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
| 39 | const SkSVGFilterContext&, |
| 40 | const SkSVGFeDistantLight*) const = 0; |
| 41 | |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 42 | virtual sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
| 43 | const SkSVGFilterContext&, |
| 44 | const SkSVGFePointLight*) const = 0; |
| 45 | |
Tyler Denniston | cdcd9a7 | 2021-04-30 11:55:07 -0400 | [diff] [blame] | 46 | virtual sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
| 47 | const SkSVGFilterContext&, |
| 48 | const SkSVGFeSpotLight*) const = 0; |
| 49 | |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 50 | SkColor resolveLightingColor(const SkSVGRenderContext&) const; |
| 51 | |
| 52 | SkPoint3 resolveXYZ(const SkSVGRenderContext&, |
| 53 | const SkSVGFilterContext&, |
| 54 | SkSVGNumberType, |
| 55 | SkSVGNumberType, |
| 56 | SkSVGNumberType) const; |
| 57 | |
| 58 | private: |
| 59 | using INHERITED = SkSVGFe; |
| 60 | }; |
| 61 | |
| 62 | class SkSVGFeSpecularLighting final : public SkSVGFeLighting { |
| 63 | public: |
| 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 | |
| 71 | protected: |
| 72 | bool parseAndSetAttribute(const char*, const char*) override; |
| 73 | |
Tyler Denniston | f208f81 | 2021-04-29 11:20:06 -0400 | [diff] [blame] | 74 | sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
| 75 | const SkSVGFilterContext&, |
| 76 | const SkSVGFeDistantLight*) const final; |
| 77 | |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 78 | sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
| 79 | const SkSVGFilterContext&, |
| 80 | const SkSVGFePointLight*) const final; |
| 81 | |
Tyler Denniston | cdcd9a7 | 2021-04-30 11:55:07 -0400 | [diff] [blame] | 82 | sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
| 83 | const SkSVGFilterContext&, |
| 84 | const SkSVGFeSpotLight*) const final; |
| 85 | |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 86 | private: |
| 87 | SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {} |
| 88 | |
| 89 | using INHERITED = SkSVGFeLighting; |
| 90 | }; |
| 91 | |
Tyler Denniston | 8cfe718 | 2021-04-29 14:54:25 -0400 | [diff] [blame] | 92 | class SkSVGFeDiffuseLighting final : public SkSVGFeLighting { |
| 93 | public: |
| 94 | static sk_sp<SkSVGFeDiffuseLighting> Make() { |
| 95 | return sk_sp<SkSVGFeDiffuseLighting>(new SkSVGFeDiffuseLighting()); |
| 96 | } |
| 97 | |
| 98 | SVG_ATTR(DiffuseConstant, SkSVGNumberType, 1) |
| 99 | |
| 100 | protected: |
| 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 Denniston | cdcd9a7 | 2021-04-30 11:55:07 -0400 | [diff] [blame] | 111 | sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
| 112 | const SkSVGFilterContext&, |
| 113 | const SkSVGFeSpotLight*) const final; |
| 114 | |
Tyler Denniston | 8cfe718 | 2021-04-29 14:54:25 -0400 | [diff] [blame] | 115 | private: |
| 116 | SkSVGFeDiffuseLighting() : INHERITED(SkSVGTag::kFeDiffuseLighting) {} |
| 117 | |
| 118 | using INHERITED = SkSVGFeLighting; |
| 119 | }; |
| 120 | |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 121 | #endif // SkSVGFeLighting_DEFINED |