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; |
| 16 | |
| 17 | class SkSVGFeLighting : public SkSVGFe { |
| 18 | public: |
| 19 | struct KernelUnitLength { |
| 20 | SkSVGNumberType fDx; |
| 21 | SkSVGNumberType fDy; |
| 22 | }; |
| 23 | |
| 24 | SVG_ATTR(SurfaceScale, SkSVGNumberType, 1) |
| 25 | SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength) |
| 26 | |
| 27 | protected: |
| 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 Denniston | f208f81 | 2021-04-29 11:20:06 -0400 | [diff] [blame^] | 37 | virtual sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
| 38 | const SkSVGFilterContext&, |
| 39 | const SkSVGFeDistantLight*) const = 0; |
| 40 | |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 41 | 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 | |
| 53 | private: |
| 54 | using INHERITED = SkSVGFe; |
| 55 | }; |
| 56 | |
| 57 | class SkSVGFeSpecularLighting final : public SkSVGFeLighting { |
| 58 | public: |
| 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 | |
| 66 | protected: |
| 67 | bool parseAndSetAttribute(const char*, const char*) override; |
| 68 | |
Tyler Denniston | f208f81 | 2021-04-29 11:20:06 -0400 | [diff] [blame^] | 69 | sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
| 70 | const SkSVGFilterContext&, |
| 71 | const SkSVGFeDistantLight*) const final; |
| 72 | |
Tyler Denniston | 8eedcd2 | 2021-01-27 09:18:06 -0500 | [diff] [blame] | 73 | sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
| 74 | const SkSVGFilterContext&, |
| 75 | const SkSVGFePointLight*) const final; |
| 76 | |
| 77 | private: |
| 78 | SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {} |
| 79 | |
| 80 | using INHERITED = SkSVGFeLighting; |
| 81 | }; |
| 82 | |
| 83 | #endif // SkSVGFeLighting_DEFINED |