halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +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 SkDiscardablePixelRef_DEFINED |
| 9 | #define SkDiscardablePixelRef_DEFINED |
| 10 | |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 11 | #include "SkDiscardableMemory.h" |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 12 | #include "SkImageGenerator.h" |
| 13 | #include "SkImageInfo.h" |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 14 | #include "SkPixelRef.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 15 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 16 | /** |
| 17 | * A PixelRef backed by SkDiscardableMemory, with the ability to |
| 18 | * re-generate the pixels (via a SkImageGenerator) if the DM is |
| 19 | * purged. |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 20 | */ |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 21 | class SkDiscardablePixelRef : public SkPixelRef { |
| 22 | public: |
commit-bot@chromium.org | 227c246 | 2014-01-24 18:33:07 +0000 | [diff] [blame] | 23 | SK_DECLARE_INST_COUNT(SkDiscardablePixelRef) |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 24 | SK_DECLARE_UNFLATTENABLE_OBJECT() |
| 25 | |
| 26 | protected: |
| 27 | ~SkDiscardablePixelRef(); |
reed@google.com | d0419b1 | 2014-01-06 17:08:27 +0000 | [diff] [blame] | 28 | |
| 29 | virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 30 | virtual void onUnlockPixels() SK_OVERRIDE; |
| 31 | virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
| 32 | |
| 33 | virtual SkData* onRefEncodedData() SK_OVERRIDE { |
| 34 | return fGenerator->refEncodedData(); |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | SkImageGenerator* const fGenerator; |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 39 | SkDiscardableMemory::Factory* const fDMFactory; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 40 | const size_t fRowBytes; |
| 41 | // These const members should not change over the life of the |
| 42 | // PixelRef, since the SkBitmap doesn't expect them to change. |
| 43 | |
| 44 | SkDiscardableMemory* fDiscardableMemory; |
commit-bot@chromium.org | b263985 | 2014-05-28 16:01:55 +0000 | [diff] [blame^] | 45 | SkAutoTUnref<SkColorTable> fCTable; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 46 | |
| 47 | /* Takes ownership of SkImageGenerator. */ |
reed@google.com | bf79023 | 2013-12-13 19:45:58 +0000 | [diff] [blame] | 48 | SkDiscardablePixelRef(const SkImageInfo&, SkImageGenerator*, |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 49 | size_t rowBytes, |
| 50 | SkDiscardableMemory::Factory* factory); |
reed@google.com | d0419b1 | 2014-01-06 17:08:27 +0000 | [diff] [blame] | 51 | |
commit-bot@chromium.org | 2d970b5 | 2014-05-27 14:14:22 +0000 | [diff] [blame] | 52 | friend bool SkInstallDiscardablePixelRef(SkImageGenerator*, SkBitmap*, |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 53 | SkDiscardableMemory::Factory*); |
reed@google.com | d0419b1 | 2014-01-06 17:08:27 +0000 | [diff] [blame] | 54 | |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 55 | typedef SkPixelRef INHERITED; |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 56 | }; |
reed@google.com | d0419b1 | 2014-01-06 17:08:27 +0000 | [diff] [blame] | 57 | |
halcanary@google.com | ad04eb4 | 2013-11-21 15:32:08 +0000 | [diff] [blame] | 58 | #endif // SkDiscardablePixelRef_DEFINED |