Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkImageFilter Class Referenceabstract

Base class for image filters. More...

#include <SkImageFilter.h>

Inheritance diagram for SkImageFilter:
SkFlattenable SkRefCnt SkRefCntBase SkColorFilterImageFilter SkComposeImageFilter SkDisplacementMapEffect SkDropShadowImageFilter SkImageSource SkLightingImageFilter SkMagnifierImageFilter SkMatrixConvolutionImageFilter SkMergeImageFilter SkMorphologyImageFilter SkOffsetImageFilter SkPaintImageFilter SkPictureImageFilter SkTileImageFilter SkXfermodeImageFilter

Classes

class  Common
 
class  Context
 
class  CropRect
 

Public Types

enum  TileUsage { kPossible_TileUsage, kNever_TileUsage }
 
enum  MapDirection { kForward_MapDirection, kReverse_MapDirection }
 
- 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

sk_sp< SkSpecialImage > filterImage (SkSpecialImage *src, const Context &, SkIPoint *offset) const
 Request a new filtered image to be created from the src image. More...
 
SkIRect filterBounds (const SkIRect &src, const SkMatrix &ctm, MapDirection=kReverse_MapDirection) const
 Map a device-space rect recursively forward or backward through the filter DAG. More...
 
bool isColorFilterNode (SkColorFilter **filterPtr) const
 Returns whether this image filter is a color filter and puts the color filter into the "filterPtr" parameter if it can. More...
 
bool asColorFilter (SkColorFilter **filterPtr) const
 
bool asAColorFilter (SkColorFilter **filterPtr) const
 Returns true (and optionally returns a ref'd filter) if this imagefilter can be completely replaced by the returned colorfilter. More...
 
int countInputs () const
 Returns the number of inputs this filter will accept (some inputs can be NULL).
 
SkImageFiltergetInput (int i) const
 Returns the input filter at a given index, or NULL if no input is connected. More...
 
bool cropRectIsSet () const
 Returns whether any edges of the crop rect have been set. More...
 
CropRect getCropRect () const
 
virtual SkRect computeFastBounds (const SkRect &) const
 
bool canComputeFastBounds () const
 
sk_sp< SkImageFiltermakeWithLocalMatrix (const SkMatrix &) const
 If this filter can be represented by another filter + a localMatrix, return that filter, else return null.
 
bool canHandleComplexCTM () const
 ImageFilters can natively handle scaling and translate components in the CTM. 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< SkSpecialImage > DrawWithFP (GrContext *context, sk_sp< GrFragmentProcessor > fp, const SkIRect &bounds, sk_sp< SkColorSpace > colorSpace)
 
static sk_sp< SkImageFilterMakeBlur (SkScalar sigmaX, SkScalar sigmaY, sk_sp< SkImageFilter > input, const CropRect *cropRect=nullptr)
 
static sk_sp< SkImageFilterMakeMatrixFilter (const SkMatrix &matrix, SkFilterQuality quality, sk_sp< SkImageFilter > input)
 Return an imagefilter which transforms its input by the given matrix.
 
- 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

 SkImageFilter (sk_sp< SkImageFilter > *inputs, int inputCount, const CropRect *cropRect)
 
 SkImageFilter (int inputCount, SkReadBuffer &rb)
 Constructs a new SkImageFilter read from an SkReadBuffer object. More...
 
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()).
 
virtual sk_sp< SkSpecialImage > onFilterImage (SkSpecialImage *src, const Context &, SkIPoint *offset) const =0
 This is the virtual which should be overridden by the derived class to perform image filtering. More...
 
virtual SkIRect onFilterBounds (const SkIRect &, const SkMatrix &, MapDirection) const
 This function recurses into its inputs with the given rect (first argument), calls filterBounds() with the given map direction on each, and returns the union of those results. More...
 
virtual SkIRect onFilterNodeBounds (const SkIRect &, const SkMatrix &, MapDirection) const
 Performs a forwards or reverse mapping of the given rect to accommodate this filter's margin requirements. More...
 
sk_sp< SkSpecialImage > filterInput (int index, SkSpecialImage *src, const Context &, SkIPoint *offset) const
 
virtual bool onIsColorFilterNode (SkColorFilter **) const
 Return true (and return a ref'd colorfilter) if this node in the DAG is just a colorfilter w/o CropRect constraints.
 
virtual bool onCanHandleComplexCTM () const
 Override this to describe the behavior of your subclass - as a leaf node. More...
 
bool applyCropRect (const Context &, const SkIRect &srcBounds, SkIRect *dstBounds) const
 Given a "srcBounds" rect, computes destination bounds for this filter. More...
 
sk_sp< SkSpecialImage > applyCropRect (const Context &, SkSpecialImage *src, SkIPoint *srcOffset, SkIRect *bounds) const
 A variant of the above call which takes the original source bitmap and source offset. More...
 
Context mapContext (const Context &ctx) const
 Creates a modified Context for use when recursing up the image filter DAG. More...
 
- 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 Member Functions

void init (sk_sp< SkImageFilter > *inputs, int inputCount, const CropRect *cropRect)
 
bool usesSrcInput () const
 
virtual bool affectsTransparentBlack () const
 

Static Private Member Functions

static void PurgeCache ()
 

Private Attributes

SkAutoSTArray< 2, sk_sp
< SkImageFilter > > 
fInputs
 
bool fUsesSrcInput
 
CropRect fCropRect
 
uint32_t fUniqueID
 
SkTArray< SkImageFilterCacheKey > fCacheKeys
 
SkMutex fMutex
 

Friends

class SkGraphics
 

Detailed Description

Base class for image filters.

If one is installed in the paint, then all drawing occurs as usual, but it is as if the drawing happened into an offscreen (before the xfermode is applied). This offscreen bitmap will then be handed to the imagefilter, who in turn creates a new bitmap which is what will finally be drawn to the device (using the original xfermode).

Member Enumeration Documentation

Enumerator
kPossible_TileUsage 

the created device may be drawn tiled

kNever_TileUsage 

the created device will never be drawn tiled

Constructor & Destructor Documentation

SkImageFilter::SkImageFilter ( int  inputCount,
SkReadBuffer &  rb 
)
explicitprotected

Constructs a new SkImageFilter read from an SkReadBuffer object.

Parameters
inputCountThe exact number of inputs expected for this SkImageFilter object. -1 can be used if the filter accepts any number of inputs.
rbSkReadBuffer object from which the SkImageFilter is read.

Member Function Documentation

bool SkImageFilter::applyCropRect ( const Context ,
const SkIRect srcBounds,
SkIRect dstBounds 
) const
protected

Given a "srcBounds" rect, computes destination bounds for this filter.

"dstBounds" are computed by transforming the crop rect by the context's CTM, applying it to the initial bounds, and intersecting the result with the context's clip bounds. "srcBounds" (if non-null) are computed by intersecting the initial bounds with "dstBounds", to ensure that we never sample outside of the crop rect (this restriction may be relaxed in the future).

sk_sp<SkSpecialImage> SkImageFilter::applyCropRect ( const Context ,
SkSpecialImage *  src,
SkIPoint srcOffset,
SkIRect bounds 
) const
protected

A variant of the above call which takes the original source bitmap and source offset.

If the resulting crop rect is not entirely contained by the source bitmap's bounds, it creates a new bitmap in "result" and pads the edges with transparent black. In that case, the srcOffset is modified to be the same as the bounds, since no further adjustment is needed by the caller. This version should only be used by filters which are not capable of processing a smaller source bitmap into a larger destination.

bool SkImageFilter::asAColorFilter ( SkColorFilter **  filterPtr) const

Returns true (and optionally returns a ref'd filter) if this imagefilter can be completely replaced by the returned colorfilter.

i.e. the two effects will affect drawing in the same way.

bool SkImageFilter::canHandleComplexCTM ( ) const

ImageFilters can natively handle scaling and translate components in the CTM.

Only some of them can handle affine (or more complex) matrices. This call returns true iff the filter and all of its (non-null) inputs can handle these more complex matrices.

bool SkImageFilter::cropRectIsSet ( ) const
inline

Returns whether any edges of the crop rect have been set.

The crop rect is set at construction time, and determines which pixels from the input image will be processed, and which pixels in the output image will be allowed. The size of the crop rect should be used as the size of the destination image. The origin of this rect should be used to offset access to the input images, and should also be added to the "offset" parameter in onFilterImage.

SkIRect SkImageFilter::filterBounds ( const SkIRect src,
const SkMatrix ctm,
MapDirection  = kReverse_MapDirection 
) const

Map a device-space rect recursively forward or backward through the filter DAG.

kForward_MapDirection is used to determine which pixels of the destination canvas a source image rect would touch after filtering. kReverse_MapDirection is used to determine which rect of the source image would be required to fill the given rect (typically, clip bounds). Used for clipping and temp-buffer allocations, so the result need not be exact, but should never be smaller than the real answer. The default implementation recursively unions all input bounds, or returns the source rect if no inputs.

sk_sp<SkSpecialImage> SkImageFilter::filterImage ( SkSpecialImage *  src,
const Context ,
SkIPoint offset 
) const

Request a new filtered image to be created from the src image.

The context contains the environment in which the filter is occurring. It includes the clip bounds, CTM and cache.

Offset is the amount to translate the resulting image relative to the src when it is drawn. This is an out-param.

If the result image cannot be created, or the result would be transparent black, return null, in which case the offset parameter should be ignored by the caller.

TODO: Right now the imagefilters sometimes return empty result bitmaps/ specialimages. That doesn't seem quite right.

SkImageFilter* SkImageFilter::getInput ( int  i) const
inline

Returns the input filter at a given index, or NULL if no input is connected.

The indices used are filter-specific.

bool SkImageFilter::isColorFilterNode ( SkColorFilter **  filterPtr) const
inline

Returns whether this image filter is a color filter and puts the color filter into the "filterPtr" parameter if it can.

Does nothing otherwise. If this returns false, then the filterPtr is unchanged. If this returns true, then if filterPtr is not null, it must be set to a ref'd colorfitler (i.e. it may not be set to NULL).

Context SkImageFilter::mapContext ( const Context ctx) const
protected

Creates a modified Context for use when recursing up the image filter DAG.

The clip bounds are adjusted to accommodate any margins that this filter requires by calling this node's onFilterNodeBounds(..., kReverse_MapDirection).

virtual bool SkImageFilter::onCanHandleComplexCTM ( ) const
inlineprotectedvirtual

Override this to describe the behavior of your subclass - as a leaf node.

The caller will take care of calling your inputs (and return false if any of them could not handle it).

Reimplemented in SkMergeImageFilter, SkColorFilterImageFilter, and SkComposeImageFilter.

virtual SkIRect SkImageFilter::onFilterBounds ( const SkIRect ,
const SkMatrix ,
MapDirection   
) const
protectedvirtual

This function recurses into its inputs with the given rect (first argument), calls filterBounds() with the given map direction on each, and returns the union of those results.

If a derived class has special recursion requirements (e.g., it has an input which does not participate in bounds computation), it can be overridden here.

Note that this function is not responsible for mapping the rect for this node's filter bounds requirements (i.e., calling onFilterNodeBounds()); that is handled by filterBounds().

Reimplemented in SkComposeImageFilter, SkDisplacementMapEffect, and SkTileImageFilter.

virtual sk_sp<SkSpecialImage> SkImageFilter::onFilterImage ( SkSpecialImage *  src,
const Context ,
SkIPoint offset 
) const
protectedpure virtual

This is the virtual which should be overridden by the derived class to perform image filtering.

src is the original primitive bitmap. If the filter has a connected input, it should recurse on that input and use that in place of src.

The matrix is the current matrix on the canvas.

Offset is the amount to translate the resulting image relative to the src when it is drawn. This is an out-param.

If the result image cannot be created (either because of error or if, say, the result is entirely clipped out), this should return nullptr. Callers that affect transparent black should explicitly handle nullptr results and press on. In the error case this behavior will produce a better result than nothing and is necessary for the clipped out case. If the return value is nullptr then offset should be ignored.

Implemented in SkMatrixConvolutionImageFilter, SkPictureImageFilter, SkXfermodeImageFilter, SkDisplacementMapEffect, SkMergeImageFilter, SkDropShadowImageFilter, SkImageSource, SkMorphologyImageFilter, SkPaintImageFilter, SkTileImageFilter, SkMagnifierImageFilter, SkColorFilterImageFilter, SkComposeImageFilter, and SkOffsetImageFilter.

virtual SkIRect SkImageFilter::onFilterNodeBounds ( const SkIRect ,
const SkMatrix ,
MapDirection   
) const
protectedvirtual

Performs a forwards or reverse mapping of the given rect to accommodate this filter's margin requirements.

kForward_MapDirection is used to determine the destination pixels which would be touched by filtering the given given source rect (e.g., given source bitmap bounds, determine the optimal bounds of the filtered offscreen bitmap). kReverse_MapDirection is used to determine which pixels of the input(s) would be required to fill the given destination rect (e.g., clip bounds). NOTE: these operations may not be the inverse of the other. For example, blurring expands the given rect in both forward and reverse directions. Unlike onFilterBounds(), this function is non-recursive.

Reimplemented in SkMatrixConvolutionImageFilter, SkDropShadowImageFilter, SkDisplacementMapEffect, SkOffsetImageFilter, SkTileImageFilter, and SkMorphologyImageFilter.


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