| 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 SkImageCache_DEFINED | 8 #ifndef SkImageCache_DEFINED |
| 9 #define SkImageCache_DEFINED | 9 #define SkImageCache_DEFINED |
| 10 | 10 |
| 11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
| 12 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Interface for a cache that manages pixel memory. | 15 * Interface for a cache that manages pixel memory. |
| 16 */ | 16 */ |
| 17 class SkImageCache : public SkRefCnt { | 17 class SkImageCache : public SkRefCnt { |
| 18 | 18 |
| 19 public: | 19 public: |
| 20 typedef intptr_t ID; |
| 21 |
| 20 /** | 22 /** |
| 21 * Allocate memory whose lifetime is managed by the cache. On success, MUST
be balanced with a | 23 * Allocate memory whose lifetime is managed by the cache. On success, MUST
be balanced with a |
| 22 * call to releaseCache and a call to throwAwayCache. | 24 * call to releaseCache and a call to throwAwayCache. |
| 23 * @param bytes Number of bytes needed. | 25 * @param bytes Number of bytes needed. |
| 24 * @param ID Output parameter which must not be NULL. On success, ID will b
e set to a value | 26 * @param ID Output parameter which must not be NULL. On success, ID will b
e set to a value |
| 25 * associated with that memory which can be used as a parameter to the
other functions | 27 * associated with that memory which can be used as a parameter to the
other functions |
| 26 * in SkImageCache. On failure, ID is unchanged. | 28 * in SkImageCache. On failure, ID is unchanged. |
| 27 * @return Pointer to the newly allocated memory, or NULL. This memory is s
afe to use until | 29 * @return Pointer to the newly allocated memory, or NULL. This memory is s
afe to use until |
| 28 * releaseCache is called with ID. | 30 * releaseCache is called with ID. |
| 29 */ | 31 */ |
| 30 virtual void* allocAndPinCache(size_t bytes, intptr_t* ID) = 0; | 32 virtual void* allocAndPinCache(size_t bytes, ID*) = 0; |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * Output parameter for pinCache, stating whether the memory still contains
the data it held | 35 * Output parameter for pinCache, stating whether the memory still contains
the data it held |
| 34 * when releaseCache was last called for the same ID. | 36 * when releaseCache was last called for the same ID. |
| 35 */ | 37 */ |
| 36 enum DataStatus { | 38 enum DataStatus { |
| 37 /** | 39 /** |
| 38 * The data has been purged, and therefore needs to be rewritten to the
returned memory. | 40 * The data has been purged, and therefore needs to be rewritten to the
returned memory. |
| 39 */ | 41 */ |
| 40 kUninitialized_DataStatus, | 42 kUninitialized_DataStatus, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 53 * @param status Output parameter which must not be NULL. On success (i.e.
the return value is | 55 * @param status Output parameter which must not be NULL. On success (i.e.
the return value is |
| 54 * not NULL), status will be set to one of two states representing the
cached memory. If | 56 * not NULL), status will be set to one of two states representing the
cached memory. If |
| 55 * status is set to kRetained_DataStatus, the memory contains the same
data it did | 57 * status is set to kRetained_DataStatus, the memory contains the same
data it did |
| 56 * before releaseCache was called with this ID. If status is set to | 58 * before releaseCache was called with this ID. If status is set to |
| 57 * kUninitialized_DataStatus, the memory is still pinned, but the previ
ous data is no | 59 * kUninitialized_DataStatus, the memory is still pinned, but the previ
ous data is no |
| 58 * longer available. If the return value is NULL, status is unchanged. | 60 * longer available. If the return value is NULL, status is unchanged. |
| 59 * @return Pointer: If non-NULL, points to the previously allocated memory,
in which case | 61 * @return Pointer: If non-NULL, points to the previously allocated memory,
in which case |
| 60 * this call must be balanced with a call to releaseCache. If NULL, the
memory | 62 * this call must be balanced with a call to releaseCache. If NULL, the
memory |
| 61 * has been reclaimed, and throwAwayCache MUST NOT be called. | 63 * has been reclaimed, and throwAwayCache MUST NOT be called. |
| 62 */ | 64 */ |
| 63 virtual void* pinCache(intptr_t ID, DataStatus* status) = 0; | 65 virtual void* pinCache(ID, DataStatus* status) = 0; |
| 64 | 66 |
| 65 /** | 67 /** |
| 66 * Inform the cache that it is safe to free the block of memory correspondi
ng to ID. After | 68 * Inform the cache that it is safe to free the block of memory correspondi
ng to ID. After |
| 67 * calling this function, the pointer returned by allocAndPinCache or pinCa
che must not be | 69 * calling this function, the pointer returned by allocAndPinCache or pinCa
che must not be |
| 68 * used again. In order to access the same memory after this, pinCache must
be called with | 70 * used again. In order to access the same memory after this, pinCache must
be called with |
| 69 * the same ID. | 71 * the same ID. |
| 70 * @param ID Unique ID for the memory block which is now safe to age out of
the cache. | 72 * @param ID Unique ID for the memory block which is now safe to age out of
the cache. |
| 71 */ | 73 */ |
| 72 virtual void releaseCache(intptr_t ID) = 0; | 74 virtual void releaseCache(ID) = 0; |
| 73 | 75 |
| 74 /** | 76 /** |
| 75 * Inform the cache that the block of memory associated with ID will not be
asked for again. | 77 * Inform the cache that the block of memory associated with ID will not be
asked for again. |
| 76 * After this call, ID is no longer valid. Must not be called while the ass
ociated memory is | 78 * After this call, ID is no longer valid. Must not be called while the ass
ociated memory is |
| 77 * pinned. Must be called to balance a successful allocAndPinCache. | 79 * pinned. Must be called to balance a successful allocAndPinCache. |
| 78 */ | 80 */ |
| 79 virtual void throwAwayCache(intptr_t ID) = 0; | 81 virtual void throwAwayCache(ID) = 0; |
| 80 | 82 |
| 81 /** | 83 /** |
| 82 * ID which does not correspond to any valid cache. | 84 * ID which does not correspond to any valid cache. |
| 83 */ | 85 */ |
| 84 static const intptr_t UNINITIALIZED_ID = 0; | 86 static const ID UNINITIALIZED_ID = 0; |
| 85 | 87 |
| 86 #ifdef SK_DEBUG | 88 #ifdef SK_DEBUG |
| 87 /** | 89 /** |
| 88 * Debug only status of a memory block. | 90 * Debug only status of a memory block. |
| 89 */ | 91 */ |
| 90 enum MemoryStatus { | 92 enum MemoryStatus { |
| 91 /** | 93 /** |
| 92 * It is safe to use the pointer returned by the most recent of allocAn
dPinCache(ID) or | 94 * It is safe to use the pointer returned by the most recent of allocAn
dPinCache(ID) or |
| 93 * pinCache(ID) with the same ID. | 95 * pinCache(ID) with the same ID. |
| 94 */ | 96 */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 116 */ | 118 */ |
| 117 virtual MemoryStatus getMemoryStatus(intptr_t ID) const = 0; | 119 virtual MemoryStatus getMemoryStatus(intptr_t ID) const = 0; |
| 118 | 120 |
| 119 /** | 121 /** |
| 120 * Debug only function to clear all unpinned caches. | 122 * Debug only function to clear all unpinned caches. |
| 121 */ | 123 */ |
| 122 virtual void purgeAllUnpinnedCaches() = 0; | 124 virtual void purgeAllUnpinnedCaches() = 0; |
| 123 #endif | 125 #endif |
| 124 }; | 126 }; |
| 125 #endif // SkImageCache_DEFINED | 127 #endif // SkImageCache_DEFINED |
| OLD | NEW |