blob: 909ee71050f5a078f5221d8f9a3c5bb8ef1476d3 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2008 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkImageRef_GlobalPool_DEFINED
11#define SkImageRef_GlobalPool_DEFINED
12
13#include "SkImageRef.h"
14
15class SkImageRef_GlobalPool : public SkImageRef {
16public:
17 // if pool is null, use the global pool
18 SkImageRef_GlobalPool(SkStream*, SkBitmap::Config, int sampleSize = 1);
19 virtual ~SkImageRef_GlobalPool();
20
21 // overrides
22 virtual Factory getFactory() const {
23 return Create;
24 }
25 static SkPixelRef* Create(SkFlattenableReadBuffer&);
caryclark@google.comd26147a2011-12-15 14:16:43 +000026
27 SK_DECLARE_PIXEL_REF_REGISTRAR()
reed@android.com8a1c16f2008-12-17 15:59:43 +000028
29 // API to control the global pool
30
31 /** Return the amount specified as the budget for the cache (in bytes).
32 */
33 static size_t GetRAMBudget();
34
35 /** Set a new budget value for the cache.
36 */
37 static void SetRAMBudget(size_t);
38
39 /** Return how much ram is currently in use by the global cache.
40 */
41 static size_t GetRAMUsed();
42
43 /** Free up (approximately) enough such that the amount used by the cache
44 is <= the specified amount. Since some images may be "in use", the
45 amount actually freed may not always result in a ram usage value <=
46 to the requested amount. In addition, because of the
47 chunky nature of the cache, the resulting usage may be < the requested
48 amount.
49 */
50 static void SetRAMUsed(size_t usageInBytes);
51
52 static void DumpPool();
53
54protected:
55 virtual bool onDecode(SkImageDecoder* codec, SkStream* stream,
56 SkBitmap* bitmap, SkBitmap::Config config,
57 SkImageDecoder::Mode mode);
58
59 virtual void onUnlockPixels();
60
61 SkImageRef_GlobalPool(SkFlattenableReadBuffer&);
62
63private:
64 typedef SkImageRef INHERITED;
65};
66
67#endif