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 
9 #include "SkGraphics.h"
10 
11 #include "SkBlitter.h"
12 #include "SkCanvas.h"
13 #include "SkCpu.h"
14 #include "SkGeometry.h"
15 #include "SkGlyphCache.h"
16 #include "SkImageFilter.h"
17 #include "SkMath.h"
18 #include "SkMatrix.h"
19 #include "SkOpts.h"
20 #include "SkPath.h"
21 #include "SkPathEffect.h"
22 #include "SkPixelRef.h"
23 #include "SkRefCnt.h"
24 #include "SkResourceCache.h"
25 #include "SkScalerContext.h"
26 #include "SkShader.h"
27 #include "SkStream.h"
28 #include "SkTSearch.h"
29 #include "SkTime.h"
30 #include "SkUtils.h"
31 #include "SkXfermode.h"
32 
33 #include <stdlib.h>
34 
GetVersion(int32_t * major,int32_t * minor,int32_t * patch)35 void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
36     if (major) {
37         *major = SKIA_VERSION_MAJOR;
38     }
39     if (minor) {
40         *minor = SKIA_VERSION_MINOR;
41     }
42     if (patch) {
43         *patch = SKIA_VERSION_PATCH;
44     }
45 }
46 
Init()47 void SkGraphics::Init() {
48     // SkGraphics::Init() must be thread-safe and idempotent.
49     SkCpu::CacheRuntimeFeatures();
50     SkOpts::Init();
51 }
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 
DumpMemoryStatistics(SkTraceMemoryDump * dump)55 void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
56   SkResourceCache::DumpMemoryStatistics(dump);
57   SkGlyphCache::DumpMemoryStatistics(dump);
58 }
59 
PurgeAllCaches()60 void SkGraphics::PurgeAllCaches() {
61     SkGraphics::PurgeFontCache();
62     SkGraphics::PurgeResourceCache();
63     SkImageFilter::PurgeCache();
64 }
65 
66 ///////////////////////////////////////////////////////////////////////////////
67 
68 static const char kFontCacheLimitStr[] = "font-cache-limit";
69 static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
70 
71 static const struct {
72     const char* fStr;
73     size_t fLen;
74     size_t (*fFunc)(size_t);
75 } gFlags[] = {
76     { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
77 };
78 
79 /* flags are of the form param; or param=value; */
SetFlags(const char * flags)80 void SkGraphics::SetFlags(const char* flags) {
81     if (!flags) {
82         return;
83     }
84     const char* nextSemi;
85     do {
86         size_t len = strlen(flags);
87         const char* paramEnd = flags + len;
88         const char* nextEqual = strchr(flags, '=');
89         if (nextEqual && paramEnd > nextEqual) {
90             paramEnd = nextEqual;
91         }
92         nextSemi = strchr(flags, ';');
93         if (nextSemi && paramEnd > nextSemi) {
94             paramEnd = nextSemi;
95         }
96         size_t paramLen = paramEnd - flags;
97         for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
98             if (paramLen != gFlags[i].fLen) {
99                 continue;
100             }
101             if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
102                 size_t val = 0;
103                 if (nextEqual) {
104                     val = (size_t) atoi(nextEqual + 1);
105                 }
106                 (gFlags[i].fFunc)(val);
107                 break;
108             }
109         }
110         flags = nextSemi + 1;
111     } while (nextSemi);
112 }
113