Flutter Engine
The Flutter Engine
Public Member Functions | Static Public 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 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 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)
 

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
Definition: SkImageShader.h:69
SkRect subset() const
Definition: SkImageShader.h:70
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
SkTileMode tmy
SkTileMode tmx

Member Function Documentation

◆ 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

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

298 {
299 SkRect subset = image ? SkRect::Make(image->dimensions()) : SkRect::MakeEmpty();
300 return MakeSubset(std::move(image), subset, tmx, tmy, options, localMatrix, clampAsIfUnpremul);
301}
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
Definition: SkImageShader.h:68
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 303 of file SkImageShader.cpp.

306 {
307 if (options.useCubic) {
308 return nullptr;
309 }
310 if (!image) {
311 return SkShaders::Empty();
312 }
314
315 sk_sp<SkShader> s = sk_make_sp<SkImageShader>(image,
316 subset,
317 tmx, tmy,
318 options,
319 /*raw=*/true,
320 /*clampAsIfUnpremul=*/false);
321 return s->makeWithLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I());
322}
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
struct MyStruct s
SK_API sk_sp< SkShader > Empty()

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

329 {
330 auto is_unit = [](float x) {
331 return x >= 0 && x <= 1;
332 };
333 if (options.useCubic) {
334 if (!is_unit(options.cubic.B) || !is_unit(options.cubic.C)) {
335 return nullptr;
336 }
337 }
338 if (!image || subset.isEmpty()) {
339 return SkShaders::Empty();
340 }
341
342 // Validate subset and check if we can drop it
344 return nullptr;
345 }
346
347 sk_sp<SkShader> s = sk_make_sp<SkImageShader>(std::move(image),
348 subset,
349 tmx, tmy,
350 options,
351 /*raw=*/false,
352 clampAsIfUnpremul);
353 return s->makeWithLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I());
354}
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

◆ 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 Function 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: