Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkConicalGradient Class Referencefinal

#include <SkConicalGradient.h>

Inheritance diagram for SkConicalGradient:
SkGradientBaseShader SkShaderBase SkShader SkFlattenable SkRefCnt SkRefCntBase

Classes

struct  FocalData
 

Public Types

enum class  Type { kRadial , kStrip , kFocal }
 
- Public Types inherited from SkGradientBaseShader
using Interpolation = SkGradientShader::Interpolation
 
- Public Types inherited from SkShaderBase
enum class  ShaderType { M }
 
enum class  GradientType { kNone , M }
 
enum  Flags { kOpaqueAlpha_Flag = 1 << 0 }
 
- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type , kSkBlender_Type , kSkDrawable_Type , kSkDrawLooper_Type ,
  kSkImageFilter_Type , kSkMaskFilter_Type , kSkPathEffect_Type , kSkShader_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory) (SkReadBuffer &)
 

Public Member Functions

GradientType asGradient (GradientInfo *info, SkMatrix *localMatrix) const override
 
bool isOpaque () const override
 
SkScalar getCenterX1 () const
 
SkScalar getStartRadius () const
 
SkScalar getDiffRadius () const
 
const SkPointgetStartCenter () const
 
const SkPointgetEndCenter () const
 
SkScalar getEndRadius () const
 
Type getType () const
 
const FocalDatagetFocalData () const
 
 SkConicalGradient (const SkPoint &c0, SkScalar r0, const SkPoint &c1, SkScalar r1, const Descriptor &, Type, const SkMatrix &, const FocalData &)
 
- Public Member Functions inherited from SkGradientBaseShader
 SkGradientBaseShader (const Descriptor &desc, const SkMatrix &ptsToUnit)
 
 ~SkGradientBaseShader () override
 
ShaderType type () const final
 
bool isOpaque () const override
 
bool interpolateInPremul () const
 
const SkMatrixgetGradientMatrix () const
 
int getColorCount () const
 
const float * getPositions () const
 
const InterpolationgetInterpolation () const
 
SkScalar getPos (int i) const
 
SkColor getLegacyColor (int i) const
 
bool colorsAreOpaque () const
 
SkTileMode getTileMode () const
 
const SkBitmapcachedBitmap () const
 
void setCachedBitmap (SkBitmap b) const
 
- Public Member Functions inherited from SkShaderBase
 ~SkShaderBase () override
 
sk_sp< SkShadermakeInvertAlpha () const
 
sk_sp< SkShadermakeWithCTM (const SkMatrix &) const
 
virtual bool isConstant () const
 
ContextmakeContext (const ContextRec &, SkArenaAlloc *) const
 
bool asLuminanceColor (SkColor4f *) const
 
bool appendRootStages (const SkStageRec &rec, const SkMatrix &ctm) const
 
virtual SkImageonIsAImage (SkMatrix *, SkTileMode[2]) const
 
virtual SkRuntimeEffectasRuntimeEffect () const
 
Type getFlattenableType () const override
 
virtual sk_sp< SkShadermakeAsALocalMatrixShader (SkMatrix *localMatrix) const
 
- Public Member Functions inherited from SkShader
SkImageisAImage (SkMatrix *localMatrix, SkTileMode xy[2]) const
 
bool isAImage () const
 
sk_sp< SkShadermakeWithLocalMatrix (const SkMatrix &) const
 
sk_sp< SkShadermakeWithColorFilter (sk_sp< SkColorFilter >) const
 
sk_sp< SkShadermakeWithWorkingColorSpace (sk_sp< SkColorSpace >) const
 
- Public Member Functions inherited from SkFlattenable
 SkFlattenable ()
 
virtual Factory getFactory () const =0
 
virtual const char * getTypeName () const =0
 
sk_sp< SkDataserialize (const SkSerialProcs *=nullptr) const
 
size_t serialize (void *memory, size_t memory_size, const SkSerialProcs *=nullptr) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< SkShaderCreate (const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const Descriptor &, const SkMatrix *localMatrix)
 
- Static Public Member Functions inherited from SkGradientBaseShader
static bool ValidGradient (const SkColor4f colors[], int count, SkTileMode tileMode, const Interpolation &interpolation)
 
