commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkCachingPixelRef_DEFINED |
| 9 | #define SkCachingPixelRef_DEFINED |
| 10 | |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 11 | #include "SkImageInfo.h" |
| 12 | #include "SkImageGenerator.h" |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 13 | #include "SkPixelRef.h" |
| 14 | |
| 15 | class SkColorTable; |
| 16 | |
| 17 | /** |
| 18 | * PixelRef which defers decoding until SkBitmap::lockPixels() is |
| 19 | * called. Caches the decoded images in the global |
| 20 | * SkScaledImageCache. When the pixels are unlocked, this cache may |
| 21 | * or be destroyed before the next lock. If so, onLockPixels will |
| 22 | * attempt to re-decode. |
| 23 | * |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 24 | * Decoding is handled by the SkImageGenerator |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 25 | */ |
| 26 | class SkCachingPixelRef : public SkPixelRef { |
| 27 | public: |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Takes ownership of SkImageGenerator. If this method fails for |
| 30 | * whatever reason, it will return false and immediatetely delete |
| 31 | * the generator. If it succeeds, it will modify destination |
| 32 | * bitmap. |
| 33 | * |
| 34 | * If Install fails or when the SkCachingPixelRef that is |
| 35 | * installed into destination is destroyed, it will call |
| 36 | * SkDELETE() on the generator. Therefore, generator should be |
| 37 | * allocated with SkNEW() or SkNEW_ARGS(). |
| 38 | */ |
| 39 | static bool Install(SkImageGenerator* gen, SkBitmap* dst); |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 40 | |
| 41 | protected: |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 42 | virtual ~SkCachingPixelRef(); |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 43 | virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 44 | virtual void onUnlockPixels() SK_OVERRIDE; |
| 45 | virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 46 | |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 47 | virtual SkData* onRefEncodedData() SK_OVERRIDE { |
| 48 | return fImageGenerator->refEncodedData(); |
| 49 | } |
| 50 | // No need to flatten this object. When flattening an SkBitmap, |
| 51 | // SkOrderedWriteBuffer will check the encoded data and write that |
| 52 | // instead. |
| 53 | // Future implementations of SkFlattenableWriteBuffer will need to |
| 54 | // special case for onRefEncodedData as well. |
| 55 | SK_DECLARE_UNFLATTENABLE_OBJECT() |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 56 | |
| 57 | private: |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 58 | SkImageGenerator* const fImageGenerator; |
| 59 | bool fErrorInDecoding; |
| 60 | void* fScaledCacheId; |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 61 | const SkImageInfo fInfo; |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 62 | const size_t fRowBytes; |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 63 | |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 64 | SkCachingPixelRef(SkImageGenerator* imageGenerator, |
| 65 | const SkImageInfo& info, |
| 66 | size_t rowBytes); |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 67 | typedef SkPixelRef INHERITED; |
| 68 | }; |
| 69 | |
| 70 | #endif // SkCachingPixelRef_DEFINED |