Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SkGradientBaseShader Class Referenceabstract

#include <SkGradientBaseShader.h>

Inheritance diagram for SkGradientBaseShader:
SkShaderBase SkShader SkFlattenable SkRefCnt SkRefCntBase SkConicalGradient SkLinearGradient SkRadialGradient SkSweepGradient

Classes

struct  Descriptor
 
class  DescriptorScope
 

Public Types

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

 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 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)
 

Public Attributes

SkColor4ffColors
 
SkScalarfPositions
 
int fColorCount
 
sk_sp< SkColorSpacefColorSpace
 
Interpolation fInterpolation
 
bool fFirstStopIsImplicit
 
bool fLastStopIsImplicit
 

Static Public Attributes

static constexpr SkScalar kDegenerateThreshold = SK_Scalar1 / (1 << 15)
 

Protected Member Functions

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
 

Protected Attributes

const SkMatrix fPtsToUnit
 
SkTileMode fTileMode
 

Detailed Description

Definition at line 35 of file SkGradientBaseShader.h.

Member Typedef Documentation

◆ Interpolation

Definition at line 37 of file SkGradientBaseShader.h.

Constructor & Destructor Documentation

◆ SkGradientBaseShader()

SkGradientBaseShader::SkGradientBaseShader ( const Descriptor desc,
const SkMatrix ptsToUnit 
)

Definition at line 178 of file SkGradientBaseShader.cpp.

