epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | dc731fd | 2010-12-23 15:19:47 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | dc731fd | 2010-12-23 15:19:47 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | dc731fd | 2010-12-23 15:19:47 +0000 | [diff] [blame] | 10 | #ifndef SkBitmapCache_DEFINED |
| 11 | #define SkBitmapCache_DEFINED |
| 12 | |
| 13 | #include "SkBitmap.h" |
| 14 | |
| 15 | class SkBitmapCache : SkNoncopyable { |
| 16 | public: |
| 17 | SkBitmapCache(int maxEntries); |
| 18 | ~SkBitmapCache(); |
| 19 | |
| 20 | bool find(const void* buffer, size_t len, SkBitmap*) const; |
| 21 | void add(const void* buffer, size_t len, const SkBitmap&); |
| 22 | |
| 23 | private: |
| 24 | int fEntryCount; |
| 25 | const int fMaxEntries; |
| 26 | |
| 27 | struct Entry; |
| 28 | mutable Entry* fHead; |
| 29 | mutable Entry* fTail; |
| 30 | |
| 31 | inline Entry* detach(Entry*) const; |
| 32 | inline void attachToHead(Entry*) const; |
| 33 | |
| 34 | #ifdef SK_DEBUG |
| 35 | void validate() const; |
| 36 | #else |
| 37 | void validate() const {} |
| 38 | #endif |
| 39 | |
| 40 | class AutoValidate : SkNoncopyable { |
| 41 | public: |
| 42 | AutoValidate(const SkBitmapCache* bc) : fBC(bc) { bc->validate(); } |
| 43 | ~AutoValidate() { fBC->validate(); } |
| 44 | private: |
| 45 | const SkBitmapCache* fBC; |
| 46 | }; |
| 47 | }; |
| 48 | |
| 49 | #endif |
| 50 | |