reed@google.com | dc731fd | 2010-12-23 15:19:47 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2010 Tetrark Inc. |
| 3 | */ |
| 4 | |
| 5 | #ifndef SkBitmapCache_DEFINED |
| 6 | #define SkBitmapCache_DEFINED |
| 7 | |
| 8 | #include "SkBitmap.h" |
| 9 | |
| 10 | class SkBitmapCache : SkNoncopyable { |
| 11 | public: |
| 12 | SkBitmapCache(int maxEntries); |
| 13 | ~SkBitmapCache(); |
| 14 | |
| 15 | bool find(const void* buffer, size_t len, SkBitmap*) const; |
| 16 | void add(const void* buffer, size_t len, const SkBitmap&); |
| 17 | |
| 18 | private: |
| 19 | int fEntryCount; |
| 20 | const int fMaxEntries; |
| 21 | |
| 22 | struct Entry; |
| 23 | mutable Entry* fHead; |
| 24 | mutable Entry* fTail; |
| 25 | |
| 26 | inline Entry* detach(Entry*) const; |
| 27 | inline void attachToHead(Entry*) const; |
| 28 | |
| 29 | #ifdef SK_DEBUG |
| 30 | void validate() const; |
| 31 | #else |
| 32 | void validate() const {} |
| 33 | #endif |
| 34 | |
| 35 | class AutoValidate : SkNoncopyable { |
| 36 | public: |
| 37 | AutoValidate(const SkBitmapCache* bc) : fBC(bc) { bc->validate(); } |
| 38 | ~AutoValidate() { fBC->validate(); } |
| 39 | private: |
| 40 | const SkBitmapCache* fBC; |
| 41 | }; |
| 42 | }; |
| 43 | |
| 44 | #endif |
| 45 | |