blob: a2456d808d1e37df0c8a33cec7936b17af3ec2cd [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00008
9#include "SkGraphics.h"
10
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#include "SkBlitter.h"
12#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkGeometry.h"
ssid33c594c2015-08-27 09:23:54 -070014#include "SkGlyphCache.h"
reed1d564482016-02-22 06:19:54 -080015#include "SkImageFilter.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016#include "SkMath.h"
17#include "SkMatrix.h"
mtklein8317a182015-07-30 07:30:16 -070018#include "SkOpts.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#include "SkPath.h"
20#include "SkPathEffect.h"
caryclark@google.com9d0c6ec2011-12-20 20:26:56 +000021#include "SkPixelRef.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000022#include "SkRefCnt.h"
ssid33c594c2015-08-27 09:23:54 -070023#include "SkResourceCache.h"
humper@google.com7af56be2013-01-14 18:49:19 +000024#include "SkRTConf.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000025#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
bungeman60e0fee2015-08-26 05:15:46 -070033#include <stdlib.h>
34
reed@google.com77407ca2011-11-08 13:48:32 +000035void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
36 if (major) {
37 *major = SKIA_VERSION_MAJOR;
38 }
39 if (minor) {
40 *minor = SKIA_VERSION_MINOR;
41 }
42 if (patch) {
43 *patch = SKIA_VERSION_PATCH;
44 }
45}
46
reed@android.com34245c72009-11-03 04:00:48 +000047void SkGraphics::Init() {
mtklein8317a182015-07-30 07:30:16 -070048 // SkGraphics::Init() must be thread-safe and idempotent.
49 SkOpts::Init();
50
humper@google.com7af56be2013-01-14 18:49:19 +000051#ifdef SK_DEVELOPER
52 skRTConfRegistry().possiblyDumpFile();
53 skRTConfRegistry().validate();
halcanary@google.com2d1adf22014-01-10 15:00:45 +000054 if (skRTConfRegistry().hasNonDefault()) {
55 SkDebugf("Non-default runtime configuration options:\n");
56 skRTConfRegistry().printNonDefault();
57 }
humper@google.com7af56be2013-01-14 18:49:19 +000058#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000059}
60
caryclark@google.com54c782c2011-11-21 20:42:14 +000061///////////////////////////////////////////////////////////////////////////////
62
ssid33c594c2015-08-27 09:23:54 -070063void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
64 SkResourceCache::DumpMemoryStatistics(dump);
65 SkGlyphCache::DumpMemoryStatistics(dump);
66}
67
reed1d564482016-02-22 06:19:54 -080068void SkGraphics::PurgeAllCaches() {
69 SkGraphics::PurgeFontCache();
70 SkGraphics::PurgeResourceCache();
71 SkImageFilter::PurgeCache();
72}
73
ssid33c594c2015-08-27 09:23:54 -070074///////////////////////////////////////////////////////////////////////////////
75
caryclark@google.com54c782c2011-11-21 20:42:14 +000076static const char kFontCacheLimitStr[] = "font-cache-limit";
rmistry@google.comfbfcd562012-08-23 18:09:54 +000077static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
caryclark@google.com54c782c2011-11-21 20:42:14 +000078
79static const struct {
80 const char* fStr;
81 size_t fLen;
82 size_t (*fFunc)(size_t);
83} gFlags[] = {
reed@google.com09837012012-04-23 15:04:44 +000084 { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
caryclark@google.com54c782c2011-11-21 20:42:14 +000085};
86
87/* flags are of the form param; or param=value; */
88void SkGraphics::SetFlags(const char* flags) {
89 if (!flags) {
90 return;
91 }
92 const char* nextSemi;
93 do {
94 size_t len = strlen(flags);
95 const char* paramEnd = flags + len;
96 const char* nextEqual = strchr(flags, '=');
97 if (nextEqual && paramEnd > nextEqual) {
98 paramEnd = nextEqual;
99 }
100 nextSemi = strchr(flags, ';');
101 if (nextSemi && paramEnd > nextSemi) {
102 paramEnd = nextSemi;
103 }
104 size_t paramLen = paramEnd - flags;
105 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
106 if (paramLen != gFlags[i].fLen) {
107 continue;
108 }
109 if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
110 size_t val = 0;
111 if (nextEqual) {
112 val = (size_t) atoi(nextEqual + 1);
113 }
114 (gFlags[i].fFunc)(val);
115 break;
116 }
117 }
118 flags = nextSemi + 1;
119 } while (nextSemi);
120}
mtklein86806062016-04-21 07:01:19 -0700121
122// Call SkGraphics::Init() automatically for Google3 processes.
123#if defined(GOOGLE3)
124 static SkAutoGraphics autoGraphics;
125#endif