[svg] Add light source classes and lighting-color pres attr
https://www.w3.org/TR/SVG11/filters.html#LightSourceDefinitions
The three classes represent light source elements that will eventually
be used for feSpecularLighting and feDiffuseLighting. Currently they are
unused.
Also added the (currently unused) lighting-color presentation attribute.
Bug: skia:10841
Change-Id: Ic7824671662b8cd88cf627affc54173d5e881b7d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359557
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/modules/svg/include/SkSVGAttribute.h b/modules/svg/include/SkSVGAttribute.h
index e063501..b8f13cb 100644
--- a/modules/svg/include/SkSVGAttribute.h
+++ b/modules/svg/include/SkSVGAttribute.h
@@ -109,6 +109,7 @@
SkSVGProperty<SkSVGNumberType, false> fStopOpacity;
SkSVGProperty<SkSVGColor , false> fFloodColor;
SkSVGProperty<SkSVGNumberType, false> fFloodOpacity;
+ SkSVGProperty<SkSVGColor , false> fLightingColor;
};
#endif // SkSVGAttribute_DEFINED
diff --git a/modules/svg/include/SkSVGFeLightSource.h b/modules/svg/include/SkSVGFeLightSource.h
new file mode 100644
index 0000000..75f0074
--- /dev/null
+++ b/modules/svg/include/SkSVGFeLightSource.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2021 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkSVGFeLightSource_DEFINED
+#define SkSVGFeLightSource_DEFINED
+
+#include "modules/svg/include/SkSVGHiddenContainer.h"
+#include "modules/svg/include/SkSVGTypes.h"
+
+class SkSVGFeLightSource : public SkSVGHiddenContainer {
+public:
+ void appendChild(sk_sp<SkSVGNode>) final {
+ SkDebugf("cannot append child nodes to an SVG light source.\n");
+ }
+
+protected:
+ explicit SkSVGFeLightSource(SkSVGTag tag) : INHERITED(tag) {}
+
+private:
+ using INHERITED = SkSVGHiddenContainer;
+};
+
+class SkSVGFeDistantLight final : public SkSVGFeLightSource {
+public:
+ static sk_sp<SkSVGFeDistantLight> Make() {
+ return sk_sp<SkSVGFeDistantLight>(new SkSVGFeDistantLight());
+ }
+
+ SVG_ATTR(Azimuth , SkSVGNumberType, 0)
+ SVG_ATTR(Elevation, SkSVGNumberType, 0)
+
+private:
+ SkSVGFeDistantLight() : INHERITED(SkSVGTag::kFeDistantLight) {}
+
+ bool parseAndSetAttribute(const char*, const char*) override;
+
+ using INHERITED = SkSVGFeLightSource;
+};
+
+class SkSVGFePointLight final : public SkSVGFeLightSource {
+public:
+ static sk_sp<SkSVGFePointLight> Make() {
+ return sk_sp<SkSVGFePointLight>(new SkSVGFePointLight());
+ }
+
+ SVG_ATTR(X, SkSVGNumberType, 0)
+ SVG_ATTR(Y, SkSVGNumberType, 0)
+ SVG_ATTR(Z, SkSVGNumberType, 0)
+
+private:
+ SkSVGFePointLight() : INHERITED(SkSVGTag::kFePointLight) {}
+
+ bool parseAndSetAttribute(const char*, const char*) override;
+
+ using INHERITED = SkSVGFeLightSource;
+};
+
+class SkSVGFeSpotLight final : public SkSVGFeLightSource {
+public:
+ static sk_sp<SkSVGFeSpotLight> Make() {
+ return sk_sp<SkSVGFeSpotLight>(new SkSVGFeSpotLight());
+ }
+
+ SVG_ATTR(X , SkSVGNumberType, 0)
+ SVG_ATTR(Y , SkSVGNumberType, 0)
+ SVG_ATTR(Z , SkSVGNumberType, 0)
+ SVG_ATTR(PointsAtX , SkSVGNumberType, 0)
+ SVG_ATTR(PointsAtY , SkSVGNumberType, 0)
+ SVG_ATTR(PointsAtZ , SkSVGNumberType, 0)
+ SVG_ATTR(SpecularExponent, SkSVGNumberType, 1)
+
+ SVG_OPTIONAL_ATTR(LimitingConeAngle, SkSVGNumberType)
+
+private:
+ SkSVGFeSpotLight() : INHERITED(SkSVGTag::kFeSpotLight) {}
+
+ bool parseAndSetAttribute(const char*, const char*) override;
+
+ using INHERITED = SkSVGFeLightSource;
+};
+
+#endif // SkSVGFeLightSource_DEFINED
diff --git a/modules/svg/include/SkSVGNode.h b/modules/svg/include/SkSVGNode.h
index f7fc6c9..e8e5a8f 100644
--- a/modules/svg/include/SkSVGNode.h
+++ b/modules/svg/include/SkSVGNode.h
@@ -29,10 +29,13 @@
kFeColorMatrix,
kFeComposite,
kFeDisplacementMap,
+ kFeDistantLight,
kFeFlood,
kFeGaussianBlur,
kFeMorphology,
kFeOffset,
+ kFePointLight,
+ kFeSpotLight,
kFeTurbulence,
kFilter,
kG,
@@ -136,6 +139,7 @@
SVG_PRES_ATTR(StopOpacity , SkSVGNumberType, false)
SVG_PRES_ATTR(FloodColor , SkSVGColor , false)
SVG_PRES_ATTR(FloodOpacity , SkSVGNumberType, false)
+ SVG_PRES_ATTR(LightingColor , SkSVGColor , false)
protected:
SkSVGNode(SkSVGTag);
diff --git a/modules/svg/src/SkSVGAttribute.cpp b/modules/svg/src/SkSVGAttribute.cpp
index 098dc7b..f636adb 100644
--- a/modules/svg/src/SkSVGAttribute.cpp
+++ b/modules/svg/src/SkSVGAttribute.cpp
@@ -40,6 +40,7 @@
result.fStopOpacity.set(SkSVGNumberType(1));
result.fFloodColor.set(SkSVGColor(SK_ColorBLACK));
result.fFloodOpacity.set(SkSVGNumberType(1));
+ result.fLightingColor.set(SkSVGColor(SK_ColorWHITE));
return result;
}
diff --git a/modules/svg/src/SkSVGDOM.cpp b/modules/svg/src/SkSVGDOM.cpp
index 08fea1f..b026e36 100644
--- a/modules/svg/src/SkSVGDOM.cpp
+++ b/modules/svg/src/SkSVGDOM.cpp
@@ -22,6 +22,7 @@
#include "modules/svg/include/SkSVGFeDisplacementMap.h"
#include "modules/svg/include/SkSVGFeFlood.h"
#include "modules/svg/include/SkSVGFeGaussianBlur.h"
+#include "modules/svg/include/SkSVGFeLightSource.h"
#include "modules/svg/include/SkSVGFeMorphology.h"
#include "modules/svg/include/SkSVGFeOffset.h"
#include "modules/svg/include/SkSVGFeTurbulence.h"
@@ -266,11 +267,14 @@
{ "feBlend" , []() -> sk_sp<SkSVGNode> { return SkSVGFeBlend::Make(); }},
{ "feColorMatrix" , []() -> sk_sp<SkSVGNode> { return SkSVGFeColorMatrix::Make(); }},
{ "feComposite" , []() -> sk_sp<SkSVGNode> { return SkSVGFeComposite::Make(); }},
+ { "feDistantLight" , []() -> sk_sp<SkSVGNode> { return SkSVGFeDistantLight::Make(); }},
{ "feDisplacementMap", []() -> sk_sp<SkSVGNode> { return SkSVGFeDisplacementMap::Make(); }},
{ "feFlood" , []() -> sk_sp<SkSVGNode> { return SkSVGFeFlood::Make(); }},
{ "feGaussianBlur" , []() -> sk_sp<SkSVGNode> { return SkSVGFeGaussianBlur::Make(); }},
{ "feMorphology" , []() -> sk_sp<SkSVGNode> { return SkSVGFeMorphology::Make(); }},
{ "feOffset" , []() -> sk_sp<SkSVGNode> { return SkSVGFeOffset::Make(); }},
+ { "fePointLight" , []() -> sk_sp<SkSVGNode> { return SkSVGFePointLight::Make(); }},
+ { "feSpotLight" , []() -> sk_sp<SkSVGNode> { return SkSVGFeSpotLight::Make(); }},
{ "feTurbulence" , []() -> sk_sp<SkSVGNode> { return SkSVGFeTurbulence::Make(); }},
{ "filter" , []() -> sk_sp<SkSVGNode> { return SkSVGFilter::Make(); }},
{ "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }},
diff --git a/modules/svg/src/SkSVGFeLightSource.cpp b/modules/svg/src/SkSVGFeLightSource.cpp
new file mode 100644
index 0000000..f1f74af
--- /dev/null
+++ b/modules/svg/src/SkSVGFeLightSource.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2021 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "modules/svg/include/SkSVGAttributeParser.h"
+#include "modules/svg/include/SkSVGFeLightSource.h"
+#include "modules/svg/include/SkSVGValue.h"
+
+bool SkSVGFeDistantLight::parseAndSetAttribute(const char* n, const char* v) {
+ return INHERITED::parseAndSetAttribute(n, v) ||
+ this->setAzimuth(SkSVGAttributeParser::parse<SkSVGNumberType>("azimuth", n, v)) ||
+ this->setElevation(SkSVGAttributeParser::parse<SkSVGNumberType>("elevation", n, v));
+}
+
+bool SkSVGFePointLight::parseAndSetAttribute(const char* n, const char* v) {
+ return INHERITED::parseAndSetAttribute(n, v) ||
+ this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) ||
+ this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) ||
+ this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v));
+}
+
+bool SkSVGFeSpotLight::parseAndSetAttribute(const char* n, const char* v) {
+ return INHERITED::parseAndSetAttribute(n, v) ||
+ this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) ||
+ this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) ||
+ this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v)) ||
+ this->setPointsAtX(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtX", n, v)) ||
+ this->setPointsAtY(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtY", n, v)) ||
+ this->setPointsAtZ(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtZ", n, v)) ||
+ this->setSpecularExponent(
+ SkSVGAttributeParser::parse<SkSVGNumberType>("specularExponent", n, v)) ||
+ this->setLimitingConeAngle(
+ SkSVGAttributeParser::parse<SkSVGNumberType>("limitingConeAngle", n, v));
+}
diff --git a/modules/svg/src/SkSVGNode.cpp b/modules/svg/src/SkSVGNode.cpp
index fd2a4e3..ae3aef2 100644
--- a/modules/svg/src/SkSVGNode.cpp
+++ b/modules/svg/src/SkSVGNode.cpp
@@ -20,6 +20,7 @@
fPresentationAttributes.fStopOpacity.set(SkSVGNumberType(1.0f));
fPresentationAttributes.fFloodColor.set(SkSVGColor(SK_ColorBLACK));
fPresentationAttributes.fFloodOpacity.set(SkSVGNumberType(1.0f));
+ fPresentationAttributes.fLightingColor.set(SkSVGColor(SK_ColorWHITE));
}
SkSVGNode::~SkSVGNode() { }
@@ -103,6 +104,7 @@
|| PARSE_AND_SET("font-size" , FontSize)
|| PARSE_AND_SET("font-style" , FontStyle)
|| PARSE_AND_SET("font-weight" , FontWeight)
+ || PARSE_AND_SET("lighting-color" , LightingColor)
|| PARSE_AND_SET("mask" , Mask)
|| PARSE_AND_SET("opacity" , Opacity)
|| PARSE_AND_SET("stop-color" , StopColor)
diff --git a/modules/svg/src/SkSVGRenderContext.cpp b/modules/svg/src/SkSVGRenderContext.cpp
index 431296e..563f8db 100644
--- a/modules/svg/src/SkSVGRenderContext.cpp
+++ b/modules/svg/src/SkSVGRenderContext.cpp
@@ -254,6 +254,7 @@
// - stop-opacity
// - flood-color
// - flood-opacity
+ // - lighting-color
}
void SkSVGRenderContext::applyOpacity(SkScalar opacity, uint32_t flags, bool hasFilter) {
diff --git a/modules/svg/svg.gni b/modules/svg/svg.gni
index 0d677dd..169ee3f 100644
--- a/modules/svg/svg.gni
+++ b/modules/svg/svg.gni
@@ -23,6 +23,7 @@
"$_include/SkSVGFeDisplacementMap.h",
"$_include/SkSVGFeFlood.h",
"$_include/SkSVGFeGaussianBlur.h",
+ "$_include/SkSVGFeLightSource.h",
"$_include/SkSVGFeMorphology.h",
"$_include/SkSVGFeOffset.h",
"$_include/SkSVGFeTurbulence.h",
@@ -67,6 +68,7 @@
"$_src/SkSVGFeDisplacementMap.cpp",
"$_src/SkSVGFeFlood.cpp",
"$_src/SkSVGFeGaussianBlur.cpp",
+ "$_src/SkSVGFeLightSource.cpp",
"$_src/SkSVGFeMorphology.cpp",
"$_src/SkSVGFeOffset.cpp",
"$_src/SkSVGFeTurbulence.cpp",