• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  
32  #include <stdlib.h>
33  
GetVersion(int32_t * major,int32_t * minor,int32_t * patch)34  void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
35      if (major) {
36          *major = SKIA_VERSION_MAJOR;
37      }
38      if (minor) {
39          *minor = SKIA_VERSION_MINOR;
40      }
41      if (patch) {
42          *patch = SKIA_VERSION_PATCH;
43      }
44  }
45  
Init()46  void SkGraphics::Init() {
47      // SkGraphics::Init() must be thread-safe and idempotent.
48      SkCpu::CacheRuntimeFeatures();
49      SkOpts::Init();
50  }
51  
52  ///////////////////////////////////////////////////////////////////////////////
53  
DumpMemoryStatistics(SkTraceMemoryDump * dump)54  void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
55    SkResourceCache::DumpMemoryStatistics(dump);
56    SkGlyphCache::DumpMemoryStatistics(dump);
57  }
58  
PurgeAllCaches()59  void SkGraphics::PurgeAllCaches() {
60      SkGraphics::PurgeFontCache();
61      SkGraphics::PurgeResourceCache();
62      SkImageFilter::PurgeCache();
63  }
64  
65  ///////////////////////////////////////////////////////////////////////////////
66  
67  static const char kFontCacheLimitStr[] = "font-cache-limit";
68  static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
69  
70  static const struct {
71      const char* fStr;
72      size_t fLen;
73      size_t (*fFunc)(size_t);
74  } gFlags[] = {
75      { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
76  };
77  
78  /* flags are of the form param; or param=value; */
SetFlags(const char * flags)79  void SkGraphics::SetFlags(const char* flags) {
80      if (!flags) {
81          return;
82      }
83      const char* nextSemi;
84      do {
85          size_t len = strlen(flags);
86          const char* paramEnd = flags + len;
87          const char* nextEqual = strchr(flags, '=');
88          if (nextEqual && paramEnd > nextEqual) {
89              paramEnd = nextEqual;
90          }
91          nextSemi = strchr(flags, ';');
92          if (nextSemi && paramEnd > nextSemi) {
93              paramEnd = nextSemi;
94          }
95          size_t paramLen = paramEnd - flags;
96          for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
97              if (paramLen != gFlags[i].fLen) {
98                  continue;
99              }
100              if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
101                  size_t val = 0;
102                  if (nextEqual) {
103                      val = (size_t) atoi(nextEqual + 1);
104                  }
105                  (gFlags[i].fFunc)(val);
106                  break;
107              }
108          }
109          flags = nextSemi + 1;
110      } while (nextSemi);
111  }
112