179 : fPtsToUnit(ptsToUnit)
180 , fColorSpace(desc.fColorSpace ? desc.fColorSpace : SkColorSpace::MakeSRGB())
181 , fFirstStopIsImplicit(false)
182 , fLastStopIsImplicit(false)
183 , fColorsAreOpaque(true) {
184 fPtsToUnit.getType(); // Precache so reads are threadsafe.
185 SkASSERT(desc.fColorCount > 1);
186
187 fInterpolation = desc.fInterpolation;
188
189 SkASSERT((unsigned)desc.fTileMode < kSkTileModeCount);
190 fTileMode = desc.fTileMode;
191
192 /* Note: we let the caller skip the first and/or last position.
193 i.e. pos[0] = 0.3, pos[1] = 0.7
194 In these cases, we insert entries to ensure that the final data
195 will be bracketed by [0, 1].
196 i.e. our_pos[0] = 0, our_pos[1] = 0.3, our_pos[2] = 0.7, our_pos[3] = 1
197
198 Thus colorCount (the caller's value, and fColorCount (our value) may
199 differ by up to 2. In the above example:
200 colorCount = 2
201 fColorCount = 4
202 */
203 fColorCount = desc.fColorCount;
204
205 // Check if we need to add in start and/or end position/colors
206 if (desc.fPositions) {
207 fFirstStopIsImplicit = desc.fPositions[0] > 0;
208 fLastStopIsImplicit = desc.fPositions[desc.fColorCount - 1] != SK_Scalar1;
210 }
211
212 size_t storageSize =
213 fColorCount * (sizeof(SkColor4f) + (desc.fPositions ? sizeof(SkScalar) : 0));
214 fColors = reinterpret_cast<SkColor4f*>(fStorage.reset(storageSize));
215 fPositions = desc.fPositions ? reinterpret_cast<SkScalar*>(fColors + fColorCount) : nullptr;
216
217 // Now copy over the colors, adding the duplicates at t=0 and t=1 as needed
220 *colors++ = desc.fColors[0];
221 }
222 for (int i = 0; i < desc.fColorCount; ++i) {
223 colors[i] = desc.fColors[i];
224 fColorsAreOpaque = fColorsAreOpaque && (desc.fColors[i].fA == 1);
225 }
227 colors += desc.fColorCount;
228 *colors = desc.fColors[desc.fColorCount - 1];
229 }
230
231 if (desc.fPositions) {
232 SkScalar prev = 0;
233 SkScalar* positions = fPositions;
234 *positions++ = prev; // force the first pos to 0
235
236 int startIndex = fFirstStopIsImplicit ? 0 : 1;
237 int count = desc.fColorCount + fLastStopIsImplicit;
238
239 bool uniformStops = true;
240 const SkScalar uniformStep = desc.fPositions[startIndex] - prev;
241 for (int i = startIndex; i < count; i++) {
242 // Pin the last value to 1.0, and make sure pos is monotonic.
243 float curr = 1.0f;
244 if (i != desc.fColorCount) {
245 curr = SkTPin(desc.fPositions[i], prev, 1.0f);
246
247 // If a value is clamped to 1.0 before the last stop, the last stop
248 // actually isn't implicit if we thought it was.
249 if (curr == 1.0f && fLastStopIsImplicit) {
250 fLastStopIsImplicit = false;
251 }
252 }
253
254 uniformStops &= SkScalarNearlyEqual(uniformStep, curr - prev);
255
256 *positions++ = prev = curr;
257 }
258
259 if (uniformStops) {
260 // If the stops are uniform, treat them as implicit.
261 fPositions = nullptr;
262 } else {
263 // Remove duplicate stops with more than two of the same stop,
264 // keeping the leftmost and rightmost stop colors.
265 // i.e. 0, 0, 0, 0.2, 0.2, 0.3, 0.3, 0.3, 1, 1
266 // w/ clamp 0, 0, 0.2, 0.2, 0.3, 0.3, 1, 1
267 // w/o clamp 0, 0.2, 0.2, 0.3, 0.3, 1
268 int i = 0;
269 int dedupedColorCount = 0;
270 for (int j = 1; j <= fColorCount; j++) {
271 // We can compare the current positions at i and j since once these fPosition
272 // values are overwritten, our i and j pointers will be past the overwritten values.
273 if (j == fColorCount || fPositions[i] != fPositions[j]) {
274 bool dupStop = j - i > 1;
275
276 // Ignore the leftmost stop (i) if it is a non-clamp tilemode with
277 // a duplicate stop on t = 0.
278 bool ignoreLeftmost = dupStop && fTileMode != SkTileMode::kClamp
279 && fPositions[i] == 0;
280 if (!ignoreLeftmost) {
281 fPositions[dedupedColorCount] = fPositions[i];
282 fColors[dedupedColorCount] = fColors[i];
283 dedupedColorCount++;
284 }
285
286 // Include the rightmost stop (j-1) only if the stop has a duplicate,
287 // ignoring the rightmost stop if it is a non-clamp tilemode with t = 1.
288 bool ignoreRightmost = fTileMode != SkTileMode::kClamp
289 && fPositions[j - 1] == 1;
290 if (dupStop && !ignoreRightmost) {
291 fPositions[dedupedColorCount] = fPositions[j - 1];
292 fColors[dedupedColorCount] = fColors[j - 1];
293 dedupedColorCount++;
294 }
295 i = j;
296 }
297 }
298 fColorCount = dedupedColorCount;
299 }
300 }
301}
int count
Definition: FontMgrTest.cpp:50
static float prev(float f)
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkRGBA4f< kUnpremul_SkAlphaType > SkColor4f
Definition: SkColor.h:426
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
#define SK_Scalar1
Definition: SkScalar.h:18
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
static constexpr int kSkTileModeCount
Definition: SkTileMode.h:39
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkColorSpace > fColorSpace
TypeMask getType() const
Definition: SkMatrix.h:207
T * reset(size_t count)
Definition: SkTemplates.h:356
float SkScalar
Definition: extension.cpp:12
PODArray< SkColor > colors
Definition: SkRecords.h:276

◆ ~SkGradientBaseShader()

SkGradientBaseShader::~SkGradientBaseShader ( )
override

Definition at line 303 of file SkGradientBaseShader.cpp.

303{}

Member Function Documentation

◆ AppendGradientFillStages()

void SkGradientBaseShader::AppendGradientFillStages ( SkRasterPipeline p,
SkArenaAlloc alloc,
const SkPMColor4f colors,
const SkScalar positions,
int  count 
)
static

Definition at line 372 of file SkGradientBaseShader.cpp.

