Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Friends | List of all members
SkPerlinNoiseShader Class Reference

#include <SkPerlinNoiseShaderImpl.h>

Inheritance diagram for SkPerlinNoiseShader:
SkShaderBase SkShader SkFlattenable SkRefCnt SkRefCntBase

Classes

struct  PaintingData
 
struct  StitchData
 

Public Member Functions

 SkPerlinNoiseShader (SkPerlinNoiseShaderType type, SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize)
 
ShaderType type () const override
 
SkPerlinNoiseShaderType noiseType () const
 
int numOctaves () const
 
bool stitchTiles () const
 
SkISize tileSize () const
 
std::unique_ptr< PaintingDatagetPaintingData () const
 
bool appendStages (const SkStageRec &rec, const SkShaders::MatrixRec &mRec) 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
 

Static Public Attributes

static const int kMaxOctaves = 255
 

Protected Member Functions

void flatten (SkWriteBuffer &) const override
 
- Protected Member Functions inherited from SkShaderBase
 SkShaderBase ()
 
void flatten (SkWriteBuffer &) const override
 
virtual bool onAsLuminanceColor (SkColor4f *) const
 

Friends

void SkRegisterPerlinNoiseShaderFlattenable ()
 

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)
 

Detailed Description

SkPerlinNoiseShader creates an image using the Perlin turbulence function.

It can produce tileable noise if asked to stitch tiles and provided a tile size. In order to fill a large area with repeating noise, set the stitchTiles flag to true, and render exactly a single tile of noise. Without this flag, the result will contain visible seams between tiles.

The algorithm used is described here : http://www.w3.org/TR/SVG/filters.html#feTurbulenceElement

Definition at line 34 of file SkPerlinNoiseShaderImpl.h.

Constructor & Destructor Documentation

◆ SkPerlinNoiseShader()

SkPerlinNoiseShader::SkPerlinNoiseShader ( SkPerlinNoiseShaderType  type,
SkScalar  baseFrequencyX,
SkScalar  baseFrequencyY,
int  numOctaves,
SkScalar  seed,
const SkISize tileSize 
)

Definition at line 26 of file SkPerlinNoiseShaderImpl.cpp.

32 : fType(type)
33 , fBaseFrequencyX(baseFrequencyX)
34 , fBaseFrequencyY(baseFrequencyY)
35 , fNumOctaves(numOctaves > kMaxOctaves ? kMaxOctaves
36 : numOctaves) // [0,255] octaves allowed
37 , fSeed(seed)
38 , fTileSize(nullptr == tileSize ? SkISize::Make(0, 0) : *tileSize)
39 , fStitchTiles(!fTileSize.isEmpty()) {
41 SkASSERT(fBaseFrequencyX >= 0);
42 SkASSERT(fBaseFrequencyY >= 0);
43
44 // If kBlockSize changes then it must be changed in the SkSL noise_function
45 // implementation and the graphite backend
46 static_assert(SkPerlinNoiseShader::kBlockSize == 256);
47}
#define SkASSERT(cond)
Definition: SkAssert.h:116
ShaderType type() const override
bool isEmpty() const
Definition: SkSize.h:31
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

Member Function Documentation

◆ appendStages()

bool SkPerlinNoiseShader::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 83 of file SkPerlinNoiseShaderImpl.cpp.

84 {
85 std::optional<SkShaders::MatrixRec> newMRec = mRec.apply(rec);
86 if (!newMRec.has_value()) {
87 return false;
88 }
89
90 fInitPaintingDataOnce([&] {
91 const_cast<SkPerlinNoiseShader*>(this)->fPaintingData = this->getPaintingData();
92 });
93
94 auto* ctx = rec.fAlloc->make<SkRasterPipeline_PerlinNoiseCtx>();
95 ctx->noiseType = fType;
96 ctx->baseFrequencyX = fPaintingData->fBaseFrequency.fX;
97 ctx->baseFrequencyY = fPaintingData->fBaseFrequency.fY;
98 ctx->stitchDataInX = fPaintingData->fStitchDataInit.fWidth;
99 ctx->stitchDataInY = fPaintingData->fStitchDataInit.fHeight;
100 ctx->stitching = fStitchTiles;
101 ctx->numOctaves = fNumOctaves;
102 ctx->latticeSelector = fPaintingData->fLatticeSelector;
103 ctx->noiseData = &fPaintingData->fNoise[0][0][0];
104
105 rec.fPipeline->append(SkRasterPipelineOp::perlin_noise, ctx);
106 return true;
107}
std::unique_ptr< PaintingData > getPaintingData() const

◆ flatten()

void SkPerlinNoiseShader::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 73 of file SkPerlinNoiseShaderImpl.cpp.

73 {
74 buffer.writeInt((int)fType);
75 buffer.writeScalar(fBaseFrequencyX);
76 buffer.writeScalar(fBaseFrequencyY);
77 buffer.writeInt(fNumOctaves);
78 buffer.writeScalar(fSeed);
79 buffer.writeInt(fTileSize.fWidth);
80 buffer.writeInt(fTileSize.fHeight);
81}
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
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

◆ getPaintingData()

std::unique_ptr< PaintingData > SkPerlinNoiseShader::getPaintingData ( ) const
inline

Definition at line 254 of file SkPerlinNoiseShaderImpl.h.

254 {
255 return std::make_unique<PaintingData>(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY);
256 }

◆ noiseType()

SkPerlinNoiseShaderType SkPerlinNoiseShader::noiseType ( ) const
inline

Definition at line 249 of file SkPerlinNoiseShaderImpl.h.

249{ return fType; }

◆ numOctaves()

int SkPerlinNoiseShader::numOctaves ( ) const
inline

Definition at line 250 of file SkPerlinNoiseShaderImpl.h.

250{ return fNumOctaves; }

◆ stitchTiles()

bool SkPerlinNoiseShader::stitchTiles ( ) const
inline

Definition at line 251 of file SkPerlinNoiseShaderImpl.h.

251{ return fStitchTiles; }

◆ tileSize()

SkISize SkPerlinNoiseShader::tileSize ( ) const
inline

Definition at line 252 of file SkPerlinNoiseShaderImpl.h.

252{ return fTileSize; }

◆ type()

ShaderType SkPerlinNoiseShader::type ( ) const
inlineoverridevirtual

Implements SkShaderBase.

Definition at line 247 of file SkPerlinNoiseShaderImpl.h.

247{ return ShaderType::kPerlinNoise; }

Friends And Related Function Documentation

◆ SkRegisterPerlinNoiseShaderFlattenable

void SkRegisterPerlinNoiseShaderFlattenable ( )
friend

Definition at line 128 of file SkPerlinNoiseShaderImpl.cpp.

128 {
130 // Previous name
131 SkFlattenable::Register("SkPerlinNoiseShaderImpl", SkPerlinNoiseShader::CreateProc);
132}
#define SK_REGISTER_FLATTENABLE(type)
static void Register(const char name[], Factory)

Member Data Documentation

◆ kMaxOctaves

const int SkPerlinNoiseShader::kMaxOctaves = 255
static

Definition at line 238 of file SkPerlinNoiseShaderImpl.h.


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