blob: 1e74a6d077c2ed70ded2a0f9afbdf1bfc8701953 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 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.
7 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkImageRefPool_DEFINED
9#define SkImageRefPool_DEFINED
10
11#include "SkTypes.h"
12
13class SkImageRef;
14class SkImageRef_GlobalPool;
15
16class SkImageRefPool {
17public:
18 SkImageRefPool();
19 ~SkImageRefPool();
rmistry@google.comd6176b02012-08-23 18:14:13 +000020
reed@android.com8a1c16f2008-12-17 15:59:43 +000021 size_t getRAMBudget() const { return fRAMBudget; }
22 void setRAMBudget(size_t);
rmistry@google.comd6176b02012-08-23 18:14:13 +000023
reed@android.com8a1c16f2008-12-17 15:59:43 +000024 size_t getRAMUsed() const { return fRAMUsed; }
25 void setRAMUsed(size_t limit);
rmistry@google.comd6176b02012-08-23 18:14:13 +000026
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 void addToHead(SkImageRef*);
28 void addToTail(SkImageRef*);
29 void detach(SkImageRef*);
30
31 void dump() const;
rmistry@google.comd6176b02012-08-23 18:14:13 +000032
reed@android.com8a1c16f2008-12-17 15:59:43 +000033private:
34 size_t fRAMBudget;
35 size_t fRAMUsed;
rmistry@google.comd6176b02012-08-23 18:14:13 +000036
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 int fCount;
38 SkImageRef* fHead, *fTail;
rmistry@google.comd6176b02012-08-23 18:14:13 +000039
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 int computeCount() const;
rmistry@google.comd6176b02012-08-23 18:14:13 +000041
reed@android.com8a1c16f2008-12-17 15:59:43 +000042 friend class SkImageRef_GlobalPool;
rmistry@google.comd6176b02012-08-23 18:14:13 +000043
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 void justAddedPixels(SkImageRef*);
45 void canLosePixels(SkImageRef*);
46 void purgeIfNeeded();
47};
48
49#endif