Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: include/core/SkImageFilter.h

Issue 26371002: Change SkImageFilter's cropRect from SkIRect to a CropRect struct (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Alternate version, using a single fFlags member. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gm/xfermodeimagefilter.cpp ('k') | include/core/SkRect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 #ifdef SK_CROP_RECT_IS_INT
35 typedef SkIRect CropRect;
36 #else
37 struct CropRect {
38 SkRect fRect;
39 uint32_t fFlags;
40 enum CropEdge {
41 kHasLeft_CropEdge = 0x01,
42 kHasTop_CropEdge = 0x02,
43 kHasRight_CropEdge = 0x04,
44 kHasBottom_CropEdge = 0x08,
45 kHasAll_CropEdge = 0x0F,
46 };
47 CropRect() {}
48 explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge) : fRect(rect), fFlags(flags) {}
49 bool isSet() const
50 {
51 return fFlags != 0x0;
52 }
53 };
54 #endif
55
34 class Proxy { 56 class Proxy {
35 public: 57 public:
36 virtual ~Proxy() {}; 58 virtual ~Proxy() {};
37 59
38 virtual SkBaseDevice* createDevice(int width, int height) = 0; 60 virtual SkBaseDevice* createDevice(int width, int height) = 0;
39 // returns true if the proxy can handle this filter natively 61 // returns true if the proxy can handle this filter natively
40 virtual bool canHandleImageFilter(SkImageFilter*) = 0; 62 virtual bool canHandleImageFilter(SkImageFilter*) = 0;
41 // returns true if the proxy handled the filter itself. if this returns 63 // returns true if the proxy handled the filter itself. if this returns
42 // false then the filter's code will be called. 64 // false then the filter's code will be called.
43 virtual bool filterImage(SkImageFilter*, const SkBitmap& src, 65 virtual bool filterImage(SkImageFilter*, const SkBitmap& src,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 153
132 /** 154 /**
133 * Returns the crop rectangle of this filter. This is set at construction 155 * Returns the crop rectangle of this filter. This is set at construction
134 * time, and determines which pixels from the input image will 156 * time, and determines which pixels from the input image will
135 * be processed. The size of this rectangle should be used as the size 157 * be processed. The size of this rectangle should be used as the size
136 * of the destination image. The origin of this rect should be used to 158 * of the destination image. The origin of this rect should be used to
137 * offset access to the input images, and should also be added to the 159 * offset access to the input images, and should also be added to the
138 * "offset" parameter in onFilterImage and filterImageGPU(). (The latter 160 * "offset" parameter in onFilterImage and filterImageGPU(). (The latter
139 * ensures that the resulting buffer is drawn in the correct location.) 161 * ensures that the resulting buffer is drawn in the correct location.)
140 */ 162 */
141 const SkIRect& cropRect() const { return fCropRect; } 163 #ifdef SK_CROP_RECT_IS_INT
164 bool cropRectIsSet() const { return !fCropRect.isLargest(); }
165 #else
166 bool cropRectIsSet() const { return fCropRect.isSet(); }
167 #endif
142 168
143 protected: 169 protected:
144 SkImageFilter(int inputCount, SkImageFilter** inputs, const SkIRect* cropRec t = NULL); 170 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe ct = NULL);
145 171
146 // Convenience constructor for 1-input filters. 172 // Convenience constructor for 1-input filters.
147 explicit SkImageFilter(SkImageFilter* input, const SkIRect* cropRect = NULL) ; 173 explicit SkImageFilter(SkImageFilter* input, const CropRect* cropRect = NULL );
148 174
149 // Convenience constructor for 2-input filters. 175 // Convenience constructor for 2-input filters.
150 SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const SkIRect* c ropRect = NULL); 176 SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const CropRect* cropRect = NULL);
151 177
152 virtual ~SkImageFilter(); 178 virtual ~SkImageFilter();
153 179
154 explicit SkImageFilter(SkFlattenableReadBuffer& rb); 180 explicit SkImageFilter(SkFlattenableReadBuffer& rb);
155 181
156 virtual void flatten(SkFlattenableWriteBuffer& wb) const SK_OVERRIDE; 182 virtual void flatten(SkFlattenableWriteBuffer& wb) const SK_OVERRIDE;
157 183
158 // Default impl returns false 184 // Default impl returns false
159 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, 185 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
160 SkBitmap* result, SkIPoint* offset); 186 SkBitmap* result, SkIPoint* offset);
161 // Default impl copies src into dst and returns true 187 // Default impl copies src into dst and returns true
162 virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*); 188 virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*);
163 189
164 // Applies "matrix" to the crop rect, and sets "rect" to the intersection of 190 // Applies "matrix" to the crop rect, and sets "rect" to the intersection of
165 // "rect" and the transformed crop rect. If there is no overlap, returns 191 // "rect" and the transformed crop rect. If there is no overlap, returns
166 // false and leaves "rect" unchanged. 192 // false and leaves "rect" unchanged.
167 bool applyCropRect(SkIRect* rect, const SkMatrix& matrix) const; 193 bool applyCropRect(SkIRect* rect, const SkMatrix& matrix) const;
168 194
169 private: 195 private:
170 typedef SkFlattenable INHERITED; 196 typedef SkFlattenable INHERITED;
171 int fInputCount; 197 int fInputCount;
172 SkImageFilter** fInputs; 198 SkImageFilter** fInputs;
173 SkIRect fCropRect; 199 CropRect fCropRect;
174 }; 200 };
175 201
176 #endif 202 #endif
OLDNEW
« no previous file with comments | « gm/xfermodeimagefilter.cpp ('k') | include/core/SkRect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698