blob: 803b7435bb6b8125817eb4cfef0541e537b070d3 [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"
mtkleineb85fd72016-04-21 10:34:41 -070013#include "SkCpu.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkGeometry.h"
ssid33c594c2015-08-27 09:23:54 -070015#include "SkGlyphCache.h"
reed1d564482016-02-22 06:19:54 -080016#include "SkImageFilter.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000017#include "SkMath.h"
18#include "SkMatrix.h"
mtklein8317a182015-07-30 07:30:16 -070019#include "SkOpts.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000020#include "SkPath.h"
21#include "SkPathEffect.h"
caryclark@google.com9d0c6ec2011-12-20 20:26:56 +000022#include "SkPixelRef.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023#include "SkRefCnt.h"
ssid33c594c2015-08-27 09:23:54 -070024#include "SkResourceCache.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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000031
bungeman60e0fee2015-08-26 05:15:46 -070032#include <stdlib.h>
33
reed@google.com77407ca2011-11-08 13:48:32 +000034void 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
reed@android.com34245c72009-11-03 04:00:48 +000046void SkGraphics::Init() {
mtklein8317a182015-07-30 07:30:16 -070047 // SkGraphics::Init() must be thread-safe and idempotent.
mtkleineb85fd72016-04-21 10:34:41 -070048 SkCpu::CacheRuntimeFeatures();
mtklein8317a182015-07-30 07:30:16 -070049 SkOpts::Init();
reed@android.com8a1c16f2008-12-17 15:59:43 +000050}
51
caryclark@google.com54c782c2011-11-21 20:42:14 +000052///////////////////////////////////////////////////////////////////////////////
53
ssid33c594c2015-08-27 09:23:54 -070054void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
55 SkResourceCache::DumpMemoryStatistics(dump);
56 SkGlyphCache::DumpMemoryStatistics(dump);
57}
58
reed1d564482016-02-22 06:19:54 -080059void SkGraphics::PurgeAllCaches() {
60 SkGraphics::PurgeFontCache();
61 SkGraphics::PurgeResourceCache();
62 SkImageFilter::PurgeCache();
63}
64
ssid33c594c2015-08-27 09:23:54 -070065///////////////////////////////////////////////////////////////////////////////
66
caryclark@google.com54c782c2011-11-21 20:42:14 +000067static const char kFontCacheLimitStr[] = "font-cache-limit";
rmistry@google.comfbfcd562012-08-23 18:09:54 +000068static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
caryclark@google.com54c782c2011-11-21 20:42:14 +000069
70static const struct {
71 const char* fStr;
72 size_t fLen;
73 size_t (*fFunc)(size_t);
74} gFlags[] = {
reed@google.com09837012012-04-23 15:04:44 +000075 { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
caryclark@google.com54c782c2011-11-21 20:42:14 +000076};
77
78/* flags are of the form param; or param=value; */
79void 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}