SkShader Class Reference

#include <SkShader.h>

Inherits SkFlattenable.

Inherited by SkColorShader, SkComposeShader, SkFilterShader, and SkTransparentShader.

Collaboration diagram for SkShader:
Collaboration graph
[legend]

List of all members.

Public Types

enum  TileMode { kClamp_TileMode, kRepeat_TileMode, kMirror_TileMode, kTileModeCount }
enum  Flags {
  kOpaqueAlpha_Flag = 0x01, kHasSpan16_Flag = 0x02, kIntrinsicly16_Flag = 0x04, kConstInY32_Flag = 0x08,
  kConstInY16_Flag = 0x10
}

Public Member Functions

 SkShader ()
virtual ~SkShader ()
bool getLocalMatrix (SkMatrix *localM) const
void setLocalMatrix (const SkMatrix &localM)
void resetLocalMatrix ()
virtual uint32_t getFlags ()
virtual uint8_t getSpan16Alpha () const
virtual bool setContext (const SkBitmap &device, const SkPaint &paint, const SkMatrix &matrix)
virtual void shadeSpan (int x, int y, SkPMColor[], int count)=0
virtual void shadeSpan16 (int x, int y, uint16_t[], int count)
virtual void shadeSpanAlpha (int x, int y, uint8_t alpha[], int count)
bool canCallShadeSpan16 ()
virtual void beginSession ()
virtual void endSession ()
virtual bool asABitmap (SkBitmap *outTexture, SkMatrix *outMatrix, TileMode xy[2])
virtual void flatten (SkFlattenableWriteBuffer &)

Static Public Member Functions

static bool CanCallShadeSpan16 (uint32_t flags)
static SkShaderCreateBitmapShader (const SkBitmap &src, TileMode tmx, TileMode tmy)

Protected Types

enum  MatrixClass { kLinear_MatrixClass, kFixedStepInX_MatrixClass, kPerspective_MatrixClass }

Protected Member Functions

uint8_t getPaintAlpha () const
SkBitmap::Config getDeviceConfig () const
const SkMatrixgetTotalInverse () const
MatrixClass getInverseClass () const
 SkShader (SkFlattenableReadBuffer &)

Static Protected Member Functions

static MatrixClass ComputeMatrixClass (const SkMatrix &)

Friends

class SkAutoBitmapShaderInstall

Detailed Description

SkShader is the based class for objects that return horizontal spans of colors during drawing. A subclass of SkShader is installed in a SkPaint calling paint.setShader(shader). After that any object (other than a bitmap) that is drawn with that paint will get its color(s) from the shader.

Definition at line 35 of file SkShader.h.


Member Enumeration Documentation

Enumerator:
kOpaqueAlpha_Flag 

set if all of the colors will be opaque

kHasSpan16_Flag 

set if this shader's shadeSpan16() method can be called

kIntrinsicly16_Flag 

Set this bit if the shader's native data type is instrinsically 16 bit, meaning that calling the 32bit shadeSpan() entry point will mean the the impl has to up-sample 16bit data into 32bit. Used as a a means of clearing a dither request if the it will have no effect

kConstInY32_Flag 

set (after setContext) if the spans only vary in X (const in Y). e.g. an Nx1 bitmap that is being tiled in Y, or a linear-gradient that varies from left-to-right. This flag specifies this for shadeSpan().

kConstInY16_Flag 

same as kConstInY32_Flag, but is set if this is true for shadeSpan16 which may not always be the case, since shadeSpan16 may be predithered, which would mean it was not const in Y, even though the 32bit shadeSpan() would be const.

Definition at line 63 of file SkShader.h.

enum SkShader::MatrixClass [protected]
Enumerator:
kLinear_MatrixClass 
kFixedStepInX_MatrixClass 
kPerspective_MatrixClass 

Definition at line 169 of file SkShader.h.

Enumerator:
kClamp_TileMode 

replicate the edge color if the shader draws outside of its original bounds

kRepeat_TileMode 

repeat the shader's image horizontally and vertically

kMirror_TileMode 

repeat the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam

kTileModeCount 

Definition at line 53 of file SkShader.h.


Constructor & Destructor Documentation

SkShader::SkShader (  ) 
virtual SkShader::~SkShader (  )  [virtual]
SkShader::SkShader ( SkFlattenableReadBuffer  )  [protected]

Member Function Documentation

virtual bool SkShader::asABitmap ( SkBitmap outTexture,
SkMatrix outMatrix,
TileMode  xy[2] 
) [virtual]

Optional methods for shaders that can pretend to be a bitmap/texture to play along with opengl. Default just returns false and ignores the out parameters.

virtual void SkShader::beginSession (  )  [virtual]

Called before a session using the shader begins. Some shaders override this to defer some of their work (like calling bitmap.lockPixels()). Must be balanced by a call to endSession.

