3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkGraphics_DEFINED
11 #define SkGraphics_DEFINED
15 class SK_API SkGraphics {
18 * Call this at process initialization time if your environment does not
19 * permit static global initializers that execute code. Note that
20 * Init() is not thread-safe.
25 * Call this to release any memory held privately, such as the font cache.
30 * Return the version numbers for the library. If the parameter is not
31 * null, it is set to the version number.
33 static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
36 * Return the max number of bytes that should be used by the font cache.
37 * If the cache needs to allocate more, it will purge previous entries.
38 * This max can be changed by calling SetFontCacheLimit().
40 static size_t GetFontCacheLimit();
43 * Specify the max number of bytes that should be used by the font cache.
44 * If the cache needs to allocate more, it will purge previous entries.
46 * This function returns the previous setting, as if GetFontCacheLimit()
47 * had be called before the new limit was set.
49 static size_t SetFontCacheLimit(size_t bytes);
52 * Return the number of bytes currently used by the font cache.
54 static size_t GetFontCacheUsed();
57 * Return the number of entries in the font cache.
58 * A cache "entry" is associated with each typeface + pointSize + matrix.
60 static int GetFontCacheCountUsed();
63 * Return the current limit to the number of entries in the font cache.
64 * A cache "entry" is associated with each typeface + pointSize + matrix.
66 static int GetFontCacheCountLimit();
69 * Set the limit to the number of entries in the font cache, and return
70 * the previous value. If this new value is lower than the previous,
71 * it will automatically try to purge entries to meet the new limit.
73 static int SetFontCacheCountLimit(int count);
76 * For debugging purposes, this will attempt to purge the font cache. It
77 * does not change the limit, but will cause subsequent font measures and
78 * draws to be recreated, since they will no longer be in the cache.
80 static void PurgeFontCache();
83 * Scaling bitmaps with the SkPaint::kHigh_FilterLevel setting is
84 * expensive, so the result is saved in the global Scaled Image
87 * This function returns the memory usage of the Scaled Image Cache.
89 static size_t GetResourceCacheTotalBytesUsed();
92 * These functions get/set the memory usage limit for the resource cache, used for temporary
93 * bitmaps and other resources. Entries are purged from the cache when the memory useage
96 static size_t GetResourceCacheTotalByteLimit();
97 static size_t SetResourceCacheTotalByteLimit(size_t newLimit);
100 * For debugging purposes, this will attempt to purge the resource cache. It
101 * does not change the limit.
103 static void PurgeResourceCache();
106 * When the cachable entry is very lage (e.g. a large scaled bitmap), adding it to the cache
107 * can cause most/all of the existing entries to be purged. To avoid the, the client can set
108 * a limit for a single allocation. If a cacheable entry would have been cached, but its size
109 * exceeds this limit, then we do not attempt to cache it at all.
111 * Zero is the default value, meaning we always attempt to cache entries.
113 static size_t GetResourceCacheSingleAllocationByteLimit();
114 static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
116 #ifdef SK_SUPPORT_LEGACY_IMAGECACHE_NAME
117 static size_t GetImageCacheBytesUsed() {
118 return GetImageCacheTotalBytesUsed();
120 static size_t GetImageCacheByteLimit() {
121 return GetImageCacheTotalByteLimit();
123 static size_t SetImageCacheByteLimit(size_t newLimit) {
124 return SetImageCacheTotalByteLimit(newLimit);
126 static size_t GetImageCacheTotalBytesUsed() {
127 return GetResourceCacheTotalBytesUsed();
129 static size_t GetImageCacheTotalByteLimit() {
130 return GetResourceCacheTotalByteLimit();
132 static size_t SetImageCacheTotalByteLimit(size_t newLimit) {
133 return SetResourceCacheTotalByteLimit(newLimit);
135 static size_t GetImageCacheSingleAllocationByteLimit() {
136 return GetResourceCacheSingleAllocationByteLimit();
138 static size_t SetImageCacheSingleAllocationByteLimit(size_t newLimit) {
139 return SetResourceCacheSingleAllocationByteLimit(newLimit);
144 * Applications with command line options may pass optional state, such
145 * as cache sizes, here, for instance:
146 * font-cache-limit=12345678
148 * The flags format is name=value[;name=value...] with no spaces.
149 * This format is subject to change.
151 static void SetFlags(const char* flags);
154 * Return the max number of bytes that should be used by the thread-local
156 * If the cache needs to allocate more, it will purge previous entries.
157 * This max can be changed by calling SetFontCacheLimit().
159 * If this thread has never called SetTLSFontCacheLimit, or has called it
160 * with 0, then this thread is using the shared font cache. In that case,
161 * this function will always return 0, and the caller may want to call
164 static size_t GetTLSFontCacheLimit();
167 * Specify the max number of bytes that should be used by the thread-local
168 * font cache. If this value is 0, then this thread will use the shared
171 static void SetTLSFontCacheLimit(size_t bytes);
174 /** This is automatically called by SkGraphics::Init(), and must be
175 implemented by the host OS. This allows the host OS to register a callback
176 with the C++ runtime to call SkGraphics::FreeCaches()
178 static void InstallNewHandler();
181 class SkAutoGraphics {