Skia
2D Graphics Library
SkImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkImageFilter_DEFINED
9 #define SkImageFilter_DEFINED
10 
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/private/base/SkAPI.h"
15 
16 #include <cstddef>
17 
18 class SkColorFilter;
19 class SkMatrix;
20 struct SkDeserialProcs;
21 
35 class SK_API SkImageFilter : public SkFlattenable {
36 public:
37  enum MapDirection {
40  };
54  SkIRect filterBounds(const SkIRect& src, const SkMatrix& ctm,
55  MapDirection, const SkIRect* inputRect = nullptr) const;
56 
64  bool isColorFilterNode(SkColorFilter** filterPtr) const;
65 
66  // DEPRECATED : use isColorFilterNode() instead
67  bool asColorFilter(SkColorFilter** filterPtr) const {
68  return this->isColorFilterNode(filterPtr);
69  }
70 
76  bool asAColorFilter(SkColorFilter** filterPtr) const;
77 
81  int countInputs() const;
82 
87  const SkImageFilter* getInput(int i) const;
88 
89  // Default impl returns union of all input bounds.
90  virtual SkRect computeFastBounds(const SkRect& bounds) const;
91 
92  // Can this filter DAG compute the resulting bounds of an object-space rectangle?
93  bool canComputeFastBounds() const;
94 
100 
101  static sk_sp<SkImageFilter> Deserialize(const void* data, size_t size,
102  const SkDeserialProcs* procs = nullptr) {
103  return sk_sp<SkImageFilter>(static_cast<SkImageFilter*>(
104  SkFlattenable::Deserialize(kSkImageFilter_Type, data, size, procs).release()));
105  }
106 
107 protected:
108 
110  return sk_ref_sp(const_cast<SkImageFilter*>(this));
111  }
112 
113 private:
114  friend class SkImageFilter_Base;
115 
116  using INHERITED = SkFlattenable;
117 };
118 
119 #endif
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
ColorFilters are optional objects in the drawing pipeline.
Definition: SkColorFilter.h:35
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:28
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
SkFlattenable()
Definition: SkFlattenable.h:43
Base class for image filters.
Definition: SkImageFilter.h:35
sk_sp< SkImageFilter > makeWithLocalMatrix(const SkMatrix &matrix) const
If this filter can be represented by another filter + a localMatrix, return that filter,...
SkIRect filterBounds(const SkIRect &src, const SkMatrix &ctm, MapDirection, const SkIRect *inputRect=nullptr) const
Map a device-space rect recursively forward or backward through the filter DAG.
sk_sp< SkImageFilter > refMe() const
Definition: SkImageFilter.h:109
bool asAColorFilter(SkColorFilter **filterPtr) const
Returns true (and optionally returns a ref'd filter) if this imagefilter can be completely replaced b...
MapDirection
Definition: SkImageFilter.h:37
@ kForward_MapDirection
Definition: SkImageFilter.h:38
@ kReverse_MapDirection
Definition: SkImageFilter.h:39
static sk_sp< SkImageFilter > Deserialize(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
Definition: SkImageFilter.h:101
bool isColorFilterNode(SkColorFilter **filterPtr) const
Returns whether this image filter is a color filter and puts the color filter into the "filterPtr" pa...
bool asColorFilter(SkColorFilter **filterPtr) const
Definition: SkImageFilter.h:67
const SkImageFilter * getInput(int i) const
Returns the input filter at a given index, or NULL if no input is connected.
int countInputs() const
Returns the number of inputs this filter will accept (some inputs can be NULL).
bool canComputeFastBounds() const
virtual SkRect computeFastBounds(const SkRect &bounds) const
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
Definition: SkRefCnt.h:119
Definition: SkSerialProcs.h:97
SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:32
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582