[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>
This commit is contained in:
Tyler Denniston 2021-01-26 14:36:32 -05:00 committed by Skia Commit-Bot
parent 578f1acbe8
commit 32b3089618
9 changed files with 138 additions and 0 deletions

View File

@ -109,6 +109,7 @@ struct SkSVGPresentationAttributes {
SkSVGProperty<SkSVGNumberType, false> fStopOpacity; SkSVGProperty<SkSVGNumberType, false> fStopOpacity;
SkSVGProperty<SkSVGColor , false> fFloodColor; SkSVGProperty<SkSVGColor , false> fFloodColor;
SkSVGProperty<SkSVGNumberType, false> fFloodOpacity; SkSVGProperty<SkSVGNumberType, false> fFloodOpacity;
SkSVGProperty<SkSVGColor , false> fLightingColor;
}; };
#endif // SkSVGAttribute_DEFINED #endif // SkSVGAttribute_DEFINED

View File

@ -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

View File

@ -29,10 +29,13 @@ enum class SkSVGTag {
kFeColorMatrix, kFeColorMatrix,
kFeComposite, kFeComposite,
kFeDisplacementMap, kFeDisplacementMap,
kFeDistantLight,
kFeFlood, kFeFlood,
kFeGaussianBlur, kFeGaussianBlur,
kFeMorphology, kFeMorphology,
kFeOffset, kFeOffset,
kFePointLight,
kFeSpotLight,
kFeTurbulence, kFeTurbulence,
kFilter, kFilter,
kG, kG,
@ -136,6 +139,7 @@ public:
SVG_PRES_ATTR(StopOpacity , SkSVGNumberType, false) SVG_PRES_ATTR(StopOpacity , SkSVGNumberType, false)
SVG_PRES_ATTR(FloodColor , SkSVGColor , false) SVG_PRES_ATTR(FloodColor , SkSVGColor , false)
SVG_PRES_ATTR(FloodOpacity , SkSVGNumberType, false) SVG_PRES_ATTR(FloodOpacity , SkSVGNumberType, false)
SVG_PRES_ATTR(LightingColor , SkSVGColor , false)
protected: protected:
SkSVGNode(SkSVGTag); SkSVGNode(SkSVGTag);

View File

@ -40,6 +40,7 @@ SkSVGPresentationAttributes SkSVGPresentationAttributes::MakeInitial() {
result.fStopOpacity.set(SkSVGNumberType(1)); result.fStopOpacity.set(SkSVGNumberType(1));
result.fFloodColor.set(SkSVGColor(SK_ColorBLACK)); result.fFloodColor.set(SkSVGColor(SK_ColorBLACK));
result.fFloodOpacity.set(SkSVGNumberType(1)); result.fFloodOpacity.set(SkSVGNumberType(1));
result.fLightingColor.set(SkSVGColor(SK_ColorWHITE));
return result; return result;
} }

View File

@ -22,6 +22,7 @@
#include "modules/svg/include/SkSVGFeDisplacementMap.h" #include "modules/svg/include/SkSVGFeDisplacementMap.h"
#include "modules/svg/include/SkSVGFeFlood.h" #include "modules/svg/include/SkSVGFeFlood.h"
#include "modules/svg/include/SkSVGFeGaussianBlur.h" #include "modules/svg/include/SkSVGFeGaussianBlur.h"
#include "modules/svg/include/SkSVGFeLightSource.h"
#include "modules/svg/include/SkSVGFeMorphology.h" #include "modules/svg/include/SkSVGFeMorphology.h"
#include "modules/svg/include/SkSVGFeOffset.h" #include "modules/svg/include/SkSVGFeOffset.h"
#include "modules/svg/include/SkSVGFeTurbulence.h" #include "modules/svg/include/SkSVGFeTurbulence.h"
@ -266,11 +267,14 @@ SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = {
{ "feBlend" , []() -> sk_sp<SkSVGNode> { return SkSVGFeBlend::Make(); }}, { "feBlend" , []() -> sk_sp<SkSVGNode> { return SkSVGFeBlend::Make(); }},
{ "feColorMatrix" , []() -> sk_sp<SkSVGNode> { return SkSVGFeColorMatrix::Make(); }}, { "feColorMatrix" , []() -> sk_sp<SkSVGNode> { return SkSVGFeColorMatrix::Make(); }},
{ "feComposite" , []() -> sk_sp<SkSVGNode> { return SkSVGFeComposite::Make(); }}, { "feComposite" , []() -> sk_sp<SkSVGNode> { return SkSVGFeComposite::Make(); }},
{ "feDistantLight" , []() -> sk_sp<SkSVGNode> { return SkSVGFeDistantLight::Make(); }},
{ "feDisplacementMap", []() -> sk_sp<SkSVGNode> { return SkSVGFeDisplacementMap::Make(); }}, { "feDisplacementMap", []() -> sk_sp<SkSVGNode> { return SkSVGFeDisplacementMap::Make(); }},
{ "feFlood" , []() -> sk_sp<SkSVGNode> { return SkSVGFeFlood::Make(); }}, { "feFlood" , []() -> sk_sp<SkSVGNode> { return SkSVGFeFlood::Make(); }},
{ "feGaussianBlur" , []() -> sk_sp<SkSVGNode> { return SkSVGFeGaussianBlur::Make(); }}, { "feGaussianBlur" , []() -> sk_sp<SkSVGNode> { return SkSVGFeGaussianBlur::Make(); }},
{ "feMorphology" , []() -> sk_sp<SkSVGNode> { return SkSVGFeMorphology::Make(); }}, { "feMorphology" , []() -> sk_sp<SkSVGNode> { return SkSVGFeMorphology::Make(); }},
{ "feOffset" , []() -> sk_sp<SkSVGNode> { return SkSVGFeOffset::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(); }}, { "feTurbulence" , []() -> sk_sp<SkSVGNode> { return SkSVGFeTurbulence::Make(); }},
{ "filter" , []() -> sk_sp<SkSVGNode> { return SkSVGFilter::Make(); }}, { "filter" , []() -> sk_sp<SkSVGNode> { return SkSVGFilter::Make(); }},
{ "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }}, { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }},

View File

@ -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));
}

