Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkTransformShader Class Reference

#include <SkTransformShader.h>

Inheritance diagram for SkTransformShader:
SkShaderBase SkShader SkFlattenable SkRefCnt SkRefCntBase

Public Member Functions

 SkTransformShader (const SkShaderBase &shader, bool allowPerspective)
 
bool appendStages (const SkStageRec &rec, const SkShaders::MatrixRec &) const override
 
bool update (const SkMatrix &matrix)
 
ShaderType type () const override
 
Factory getFactory () const override
 
const char * getTypeName () const override
 
bool isOpaque () const override
 
- 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
 

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

Detailed Description

Definition at line 23 of file SkTransformShader.h.

Constructor & Destructor Documentation

◆ SkTransformShader()

SkTransformShader::SkTransformShader ( const SkShaderBase shader,
bool  allowPerspective 
)
explicit

Definition at line 17 of file SkTransformShader.cpp.

18 : fShader{shader}, fAllowPerspective{allowPerspective} {
19 SkMatrix::I().get9(fMatrixStorage);
20}
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void get9(SkScalar buffer[9]) const
Definition: SkMatrix.h:584

Member Function Documentation

◆ appendStages()

bool SkTransformShader::appendStages ( const SkStageRec ,
const SkShaders::MatrixRec  
) const
overridevirtual

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 31 of file SkTransformShader.cpp.

32 {
33 // We have to seed and apply any constant matrices before appending our matrix that may
34 // mutate. We could try to add one matrix stage and then incorporate the parent matrix
35 // with the variable matrix in each call to update(). However, in practice our callers
36 // fold the CTM into the update() matrix and don't wrap the transform shader in local matrix
37 // shaders so the call to apply below should just seed the coordinates. If this assert fires
38 // it just indicates an optimization opportunity, not a correctness bug.
39 SkASSERT(!mRec.hasPendingMatrix());
40 std::optional<SkShaders::MatrixRec> childMRec = mRec.apply(rec);
41 if (!childMRec.has_value()) {
42 return false;
43 }
44 // The matrix we're about to insert gets updated between uses of the pipeline so our children
45 // can't know the total transform when they add their stages. We don't even incorporate this
46 // matrix into the SkShaders::MatrixRec at all.
47 childMRec->markTotalMatrixInvalid();
48
49 auto type = fAllowPerspective ? SkRasterPipelineOp::matrix_perspective
50 : SkRasterPipelineOp::matrix_2x3;
51 rec.fPipeline->append(type, fMatrixStorage);
52
53 fShader.appendStages(rec, *childMRec);
54 return true;
55}
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual bool appendStages(const SkStageRec &, const SkShaders::MatrixRec &) const =0
ShaderType type() const override

◆ getFactory()

Factory SkTransformShader::getFactory ( ) const
inlineoverridevirtual

Implement this to return a factory function pointer that can be called to recreate your class given a buffer (previously written to by your override of flatten().

Implements SkFlattenable.

Definition at line 37 of file SkTransformShader.h.

37 {
38 SkDEBUGFAIL("SkTransformShader shouldn't be serialized.");
39 return {};
40 }
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118

◆ getTypeName()

const char * SkTransformShader::getTypeName ( ) const
inlineoverridevirtual

Returns the name of the object's class.

Implements SkFlattenable.

Definition at line 41 of file SkTransformShader.h.

41 {
42 SkDEBUGFAIL("SkTransformShader shouldn't be serialized.");
43 return nullptr;
44 }

◆ isOpaque()

bool SkTransformShader::isOpaque ( ) const
inlineoverridevirtual

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 46 of file SkTransformShader.h.

46{ return fShader.isOpaque(); }
virtual bool isOpaque() const
Definition: SkShader.h:44

◆ type()

ShaderType SkTransformShader::type ( ) const
inlineoverridevirtual

Implements SkShaderBase.

Definition at line 34 of file SkTransformShader.h.

34{ return ShaderType::kTransform; }

◆ update()

bool SkTransformShader::update ( const SkMatrix matrix)

Definition at line 22 of file SkTransformShader.cpp.

22 {
23 if (!fAllowPerspective && matrix.hasPerspective()) {
24 return false;
25 }
26
27 matrix.get9(fMatrixStorage);
28 return true;
29}
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

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