Skia
2DGraphicsLibrary
|
Shaders specify the source color(s) for what is being drawn. More...
#include <SkShader.h>
Classes | |
struct | AsFPArgs |
struct | ComposeRec |
If the shader subclass is composed of two shaders, return true, and if rec is not NULL, fill it out with info about the shader. More... | |
class | Context |
struct | ContextRec |
ContextRec acts as a parameter bundle for creating Contexts. More... | |
struct | GradientInfo |
Public Types | |
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 &) |
Public Member Functions | |
SkShader (const SkMatrix *localMatrix=NULL) | |
const SkMatrix & | getLocalMatrix () 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... | |
Context * | createContext (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 |
SkImage * | isAImage (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< SkShader > | makeWithLocalMatrix (const SkMatrix &) const |
Return a shader that will apply the specified localMatrix to this shader. More... | |
sk_sp< SkShader > | makeWithColorFilter (sk_sp< SkColorFilter >) const |
Create a new shader that produces the same colors as invoking this shader and then applying the colorfilter. | |
virtual SkShader * | refAsALocalMatrixShader (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... | |
Static Public Member Functions | |
static sk_sp< SkShader > | MakeEmptyShader () |
Call this to create a new "empty" shader, that will not draw anything. | |
static sk_sp< SkShader > | MakeColorShader (SkColor) |
Call this to create a new shader that just draws the specified color. More... | |
static sk_sp< SkShader > | MakeColorShader (const SkColor4f &, sk_sp< SkColorSpace >) |
Create a shader that draws the specified color (in the specified colorspace). More... | |
static sk_sp< SkShader > | MakeComposeShader (sk_sp< SkShader > dst, sk_sp< SkShader > src, SkXfermode::Mode) |
static sk_sp< SkShader > | MakeComposeShader (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< SkShader > | MakeBitmapShader (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< SkShader > | MakePictureShader (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()). | |
bool | computeTotalInverse (const ContextRec &, SkMatrix *totalInverse) const |
virtual Context * | onCreateContext (const ContextRec &, void *storage) const |
Your subclass must also override contextSize() if it overrides onCreateContext(). More... | |
virtual size_t | onContextSize (const ContextRec &) const |
Override this if your subclass overrides createContext, to return the correct size of your subclass' context. | |
virtual bool | onAsLuminanceColor (SkColor *) const |
virtual bool | onIsABitmap (SkBitmap *, SkMatrix *, TileMode[2]) const |
virtual SkImage * | onIsAImage (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 SkFlattenable | INHERITED |
Private Attributes | |
SkMatrix | fLocalMatrix |
Friends | |
class | SkLocalMatrixShader |
class | SkBitmapProcLegacyShader |
Shaders specify the source color(s) for what is being drawn.
If a paint has no shader, then the paint's color is used. If the paint has a shader, then the shader's color(s) are use instead, but they are modulated by the paint's alpha. This makes it easy to create a shader once (e.g. bitmap tiling or gradient) and then change its transparency w/o having to modify the original shader... only the paint's alpha needs to be modified.
enum SkShader::Flags |
If the shader subclass can be represented as a gradient, asAGradient returns the matching GradientType enum (or kNone_GradientType if it cannot).
Also, if info is not null, asAGradient populates info with the relevant (see below) parameters for the gradient. fColorCount is both an input and output parameter. On input, it indicates how many entries in fColors and fColorOffsets can be used, if they are non-NULL. After asAGradient has run, fColorCount indicates how many color-offset pairs there are in the gradient. If there is insufficient space to store all of the color-offset pairs, fColors and fColorOffsets will not be altered. fColorOffsets specifies where on the range of 0 to 1 to transition to the given color. The meaning of fPoint and fRadius is dependant on the type of gradient.
None: info is ignored. Color: fColorOffsets[0] is meaningless. Linear: fPoint[0] and fPoint[1] are the end-points of the gradient Radial: fPoint[0] and fRadius[0] are the center and radius Conical: fPoint[0] and fRadius[0] are the center and radius of the 1st circle fPoint[1] and fRadius[1] are the center and radius of the 2nd circle Sweep: fPoint[0] is the center of the sweep.
enum SkShader::TileMode |
|
virtual |
Returns a GrFragmentProcessor that implements the shader for the GPU backend.
NULL is returned if there is no GPU implementation.
The GPU device does not call SkShader::createContext(), instead we pass the view matrix, local matrix, and filter quality directly.
The GrContext may be used by the to create textures that are required by the returned processor.
The returned GrFragmentProcessor should expect an unpremultiplied input color and produce a premultiplied output.
bool SkShader::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.
If it cannot, return false and ignore the color parameter.
Note: if this returns true, the returned color will always be opaque, as only the RGB components are used to compute luminance.
Context* SkShader::createContext | ( | const ContextRec & | , |
void * | storage | ||
) | const |
Create the actual object that does the shading.
Size of storage must be >= contextSize.
|
inline |
Returns the local matrix.
FIXME: This can be incorrect for a Shader with its own local matrix that is also wrapped via CreateLocalMatrixShader.
|
inline |
Returns true if this shader is just a bitmap, and if not null, returns the bitmap, localMatrix, and tilemodes.
If this is not a bitmap, returns false and ignores the out-parameters.
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).
If not, return nullptr.
|
inlinevirtual |
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.
|
static |
Call this to create a new shader that will draw with the specified bitmap.
If the bitmap cannot be used (e.g. has no pixels, or its dimensions exceed implementation limits (currently at 64K - 1)) then SkEmptyShader may be returned.
If the src is kA8_Config then that mask will be colorized using the color on the paint.
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. |
Call this to create a new shader that just draws the specified color.
This should always draw the same as a paint with this color (and no shader).
|
static |
Create a shader that draws the specified color (in the specified colorspace).
This works around the limitation that SkPaint::setColor() only takes byte values, and does not support specific colorspaces.
|
static |
Create a new compose shader, given shaders dst, src, and a combining xfermode mode.
The xfermode is called with the output of the two shaders, and its output is returned. If xfer is null, SkXfermode::kSrcOver_Mode is assumed.
The caller is responsible for managing its reference-count for the xfer (if not null).
|
static |
Call this to create a new shader that will draw with the specified picture.
src | The picture to use inside the shader (if not NULL, its ref count is incremented). The SkPicture must not be changed after successfully creating a picture 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. |
tile | The tile rectangle in picture coordinates: this represents the subset (or superset) of the picture used when building a tile. It is not affected by localMatrix and does not imply scaling (only translation and cropping). If null, the tile rect is considered equal to the picture bounds. |
Return a shader that will apply the specified localMatrix to this shader.
The specified matrix will be applied before any matrix associated with this shader.
|
protectedvirtual |
Your subclass must also override contextSize() if it overrides onCreateContext().
Base class impl returns NULL.
Reimplemented in SkPerlinNoiseShader.
If this shader can be represented by another shader + a localMatrix, return that shader and, if not NULL, the localMatrix.
If not, return NULL and ignore the localMatrix parameter.
Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility of the caller to balance that with unref() when they are done.