Flutter Engine
The Flutter Engine
SkSVGRadialGradient.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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
13
14SkSVGRadialGradient::SkSVGRadialGradient() : INHERITED(SkSVGTag::kRadialGradient) {}
15
18 this->setCx(SkSVGAttributeParser::parse<SkSVGLength>("cx", name, value)) ||
19 this->setCy(SkSVGAttributeParser::parse<SkSVGLength>("cy", name, value)) ||
20 this->setR(SkSVGAttributeParser::parse<SkSVGLength>("r", name, value)) ||
21 this->setFx(SkSVGAttributeParser::parse<SkSVGLength>("fx", name, value)) ||
22 this->setFy(SkSVGAttributeParser::parse<SkSVGLength>("fy", name, value));
23}
24
26 const SkColor4f* colors, const SkScalar* pos,
27 int count, SkTileMode tm,
28 const SkMatrix& m) const {
29 const SkSVGLengthContext lctx =
30 this->getGradientUnits().type() == SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox
31 ? SkSVGLengthContext({1, 1})
32 : ctx.lengthContext();
33
34 const auto r = lctx.resolve(fR , SkSVGLengthContext::LengthType::kOther);
35 const auto center = SkPoint::Make(
38 const auto focal = SkPoint::Make(
40 : center.x(),
41 fFy.isValid() ? lctx.resolve(*fFy, SkSVGLengthContext::LengthType::kVertical)
42 : center.y());
43
44 if (r == 0) {
45 const auto last_color = count > 0 ? colors[count - 1] : SkColors::kBlack;
46 return SkShaders::Color(last_color, nullptr);
47 }
48
49 return center == focal
50 ? SkGradientShader::MakeRadial(center, r, colors, nullptr, pos, count, tm, 0, &m)
52 count, tm, 0, &m);
53}
int count
Definition: FontMgrTest.cpp:50
SkPoint pos
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
SkSVGTag
Definition: SkSVGNode.h:23
SkTileMode
Definition: SkTileMode.h:13
static SkScalar center(float pos0, float pos1)
static sk_sp< SkShader > MakeTwoPointConical(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
bool parseAndSetAttribute(const char *, const char *) override
SkScalar resolve(const SkSVGLength &, LengthType) const
sk_sp< SkShader > onMakeShader(const SkSVGRenderContext &, const SkColor4f *, const SkScalar *, int count, SkTileMode, const SkMatrix &) const override
bool parseAndSetAttribute(const char *, const char *) override
const SkSVGLengthContext & lengthContext() const
float SkScalar
Definition: extension.cpp:12
uint8_t value
constexpr SkColor4f kBlack
Definition: SkColor.h:435
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkShader > Color(SkColor)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173