|
1 |
|
2 /* |
|
3 * Copyright 2008 The Android Open Source Project |
|
4 * |
|
5 * Use of this source code is governed by a BSD-style license that can be |
|
6 * found in the LICENSE file. |
|
7 */ |
|
8 |
|
9 |
|
10 #ifndef SkImageRef_GlobalPool_DEFINED |
|
11 #define SkImageRef_GlobalPool_DEFINED |
|
12 |
|
13 #include "SkImageRef.h" |
|
14 |
|
15 class SkImageRef_GlobalPool : public SkImageRef { |
|
16 public: |
|
17 // if pool is null, use the global pool |
|
18 SkImageRef_GlobalPool(const SkImageInfo&, SkStreamRewindable*, |
|
19 int sampleSize = 1); |
|
20 virtual ~SkImageRef_GlobalPool(); |
|
21 |
|
22 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_GlobalPool) |
|
23 |
|
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(); |
|
29 |
|
30 /** Set a new budget value for the cache. |
|
31 */ |
|
32 static void SetRAMBudget(size_t); |
|
33 |
|
34 /** Return how much ram is currently in use by the global cache. |
|
35 */ |
|
36 static size_t GetRAMUsed(); |
|
37 |
|
38 /** 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); |
|
46 |
|
47 static void DumpPool(); |
|
48 |
|
49 protected: |
|
50 virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable* stream, |
|
51 SkBitmap* bitmap, SkBitmap::Config config, |
|
52 SkImageDecoder::Mode mode); |
|
53 |
|
54 virtual void onUnlockPixels(); |
|
55 |
|
56 SkImageRef_GlobalPool(SkReadBuffer&); |
|
57 |
|
58 private: |
|
59 typedef SkImageRef INHERITED; |
|
60 }; |
|
61 |
|
62 #endif |