| 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 "../private/SkTArray.h" | 11 #include "../private/SkTArray.h" |
| 12 #include "../private/SkTemplates.h" | 12 #include "../private/SkTemplates.h" |
| 13 #include "../private/SkMutex.h" | 13 #include "../private/SkMutex.h" |
| 14 #include "SkFilterQuality.h" | 14 #include "SkFilterQuality.h" |
| 15 #include "SkFlattenable.h" | 15 #include "SkFlattenable.h" |
| 16 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
| 17 #include "SkRect.h" | 17 #include "SkRect.h" |
| 18 | 18 |
| 19 class GrContext; | 19 class GrContext; |
| 20 class GrFragmentProcessor; | 20 class GrFragmentProcessor; |
| 21 class SkColorFilter; | 21 class SkColorFilter; |
| 22 struct SkIPoint; | 22 struct SkIPoint; |
| 23 class SkSpecialImage; | 23 class SkSpecialImage; |
| 24 class SkImageFilterCache; |
| 25 struct SkImageFilterCacheKey; |
| 24 | 26 |
| 25 /** | 27 /** |
| 26 * Base class for image filters. If one is installed in the paint, then | 28 * Base class for image filters. If one is installed in the paint, then |
| 27 * all drawing occurs as usual, but it is as if the drawing happened into an | 29 * all drawing occurs as usual, but it is as if the drawing happened into an |
| 28 * offscreen (before the xfermode is applied). This offscreen bitmap will | 30 * offscreen (before the xfermode is applied). This offscreen bitmap will |
| 29 * then be handed to the imagefilter, who in turn creates a new bitmap which | 31 * then be handed to the imagefilter, who in turn creates a new bitmap which |
| 30 * is what will finally be drawn to the device (using the original xfermode). | 32 * is what will finally be drawn to the device (using the original xfermode). |
| 31 */ | 33 */ |
| 32 class SK_API SkImageFilter : public SkFlattenable { | 34 class SK_API SkImageFilter : public SkFlattenable { |
| 33 public: | 35 public: |
| 34 // This cache maps from (filter's unique ID + CTM + clipBounds + src bitmap
generation ID) to | |
| 35 // (result, offset). | |
| 36 class Cache : public SkRefCnt { | |
| 37 public: | |
| 38 struct Key; | |
| 39 virtual ~Cache() {} | |
| 40 static Cache* Create(size_t maxBytes); | |
| 41 static Cache* Get(); | |
| 42 virtual SkSpecialImage* get(const Key& key, SkIPoint* offset) const = 0; | |
| 43 virtual void set(const Key& key, SkSpecialImage* image, const SkIPoint&
offset) = 0; | |
| 44 virtual void purge() = 0; | |
| 45 virtual void purgeByKeys(const Key[], int) = 0; | |
| 46 SkDEBUGCODE(virtual int count() const = 0;) | |
| 47 }; | |
| 48 | |
| 49 class Context { | 36 class Context { |
| 50 public: | 37 public: |
| 51 Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache) | 38 Context(const SkMatrix& ctm, const SkIRect& clipBounds, SkImageFilterCac
he* cache) |
| 52 : fCTM(ctm) | 39 : fCTM(ctm) |
| 53 , fClipBounds(clipBounds) | 40 , fClipBounds(clipBounds) |
| 54 , fCache(cache) | 41 , fCache(cache) |
| 55 {} | 42 {} |
| 56 | 43 |
| 57 const SkMatrix& ctm() const { return fCTM; } | 44 const SkMatrix& ctm() const { return fCTM; } |
| 58 const SkIRect& clipBounds() const { return fClipBounds; } | 45 const SkIRect& clipBounds() const { return fClipBounds; } |
| 59 Cache* cache() const { return fCache; } | 46 SkImageFilterCache* cache() const { return fCache; } |
| 60 | 47 |
| 61 private: | 48 private: |
| 62 SkMatrix fCTM; | 49 SkMatrix fCTM; |
| 63 SkIRect fClipBounds; | 50 SkIRect fClipBounds; |
| 64 Cache* fCache; | 51 SkImageFilterCache* fCache; |
| 65 }; | 52 }; |
| 66 | 53 |
| 67 class CropRect { | 54 class CropRect { |
| 68 public: | 55 public: |
| 69 enum CropEdge { | 56 enum CropEdge { |
| 70 kHasLeft_CropEdge = 0x01, | 57 kHasLeft_CropEdge = 0x01, |
| 71 kHasTop_CropEdge = 0x02, | 58 kHasTop_CropEdge = 0x02, |
| 72 kHasWidth_CropEdge = 0x04, | 59 kHasWidth_CropEdge = 0x04, |
| 73 kHasHeight_CropEdge = 0x08, | 60 kHasHeight_CropEdge = 0x08, |
| 74 kHasAll_CropEdge = 0x0F, | 61 kHasAll_CropEdge = 0x0F, |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 void init(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* crop
Rect); | 379 void init(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* crop
Rect); |
| 393 | 380 |
| 394 bool usesSrcInput() const { return fUsesSrcInput; } | 381 bool usesSrcInput() const { return fUsesSrcInput; } |
| 395 virtual bool affectsTransparentBlack() const { return false; } | 382 virtual bool affectsTransparentBlack() const { return false; } |
| 396 | 383 |
| 397 SkAutoSTArray<2, sk_sp<SkImageFilter>> fInputs; | 384 SkAutoSTArray<2, sk_sp<SkImageFilter>> fInputs; |
| 398 | 385 |
| 399 bool fUsesSrcInput; | 386 bool fUsesSrcInput; |
| 400 CropRect fCropRect; | 387 CropRect fCropRect; |
| 401 uint32_t fUniqueID; // Globally unique | 388 uint32_t fUniqueID; // Globally unique |
| 402 mutable SkTArray<Cache::Key> fCacheKeys; | 389 mutable SkTArray<SkImageFilterCacheKey> fCacheKeys; |
| 403 mutable SkMutex fMutex; | 390 mutable SkMutex fMutex; |
| 404 typedef SkFlattenable INHERITED; | 391 typedef SkFlattenable INHERITED; |
| 405 }; | 392 }; |
| 406 | 393 |
| 407 /** | 394 /** |
| 408 * Helper to unflatten the common data, and return NULL if we fail. | 395 * Helper to unflatten the common data, and return NULL if we fail. |
| 409 */ | 396 */ |
| 410 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ | 397 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ |
| 411 Common localVar; \ | 398 Common localVar; \ |
| 412 do { \ | 399 do { \ |
| 413 if (!localVar.unflatten(buffer, expectedCount)) { \ | 400 if (!localVar.unflatten(buffer, expectedCount)) { \ |
| 414 return NULL; \ | 401 return NULL; \ |
| 415 } \ | 402 } \ |
| 416 } while (0) | 403 } while (0) |
| 417 | 404 |
| 418 #endif | 405 #endif |
| OLD | NEW |