reed@google.com | dc731fd | 2010-12-23 15:19:47 +0000 | [diff] [blame] | 1 | /* |
reed@google.com | 57c3a86 | 2010-12-23 20:34:08 +0000 | [diff] [blame] | 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
reed@google.com | dc731fd | 2010-12-23 15:19:47 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #ifndef SkBitmapCache_DEFINED |
| 18 | #define SkBitmapCache_DEFINED |
| 19 | |
| 20 | #include "SkBitmap.h" |
| 21 | |
| 22 | class SkBitmapCache : SkNoncopyable { |
| 23 | public: |
| 24 | SkBitmapCache(int maxEntries); |
| 25 | ~SkBitmapCache(); |
| 26 | |
| 27 | bool find(const void* buffer, size_t len, SkBitmap*) const; |
| 28 | void add(const void* buffer, size_t len, const SkBitmap&); |
| 29 | |
| 30 | private: |
| 31 | int fEntryCount; |
| 32 | const int fMaxEntries; |
| 33 | |
| 34 | struct Entry; |
| 35 | mutable Entry* fHead; |
| 36 | mutable Entry* fTail; |
| 37 | |
| 38 | inline Entry* detach(Entry*) const; |
| 39 | inline void attachToHead(Entry*) const; |
| 40 | |
| 41 | #ifdef SK_DEBUG |
| 42 | void validate() const; |
| 43 | #else |
| 44 | void validate() const {} |
| 45 | #endif |
| 46 | |
| 47 | class AutoValidate : SkNoncopyable { |
| 48 | public: |
| 49 | AutoValidate(const SkBitmapCache* bc) : fBC(bc) { bc->validate(); } |
| 50 | ~AutoValidate() { fBC->validate(); } |
| 51 | private: |
| 52 | const SkBitmapCache* fBC; |
| 53 | }; |
| 54 | }; |
| 55 | |
| 56 | #endif |
| 57 | |