blob: 0dcd32272e6f70a8a7015975b924a671f187de55 [file] [log] [blame]
reed@google.comdc731fd2010-12-23 15:19:47 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.
reed@google.comdc731fd2010-12-23 15:19:47 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reeda6cac4c2014-08-21 10:50:25 -07009#ifndef SkGradientBitmapCache_DEFINED
10#define SkGradientBitmapCache_DEFINED
reed@google.comdc731fd2010-12-23 15:19:47 +000011
12#include "SkBitmap.h"
13
reeda6cac4c2014-08-21 10:50:25 -070014class SkGradientBitmapCache : SkNoncopyable {
reed@google.comdc731fd2010-12-23 15:19:47 +000015public:
reeda6cac4c2014-08-21 10:50:25 -070016 SkGradientBitmapCache(int maxEntries);
17 ~SkGradientBitmapCache();
reed@google.comdc731fd2010-12-23 15:19:47 +000018
19 bool find(const void* buffer, size_t len, SkBitmap*) const;
20 void add(const void* buffer, size_t len, const SkBitmap&);
21
22private:
23 int fEntryCount;
24 const int fMaxEntries;
25
26 struct Entry;
27 mutable Entry* fHead;
28 mutable Entry* fTail;
29
mtklein18300a32016-03-16 13:53:35 -070030 inline Entry* release(Entry*) const;
reed@google.comdc731fd2010-12-23 15:19:47 +000031 inline void attachToHead(Entry*) const;
32
33#ifdef SK_DEBUG
34 void validate() const;
35#else
36 void validate() const {}
37#endif
38
39 class AutoValidate : SkNoncopyable {
40 public:
reeda6cac4c2014-08-21 10:50:25 -070041 AutoValidate(const SkGradientBitmapCache* bc) : fBC(bc) { bc->validate(); }
reed@google.comdc731fd2010-12-23 15:19:47 +000042 ~AutoValidate() { fBC->validate(); }
43 private:
reeda6cac4c2014-08-21 10:50:25 -070044 const SkGradientBitmapCache* fBC;
reed@google.comdc731fd2010-12-23 15:19:47 +000045 };
46};
47
48#endif