| 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 "include/core/SkColor.h" |
| 12 |
#include "include/core/SkPoint3.h" |
| 13 |
#include "include/core/SkRefCnt.h" |
| 14 |
#include "include/private/base/SkAPI.h" |
| 15 |
#include "modules/svg/include/SkSVGFe.h" |
| 16 |
#include "modules/svg/include/SkSVGNode.h" |
| 17 |
#include "modules/svg/include/SkSVGTypes.h" |
| 18 |
|
| 19 |
#include <vector> |
| 20 |
|
| 21 |
class SkImageFilter; |
| 22 |
class SkSVGFeDistantLight; |
| 23 |
class SkSVGFePointLight; |
| 24 |
class SkSVGFeSpotLight; |
| 25 |
class SkSVGFilterContext; |
| 26 |
class SkSVGRenderContext; |
| 27 |
|
| 28 |
class SK_API SkSVGFeLighting : public SkSVGFe { |
| 29 |
public: |
| 30 |
struct KernelUnitLength { |
| 31 |
SkSVGNumberType fDx; |
| 32 |
SkSVGNumberType fDy; |
| 33 |
}; |
| 34 |
|
| 35 |
SVG_ATTR(SurfaceScale, SkSVGNumberType, 1) |
| 36 |
SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength) |
| 37 |
|
| 38 |
protected: |
| 39 |
explicit SkSVGFeLighting(SkSVGTag t) : INHERITED(t) {} |
| 40 |
|
| 41 |
std::vector<SkSVGFeInputType> getInputs() const final { return {this->getIn()}; } |
| 42 |
|
| 43 |
bool parseAndSetAttribute(const char*, const char*) override; |
| 44 |
|
| 45 |
sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&, |
| 46 |
const SkSVGFilterContext&) const final; |
| 47 |
|
| 48 |
virtual sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
| 49 |
const SkSVGFilterContext&, |
| 50 |
const SkSVGFeDistantLight*) const = 0; |
| 51 |
|
| 52 |
virtual sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
| 53 |
const SkSVGFilterContext&, |
| 54 |
const SkSVGFePointLight*) const = 0; |
| 55 |
|
| 56 |
virtual sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
| 57 |
const SkSVGFilterContext&, |
| 58 |
const SkSVGFeSpotLight*) const = 0; |
| 59 |
|
| 60 |
SkColor resolveLightingColor(const SkSVGRenderContext&) const; |
| 61 |
|
| 62 |
SkPoint3 resolveXYZ(const SkSVGRenderContext&, |
| 63 |
const SkSVGFilterContext&, |
| 64 |
SkSVGNumberType, |
| 65 |
SkSVGNumberType, |
| 66 |
SkSVGNumberType) const; |
| 67 |
|
| 68 |
private: |
| 69 |
using INHERITED = SkSVGFe; |
| 70 |
}; |
| 71 |
|
| 72 |
class SkSVGFeSpecularLighting final : public SkSVGFeLighting { |
| 73 |
public: |
| 74 |
static sk_sp<SkSVGFeSpecularLighting> Make() { |
| 75 |
return sk_sp<SkSVGFeSpecularLighting>(new SkSVGFeSpecularLighting()); |
| 76 |
} |
| 77 |
|
| 78 |
SVG_ATTR(SpecularConstant, SkSVGNumberType, 1) |
| 79 |
SVG_ATTR(SpecularExponent, SkSVGNumberType, 1) |
| 80 |
|
| 81 |
protected: |
| 82 |
bool parseAndSetAttribute(const char*, const char*) override; |
| 83 |
|
| 84 |
sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
| 85 |
const SkSVGFilterContext&, |
| 86 |
const SkSVGFeDistantLight*) const final; |
| 87 |
|
| 88 |
sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
| 89 |
const SkSVGFilterContext&, |
| 90 |
const SkSVGFePointLight*) const final; |
| 91 |
|
| 92 |
sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
| 93 |
const SkSVGFilterContext&, |
| 94 |
const SkSVGFeSpotLight*) const final; |
| 95 |
|
| 96 |
private: |
| 97 |
SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {} |
| 98 |
|
| 99 |
using INHERITED = SkSVGFeLighting; |
| 100 |
}; |
| 101 |
|
| 102 |
class SkSVGFeDiffuseLighting final : public SkSVGFeLighting { |
| 103 |
public: |
| 104 |
static sk_sp<SkSVGFeDiffuseLighting> Make() { |
| 105 |
return sk_sp<SkSVGFeDiffuseLighting>(new SkSVGFeDiffuseLighting()); |
| 106 |
} |
| 107 |
|
| 108 |
SVG_ATTR(DiffuseConstant, SkSVGNumberType, 1) |
| 109 |
|
| 110 |
protected: |
| 111 |
bool parseAndSetAttribute(const char*, const char*) override; |
| 112 |
|
| 113 |
sk_sp<SkImageFilter> makeDistantLight(const SkSVGRenderContext&, |
| 114 |
const SkSVGFilterContext&, |
| 115 |
const SkSVGFeDistantLight*) const final; |
| 116 |
|
| 117 |
sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&, |
| 118 |
const SkSVGFilterContext&, |
| 119 |
const SkSVGFePointLight*) const final; |
| 120 |
|
| 121 |
sk_sp<SkImageFilter> makeSpotLight(const SkSVGRenderContext&, |
| 122 |
const SkSVGFilterContext&, |
| 123 |
const SkSVGFeSpotLight*) const final; |
| 124 |
|
| 125 |
private: |
| 126 |
SkSVGFeDiffuseLighting() : INHERITED(SkSVGTag::kFeDiffuseLighting) {} |
| 127 |
|
| 128 |
using INHERITED = SkSVGFeLighting; |
| 129 |
}; |
| 130 |
|
| 131 |
#endif // SkSVGFeLighting_DEFINED |