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