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 "SkMath.h"
16#include "SkMatrix.h"
17#include "SkPath.h"
18#include "SkPathEffect.h"
19#include "SkPixelRef.h"
20#include "SkRefCnt.h"
21#include "SkRTConf.h"
22#include "SkScalerContext.h"
23#include "SkShader.h"
24#include "SkStream.h"
25#include "SkTSearch.h"
26#include "SkTime.h"
27#include "SkUtils.h"
28#include "SkXfermode.h"
29
30void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
31    if (major) {
32        *major = SKIA_VERSION_MAJOR;
33    }
34    if (minor) {
35        *minor = SKIA_VERSION_MINOR;
36    }
37    if (patch) {
38        *patch = SKIA_VERSION_PATCH;
39    }
40}
41
42#define typesizeline(type)  { #type , sizeof(type) }
43
44#ifdef BUILD_EMBOSS_TABLE
45    extern void SkEmbossMask_BuildTable();
46#endif
47
48#ifdef BUILD_RADIALGRADIENT_TABLE
49    extern void SkRadialGradient_BuildTable();
50#endif
51
52void SkGraphics::Init() {
53#ifdef SK_DEVELOPER
54    skRTConfRegistry().possiblyDumpFile();
55    skRTConfRegistry().validate();
56    if (skRTConfRegistry().hasNonDefault()) {
57        SkDebugf("Non-default runtime configuration options:\n");
58        skRTConfRegistry().printNonDefault();
59    }
60#endif
61
62#ifdef BUILD_EMBOSS_TABLE
63    SkEmbossMask_BuildTable();
64#endif
65#ifdef BUILD_RADIALGRADIENT_TABLE
66    SkRadialGradient_BuildTable();
67#endif
68
69#ifdef SK_DEBUGx
70    int i;
71
72    static const struct {
73        const char* fTypeName;
74        size_t      fSizeOf;
75    } gTypeSize[] = {
76        typesizeline(char),
77        typesizeline(short),
78        typesizeline(int),
79        typesizeline(long),
80        typesizeline(size_t),
81        typesizeline(void*),
82
83        typesizeline(S8CPU),
84        typesizeline(U8CPU),
85        typesizeline(S16CPU),
86        typesizeline(U16CPU),
87
88        typesizeline(SkPoint),
89        typesizeline(SkRect),
90        typesizeline(SkMatrix),
91        typesizeline(SkPath),
92        typesizeline(SkGlyph),
93        typesizeline(SkRefCnt),
94
95        typesizeline(SkPaint),
96        typesizeline(SkCanvas),
97        typesizeline(SkBlitter),
98        typesizeline(SkShader),
99        typesizeline(SkXfermode),
100        typesizeline(SkPathEffect)
101    };
102
103#ifdef SK_CPU_BENDIAN
104    SkDebugf("SkGraphics: big-endian\n");
105#else
106    SkDebugf("SkGraphics: little-endian\n");
107#endif
108
109    {
110        char    test = 0xFF;
111        int     itest = test;   // promote to int, see if it sign-extended
112        if (itest < 0)
113            SkDebugf("SkGraphics: char is signed\n");
114        else
115            SkDebugf("SkGraphics: char is unsigned\n");
116    }
117    for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
118        SkDebugf("SkGraphics: sizeof(%s) = %d\n",
119                 gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
120    }
121    SkDebugf("SkGraphics: font cache limit %dK\n",
122             GetFontCacheLimit() >> 10);
123
124#endif
125
126}
127
128void SkGraphics::Term() {
129    PurgeFontCache();
130    PurgeResourceCache();
131    SkPaint::Term();
132}
133
134///////////////////////////////////////////////////////////////////////////////
135
136static const char kFontCacheLimitStr[] = "font-cache-limit";
137static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
138
139static const struct {
140    const char* fStr;
141    size_t fLen;
142    size_t (*fFunc)(size_t);
143} gFlags[] = {
144    { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
145};
146
147/* flags are of the form param; or param=value; */
148void SkGraphics::SetFlags(const char* flags) {
149    if (!flags) {
150        return;
151    }
152    const char* nextSemi;
153    do {
154        size_t len = strlen(flags);
155        const char* paramEnd = flags + len;
156        const char* nextEqual = strchr(flags, '=');
157        if (nextEqual && paramEnd > nextEqual) {
158            paramEnd = nextEqual;
159        }
160        nextSemi = strchr(flags, ';');
161        if (nextSemi && paramEnd > nextSemi) {
162            paramEnd = nextSemi;
163        }
164        size_t paramLen = paramEnd - flags;
165        for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
166            if (paramLen != gFlags[i].fLen) {
167                continue;
168            }
169            if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
170                size_t val = 0;
171                if (nextEqual) {
172                    val = (size_t) atoi(nextEqual + 1);
173                }
174                (gFlags[i].fFunc)(val);
175                break;
176            }
177        }
178        flags = nextSemi + 1;
179    } while (nextSemi);
180}
181