376 {
377 // The two-stop case with stops at 0 and 1.
378 if (count == 2 && positions == nullptr) {
379 const SkPMColor4f c_l = pmColors[0], c_r = pmColors[1];
380
381 // See F and B below.
383 (skvx::float4::Load(c_r.vec()) - skvx::float4::Load(c_l.vec())).store(ctx->f);
384 (skvx::float4::Load(c_l.vec())).store(ctx->b);
385
386 p->append(SkRasterPipelineOp::evenly_spaced_2_stop_gradient, ctx);
387 } else {
388 auto* ctx = alloc->make<SkRasterPipeline_GradientCtx>();
389
390 // Note: In order to handle clamps in search, the search assumes a stop conceptully placed
391 // at -inf. Therefore, the max number of stops is fColorCount+1.
392 for (int i = 0; i < 4; i++) {
393 // Allocate at least at for the AVX2 gather from a YMM register.
394 ctx->fs[i] = alloc->makeArray<float>(std::max(count + 1, 8));
395 ctx->bs[i] = alloc->makeArray<float>(std::max(count + 1, 8));
396 }
397
398 if (positions == nullptr) {
399 // Handle evenly distributed stops.
400
401 size_t stopCount = count;
402 float gapCount = stopCount - 1;
403
404 SkPMColor4f c_l = pmColors[0];
405 for (size_t i = 0; i < stopCount - 1; i++) {
406 SkPMColor4f c_r = pmColors[i + 1];
407 init_stop_evenly(ctx, gapCount, i, c_l, c_r);
408 c_l = c_r;
409 }
410 add_const_color(ctx, stopCount - 1, c_l);
411
412 ctx->stopCount = stopCount;
413 p->append(SkRasterPipelineOp::evenly_spaced_gradient, ctx);
414 } else {
415 // Handle arbitrary stops.
416
417 ctx->ts = alloc->makeArray<float>(count + 1);
418
419 // Remove the default stops inserted by SkGradientBaseShader::SkGradientBaseShader
420 // because they are naturally handled by the search method.
421 int firstStop;
422 int lastStop;
423 if (count > 2) {
424 firstStop = pmColors[0] != pmColors[1] ? 0 : 1;
425 lastStop = pmColors[count - 2] != pmColors[count - 1] ? count - 1 : count - 2;
426 } else {
427 firstStop = 0;
428 lastStop = 1;
429 }
430
431 size_t stopCount = 0;
432 float t_l = positions[firstStop];
433 SkPMColor4f c_l = pmColors[firstStop];
434 add_const_color(ctx, stopCount++, c_l);
435 // N.B. lastStop is the index of the last stop, not one after.
436 for (int i = firstStop; i < lastStop; i++) {
437 float t_r = positions[i + 1];
438 SkPMColor4f c_r = pmColors[i + 1];
439 SkASSERT(t_l <= t_r);
440 if (t_l < t_r) {
441 float c_scale = sk_ieee_float_divide(1, t_r - t_l);
442 if (SkIsFinite(c_scale)) {
443 init_stop_pos(ctx, stopCount, t_l, c_scale, c_l, c_r);
444 stopCount += 1;
445 }
446 }
447 t_l = t_r;
448 c_l = c_r;
449 }
450
451 ctx->ts[stopCount] = t_l;
452 add_const_color(ctx, stopCount++, c_l);
453
454 ctx->stopCount = stopCount;
455 p->append(SkRasterPipelineOp::gradient, ctx);
456 }
457 }
458}
float c_scale
static bool SkIsFinite(T x, Pack... values)
static constexpr float sk_ieee_float_divide(float numer, float denom)
static void add_const_color(SkRasterPipeline_GradientCtx *ctx, size_t stop, SkPMColor4f color)
static void init_stop_evenly(SkRasterPipeline_GradientCtx *ctx, float gapCount, size_t stop, SkPMColor4f c_l, SkPMColor4f c_r)
static void init_stop_pos(SkRasterPipeline_GradientCtx *ctx, size_t stop, float t_l, float c_scale, SkPMColor4f c_l, SkPMColor4f c_r)
SI void store(P *ptr, const T &val)
T * makeArray(size_t count)
Definition: SkArenaAlloc.h:181
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
static float max(float r, float g, float b)
Definition: hsl.cpp:49
const float * vec() const
Definition: SkColor.h:308
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109

◆ appendGradientStages()

virtual void SkGradientBaseShader::appendGradientStages ( SkArenaAlloc alloc,
SkRasterPipeline tPipeline,
SkRasterPipeline postPipeline 
) const
protectedpure virtual

◆ AppendInterpolatedToDstStages()

