epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | |
| 9 | #include "SkGraphics.h" |
| 10 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | #include "SkBlitter.h" |
| 12 | #include "SkCanvas.h" |
mtklein | eb85fd7 | 2016-04-21 10:34:41 -0700 | [diff] [blame] | 13 | #include "SkCpu.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #include "SkGeometry.h" |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 15 | #include "SkGlyphCache.h" |
reed | 1d56448 | 2016-02-22 06:19:54 -0800 | [diff] [blame] | 16 | #include "SkImageFilter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | #include "SkMath.h" |
| 18 | #include "SkMatrix.h" |
mtklein | 8317a18 | 2015-07-30 07:30:16 -0700 | [diff] [blame] | 19 | #include "SkOpts.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | #include "SkPath.h" |
| 21 | #include "SkPathEffect.h" |
caryclark@google.com | 9d0c6ec | 2011-12-20 20:26:56 +0000 | [diff] [blame] | 22 | #include "SkPixelRef.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | #include "SkRefCnt.h" |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 24 | #include "SkResourceCache.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | #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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 32 | #include <stdlib.h> |
| 33 | |
reed@google.com | 77407ca | 2011-11-08 13:48:32 +0000 | [diff] [blame] | 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 | |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 46 | void SkGraphics::Init() { |
mtklein | 8317a18 | 2015-07-30 07:30:16 -0700 | [diff] [blame] | 47 | // SkGraphics::Init() must be thread-safe and idempotent. |
mtklein | eb85fd7 | 2016-04-21 10:34:41 -0700 | [diff] [blame] | 48 | SkCpu::CacheRuntimeFeatures(); |
mtklein | 8317a18 | 2015-07-30 07:30:16 -0700 | [diff] [blame] | 49 | SkOpts::Init(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | } |
| 51 | |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 54 | void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) { |
| 55 | SkResourceCache::DumpMemoryStatistics(dump); |
| 56 | SkGlyphCache::DumpMemoryStatistics(dump); |
| 57 | } |
| 58 | |
reed | 1d56448 | 2016-02-22 06:19:54 -0800 | [diff] [blame] | 59 | void SkGraphics::PurgeAllCaches() { |
| 60 | SkGraphics::PurgeFontCache(); |
| 61 | SkGraphics::PurgeResourceCache(); |
| 62 | SkImageFilter::PurgeCache(); |
| 63 | } |
| 64 | |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 65 | /////////////////////////////////////////////////////////////////////////////// |
| 66 | |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 67 | static const char kFontCacheLimitStr[] = "font-cache-limit"; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 68 | static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1; |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 69 | |
| 70 | static const struct { |
| 71 | const char* fStr; |
| 72 | size_t fLen; |
| 73 | size_t (*fFunc)(size_t); |
| 74 | } gFlags[] = { |
reed@google.com | 0983701 | 2012-04-23 15:04:44 +0000 | [diff] [blame] | 75 | { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit } |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /* flags are of the form param; or param=value; */ |
| 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 | } |