1
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef SkGraphics_DEFINED
11#define SkGraphics_DEFINED
12
13#include "SkTypes.h"
14
15class SK_API SkGraphics {
16public:
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     */
22    static void Init();
23
24    /**
25     *  Call this to release any memory held privately, such as the font cache.
26     */
27    static void Term();
28
29    /**
30     *  Return the version numbers for the library. If the parameter is not
31     *  null, it is set to the version number.
32     */
33    static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
34
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
51    /**
52     *  Return the number of bytes currently used by the font cache.
53     */
54    static size_t GetFontCacheUsed();
55
56    /**
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();
62
63    static size_t GetImageCacheBytesUsed();
64    static size_t GetImageCacheByteLimit();
65    static size_t SetImageCacheByteLimit(size_t newLimit);
66
67    /**
68     *  Applications with command line options may pass optional state, such
69     *  as cache sizes, here, for instance:
70     *  font-cache-limit=12345678
71     *
72     *  The flags format is name=value[;name=value...] with no spaces.
73     *  This format is subject to change.
74     */
75    static void SetFlags(const char* flags);
76
77    /**
78     *  Return the max number of bytes that should be used by the thread-local
79     *  font cache.
80     *  If the cache needs to allocate more, it will purge previous entries.
81     *  This max can be changed by calling SetFontCacheLimit().
82     *
83     *  If this thread has never called SetTLSFontCacheLimit, or has called it
84     *  with 0, then this thread is using the shared font cache. In that case,
85     *  this function will always return 0, and the caller may want to call
86     *  GetFontCacheLimit.
87     */
88    static size_t GetTLSFontCacheLimit();
89
90    /**
91     *  Specify the max number of bytes that should be used by the thread-local
92     *  font cache. If this value is 0, then this thread will use the shared
93     *  global font cache.
94     */
95    static void SetTLSFontCacheLimit(size_t bytes);
96
97private:
98    /** This is automatically called by SkGraphics::Init(), and must be
99        implemented by the host OS. This allows the host OS to register a callback
100        with the C++ runtime to call SkGraphics::FreeCaches()
101    */
102    static void InstallNewHandler();
103};
104
105class SkAutoGraphics {
106public:
107    SkAutoGraphics() {
108        SkGraphics::Init();
109    }
110    ~SkAutoGraphics() {
111        SkGraphics::Term();
112    }
113};
114
115#endif
116