void SkGradientBaseShader::AppendInterpolatedToDstStages ( SkRasterPipeline p,
SkArenaAlloc alloc,
bool  colorsAreOpaque,
const Interpolation interpolation,
const SkColorSpace intermediateColorSpace,
const SkColorSpace dstColorSpace 
)
static

Definition at line 460 of file SkGradientBaseShader.cpp.

465 {
467 bool colorIsPremul = static_cast<bool>(interpolation.fInPremul);
468
469 // If we interpolated premul colors in any of the special color spaces, we need to unpremul
470 if (colorIsPremul && !colorsAreOpaque) {
471 switch (interpolation.fColorSpace) {
472 case ColorSpace::kLab:
473 case ColorSpace::kOKLab:
474 case ColorSpace::kOKLabGamutMap:
475 p->append(SkRasterPipelineOp::unpremul);
476 colorIsPremul = false;
477 break;
478 case ColorSpace::kLCH:
479 case ColorSpace::kOKLCH:
480 case ColorSpace::kOKLCHGamutMap:
481 case ColorSpace::kHSL:
482 case ColorSpace::kHWB:
483 p->append(SkRasterPipelineOp::unpremul_polar);
484 colorIsPremul = false;
485 break;
486 default:
487 break;
488 }
489 }
490
491 // Convert colors in exotic spaces back to their intermediate SkColorSpace
492 switch (interpolation.fColorSpace) {
493 case ColorSpace::kLab: p->append(SkRasterPipelineOp::css_lab_to_xyz); break;
494 case ColorSpace::kOKLab: p->append(SkRasterPipelineOp::css_oklab_to_linear_srgb); break;
495 case ColorSpace::kOKLabGamutMap:
496 p->append(SkRasterPipelineOp::css_oklab_gamut_map_to_linear_srgb);
497 break;
498 case ColorSpace::kLCH: p->append(SkRasterPipelineOp::css_hcl_to_lab);
499 p->append(SkRasterPipelineOp::css_lab_to_xyz); break;
500 case ColorSpace::kOKLCH: p->append(SkRasterPipelineOp::css_hcl_to_lab);
501 p->append(SkRasterPipelineOp::css_oklab_to_linear_srgb); break;
502 case ColorSpace::kOKLCHGamutMap:
503 p->append(SkRasterPipelineOp::css_hcl_to_lab);
504 p->append(SkRasterPipelineOp::css_oklab_gamut_map_to_linear_srgb);
505 break;
506 case ColorSpace::kHSL: p->append(SkRasterPipelineOp::css_hsl_to_srgb); break;
507 case ColorSpace::kHWB: p->append(SkRasterPipelineOp::css_hwb_to_srgb); break;
508 default: break;
509 }
510
511 // Now transform from intermediate to destination color space.
512 // See comments in GrGradientShader.cpp about the decisions here.
513 if (!dstColorSpace) {
514 dstColorSpace = sk_srgb_singleton();
515 }
516 SkAlphaType intermediateAlphaType = colorIsPremul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
517 // TODO(skia:13108): Get dst alpha type correctly
518 SkAlphaType dstAlphaType = kPremul_SkAlphaType;
519
520 if (colorsAreOpaque) {
521 intermediateAlphaType = dstAlphaType = kUnpremul_SkAlphaType;
522 }
523
525 intermediateColorSpace, intermediateAlphaType, dstColorSpace, dstAlphaType)
526 ->apply(p);
527}
kUnpremul_SkAlphaType
SkAlphaType
Definition: SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorSpace * sk_srgb_singleton()
static bool apply(Pass *pass, SkRecord *record)
ColorSpace
Definition: image.h:16

◆ appendStages()

bool SkGradientBaseShader::appendStages ( const SkStageRec ,
const SkShaders::MatrixRec  
) const
overrideprotectedvirtual

Adds stages to implement this shader. To ensure that the correct input coords are present in r,g MatrixRec::apply() must be called (unless the shader doesn't require it's input coords). The default impl creates shadercontext and calls that (not very efficient).

Implements SkShaderBase.

Definition at line 529 of file SkGradientBaseShader.cpp.

