epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkGraphics.h" |
| 11 | |
| 12 | #include "Sk64.h" |
| 13 | #include "SkBlitter.h" |
| 14 | #include "SkCanvas.h" |
| 15 | #include "SkFloat.h" |
| 16 | #include "SkGeometry.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | #include "SkMath.h" |
| 18 | #include "SkMatrix.h" |
| 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 "SkRandom.h" |
| 23 | #include "SkRefCnt.h" |
| 24 | #include "SkScalerContext.h" |
| 25 | #include "SkShader.h" |
| 26 | #include "SkStream.h" |
| 27 | #include "SkTSearch.h" |
| 28 | #include "SkTime.h" |
| 29 | #include "SkUtils.h" |
| 30 | #include "SkXfermode.h" |
| 31 | |
reed@google.com | 77407ca | 2011-11-08 13:48:32 +0000 | [diff] [blame] | 32 | void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) { |
| 33 | if (major) { |
| 34 | *major = SKIA_VERSION_MAJOR; |
| 35 | } |
| 36 | if (minor) { |
| 37 | *minor = SKIA_VERSION_MINOR; |
| 38 | } |
| 39 | if (patch) { |
| 40 | *patch = SKIA_VERSION_PATCH; |
| 41 | } |
| 42 | } |
| 43 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | #define typesizeline(type) { #type , sizeof(type) } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | #ifdef BUILD_EMBOSS_TABLE |
| 47 | extern void SkEmbossMask_BuildTable(); |
| 48 | #endif |
| 49 | |
| 50 | #ifdef BUILD_RADIALGRADIENT_TABLE |
| 51 | extern void SkRadialGradient_BuildTable(); |
| 52 | #endif |
| 53 | |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 54 | void SkGraphics::Init() { |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 55 | #if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 56 | SkFlattenable::InitializeFlattenables(); |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 57 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | #ifdef BUILD_EMBOSS_TABLE |
| 59 | SkEmbossMask_BuildTable(); |
| 60 | #endif |
| 61 | #ifdef BUILD_RADIALGRADIENT_TABLE |
| 62 | SkRadialGradient_BuildTable(); |
| 63 | #endif |
| 64 | |
reed@android.com | 5e5adfd | 2009-03-07 03:39:23 +0000 | [diff] [blame] | 65 | #ifdef SK_DEBUGx |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | int i; |
| 67 | |
| 68 | static const struct { |
| 69 | const char* fTypeName; |
| 70 | size_t fSizeOf; |
| 71 | } gTypeSize[] = { |
| 72 | typesizeline(char), |
| 73 | typesizeline(short), |
| 74 | typesizeline(int), |
| 75 | typesizeline(long), |
| 76 | typesizeline(size_t), |
| 77 | typesizeline(void*), |
| 78 | |
| 79 | typesizeline(S8CPU), |
| 80 | typesizeline(U8CPU), |
| 81 | typesizeline(S16CPU), |
| 82 | typesizeline(U16CPU), |
| 83 | |
| 84 | typesizeline(SkPoint), |
| 85 | typesizeline(SkRect), |
| 86 | typesizeline(SkMatrix), |
| 87 | typesizeline(SkPath), |
| 88 | typesizeline(SkGlyph), |
| 89 | typesizeline(SkRefCnt), |
| 90 | |
| 91 | typesizeline(SkPaint), |
| 92 | typesizeline(SkCanvas), |
| 93 | typesizeline(SkBlitter), |
| 94 | typesizeline(SkShader), |
| 95 | typesizeline(SkXfermode), |
| 96 | typesizeline(SkPathEffect) |
| 97 | }; |
| 98 | |
| 99 | #ifdef SK_CPU_BENDIAN |
| 100 | SkDebugf("SkGraphics: big-endian\n"); |
| 101 | #else |
| 102 | SkDebugf("SkGraphics: little-endian\n"); |
| 103 | #endif |
| 104 | |
| 105 | { |
| 106 | char test = 0xFF; |
| 107 | int itest = test; // promote to int, see if it sign-extended |
| 108 | if (itest < 0) |
| 109 | SkDebugf("SkGraphics: char is signed\n"); |
| 110 | else |
| 111 | SkDebugf("SkGraphics: char is unsigned\n"); |
| 112 | } |
reed@android.com | 5e5adfd | 2009-03-07 03:39:23 +0000 | [diff] [blame] | 113 | for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) { |
| 114 | SkDebugf("SkGraphics: sizeof(%s) = %d\n", |
| 115 | gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | } |
reed@google.com | 073c907 | 2011-11-08 20:03:48 +0000 | [diff] [blame] | 117 | SkDebugf("SkGraphics: font cache limit %dK\n", |
| 118 | GetFontCacheLimit() >> 10); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 119 | |
| 120 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 121 | } |
| 122 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 123 | void SkGraphics::Term() { |
caryclark@google.com | f86ab84 | 2011-12-16 17:11:17 +0000 | [diff] [blame] | 124 | PurgeFontCache(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 125 | } |
| 126 | |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 127 | /////////////////////////////////////////////////////////////////////////////// |
| 128 | |
| 129 | static const char kFontCacheLimitStr[] = "font-cache-limit"; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 130 | static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1; |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 131 | |
| 132 | static const struct { |
| 133 | const char* fStr; |
| 134 | size_t fLen; |
| 135 | size_t (*fFunc)(size_t); |
| 136 | } gFlags[] = { |
reed@google.com | 0983701 | 2012-04-23 15:04:44 +0000 | [diff] [blame] | 137 | { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit } |
caryclark@google.com | 54c782c | 2011-11-21 20:42:14 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | /* flags are of the form param; or param=value; */ |
| 141 | void SkGraphics::SetFlags(const char* flags) { |
| 142 | if (!flags) { |
| 143 | return; |
| 144 | } |
| 145 | const char* nextSemi; |
| 146 | do { |
| 147 | size_t len = strlen(flags); |
| 148 | const char* paramEnd = flags + len; |
| 149 | const char* nextEqual = strchr(flags, '='); |
| 150 | if (nextEqual && paramEnd > nextEqual) { |
| 151 | paramEnd = nextEqual; |
| 152 | } |
| 153 | nextSemi = strchr(flags, ';'); |
| 154 | if (nextSemi && paramEnd > nextSemi) { |
| 155 | paramEnd = nextSemi; |
| 156 | } |
| 157 | size_t paramLen = paramEnd - flags; |
| 158 | for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) { |
| 159 | if (paramLen != gFlags[i].fLen) { |
| 160 | continue; |
| 161 | } |
| 162 | if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) { |
| 163 | size_t val = 0; |
| 164 | if (nextEqual) { |
| 165 | val = (size_t) atoi(nextEqual + 1); |
| 166 | } |
| 167 | (gFlags[i].fFunc)(val); |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | flags = nextSemi + 1; |
| 172 | } while (nextSemi); |
| 173 | } |