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#include "include/core/SkGraphics.h"
9
10#include "include/core/SkCanvas.h"
11#include "include/core/SkMath.h"
12#include "include/core/SkMatrix.h"
13#include "include/core/SkPath.h"
14#include "include/core/SkPathEffect.h"
15#include "include/core/SkRefCnt.h"
16#include "include/core/SkShader.h"
17#include "include/core/SkStream.h"
18#include "include/core/SkTime.h"
19#include "src/core/SkBlitter.h"
20#include "src/core/SkCpu.h"
21#include "src/core/SkGeometry.h"
22#include "src/core/SkImageFilter_Base.h"
23#include "src/core/SkOpts.h"
24#include "src/core/SkResourceCache.h"
25#include "src/core/SkScalerContext.h"
26#include "src/core/SkStrikeCache.h"
27#include "src/core/SkTSearch.h"
28#include "src/core/SkTypefaceCache.h"
29
30#include <stdlib.h>
31
32void SkGraphics::Init() {
33 // SkGraphics::Init() must be thread-safe and idempotent.
34 SkCpu::CacheRuntimeFeatures();
35 SkOpts::Init();
36}
37
38///////////////////////////////////////////////////////////////////////////////
39
40void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
41 SkResourceCache::DumpMemoryStatistics(dump);
42 SkStrikeCache::DumpMemoryStatistics(dump);
43}
44
45void SkGraphics::PurgeAllCaches() {
46 SkGraphics::PurgeFontCache();
47 SkGraphics::PurgeResourceCache();
48 SkImageFilter_Base::PurgeCache();
49}
50
51///////////////////////////////////////////////////////////////////////////////
52
53static const char kFontCacheLimitStr[] = "font-cache-limit";
54static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
55
56static const struct {
57 const char* fStr;
58 size_t fLen;
59 size_t (*fFunc)(size_t);
60} gFlags[] = {
61 { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
62};
63
64/* flags are of the form param; or param=value; */
65void SkGraphics::SetFlags(const char* flags) {
66 if (!flags) {
67 return;
68 }
69 const char* nextSemi;
70 do {
71 size_t len = strlen(flags);
72 const char* paramEnd = flags + len;
73 const char* nextEqual = strchr(flags, '=');
74 if (nextEqual && paramEnd > nextEqual) {
75 paramEnd = nextEqual;
76 }
77 nextSemi = strchr(flags, ';');
78 if (nextSemi && paramEnd > nextSemi) {
79 paramEnd = nextSemi;
80 }
81 size_t paramLen = paramEnd - flags;
82 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
83 if (paramLen != gFlags[i].fLen) {
84 continue;
85 }
86 if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
87 size_t val = 0;
88 if (nextEqual) {
89 val = (size_t) atoi(nextEqual + 1);
90 }
91 (gFlags[i].fFunc)(val);
92 break;
93 }
94 }
95 flags = nextSemi + 1;
96 } while (nextSemi);
97}
98
99size_t SkGraphics::GetFontCacheLimit() {
100 return SkStrikeCache::GlobalStrikeCache()->getCacheSizeLimit();
101}
102
103size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
104 return SkStrikeCache::GlobalStrikeCache()->setCacheSizeLimit(bytes);
105}
106
107size_t SkGraphics::GetFontCacheUsed() {
108 return SkStrikeCache::GlobalStrikeCache()->getTotalMemoryUsed();
109}
110
111int SkGraphics::GetFontCacheCountLimit() {
112 return SkStrikeCache::GlobalStrikeCache()->getCacheCountLimit();
113}
114
115int SkGraphics::SetFontCacheCountLimit(int count) {
116 return SkStrikeCache::GlobalStrikeCache()->setCacheCountLimit(count);
117}
118
119int SkGraphics::GetFontCacheCountUsed() {
120 return SkStrikeCache::GlobalStrikeCache()->getCacheCountUsed();
121}
122
123int SkGraphics::GetFontCachePointSizeLimit() {
124 return SkStrikeCache::GlobalStrikeCache()->getCachePointSizeLimit();
125}
126
127int SkGraphics::SetFontCachePointSizeLimit(int limit) {
128 return SkStrikeCache::GlobalStrikeCache()->setCachePointSizeLimit(limit);
129}
130
131void SkGraphics::PurgeFontCache() {
132 SkStrikeCache::GlobalStrikeCache()->purgeAll();
133 SkTypefaceCache::PurgeAll();
134}
135