180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkGraphics_DEFINED 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkGraphics_DEFINED 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTypes.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SK_API SkGraphics { 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Call this at process initialization time if your environment does not 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * permit static global initializers that execute code. Note that 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Init() is not thread-safe. 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void Init(); 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Call this to release any memory held privately, such as the font cache. 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void Term(); 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Return the version numbers for the library. If the parameter is not 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * null, it is set to the version number. 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch); 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Return the max number of bytes that should be used by the font cache. 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * If the cache needs to allocate more, it will purge previous entries. 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * This max can be changed by calling SetFontCacheLimit(). 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static size_t GetFontCacheLimit(); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Specify the max number of bytes that should be used by the font cache. 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * If the cache needs to allocate more, it will purge previous entries. 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * This function returns the previous setting, as if GetFontCacheLimit() 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * had be called before the new limit was set. 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static size_t SetFontCacheLimit(size_t bytes); 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Return the number of bytes currently used by the font cache. 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static size_t GetFontCacheUsed(); 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * For debugging purposes, this will attempt to purge the font cache. It 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * does not change the limit, but will cause subsequent font measures and 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * draws to be recreated, since they will no longer be in the cache. 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void PurgeFontCache(); 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger static size_t GetImageCacheBytesUsed(); 6458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger static size_t GetImageCacheByteLimit(); 6558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger static size_t SetImageCacheByteLimit(size_t newLimit); 6658190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Applications with command line options may pass optional state, such 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * as cache sizes, here, for instance: 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * font-cache-limit=12345678 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * The flags format is name=value[;name=value...] with no spaces. 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * This format is subject to change. 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void SetFlags(const char* flags); 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Return the max number of bytes that should be used by the thread-local 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * font cache. 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * If the cache needs to allocate more, it will purge previous entries. 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * This max can be changed by calling SetFontCacheLimit(). 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * If this thread has never called SetTLSFontCacheLimit, or has called it 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * with 0, then this thread is using the shared font cache. In that case, 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * this function will always return 0, and the caller may want to call 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * GetFontCacheLimit. 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static size_t GetTLSFontCacheLimit(); 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Specify the max number of bytes that should be used by the thread-local 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * font cache. If this value is 0, then this thread will use the shared 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * global font cache. 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void SetTLSFontCacheLimit(size_t bytes); 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** This is automatically called by SkGraphics::Init(), and must be 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru implemented by the host OS. This allows the host OS to register a callback 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru with the C++ runtime to call SkGraphics::FreeCaches() 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void InstallNewHandler(); 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkAutoGraphics { 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAutoGraphics() { 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkGraphics::Init(); 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ~SkAutoGraphics() { 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkGraphics::Term(); 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 116