1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use skia_bindings::SkGraphics;
use std::ffi::CString;

pub fn init() {
    unsafe { SkGraphics::Init() };
}

pub fn font_cache_limit() -> usize {
    unsafe { SkGraphics::GetFontCacheLimit() }
}

pub fn set_font_cache_limit(bytes: usize) -> usize {
    unsafe { SkGraphics::SetFontCacheLimit(bytes) }
}

pub fn font_cache_used() -> usize {
    unsafe { SkGraphics::GetFontCacheUsed() }
}

pub fn font_cache_count_used() -> i32 {
    unsafe { SkGraphics::GetFontCacheCountUsed() }
}

pub fn font_cache_count_limit() -> i32 {
    unsafe { SkGraphics::GetFontCacheCountLimit() }
}

pub fn set_font_cache_count_limit(count: i32) -> i32 {
    unsafe { SkGraphics::SetFontCacheCountLimit(count) }
}

pub fn font_cache_point_size_limit() -> i32 {
    unsafe { SkGraphics::GetFontCachePointSizeLimit() }
}

pub fn set_font_cache_point_size_limit(max_point_size: i32) -> i32 {
    unsafe { SkGraphics::SetFontCachePointSizeLimit(max_point_size) }
}

pub fn purge_font_cache() {
    unsafe { SkGraphics::PurgeFontCache() }
}

pub fn resource_cache_total_bytes_used() -> usize {
    unsafe { SkGraphics::GetResourceCacheTotalBytesUsed() }
}

pub fn resource_cache_total_bytes_limit() -> usize {
    unsafe { SkGraphics::GetResourceCacheTotalByteLimit() }
}

pub fn set_resource_cache_total_bytes_limit(new_limit: usize) -> usize {
    unsafe { SkGraphics::SetResourceCacheTotalByteLimit(new_limit) }
}

pub fn purge_resource_cache() {
    unsafe { SkGraphics::PurgeResourceCache() }
}

pub fn resource_cache_single_allocation_byte_limit() -> Option<usize> {
    let size = unsafe { SkGraphics::GetResourceCacheSingleAllocationByteLimit() };
    if size != 0 {
        Some(size)
    } else {
        None
    }
}

pub fn set_resource_cache_single_allocation_byte_limit(new_limit: Option<usize>) -> Option<usize> {
    let size = unsafe {
        SkGraphics::SetResourceCacheSingleAllocationByteLimit(new_limit.unwrap_or_default())
    };
    if size != 0 {
        Some(size)
    } else {
        None
    }
}

// TODO: dump_memory_statistics() (needs SkTraceMemoryDumpWrapper interop wrapper).

pub fn purge_all_caches() {
    unsafe { SkGraphics::PurgeAllCaches() }
}

pub fn set_flags(flags: impl AsRef<str>) {
    let c_str = CString::new(flags.as_ref()).unwrap();
    unsafe { SkGraphics::SetFlags(c_str.as_ptr()) }
}

// TODO: ImageGeneratorFromEncodedDataFactory