Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
SkImageShader Class Reference

#include <SkImageShader.h>

Inheritance diagram for SkImageShader:
SkShaderBase SkShader SkFlattenable SkRefCnt SkRefCntBase

Public Member Functions

 SkImageShader (sk_sp< SkImage >, const SkRect &subset, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, bool raw, bool clampAsIfUnpremul)
 
bool isOpaque () const override
 
ShaderType type () const override
 
SkTileMode tileModeX () const
 
SkTileMode tileModeY () const
 
sk_sp< SkImageimage () const
 
SkSamplingOptions sampling () const
 
SkRect subset () const
 
bool isRaw () const
 
- Public Member Functions inherited from SkShaderBase
 ~SkShaderBase () override
 
sk_sp< SkShadermakeInvertAlpha () const
 
sk_sp< SkShadermakeWithCTM (const SkMatrix &) const
 
virtual bool isConstant () const
 
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 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< SkShaderMake (sk_sp< SkImage >, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
 
static sk_sp< SkShaderMakeRaw (sk_sp< SkImage >, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix)
 
static sk_sp< SkShaderMakeSubset (sk_sp< SkImage >, const SkRect &subset, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
 
static SkM44 CubicResamplerMatrix (float B, float C)
 
- 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)
 

Private Member Functions

void flatten (SkWriteBuffer &) const override
 
SkImageonIsAImage (SkMatrix *, SkTileMode *) const override
 
bool appendStages (const SkStageRec &, const SkShaders::MatrixRec &) const override
 

Friends

class SkShaderBase
 

Additional Inherited Members

- 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 &)
 
- Protected Member Functions inherited from SkShaderBase
 SkShaderBase ()
 
void flatten (SkWriteBuffer &) const override
 
virtual bool onAsLuminanceColor (SkColor4f *) const
 

Detailed Description

Definition at line 28 of file SkImageShader.h.

Constructor & Destructor Documentation

◆ SkImageShader()

SkImageShader::SkImageShader ( sk_sp< SkImage img,
const SkRect subset,
SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions sampling,
bool  raw,
bool  clampAsIfUnpremul 
)

Definition at line 95 of file SkImageShader.cpp.

101 : fImage(std::move(img))
102 , fSampling(sampling)
103 , fTileModeX(optimize(tmx, fImage->width()))
104 , fTileModeY(optimize(tmy, fImage->height()))
105 , fSubset(subset)
106 , fRaw(raw)
107 , fClampAsIfUnpremul(clampAsIfUnpremul) {
108 // These options should never appear together:
109 SkASSERT(!fRaw || !fClampAsIfUnpremul);
110
111 // Bicubic filtering of raw image shaders would add a surprising clamp - so we don't support it
112 SkASSERT(!fRaw || !fSampling.useCubic);
113}
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkTileMode optimize(SkTileMode tm, int dimension)
SkSamplingOptions sampling() const
SkRect subset() const
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
SkTileMode tmy
SkTileMode tmx

Member Function Documentation

◆ appendStages()

bool SkImageShader::appendStages ( const SkStageRec ,
const SkShaders::MatrixRec  
) const
overrideprivatevirtual

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 516 of file SkImageShader.cpp.

516 {
517 SkASSERT(!needs_subset(fImage.get(), fSubset)); // TODO(skbug.com/12784)
518
519 // We only support certain sampling options in stages so far
520 auto sampling = fSampling;
521 if (sampling.isAniso()) {
523 }
524
525 SkRasterPipeline* p = rec.fPipeline;
526 SkArenaAlloc* alloc = rec.fAlloc;
527
528 SkMatrix baseInv;
529 // If the total matrix isn't valid then we will always access the base MIP level.
530 if (mRec.totalMatrixIsValid()) {
531 if (!mRec.totalInverse(&baseInv)) {
532 return false;
533 }
534 baseInv.normalizePerspective();
535 }
536
538 auto* access = SkMipmapAccessor::Make(alloc, fImage.get(), baseInv, sampling.mipmap);
539 if (!access) {
540 return false;
541 }
542
543 MipLevelHelper upper;
544 std::tie(upper.pm, upper.inv) = access->level();
545
546 if (!sampling.useCubic) {
547 // TODO: can tweak_sampling sometimes for cubic too when B=0
548 if (mRec.totalMatrixIsValid()) {
549 sampling = tweak_sampling(sampling, SkMatrix::Concat(upper.inv, baseInv));
550 }
551 }
552
553 if (!mRec.apply(rec, upper.inv)) {
554 return false;
555 }
556
557 upper.allocAndInit(alloc, sampling, fTileModeX, fTileModeY);
558
559 MipLevelHelper lower;
560 SkRasterPipeline_MipmapCtx* mipmapCtx = nullptr;
561 float lowerWeight = access->lowerWeight();
562 if (lowerWeight > 0) {
563 std::tie(lower.pm, lower.inv) = access->lowerLevel();
564 mipmapCtx = alloc->make<SkRasterPipeline_MipmapCtx>();
565 mipmapCtx->lowerWeight = lowerWeight;
566 mipmapCtx->scaleX = static_cast<float>(lower.pm.width()) / upper.pm.width();
567 mipmapCtx->scaleY = static_cast<float>(lower.pm.height()) / upper.pm.height();
568
569 lower.allocAndInit(alloc, sampling, fTileModeX, fTileModeY);
570
571 p->append(SkRasterPipelineOp::mipmap_linear_init, mipmapCtx);
572 }
573
574 const bool decalBothAxes = fTileModeX == SkTileMode::kDecal && fTileModeY == SkTileMode::kDecal;
575
576 auto append_tiling_and_gather = [&](const MipLevelHelper* level) {
577 if (decalBothAxes) {
578 p->append(SkRasterPipelineOp::decal_x_and_y, level->decalCtx);
579 } else {
580 switch (fTileModeX) {
581 case SkTileMode::kClamp: /* The gather_xxx stage will clamp for us. */
582 break;
584 p->append(SkRasterPipelineOp::mirror_x, level->limitX);
585 break;
587 p->append(SkRasterPipelineOp::repeat_x, level->limitX);
588 break;
590 p->append(SkRasterPipelineOp::decal_x, level->decalCtx);
591 break;
592 }
593 switch (fTileModeY) {
594 case SkTileMode::kClamp: /* The gather_xxx stage will clamp for us. */
595 break;
597 p->append(SkRasterPipelineOp::mirror_y, level->limitY);
598 break;
600 p->append(SkRasterPipelineOp::repeat_y, level->limitY);
601 break;
603 p->append(SkRasterPipelineOp::decal_y, level->decalCtx);
604 break;
605 }
606 }
607
608 void* ctx = level->gather;
609 switch (level->pm.colorType()) {
610 case kAlpha_8_SkColorType: p->append(SkRasterPipelineOp::gather_a8, ctx); break;
611 case kA16_unorm_SkColorType: p->append(SkRasterPipelineOp::gather_a16, ctx); break;
612 case kA16_float_SkColorType: p->append(SkRasterPipelineOp::gather_af16, ctx); break;
613 case kRGB_565_SkColorType: p->append(SkRasterPipelineOp::gather_565, ctx); break;
614 case kARGB_4444_SkColorType: p->append(SkRasterPipelineOp::gather_4444, ctx); break;
615 case kR8G8_unorm_SkColorType: p->append(SkRasterPipelineOp::gather_rg88, ctx); break;
616 case kR16G16_unorm_SkColorType: p->append(SkRasterPipelineOp::gather_rg1616,ctx); break;
617 case kR16G16_float_SkColorType: p->append(SkRasterPipelineOp::gather_rgf16, ctx); break;
618 case kRGBA_8888_SkColorType: p->append(SkRasterPipelineOp::gather_8888, ctx); break;
619
621 p->append(SkRasterPipelineOp::gather_1010102, ctx);
622 break;
623
625 p->append(SkRasterPipelineOp::gather_16161616, ctx);
626 break;
627
629 case kRGBA_F16_SkColorType: p->append(SkRasterPipelineOp::gather_f16, ctx); break;
630 case kRGBA_F32_SkColorType: p->append(SkRasterPipelineOp::gather_f32, ctx); break;
632 p->append(SkRasterPipelineOp::gather_10101010_xr, ctx);
633 p->append(SkRasterPipelineOp::swap_rb);
634 break;
635 case kRGBA_10x6_SkColorType: p->append(SkRasterPipelineOp::gather_10x6, ctx); break;
636
637 case kGray_8_SkColorType: p->append(SkRasterPipelineOp::gather_a8, ctx);
638 p->append(SkRasterPipelineOp::alpha_to_gray ); break;
639
640 case kR8_unorm_SkColorType: p->append(SkRasterPipelineOp::gather_a8, ctx);
641 p->append(SkRasterPipelineOp::alpha_to_red ); break;
642
643 case kRGB_888x_SkColorType: p->append(SkRasterPipelineOp::gather_8888, ctx);
644 p->append(SkRasterPipelineOp::force_opaque ); break;
645
647 p->append(SkRasterPipelineOp::gather_1010102, ctx);
648 p->append(SkRasterPipelineOp::swap_rb);
649 break;
650
652 p->append(SkRasterPipelineOp::gather_1010102, ctx);
653 p->append(SkRasterPipelineOp::force_opaque);
654 break;
655
657 p->append(SkRasterPipelineOp::gather_1010102_xr, ctx);
658 p->append(SkRasterPipelineOp::force_opaque);
659 p->append(SkRasterPipelineOp::swap_rb);
660 break;
661
663 p->append(SkRasterPipelineOp::gather_1010102, ctx);
664 p->append(SkRasterPipelineOp::force_opaque);
665 p->append(SkRasterPipelineOp::swap_rb);
666 break;
667
669 p->append(SkRasterPipelineOp::gather_8888, ctx);
670 p->append(SkRasterPipelineOp::swap_rb);
671 break;
672
674 p->append(SkRasterPipelineOp::gather_8888, ctx);
675 p->appendTransferFunction(*skcms_sRGB_TransferFunction());
676 break;
677
678 case kUnknown_SkColorType: SkASSERT(false);
679 }
680 if (level->decalCtx) {
681 p->append(SkRasterPipelineOp::check_decal_mask, level->decalCtx);
682 }
683 };
684
685 auto append_misc = [&] {
686 SkColorSpace* cs = upper.pm.colorSpace();
687 SkAlphaType at = upper.pm.alphaType();
688
689 // Color for alpha-only images comes from the paint (already converted to dst color space).
690 // If we were sampled by a runtime effect, the paint color was replaced with transparent
691 // black, so this tinting is effectively suppressed. See also: RuntimeEffectRPCallbacks
692 if (SkColorTypeIsAlphaOnly(upper.pm.colorType()) && !fRaw) {
693 p->appendSetRGB(alloc, rec.fPaintColor);
694
695 cs = rec.fDstCS;
697 }
698
699 // Bicubic filtering naturally produces out of range values on both sides of [0,1].
700 if (sampling.useCubic) {
701 p->append(at == kUnpremul_SkAlphaType || fClampAsIfUnpremul
702 ? SkRasterPipelineOp::clamp_01
703 : SkRasterPipelineOp::clamp_gamut);
704 }
705
706 // Transform color space and alpha type to match shader convention (dst CS, premul alpha).
707 if (!fRaw) {
708 alloc->make<SkColorSpaceXformSteps>(cs, at, rec.fDstCS, kPremul_SkAlphaType)->apply(p);
709 }
710
711 return true;
712 };
713
714 // Check for fast-path stages.
715 // TODO: Could we use the fast-path stages for each level when doing linear mipmap filtering?
716 SkColorType ct = upper.pm.colorType();
717 if (true
721 && fTileModeX == SkTileMode::kClamp && fTileModeY == SkTileMode::kClamp) {
722
723 p->append(SkRasterPipelineOp::bilerp_clamp_8888, upper.gather);
724 if (ct == kBGRA_8888_SkColorType) {
725 p->append(SkRasterPipelineOp::swap_rb);
726 }
727 return append_misc();
728 }
729 if (true
732 && fTileModeX == SkTileMode::kClamp && fTileModeY == SkTileMode::kClamp) {
733
734 p->append(SkRasterPipelineOp::bicubic_clamp_8888, upper.gather);
735 if (ct == kBGRA_8888_SkColorType) {
736 p->append(SkRasterPipelineOp::swap_rb);
737 }
738 return append_misc();
739 }
740
741 // This context can be shared by both levels when doing linear mipmap filtering
743
744 auto sample = [&](SkRasterPipelineOp setup_x,
745 SkRasterPipelineOp setup_y,
746 const MipLevelHelper* level) {
747 p->append(setup_x, sampler);
748 p->append(setup_y, sampler);
749 append_tiling_and_gather(level);
750 p->append(SkRasterPipelineOp::accumulate, sampler);
751 };
752
753 auto sample_level = [&](const MipLevelHelper* level) {
754 if (sampling.useCubic) {
756
757 p->append(SkRasterPipelineOp::bicubic_setup, sampler);
758
759 sample(SkRasterPipelineOp::bicubic_n3x, SkRasterPipelineOp::bicubic_n3y, level);
760 sample(SkRasterPipelineOp::bicubic_n1x, SkRasterPipelineOp::bicubic_n3y, level);
761 sample(SkRasterPipelineOp::bicubic_p1x, SkRasterPipelineOp::bicubic_n3y, level);
762 sample(SkRasterPipelineOp::bicubic_p3x, SkRasterPipelineOp::bicubic_n3y, level);
763
764 sample(SkRasterPipelineOp::bicubic_n3x, SkRasterPipelineOp::bicubic_n1y, level);
765 sample(SkRasterPipelineOp::bicubic_n1x, SkRasterPipelineOp::bicubic_n1y, level);
766 sample(SkRasterPipelineOp::bicubic_p1x, SkRasterPipelineOp::bicubic_n1y, level);
767 sample(SkRasterPipelineOp::bicubic_p3x, SkRasterPipelineOp::bicubic_n1y, level);
768
769 sample(SkRasterPipelineOp::bicubic_n3x, SkRasterPipelineOp::bicubic_p1y, level);
770 sample(SkRasterPipelineOp::bicubic_n1x, SkRasterPipelineOp::bicubic_p1y, level);
771 sample(SkRasterPipelineOp::bicubic_p1x, SkRasterPipelineOp::bicubic_p1y, level);
772 sample(SkRasterPipelineOp::bicubic_p3x, SkRasterPipelineOp::bicubic_p1y, level);
773
774 sample(SkRasterPipelineOp::bicubic_n3x, SkRasterPipelineOp::bicubic_p3y, level);
775 sample(SkRasterPipelineOp::bicubic_n1x, SkRasterPipelineOp::bicubic_p3y, level);
776 sample(SkRasterPipelineOp::bicubic_p1x, SkRasterPipelineOp::bicubic_p3y, level);
777 sample(SkRasterPipelineOp::bicubic_p3x, SkRasterPipelineOp::bicubic_p3y, level);
778
779 p->append(SkRasterPipelineOp::move_dst_src);
780 } else if (sampling.filter == SkFilterMode::kLinear) {
781 p->append(SkRasterPipelineOp::bilinear_setup, sampler);
782
783 sample(SkRasterPipelineOp::bilinear_nx, SkRasterPipelineOp::bilinear_ny, level);
784 sample(SkRasterPipelineOp::bilinear_px, SkRasterPipelineOp::bilinear_ny, level);
785 sample(SkRasterPipelineOp::bilinear_nx, SkRasterPipelineOp::bilinear_py, level);
786 sample(SkRasterPipelineOp::bilinear_px, SkRasterPipelineOp::bilinear_py, level);
787
788 p->append(SkRasterPipelineOp::move_dst_src);
789 } else {
790 append_tiling_and_gather(level);
791 }
792 };
793
794 sample_level(&upper);
795
796 if (mipmapCtx) {
797 p->append(SkRasterPipelineOp::mipmap_linear_update, mipmapCtx);
798 sample_level(&lower);
799 p->append(SkRasterPipelineOp::mipmap_linear_finish, mipmapCtx);
800 }
801
802 return append_misc();
803}
kUnpremul_SkAlphaType
SkAlphaType
Definition SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkColorType
Definition SkColorType.h:19
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition SkColorType.h:50
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
Definition SkColorType.h:33
@ kR8_unorm_SkColorType
Definition SkColorType.h:54
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
Definition SkColorType.h:30
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition SkColorType.h:23
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
Definition SkColorType.h:43
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition SkColorType.h:48
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:29
@ kSRGBA_8888_SkColorType
Definition SkColorType.h:53
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
Definition SkColorType.h:32
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:25
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
Definition SkColorType.h:28
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition SkColorType.h:45
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition SkColorType.h:40
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition SkColorType.h:27
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
Definition SkColorType.h:31
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition SkColorType.h:49
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition SkColorType.h:36
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition SkColorType.h:46
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
static SkSamplingOptions tweak_sampling(SkSamplingOptions sampling, const SkMatrix &matrix)
static bool apply(Pass *pass, SkRecord *record)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
static SkM44 CubicResamplerMatrix(float B, float C)
bool hasMipmaps() const
Definition SkImage.cpp:292
void getColMajor(SkScalar v[]) const
Definition SkM44.h:256
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition SkMatrix.h:1775
void normalizePerspective()
Definition SkMatrix.h:1270
static SkMipmapAccessor * Make(SkArenaAlloc *, const SkImage *, const SkMatrix &inv, SkMipmapMode)
static SkSamplingOptions AnisoFallback(bool imageIsMipped)
T * get() const
Definition SkRefCnt.h:303
const skcms_TransferFunction * skcms_sRGB_TransferFunction()
Definition skcms.cc:1587
const SkCubicResampler cubic
const SkFilterMode filter
const SkMipmapMode mipmap

◆ CubicResamplerMatrix()

SkM44 SkImageShader::CubicResamplerMatrix ( float  B,
float  C 
)
static

Definition at line 48 of file SkImageShader.cpp.

48 {
49#if 0
50 constexpr SkM44 kMitchell = SkM44( 1.f/18.f, -9.f/18.f, 15.f/18.f, -7.f/18.f,
51 16.f/18.f, 0.f/18.f, -36.f/18.f, 21.f/18.f,
52 1.f/18.f, 9.f/18.f, 27.f/18.f, -21.f/18.f,
53 0.f/18.f, 0.f/18.f, -6.f/18.f, 7.f/18.f);
54
55 constexpr SkM44 kCatmull = SkM44(0.0f, -0.5f, 1.0f, -0.5f,
56 1.0f, 0.0f, -2.5f, 1.5f,
57 0.0f, 0.5f, 2.0f, -1.5f,
58 0.0f, 0.0f, -0.5f, 0.5f);
59
60 if (B == 1.0f/3 && C == 1.0f/3) {
61 return kMitchell;
62 }
63 if (B == 0 && C == 0.5f) {
64 return kCatmull;
65 }
66#endif
67 return SkM44( (1.f/6)*B, -(3.f/6)*B - C, (3.f/6)*B + 2*C, - (1.f/6)*B - C,
68 1 - (2.f/6)*B, 0, -3 + (12.f/6)*B + C, 2 - (9.f/6)*B - C,
69 (1.f/6)*B, (3.f/6)*B + C, 3 - (15.f/6)*B - 2*C, -2 + (9.f/6)*B + C,
70 0, 0, -C, (1.f/6)*B + C);
71}
Definition SkM44.h:150

◆ flatten()

void SkImageShader::flatten ( SkWriteBuffer ) const
overrideprivatevirtual

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 169 of file SkImageShader.cpp.

169 {
170 buffer.writeUInt((unsigned)fTileModeX);
171 buffer.writeUInt((unsigned)fTileModeY);
172
173 buffer.writeSampling(fSampling);
174
175 buffer.writeImage(fImage.get());
176 SkASSERT(fClampAsIfUnpremul == false);
177
178 // TODO(skbug.com/12784): Subset is not serialized yet; it's only used by special images so it
179 // will never be written to an SKP.
180 SkASSERT(!needs_subset(fImage.get(), fSubset));
181
182 buffer.writeBool(fRaw);
183}
static const uint8_t buffer[]

◆ image()

sk_sp< SkImage > SkImageShader::image ( ) const
inline

Definition at line 68 of file SkImageShader.h.

68{ return fImage; }

◆ isOpaque()

bool SkImageShader::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 185 of file SkImageShader.cpp.

185 {
186 return fImage->isOpaque() &&
187 fTileModeX != SkTileMode::kDecal && fTileModeY != SkTileMode::kDecal;
188}
bool isOpaque() const
Definition SkImage.h:375

◆ isRaw()

bool SkImageShader::isRaw ( ) const
inline

Definition at line 71 of file SkImageShader.h.

71{ return fRaw; }

◆ Make()

sk_sp< SkShader > SkImageShader::Make ( sk_sp< SkImage image,
SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions options,
const SkMatrix localMatrix,
bool  clampAsIfUnpremul = false 
)
static

Definition at line 301 of file SkImageShader.cpp.

305 {
306 SkRect subset = image ? SkRect::Make(image->dimensions()) : SkRect::MakeEmpty();
307 return MakeSubset(std::move(image), subset, tmx, tmy, options, localMatrix, clampAsIfUnpremul);
308}
const char * options
static sk_sp< SkShader > MakeSubset(sk_sp< SkImage >, const SkRect &subset, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
sk_sp< SkImage > image() const
SkISize dimensions() const
Definition SkImage.h:297
static SkRect Make(const SkISize &size)
Definition SkRect.h:669

◆ MakeRaw()

sk_sp< SkShader > SkImageShader::MakeRaw ( sk_sp< SkImage image,
SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions options,
const SkMatrix localMatrix 
)
static

Definition at line 310 of file SkImageShader.cpp.

313 {
314 if (options.useCubic) {
315 return nullptr;
316 }
317 if (!image) {
318 return SkShaders::Empty();
319 }
321
322 sk_sp<SkShader> s = sk_make_sp<SkImageShader>(image,
323 subset,
324 tmx, tmy,
325 options,
326 /*raw=*/true,
327 /*clampAsIfUnpremul=*/false);
328 return s->makeWithLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I());
329}
struct MyStruct s
Definition SkMD5.cpp:134

