Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 SkDiscardablePixelRef_DEFINED | 8 #ifndef SkDiscardablePixelRef_DEFINED |
| 9 #define SkDiscardablePixelRef_DEFINED | 9 #define SkDiscardablePixelRef_DEFINED |
| 10 | 10 |
| 11 #include "SkDiscardableMemory.h" | |
| 11 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" |
| 12 #include "SkImageGenerator.h" | 13 #include "SkImageGenerator.h" |
| 13 #include "SkImageInfo.h" | 14 #include "SkImageInfo.h" |
| 14 | 15 |
| 15 class SkDiscardableMemory; | |
| 16 | |
| 17 /** | 16 /** |
| 18 * An interface that allows a purgable PixelRef to re-decode an image. | 17 * An interface that allows a purgable PixelRef to re-decode an image. |
| 19 */ | 18 */ |
| 20 | 19 |
| 20 typedef SkDiscardableMemory* (*SkDiscardableMemoryFactory)(size_t bytes); | |
| 21 | |
| 22 | |
| 21 class SkDiscardablePixelRef : public SkPixelRef { | 23 class SkDiscardablePixelRef : public SkPixelRef { |
| 22 public: | 24 public: |
| 23 /** | 25 /** |
| 24 * Takes ownership of SkImageGenerator. If this method fails for | 26 * Takes ownership of SkImageGenerator. If this method fails for |
| 25 * whatever reason, it will return false and immediatetely delete | 27 * whatever reason, it will return false and immediatetely delete |
| 26 * the generator. If it succeeds, it will modify destination | 28 * the generator. If it succeeds, it will modify destination |
| 27 * bitmap. | 29 * bitmap. |
| 28 * | 30 * |
| 29 * If Install fails or when the SkDiscardablePixelRef that is | 31 * If Install fails or when the SkDiscardablePixelRef that is |
| 30 * installed into destination is destroyed, it will call | 32 * installed into destination is destroyed, it will call |
| 31 * SkDELETE() on the generator. Therefore, generator should be | 33 * SkDELETE() on the generator. Therefore, generator should be |
| 32 * allocated with SkNEW() or SkNEW_ARGS(). | 34 * allocated with SkNEW() or SkNEW_ARGS(). |
| 33 */ | 35 */ |
| 34 static bool Install(SkImageGenerator* generator, SkBitmap* destination); | 36 static bool Install(SkImageGenerator* generator, |
| 37 SkBitmap* destination, | |
| 38 SkDiscardableMemory::Factory* factory = NULL); | |
|
scroggo
2013/12/03 23:00:01
Can you add a comment about how the factory is use
hal.canary
2013/12/04 00:01:36
Done.
| |
| 35 | 39 |
| 36 SK_DECLARE_UNFLATTENABLE_OBJECT() | 40 SK_DECLARE_UNFLATTENABLE_OBJECT() |
| 37 | 41 |
| 38 protected: | 42 protected: |
| 39 ~SkDiscardablePixelRef(); | 43 ~SkDiscardablePixelRef(); |
| 40 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; | 44 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; |
| 41 virtual void onUnlockPixels() SK_OVERRIDE; | 45 virtual void onUnlockPixels() SK_OVERRIDE; |
| 42 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | 46 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
| 43 | 47 |
| 44 virtual SkData* onRefEncodedData() SK_OVERRIDE { | 48 virtual SkData* onRefEncodedData() SK_OVERRIDE { |
| 45 return fGenerator->refEncodedData(); | 49 return fGenerator->refEncodedData(); |
| 46 } | 50 } |
| 47 | 51 |
| 48 private: | 52 private: |
| 49 SkImageGenerator* const fGenerator; | 53 SkImageGenerator* const fGenerator; |
| 54 SkDiscardableMemory::Factory* const fDMFactory; | |
| 50 const SkImageInfo fInfo; | 55 const SkImageInfo fInfo; |
| 51 const size_t fSize; // size of memory to be allocated | 56 const size_t fSize; // size of memory to be allocated |
| 52 const size_t fRowBytes; | 57 const size_t fRowBytes; |
| 53 // These const members should not change over the life of the | 58 // These const members should not change over the life of the |
| 54 // PixelRef, since the SkBitmap doesn't expect them to change. | 59 // PixelRef, since the SkBitmap doesn't expect them to change. |
| 55 | 60 |
| 56 SkDiscardableMemory* fDiscardableMemory; | 61 SkDiscardableMemory* fDiscardableMemory; |
| 57 | 62 |
| 58 /* Takes ownership of SkImageGenerator. */ | 63 /* Takes ownership of SkImageGenerator. */ |
| 59 SkDiscardablePixelRef(SkImageGenerator* generator, | 64 SkDiscardablePixelRef(SkImageGenerator* generator, |
| 60 const SkImageInfo& info, | 65 const SkImageInfo& info, |
| 61 size_t size, | 66 size_t size, |
| 62 size_t rowBytes); | 67 size_t rowBytes, |
| 68 SkDiscardableMemory::Factory* factory); | |
| 63 }; | 69 }; |
| 64 #endif // SkDiscardablePixelRef_DEFINED | 70 #endif // SkDiscardablePixelRef_DEFINED |
| OLD | NEW |