static sk_sp< SkShaderMakeDegenerateGradient (const SkColor4f colors[], const SkScalar pos[], int colorCount, sk_sp< SkColorSpace > colorSpace, SkTileMode mode)
 
static void AppendGradientFillStages (SkRasterPipeline *p, SkArenaAlloc *alloc, const SkPMColor4f *colors, const SkScalar *positions, int count)
 
static void AppendInterpolatedToDstStages (SkRasterPipeline *p, SkArenaAlloc *alloc, bool colorsAreOpaque, const Interpolation &interpolation, const SkColorSpace *intermediateColorSpace, const SkColorSpace *dstColorSpace)
 
- Static Public Member Functions inherited from SkShaderBase
static Type GetFlattenableType ()
 
static sk_sp< SkShaderBaseDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
static void RegisterFlattenables ()
 
static SkMatrix ConcatLocalMatrices (const SkMatrix &parentLM, const SkMatrix &childLM)
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static void Register (const char name[], Factory)
 
static sk_sp< SkFlattenableDeserialize (Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
 

Protected Member Functions

void flatten (SkWriteBuffer &buffer) const override
 
void appendGradientStages (SkArenaAlloc *alloc, SkRasterPipeline *tPipeline, SkRasterPipeline *postPipeline) const override
 
- Protected Member Functions inherited from SkGradientBaseShader
void flatten (SkWriteBuffer &) const override
 
void commonAsAGradient (GradientInfo *) const
 
bool onAsLuminanceColor (SkColor4f *) const override
 
bool appendStages (const SkStageRec &, const SkShaders::MatrixRec &) const override
 
- Protected Member Functions inherited from SkShaderBase
 SkShaderBase ()
 
void flatten (SkWriteBuffer &) const override
 

Additional Inherited Members

- Public Attributes inherited from SkGradientBaseShader
SkColor4ffColors
 
SkScalarfPositions
 
int fColorCount
 
sk_sp< SkColorSpacefColorSpace
 
Interpolation fInterpolation
 
bool fFirstStopIsImplicit
 
bool fLastStopIsImplicit
 
- Static Public Attributes inherited from SkGradientBaseShader
static constexpr SkScalar kDegenerateThreshold = SK_Scalar1 / (1 << 15)
 
- Protected Attributes inherited from SkGradientBaseShader
const SkMatrix fPtsToUnit
 
SkTileMode fTileMode
 

Detailed Description

Definition at line 24 of file SkConicalGradient.h.

Member Enumeration Documentation

◆ Type

enum class SkConicalGradient::Type
strong
Enumerator
kRadial 
kStrip 
kFocal 

Definition at line 51 of file SkConicalGradient.h.

Constructor & Destructor Documentation

◆ SkConicalGradient()

SkConicalGradient::SkConicalGradient ( const SkPoint c0,
SkScalar  r0,
const SkPoint c1,
SkScalar  r1,
const Descriptor desc,
Type  type,
const SkMatrix gradientMatrix,
const FocalData data 
)

Definition at line 110 of file SkConicalGradient.cpp.

118 : SkGradientBaseShader(desc, gradientMatrix)
119 , fCenter1(start)
120 , fCenter2(end)
121 , fRadius1(startRadius)
122 , fRadius2(endRadius)
123 , fType(type) {
124 // this is degenerate, and should be caught by our caller
125 SkASSERT(fCenter1 != fCenter2 || fRadius1 != fRadius2);
126 if (type == Type::kFocal) {
127 fFocalData = data;
128 }
129}
#define SkASSERT(cond)
Definition SkAssert.h:116
ShaderType type() const final
glong glong end
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

Member Function Documentation

◆ appendGradientStages()

void SkConicalGradient::appendGradientStages ( SkArenaAlloc alloc,
SkRasterPipeline tPipeline,
SkRasterPipeline postPipeline 
) const
overrideprotectedvirtual

Implements SkGradientBaseShader.

Definition at line 192 of file SkConicalGradient.cpp.

194 {
195 const auto dRadius = fRadius2 - fRadius1;
196
197 if (fType == Type::kRadial) {
198 p->append(SkRasterPipelineOp::xy_to_radius);
199
200 // Tiny twist: radial computes a t for [0, r2], but we want a t for [r1, r2].
201 auto scale = std::max(fRadius1, fRadius2) / dRadius;
202 auto bias = -fRadius1 / dRadius;
203
204 p->appendMatrix(alloc, SkMatrix::Translate(bias, 0) * SkMatrix::Scale(scale, 1));
205 return;
206 }
207
208 if (fType == Type::kStrip) {
209 auto* ctx = alloc->make<SkRasterPipeline_2PtConicalCtx>();
210 SkScalar scaledR0 = fRadius1 / this->getCenterX1();
211 ctx->fP0 = scaledR0 * scaledR0;
212 p->append(SkRasterPipelineOp::xy_to_2pt_conical_strip, ctx);
213 p->append(SkRasterPipelineOp::mask_2pt_conical_nan, ctx);
214 postPipeline->append(SkRasterPipelineOp::apply_vector_mask, &ctx->fMask);
215 return;
216 }
217
218 auto* ctx = alloc->make<SkRasterPipeline_2PtConicalCtx>();
219 ctx->fP0 = 1 / fFocalData.fR1;
220 ctx->fP1 = fFocalData.fFocalX;
221
222 if (fFocalData.isFocalOnCircle()) {
223 p->append(SkRasterPipelineOp::xy_to_2pt_conical_focal_on_circle);
224 } else if (fFocalData.isWellBehaved()) {
225 p->append(SkRasterPipelineOp::xy_to_2pt_conical_well_behaved, ctx);
226 } else if (fFocalData.isSwapped() || 1 - fFocalData.fFocalX < 0) {
227 p->append(SkRasterPipelineOp::xy_to_2pt_conical_smaller, ctx);
228 } else {
229 p->append(SkRasterPipelineOp::xy_to_2pt_conical_greater, ctx);
230 }
231
232 if (!fFocalData.isWellBehaved()) {
233 p->append(SkRasterPipelineOp::mask_2pt_conical_degenerates, ctx);
234 }
235 if (1 - fFocalData.fFocalX < 0) {
236 p->append(SkRasterPipelineOp::negate_x);
237 }
238 if (!fFocalData.isNativelyFocal()) {
239 p->append(SkRasterPipelineOp::alter_2pt_conical_compensate_focal, ctx);
240 }
241 if (fFocalData.isSwapped()) {
242 p->append(SkRasterPipelineOp::alter_2pt_conical_unswap);
243 }
244 if (!fFocalData.isWellBehaved()) {
245 postPipeline->append(SkRasterPipelineOp::apply_vector_mask, &ctx->fMask);
246 }
247}
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
SkScalar getCenterX1() const
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
void append(SkRasterPipelineOp, void *=nullptr)
float SkScalar
Definition extension.cpp:12
const Scalar scale

◆ asGradient()

SkShaderBase::GradientType SkConicalGradient::asGradient ( GradientInfo info,
SkMatrix localMatrix 
) const
overridevirtual

Reimplemented from SkShaderBase.

Definition at line 139 of file SkConicalGradient.cpp.

140 {
141 if (info) {
143 info->fPoint[0] = fCenter1;
144 info->fPoint[1] = fCenter2;
145 info->fRadius[0] = fRadius1;
146 info->fRadius[1] = fRadius2;
147 }
148 if (localMatrix) {
149 *localMatrix = SkMatrix::I();
150 }
151 return GradientType::kConical;
152}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
void commonAsAGradient(GradientInfo *) const
static const SkMatrix & I()

◆ Create()

sk_sp< SkShader > SkConicalGradient::Create ( const SkPoint start,
SkScalar  startRadius,
const SkPoint end,
SkScalar  endRadius,
const Descriptor desc,
const SkMatrix localMatrix 
)
static

Definition at line 66 of file SkConicalGradient.cpp.

71 {
72 SkMatrix gradientMatrix;
73 Type gradientType;
74
75 if (SkScalarNearlyZero((c0 - c1).length())) {
76 if (SkScalarNearlyZero(std::max(r0, r1)) || SkScalarNearlyEqual(r0, r1)) {
77 // Degenerate case; avoid dividing by zero. Should have been caught by caller but
78 // just in case, recheck here.
79 return nullptr;
80 }
81 // Concentric case: we can pretend we're radial (with a tiny twist).
82 const SkScalar scale = sk_ieee_float_divide(1, std::max(r0, r1));
83 gradientMatrix = SkMatrix::Translate(-c1.x(), -c1.y());
84 gradientMatrix.postScale(scale, scale);
85
86 gradientType = Type::kRadial;
87 } else {
88 const SkPoint centers[2] = { c0 , c1 };
89 const SkPoint unitvec[2] = { {0, 0}, {1, 0} };
90
91 if (!gradientMatrix.setPolyToPoly(centers, unitvec, 2)) {
92 // Degenerate case.
93 return nullptr;
94 }
95
96 gradientType = SkScalarNearlyZero(r1 - r0) ? Type::kStrip : Type::kFocal;
97 }
98
99 FocalData focalData;
100 if (gradientType == Type::kFocal) {
101 const auto dCenter = (c0 - c1).length();
102 if (!focalData.set(r0 / dCenter, r1 / dCenter, &gradientMatrix)) {
103 return nullptr;
104 }
105 }
106 return SkLocalMatrixShader::MakeWrapped<SkConicalGradient>(
107 localMatrix, c0, r0, c1, r1, desc, gradientType, gradientMatrix, focalData);
108}
static constexpr float sk_ieee_float_divide(float numer, float denom)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:360
bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)
size_t length

