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