blob: 2c8b0c2fdd628117a6a49fe2ac78a46e9d24ea31 [file] [log] [blame]
reed@google.comdc731fd2010-12-23 15:19:47 +00001/*
reed@google.com57c3a862010-12-23 20:34:08 +00002 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.comdc731fd2010-12-23 15:19:47 +000015 */
16
17#ifndef SkBitmapCache_DEFINED
18#define SkBitmapCache_DEFINED
19
20#include "SkBitmap.h"
21
22class SkBitmapCache : SkNoncopyable {
23public:
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
30private:
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