Reimplemented in SkFilterShader, and SkComposeShader.

static bool SkShader::CanCallShadeSpan16 ( uint32_t  flags  )  [inline, static]

Helper to check the flags to know if it is legal to call shadeSpan16()

Definition at line 137 of file SkShader.h.

bool SkShader::canCallShadeSpan16 (  )  [inline]

Helper function that returns true if this shader's shadeSpan16() method can be called.

Definition at line 131 of file SkShader.h.

static MatrixClass SkShader::ComputeMatrixClass ( const SkMatrix  )  [static, protected]
static SkShader* SkShader::CreateBitmapShader ( const SkBitmap src,
TileMode  tmx,
TileMode  tmy 
) [static]

Call this to create a new shader that will draw with the specified bitmap.

Parameters:
src The bitmap to use inside the shader
tmx The tiling mode to use when sampling the bitmap in the x-direction.
tmy The tiling mode to use when sampling the bitmap in the y-direction.
Returns:
Returns a new shader object. Note: this function never returns null.
virtual void SkShader::endSession (  )  [virtual]

Reimplemented in SkFilterShader, and SkComposeShader.

virtual void SkShader::flatten ( SkFlattenableWriteBuffer  )  [virtual]

Override this to write data specific to your subclass into the buffer, being sure to call your super-class' version first. This data will later be passed to your Factory function, returned by getFactory().

Reimplemented from SkFlattenable.

Reimplemented in SkFilterShader, SkColorShader, SkComposeShader, and SkTransparentShader.

SkBitmap::Config SkShader::getDeviceConfig (  )  const [inline, protected]

Definition at line 178 of file SkShader.h.

virtual uint32_t SkShader::getFlags (  )  [inline, virtual]

Called sometimes before drawing with this shader. Return the type of alpha your shader will return. The default implementation returns 0. Your subclass should override if it can (even sometimes) report a non-zero value, since that will enable various blitters to perform faster.

Reimplemented in SkFilterShader, SkColorShader, and SkTransparentShader.

Definition at line 98 of file SkShader.h.

MatrixClass SkShader::getInverseClass (  )  const [inline, protected]

Definition at line 180 of file SkShader.h.

bool SkShader::getLocalMatrix ( SkMatrix localM  )  const

Return true if the shader has a non-identity local matrix.

Parameters:
localM Optional: If not null, return the shader's local matrix
Returns:
true if the shader has a non-identity local matrix.
uint8_t SkShader::getPaintAlpha (  )  const [inline, protected]

Definition at line 177 of file SkShader.h.

virtual uint8_t SkShader::getSpan16Alpha (  )  const [inline, virtual]

Return the alpha associated with the data returned by shadeSpan16(). If kHasSpan16_Flag is not set, this value is meaningless.

Reimplemented in SkColorShader.

Definition at line 103 of file SkShader.h.

const SkMatrix& SkShader::getTotalInverse (  )  const [inline, protected]

Definition at line 179 of file SkShader.h.

void SkShader::resetLocalMatrix (  ) 

Reset the shader's local matrix to identity.

virtual bool SkShader::setContext ( const SkBitmap device,
const SkPaint paint,
const SkMatrix matrix 
) [virtual]

Called once before drawing, with the current paint and device matrix. Return true if your shader supports these parameters, or false if not. If false is returned, nothing will be drawn.

Reimplemented in SkFilterShader, SkColorShader, SkComposeShader, and SkTransparentShader.

void SkShader::setLocalMatrix ( const SkMatrix localM  ) 

Set the shader's local matrix.

Parameters:
localM The shader's new local matrix.
virtual void SkShader::shadeSpan ( int  x,
int  y,
SkPMColor  [],
int  count 
) [pure virtual]

Called for each span of the object being drawn. Your subclass should set the appropriate colors (with premultiplied alpha) that correspond to the specified device coordinates.

Implemented in SkFilterShader, SkColorShader, SkComposeShader, and SkTransparentShader.

virtual void SkShader::shadeSpan16 ( int  x,
int  y,
uint16_t  [],
int  count 
) [virtual]

Called only for 16bit devices when getFlags() returns kOpaqueAlphaFlag | kHasSpan16_Flag

Reimplemented in SkFilterShader, SkColorShader, and SkTransparentShader.

virtual void SkShader::shadeSpanAlpha ( int  x,
int  y,
uint8_t  alpha[],
int  count 
) [virtual]

Similar to shadeSpan, but only returns the alpha-channel for a span. The default implementation calls shadeSpan() and then extracts the alpha values from the returned colors.

Reimplemented in SkColorShader.


Friends And Related Function Documentation

friend class SkAutoBitmapShaderInstall [friend]

Definition at line 194 of file SkShader.h.


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

Generated on Tue Oct 20 11:03:42 2009 for Skia by  doxygen 1.6.1