◆ flatten()

void SkConicalGradient::flatten ( SkWriteBuffer ) const
overrideprotectedvirtual

Override this if your subclass needs to record data that it will need to recreate itself from its CreateProc (returned by getFactory()).

DEPRECATED public : will move to protected ... use serialize() instead

Reimplemented from SkFlattenable.

Definition at line 184 of file SkConicalGradient.cpp.

184 {
186 buffer.writePoint(fCenter1);
187 buffer.writePoint(fCenter2);
188 buffer.writeScalar(fRadius1);
189 buffer.writeScalar(fRadius2);
190}
void flatten(SkWriteBuffer &) const override
static const uint8_t buffer[]

◆ getCenterX1()

SkScalar SkConicalGradient::getCenterX1 ( ) const
inline

Definition at line 63 of file SkConicalGradient.h.

63{ return SkPoint::Distance(fCenter1, fCenter2); }
static float Distance(const SkPoint &a, const SkPoint &b)

◆ getDiffRadius()

SkScalar SkConicalGradient::getDiffRadius ( ) const
inline

Definition at line 65 of file SkConicalGradient.h.

65{ return fRadius2 - fRadius1; }

◆ getEndCenter()

const SkPoint & SkConicalGradient::getEndCenter ( ) const
inline

Definition at line 67 of file SkConicalGradient.h.

