• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkFloat.h"
15 #include "SkGeometry.h"
16 #include "SkMath.h"
17 #include "SkMatrix.h"
18 #include "SkPath.h"
19 #include "SkPathEffect.h"
20 #include "SkPixelRef.h"
21 #include "SkRefCnt.h"
22 #include "SkRTConf.h"
23 #include "SkScalerContext.h"
24 #include "SkShader.h"
25 #include "SkStream.h"
26 #include "SkTSearch.h"
27 #include "SkTime.h"
28 #include "SkUtils.h"
29 #include "SkXfermode.h"
30 
GetVersion(int32_t * major,int32_t * minor,int32_t * patch)31 void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
32     if (major) {
33         *major = SKIA_VERSION_MAJOR;
34     }
35     if (minor) {
36         *minor = SKIA_VERSION_MINOR;
37     }
38     if (patch) {
39         *patch = SKIA_VERSION_PATCH;
40     }
41 }
42 
43 #define typesizeline(type)  { #type , sizeof(type) }
44 
45 #ifdef BUILD_EMBOSS_TABLE
46     extern void SkEmbossMask_BuildTable();
47 #endif
48 
49 #ifdef BUILD_RADIALGRADIENT_TABLE
50     extern void SkRadialGradient_BuildTable();
51 #endif
52 
Init()53 void SkGraphics::Init() {
54 #ifdef SK_DEVELOPER
55     skRTConfRegistry().possiblyDumpFile();
56     skRTConfRegistry().validate();
57     if (skRTConfRegistry().hasNonDefault()) {
58         SkDebugf("Non-default runtime configuration options:\n");
59         skRTConfRegistry().printNonDefault();
60     }
61 #endif
62 
63 #ifdef BUILD_EMBOSS_TABLE
64     SkEmbossMask_BuildTable();
65 #endif
66 #ifdef BUILD_RADIALGRADIENT_TABLE
67     SkRadialGradient_BuildTable();
68 #endif
69 
70 #ifdef SK_DEBUGx
71     int i;
72 
73     static const struct {
74         const char* fTypeName;
75         size_t      fSizeOf;
76     } gTypeSize[] = {
77         typesizeline(char),
78         typesizeline(short),
79         typesizeline(int),
80         typesizeline(long),
81         typesizeline(size_t),
82         typesizeline(void*),
83 
84         typesizeline(S8CPU),
85         typesizeline(U8CPU),
86         typesizeline(S16CPU),
87         typesizeline(U16CPU),
88 
89         typesizeline(SkPoint),
90         typesizeline(SkRect),
91         typesizeline(SkMatrix),
92         typesizeline(SkPath),
93         typesizeline(SkGlyph),
94         typesizeline(SkRefCnt),
95 
96         typesizeline(SkPaint),
97         typesizeline(SkCanvas),
98         typesizeline(SkBlitter),
99         typesizeline(SkShader),
100         typesizeline(SkXfermode),
101         typesizeline(SkPathEffect)
102     };
103 
104 #ifdef SK_CPU_BENDIAN
105     SkDebugf("SkGraphics: big-endian\n");
106 #else
107     SkDebugf("SkGraphics: little-endian\n");
108 #endif
109 
110     {
111         char    test = 0xFF;
112         int     itest = test;   // promote to int, see if it sign-extended
113         if (itest < 0)
114             SkDebugf("SkGraphics: char is signed\n");
115         else
116             SkDebugf("SkGraphics: char is unsigned\n");
117     }
118     for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
119         SkDebugf("SkGraphics: sizeof(%s) = %d\n",
120                  gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
121     }
122     SkDebugf("SkGraphics: font cache limit %dK\n",
123              GetFontCacheLimit() >> 10);
124 
125 #endif
126 
127 }
128 
Term()129 void SkGraphics::Term() {
130     PurgeFontCache();
131     SkPaint::Term();
132 }
133 
134 ///////////////////////////////////////////////////////////////////////////////
135 
136 static const char kFontCacheLimitStr[] = "font-cache-limit";
137 static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
138 
139 static 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; */
SetFlags(const char * flags)148 void 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