530 {
531 SkRasterPipeline* p = rec.fPipeline;
532 SkArenaAlloc* alloc = rec.fAlloc;
533 SkRasterPipeline_DecalTileCtx* decal_ctx = nullptr;
534
535 std::optional<SkShaders::MatrixRec> newMRec = mRec.apply(rec, fPtsToUnit);
536 if (!newMRec.has_value()) {
537 return false;
538 }
539
540 SkRasterPipeline_<256> postPipeline;
541
542 this->appendGradientStages(alloc, p, &postPipeline);
543
544 switch (fTileMode) {
546 p->append(SkRasterPipelineOp::mirror_x_1);
547 break;
549 p->append(SkRasterPipelineOp::repeat_x_1);
550 break;
552 decal_ctx = alloc->make<SkRasterPipeline_DecalTileCtx>();
553 decal_ctx->limit_x = SkBits2Float(SkFloat2Bits(1.0f) + 1);
554 // reuse mask + limit_x stage, or create a custom decal_1 that just stores the mask
555 p->append(SkRasterPipelineOp::decal_x, decal_ctx);
556 [[fallthrough]];
557
559 if (!fPositions) {
560 // We clamp only when the stops are evenly spaced.
561 // If not, there may be hard stops, and clamping ruins hard stops at 0 and/or 1.
562 // In that case, we must make sure we're using the general "gradient" stage,
563 // which is the only stage that will correctly handle unclamped t.
564 p->append(SkRasterPipelineOp::clamp_x_1);
565 }
566 break;
567 }
568
569 // Transform all of the colors to destination color space, possibly premultiplied
570 SkColor4fXformer xformedColors(this, rec.fDstCS);
572 xformedColors.fColors.begin(),
573 xformedColors.fPositions,
574 xformedColors.fColors.size());
575 AppendInterpolatedToDstStages(p, alloc, fColorsAreOpaque, fInterpolation,
576 xformedColors.fIntermediateColorSpace.get(), rec.fDstCS);
577
578 if (decal_ctx) {
579 p->append(SkRasterPipelineOp::check_decal_mask, decal_ctx);
580 }
581
582 p->extend(postPipeline);
583
584 return true;
585}
static float SkBits2Float(uint32_t bits)
Definition: SkFloatBits.h:48
static uint32_t SkFloat2Bits(float value)
Definition: SkFloatBits.h:41
virtual void appendGradientStages(SkArenaAlloc *alloc, SkRasterPipeline *tPipeline, SkRasterPipeline *postPipeline) const =0
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)

◆ cachedBitmap()

const SkBitmap & SkGradientBaseShader::cachedBitmap ( ) const
inline

Definition at line 152 of file SkGradientBaseShader.h.

152{ return fColorsAndOffsetsBitmap; }

◆ colorsAreOpaque()

bool SkGradientBaseShader::colorsAreOpaque ( ) const
inline

Definition at line 148 of file SkGradientBaseShader.h.

148{ return fColorsAreOpaque; }

◆ commonAsAGradient()

void SkGradientBaseShader::commonAsAGradient ( GradientInfo info) const
protected

Definition at line 972 of file SkGradientBaseShader.cpp.

972 {
973 if (info) {
974 if (info->fColorCount >= fColorCount) {
975 if (info->fColors) {
976 for (int i = 0; i < fColorCount; ++i) {
977 info->fColors[i] = this->getLegacyColor(i);
978 }
979 }
980 if (info->fColorOffsets) {
981 for (int i = 0; i < fColorCount; ++i) {
982 info->fColorOffsets[i] = this->getPos(i);
983 }
984 }
985 }
986 info->fColorCount = fColorCount;
987 info->fTileMode = fTileMode;
988
989 info->fGradientFlags =
991 }
992}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkColor getLegacyColor(int i) const
SkScalar getPos(int i) const
bool interpolateInPremul() const

◆ flatten()

void SkGradientBaseShader::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.

Reimplemented in SkLinearGradient, SkRadialGradient, and SkSweepGradient.

Definition at line 75 of file SkGradientBaseShader.cpp.

