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 SkScalar scaleX, |
| 38 SkScalar scaleY, |
| 39 SkBitmap* scaled); |
| 40 |
34 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, | 41 static ID* FindAndLock(const SkBitmap& original, SkScalar scaleX, |
35 SkScalar scaleY, SkBitmap* scaled); | 42 SkScalar scaleY, SkBitmap* scaled); |
36 static ID* FindAndLockMip(const SkBitmap& original, SkMipMap const**); | 43 static ID* FindAndLockMip(const SkBitmap& original, SkMipMap const**); |
37 | 44 |
| 45 |
| 46 static ID* AddAndLock(uint32_t pixelGenerationID, |
| 47 int32_t width, |
| 48 int32_t height, |
| 49 SkScalar scaleX, |
| 50 SkScalar scaleY, |
| 51 const SkBitmap& scaled); |
| 52 |
38 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, | 53 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, |
39 SkScalar scaleY, const SkBitmap& scaled); | 54 SkScalar scaleY, const SkBitmap& scaled); |
40 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap*); | 55 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap*); |
41 | 56 |
42 static void Unlock(ID*); | 57 static void Unlock(ID*); |
43 | 58 |
44 static size_t GetBytesUsed(); | 59 static size_t GetBytesUsed(); |
45 static size_t GetByteLimit(); | 60 static size_t GetByteLimit(); |
46 static size_t SetByteLimit(size_t newLimit); | 61 static size_t SetByteLimit(size_t newLimit); |
47 | 62 |
48 /////////////////////////////////////////////////////////////////////////// | 63 /////////////////////////////////////////////////////////////////////////// |
49 | 64 |
50 SkScaledImageCache(size_t byteLimit); | 65 SkScaledImageCache(size_t byteLimit); |
51 ~SkScaledImageCache(); | 66 ~SkScaledImageCache(); |
52 | 67 |
53 /** | 68 /** |
54 * Search the cache for a scaled version of original. If found, return it | 69 * 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 | 70 * in scaled, and return its ID pointer. Use the returned ptr to unlock |
56 * the cache when you are done using scaled. | 71 * the cache when you are done using scaled. |
57 * | 72 * |
58 * If a match is not found, scaled will be unmodifed, and NULL will be | 73 * If a match is not found, scaled will be unmodifed, and NULL will be |
59 * returned. | 74 * returned. |
60 */ | 75 */ |
| 76 ID* findAndLock(uint32_t pixelGenerationID, |
| 77 int32_t width, |
| 78 int32_t height, |
| 79 SkScalar scaleX, |
| 80 SkScalar scaleY, |
| 81 SkBitmap* scaled); |
| 82 |
61 ID* findAndLock(const SkBitmap& original, SkScalar scaleX, | 83 ID* findAndLock(const SkBitmap& original, SkScalar scaleX, |
62 SkScalar scaleY, SkBitmap* scaled); | 84 SkScalar scaleY, SkBitmap* scaled); |
63 ID* findAndLockMip(const SkBitmap& original, SkMipMap const**); | 85 ID* findAndLockMip(const SkBitmap& original, SkMipMap const**); |
64 | 86 |
65 /** | 87 /** |
66 * To add a new (scaled) bitmap to the cache, call AddAndLock. Use the | 88 * 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. | 89 * returned ptr to unlock the cache when you are done using scaled. |
68 */ | 90 */ |
| 91 ID* addAndLock(uint32_t pixelGenerationID, |
| 92 int32_t width, |
| 93 int32_t height, |
| 94 SkScalar scaleX, |
| 95 SkScalar scaleY, |
| 96 const SkBitmap& scaled); |
69 ID* addAndLock(const SkBitmap& original, SkScalar scaleX, | 97 ID* addAndLock(const SkBitmap& original, SkScalar scaleX, |
70 SkScalar scaleY, const SkBitmap& scaled); | 98 SkScalar scaleY, const SkBitmap& scaled); |
71 ID* addAndLockMip(const SkBitmap& original, const SkMipMap*); | 99 ID* addAndLockMip(const SkBitmap& original, const SkMipMap*); |
72 | 100 |
73 /** | 101 /** |
74 * Given a non-null ID ptr returned by either findAndLock or addAndLock, | 102 * Given a non-null ID ptr returned by either findAndLock or addAndLock, |
75 * this releases the associated resources to be available to be purged | 103 * this releases the associated resources to be available to be purged |
76 * if needed. After this, the cached bitmap should no longer be | 104 * if needed. After this, the cached bitmap should no longer be |
77 * referenced by the caller. | 105 * referenced by the caller. |
78 */ | 106 */ |
(...skipping 29 matching lines...) Expand all Loading... |
108 // linklist management | 136 // linklist management |
109 void moveToHead(Rec*); | 137 void moveToHead(Rec*); |
110 void addToHead(Rec*); | 138 void addToHead(Rec*); |
111 void detach(Rec*); | 139 void detach(Rec*); |
112 #ifdef SK_DEBUG | 140 #ifdef SK_DEBUG |
113 void validate() const; | 141 void validate() const; |
114 #else | 142 #else |
115 void validate() const {} | 143 void validate() const {} |
116 #endif | 144 #endif |
117 }; | 145 }; |
118 | |
119 #endif | 146 #endif |
OLD | NEW |