Flutter Engine
The Flutter Engine
SkSVGFeLighting.cpp
Go to the documentation of this file.
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
16
17bool SkSVGFeLighting::parseAndSetAttribute(const char* n, const char* v) {
19 this->setSurfaceScale(
20 SkSVGAttributeParser::parse<SkSVGNumberType>("surfaceScale", n, v)) ||
21 this->setKernelUnitLength(SkSVGAttributeParser::parse<SkSVGFeLighting::KernelUnitLength>(
22 "kernelUnitLength", n, v));
23}
24
25template <>
26bool SkSVGAttributeParser::parse<SkSVGFeLighting::KernelUnitLength>(
27 SkSVGFeLighting::KernelUnitLength* kernelUnitLength) {
28 std::vector<SkSVGNumberType> values;
29 if (!this->parse(&values)) {
30 return false;
31 }
32
33 kernelUnitLength->fDx = values[0];
34 kernelUnitLength->fDy = values.size() > 1 ? values[1] : values[0];
35 return true;
36}
37
39 const SkSVGFilterContext& fctx) const {
40 for (const auto& child : fChildren) {
41 switch (child->tag()) {
43 return this->makeDistantLight(
44 ctx, fctx, static_cast<const SkSVGFeDistantLight*>(child.get()));
46 return this->makePointLight(
47 ctx, fctx, static_cast<const SkSVGFePointLight*>(child.get()));
49 return this->makeSpotLight(
50 ctx, fctx, static_cast<const SkSVGFeSpotLight*>(child.get()));
51 default:
52 // Ignore unknown children, such as <desc> elements
53 break;
54 }
55 }
56
57 SkDebugf("lighting filter effect needs exactly one light source\n");
58 return nullptr;
59}
60
62 const auto color = this->getLightingColor();
63 if (!color.isValue()) {
64 // Uninherited presentation attributes should have a concrete value by now.
65 SkDebugf("unhandled: lighting-color has no value\n");
66 return SK_ColorWHITE;
67 }
68
69 return ctx.resolveSvgColor(*color);
70}
71
73 const SkSVGFilterContext& fctx,
76 SkSVGNumberType z) const {
77 const auto obbt = ctx.transformForCurrentOBB(fctx.primitiveUnits());
78 const auto xy = SkV2{x,y} * obbt.scale + obbt.offset;
79 z = SkSVGLengthContext({obbt.scale.x, obbt.scale.y})
82 return SkPoint3::Make(xy.x, xy.y, z);
83}
84
85bool SkSVGFeSpecularLighting::parseAndSetAttribute(const char* n, const char* v) {
87 this->setSpecularConstant(
88 SkSVGAttributeParser::parse<SkSVGNumberType>("specularConstant", n, v)) ||
89 this->setSpecularExponent(
90 SkSVGAttributeParser::parse<SkSVGNumberType>("specularExponent", n, v));
91}
92
94 const SkSVGRenderContext& ctx,
95 const SkSVGFilterContext& fctx,
96 const SkSVGFeDistantLight* light) const {
97 const SkPoint3 dir = light->computeDirection();
99 this->resolveXYZ(ctx, fctx, dir.fX, dir.fY, dir.fZ),
100 this->resolveLightingColor(ctx),
101 this->getSurfaceScale(),
102 fSpecularConstant,
103 fSpecularExponent,
104 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
105 this->resolveFilterSubregion(ctx, fctx));
106}
107
109 const SkSVGFilterContext& fctx,
110 const SkSVGFePointLight* light) const {
112 this->resolveXYZ(ctx, fctx, light->getX(), light->getY(), light->getZ()),
113 this->resolveLightingColor(ctx),
114 this->getSurfaceScale(),
115 fSpecularConstant,
116 fSpecularExponent,
117 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
118 this->resolveFilterSubregion(ctx, fctx));
119}
120
122 const SkSVGFilterContext& fctx,
123 const SkSVGFeSpotLight* light) const {
124 const auto& limitingConeAngle = light->getLimitingConeAngle();
125 const float cutoffAngle = limitingConeAngle.isValid() ? *limitingConeAngle : 180.f;
126
128 this->resolveXYZ(ctx, fctx, light->getX(), light->getY(), light->getZ()),
129 this->resolveXYZ(
130 ctx, fctx, light->getPointsAtX(), light->getPointsAtY(), light->getPointsAtZ()),
131 light->getSpecularExponent(),
132 cutoffAngle,
133 this->resolveLightingColor(ctx),
134 this->getSurfaceScale(),
135 fSpecularConstant,
136 fSpecularExponent,
137 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
138 this->resolveFilterSubregion(ctx, fctx));
139}
140
141bool SkSVGFeDiffuseLighting::parseAndSetAttribute(const char* n, const char* v) {
142 return INHERITED::parseAndSetAttribute(n, v) ||
143 this->setDiffuseConstant(
144 SkSVGAttributeParser::parse<SkSVGNumberType>("diffuseConstant", n, v));
145}
146
148 const SkSVGRenderContext& ctx,
149 const SkSVGFilterContext& fctx,
150 const SkSVGFeDistantLight* light) const {
151 const SkPoint3 dir = light->computeDirection();
153 this->resolveXYZ(ctx, fctx, dir.fX, dir.fY, dir.fZ),
154 this->resolveLightingColor(ctx),
155 this->getSurfaceScale(),
156 this->getDiffuseConstant(),
157 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
158 this->resolveFilterSubregion(ctx, fctx));
159}
160
162 const SkSVGFilterContext& fctx,
163 const SkSVGFePointLight* light) const {
165 this->resolveXYZ(ctx, fctx, light->getX(), light->getY(), light->getZ()),
166 this->resolveLightingColor(ctx),
167 this->getSurfaceScale(),
168 this->getDiffuseConstant(),
169 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
170 this->resolveFilterSubregion(ctx, fctx));
171}
172
174 const SkSVGFilterContext& fctx,
175 const SkSVGFeSpotLight* light) const {
176 const auto& limitingConeAngle = light->getLimitingConeAngle();
177 const float cutoffAngle = limitingConeAngle.isValid() ? *limitingConeAngle : 180.f;
178
180 this->resolveXYZ(ctx, fctx, light->getX(), light->getY(), light->getZ()),
181 this->resolveXYZ(
182 ctx, fctx, light->getPointsAtX(), light->getPointsAtY(), light->getPointsAtZ()),
183 light->getSpecularExponent(),
184 cutoffAngle,
185 this->resolveLightingColor(ctx),
186 this->getSurfaceScale(),
187 this->getDiffuseConstant(),
188 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
189 this->resolveFilterSubregion(ctx, fctx));
190}
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
@ kFeDistantLight
SkScalar SkSVGNumberType
Definition: SkSVGTypes.h:27
static sk_sp< SkImageFilter > PointLitDiffuse(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitSpecular(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitDiffuse(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > PointLitSpecular(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitDiffuse(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitSpecular(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
skia_private::STArray< 1, sk_sp< SkSVGNode >, true > fChildren
sk_sp< SkImageFilter > makeDistantLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFeDistantLight *) const final
sk_sp< SkImageFilter > makePointLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFePointLight *) const final
sk_sp< SkImageFilter > makeSpotLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFeSpotLight *) const final
bool parseAndSetAttribute(const char *, const char *) override
SkPoint3 computeDirection() const
virtual sk_sp< SkImageFilter > makePointLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFePointLight *) const =0
bool parseAndSetAttribute(const char *, const char *) override
sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const final
SkPoint3 resolveXYZ(const SkSVGRenderContext &, const SkSVGFilterContext &, SkSVGNumberType, SkSVGNumberType, SkSVGNumberType) const
virtual sk_sp< SkImageFilter > makeDistantLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFeDistantLight *) const =0
SkColor resolveLightingColor(const SkSVGRenderContext &) const
virtual sk_sp< SkImageFilter > makeSpotLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFeSpotLight *) const =0
sk_sp< SkImageFilter > makeSpotLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFeSpotLight *) const final
bool parseAndSetAttribute(const char *, const char *) override
sk_sp< SkImageFilter > makePointLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFePointLight *) const final
sk_sp< SkImageFilter > makeDistantLight(const SkSVGRenderContext &, const SkSVGFilterContext &, const SkSVGFeDistantLight *) const final
bool parseAndSetAttribute(const char *, const char *) override
Definition: SkSVGFe.cpp:93
sk_sp< SkImageFilter > resolveInput(const SkSVGRenderContext &, const SkSVGFeInputType &) const
const SkSVGObjectBoundingBoxUnits & primitiveUnits() const
SkSVGColorType resolveSvgColor(const SkSVGColor &) const
OBBTransform transformForCurrentOBB(SkSVGObjectBoundingBoxUnits) const
DlColor color
double y
double x
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
def parse(repo_root, recipes_cfg_path)
Definition: recipes.py:56
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
Definition: SkM44.h:19