Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / core / SkGraphics.h
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #ifndef SkGraphics_DEFINED
9 #define SkGraphics_DEFINED
10
11 #include "SkTypes.h"
12
13 class SK_API SkGraphics {
14 public:
15     /**
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.
19      */
20     static void Init();
21
22     /**
23      *  Call this to release any memory held privately, such as the font cache.
24      */
25     static void Term();
26
27     /**
28      *  Return the version numbers for the library. If the parameter is not
29      *  null, it is set to the version number.
30      */
31     static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
32
33     /**
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().
37      */
38     static size_t GetFontCacheLimit();
39
40     /**
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.
43      *
44      *  This function returns the previous setting, as if GetFontCacheLimit()
45      *  had be called before the new limit was set.
46      */
47     static size_t SetFontCacheLimit(size_t bytes);
48
49     /**
50      *  Return the number of bytes currently used by the font cache.
51      */
52     static size_t GetFontCacheUsed();
53
54     /**
55      *  Return the number of entries in the font cache.
56      *  A cache "entry" is associated with each typeface + pointSize + matrix.
57      */
58     static int GetFontCacheCountUsed();
59
60     /**
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.
63      */
64     static int GetFontCacheCountLimit();
65
66     /**
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.
70      */
71     static int SetFontCacheCountLimit(int count);
72
73     /**
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.
77      */
78     static void PurgeFontCache();
79
80     /**
81      *  Scaling bitmaps with the SkPaint::kHigh_FilterLevel setting is
82      *  expensive, so the result is saved in the global Scaled Image
83      *  Cache.
84      *
85      *  This function returns the memory usage of the Scaled Image Cache.
86      */
87     static size_t GetResourceCacheTotalBytesUsed();
88
89     /**
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
92      *  exceeds this limit.
93      */
94     static size_t GetResourceCacheTotalByteLimit();
95     static size_t SetResourceCacheTotalByteLimit(size_t newLimit);
96
97     /**
98      *  For debugging purposes, this will attempt to purge the resource cache. It
99      *  does not change the limit.
100      */
101     static void PurgeResourceCache();
102
103     /**
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.
108      *
109      *  Zero is the default value, meaning we always attempt to cache entries.
110      */
111     static size_t GetResourceCacheSingleAllocationByteLimit();
112     static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
113
114     /**
115      *  Applications with command line options may pass optional state, such
116      *  as cache sizes, here, for instance:
117      *  font-cache-limit=12345678
118      *
119      *  The flags format is name=value[;name=value...] with no spaces.
120      *  This format is subject to change.
121      */
122     static void SetFlags(const char* flags);
123
124     /**
125      *  Return the max number of bytes that should be used by the thread-local
126      *  font cache.
127      *  If the cache needs to allocate more, it will purge previous entries.
128      *  This max can be changed by calling SetFontCacheLimit().
129      *
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
133      *  GetFontCacheLimit.
134      */
135     static size_t GetTLSFontCacheLimit();
136
137     /**
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
140      *  global font cache.
141      */
142     static void SetTLSFontCacheLimit(size_t bytes);
143 };
144
145 class SkAutoGraphics {
146 public:
147     SkAutoGraphics() {
148         SkGraphics::Init();
149     }
150     ~SkAutoGraphics() {
151         SkGraphics::Term();
152     }
153 };
154
155 #endif