75 {
76 uint32_t flags = 0;
77 if (fPositions) {
79 }
80 sk_sp<SkData> colorSpaceData = fColorSpace ? fColorSpace->serialize() : nullptr;
81 if (colorSpaceData) {
83 }
86 }
87 SkASSERT(static_cast<uint32_t>(fTileMode) <= kTileModeMask_GSF);
88 flags |= ((uint32_t)fTileMode << kTileModeShift_GSF);
93
94 buffer.writeUInt(flags);
95
96 // If we injected implicit first/last stops at construction time, omit those when serializing:
97 int colorCount = fColorCount;
98 const SkColor4f* colors = fColors;
99 const SkScalar* positions = fPositions;
101 colorCount--;
102 colors++;
103 if (positions) {
104 positions++;
105 }
106 }
108 colorCount--;
109 }
110
111 buffer.writeColor4fArray(colors, colorCount);
112 if (colorSpaceData) {
113 buffer.writeDataAsByteArray(colorSpaceData.get());
114 }
115 if (positions) {
116 buffer.writeScalarArray(positions, colorCount);
117 }
118}
@ kHasColorSpace_GSF
@ kTileModeShift_GSF
@ kInterpolationColorSpaceMask_GSF
@ kInterpolationColorSpaceShift_GSF
@ kInterpolationHueMethodShift_GSF
@ kHasPosition_GSF
@ kInterpolationInPremul_GSF
@ kInterpolationHueMethodMask_GSF
@ kTileModeMask_GSF
sk_sp< SkData > serialize() const
T * get() const
Definition: SkRefCnt.h:303
FlutterSemanticsFlag flags
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

◆ getColorCount()

int SkGradientBaseShader::getColorCount ( ) const
inline

Definition at line 81 of file SkGradientBaseShader.h.

81{ return fColorCount; }

◆ getGradientMatrix()

const SkMatrix & SkGradientBaseShader::getGradientMatrix ( ) const
inline

Definition at line 80 of file SkGradientBaseShader.h.

80{ return fPtsToUnit; }

◆ getInterpolation()

const Interpolation & SkGradientBaseShader::getInterpolation ( ) const
inline

Definition at line 83 of file SkGradientBaseShader.h.

83{ return fInterpolation; }

◆ getLegacyColor()

SkColor SkGradientBaseShader::getLegacyColor ( int  i) const
inline

Definition at line 135 of file SkGradientBaseShader.h.

135 {
137 return fColors[i].toSkColor();
138 }

◆ getPos()

SkScalar SkGradientBaseShader::getPos ( int  i) const
inline

Definition at line 130 of file SkGradientBaseShader.h.

130 {
132 return fPositions ? fPositions[i] : SkIntToScalar(i) / (fColorCount - 1);
133 }
#define SkIntToScalar(x)
Definition: SkScalar.h:57

◆ getPositions()

const float * SkGradientBaseShader::getPositions ( ) const
inline

Definition at line 82 of file SkGradientBaseShader.h.

82{ return fPositions; }

◆ getTileMode()

SkTileMode SkGradientBaseShader::getTileMode ( ) const
inline

Definition at line 150 of file SkGradientBaseShader.h.

150{ return fTileMode; }

◆ interpolateInPremul()

bool SkGradientBaseShader::interpolateInPremul ( ) const
inline

◆ isOpaque()

bool SkGradientBaseShader::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 587 of file SkGradientBaseShader.cpp.

587 {
588 return fColorsAreOpaque && (this->getTileMode() != SkTileMode::kDecal);
589}
SkTileMode getTileMode() const

◆ MakeDegenerateGradient()

sk_sp< SkShader > SkGradientBaseShader::MakeDegenerateGradient ( const SkColor4f  colors[],
const SkScalar  pos[],
int  colorCount,
sk_sp< SkColorSpace colorSpace,
SkTileMode  mode 
)
static

Definition at line 1075 of file SkGradientBaseShader.cpp.

1079 {
1080 switch (mode) {
1081 case SkTileMode::kDecal:
1082 // normally this would reject the area outside of the interpolation region, so since
1083 // inside region is empty when the radii are equal, the entire draw region is empty
1084 return SkShaders::Empty();
1087 // repeat and mirror are treated the same: the border colors are never visible,
1088 // but approximate the final color as infinite repetitions of the colors, so
1089 // it can be represented as the average color of the gradient.
1091 std::move(colorSpace));
1092 case SkTileMode::kClamp:
1093 // Depending on how the gradient shape degenerates, there may be a more specialized
1094 // fallback representation for the factories to use, but this is a reasonable default.
1095 return SkShaders::Color(colors[colorCount - 1], std::move(colorSpace));
1096 }
1097 SkDEBUGFAIL("Should not be reached");
1098 return nullptr;
1099}
SkPoint pos
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
static SkColor4f average_gradient_color(const SkColor4f colors[], const SkScalar pos[], int colorCount)
SK_API sk_sp< SkShader > Color(SkColor)
SK_API sk_sp< SkShader > Empty()
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

