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 |
11 #include "SkFlattenable.h" | 11 #include "SkFlattenable.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 | 14 |
15 class SkBitmap; | 15 class SkBitmap; |
16 class SkColorFilter; | 16 class SkColorFilter; |
17 class SkBaseDevice; | 17 class SkBaseDevice; |
18 struct SkIPoint; | 18 struct SkIPoint; |
19 class SkShader; | |
20 class GrEffectRef; | 19 class GrEffectRef; |
21 class GrTexture; | 20 class GrTexture; |
22 | 21 |
23 /** | 22 /** |
24 * Base class for image filters. If one is installed in the paint, then | 23 * 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 | 24 * 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 | 25 * 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 | 26 * 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). | 27 * is what will finally be drawn to the device (using the original xfermode). |
29 */ | 28 */ |
(...skipping 12 matching lines...) Expand all Loading... |
42 }; | 41 }; |
43 CropRect() {} | 42 CropRect() {} |
44 explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge)
: fRect(rect), fFlags(flags) {} | 43 explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge)
: fRect(rect), fFlags(flags) {} |
45 uint32_t flags() const { return fFlags; } | 44 uint32_t flags() const { return fFlags; } |
46 const SkRect& rect() const { return fRect; } | 45 const SkRect& rect() const { return fRect; } |
47 private: | 46 private: |
48 SkRect fRect; | 47 SkRect fRect; |
49 uint32_t fFlags; | 48 uint32_t fFlags; |
50 }; | 49 }; |
51 | 50 |
| 51 class Cache : public SkRefCnt { |
| 52 public: |
| 53 // By default, we cache only image filters with 2 or more children. |
| 54 static Cache* Create(int minChildren = 2); |
| 55 virtual ~Cache() {} |
| 56 virtual bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* o
ffset) = 0; |
| 57 virtual void set(const SkImageFilter* key, |
| 58 const SkBitmap& result, const SkIPoint& offset) = 0; |
| 59 }; |
| 60 |
52 class Context { | 61 class Context { |
53 public: | 62 public: |
54 Context(const SkMatrix& ctm, const SkIRect& clipBounds) : | 63 Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache) : |
55 fCTM(ctm), fClipBounds(clipBounds) { | 64 fCTM(ctm), fClipBounds(clipBounds), fCache(cache) { |
56 } | 65 } |
57 const SkMatrix& ctm() const { return fCTM; } | 66 const SkMatrix& ctm() const { return fCTM; } |
58 const SkIRect& clipBounds() const { return fClipBounds; } | 67 const SkIRect& clipBounds() const { return fClipBounds; } |
| 68 Cache* cache() const { return fCache; } |
59 private: | 69 private: |
60 SkMatrix fCTM; | 70 SkMatrix fCTM; |
61 SkIRect fClipBounds; | 71 SkIRect fClipBounds; |
| 72 Cache* fCache; |
62 }; | 73 }; |
63 | 74 |
64 class Proxy { | 75 class Proxy { |
65 public: | 76 public: |
66 virtual ~Proxy() {}; | 77 virtual ~Proxy() {}; |
67 | 78 |
68 virtual SkBaseDevice* createDevice(int width, int height) = 0; | 79 virtual SkBaseDevice* createDevice(int width, int height) = 0; |
69 // returns true if the proxy can handle this filter natively | 80 // returns true if the proxy can handle this filter natively |
70 virtual bool canHandleImageFilter(const SkImageFilter*) = 0; | 81 virtual bool canHandleImageFilter(const SkImageFilter*) = 0; |
71 // returns true if the proxy handled the filter itself. if this returns | 82 // returns true if the proxy handled the filter itself. if this returns |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 276 |
266 | 277 |
267 private: | 278 private: |
268 typedef SkFlattenable INHERITED; | 279 typedef SkFlattenable INHERITED; |
269 int fInputCount; | 280 int fInputCount; |
270 SkImageFilter** fInputs; | 281 SkImageFilter** fInputs; |
271 CropRect fCropRect; | 282 CropRect fCropRect; |
272 }; | 283 }; |
273 | 284 |
274 #endif | 285 #endif |
OLD | NEW |