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 9 10 #include "SkGraphics.h" 11 12 #include "SkBlitter.h" 13 #include "SkCanvas.h" 14 #include "SkFloat.h" 15 #include "SkGeometry.h" 16 #include "SkMath.h" 17 #include "SkMatrix.h" 18 #include "SkPath.h" 19 #include "SkPathEffect.h" 20 #include "SkPixelRef.h" 21 #include "SkRefCnt.h" 22 #include "SkRTConf.h" 23 #include "SkScalerContext.h" 24 #include "SkShader.h" 25 #include "SkStream.h" 26 #include "SkTSearch.h" 27 #include "SkTime.h" 28 #include "SkUtils.h" 29 #include "SkXfermode.h" 30 31 void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) { 32 if (major) { 33 *major = SKIA_VERSION_MAJOR; 34 } 35 if (minor) { 36 *minor = SKIA_VERSION_MINOR; 37 } 38 if (patch) { 39 *patch = SKIA_VERSION_PATCH; 40 } 41 } 42 43 #define typesizeline(type) { #type , sizeof(type) } 44 45 #ifdef BUILD_EMBOSS_TABLE 46 extern void SkEmbossMask_BuildTable(); 47 #endif 48 49 #ifdef BUILD_RADIALGRADIENT_TABLE 50 extern void SkRadialGradient_BuildTable(); 51 #endif 52 53 void SkGraphics::Init() { 54 #ifdef SK_DEVELOPER 55 skRTConfRegistry().possiblyDumpFile(); 56 skRTConfRegistry().validate(); 57 if (skRTConfRegistry().hasNonDefault()) { 58 SkDebugf("Non-default runtime configuration options:\n"); 59 skRTConfRegistry().printNonDefault(); 60 } 61 #endif 62 63 #ifdef BUILD_EMBOSS_TABLE 64 SkEmbossMask_BuildTable(); 65 #endif 66 #ifdef BUILD_RADIALGRADIENT_TABLE 67 SkRadialGradient_BuildTable(); 68 #endif 69 70 #ifdef SK_DEBUGx 71 int i; 72 73 static const struct { 74 const char* fTypeName; 75 size_t fSizeOf; 76 } gTypeSize[] = { 77 typesizeline(char), 78 typesizeline(short), 79 typesizeline(int), 80 typesizeline(long), 81 typesizeline(size_t), 82 typesizeline(void*), 83 84 typesizeline(S8CPU), 85 typesizeline(U8CPU), 86 typesizeline(S16CPU), 87 typesizeline(U16CPU), 88 89 typesizeline(SkPoint), 90 typesizeline(SkRect), 91 typesizeline(SkMatrix), 92 typesizeline(SkPath), 93 typesizeline(SkGlyph), 94 typesizeline(SkRefCnt), 95 96 typesizeline(SkPaint), 97 typesizeline(SkCanvas), 98 typesizeline(SkBlitter), 99 typesizeline(SkShader), 100 typesizeline(SkXfermode), 101 typesizeline(SkPathEffect) 102 }; 103 104 #ifdef SK_CPU_BENDIAN 105 SkDebugf("SkGraphics: big-endian\n"); 106 #else 107 SkDebugf("SkGraphics: little-endian\n"); 108 #endif 109 110 { 111 char test = 0xFF; 112 int itest = test; // promote to int, see if it sign-extended 113 if (itest < 0) 114 SkDebugf("SkGraphics: char is signed\n"); 115 else 116 SkDebugf("SkGraphics: char is unsigned\n"); 117 } 118 for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) { 119 SkDebugf("SkGraphics: sizeof(%s) = %d\n", 120 gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf); 121 } 122 SkDebugf("SkGraphics: font cache limit %dK\n", 123 GetFontCacheLimit() >> 10); 124 125 #endif 126 127 } 128 129 void SkGraphics::Term() { 130 PurgeFontCache(); 131 PurgeResourceCache(); 132 SkPaint::Term(); 133 } 134 135 /////////////////////////////////////////////////////////////////////////////// 136 137 static const char kFontCacheLimitStr[] = "font-cache-limit"; 138 static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1; 139 140 static const struct { 141 const char* fStr; 142 size_t fLen; 143 size_t (*fFunc)(size_t); 144 } gFlags[] = { 145 { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit } 146 }; 147 148 /* flags are of the form param; or param=value; */ 149 void SkGraphics::SetFlags(const char* flags) { 150 if (!flags) { 151 return; 152 } 153 const char* nextSemi; 154 do { 155 size_t len = strlen(flags); 156 const char* paramEnd = flags + len; 157 const char* nextEqual = strchr(flags, '='); 158 if (nextEqual && paramEnd > nextEqual) { 159 paramEnd = nextEqual; 160 } 161 nextSemi = strchr(flags, ';'); 162 if (nextSemi && paramEnd > nextSemi) { 163 paramEnd = nextSemi; 164 } 165 size_t paramLen = paramEnd - flags; 166 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) { 167 if (paramLen != gFlags[i].fLen) { 168 continue; 169 } 170 if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) { 171 size_t val = 0; 172 if (nextEqual) { 173 val = (size_t) atoi(nextEqual + 1); 174 } 175 (gFlags[i].fFunc)(val); 176 break; 177 } 178 } 179 flags = nextSemi + 1; 180 } while (nextSemi); 181 } 182