Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
 
virtual ShaderType type () const =0
 
virtual GradientType asGradient (GradientInfo *info=nullptr, SkMatrix *localMatrix=nullptr) const
 
ContextmakeContext (const ContextRec &, SkArenaAlloc *) const
 
bool asLuminanceColor (SkColor4f *) const
 
bool appendRootStages (const SkStageRec &rec, const SkMatrix &ctm) const
 
virtual bool appendStages (const SkStageRec &, const SkShaders::MatrixRec &) const =0
 
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
virtual bool isOpaque () const
 
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
 
virtual void flatten (SkWriteBuffer &) const
 
virtual Type getFlattenableType () 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 bool MapToUnitX (const SkPoint &startCenter, const SkPoint &endCenter, SkMatrix *dstMatrix)
 
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
 
virtual void appendGradientStages (SkArenaAlloc *alloc, SkRasterPipeline *tPipeline, SkRasterPipeline *postPipeline) const =0
 
- Protected Member Functions inherited from SkShaderBase
 SkShaderBase ()
 
void flatten (SkWriteBuffer &) const override
 
virtual bool onAsLuminanceColor (SkColor4f *) const
 

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.

51{ kRadial, kStrip, kFocal };

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 117 of file SkConicalGradient.cpp.

125 : SkGradientBaseShader(desc, gradientMatrix)
126 , fCenter1(start)
127 , fCenter2(end)
128 , fRadius1(startRadius)
129 , fRadius2(endRadius)
130 , fType(type) {
131 // this is degenerate, and should be caught by our caller
132 SkASSERT(fCenter1 != fCenter2 || fRadius1 != fRadius2);
133 if (type == Type::kFocal) {
134 fFocalData = data;
135 }
136}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkGradientBaseShader(const Descriptor &desc, const SkMatrix &ptsToUnit)
ShaderType type() const final
glong glong end
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

Member Function Documentation

◆ appendGradientStages()

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

Implements SkGradientBaseShader.

Definition at line 199 of file SkConicalGradient.cpp.

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

◆ asGradient()

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

Reimplemented from SkShaderBase.

Definition at line 146 of file SkConicalGradient.cpp.

147 {
148 if (info) {
150 info->fPoint[0] = fCenter1;
151 info->fPoint[1] = fCenter2;
152 info->fRadius[0] = fRadius1;
153 info->fRadius[1] = fRadius2;
154 }
155 if (localMatrix) {
156 *localMatrix = SkMatrix::I();
157 }
158 return GradientType::kConical;
159}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
void commonAsAGradient(GradientInfo *) const
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544

◆ 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 74 of file SkConicalGradient.cpp.

79 {
80 SkMatrix gradientMatrix;
81 Type gradientType;
82
83 if (SkScalarNearlyZero((c0 - c1).length())) {
84 if (SkScalarNearlyZero(std::max(r0, r1)) || SkScalarNearlyEqual(r0, r1)) {
85 // Degenerate case; avoid dividing by zero. Should have been caught by caller but
86 // just in case, recheck here.
87 return nullptr;
88 }
89 // Concentric case: we can pretend we're radial (with a tiny twist).
90 const SkScalar scale = sk_ieee_float_divide(1, std::max(r0, r1));
91 gradientMatrix = SkMatrix::Translate(-c1.x(), -c1.y());
92 gradientMatrix.postScale(scale, scale);
93
94 gradientType = Type::kRadial;
95 } else {
96 if (!MapToUnitX(c0, c1, &gradientMatrix)) {
97 // Degenerate case.
98 return nullptr;
99 }
100
101 gradientType = SkScalarNearlyZero(r1 - r0) ? Type::kStrip : Type::kFocal;
102 }
103
104 FocalData focalData;
105 if (gradientType == Type::kFocal) {
106 const auto dCenter = (c0 - c1).length();
107 if (!focalData.set(r0 / dCenter, r1 / dCenter, &gradientMatrix)) {
108 return nullptr;
109 }
110 }
111
112 sk_sp<SkShader> s = sk_make_sp<SkConicalGradient>(
113 c0, r0, c1, r1, desc, gradientType, gradientMatrix, focalData);
114 return s->makeWithLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I());
115}
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
static bool MapToUnitX(const SkPoint &startCenter, const SkPoint &endCenter, SkMatrix *dstMatrix)
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:360
struct MyStruct s
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 191 of file SkConicalGradient.cpp.

191 {
193 buffer.writePoint(fCenter1);
194 buffer.writePoint(fCenter2);
195 buffer.writeScalar(fRadius1);
196 buffer.writeScalar(fRadius2);
197}
void flatten(SkWriteBuffer &) const override
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

◆ getCenterX1()

SkScalar SkConicalGradient::getCenterX1 ( ) const
inline

Definition at line 67 of file SkConicalGradient.h.

67{ return SkPoint::Distance(fCenter1, fCenter2); }
static float Distance(const SkPoint &a, const SkPoint &b)
Definition: SkPoint_impl.h:508

◆ getDiffRadius()

SkScalar SkConicalGradient::getDiffRadius ( ) const
inline

Definition at line 69 of file SkConicalGradient.h.

69{ return fRadius2 - fRadius1; }

◆ getEndCenter()

const SkPoint & SkConicalGradient::getEndCenter ( ) const
inline

Definition at line 71 of file SkConicalGradient.h.

71{ return fCenter2; }

◆ getEndRadius()

SkScalar SkConicalGradient::getEndRadius ( ) const
inline

Definition at line 72 of file SkConicalGradient.h.

72{ return fRadius2; }

◆ getFocalData()

const FocalData & SkConicalGradient::getFocalData ( ) const
inline

Definition at line 75 of file SkConicalGradient.h.

75{ return fFocalData; }

◆ getStartCenter()

const SkPoint & SkConicalGradient::getStartCenter ( ) const
inline

Definition at line 70 of file SkConicalGradient.h.

70{ return fCenter1; }

◆ getStartRadius()

SkScalar SkConicalGradient::getStartRadius ( ) const
inline

Definition at line 68 of file SkConicalGradient.h.

68{ return fRadius1; }

◆ getType()

Type SkConicalGradient::getType ( ) const
inline

Definition at line 74 of file SkConicalGradient.h.

74{ 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 138 of file SkConicalGradient.cpp.

138 {
139 // Because areas outside the cone are left untouched, we cannot treat the
140 // shader as opaque even if the gradient itself is opaque.
141 // TODO(junov): Compute whether the cone fills the plane crbug.com/222380
142 return false;
143}

◆ MapToUnitX()

bool SkConicalGradient::MapToUnitX ( const SkPoint startCenter,
const SkPoint endCenter,
SkMatrix dstMatrix 
)
static

Definition at line 65 of file SkConicalGradient.cpp.

67 {
68 const SkPoint centers[2] = { startCenter, endCenter };
69 const SkPoint unitvec[2] = { {0, 0}, {1, 0} };
70
71 return dstMatrix->setPolyToPoly(centers, unitvec, 2);
72}
bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)
Definition: SkMatrix.cpp:1385

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