epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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(SkStream*, SkBitmap::Config, int sampleSize = 1); |
| 19 | virtual ~SkImageRef_GlobalPool(); |
| 20 | |
djsollen@google.com | 5370cd9 | 2012-03-28 20:47:01 +0000 | [diff] [blame] | 21 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_GlobalPool) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | |
| 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(); |
| 28 | |
| 29 | /** Set a new budget value for the cache. |
| 30 | */ |
| 31 | static void SetRAMBudget(size_t); |
| 32 | |
| 33 | /** Return how much ram is currently in use by the global cache. |
| 34 | */ |
| 35 | static size_t GetRAMUsed(); |
| 36 | |
| 37 | /** 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); |
| 45 | |
| 46 | static void DumpPool(); |
| 47 | |
| 48 | protected: |
| 49 | virtual bool onDecode(SkImageDecoder* codec, SkStream* stream, |
| 50 | SkBitmap* bitmap, SkBitmap::Config config, |
| 51 | SkImageDecoder::Mode mode); |
| 52 | |
| 53 | virtual void onUnlockPixels(); |
| 54 | |
| 55 | SkImageRef_GlobalPool(SkFlattenableReadBuffer&); |
| 56 | |
| 57 | private: |
| 58 | typedef SkImageRef INHERITED; |
| 59 | }; |
| 60 | |
| 61 | #endif |