blob: 914b0eb4350d7b0f36ffcc88aa5c6db3b1a79646 [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();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000020
djsollen@google.com5370cd92012-03-28 20:47:01 +000021 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_GlobalPool)
reed@android.com8a1c16f2008-12-17 15:59:43 +000022
23 // API to control the global pool
24
25 /** Return the amount specified as the budget for the cache (in bytes).
26 */
27 static size_t GetRAMBudget();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000028
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 /** Set a new budget value for the cache.
30 */
31 static void SetRAMBudget(size_t);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000032
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 /** Return how much ram is currently in use by the global cache.
34 */
35 static size_t GetRAMUsed();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000036
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 /** Free up (approximately) enough such that the amount used by the cache
38 is <= the specified amount. Since some images may be "in use", the
39 amount actually freed may not always result in a ram usage value <=
40 to the requested amount. In addition, because of the
41 chunky nature of the cache, the resulting usage may be < the requested
42 amount.
43 */
44 static void SetRAMUsed(size_t usageInBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000045
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 static void DumpPool();
47
48protected:
49 virtual bool onDecode(SkImageDecoder* codec, SkStream* stream,
50 SkBitmap* bitmap, SkBitmap::Config config,
51 SkImageDecoder::Mode mode);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000052
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 virtual void onUnlockPixels();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000054
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 SkImageRef_GlobalPool(SkFlattenableReadBuffer&);
56
57private:
58 typedef SkImageRef INHERITED;
59};
60
61#endif