Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 sk_sp<SkShader> Create(const SkPoint& start,
54 SkScalar startRadius,
55 const SkPoint& end,
56 SkScalar endRadius,
57 const Descriptor&,
58 const SkMatrix* localMatrix);
59
60 GradientType asGradient(GradientInfo* info, SkMatrix* localMatrix) const override;
61 bool isOpaque() const override;
62
63 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
64 SkScalar getStartRadius() const { return fRadius1; }
65 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
66 const SkPoint& getStartCenter() const { return fCenter1; }
67 const SkPoint& getEndCenter() const { return fCenter2; }
68 SkScalar getEndRadius() const { return fRadius2; }
69
70 Type getType() const { return fType; }
71 const FocalData& getFocalData() const { return fFocalData; }
72
73 SkConicalGradient(const SkPoint& c0,
74 SkScalar r0,
75 const SkPoint& c1,
76 SkScalar r1,
77 const Descriptor&,
78 Type,
79 const SkMatrix&,
80 const FocalData&);
81
82protected:
83 void flatten(SkWriteBuffer& buffer) const override;
84
86 SkRasterPipeline* tPipeline,
87 SkRasterPipeline* postPipeline) const override;
88
89private:
90 friend void ::SkRegisterConicalGradientShaderFlattenable();
92
93 SkPoint fCenter1;
94 SkPoint fCenter2;
95 SkScalar fRadius1;
96 SkScalar fRadius2;
97 Type fType;
98
99 FocalData fFocalData;
100};
101
102#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static sk_sp< Effect > Create()
#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
SkScalar getDiffRadius() const
SkScalar getCenterX1() const
void flatten(SkWriteBuffer &buffer) const override
SkScalar getStartRadius() const
GradientType asGradient(GradientInfo *info, SkMatrix *localMatrix) const override
const FocalData & getFocalData() const
void appendGradientStages(SkArenaAlloc *alloc, SkRasterPipeline *tPipeline, SkRasterPipeline *postPipeline) const override
bool isOpaque() const override
float SkScalar
Definition extension.cpp:12
glong glong end
static const uint8_t buffer[]
bool set(SkScalar r0, SkScalar r1, SkMatrix *matrix)
static float Distance(const SkPoint &a, const SkPoint &b)