2 * Copyright 2006 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkGraphics_DEFINED
9 #define SkGraphics_DEFINED
13 class SK_API SkGraphics {
16 * Call this at process initialization time if your environment does not
17 * permit static global initializers that execute code. Note that
18 * Init() is not thread-safe.
23 * Call this to release any memory held privately, such as the font cache.
28 * Return the version numbers for the library. If the parameter is not
29 * null, it is set to the version number.
31 static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
34 * Return the max number of bytes that should be used by the font cache.
35 * If the cache needs to allocate more, it will purge previous entries.
36 * This max can be changed by calling SetFontCacheLimit().
38 static size_t GetFontCacheLimit();
41 * Specify the max number of bytes that should be used by the font cache.
42 * If the cache needs to allocate more, it will purge previous entries.
44 * This function returns the previous setting, as if GetFontCacheLimit()
45 * had be called before the new limit was set.
47 static size_t SetFontCacheLimit(size_t bytes);
50 * Return the number of bytes currently used by the font cache.
52 static size_t GetFontCacheUsed();
55 * Return the number of entries in the font cache.
56 * A cache "entry" is associated with each typeface + pointSize + matrix.
58 static int GetFontCacheCountUsed();
61 * Return the current limit to the number of entries in the font cache.
62 * A cache "entry" is associated with each typeface + pointSize + matrix.
64 static int GetFontCacheCountLimit();
67 * Set the limit to the number of entries in the font cache, and return
68 * the previous value. If this new value is lower than the previous,
69 * it will automatically try to purge entries to meet the new limit.
71 static int SetFontCacheCountLimit(int count);
74 * For debugging purposes, this will attempt to purge the font cache. It
75 * does not change the limit, but will cause subsequent font measures and
76 * draws to be recreated, since they will no longer be in the cache.
78 static void PurgeFontCache();
81 * Scaling bitmaps with the SkPaint::kHigh_FilterLevel setting is
82 * expensive, so the result is saved in the global Scaled Image
85 * This function returns the memory usage of the Scaled Image Cache.
87 static size_t GetResourceCacheTotalBytesUsed();
90 * These functions get/set the memory usage limit for the resource cache, used for temporary
91 * bitmaps and other resources. Entries are purged from the cache when the memory useage
94 static size_t GetResourceCacheTotalByteLimit();
95 static size_t SetResourceCacheTotalByteLimit(size_t newLimit);
98 * For debugging purposes, this will attempt to purge the resource cache. It
99 * does not change the limit.
101 static void PurgeResourceCache();
104 * When the cachable entry is very lage (e.g. a large scaled bitmap), adding it to the cache
105 * can cause most/all of the existing entries to be purged. To avoid the, the client can set
106 * a limit for a single allocation. If a cacheable entry would have been cached, but its size
107 * exceeds this limit, then we do not attempt to cache it at all.
109 * Zero is the default value, meaning we always attempt to cache entries.
111 static size_t GetResourceCacheSingleAllocationByteLimit();
112 static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
115 * Applications with command line options may pass optional state, such
116 * as cache sizes, here, for instance:
117 * font-cache-limit=12345678
119 * The flags format is name=value[;name=value...] with no spaces.
120 * This format is subject to change.
122 static void SetFlags(const char* flags);
125 * Return the max number of bytes that should be used by the thread-local
127 * If the cache needs to allocate more, it will purge previous entries.
128 * This max can be changed by calling SetFontCacheLimit().
130 * If this thread has never called SetTLSFontCacheLimit, or has called it
131 * with 0, then this thread is using the shared font cache. In that case,
132 * this function will always return 0, and the caller may want to call
135 static size_t GetTLSFontCacheLimit();
138 * Specify the max number of bytes that should be used by the thread-local
139 * font cache. If this value is 0, then this thread will use the shared
142 static void SetTLSFontCacheLimit(size_t bytes);
145 class SkAutoGraphics {