Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkRadialGradient.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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 */
8
23
24#include <cstdint>
25#include <utility>
26
27class SkArenaAlloc;
28enum class SkTileMode;
29
31 SkScalar inv = SkScalarInvert(radius);
32
33 SkMatrix matrix;
34 matrix.setTranslate(-center.fX, -center.fY);
35 matrix.postScale(inv, inv);
36 return matrix;
37}
38
41 , fCenter(center)
42 , fRadius(radius) {}
43
45 SkMatrix* localMatrix) const {
46 if (info) {
48 info->fPoint[0] = fCenter;
49 info->fRadius[0] = fRadius;
50 }
51 if (localMatrix) {
52 *localMatrix = SkMatrix::I();
53 }
54 return GradientType::kRadial;
55}
56
57sk_sp<SkFlattenable> SkRadialGradient::CreateProc(SkReadBuffer& buffer) {
58 DescriptorScope desc;
59 SkMatrix legacyLocalMatrix, *lmPtr = nullptr;
60 if (!desc.unflatten(buffer, &legacyLocalMatrix)) {
61 return nullptr;
62 }
63 if (!legacyLocalMatrix.isIdentity()) {
64 lmPtr = &legacyLocalMatrix;
65 }
66 const SkPoint center = buffer.readPoint();
67 const SkScalar radius = buffer.readScalar();
69 radius,
70 desc.fColors,
71 std::move(desc.fColorSpace),
72 desc.fPositions,
73 desc.fColorCount,
74 desc.fTileMode,
75 desc.fInterpolation,
76 lmPtr);
77}
78
81 buffer.writePoint(fCenter);
82 buffer.writeScalar(fRadius);
83}
84
86 SkRasterPipeline*) const {
87 p->append(SkRasterPipelineOp::xy_to_radius);
88}
89
91 const SkColor4f colors[],
92 sk_sp<SkColorSpace> colorSpace,
93 const SkScalar pos[],
94 int colorCount,
95 SkTileMode mode,
96 const Interpolation& interpolation,
97 const SkMatrix* localMatrix) {
98 if (radius < 0) {
99 return nullptr;
100 }
101 if (!SkGradientBaseShader::ValidGradient(colors, colorCount, mode, interpolation)) {
102 return nullptr;
103 }
104 if (1 == colorCount) {
105 return SkShaders::Color(colors[0], std::move(colorSpace));
106 }
107 if (localMatrix && !localMatrix->invert(nullptr)) {
108 return nullptr;
109 }
110
112 // Degenerate gradient optimization, and no special logic needed for clamped radial gradient
114 colors, pos, colorCount, std::move(colorSpace), mode);
115 }
116
118 colors, std::move(colorSpace), pos, colorCount, mode, interpolation);
119 return SkLocalMatrixShader::MakeWrapped<SkRadialGradient>(localMatrix, center, radius, desc);
120}
121
123 const SkColor colors[],
124 const SkScalar pos[],
125 int colorCount,
126 SkTileMode mode,
127 uint32_t flags,
128 const SkMatrix* localMatrix) {
129 SkColorConverter converter(colors, colorCount);
130 return MakeRadial(center, radius, converter.fColors4f.begin(), nullptr, pos, colorCount, mode,
131 flags, localMatrix);
132}
133
static SkM44 inv(const SkM44 &m)
Definition 3d.cpp:26
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkPoint pos
uint32_t SkColor
Definition SkColor.h:37
#define SK_REGISTER_FLATTENABLE(type)
static SkMatrix rad_to_unit_matrix(const SkPoint &center, SkScalar radius)
void SkRegisterRadialGradientShaderFlattenable()
#define SkScalarInvert(x)
Definition SkScalar.h:73
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
SkTileMode
Definition SkTileMode.h:13
static SkScalar center(float pos0, float pos1)
static sk_sp< SkShader > MakeRadial()
static constexpr SkScalar kDegenerateThreshold
static bool ValidGradient(const SkColor4f colors[], int count, SkTileMode tileMode, const Interpolation &interpolation)
static sk_sp< SkShader > MakeDegenerateGradient(const SkColor4f colors[], const SkScalar pos[], int colorCount, sk_sp< SkColorSpace > colorSpace, SkTileMode mode)
void flatten(SkWriteBuffer &) const override
void commonAsAGradient(GradientInfo *) const
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 invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206
static const SkMatrix & I()
bool isIdentity() const
Definition SkMatrix.h:223
SkScalar radius() const
void flatten(SkWriteBuffer &buffer) const override
SkRadialGradient(const SkPoint &center, SkScalar radius, const Descriptor &)
void appendGradientStages(SkArenaAlloc *alloc, SkRasterPipeline *tPipeline, SkRasterPipeline *postPipeline) const override
const SkPoint & center() const
GradientType asGradient(GradientInfo *info, SkMatrix *matrix) const override
float SkScalar
Definition extension.cpp:12
FlutterSemanticsFlag flags
static const uint8_t buffer[]