michael@0: michael@0: /* michael@0: * Copyright 2008 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkImageRef_GlobalPool_DEFINED michael@0: #define SkImageRef_GlobalPool_DEFINED michael@0: michael@0: #include "SkImageRef.h" michael@0: michael@0: class SkImageRef_GlobalPool : public SkImageRef { michael@0: public: michael@0: // if pool is null, use the global pool michael@0: SkImageRef_GlobalPool(const SkImageInfo&, SkStreamRewindable*, michael@0: int sampleSize = 1); michael@0: virtual ~SkImageRef_GlobalPool(); michael@0: michael@0: SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageRef_GlobalPool) michael@0: michael@0: // API to control the global pool michael@0: michael@0: /** Return the amount specified as the budget for the cache (in bytes). michael@0: */ michael@0: static size_t GetRAMBudget(); michael@0: michael@0: /** Set a new budget value for the cache. michael@0: */ michael@0: static void SetRAMBudget(size_t); michael@0: michael@0: /** Return how much ram is currently in use by the global cache. michael@0: */ michael@0: static size_t GetRAMUsed(); michael@0: michael@0: /** Free up (approximately) enough such that the amount used by the cache michael@0: is <= the specified amount. Since some images may be "in use", the michael@0: amount actually freed may not always result in a ram usage value <= michael@0: to the requested amount. In addition, because of the michael@0: chunky nature of the cache, the resulting usage may be < the requested michael@0: amount. michael@0: */ michael@0: static void SetRAMUsed(size_t usageInBytes); michael@0: michael@0: static void DumpPool(); michael@0: michael@0: protected: michael@0: virtual bool onDecode(SkImageDecoder* codec, SkStreamRewindable* stream, michael@0: SkBitmap* bitmap, SkBitmap::Config config, michael@0: SkImageDecoder::Mode mode); michael@0: michael@0: virtual void onUnlockPixels(); michael@0: michael@0: SkImageRef_GlobalPool(SkReadBuffer&); michael@0: michael@0: private: michael@0: typedef SkImageRef INHERITED; michael@0: }; michael@0: michael@0: #endif