michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkGraphics.h" michael@0: michael@0: #include "SkBlitter.h" michael@0: #include "SkCanvas.h" michael@0: #include "SkFloat.h" michael@0: #include "SkGeometry.h" michael@0: #include "SkMath.h" michael@0: #include "SkMatrix.h" michael@0: #include "SkPath.h" michael@0: #include "SkPathEffect.h" michael@0: #include "SkPixelRef.h" michael@0: #include "SkRefCnt.h" michael@0: #include "SkRTConf.h" michael@0: #include "SkScalerContext.h" michael@0: #include "SkShader.h" michael@0: #include "SkStream.h" michael@0: #include "SkTSearch.h" michael@0: #include "SkTime.h" michael@0: #include "SkUtils.h" michael@0: #include "SkXfermode.h" michael@0: michael@0: void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) { michael@0: if (major) { michael@0: *major = SKIA_VERSION_MAJOR; michael@0: } michael@0: if (minor) { michael@0: *minor = SKIA_VERSION_MINOR; michael@0: } michael@0: if (patch) { michael@0: *patch = SKIA_VERSION_PATCH; michael@0: } michael@0: } michael@0: michael@0: #define typesizeline(type) { #type , sizeof(type) } michael@0: michael@0: #ifdef BUILD_EMBOSS_TABLE michael@0: extern void SkEmbossMask_BuildTable(); michael@0: #endif michael@0: michael@0: #ifdef BUILD_RADIALGRADIENT_TABLE michael@0: extern void SkRadialGradient_BuildTable(); michael@0: #endif michael@0: michael@0: void SkGraphics::Init() { michael@0: #ifdef SK_DEVELOPER michael@0: skRTConfRegistry().possiblyDumpFile(); michael@0: skRTConfRegistry().validate(); michael@0: if (skRTConfRegistry().hasNonDefault()) { michael@0: SkDebugf("Non-default runtime configuration options:\n"); michael@0: skRTConfRegistry().printNonDefault(); michael@0: } michael@0: #endif michael@0: michael@0: #ifdef BUILD_EMBOSS_TABLE michael@0: SkEmbossMask_BuildTable(); michael@0: #endif michael@0: #ifdef BUILD_RADIALGRADIENT_TABLE michael@0: SkRadialGradient_BuildTable(); michael@0: #endif michael@0: michael@0: #ifdef SK_DEBUGx michael@0: int i; michael@0: michael@0: static const struct { michael@0: const char* fTypeName; michael@0: size_t fSizeOf; michael@0: } gTypeSize[] = { michael@0: typesizeline(char), michael@0: typesizeline(short), michael@0: typesizeline(int), michael@0: typesizeline(long), michael@0: typesizeline(size_t), michael@0: typesizeline(void*), michael@0: michael@0: typesizeline(S8CPU), michael@0: typesizeline(U8CPU), michael@0: typesizeline(S16CPU), michael@0: typesizeline(U16CPU), michael@0: michael@0: typesizeline(SkPoint), michael@0: typesizeline(SkRect), michael@0: typesizeline(SkMatrix), michael@0: typesizeline(SkPath), michael@0: typesizeline(SkGlyph), michael@0: typesizeline(SkRefCnt), michael@0: michael@0: typesizeline(SkPaint), michael@0: typesizeline(SkCanvas), michael@0: typesizeline(SkBlitter), michael@0: typesizeline(SkShader), michael@0: typesizeline(SkXfermode), michael@0: typesizeline(SkPathEffect) michael@0: }; michael@0: michael@0: #ifdef SK_CPU_BENDIAN michael@0: SkDebugf("SkGraphics: big-endian\n"); michael@0: #else michael@0: SkDebugf("SkGraphics: little-endian\n"); michael@0: #endif michael@0: michael@0: { michael@0: char test = 0xFF; michael@0: int itest = test; // promote to int, see if it sign-extended michael@0: if (itest < 0) michael@0: SkDebugf("SkGraphics: char is signed\n"); michael@0: else michael@0: SkDebugf("SkGraphics: char is unsigned\n"); michael@0: } michael@0: for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) { michael@0: SkDebugf("SkGraphics: sizeof(%s) = %d\n", michael@0: gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf); michael@0: } michael@0: SkDebugf("SkGraphics: font cache limit %dK\n", michael@0: GetFontCacheLimit() >> 10); michael@0: michael@0: #endif michael@0: michael@0: } michael@0: michael@0: void SkGraphics::Term() { michael@0: PurgeFontCache(); michael@0: SkPaint::Term(); michael@0: SkXfermode::Term(); michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: static const char kFontCacheLimitStr[] = "font-cache-limit"; michael@0: static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1; michael@0: michael@0: static const struct { michael@0: const char* fStr; michael@0: size_t fLen; michael@0: size_t (*fFunc)(size_t); michael@0: } gFlags[] = { michael@0: { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit } michael@0: }; michael@0: michael@0: /* flags are of the form param; or param=value; */ michael@0: void SkGraphics::SetFlags(const char* flags) { michael@0: if (!flags) { michael@0: return; michael@0: } michael@0: const char* nextSemi; michael@0: do { michael@0: size_t len = strlen(flags); michael@0: const char* paramEnd = flags + len; michael@0: const char* nextEqual = strchr(flags, '='); michael@0: if (nextEqual && paramEnd > nextEqual) { michael@0: paramEnd = nextEqual; michael@0: } michael@0: nextSemi = strchr(flags, ';'); michael@0: if (nextSemi && paramEnd > nextSemi) { michael@0: paramEnd = nextSemi; michael@0: } michael@0: size_t paramLen = paramEnd - flags; michael@0: for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) { michael@0: if (paramLen != gFlags[i].fLen) { michael@0: continue; michael@0: } michael@0: if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) { michael@0: size_t val = 0; michael@0: if (nextEqual) { michael@0: val = (size_t) atoi(nextEqual + 1); michael@0: } michael@0: (gFlags[i].fFunc)(val); michael@0: break; michael@0: } michael@0: } michael@0: flags = nextSemi + 1; michael@0: } while (nextSemi); michael@0: }