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 | |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 11 | #include "SkBitmapCache.h" |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 12 | #include "SkImageInfo.h" |
| 13 | #include "SkImageGenerator.h" |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 14 | #include "SkPixelRef.h" |
| 15 | |
| 16 | class SkColorTable; |
| 17 | |
| 18 | /** |
| 19 | * PixelRef which defers decoding until SkBitmap::lockPixels() is |
| 20 | * called. Caches the decoded images in the global |
| 21 | * SkScaledImageCache. When the pixels are unlocked, this cache may |
| 22 | * or be destroyed before the next lock. If so, onLockPixels will |
| 23 | * attempt to re-decode. |
| 24 | * |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 25 | * Decoding is handled by the SkImageGenerator |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 26 | */ |
| 27 | class SkCachingPixelRef : public SkPixelRef { |
| 28 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 29 | |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 30 | /** |
| 31 | * Takes ownership of SkImageGenerator. If this method fails for |
| 32 | * whatever reason, it will return false and immediatetely delete |
| 33 | * the generator. If it succeeds, it will modify destination |
| 34 | * bitmap. |
| 35 | * |
| 36 | * If Install fails or when the SkCachingPixelRef that is |
| 37 | * installed into destination is destroyed, it will call |
| 38 | * SkDELETE() on the generator. Therefore, generator should be |
| 39 | * allocated with SkNEW() or SkNEW_ARGS(). |
| 40 | */ |
| 41 | static bool Install(SkImageGenerator* gen, SkBitmap* dst); |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 42 | |
| 43 | protected: |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 44 | virtual ~SkCachingPixelRef(); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 45 | bool onNewLockPixels(LockRec*) override; |
| 46 | void onUnlockPixels() override; |
| 47 | bool onLockPixelsAreWritable() const override { return false; } |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 48 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 49 | SkData* onRefEncodedData() override { |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 50 | return fImageGenerator->refEncodedData(); |
| 51 | } |
reed | 9a9eae2 | 2014-07-07 14:32:06 -0700 | [diff] [blame] | 52 | |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 53 | private: |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 54 | SkImageGenerator* const fImageGenerator; |
| 55 | bool fErrorInDecoding; |
halcanary@google.com | 36d08c5 | 2013-12-05 14:00:03 +0000 | [diff] [blame] | 56 | const size_t fRowBytes; |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 57 | |
reed | 680fb9e | 2014-08-26 09:08:04 -0700 | [diff] [blame] | 58 | SkBitmap fLockedBitmap; |
| 59 | |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 60 | SkCachingPixelRef(const SkImageInfo&, SkImageGenerator*, size_t rowBytes); |
| 61 | |
commit-bot@chromium.org | 6e3e422 | 2013-11-06 10:08:30 +0000 | [diff] [blame] | 62 | typedef SkPixelRef INHERITED; |
| 63 | }; |
| 64 | |
| 65 | #endif // SkCachingPixelRef_DEFINED |