Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
SkImageFilter Class Reference

#include <SkImageFilter.h>

Inheritance diagram for SkImageFilter:
SkFlattenable SkRefCnt SkRefCntBase SkImageFilter_Base SkLocalMatrixImageFilter SkRuntimeImageFilter

Public Types

enum  MapDirection { kForward_MapDirection , kReverse_MapDirection }
 
- 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 &)
 

Public Member Functions

SkIRect filterBounds (const SkIRect &src, const SkMatrix &ctm, MapDirection, const SkIRect *inputRect=nullptr) const
 
bool isColorFilterNode (SkColorFilter **filterPtr) const
 
bool asColorFilter (SkColorFilter **filterPtr) const
 
bool asAColorFilter (SkColorFilter **filterPtr) const
 
int countInputs () const
 
const SkImageFiltergetInput (int i) const
 
virtual SkRect computeFastBounds (const SkRect &bounds) const
 
bool canComputeFastBounds () const
 
sk_sp< SkImageFiltermakeWithLocalMatrix (const SkMatrix &matrix) 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 Member Functions

static sk_sp< SkImageFilterDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
- 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)
 

Protected Member Functions

sk_sp< SkImageFilterrefMe () const
 

Friends

class SkImageFilter_Base
 

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).

The local space of image filters matches the local space of the drawn geometry. For instance if there is rotation on the canvas, the blur will be computed along those rotated axes and not in the device space. In order to achieve this result, the actual drawing of the geometry may happen in an unrotated coordinate system so that the filtered image can be computed more easily, and then it will be post transformed to match what would have been produced if the geometry were drawn with the total canvas matrix to begin with.

Definition at line 35 of file SkImageFilter.h.

Member Enumeration Documentation

◆ MapDirection

Enumerator
kForward_MapDirection 
kReverse_MapDirection 

Definition at line 37 of file SkImageFilter.h.

Member Function Documentation

◆ asAColorFilter()

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.

Definition at line 118 of file SkImageFilter.cpp.

118 {
119 SkASSERT(nullptr != filterPtr);
120 if (!this->isColorFilterNode(filterPtr)) {
121 return false;
122 }
123 if (nullptr != this->getInput(0) || as_CFB(*filterPtr)->affectsTransparentBlack()) {
124 (*filterPtr)->unref();
125 return false;
126 }
127 return true;
128}
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkColorFilterBase * as_CFB(SkColorFilter *filter)
bool affectsTransparentBlack() const
bool isColorFilterNode(SkColorFilter **filterPtr) const
const SkImageFilter * getInput(int i) const

◆ asColorFilter()

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

Definition at line 67 of file SkImageFilter.h.

67 {
68 return this->isColorFilterNode(filterPtr);
69 }

◆ canComputeFastBounds()

bool SkImageFilter::canComputeFastBounds ( ) const

Definition at line 98 of file SkImageFilter.cpp.

98 {
99 return !as_IFB(this)->affectsTransparentBlack();
100}
static SkImageFilter_Base * as_IFB(SkImageFilter *filter)
bool affectsTransparentBlack() const

◆ computeFastBounds()

SkRect SkImageFilter::computeFastBounds ( const SkRect bounds) const
virtual

Reimplemented in SkLocalMatrixImageFilter, and SkRuntimeImageFilter.

Definition at line 82 of file SkImageFilter.cpp.

82 {
83 if (0 == this->countInputs()) {
84 return src;
85 }
86 SkRect combinedBounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src) : src;
87 for (int i = 1; i < this->countInputs(); i++) {
88 const SkImageFilter* input = this->getInput(i);
89 if (input) {
90 combinedBounds.join(input->computeFastBounds(src));
91 } else {
92 combinedBounds.join(src);
93 }
94 }
95 return combinedBounds;
96}
virtual SkRect computeFastBounds(const SkRect &bounds) const
int countInputs() const
void join(const SkRect &r)
Definition SkRect.cpp:126

