Flutter Engine
The Flutter Engine
SkConicalGradient.h
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 */
7#ifndef SkConicalGradient_DEFINED
8#define SkConicalGradient_DEFINED
9
15
16class SkArenaAlloc;
17class SkMatrix;
19class SkReadBuffer;
20class SkShader;
21class SkWriteBuffer;
22
23// Please see https://skia.org/dev/design/conical for how our shader works.
25public:
26 // See https://skia.org/dev/design/conical for what focal data means and how our shader works.
27 // We make it public so the GPU shader can also use it.
28 struct FocalData {
29 SkScalar fR1; // r1 after mapping focal point to (0, 0)
31 bool fIsSwapped; // whether we swapped r0, r1
32
33 // The input r0, r1 are the radii when we map centers to {(0, 0), (1, 0)}.
34 // We'll post concat matrix with our transformation matrix that maps focal point to (0, 0).
35 // Returns true if the set succeeded
36 bool set(SkScalar r0, SkScalar r1, SkMatrix* matrix);
37
38 // Whether the focal point (0, 0) is on the end circle with center (1, 0) and radius r1. If
39 // this is true, it's as if an aircraft is flying at Mach 1 and all circles (soundwaves)
40 // will go through the focal point (aircraft). In our previous implementations, this was
41 // known as the edge case where the inside circle touches the outside circle (on the focal
42 // point). If we were to solve for t bruteforcely using a quadratic equation, this case
43 // implies that the quadratic equation degenerates to a linear equation.
44 bool isFocalOnCircle() const { return SkScalarNearlyZero(1 - fR1); }
45
46 bool isSwapped() const { return fIsSwapped; }
47 bool isWellBehaved() const { return !this->isFocalOnCircle() && fR1 > 1; }
48 bool isNativelyFocal() const { return SkScalarNearlyZero(fFocalX); }
49 };
50
51 enum class Type { kRadial, kStrip, kFocal };
52
53 static bool MapToUnitX(const SkPoint& startCenter,
54 const SkPoint& endCenter,
55 SkMatrix* dstMatrix);
56
57 static sk_sp<SkShader> Create(const SkPoint& start,
58 SkScalar startRadius,
59 const SkPoint& end,
60 SkScalar endRadius,
61 const Descriptor&,
62 const SkMatrix* localMatrix);
63
64 GradientType asGradient(GradientInfo* info, SkMatrix* localMatrix) const override;
65 bool isOpaque() const override;
66
67 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
68 SkScalar getStartRadius() const { return fRadius1; }
69 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
70 const SkPoint& getStartCenter() const { return fCenter1; }
71 const SkPoint& getEndCenter() const { return fCenter2; }
72 SkScalar getEndRadius() const { return fRadius2; }
73
74 Type getType() const { return fType; }
75 const FocalData& getFocalData() const { return fFocalData; }
76
77 SkConicalGradient(const SkPoint& c0,
78 SkScalar r0,
79 const SkPoint& c1,
80 SkScalar r1,
81 const Descriptor&,
82 Type,
83 const SkMatrix&,
84 const FocalData&);
85
86protected:
87 void flatten(SkWriteBuffer& buffer) const override;
88
90 SkRasterPipeline* tPipeline,
91 SkRasterPipeline* postPipeline) const override;
92
93private:
96
97 SkPoint fCenter1;
98 SkPoint fCenter2;
99 SkScalar fRadius1;
100 SkScalar fRadius2;
101 Type fType;
102
103 FocalData fFocalData;
104};
105
106#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
void SkRegisterConicalGradientShaderFlattenable()
#define SK_FLATTENABLE_HOOKS(type)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101
const SkPoint & getEndCenter() const
SkScalar getEndRadius() const
const SkPoint & getStartCenter() const
SkConicalGradient(const SkPoint &c0, SkScalar r0, const SkPoint &c1, SkScalar r1, const Descriptor &, Type, const SkMatrix &, const FocalData &)
Type getType() const
SkScalar getDiffRadius() const
SkScalar getCenterX1() const
void flatten(SkWriteBuffer &buffer) const override
SkScalar getStartRadius() const
static bool MapToUnitX(const SkPoint &startCenter, const SkPoint &endCenter, SkMatrix *dstMatrix)
GradientType asGradient(GradientInfo *info, SkMatrix *localMatrix) const override
const FocalData & getFocalData() const
void appendGradientStages(SkArenaAlloc *alloc, SkRasterPipeline *tPipeline, SkRasterPipeline *postPipeline) const override
static sk_sp< SkShader > Create(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const Descriptor &, const SkMatrix *localMatrix)
bool isOpaque() const override
float SkScalar
Definition: extension.cpp:12
glong glong end
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
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
bool set(SkScalar r0, SkScalar r1, SkMatrix *matrix)
static float Distance(const SkPoint &a, const SkPoint &b)
Definition: SkPoint_impl.h:508