1
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#include "SkGraphics.h"
11
12#include "SkBlitter.h"
13#include "SkCanvas.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 "SkRTConf.h"
26#include "SkScalerContext.h"
27#include "SkShader.h"
28#include "SkStream.h"
29#include "SkTSearch.h"
30#include "SkTime.h"
31#include "SkUtils.h"
32#include "SkXfermode.h"
33
34#include <stdlib.h>
35
36void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
37    if (major) {
38        *major = SKIA_VERSION_MAJOR;
39    }
40    if (minor) {
41        *minor = SKIA_VERSION_MINOR;
42    }
43    if (patch) {
44        *patch = SKIA_VERSION_PATCH;
45    }
46}
47
48void SkGraphics::Init() {
49    // SkGraphics::Init() must be thread-safe and idempotent.
50    SkOpts::Init();
51
52#ifdef SK_DEVELOPER
53    skRTConfRegistry().possiblyDumpFile();
54    skRTConfRegistry().validate();
55    if (skRTConfRegistry().hasNonDefault()) {
56        SkDebugf("Non-default runtime configuration options:\n");
57        skRTConfRegistry().printNonDefault();
58    }
59#endif
60}
61
62///////////////////////////////////////////////////////////////////////////////
63
64void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
65  SkResourceCache::DumpMemoryStatistics(dump);
66  SkGlyphCache::DumpMemoryStatistics(dump);
67}
68
69void SkGraphics::PurgeAllCaches() {
70    SkGraphics::PurgeFontCache();
71    SkGraphics::PurgeResourceCache();
72    SkImageFilter::PurgeCache();
73}
74
75///////////////////////////////////////////////////////////////////////////////
76
77static const char kFontCacheLimitStr[] = "font-cache-limit";
78static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
79
80static const struct {
81    const char* fStr;
82    size_t fLen;
83    size_t (*fFunc)(size_t);
84} gFlags[] = {
85    { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
86};
87
88/* flags are of the form param; or param=value; */
89void SkGraphics::SetFlags(const char* flags) {
90    if (!flags) {
91        return;
92    }
93    const char* nextSemi;
94    do {
95        size_t len = strlen(flags);
96        const char* paramEnd = flags + len;
97        const char* nextEqual = strchr(flags, '=');
98        if (nextEqual && paramEnd > nextEqual) {
99            paramEnd = nextEqual;
100        }
101        nextSemi = strchr(flags, ';');
102        if (nextSemi && paramEnd > nextSemi) {
103            paramEnd = nextSemi;
104        }
105        size_t paramLen = paramEnd - flags;
106        for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
107            if (paramLen != gFlags[i].fLen) {
108                continue;
109            }
110            if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
111                size_t val = 0;
112                if (nextEqual) {
113                    val = (size_t) atoi(nextEqual + 1);
114                }
115                (gFlags[i].fFunc)(val);
116                break;
117            }
118        }
119        flags = nextSemi + 1;
120    } while (nextSemi);
121}
122