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" |
| 17 | #include "SkGlobals.h" |
| 18 | #include "SkMath.h" |
| 19 | #include "SkMatrix.h" |
| 20 | #include "SkPath.h" |
| 21 | #include "SkPathEffect.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() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | SkGlobals::Init(); |
| 56 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | #ifdef BUILD_EMBOSS_TABLE |
| 58 | SkEmbossMask_BuildTable(); |
| 59 | #endif |
| 60 | #ifdef BUILD_RADIALGRADIENT_TABLE |
| 61 | SkRadialGradient_BuildTable(); |
| 62 | #endif |
| 63 | |
reed@android.com | 5e5adfd | 2009-03-07 03:39:23 +0000 | [diff] [blame] | 64 | #ifdef SK_DEBUGx |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | int i; |
| 66 | |
| 67 | static const struct { |
| 68 | const char* fTypeName; |
| 69 | size_t fSizeOf; |
| 70 | } gTypeSize[] = { |
| 71 | typesizeline(char), |
| 72 | typesizeline(short), |
| 73 | typesizeline(int), |
| 74 | typesizeline(long), |
| 75 | typesizeline(size_t), |
| 76 | typesizeline(void*), |
| 77 | |
| 78 | typesizeline(S8CPU), |
| 79 | typesizeline(U8CPU), |
| 80 | typesizeline(S16CPU), |
| 81 | typesizeline(U16CPU), |
| 82 | |
| 83 | typesizeline(SkPoint), |
| 84 | typesizeline(SkRect), |
| 85 | typesizeline(SkMatrix), |
| 86 | typesizeline(SkPath), |
| 87 | typesizeline(SkGlyph), |
| 88 | typesizeline(SkRefCnt), |
| 89 | |
| 90 | typesizeline(SkPaint), |
| 91 | typesizeline(SkCanvas), |
| 92 | typesizeline(SkBlitter), |
| 93 | typesizeline(SkShader), |
| 94 | typesizeline(SkXfermode), |
| 95 | typesizeline(SkPathEffect) |
| 96 | }; |
| 97 | |
| 98 | #ifdef SK_CPU_BENDIAN |
| 99 | SkDebugf("SkGraphics: big-endian\n"); |
| 100 | #else |
| 101 | SkDebugf("SkGraphics: little-endian\n"); |
| 102 | #endif |
| 103 | |
| 104 | { |
| 105 | char test = 0xFF; |
| 106 | int itest = test; // promote to int, see if it sign-extended |
| 107 | if (itest < 0) |
| 108 | SkDebugf("SkGraphics: char is signed\n"); |
| 109 | else |
| 110 | SkDebugf("SkGraphics: char is unsigned\n"); |
| 111 | } |
reed@android.com | 5e5adfd | 2009-03-07 03:39:23 +0000 | [diff] [blame] | 112 | for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) { |
| 113 | SkDebugf("SkGraphics: sizeof(%s) = %d\n", |
| 114 | gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 116 | |
| 117 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 118 | } |
| 119 | |
reed@google.com | 7db9fe6 | 2011-04-11 11:57:54 +0000 | [diff] [blame] | 120 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 121 | |
| 122 | #include "SkGlyphCache.h" |
reed@google.com | d40da64 | 2011-10-20 13:18:37 +0000 | [diff] [blame] | 123 | #include "SkTypefaceCache.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 124 | |
| 125 | void SkGraphics::Term() { |
| 126 | SkGraphics::SetFontCacheUsed(0); |
reed@google.com | d40da64 | 2011-10-20 13:18:37 +0000 | [diff] [blame] | 127 | SkTypefaceCache::PurgeAll(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 128 | SkGlobals::Term(); |
| 129 | } |
| 130 | |
| 131 | size_t SkGraphics::GetFontCacheUsed() { |
| 132 | return SkGlyphCache::GetCacheUsed(); |
| 133 | } |
| 134 | |
| 135 | bool SkGraphics::SetFontCacheUsed(size_t usageInBytes) { |
| 136 | return SkGlyphCache::SetCacheUsed(usageInBytes); |
| 137 | } |
| 138 | |
reed@google.com | 77407ca | 2011-11-08 13:48:32 +0000 | [diff] [blame^] | 139 | #ifndef SK_DEFAULT_FONT_CACHE_LIMIT |
| 140 | #define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024) |
| 141 | #endif |
| 142 | |
| 143 | #define SK_MIN_FONT_CACHE_LIMIT (256 * 1024) |
| 144 | |
| 145 | static size_t gFontCacheLimit = SK_DEFAULT_FONT_CACHE_LIMIT; |
| 146 | |
| 147 | size_t SkGraphics::GetFontCacheLimit() { |
| 148 | return gFontCacheLimit; |
| 149 | } |
| 150 | |
| 151 | size_t SkGraphics::SetFontCacheLimit(size_t bytes) { |
| 152 | if (bytes < SK_MIN_FONT_CACHE_LIMIT) { |
| 153 | bytes = SK_MIN_FONT_CACHE_LIMIT; |
reed@android.com | 9aa8b32 | 2010-04-13 13:22:54 +0000 | [diff] [blame] | 154 | } |
reed@google.com | 77407ca | 2011-11-08 13:48:32 +0000 | [diff] [blame^] | 155 | gFontCacheLimit = bytes; |
| 156 | |
| 157 | // trigger a purge if the new size is smaller that our currently used amount |
| 158 | if (bytes < GetFontCacheUsed()) { |
| 159 | SetFontCacheUsed(bytes); |
reed@android.com | 9aa8b32 | 2010-04-13 13:22:54 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |