skia2/modules/svg/include/SkSVGFeLighting.h
Tyler Denniston 8eedcd2dea [svg] Partial implementation of feSpecularLighting
https://www.w3.org/TR/SVG11/filters.html#feSpecularLightingElement

Because a fair amount of functionality will be shared between
feSpecularLighting and feDiffuseLighting, this CL adds an intermediate
SkSVGFeLighting base class for common code.

The only light source type implemented in this CL is fePointLight, which
exercised by the filters-light-03 W3C test.

Bug: skia:10841
Change-Id: Icae26dedb1aae1cd25ba2db7c6468a243ebacbc5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359756
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
2021-01-27 16:14:29 +00:00

75 lines
2.2 KiB
C++

/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkSVGFeLighting_DEFINED
#define SkSVGFeLighting_DEFINED
#include "modules/svg/include/SkSVGFe.h"
#include "modules/svg/include/SkSVGTypes.h"
class SkSVGFePointLight;
class SkSVGFeLighting : public SkSVGFe {
public:
struct KernelUnitLength {
SkSVGNumberType fDx;
SkSVGNumberType fDy;
};
SVG_ATTR(SurfaceScale, SkSVGNumberType, 1)
SVG_OPTIONAL_ATTR(KernelUnitLength, KernelUnitLength)
protected:
explicit SkSVGFeLighting(SkSVGTag t) : INHERITED(t) {}
std::vector<SkSVGFeInputType> getInputs() const final { return {this->getIn()}; }
bool parseAndSetAttribute(const char*, const char*) override;
sk_sp<SkImageFilter> onMakeImageFilter(const SkSVGRenderContext&,
const SkSVGFilterContext&) const final;
virtual sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
const SkSVGFilterContext&,
const SkSVGFePointLight*) const = 0;
SkColor resolveLightingColor(const SkSVGRenderContext&) const;
SkPoint3 resolveXYZ(const SkSVGRenderContext&,
const SkSVGFilterContext&,
SkSVGNumberType,
SkSVGNumberType,
SkSVGNumberType) const;
private:
using INHERITED = SkSVGFe;
};
class SkSVGFeSpecularLighting final : public SkSVGFeLighting {
public:
static sk_sp<SkSVGFeSpecularLighting> Make() {
return sk_sp<SkSVGFeSpecularLighting>(new SkSVGFeSpecularLighting());
}
SVG_ATTR(SpecularConstant, SkSVGNumberType, 1)
SVG_ATTR(SpecularExponent, SkSVGNumberType, 1)
protected:
bool parseAndSetAttribute(const char*, const char*) override;
sk_sp<SkImageFilter> makePointLight(const SkSVGRenderContext&,
const SkSVGFilterContext&,
const SkSVGFePointLight*) const final;
private:
SkSVGFeSpecularLighting() : INHERITED(SkSVGTag::kFeSpecularLighting) {}
using INHERITED = SkSVGFeLighting;
};
#endif // SkSVGFeLighting_DEFINED