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 | |
| 14 | class SkSVGFePointLight; |
| 15 | |
| 16 | class SkSVGFeLighting : public SkSVGFe { |
| 17 | public: |
| 18 | struct KernelUnitLength { |
| 19 | SkSVGNumberType fDx; |
| 20 | SkSVGNumberType fDy; |
| 21 | }; |
| 22 | |
| 23 | SVG_ATTR(SurfaceScale, SkSVGNumberType, 1) |
| 24 | SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength) |
| 25 | |
| 26 | protected: |
| 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 | |
| 48 | private: |
| 49 | using INHERITED = SkSVGFe; |
| 50 | }; |
| 51 | |
| 52 | class SkSVGFeSpecularLighting final : public SkSVGFeLighting { |
| 53 | public: |
| 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 | |
| 61 | protected: |
| 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 | |
| 68 | private: |
| 69 | SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {} |
| 70 | |
| 71 | using INHERITED = SkSVGFeLighting; |
| 72 | }; |
| 73 | |
| 74 | #endif // SkSVGFeLighting_DEFINED |