blob: a9d4dcec389d96930b66304593e6cab709c9d675 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkImageRef_GlobalPool_DEFINED
18#define SkImageRef_GlobalPool_DEFINED
19
20#include "SkImageRef.h"
21
22class SkImageRef_GlobalPool : public SkImageRef {
23public:
24 // if pool is null, use the global pool
25 SkImageRef_GlobalPool(SkStream*, SkBitmap::Config, int sampleSize = 1);
26 virtual ~SkImageRef_GlobalPool();
27
28 // overrides
29 virtual Factory getFactory() const {
30 return Create;
31 }
32 static SkPixelRef* Create(SkFlattenableReadBuffer&);
33
34 // API to control the global pool
35
36 /** Return the amount specified as the budget for the cache (in bytes).
37 */
38 static size_t GetRAMBudget();
39
40 /** Set a new budget value for the cache.
41 */
42 static void SetRAMBudget(size_t);
43
44 /** Return how much ram is currently in use by the global cache.
45 */
46 static size_t GetRAMUsed();
47
48 /** Free up (approximately) enough such that the amount used by the cache
49 is <= the specified amount. Since some images may be "in use", the
50 amount actually freed may not always result in a ram usage value <=
51 to the requested amount. In addition, because of the
52 chunky nature of the cache, the resulting usage may be < the requested
53 amount.
54 */
55 static void SetRAMUsed(size_t usageInBytes);
56
57 static void DumpPool();
58
59protected:
60 virtual bool onDecode(SkImageDecoder* codec, SkStream* stream,
61 SkBitmap* bitmap, SkBitmap::Config config,
62 SkImageDecoder::Mode mode);
63
64 virtual void onUnlockPixels();
65
66 SkImageRef_GlobalPool(SkFlattenableReadBuffer&);
67
68private:
69 typedef SkImageRef INHERITED;
70};
71
72#endif