| 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 SkAshmemImageCache_DEFINED | 8 #ifndef SkAshmemImageCache_DEFINED |
| 9 #define SkAshmemImageCache_DEFINED | 9 #define SkAshmemImageCache_DEFINED |
| 10 | 10 |
| 11 #include "SkImageCache.h" | 11 #include "SkImageCache.h" |
| 12 #include "SkTDArray.h" | |
| 13 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 14 | 13 |
| 14 #ifdef SK_DEBUG |
| 15 #include "SkTDArray.h" |
| 16 #endif |
| 17 |
| 15 class SkAshmemImageCache : public SkImageCache { | 18 class SkAshmemImageCache : public SkImageCache { |
| 16 | 19 |
| 17 public: | 20 public: |
| 18 /** | 21 /** |
| 19 * Get a pointer to the single global instance of SkAshmemImageCache. | 22 * Get a pointer to the single global instance of SkAshmemImageCache. |
| 20 */ | 23 */ |
| 21 static SkAshmemImageCache* GetAshmemImageCache(); | 24 static SkAshmemImageCache* GetAshmemImageCache(); |
| 22 | 25 |
| 23 virtual void* allocAndPinCache(size_t bytes, intptr_t* ID) SK_OVERRIDE; | 26 virtual void* allocAndPinCache(size_t bytes, intptr_t* ID) SK_OVERRIDE; |
| 24 virtual void* pinCache(intptr_t ID) SK_OVERRIDE; | 27 virtual void* pinCache(intptr_t ID, PurgeStatus* status) SK_OVERRIDE; |
| 25 virtual void releaseCache(intptr_t ID) SK_OVERRIDE; | 28 virtual void releaseCache(intptr_t ID) SK_OVERRIDE; |
| 26 virtual void throwAwayCache(intptr_t ID) SK_OVERRIDE; | 29 virtual void throwAwayCache(intptr_t ID) SK_OVERRIDE; |
| 27 | 30 |
| 28 #ifdef SK_DEBUG | 31 #ifdef SK_DEBUG |
| 29 SkImageCache::CacheStatus getCacheStatus(intptr_t ID) const SK_OVERRIDE; | 32 SkImageCache::PinStatus getPinStatus(intptr_t ID) const SK_OVERRIDE; |
| 30 | 33 virtual void purgeAllCaches() SK_OVERRIDE; |
| 31 virtual ~SkAshmemImageCache(); | 34 virtual ~SkAshmemImageCache(); |
| 32 #endif | 35 #endif |
| 33 | 36 |
| 34 private: | 37 private: |
| 35 struct AshmemRec { | 38 struct AshmemRec { |
| 36 int fFD; | 39 int fFD; |
| 37 void* fAddr; | 40 void* fAddr; |
| 38 size_t fSize; | 41 size_t fSize; |
| 39 #ifdef SK_DEBUG | 42 #ifdef SK_DEBUG |
| 40 bool fPinned; | 43 bool fPinned; |
| 41 | 44 |
| 42 static int Compare(const AshmemRec*, const AshmemRec*); | 45 static int Compare(const AshmemRec*, const AshmemRec*); |
| 43 #endif | 46 #endif |
| 44 }; | 47 }; |
| 45 | 48 |
| 46 /** | 49 /** |
| 47 * Constructor is private. The correct way to get this cache is through | 50 * Constructor is private. The correct way to get this cache is through |
| 48 * GetAshmemImageCache, so that all callers can get the single global. | 51 * GetAshmemImageCache, so that all callers can get the single global. |
| 49 */ | 52 */ |
| 50 SkAshmemImageCache(); | 53 SkAshmemImageCache(); |
| 51 | 54 |
| 55 /** |
| 56 * Destroy the cache associated with ID completely. Assumes the mutex is |
| 57 * already locked. |
| 58 */ |
| 59 void throwAwayCacheInternal(intptr_t ID); |
| 60 |
| 52 #ifdef SK_DEBUG | 61 #ifdef SK_DEBUG |
| 53 // Stores a list of AshmemRecs to track deletion. | 62 // Stores a list of AshmemRecs to track deletion. |
| 54 SkTDArray<AshmemRec*> fRecs; | 63 SkTDArray<AshmemRec*> fRecs; |
| 55 | 64 |
| 56 /** | 65 /** |
| 57 * Debug only function to add an AshmemRec to the list. | 66 * Debug only function to add an AshmemRec to the list. |
| 58 */ | 67 */ |
| 59 void appendRec(AshmemRec*); | 68 void appendRec(AshmemRec*); |
| 60 | 69 |
| 61 /** | 70 /** |
| 62 * Return the index of AshmemRec. | 71 * Return the index of AshmemRec. |
| 63 */ | 72 */ |
| 64 int findRec(const AshmemRec*) const; | 73 int findRec(const AshmemRec*) const; |
| 74 |
| 65 #endif | 75 #endif |
| 66 | |
| 67 /** | |
| 68 * Deletes AshmemRec. In debug, also removes from the list. | |
| 69 */ | |
| 70 void removeRec(AshmemRec*); | |
| 71 }; | 76 }; |
| 72 #endif // SkAshmemImageCache_DEFINED | 77 #endif // SkAshmemImageCache_DEFINED |
| OLD | NEW |