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