Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPerlinNoiseShader Class Reference

SkPerlinNoiseShader creates an image using the Perlin turbulence function. More...

#include <SkPerlinNoiseShader.h>

Inheritance diagram for SkPerlinNoiseShader:
SkShader SkFlattenable SkRefCnt SkRefCntBase

Classes

class  PerlinNoiseShaderContext
 

Public Types

enum  Type { kFractalNoise_Type, kTurbulence_Type, kFirstType = kFractalNoise_Type, kLastType = kTurbulence_Type }
 About the noise types : the difference between the 2 is just minor tweaks to the algorithm, they're not 2 entirely different noises. More...
 
- Public Types inherited from SkShader
enum  TileMode { kClamp_TileMode, kRepeat_TileMode, kMirror_TileMode }
 
enum  { kTileModeCount = kMirror_TileMode + 1 }
 
enum  Flags { kOpaqueAlpha_Flag = 1 << 0, kConstInY32_Flag = 1 << 1, kPrefers4f_Flag = 1 << 2 }
 
enum  GradientType {
  kNone_GradientType, kColor_GradientType, kLinear_GradientType, kRadial_GradientType,
  kSweep_GradientType, kConical_GradientType, kLast_GradientType = kConical_GradientType
}
 If the shader subclass can be represented as a gradient, asAGradient returns the matching GradientType enum (or kNone_GradientType if it cannot). More...
 
- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type, kSkDrawable_Type, kSkDrawLooper_Type, kSkImageFilter_Type,
  kSkMaskFilter_Type, kSkPathEffect_Type, kSkPixelRef_Type, kSkRasterizer_Type,
  kSkShader_Type, kSkUnused_Type, kSkXfermode_Type, kSkNormalSource_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory )(SkReadBuffer &)
 

Static Public Member Functions

