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