Flutter Engine
The Flutter Engine
SkSVGFeTurbulence.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
15
16bool SkSVGFeTurbulence::parseAndSetAttribute(const char* name, const char* value) {
18 this->setNumOctaves(
19 SkSVGAttributeParser::parse<SkSVGIntegerType>("numOctaves", name, value)) ||
20 this->setSeed(SkSVGAttributeParser::parse<SkSVGNumberType>("seed", name, value)) ||
21 this->setBaseFrequency(SkSVGAttributeParser::parse<SkSVGFeTurbulenceBaseFrequency>(
22 "baseFrequency", name, value)) ||
23 this->setTurbulenceType(SkSVGAttributeParser::parse<SkSVGFeTurbulenceType>(
24 "type", name, value));
25}
26
27template <>
28bool SkSVGAttributeParser::parse<SkSVGFeTurbulenceBaseFrequency>(
30 SkSVGNumberType freqX;
31 if (!this->parse(&freqX)) {
32 return false;
33 }
34
35 SkSVGNumberType freqY;
36 this->parseCommaWspToken();
37 if (this->parse(&freqY)) {
38 *freq = SkSVGFeTurbulenceBaseFrequency(freqX, freqY);
39 } else {
40 *freq = SkSVGFeTurbulenceBaseFrequency(freqX, freqX);
41 }
42
43 return this->parseEOSToken();
44}
45
46template <>
47bool SkSVGAttributeParser::parse<SkSVGFeTurbulenceType>(SkSVGFeTurbulenceType* type) {
48 bool parsedValue = false;
49
50 if (this->parseExpectedStringToken("fractalNoise")) {
52 parsedValue = true;
53 } else if (this->parseExpectedStringToken("turbulence")) {
55 parsedValue = true;
56 }
57
58 return parsedValue && this->parseEOSToken();
59}
60
62 const SkSVGFilterContext& fctx) const {
63 const SkISize* tileSize = nullptr; // TODO: needs filter element subregion properties
64
65 sk_sp<SkShader> shader;
66 switch (fTurbulenceType.fType) {
67 case SkSVGFeTurbulenceType::Type::kTurbulence:
69 fBaseFrequency.freqX(), fBaseFrequency.freqY(), fNumOctaves, fSeed, tileSize);
70 break;
71 case SkSVGFeTurbulenceType::Type::kFractalNoise:
73 fBaseFrequency.freqX(), fBaseFrequency.freqY(), fNumOctaves, fSeed, tileSize);
74 break;
75 }
76
77 return SkImageFilters::Shader(shader, this->resolveFilterSubregion(ctx, fctx));
78}
SkScalar SkSVGNumberType
Definition: SkSVGTypes.h:27
GLenum type
static sk_sp< SkImageFilter > Shader(sk_sp< SkShader > shader, const CropRect &cropRect={})
bool parse(SkSVGIntegerType *v)
bool parseAndSetAttribute(const char *, const char *) override
SkRect resolveFilterSubregion(const SkSVGRenderContext &, const SkSVGFilterContext &) const
Definition: SkSVGFe.cpp:54
bool parseAndSetAttribute(const char *, const char *) override
Definition: SkSVGFe.cpp:93
virtual sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const =0
uint8_t value
SK_API sk_sp< SkShader > MakeTurbulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
SK_API sk_sp< SkShader > MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: SkSize.h:16