◆ onAsLuminanceColor()

bool SkGradientBaseShader::onAsLuminanceColor ( SkColor4f lum) const
overrideprotectedvirtual

Reimplemented from SkShaderBase.

Definition at line 591 of file SkGradientBaseShader.cpp.

591 {
592 // We just compute an average color. There are several things we could do better:
593 // 1) We already have a different average_gradient_color helper later in this file, that weights
594 // contribution by the relative size of each band.
595 // 2) Colors should be converted to some standard color space! These could be in any space.
596 // 3) Do we want to average in the source space, sRGB, or some linear space?
597 SkColor4f color{0, 0, 0, 1};
598 for (int i = 0; i < fColorCount; ++i) {
599 color.fR += fColors[i].fR;
600 color.fG += fColors[i].fG;
601 color.fB += fColors[i].fB;
602 }
603 const float scale = 1.0f / fColorCount;
604 color.fR *= scale;
605 color.fG *= scale;
606 color.fB *= scale;
607 *lum = color;
608 return true;
609}
DlColor color
static float lum(float r, float g, float b)
Definition: hsl.cpp:52
const Scalar scale

◆ setCachedBitmap()

void SkGradientBaseShader::setCachedBitmap ( SkBitmap  b) const
inline

Definition at line 153 of file SkGradientBaseShader.h.

153{ fColorsAndOffsetsBitmap = b; }
static bool b

◆ type()

ShaderType SkGradientBaseShader::type ( ) const
inlinefinalvirtual

Implements SkShaderBase.

Definition at line 72 of file SkGradientBaseShader.h.

72{ return ShaderType::kGradientBase; }

◆ ValidGradient()

bool SkGradientBaseShader::ValidGradient ( const SkColor4f  colors[],
int  count,
SkTileMode  tileMode,
const Interpolation interpolation 
)
static

Definition at line 996 of file SkGradientBaseShader.cpp.

999 {
1000 return nullptr != colors && count >= 1 && (unsigned)tileMode < kSkTileModeCount &&
1001 (unsigned)interpolation.fColorSpace < Interpolation::kColorSpaceCount &&
1002 (unsigned)interpolation.fHueMethod < Interpolation::kHueMethodCount;
1003}
static constexpr int kColorSpaceCount
static constexpr int kHueMethodCount

Member Data Documentation

◆ fColorCount

int SkGradientBaseShader::fColorCount

Definition at line 142 of file SkGradientBaseShader.h.

◆ fColors

SkColor4f* SkGradientBaseShader::fColors

Definition at line 140 of file SkGradientBaseShader.h.

◆ fColorSpace

sk_sp<SkColorSpace> SkGradientBaseShader::fColorSpace

Definition at line 143 of file SkGradientBaseShader.h.

◆ fFirstStopIsImplicit

bool SkGradientBaseShader::fFirstStopIsImplicit

Definition at line 145 of file SkGradientBaseShader.h.

◆ fInterpolation

Interpolation SkGradientBaseShader::fInterpolation

Definition at line 144 of file SkGradientBaseShader.h.

◆ fLastStopIsImplicit

bool SkGradientBaseShader::fLastStopIsImplicit

Definition at line 146 of file SkGradientBaseShader.h.

◆ fPositions

SkScalar* SkGradientBaseShader::fPositions

Definition at line 141 of file SkGradientBaseShader.h.

◆ fPtsToUnit

const SkMatrix SkGradientBaseShader::fPtsToUnit
protected

Definition at line 113 of file SkGradientBaseShader.h.

◆ fTileMode

SkTileMode SkGradientBaseShader::fTileMode
protected

Definition at line 114 of file SkGradientBaseShader.h.

◆ kDegenerateThreshold

constexpr SkScalar SkGradientBaseShader::kDegenerateThreshold = SK_Scalar1 / (1 << 15)
staticconstexpr

Definition at line 98 of file SkGradientBaseShader.h.


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