67{ return fCenter2; }

◆ getEndRadius()

SkScalar SkConicalGradient::getEndRadius ( ) const
inline

Definition at line 68 of file SkConicalGradient.h.

68{ return fRadius2; }

◆ getFocalData()

const FocalData & SkConicalGradient::getFocalData ( ) const
inline

Definition at line 71 of file SkConicalGradient.h.

71{ return fFocalData; }

◆ getStartCenter()

const SkPoint & SkConicalGradient::getStartCenter ( ) const
inline

Definition at line 66 of file SkConicalGradient.h.

66{ return fCenter1; }

◆ getStartRadius()

SkScalar SkConicalGradient::getStartRadius ( ) const
inline

Definition at line 64 of file SkConicalGradient.h.

64{ return fRadius1; }

◆ getType()

Type SkConicalGradient::getType ( ) const
inline

Definition at line 70 of file SkConicalGradient.h.

70{ return fType; }

◆ isOpaque()

bool SkConicalGradient::isOpaque ( ) const
overridevirtual

Returns true if the shader is guaranteed to produce only opaque colors, subject to the SkPaint using the shader to apply an opaque alpha value. Subclasses should override this to allow some optimizations.

Reimplemented from SkShader.

Definition at line 131 of file SkConicalGradient.cpp.

131 {
132 // Because areas outside the cone are left untouched, we cannot treat the
133 // shader as opaque even if the gradient itself is opaque.
134 // TODO(junov): Compute whether the cone fills the plane crbug.com/222380
135 return false;
136}

The documentation for this class was generated from the following files: