Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
SkTypefaceCache Class Reference

#include <SkTypefaceCache.h>

Public Types

typedef bool(* FindProc) (SkTypeface *, void *context)
 

Public Member Functions

 SkTypefaceCache ()
 
void add (sk_sp< SkTypeface >)
 
sk_sp< SkTypefacefindByProcAndRef (FindProc proc, void *ctx) const
 
void purgeAll ()
 

Static Public Member Functions

static SkTypefaceID NewTypefaceID ()
 
static void Add (sk_sp< SkTypeface >)
 
static sk_sp< SkTypefaceFindByProcAndRef (FindProc proc, void *ctx)
 
static void PurgeAll ()
 
static void Dump ()
 

Detailed Description

Definition at line 17 of file SkTypefaceCache.h.

Member Typedef Documentation

◆ FindProc

typedef bool(* SkTypefaceCache::FindProc) (SkTypeface *, void *context)

Callback for FindByProc. Returns true if the given typeface is a match for the given context. The passed typeface is owned by the cache and is not additionally ref()ed. The typeface may be in the disposed state.

Definition at line 26 of file SkTypefaceCache.h.

Constructor & Destructor Documentation

◆ SkTypefaceCache()

SkTypefaceCache::SkTypefaceCache ( )

Definition at line 20 of file SkTypefaceCache.cpp.

20{}

Member Function Documentation

◆ add()

void SkTypefaceCache::add ( sk_sp< SkTypeface face)

Add a typeface to the cache. Later, if we need to purge the cache, typefaces uniquely owned by the cache will be unref()ed.

Definition at line 22 of file SkTypefaceCache.cpp.

22 {
23 const auto limit = SkGraphics::GetTypefaceCacheCountLimit();
24
25 if (fTypefaces.size() >= limit) {
26 this->purge(limit >> 2);
27 }
28 if (limit > 0) {
29 fTypefaces.emplace_back(std::move(face));
30 }
31}
static int GetTypefaceCacheCountLimit()
int size() const
Definition SkTArray.h:416
T & emplace_back(Args &&... args)
Definition SkTArray.h:243

◆ Add()

void SkTypefaceCache::Add ( sk_sp< SkTypeface face)
static

Definition at line 79 of file SkTypefaceCache.cpp.

79 {
81 Get().add(std::move(face));
82}
static SkMutex & typeface_cache_mutex()
void add(sk_sp< SkTypeface >)

◆ Dump()

void SkTypefaceCache::Dump ( )
static

Debugging only: dumps the status of the typefaces in the cache

Definition at line 108 of file SkTypefaceCache.cpp.

108 {
109#ifdef SK_DEBUG
110 (void)Get().findByProcAndRef(DumpProc, nullptr);
111#endif
112}
sk_sp< SkTypeface > findByProcAndRef(FindProc proc, void *ctx) const

◆ FindByProcAndRef()

sk_sp< SkTypeface > SkTypefaceCache::FindByProcAndRef ( FindProc  proc,
void *  ctx 
)
static

Definition at line 84 of file SkTypefaceCache.cpp.

84 {
86 return Get().findByProcAndRef(proc, ctx);
87}

◆ findByProcAndRef()

sk_sp< SkTypeface > SkTypefaceCache::findByProcAndRef ( FindProc  proc,
void *  ctx 
) const

Iterate through the cache, calling proc(typeface, ctx) for each typeface. If proc returns true, then return that typeface. If it never returns true, return nullptr.

Definition at line 33 of file SkTypefaceCache.cpp.

33 {
34 for (const sk_sp<SkTypeface>& typeface : fTypefaces) {
35 if (proc(typeface.get(), ctx)) {
36 return typeface;
37 }
38 }
39 return nullptr;
40}

◆ NewTypefaceID()

SkTypefaceID SkTypefaceCache::NewTypefaceID ( )
static

Helper: returns a unique typefaceID to pass to the constructor of your subclass of SkTypeface

Definition at line 69 of file SkTypefaceCache.cpp.

69 {
70 static std::atomic<int32_t> nextID{1};
71 return nextID.fetch_add(1, std::memory_order_relaxed);
72}

◆ purgeAll()

void SkTypefaceCache::purgeAll ( )

This will unref all of the typefaces in the cache for which the cache is the only owner. Normally this is handled automatically as needed. This function is exposed for clients that explicitly want to purge the cache (e.g. to look for leaks).

Definition at line 58 of file SkTypefaceCache.cpp.

58 {
59 this->purge(fTypefaces.size());
60}

◆ PurgeAll()

void SkTypefaceCache::PurgeAll ( )
static

Definition at line 89 of file SkTypefaceCache.cpp.


The documentation for this class was generated from the following files: