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 #ifdef SK_DEBUG |
| 17 #define LAZY_CACHE_STATS 1 | |
| 18 #elif !defined(LAZY_CACHE_STATS) | |
| 19 #define LAZY_CACHE_STATS 0 | |
| 20 #endif | |
| 16 | 21 |
| 17 /** | 22 /** |
| 18 * An interface that allows a purgable PixelRef to re-decode an image. | 23 * An interface that allows a purgable PixelRef to re-decode an image. |
| 19 */ | 24 */ |
| 20 | 25 |
| 21 class SkDiscardablePixelRef : public SkPixelRef { | 26 class SkDiscardablePixelRef : public SkPixelRef { |
| 22 public: | 27 public: |
| 23 /** | 28 /** |
| 24 * Takes ownership of SkImageGenerator. If this method fails for | 29 * Takes ownership of SkImageGenerator. If this method fails for |
| 25 * whatever reason, it will return false and immediatetely delete | 30 * whatever reason, it will return false and immediatetely delete |
| 26 * the generator. If it succeeds, it will modify destination | 31 * the generator. If it succeeds, it will modify destination |
| 27 * bitmap. | 32 * bitmap. |
| 28 * | 33 * |
| 29 * If Install fails or when the SkDiscardablePixelRef that is | 34 * If Install fails or when the SkDiscardablePixelRef that is |
| 30 * installed into destination is destroyed, it will call | 35 * installed into destination is destroyed, it will call |
| 31 * SkDELETE() on the generator. Therefore, generator should be | 36 * SkDELETE() on the generator. Therefore, generator should be |
| 32 * allocated with SkNEW() or SkNEW_ARGS(). | 37 * allocated with SkNEW() or SkNEW_ARGS(). |
| 33 */ | 38 */ |
| 34 static bool Install(SkImageGenerator* generator, SkBitmap* destination); | 39 static bool Install(SkImageGenerator* generator, SkBitmap* destination, |
| 40 SkDiscardableMemory::Factory* factory = NULL); | |
|
scroggo
2013/12/02 19:00:09
Can you add a comment explaining how the factory i
| |
| 41 | |
| 42 #if LAZY_CACHE_STATS | |
| 43 static int32_t GetCacheHits() { return gCacheHits; } | |
| 44 static int32_t GetCacheMisses() { return gCacheMisses; } | |
| 45 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } | |
| 46 #endif | |
| 35 | 47 |
| 36 SK_DECLARE_UNFLATTENABLE_OBJECT() | 48 SK_DECLARE_UNFLATTENABLE_OBJECT() |
| 37 | 49 |
| 38 protected: | 50 protected: |
| 39 ~SkDiscardablePixelRef(); | 51 ~SkDiscardablePixelRef(); |
| 40 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; | 52 virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; |
| 41 virtual void onUnlockPixels() SK_OVERRIDE; | 53 virtual void onUnlockPixels() SK_OVERRIDE; |
| 42 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | 54 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
| 43 | 55 |
| 44 virtual SkData* onRefEncodedData() SK_OVERRIDE { | 56 virtual SkData* onRefEncodedData() SK_OVERRIDE { |
| 45 return fGenerator->refEncodedData(); | 57 return fGenerator->refEncodedData(); |
| 46 } | 58 } |
| 47 | 59 |
| 48 private: | 60 private: |
| 49 SkImageGenerator* const fGenerator; | 61 SkDiscardableMemory::Factory* const fDMFactory; |
| 50 const SkImageInfo fInfo; | 62 SkImageGenerator* const fGenerator; |
| 51 const size_t fSize; // size of memory to be allocated | 63 const SkImageInfo fInfo; |
| 52 const size_t fRowBytes; | 64 const size_t fSize; // size of allocation |
| 65 const size_t fRowBytes; | |
| 53 // These const members should not change over the life of the | 66 // These const members should not change over the life of the |
| 54 // PixelRef, since the SkBitmap doesn't expect them to change. | 67 // PixelRef, since the SkBitmap doesn't expect them to change. |
| 55 | 68 |
| 56 SkDiscardableMemory* fDiscardableMemory; | 69 SkDiscardableMemory* fDiscardableMemory; |
| 70 | |
| 71 #if LAZY_CACHE_STATS | |
| 72 static int32_t gCacheHits; | |
| 73 static int32_t gCacheMisses; | |
| 74 #endif | |
| 57 | 75 |
| 58 /* Takes ownership of SkImageGenerator. */ | 76 /* Takes ownership of SkImageGenerator. */ |
| 59 SkDiscardablePixelRef(SkImageGenerator* generator, | 77 SkDiscardablePixelRef(SkDiscardableMemory::Factory* factory, |
| 78 SkImageGenerator* generator, | |
| 60 const SkImageInfo& info, | 79 const SkImageInfo& info, |
| 61 size_t size, | 80 size_t size, |
| 62 size_t rowBytes); | 81 size_t rowBytes); |
| 63 }; | 82 }; |
| 64 #endif // SkDiscardablePixelRef_DEFINED | 83 #endif // SkDiscardablePixelRef_DEFINED |
| OLD | NEW |