skia2/modules/svg/include/SkSVGFeLightSource.h
Tyler Denniston 8cfe718e0c [svg] Implement feDiffuseLighting
https://www.w3.org/TR/SVG11/filters.html#feDiffuseLightingElement

- Add SkSVGFeDiffuseLighting node
- Move distant light source direction computation into a method on
  SkSVGFeDistantLight
- Implement distant and point light sources for feDiffuseLighting

Bug: skia:10841
Change-Id: I74b8b9e04be5d2c5ac9f912d015dce96367040a1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402645
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-04-29 19:59:48 +00:00

90 lines
2.4 KiB
C++

/*
* 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 "include/core/SkPoint3.h"
#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());
}
SkPoint3 computeDirection() const;
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