michael@0: michael@0: /* michael@0: * Copyright 2006 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 SkGraphics_DEFINED michael@0: #define SkGraphics_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: class SK_API SkGraphics { michael@0: public: michael@0: /** michael@0: * Call this at process initialization time if your environment does not michael@0: * permit static global initializers that execute code. Note that michael@0: * Init() is not thread-safe. michael@0: */ michael@0: static void Init(); michael@0: michael@0: /** michael@0: * Call this to release any memory held privately, such as the font cache. michael@0: */ michael@0: static void Term(); michael@0: michael@0: /** michael@0: * Return the version numbers for the library. If the parameter is not michael@0: * null, it is set to the version number. michael@0: */ michael@0: static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch); michael@0: michael@0: /** michael@0: * Return the max number of bytes that should be used by the font cache. michael@0: * If the cache needs to allocate more, it will purge previous entries. michael@0: * This max can be changed by calling SetFontCacheLimit(). michael@0: */ michael@0: static size_t GetFontCacheLimit(); michael@0: michael@0: /** michael@0: * Specify the max number of bytes that should be used by the font cache. michael@0: * If the cache needs to allocate more, it will purge previous entries. michael@0: * michael@0: * This function returns the previous setting, as if GetFontCacheLimit() michael@0: * had be called before the new limit was set. michael@0: */ michael@0: static size_t SetFontCacheLimit(size_t bytes); michael@0: michael@0: /** michael@0: * Return the number of bytes currently used by the font cache. michael@0: */ michael@0: static size_t GetFontCacheUsed(); michael@0: michael@0: /** michael@0: * Return the number of entries in the font cache. michael@0: * A cache "entry" is associated with each typeface + pointSize + matrix. michael@0: */ michael@0: static int GetFontCacheCountUsed(); michael@0: michael@0: /** michael@0: * Return the current limit to the number of entries in the font cache. michael@0: * A cache "entry" is associated with each typeface + pointSize + matrix. michael@0: */ michael@0: static int GetFontCacheCountLimit(); michael@0: michael@0: /** michael@0: * Set the limit to the number of entries in the font cache, and return michael@0: * the previous value. If this new value is lower than the previous, michael@0: * it will automatically try to purge entries to meet the new limit. michael@0: */ michael@0: static int SetFontCacheCountLimit(int count); michael@0: michael@0: /** michael@0: * For debugging purposes, this will attempt to purge the font cache. It michael@0: * does not change the limit, but will cause subsequent font measures and michael@0: * draws to be recreated, since they will no longer be in the cache. michael@0: */ michael@0: static void PurgeFontCache(); michael@0: michael@0: static size_t GetImageCacheBytesUsed(); michael@0: static size_t GetImageCacheByteLimit(); michael@0: static size_t SetImageCacheByteLimit(size_t newLimit); michael@0: michael@0: /** michael@0: * Applications with command line options may pass optional state, such michael@0: * as cache sizes, here, for instance: michael@0: * font-cache-limit=12345678 michael@0: * michael@0: * The flags format is name=value[;name=value...] with no spaces. michael@0: * This format is subject to change. michael@0: */ michael@0: static void SetFlags(const char* flags); michael@0: michael@0: /** michael@0: * Return the max number of bytes that should be used by the thread-local michael@0: * font cache. michael@0: * If the cache needs to allocate more, it will purge previous entries. michael@0: * This max can be changed by calling SetFontCacheLimit(). michael@0: * michael@0: * If this thread has never called SetTLSFontCacheLimit, or has called it michael@0: * with 0, then this thread is using the shared font cache. In that case, michael@0: * this function will always return 0, and the caller may want to call michael@0: * GetFontCacheLimit. michael@0: */ michael@0: static size_t GetTLSFontCacheLimit(); michael@0: michael@0: /** michael@0: * Specify the max number of bytes that should be used by the thread-local michael@0: * font cache. If this value is 0, then this thread will use the shared michael@0: * global font cache. michael@0: */ michael@0: static void SetTLSFontCacheLimit(size_t bytes); michael@0: michael@0: private: michael@0: /** This is automatically called by SkGraphics::Init(), and must be michael@0: implemented by the host OS. This allows the host OS to register a callback michael@0: with the C++ runtime to call SkGraphics::FreeCaches() michael@0: */ michael@0: static void InstallNewHandler(); michael@0: }; michael@0: michael@0: class SkAutoGraphics { michael@0: public: michael@0: SkAutoGraphics() { michael@0: SkGraphics::Init(); michael@0: } michael@0: ~SkAutoGraphics() { michael@0: SkGraphics::Term(); michael@0: } michael@0: }; michael@0: michael@0: #endif