Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkTypefaceCache.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
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
9
10#ifndef SkTypefaceCache_DEFINED
11#define SkTypefaceCache_DEFINED
12
16
18public:
20
21 /**
22 * Callback for FindByProc. Returns true if the given typeface is a match
23 * for the given context. The passed typeface is owned by the cache and is
24 * not additionally ref()ed. The typeface may be in the disposed state.
25 */
26 typedef bool(*FindProc)(SkTypeface*, void* context);
27
28 /**
29 * Add a typeface to the cache. Later, if we need to purge the cache,
30 * typefaces uniquely owned by the cache will be unref()ed.
31 */
33
34 /**
35 * Iterate through the cache, calling proc(typeface, ctx) for each typeface.
36 * If proc returns true, then return that typeface.
37 * If it never returns true, return nullptr.
38 */
39 sk_sp<SkTypeface> findByProcAndRef(FindProc proc, void* ctx) const;
40
41 /**
42 * This will unref all of the typefaces in the cache for which the cache
43 * is the only owner. Normally this is handled automatically as needed.
44 * This function is exposed for clients that explicitly want to purge the
45 * cache (e.g. to look for leaks).
46 */
47 void purgeAll();
48
49 /**
50 * Helper: returns a unique typefaceID to pass to the constructor of
51 * your subclass of SkTypeface
52 */
54
55 // These are static wrappers around a global instance of a cache.
56
57 static void Add(sk_sp<SkTypeface>);
58 static sk_sp<SkTypeface> FindByProcAndRef(FindProc proc, void* ctx);
59 static void PurgeAll();
60
61 /**
62 * Debugging only: dumps the status of the typefaces in the cache
63 */
64 static void Dump();
65
66private:
67 static SkTypefaceCache& Get();
68
69 void purge(int count);
70
72};
73
74#endif
int count
uint32_t SkTypefaceID
Definition SkTypeface.h:38
static sk_sp< SkTypeface > FindByProcAndRef(FindProc proc, void *ctx)
sk_sp< SkTypeface > findByProcAndRef(FindProc proc, void *ctx) const
bool(* FindProc)(SkTypeface *, void *context)
void add(sk_sp< SkTypeface >)
static void Add(sk_sp< SkTypeface >)
static void PurgeAll()
static SkTypefaceID NewTypefaceID()