Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
16bool SkSVGRadialGradient::parseAndSetAttribute(const char* name, const char* value) {
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)
51 : SkGradientShader::MakeTwoPointConical(focal, 0, center, r, colors, nullptr, pos,
52 count, tm, 0, &m);
53}
int count
SkPoint pos
#define INHERITED(method,...)
SkSVGTag
Definition SkSVGNode.h:23
@ kRadialGradient
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
const char * name
Definition fuchsia.cc:50
constexpr SkColor4f kBlack
Definition SkColor.h:435
static constexpr SkPoint Make(float x, float y)