Flutter Engine
The Flutter Engine
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
22
23#include <cstdint>
24#include <utility>
25
26class SkArenaAlloc;
27enum class SkTileMode;
28
30 SkScalar inv = SkScalarInvert(radius);
31
33 matrix.setTranslate(-center.fX, -center.fY);
34 matrix.postScale(inv, inv);
35 return matrix;
36}
37
40 , fCenter(center)
41 , fRadius(radius) {}
42
44 SkMatrix* localMatrix) const {
45 if (info) {
47 info->fPoint[0] = fCenter;
48 info->fRadius[0] = fRadius;
49 }
50 if (localMatrix) {
51 *localMatrix = SkMatrix::I();
52 }
53 return GradientType::kRadial;
54}
55
56sk_sp<SkFlattenable> SkRadialGradient::CreateProc(SkReadBuffer& buffer) {
57 DescriptorScope desc;
58 SkMatrix legacyLocalMatrix, *lmPtr = nullptr;
59 if (!desc.unflatten(buffer, &legacyLocalMatrix)) {
60 return nullptr;
61 }
62 if (!legacyLocalMatrix.isIdentity()) {
63 lmPtr = &legacyLocalMatrix;
64 }
65 const SkPoint center = buffer.readPoint();
66 const SkScalar radius = buffer.readScalar();
68 radius,
69 desc.fColors,
70 std::move(desc.fColorSpace),
71 desc.fPositions,
72 desc.fColorCount,
73 desc.fTileMode,
74 desc.fInterpolation,
75 lmPtr);
76}
77
80 buffer.writePoint(fCenter);
81 buffer.writeScalar(fRadius);
82}
83
85 SkRasterPipeline*) const {
86 p->append(SkRasterPipelineOp::xy_to_radius);
87}
88
90 const SkColor4f colors[],
91 sk_sp<SkColorSpace> colorSpace,
92 const SkScalar pos[],
93 int colorCount,
95 const Interpolation& interpolation,
96 const SkMatrix* localMatrix) {
97 if (radius < 0) {
98 return nullptr;
99 }
100 if (!SkGradientBaseShader::ValidGradient(colors, colorCount, mode, interpolation)) {
101 return nullptr;
102 }
103 if (1 == colorCount) {
104 return SkShaders::Color(colors[0], std::move(colorSpace));
105 }
106 if (localMatrix && !localMatrix->invert(nullptr)) {
107 return nullptr;
108 }
109
111 // Degenerate gradient optimization, and no special logic needed for clamped radial gradient
113 colors, pos, colorCount, std::move(colorSpace), mode);
114 }
115
117 colors, std::move(colorSpace), pos, colorCount, mode, interpolation);
118
119 sk_sp<SkShader> s = sk_make_sp<SkRadialGradient>(center, radius, desc);
120 return s->makeWithLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I());
121}
122
124 const SkColor colors[],
125 const SkScalar pos[],
126 int colorCount,
128 uint32_t flags,
129 const SkMatrix* localMatrix) {
130 SkColorConverter converter(colors, colorCount);
131 return MakeRadial(center, radius, converter.fColors4f.begin(), nullptr, pos, colorCount, mode,
132 flags, localMatrix);
133}
134
137}
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 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()
Definition: SkMatrix.cpp:1544
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
struct MyStruct s
FlutterSemanticsFlag flags
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkShader > Color(SkColor)
string converter
Definition: cacheimages.py:19
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228