◆ MakeSubset()

sk_sp< SkShader > SkImageShader::MakeSubset ( sk_sp< SkImage image,
const SkRect subset,
SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions options,
const SkMatrix localMatrix,
bool  clampAsIfUnpremul = false 
)
static

Definition at line 331 of file SkImageShader.cpp.

336 {
337 auto is_unit = [](float x) {
338 return x >= 0 && x <= 1;
339 };
340 if (options.useCubic) {
341 if (!is_unit(options.cubic.B) || !is_unit(options.cubic.C)) {
342 return nullptr;
343 }
344 }
345 if (!image || subset.isEmpty()) {
346 return SkShaders::Empty();
347 }
348
349 // Validate subset and check if we can drop it
351 return nullptr;
352 }
353
354 sk_sp<SkShader> s = sk_make_sp<SkImageShader>(std::move(image),
355 subset,
356 tmx, tmy,
357 options,
358 /*raw=*/false,
359 clampAsIfUnpremul);
360 return s->makeWithLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I());
361}
SkIRect bounds() const
Definition SkImage.h:303
double x
bool contains(SkScalar x, SkScalar y) const
Definition extension.cpp:19
bool isEmpty() const
Definition SkRect.h:693

◆ onIsAImage()

SkImage * SkImageShader::onIsAImage ( SkMatrix ,
SkTileMode  
) const
overrideprivate

Definition at line 290 of file SkImageShader.cpp.

290 {
291 if (texM) {
292 *texM = SkMatrix::I();
293 }
294 if (xy) {
295 xy[0] = fTileModeX;
296 xy[1] = fTileModeY;
297 }
298 return const_cast<SkImage*>(fImage.get());
299}
static const SkMatrix & I()

◆ sampling()

SkSamplingOptions SkImageShader::sampling ( ) const
inline

Definition at line 69 of file SkImageShader.h.

69{ return fSampling; }

◆ subset()

SkRect SkImageShader::subset ( ) const
inline

Definition at line 70 of file SkImageShader.h.

70{ return fSubset; }

◆ tileModeX()

SkTileMode SkImageShader::tileModeX ( ) const
inline

Definition at line 66 of file SkImageShader.h.

66{ return fTileModeX; }

◆ tileModeY()

SkTileMode SkImageShader::tileModeY ( ) const
inline

Definition at line 67 of file SkImageShader.h.

67{ return fTileModeY; }

◆ type()

ShaderType SkImageShader::type ( ) const
inlineoverridevirtual

Implements SkShaderBase.

Definition at line 62 of file SkImageShader.h.

62{ return ShaderType::kImage; }

Friends And Related Symbol Documentation

◆ SkShaderBase

friend class SkShaderBase
friend

Definition at line 96 of file SkImageShader.h.


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