1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkGraphics.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkGraphics_DEFINED 1.14 +#define SkGraphics_DEFINED 1.15 + 1.16 +#include "SkTypes.h" 1.17 + 1.18 +class SK_API SkGraphics { 1.19 +public: 1.20 + /** 1.21 + * Call this at process initialization time if your environment does not 1.22 + * permit static global initializers that execute code. Note that 1.23 + * Init() is not thread-safe. 1.24 + */ 1.25 + static void Init(); 1.26 + 1.27 + /** 1.28 + * Call this to release any memory held privately, such as the font cache. 1.29 + */ 1.30 + static void Term(); 1.31 + 1.32 + /** 1.33 + * Return the version numbers for the library. If the parameter is not 1.34 + * null, it is set to the version number. 1.35 + */ 1.36 + static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch); 1.37 + 1.38 + /** 1.39 + * Return the max number of bytes that should be used by the font cache. 1.40 + * If the cache needs to allocate more, it will purge previous entries. 1.41 + * This max can be changed by calling SetFontCacheLimit(). 1.42 + */ 1.43 + static size_t GetFontCacheLimit(); 1.44 + 1.45 + /** 1.46 + * Specify the max number of bytes that should be used by the font cache. 1.47 + * If the cache needs to allocate more, it will purge previous entries. 1.48 + * 1.49 + * This function returns the previous setting, as if GetFontCacheLimit() 1.50 + * had be called before the new limit was set. 1.51 + */ 1.52 + static size_t SetFontCacheLimit(size_t bytes); 1.53 + 1.54 + /** 1.55 + * Return the number of bytes currently used by the font cache. 1.56 + */ 1.57 + static size_t GetFontCacheUsed(); 1.58 + 1.59 + /** 1.60 + * Return the number of entries in the font cache. 1.61 + * A cache "entry" is associated with each typeface + pointSize + matrix. 1.62 + */ 1.63 + static int GetFontCacheCountUsed(); 1.64 + 1.65 + /** 1.66 + * Return the current limit to the number of entries in the font cache. 1.67 + * A cache "entry" is associated with each typeface + pointSize + matrix. 1.68 + */ 1.69 + static int GetFontCacheCountLimit(); 1.70 + 1.71 + /** 1.72 + * Set the limit to the number of entries in the font cache, and return 1.73 + * the previous value. If this new value is lower than the previous, 1.74 + * it will automatically try to purge entries to meet the new limit. 1.75 + */ 1.76 + static int SetFontCacheCountLimit(int count); 1.77 + 1.78 + /** 1.79 + * For debugging purposes, this will attempt to purge the font cache. It 1.80 + * does not change the limit, but will cause subsequent font measures and 1.81 + * draws to be recreated, since they will no longer be in the cache. 1.82 + */ 1.83 + static void PurgeFontCache(); 1.84 + 1.85 + static size_t GetImageCacheBytesUsed(); 1.86 + static size_t GetImageCacheByteLimit(); 1.87 + static size_t SetImageCacheByteLimit(size_t newLimit); 1.88 + 1.89 + /** 1.90 + * Applications with command line options may pass optional state, such 1.91 + * as cache sizes, here, for instance: 1.92 + * font-cache-limit=12345678 1.93 + * 1.94 + * The flags format is name=value[;name=value...] with no spaces. 1.95 + * This format is subject to change. 1.96 + */ 1.97 + static void SetFlags(const char* flags); 1.98 + 1.99 + /** 1.100 + * Return the max number of bytes that should be used by the thread-local 1.101 + * font cache. 1.102 + * If the cache needs to allocate more, it will purge previous entries. 1.103 + * This max can be changed by calling SetFontCacheLimit(). 1.104 + * 1.105 + * If this thread has never called SetTLSFontCacheLimit, or has called it 1.106 + * with 0, then this thread is using the shared font cache. In that case, 1.107 + * this function will always return 0, and the caller may want to call 1.108 + * GetFontCacheLimit. 1.109 + */ 1.110 + static size_t GetTLSFontCacheLimit(); 1.111 + 1.112 + /** 1.113 + * Specify the max number of bytes that should be used by the thread-local 1.114 + * font cache. If this value is 0, then this thread will use the shared 1.115 + * global font cache. 1.116 + */ 1.117 + static void SetTLSFontCacheLimit(size_t bytes); 1.118 + 1.119 +private: 1.120 + /** This is automatically called by SkGraphics::Init(), and must be 1.121 + implemented by the host OS. This allows the host OS to register a callback 1.122 + with the C++ runtime to call SkGraphics::FreeCaches() 1.123 + */ 1.124 + static void InstallNewHandler(); 1.125 +}; 1.126 + 1.127 +class SkAutoGraphics { 1.128 +public: 1.129 + SkAutoGraphics() { 1.130 + SkGraphics::Init(); 1.131 + } 1.132 + ~SkAutoGraphics() { 1.133 + SkGraphics::Term(); 1.134 + } 1.135 +}; 1.136 + 1.137 +#endif