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

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

Issue 1218993002: refactor code to apply the croprect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | src/core/SkImageFilter.cpp » ('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 14 matching lines...) Expand all
25 25
26 /** 26 /**
27 * Base class for image filters. If one is installed in the paint, then 27 * Base class for image filters. If one is installed in the paint, then
28 * all drawing occurs as usual, but it is as if the drawing happened into an 28 * all drawing occurs as usual, but it is as if the drawing happened into an
29 * offscreen (before the xfermode is applied). This offscreen bitmap will 29 * offscreen (before the xfermode is applied). This offscreen bitmap will
30 * then be handed to the imagefilter, who in turn creates a new bitmap which 30 * then be handed to the imagefilter, who in turn creates a new bitmap which
31 * is what will finally be drawn to the device (using the original xfermode). 31 * is what will finally be drawn to the device (using the original xfermode).
32 */ 32 */
33 class SK_API SkImageFilter : public SkFlattenable { 33 class SK_API SkImageFilter : public SkFlattenable {
34 public: 34 public:
35 class CropRect {
36 public:
37 enum CropEdge {
38 kHasLeft_CropEdge = 0x01,
39 kHasTop_CropEdge = 0x02,
40 kHasRight_CropEdge = 0x04,
41 kHasBottom_CropEdge = 0x08,
42 kHasAll_CropEdge = 0x0F,
43 };
44 CropRect() {}
45 explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge) : fRect(rect), fFlags(flags) {}
46 uint32_t flags() const { return fFlags; }
47 const SkRect& rect() const { return fRect; }
48 private:
49 SkRect fRect;
50 uint32_t fFlags;
51 };
52
53 // This cache maps from (filter's unique ID + CTM + clipBounds + src bitmap generation ID) to 35 // This cache maps from (filter's unique ID + CTM + clipBounds + src bitmap generation ID) to
54 // (result, offset). 36 // (result, offset).
55 class Cache : public SkRefCnt { 37 class Cache : public SkRefCnt {
56 public: 38 public:
57 struct Key; 39 struct Key;
58 virtual ~Cache() {} 40 virtual ~Cache() {}
59 static Cache* Create(size_t maxBytes); 41 static Cache* Create(size_t maxBytes);
60 static Cache* Get(); 42 static Cache* Get();
61 virtual bool get(const Key& key, SkBitmap* result, SkIPoint* offset) con st = 0; 43 virtual bool get(const Key& key, SkBitmap* result, SkIPoint* offset) con st = 0;
62 virtual void set(const Key& key, const SkBitmap& result, const SkIPoint& offset) = 0; 44 virtual void set(const Key& key, const SkBitmap& result, const SkIPoint& offset) = 0;
63 virtual void purge() {} 45 virtual void purge() {}
64 }; 46 };
65 47
66 class Context { 48 class Context {
67 public: 49 public:
68 Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache) : 50 Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache) :
69 fCTM(ctm), fClipBounds(clipBounds), fCache(cache) { 51 fCTM(ctm), fClipBounds(clipBounds), fCache(cache) {
70 } 52 }
71 const SkMatrix& ctm() const { return fCTM; } 53 const SkMatrix& ctm() const { return fCTM; }
72 const SkIRect& clipBounds() const { return fClipBounds; } 54 const SkIRect& clipBounds() const { return fClipBounds; }
73 Cache* cache() const { return fCache; } 55 Cache* cache() const { return fCache; }
74 private: 56 private:
75 SkMatrix fCTM; 57 SkMatrix fCTM;
76 SkIRect fClipBounds; 58 SkIRect fClipBounds;
77 Cache* fCache; 59 Cache* fCache;
78 }; 60 };
79 61
62 class CropRect {
63 public:
64 enum CropEdge {
65 kHasLeft_CropEdge = 0x01,
66 kHasTop_CropEdge = 0x02,
67 kHasRight_CropEdge = 0x04,
68 kHasBottom_CropEdge = 0x08,
69 kHasAll_CropEdge = 0x0F,
70 };
71 CropRect() {}
72 explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge)
73 : fRect(rect), fFlags(flags) {}
74 uint32_t flags() const { return fFlags; }
75 const SkRect& rect() const { return fRect; }
76 #ifndef SK_IGNORE_TO_STRING
77 void toString(SkString* str) const;
78 #endif
79
80 /**
81 * Apply this cropRect to the imageBounds. If a given edge of the cropR ect is not
82 * set, then the corresponding edge from imageBounds will be used.
83 *
84 * Note: imageBounds is in "device" space, as the output cropped rectan gle will be,
85 * so the context's CTM is ignore for those. It is only applied the cro prect's bounds.
86 *
87 * The resulting rect will be intersected with the context's clip. If t hat intersection is
88 * empty, then this returns false and cropped is unmodified.
89 */
90 bool applyTo(const SkIRect& imageBounds, const Context&, SkIRect* croppe d) const;
91
92 private:
93 SkRect fRect;
94 uint32_t fFlags;
95 };
96
80 class Proxy { 97 class Proxy {
81 public: 98 public:
82 Proxy(SkBaseDevice* device) : fDevice(device) { } 99 Proxy(SkBaseDevice* device) : fDevice(device) { }
83 100
84 SkBaseDevice* createDevice(int width, int height); 101 SkBaseDevice* createDevice(int width, int height);
85 102
86 // Returns true if the proxy handled the filter itself. If this returns 103 // Returns true if the proxy handled the filter itself. If this returns
87 // false then the filter's code will be called. 104 // false then the filter's code will be called.
88 bool filterImage(const SkImageFilter*, const SkBitmap& src, const SkImag eFilter::Context&, 105 bool filterImage(const SkImageFilter*, const SkBitmap& src, const SkImag eFilter::Context&,
89 SkBitmap* result, SkIPoint* offset); 106 SkBitmap* result, SkIPoint* offset);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 * connected. The indices used are filter-specific. 192 * connected. The indices used are filter-specific.
176 */ 193 */
177 SkImageFilter* getInput(int i) const { 194 SkImageFilter* getInput(int i) const {
178 SkASSERT(i < fInputCount); 195 SkASSERT(i < fInputCount);
179 return fInputs[i]; 196 return fInputs[i];
180 } 197 }
181 198
182 /** 199 /**
183 * Returns whether any edges of the crop rect have been set. The crop 200 * Returns whether any edges of the crop rect have been set. The crop
184 * rect is set at construction time, and determines which pixels from the 201 * rect is set at construction time, and determines which pixels from the
185 * input image will be processed. The size of the crop rect should be 202 * input image will be processed, and which pixels in the output image will be allowed.
203 * The size of the crop rect should be
186 * used as the size of the destination image. The origin of this rect 204 * used as the size of the destination image. The origin of this rect
187 * should be used to offset access to the input images, and should also 205 * should be used to offset access to the input images, and should also
188 * be added to the "offset" parameter in onFilterImage and 206 * be added to the "offset" parameter in onFilterImage and
189 * filterImageGPU(). (The latter ensures that the resulting buffer is 207 * filterImageGPU(). (The latter ensures that the resulting buffer is
190 * drawn in the correct location.) 208 * drawn in the correct location.)
191 */ 209 */
192 bool cropRectIsSet() const { return fCropRect.flags() != 0x0; } 210 bool cropRectIsSet() const { return fCropRect.flags() != 0x0; }
193 211
194 CropRect getCropRect() const { return fCropRect; } 212 CropRect getCropRect() const { return fCropRect; }
195 213
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 */ 381 */
364 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ 382 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \
365 Common localVar; \ 383 Common localVar; \
366 do { \ 384 do { \
367 if (!localVar.unflatten(buffer, expectedCount)) { \ 385 if (!localVar.unflatten(buffer, expectedCount)) { \
368 return NULL; \ 386 return NULL; \
369 } \ 387 } \
370 } while (0) 388 } while (0)
371 389
372 #endif 390 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698