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" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkGeometry.h" |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 14 | #include "SkGlyphCache.h" |
reed | 1d56448 | 2016-02-22 06:19:54 -0800 | [diff] [blame] | 15 | #include "SkImageFilter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkMath.h" |
| 17 | #include "SkMatrix.h" |
mtklein | 8317a18 | 2015-07-30 07:30:16 -0700 | [diff] [blame] | 18 | #include "SkOpts.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | #include "SkPath.h" |
| 20 | #include "SkPathEffect.h" |
caryclark@google.com | 9d0c6ec | 2011-12-20 20:26:56 +0000 | [diff] [blame] | 21 | #include "SkPixelRef.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | #include "SkRefCnt.h" |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 23 | #include "SkResourceCache.h" |
humper@google.com | 7af56be | 2013-01-14 18:49:19 +0000 | [diff] [blame] | 24 | #include "SkRTConf.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" |
| 31 | #include "SkXfermode.h" |
| 32 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 33 | #include <stdlib.h> |
| 34 | |
reed@google.com | 77407ca | 2011-11-08 13:48:32 +0000 | [diff] [blame] | 35 | void 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.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 47 | void SkGraphics::Init() { |
mtklein | 8317a18 | 2015-07-30 07:30:16 -0700 | [diff] [blame] | 48 | // SkGraphics::Init() must be thread-safe and idempotent. |
| 49 | SkOpts::Init(); |
| 50 | |
humper@google.com | 7af56be | 2013-01-14 18:49:19 +0000 | [diff] [blame] | 51 | #ifdef SK_DEVELOPER |
| 52 | skRTConfRegistry().possiblyDumpFile(); |
| 53 | skRTConfRegistry().validate(); |
halcanary@google.com | 2d1adf2 | 2014-01-10 15:00:45 +0000 | [diff] [blame] | 54 | if (skRTConfRegistry().hasNonDefault()) { |
| 55 | SkDebugf("Non-default runtime configuration options:\n"); |
| 56 | skRTConfRegistry().printNonDefault(); |
| 57 | } |
humper@google.com | 7af56be | 2013-01-14 18:49:19 +0000 | [diff] [blame] | 58 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | } |
| 60 | |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 61 | /////////////////////////////////////////////////////////////////////////////// |
| 62 | |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 63 | void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) { |
| 64 | SkResourceCache::DumpMemoryStatistics(dump); |
| 65 | SkGlyphCache::DumpMemoryStatistics(dump); |
| 66 | } |
| 67 | |
reed | 1d56448 | 2016-02-22 06:19:54 -0800 | [diff] [blame] | 68 | void SkGraphics::PurgeAllCaches() { |
| 69 | SkGraphics::PurgeFontCache(); |
| 70 | SkGraphics::PurgeResourceCache(); |
| 71 | SkImageFilter::PurgeCache(); |
| 72 | } |
| 73 | |
ssid | 33c594c | 2015-08-27 09:23:54 -0700 | [diff] [blame] | 74 | /////////////////////////////////////////////////////////////////////////////// |
| 75 | |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 76 | static const char kFontCacheLimitStr[] = "font-cache-limit"; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 77 | static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1; |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 78 | |
| 79 | static const struct { |
| 80 | const char* fStr; |
| 81 | size_t fLen; |
| 82 | size_t (*fFunc)(size_t); |
| 83 | } gFlags[] = { |
reed@google.com | 0983701 | 2012-04-23 15:04:44 +0000 | [diff] [blame] | 84 | { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit } |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /* flags are of the form param; or param=value; */ |
| 88 | void 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 | } |
mtklein | 8680606 | 2016-04-21 07:01:19 -0700 | [diff] [blame^] | 121 | |
| 122 | // Call SkGraphics::Init() automatically for Google3 processes. |
| 123 | #if defined(GOOGLE3) |
| 124 | static SkAutoGraphics autoGraphics; |
| 125 | #endif |