◆ countInputs()

int SkImageFilter::countInputs ( ) const

Returns the number of inputs this filter will accept (some inputs can be NULL).

Definition at line 46 of file SkImageFilter.cpp.

46{ return as_IFB(this)->fInputs.count(); }

◆ Deserialize()

static sk_sp< SkImageFilter > SkImageFilter::Deserialize ( const void *  data,
size_t  size,
const SkDeserialProcs procs = nullptr 
)
inlinestatic

Definition at line 101 of file SkImageFilter.h.

102 {
103 return sk_sp<SkImageFilter>(static_cast<SkImageFilter*>(
104 SkFlattenable::Deserialize(kSkImageFilter_Type, data, size, procs).release()));
105 }
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)

◆ filterBounds()

SkIRect SkImageFilter::filterBounds ( const SkIRect src,
const SkMatrix ctm,
MapDirection  direction,
const SkIRect inputRect = nullptr 
) 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.

In kReverse mode, 'inputRect' is the device-space bounds of the input pixels. In kForward mode it should always be null. If 'inputRect' is null in kReverse mode the resulting answer may be incorrect.

Definition at line 61 of file SkImageFilter.cpp.

62 {
63 // The old filterBounds() function uses SkIRects that are defined in layer space so, while
64 // we still are supporting it, bypass SkIF_B's new public filter bounds functions and go right
65 // to the internal layer-space calculations.
66 skif::Mapping mapping{ctm};
67 if (kReverse_MapDirection == direction) {
68 skif::LayerSpace<SkIRect> targetOutput(src);
69 std::optional<skif::LayerSpace<SkIRect>> content;
70 if (inputRect) {
72 }
73 return SkIRect(as_IFB(this)->onGetInputLayerBounds(mapping, targetOutput, content));
74 } else {
75 SkASSERT(!inputRect);
77 auto output = as_IFB(this)->onGetOutputLayerBounds(mapping, content);
78 return output ? SkIRect(*output) : SkRectPriv::MakeILarge();
79 }
80}
virtual std::optional< skif::LayerSpace< SkIRect > > onGetOutputLayerBounds(const skif::Mapping &mapping, std::optional< skif::LayerSpace< SkIRect > > contentBounds) const =0
union flutter::testing::@2838::KeyboardChange::@76 content

◆ getInput()

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

Returns the input filter at a given index, or NULL if no input is connected. The indices used are filter-specific.

Definition at line 52 of file SkImageFilter.cpp.

52 {
53 SkASSERT(i < this->countInputs());
54 return as_IFB(this)->fInputs[i].get();
55}

◆ isColorFilterNode()

bool SkImageFilter::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. 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).

Definition at line 57 of file SkImageFilter.cpp.

57 {
58 return as_IFB(this)->onIsColorFilterNode(filterPtr);
59}
virtual bool onIsColorFilterNode(SkColorFilter **) const

◆ makeWithLocalMatrix()

sk_sp< SkImageFilter > SkImageFilter::makeWithLocalMatrix ( const SkMatrix matrix) const

If this filter can be represented by another filter + a localMatrix, return that filter, else return null.

Definition at line 130 of file SkImageFilter.cpp.

130 {
131 return SkLocalMatrixImageFilter::Make(matrix, this->refMe());
132}
sk_sp< SkImageFilter > refMe() const
static sk_sp< SkImageFilter > Make(const SkMatrix &localMatrix, sk_sp< SkImageFilter > input)

◆ refMe()

sk_sp< SkImageFilter > SkImageFilter::refMe ( ) const
inlineprotected

Definition at line 109 of file SkImageFilter.h.

109 {
110 return sk_ref_sp(const_cast<SkImageFilter*>(this));
111 }
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381

Friends And Related Symbol Documentation

◆ SkImageFilter_Base

friend class SkImageFilter_Base
friend

Definition at line 114 of file SkImageFilter.h.


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