static sk_sp< SkShaderMakeFractalNoise (SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
 This will construct Perlin noise of the given type (Fractal Noise or Turbulence). More...
 
static sk_sp< SkShaderMakeTurbulence (SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
 
- Static Public Member Functions inherited from SkShader
static sk_sp< SkShaderMakeEmptyShader ()
 Call this to create a new "empty" shader, that will not draw anything.
 
static sk_sp< SkShaderMakeColorShader (SkColor)
 Call this to create a new shader that just draws the specified color. More...
 
static sk_sp< SkShaderMakeColorShader (const SkColor4f &, sk_sp< SkColorSpace >)
 Create a shader that draws the specified color (in the specified colorspace). More...
 
static sk_sp< SkShaderMakeComposeShader (sk_sp< SkShader > dst, sk_sp< SkShader > src, SkXfermode::Mode)
 
static sk_sp< SkShaderMakeComposeShader (sk_sp< SkShader > dst, sk_sp< SkShader > src, sk_sp< SkXfermode > xfer)
 Create a new compose shader, given shaders dst, src, and a combining xfermode mode. More...
 
static sk_sp< SkShaderMakeBitmapShader (const SkBitmap &src, TileMode tmx, TileMode tmy, const SkMatrix *localMatrix=nullptr)
 Call this to create a new shader that will draw with the specified bitmap. More...
 
static sk_sp< SkShaderMakePictureShader (sk_sp< SkPicture > src, TileMode tmx, TileMode tmy, const SkMatrix *localMatrix, const SkRect *tile)
 Call this to create a new shader that will draw with the specified picture. More...
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static bool NameToType (const char name[], Type *type)
 
static void Register (const char name[], Factory, Type)
 

Protected Member Functions

void flatten (SkWriteBuffer &) const override
 Override this if your subclass needs to record data that it will need to recreate itself from its CreateProc (returned by getFactory()).
 
ContextonCreateContext (const ContextRec &, void *storage) const override
 Your subclass must also override contextSize() if it overrides onCreateContext(). More...
 
size_t onContextSize (const ContextRec &) const override
 Override this if your subclass overrides createContext, to return the correct size of your subclass' context.
 
- Protected Member Functions inherited from SkShader
bool computeTotalInverse (const ContextRec &, SkMatrix *totalInverse) const
 
virtual bool onAsLuminanceColor (SkColor *) const
 
virtual bool onIsABitmap (SkBitmap *, SkMatrix *, TileMode[2]) const
 
virtual SkImageonIsAImage (SkMatrix *, TileMode[2]) const
 
- Protected Member Functions inherited from SkRefCntBase
void internal_dispose_restore_refcnt_to_1 () const
 Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More...
 

Private Types

typedef SkShader INHERITED
 

Private Member Functions

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

Private Attributes

const SkPerlinNoiseShader::Type fType
 
const SkScalar fBaseFrequencyX
 
const SkScalar fBaseFrequencyY
 
const int fNumOctaves
 
const SkScalar fSeed
 
const SkISize fTileSize
 
const bool fStitchTiles
 

Additional Inherited Members

- Public Member Functions inherited from SkShader
 SkShader (const SkMatrix *localMatrix=NULL)
 
const SkMatrixgetLocalMatrix () const
 Returns the local matrix. More...
 
virtual bool isOpaque () const
 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. More...
 
ContextcreateContext (const ContextRec &, void *storage) const
 Create the actual object that does the shading. More...
 
size_t contextSize (const ContextRec &) const
 Return the size of a Context returned by createContext.
 
bool isABitmap (SkBitmap *outTexture, SkMatrix *outMatrix, TileMode xy[2]) const
 Returns true if this shader is just a bitmap, and if not null, returns the bitmap, localMatrix, and tilemodes. More...
 
bool isABitmap () const
 
SkImageisAImage (SkMatrix *localMatrix, TileMode xy[2]) const
 Iff this shader is backed by a single SkImage, return its ptr (the caller must ref this if they want to keep it longer than the lifetime of the shader). More...
 
bool isAImage () const
 
virtual GradientType asAGradient (GradientInfo *info) const
 
virtual bool asACompose (ComposeRec *) const
 
virtual sk_sp
< GrFragmentProcessor
asFragmentProcessor (const AsFPArgs &) const
 Returns a GrFragmentProcessor that implements the shader for the GPU backend. More...
 
bool asLuminanceColor (SkColor *) const
 If the shader can represent its "average" luminance in a single color, return true and if color is not NULL, return that color. More...
 
sk_sp< SkShadermakeWithLocalMatrix (const SkMatrix &) const
 Return a shader that will apply the specified localMatrix to this shader. More...
 
sk_sp< SkShadermakeWithColorFilter (sk_sp< SkColorFilter >) const
 Create a new shader that produces the same colors as invoking this shader and then applying the colorfilter.
 
virtual SkShaderrefAsALocalMatrixShader (SkMatrix *localMatrix) const
 If this shader can be represented by another shader + a localMatrix, return that shader and, if not NULL, the localMatrix. More...
 
- Public Member Functions inherited from SkFlattenable
virtual Factory getFactory () const =0
 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().
 
virtual const char * getTypeName () const
 Returns the name of the object's class. More...
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 Default construct, initializing the reference count to 1.
 
virtual ~SkRefCntBase ()
 Destruct, asserting that the reference count is 1.
 
int32_t getRefCnt () const
 Return the reference count. More...
 
void validate () const
 
bool unique () const
 May return true if the caller is the only owner. More...
 
void ref () const
 Increment the reference count. More...
 
void unref () const
 Decrement the reference count. More...
 

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

Member Enumeration Documentation

About the noise types : the difference between the 2 is just minor tweaks to the algorithm, they're not 2 entirely different noises.

The output looks different, but once the noise is generated in the [1, -1] range, the output is brought back in the [0, 1] range by doing : kFractalNoise_Type : noise * 0.5 + 0.5 kTurbulence_Type : abs(noise) Very little differences between the 2 types, although you can tell the difference visually.

Member Function Documentation

static sk_sp<SkShader> SkPerlinNoiseShader::MakeFractalNoise ( SkScalar  baseFrequencyX,
SkScalar  baseFrequencyY,
int  numOctaves,
SkScalar  seed,
const SkISize tileSize = nullptr 
)
static

This will construct Perlin noise of the given type (Fractal Noise or Turbulence).

Both base frequencies (X and Y) have a usual range of (0..1).

The number of octaves provided should be fairly small, although no limit is enforced. Each octave doubles the frequency, so 10 octaves would produce noise from baseFrequency * 1, * 2, * 4, ..., * 512, which quickly yields insignificantly small periods and resembles regular unstructured noise rather than Perlin noise.

If tileSize isn't NULL or an empty size, the tileSize parameter will be used to modify the frequencies so that the noise will be tileable for the given tile size. If tileSize is NULL or an empty size, the frequencies will be used as is without modification.

Context* SkPerlinNoiseShader::onCreateContext ( const ContextRec ,
void *  storage 
) const
overrideprotectedvirtual

Your subclass must also override contextSize() if it overrides onCreateContext().

Base class impl returns NULL.

Reimplemented from SkShader.


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