OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkImageFilter_DEFINED | 8 #ifndef SkImageFilter_DEFINED |
9 #define SkImageFilter_DEFINED | 9 #define SkImageFilter_DEFINED |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 * Base class for image filters. If one is installed in the paint, then | 24 * Base class for image filters. If one is installed in the paint, then |
25 * all drawing occurs as usual, but it is as if the drawing happened into an | 25 * all drawing occurs as usual, but it is as if the drawing happened into an |
26 * offscreen (before the xfermode is applied). This offscreen bitmap will | 26 * offscreen (before the xfermode is applied). This offscreen bitmap will |
27 * then be handed to the imagefilter, who in turn creates a new bitmap which | 27 * then be handed to the imagefilter, who in turn creates a new bitmap which |
28 * is what will finally be drawn to the device (using the original xfermode). | 28 * is what will finally be drawn to the device (using the original xfermode). |
29 */ | 29 */ |
30 class SK_API SkImageFilter : public SkFlattenable { | 30 class SK_API SkImageFilter : public SkFlattenable { |
31 public: | 31 public: |
32 SK_DECLARE_INST_COUNT(SkImageFilter) | 32 SK_DECLARE_INST_COUNT(SkImageFilter) |
33 | 33 |
34 struct CropRect { | 34 class CropRect { |
35 SkRect fRect; | 35 public: |
36 uint32_t fFlags; | |
37 enum CropEdge { | 36 enum CropEdge { |
38 kHasLeft_CropEdge = 0x01, | 37 kHasLeft_CropEdge = 0x01, |
39 kHasTop_CropEdge = 0x02, | 38 kHasTop_CropEdge = 0x02, |
40 kHasRight_CropEdge = 0x04, | 39 kHasRight_CropEdge = 0x04, |
41 kHasBottom_CropEdge = 0x08, | 40 kHasBottom_CropEdge = 0x08, |
42 kHasAll_CropEdge = 0x0F, | 41 kHasAll_CropEdge = 0x0F, |
43 }; | 42 }; |
44 CropRect() {} | 43 CropRect() {} |
45 explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge)
: fRect(rect), fFlags(flags) {} | 44 explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge)
: fRect(rect), fFlags(flags) {} |
46 // Returns true if any of the crop edges have been set. | 45 uint32_t flags() const { return fFlags; } |
47 bool isSet() const | 46 const SkRect& rect() const { return fRect; } |
48 { | 47 private: |
49 return fFlags != 0x0; | 48 SkRect fRect; |
50 } | 49 uint32_t fFlags; |
51 }; | 50 }; |
52 | 51 |
53 class Proxy { | 52 class Proxy { |
54 public: | 53 public: |
55 virtual ~Proxy() {}; | 54 virtual ~Proxy() {}; |
56 | 55 |
57 virtual SkBaseDevice* createDevice(int width, int height) = 0; | 56 virtual SkBaseDevice* createDevice(int width, int height) = 0; |
58 // returns true if the proxy can handle this filter natively | 57 // returns true if the proxy can handle this filter natively |
59 virtual bool canHandleImageFilter(SkImageFilter*) = 0; | 58 virtual bool canHandleImageFilter(SkImageFilter*) = 0; |
60 // returns true if the proxy handled the filter itself. if this returns | 59 // returns true if the proxy handled the filter itself. if this returns |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 /** | 141 /** |
143 * Returns the input filter at a given index, or NULL if no input is | 142 * Returns the input filter at a given index, or NULL if no input is |
144 * connected. The indices used are filter-specific. | 143 * connected. The indices used are filter-specific. |
145 */ | 144 */ |
146 SkImageFilter* getInput(int i) const { | 145 SkImageFilter* getInput(int i) const { |
147 SkASSERT(i < fInputCount); | 146 SkASSERT(i < fInputCount); |
148 return fInputs[i]; | 147 return fInputs[i]; |
149 } | 148 } |
150 | 149 |
151 /** | 150 /** |
152 * Returns the crop rectangle of this filter. This is set at construction | 151 * Returns whether any edges of the crop rect have been set. The crop |
153 * time, and determines which pixels from the input image will | 152 * rect is set at construction time, and determines which pixels from the |
154 * be processed. The size of this rectangle should be used as the size | 153 * input image will be processed. The size of the crop rect should be |
155 * of the destination image. The origin of this rect should be used to | 154 * used as the size of the destination image. The origin of this rect |
156 * offset access to the input images, and should also be added to the | 155 * should be used to offset access to the input images, and should also |
157 * "offset" parameter in onFilterImage and filterImageGPU(). (The latter | 156 * be added to the "offset" parameter in onFilterImage and |
158 * ensures that the resulting buffer is drawn in the correct location.) | 157 * filterImageGPU(). (The latter ensures that the resulting buffer is |
| 158 * drawn in the correct location.) |
159 */ | 159 */ |
160 bool cropRectIsSet() const { return fCropRect.isSet(); } | 160 bool cropRectIsSet() const { return fCropRect.flags() != 0x0; } |
161 | 161 |
162 protected: | 162 protected: |
163 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe
ct = NULL); | 163 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe
ct = NULL); |
164 | 164 |
165 // Convenience constructor for 1-input filters. | 165 // Convenience constructor for 1-input filters. |
166 explicit SkImageFilter(SkImageFilter* input, const CropRect* cropRect = NULL
); | 166 explicit SkImageFilter(SkImageFilter* input, const CropRect* cropRect = NULL
); |
167 | 167 |
168 // Convenience constructor for 2-input filters. | 168 // Convenience constructor for 2-input filters. |
169 SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const CropRect*
cropRect = NULL); | 169 SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const CropRect*
cropRect = NULL); |
170 | 170 |
(...skipping 15 matching lines...) Expand all Loading... |
186 bool applyCropRect(SkIRect* rect, const SkMatrix& matrix) const; | 186 bool applyCropRect(SkIRect* rect, const SkMatrix& matrix) const; |
187 | 187 |
188 private: | 188 private: |
189 typedef SkFlattenable INHERITED; | 189 typedef SkFlattenable INHERITED; |
190 int fInputCount; | 190 int fInputCount; |
191 SkImageFilter** fInputs; | 191 SkImageFilter** fInputs; |
192 CropRect fCropRect; | 192 CropRect fCropRect; |
193 }; | 193 }; |
194 | 194 |
195 #endif | 195 #endif |
OLD | NEW |