blob: caaf2487de7ec51c1494d4e7fccae2d008e75862 [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
reed@google.com6965a0a2013-12-11 18:04:56 +000018 SkImageRef_GlobalPool(const SkImageInfo&, SkStreamRewindable*,
scroggo@google.comb5571b32013-09-25 21:34:24 +000019 int sampleSize = 1);
reed@android.com8a1c16f2008-12-17 15:59:43 +000020 virtual ~SkImageRef_GlobalPool();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000021
djsollen@google.com5370cd92012-03-28 20:47:01 +000022 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_GlobalPool)
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
24 // API to control the global pool
25
26 /** Return the amount specified as the budget for the cache (in bytes).
27 */
28 static size_t GetRAMBudget();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000029
reed@android.com8a1c16f2008-12-17 15:59:43 +000030 /** Set a new budget value for the cache.
31 */
32 static void SetRAMBudget(size_t);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000033
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 /** Return how much ram is currently in use by the global cache.
35 */
36 static size_t GetRAMUsed();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000037
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 /** Free up (approximately) enough such that the amount used by the cache
39 is <= the specified amount. Since some images may be "in use", the
40 amount actually freed may not always result in a ram usage value <=
41 to the requested amount. In addition, because of the
42 chunky nature of the cache, the resulting usage may be < the requested
43 amount.
44 */
45 static void SetRAMUsed(size_t usageInBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000046
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 static void DumpPool();
48
49protected:
scroggo@google.comb5571b32013-09-25 21:34:24 +000050 virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable* stream,
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 SkBitmap* bitmap, SkBitmap::Config config,
52 SkImageDecoder::Mode mode);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 virtual void onUnlockPixels();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 SkImageRef_GlobalPool(SkFlattenableReadBuffer&);
57
58private:
59 typedef SkImageRef INHERITED;
60};
61
62#endif