View File

@ -20,6 +20,7 @@ SkSVGNode::SkSVGNode(SkSVGTag t) : fTag(t) {
fPresentationAttributes.fStopOpacity.set(SkSVGNumberType(1.0f)); fPresentationAttributes.fStopOpacity.set(SkSVGNumberType(1.0f));
fPresentationAttributes.fFloodColor.set(SkSVGColor(SK_ColorBLACK)); fPresentationAttributes.fFloodColor.set(SkSVGColor(SK_ColorBLACK));
fPresentationAttributes.fFloodOpacity.set(SkSVGNumberType(1.0f)); fPresentationAttributes.fFloodOpacity.set(SkSVGNumberType(1.0f));
fPresentationAttributes.fLightingColor.set(SkSVGColor(SK_ColorWHITE));
} }
SkSVGNode::~SkSVGNode() { } SkSVGNode::~SkSVGNode() { }
@ -103,6 +104,7 @@ bool SkSVGNode::parseAndSetAttribute(const char* n, const char* v) {
|| PARSE_AND_SET("font-size" , FontSize) || PARSE_AND_SET("font-size" , FontSize)
|| PARSE_AND_SET("font-style" , FontStyle) || PARSE_AND_SET("font-style" , FontStyle)
|| PARSE_AND_SET("font-weight" , FontWeight) || PARSE_AND_SET("font-weight" , FontWeight)
|| PARSE_AND_SET("lighting-color" , LightingColor)
|| PARSE_AND_SET("mask" , Mask) || PARSE_AND_SET("mask" , Mask)
|| PARSE_AND_SET("opacity" , Opacity) || PARSE_AND_SET("opacity" , Opacity)
|| PARSE_AND_SET("stop-color" , StopColor) || PARSE_AND_SET("stop-color" , StopColor)

View File

@ -254,6 +254,7 @@ void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttr
// - stop-opacity // - stop-opacity
// - flood-color // - flood-color
// - flood-opacity // - flood-opacity
// - lighting-color
} }
void SkSVGRenderContext::applyOpacity(SkScalar opacity, uint32_t flags, bool hasFilter) { void SkSVGRenderContext::applyOpacity(SkScalar opacity, uint32_t flags, bool hasFilter) {

View File

@ -23,6 +23,7 @@ skia_svg_public = [
"$_include/SkSVGFeDisplacementMap.h", "$_include/SkSVGFeDisplacementMap.h",
"$_include/SkSVGFeFlood.h", "$_include/SkSVGFeFlood.h",
"$_include/SkSVGFeGaussianBlur.h", "$_include/SkSVGFeGaussianBlur.h",
"$_include/SkSVGFeLightSource.h",
"$_include/SkSVGFeMorphology.h", "$_include/SkSVGFeMorphology.h",
"$_include/SkSVGFeOffset.h", "$_include/SkSVGFeOffset.h",
"$_include/SkSVGFeTurbulence.h", "$_include/SkSVGFeTurbulence.h",
@ -67,6 +68,7 @@ skia_svg_sources = [
"$_src/SkSVGFeDisplacementMap.cpp", "$_src/SkSVGFeDisplacementMap.cpp",
"$_src/SkSVGFeFlood.cpp", "$_src/SkSVGFeFlood.cpp",
"$_src/SkSVGFeGaussianBlur.cpp", "$_src/SkSVGFeGaussianBlur.cpp",
"$_src/SkSVGFeLightSource.cpp",
"$_src/SkSVGFeMorphology.cpp", "$_src/SkSVGFeMorphology.cpp",
"$_src/SkSVGFeOffset.cpp", "$_src/SkSVGFeOffset.cpp",
"$_src/SkSVGFeTurbulence.cpp", "$_src/SkSVGFeTurbulence.cpp",