epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkGraphics_DEFINED |
| 11 | #define SkGraphics_DEFINED |
| 12 | |
| 13 | #include "SkTypes.h" |
| 14 | |
reed@google.com | eb9a9bf | 2012-04-23 13:43:30 +0000 | [diff] [blame] | 15 | class SK_API SkGraphics { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | public: |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 17 | /** |
| 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. |
| 21 | */ |
reed@android.com | 5e5adfd | 2009-03-07 03:39:23 +0000 | [diff] [blame] | 22 | static void Init(); |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 23 | |
caryclark@google.com | f86ab84 | 2011-12-16 17:11:17 +0000 | [diff] [blame] | 24 | /** |
| 25 | * Call this to release any memory held privately, such as the font cache. |
| 26 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | static void Term(); |
| 28 | |
reed@google.com | 77407ca | 2011-11-08 13:48:32 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Return the version numbers for the library. If the parameter is not |
| 31 | * null, it is set to the version number. |
reed@android.com | 9aa8b32 | 2010-04-13 13:22:54 +0000 | [diff] [blame] | 32 | */ |
| 33 | static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch); |
| 34 | |
reed@google.com | 77407ca | 2011-11-08 13:48:32 +0000 | [diff] [blame] | 35 | /** |
| 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(). |
| 39 | */ |
| 40 | static size_t GetFontCacheLimit(); |
| 41 | |
| 42 | /** |
| 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. |
| 45 | * |
| 46 | * This function returns the previous setting, as if GetFontCacheLimit() |
| 47 | * had be called before the new limit was set. |
| 48 | */ |
| 49 | static size_t SetFontCacheLimit(size_t bytes); |
| 50 | |
reed@google.com | 073c907 | 2011-11-08 20:03:48 +0000 | [diff] [blame] | 51 | /** |
reed@google.com | 79a1c34ee | 2012-07-30 13:08:01 +0000 | [diff] [blame^] | 52 | * Return the number of bytes currently used by the font cache. |
| 53 | */ |
| 54 | static size_t GetFontCacheUsed(); |
| 55 | |
| 56 | /** |
reed@google.com | 073c907 | 2011-11-08 20:03:48 +0000 | [diff] [blame] | 57 | * For debugging purposes, this will attempt to purge the font cache. It |
| 58 | * does not change the limit, but will cause subsequent font measures and |
| 59 | * draws to be recreated, since they will no longer be in the cache. |
| 60 | */ |
| 61 | static void PurgeFontCache(); |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Applications with command line options may pass optional state, such |
| 65 | * as cache sizes, here, for instance: |
| 66 | * font-cache-limit=12345678 |
| 67 | * |
| 68 | * The flags format is name=value[;name=value...] with no spaces. |
| 69 | * This format is subject to change. |
| 70 | */ |
| 71 | static void SetFlags(const char* flags); |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 72 | |
reed@google.com | 6172d67 | 2012-05-17 13:38:03 +0000 | [diff] [blame] | 73 | /** |
| 74 | * Return the max number of bytes that should be used by the thread-local |
| 75 | * font cache. |
| 76 | * If the cache needs to allocate more, it will purge previous entries. |
| 77 | * This max can be changed by calling SetFontCacheLimit(). |
| 78 | * |
| 79 | * If this thread has never called SetTLSFontCacheLimit, or has called it |
| 80 | * with 0, then this thread is using the shared font cache. In that case, |
| 81 | * this function will always return 0, and the caller may want to call |
| 82 | * GetFontCacheLimit. |
| 83 | */ |
| 84 | static size_t GetTLSFontCacheLimit(); |
| 85 | |
| 86 | /** |
| 87 | * Specify the max number of bytes that should be used by the thread-local |
reed@google.com | 803c67d | 2012-05-17 13:50:36 +0000 | [diff] [blame] | 88 | * font cache. If this value is 0, then this thread will use the shared |
| 89 | * global font cache. |
reed@google.com | 6172d67 | 2012-05-17 13:38:03 +0000 | [diff] [blame] | 90 | */ |
reed@google.com | 803c67d | 2012-05-17 13:50:36 +0000 | [diff] [blame] | 91 | static void SetTLSFontCacheLimit(size_t bytes); |
reed@google.com | 6172d67 | 2012-05-17 13:38:03 +0000 | [diff] [blame] | 92 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 93 | private: |
| 94 | /** This is automatically called by SkGraphics::Init(), and must be |
| 95 | implemented by the host OS. This allows the host OS to register a callback |
| 96 | with the C++ runtime to call SkGraphics::FreeCaches() |
| 97 | */ |
| 98 | static void InstallNewHandler(); |
| 99 | }; |
| 100 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 101 | class SkAutoGraphics { |
| 102 | public: |
| 103 | SkAutoGraphics() { |
| 104 | SkGraphics::Init(); |
| 105 | } |
| 106 | ~SkAutoGraphics() { |
| 107 | SkGraphics::Term(); |
| 108 | } |
| 109 | }; |
| 110 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | #endif |
| 112 | |