| 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 SkScaledImageCache_DEFINED | 8 #ifndef SkScaledImageCache_DEFINED |
| 9 #define SkScaledImageCache_DEFINED | 9 #define SkScaledImageCache_DEFINED |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 class SkScaledImageCache { | 25 class SkScaledImageCache { |
| 26 public: | 26 public: |
| 27 struct ID; | 27 struct ID; |
| 28 | 28 |
| 29 /* | 29 /* |
| 30 * The following static methods are thread-safe wrappers around a global | 30 * The following static methods are thread-safe wrappers around a global |
| 31 * instance of this cache. | 31 * instance of this cache. |
| 32 */ | 32 */ |
| 33 | 33 |
| 34 static ID* FindAndLock(uint32_t pixelGenerationID, |
| 35 int32_t width, |
| 36 int32_t height, |
| 37 SkBitmap* scaled); |
| 38 |
| 34 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, | 39 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, |
| 35 SkScalar scaleY, SkBitmap* scaled); | 40 SkScalar scaleY, SkBitmap* scaled); |
| 36 static ID* FindAndLockMip(const SkBitmap& original, SkMipMap const**); | 41 static ID* FindAndLockMip(const SkBitmap& original, SkMipMap const**); |
| 37 | 42 |
| 43 |
| 44 static ID* AddAndLock(uint32_t pixelGenerationID, |
| 45 int32_t width, |
| 46 int32_t height, |
| 47 const SkBitmap& scaled); |
| 48 |
| 38 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, | 49 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, |
| 39 SkScalar scaleY, const SkBitmap& scaled); | 50 SkScalar scaleY, const SkBitmap& scaled); |
| 40 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap*); | 51 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap*); |
| 41 | 52 |
| 42 static void Unlock(ID*); | 53 static void Unlock(ID*); |
| 43 | 54 |
| 44 static size_t GetBytesUsed(); | 55 static size_t GetBytesUsed(); |
| 45 static size_t GetByteLimit(); | 56 static size_t GetByteLimit(); |
| 46 static size_t SetByteLimit(size_t newLimit); | 57 static size_t SetByteLimit(size_t newLimit); |
| 47 | 58 |
| 48 /////////////////////////////////////////////////////////////////////////// | 59 /////////////////////////////////////////////////////////////////////////// |
| 49 | 60 |
| 50 SkScaledImageCache(size_t byteLimit); | 61 SkScaledImageCache(size_t byteLimit); |
| 51 ~SkScaledImageCache(); | 62 ~SkScaledImageCache(); |
| 52 | 63 |
| 53 /** | 64 /** |
| 54 * Search the cache for a scaled version of original. If found, return it | 65 * Search the cache for a scaled version of original. If found, return it |
| 55 * in scaled, and return its ID pointer. Use the returned ptr to unlock | 66 * in scaled, and return its ID pointer. Use the returned ptr to unlock |
| 56 * the cache when you are done using scaled. | 67 * the cache when you are done using scaled. |
| 57 * | 68 * |
| 58 * If a match is not found, scaled will be unmodifed, and NULL will be | 69 * If a match is not found, scaled will be unmodifed, and NULL will be |
| 59 * returned. | 70 * returned. |
| 60 */ | 71 */ |
| 72 ID* findAndLock(uint32_t pixelGenerationID, |
| 73 int32_t width, |
| 74 int32_t height, |
| 75 SkBitmap* scaled); |
| 76 |
| 61 ID* findAndLock(const SkBitmap& original, SkScalar scaleX, | 77 ID* findAndLock(const SkBitmap& original, SkScalar scaleX, |
| 62 SkScalar scaleY, SkBitmap* scaled); | 78 SkScalar scaleY, SkBitmap* scaled); |
| 63 ID* findAndLockMip(const SkBitmap& original, SkMipMap const**); | 79 ID* findAndLockMip(const SkBitmap& original, SkMipMap const**); |
| 64 | 80 |
| 65 /** | 81 /** |
| 66 * To add a new (scaled) bitmap to the cache, call AddAndLock. Use the | 82 * To add a new (scaled) bitmap to the cache, call AddAndLock. Use the |
| 67 * returned ptr to unlock the cache when you are done using scaled. | 83 * returned ptr to unlock the cache when you are done using scaled. |
| 68 */ | 84 */ |
| 85 ID* addAndLock(uint32_t pixelGenerationID, |
| 86 int32_t width, |
| 87 int32_t height, |
| 88 const SkBitmap& scaled); |
| 69 ID* addAndLock(const SkBitmap& original, SkScalar scaleX, | 89 ID* addAndLock(const SkBitmap& original, SkScalar scaleX, |
| 70 SkScalar scaleY, const SkBitmap& scaled); | 90 SkScalar scaleY, const SkBitmap& scaled); |
| 71 ID* addAndLockMip(const SkBitmap& original, const SkMipMap*); | 91 ID* addAndLockMip(const SkBitmap& original, const SkMipMap*); |
| 72 | 92 |
| 73 /** | 93 /** |
| 74 * Given a non-null ID ptr returned by either findAndLock or addAndLock, | 94 * Given a non-null ID ptr returned by either findAndLock or addAndLock, |
| 75 * this releases the associated resources to be available to be purged | 95 * this releases the associated resources to be available to be purged |
| 76 * if needed. After this, the cached bitmap should no longer be | 96 * if needed. After this, the cached bitmap should no longer be |
| 77 * referenced by the caller. | 97 * referenced by the caller. |
| 78 */ | 98 */ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 108 // linklist management | 128 // linklist management |
| 109 void moveToHead(Rec*); | 129 void moveToHead(Rec*); |
| 110 void addToHead(Rec*); | 130 void addToHead(Rec*); |
| 111 void detach(Rec*); | 131 void detach(Rec*); |
| 112 #ifdef SK_DEBUG | 132 #ifdef SK_DEBUG |
| 113 void validate() const; | 133 void validate() const; |
| 114 #else | 134 #else |
| 115 void validate() const {} | 135 void validate() const {} |
| 116 #endif | 136 #endif |
| 117 }; | 137 }; |
| 118 | |
| 119 #endif | 138 #endif |
| OLD | NEW |