Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_TEXT_LAYOUT_CACHE_H |
| 18 | #define ANDROID_TEXT_LAYOUT_CACHE_H |
| 19 | |
| 20 | #include "RtlProperties.h" |
| 21 | |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 22 | #include <stddef.h> |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 23 | #include <utils/threads.h> |
| 24 | #include <utils/String16.h> |
Raph Levien | d98efca | 2012-10-25 23:17:33 -0700 | [diff] [blame^] | 25 | #include <utils/LruCache.h> |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 26 | #include <utils/KeyedVector.h> |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 27 | #include <utils/Compare.h> |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
Fabrice Di Meglio | 163268b | 2011-09-07 18:12:11 -0700 | [diff] [blame] | 29 | #include <utils/Singleton.h> |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 30 | |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 31 | #include <SkPaint.h> |
| 32 | #include <SkTemplates.h> |
| 33 | #include <SkUtils.h> |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 34 | #include <SkAutoKern.h> |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 35 | #include <SkLanguage.h> |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 36 | |
Fabrice Di Meglio | eee49c6 | 2011-03-24 17:21:23 -0700 | [diff] [blame] | 37 | #include <unicode/ubidi.h> |
| 38 | #include <unicode/ushape.h> |
Fabrice Di Meglio | 902a5b3 | 2011-12-08 18:59:14 -0800 | [diff] [blame] | 39 | #include <unicode/unistr.h> |
| 40 | |
Fabrice Di Meglio | 9f82b58 | 2011-03-08 12:02:59 -0800 | [diff] [blame] | 41 | #include "HarfbuzzSkia.h" |
| 42 | #include "harfbuzz-shaper.h" |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 43 | |
| 44 | #include <android_runtime/AndroidRuntime.h> |
| 45 | |
| 46 | #define UNICODE_NOT_A_CHAR 0xffff |
| 47 | #define UNICODE_ZWSP 0x200b |
| 48 | #define UNICODE_FIRST_LOW_SURROGATE 0xdc00 |
| 49 | #define UNICODE_FIRST_HIGH_SURROGATE 0xd800 |
| 50 | #define UNICODE_FIRST_PRIVATE_USE 0xe000 |
| 51 | #define UNICODE_FIRST_RTL_CHAR 0x0590 |
| 52 | |
| 53 | // Temporary buffer size |
| 54 | #define CHAR_BUFFER_SIZE 80 |
| 55 | |
| 56 | // Converts a number of mega-bytes into bytes |
| 57 | #define MB(s) s * 1024 * 1024 |
| 58 | |
| 59 | // Define the default cache size in Mb |
Raph Levien | 161ebab | 2012-07-18 15:57:15 -0700 | [diff] [blame] | 60 | #define DEFAULT_TEXT_LAYOUT_CACHE_SIZE_IN_MB 0.500f |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 61 | |
| 62 | // Define the interval in number of cache hits between two statistics dump |
| 63 | #define DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL 100 |
| 64 | |
| 65 | namespace android { |
| 66 | |
| 67 | /** |
| 68 | * TextLayoutCacheKey is the Cache key |
| 69 | */ |
| 70 | class TextLayoutCacheKey { |
| 71 | public: |
Fabrice Di Meglio | 48796a8 | 2011-04-05 15:22:41 -0700 | [diff] [blame] | 72 | TextLayoutCacheKey(); |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 73 | |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 74 | TextLayoutCacheKey(const SkPaint* paint, const UChar* text, size_t start, size_t count, |
| 75 | size_t contextCount, int dirFlags); |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 76 | |
Fabrice Di Meglio | e74fef3 | 2011-09-18 14:30:21 -0700 | [diff] [blame] | 77 | TextLayoutCacheKey(const TextLayoutCacheKey& other); |
| 78 | |
Fabrice Di Meglio | 48796a8 | 2011-04-05 15:22:41 -0700 | [diff] [blame] | 79 | /** |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 80 | * Get the size of the Cache key. |
| 81 | */ |
Jeff Brown | 06daa7b | 2011-11-11 15:14:56 -0800 | [diff] [blame] | 82 | size_t getSize() const; |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 83 | |
Fabrice Di Meglio | 717060b | 2011-09-27 15:53:42 -0700 | [diff] [blame] | 84 | static int compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs); |
| 85 | |
Raph Levien | 832815c | 2012-10-02 10:30:41 -0700 | [diff] [blame] | 86 | inline const UChar* getText() const { return textCopy.string(); } |
| 87 | |
Raph Levien | d98efca | 2012-10-25 23:17:33 -0700 | [diff] [blame^] | 88 | bool operator==(const TextLayoutCacheKey& other) const { |
| 89 | return compare(*this, other) == 0; |
| 90 | } |
| 91 | |
| 92 | bool operator!=(const TextLayoutCacheKey& other) const { |
| 93 | return compare(*this, other) != 0; |
| 94 | } |
| 95 | |
| 96 | hash_t hash() const; |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 97 | private: |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 98 | String16 textCopy; |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 99 | size_t start; |
Fabrice Di Meglio | 9c418db | 2011-09-18 12:54:38 -0700 | [diff] [blame] | 100 | size_t count; |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 101 | size_t contextCount; |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 102 | int dirFlags; |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 103 | SkTypeface* typeface; |
Fabrice Di Meglio | aabe537 | 2011-03-30 16:06:02 -0700 | [diff] [blame] | 104 | SkScalar textSize; |
| 105 | SkScalar textSkewX; |
| 106 | SkScalar textScaleX; |
| 107 | uint32_t flags; |
| 108 | SkPaint::Hinting hinting; |
Billy Hewlett | ac1cbaf | 2012-07-18 09:51:45 -0700 | [diff] [blame] | 109 | SkPaint::FontVariant variant; |
| 110 | SkLanguage language; |
Fabrice Di Meglio | e74fef3 | 2011-09-18 14:30:21 -0700 | [diff] [blame] | 111 | |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 112 | }; // TextLayoutCacheKey |
| 113 | |
Fabrice Di Meglio | 717060b | 2011-09-27 15:53:42 -0700 | [diff] [blame] | 114 | inline int strictly_order_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) { |
| 115 | return TextLayoutCacheKey::compare(lhs, rhs) < 0; |
| 116 | } |
| 117 | |
| 118 | inline int compare_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) { |
| 119 | return TextLayoutCacheKey::compare(lhs, rhs); |
| 120 | } |
| 121 | |
Raph Levien | d98efca | 2012-10-25 23:17:33 -0700 | [diff] [blame^] | 122 | inline hash_t hash_type(const TextLayoutCacheKey& key) { |
| 123 | return key.hash(); |
| 124 | } |
| 125 | |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 126 | /* |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 127 | * TextLayoutValue is the Cache value |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 128 | */ |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 129 | class TextLayoutValue : public RefBase { |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 130 | public: |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 131 | TextLayoutValue(size_t contextCount); |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 132 | |
Fabrice Di Meglio | 48796a8 | 2011-04-05 15:22:41 -0700 | [diff] [blame] | 133 | void setElapsedTime(uint32_t time); |
| 134 | uint32_t getElapsedTime(); |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 135 | |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 136 | inline const jfloat* getAdvances() const { return mAdvances.array(); } |
| 137 | inline size_t getAdvancesCount() const { return mAdvances.size(); } |
| 138 | inline jfloat getTotalAdvance() const { return mTotalAdvance; } |
| 139 | inline const jchar* getGlyphs() const { return mGlyphs.array(); } |
| 140 | inline size_t getGlyphsCount() const { return mGlyphs.size(); } |
Raph Levien | 2301d32 | 2012-07-17 16:39:49 -0700 | [diff] [blame] | 141 | inline const jfloat* getPos() const { return mPos.array(); } |
| 142 | inline size_t getPosCount() const { return mPos.size(); } |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 143 | |
| 144 | /** |
Fabrice Di Meglio | 4dd99e5 | 2011-09-19 10:47:10 -0700 | [diff] [blame] | 145 | * Advances vector |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 146 | */ |
Fabrice Di Meglio | 4dd99e5 | 2011-09-19 10:47:10 -0700 | [diff] [blame] | 147 | Vector<jfloat> mAdvances; |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 148 | |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 149 | /** |
| 150 | * Total number of advances |
| 151 | */ |
| 152 | jfloat mTotalAdvance; |
| 153 | |
| 154 | /** |
Fabrice Di Meglio | 4dd99e5 | 2011-09-19 10:47:10 -0700 | [diff] [blame] | 155 | * Glyphs vector |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 156 | */ |
Fabrice Di Meglio | 4dd99e5 | 2011-09-19 10:47:10 -0700 | [diff] [blame] | 157 | Vector<jchar> mGlyphs; |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
Raph Levien | 2301d32 | 2012-07-17 16:39:49 -0700 | [diff] [blame] | 160 | * Pos vector (2 * i is x pos, 2 * i + 1 is y pos, same as drawPosText) |
| 161 | */ |
| 162 | Vector<jfloat> mPos; |
| 163 | |
| 164 | /** |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 165 | * Get the size of the Cache entry |
| 166 | */ |
| 167 | size_t getSize() const; |
| 168 | |
| 169 | private: |
| 170 | /** |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 171 | * Time for computing the values (in milliseconds) |
| 172 | */ |
| 173 | uint32_t mElapsedTime; |
Fabrice Di Meglio | 9f82b58 | 2011-03-08 12:02:59 -0800 | [diff] [blame] | 174 | |
Fabrice Di Meglio | 48796a8 | 2011-04-05 15:22:41 -0700 | [diff] [blame] | 175 | }; // TextLayoutCacheValue |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 176 | |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 177 | /** |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 178 | * The TextLayoutShaper is responsible for shaping (with the Harfbuzz library) |
Fabrice Di Meglio | fcf2be1 | 2011-04-05 17:02:36 -0700 | [diff] [blame] | 179 | */ |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 180 | class TextLayoutShaper { |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 181 | public: |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 182 | TextLayoutShaper(); |
| 183 | virtual ~TextLayoutShaper(); |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 184 | |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 185 | void computeValues(TextLayoutValue* value, const SkPaint* paint, const UChar* chars, |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 186 | size_t start, size_t count, size_t contextCount, int dirFlags); |
| 187 | |
Fabrice Di Meglio | 15cc68c | 2012-05-15 14:47:03 -0700 | [diff] [blame] | 188 | void purgeCaches(); |
| 189 | |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 190 | private: |
| 191 | /** |
| 192 | * Harfbuzz shaper item |
| 193 | */ |
| 194 | HB_ShaperItem mShaperItem; |
| 195 | |
| 196 | /** |
| 197 | * Harfbuzz font |
| 198 | */ |
| 199 | HB_FontRec mFontRec; |
| 200 | |
| 201 | /** |
| 202 | * Skia Paint used for shaping |
| 203 | */ |
| 204 | SkPaint mShapingPaint; |
| 205 | |
| 206 | /** |
Billy Hewlett | d6deccb | 2012-06-22 10:30:55 -0700 | [diff] [blame] | 207 | * Skia default typeface to be returned if we cannot resolve script |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 208 | */ |
| 209 | SkTypeface* mDefaultTypeface; |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 210 | |
Fabrice Di Meglio | 902a5b3 | 2011-12-08 18:59:14 -0800 | [diff] [blame] | 211 | /** |
| 212 | * Cache of Harfbuzz faces |
| 213 | */ |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 214 | KeyedVector<SkFontID, HB_Face> mCachedHBFaces; |
| 215 | |
Fabrice Di Meglio | 902a5b3 | 2011-12-08 18:59:14 -0800 | [diff] [blame] | 216 | /** |
| 217 | * Cache of glyph array size |
| 218 | */ |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 219 | size_t mShaperItemGlyphArraySize; |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 220 | |
Fabrice Di Meglio | 902a5b3 | 2011-12-08 18:59:14 -0800 | [diff] [blame] | 221 | /** |
| 222 | * Buffer for containing the ICU normalized form of a run |
| 223 | */ |
| 224 | UnicodeString mNormalizedString; |
| 225 | |
| 226 | /** |
| 227 | * Buffer for normalizing a piece of a run with ICU |
| 228 | */ |
| 229 | UnicodeString mBuffer; |
| 230 | |
Fabrice Di Meglio | 15cc68c | 2012-05-15 14:47:03 -0700 | [diff] [blame] | 231 | void init(); |
| 232 | void unrefTypefaces(); |
| 233 | |
Billy Hewlett | d6deccb | 2012-06-22 10:30:55 -0700 | [diff] [blame] | 234 | SkTypeface* typefaceForScript(const SkPaint* paint, SkTypeface* typeface, |
| 235 | HB_Script script); |
Raph Levien | 1637dcd | 2012-05-02 10:41:14 -0700 | [diff] [blame] | 236 | |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 237 | size_t shapeFontRun(const SkPaint* paint, bool isRTL); |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 238 | |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 239 | void computeValues(const SkPaint* paint, const UChar* chars, |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 240 | size_t start, size_t count, size_t contextCount, int dirFlags, |
| 241 | Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance, |
Raph Levien | 2301d32 | 2012-07-17 16:39:49 -0700 | [diff] [blame] | 242 | Vector<jchar>* const outGlyphs, Vector<jfloat>* const outPos); |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 243 | |
Fabrice Di Meglio | bd901de | 2012-01-20 17:41:55 -0800 | [diff] [blame] | 244 | void computeRunValues(const SkPaint* paint, const UChar* chars, |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 245 | size_t count, bool isRTL, |
| 246 | Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance, |
Raph Levien | 2301d32 | 2012-07-17 16:39:49 -0700 | [diff] [blame] | 247 | Vector<jchar>* const outGlyphs, Vector<jfloat>* const outPos); |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 248 | |
Billy Hewlett | 9605118 | 2012-06-21 09:58:42 -0700 | [diff] [blame] | 249 | SkTypeface* getCachedTypeface(SkTypeface** typeface, HB_Script script, SkTypeface::Style style); |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 250 | HB_Face getCachedHBFace(SkTypeface* typeface); |
| 251 | |
Raph Levien | f62034d | 2012-06-25 16:05:57 -0700 | [diff] [blame] | 252 | bool doShaping(size_t size); |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 253 | void createShaperItemGlyphArrays(size_t size); |
| 254 | void deleteShaperItemGlyphArrays(); |
Billy Hewlett | d6deccb | 2012-06-22 10:30:55 -0700 | [diff] [blame] | 255 | bool isComplexScript(HB_Script script); |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 256 | |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 257 | }; // TextLayoutShaper |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 258 | |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 259 | /** |
| 260 | * Cache of text layout information. |
| 261 | */ |
| 262 | class TextLayoutCache : private OnEntryRemoved<TextLayoutCacheKey, sp<TextLayoutValue> > |
| 263 | { |
| 264 | public: |
| 265 | TextLayoutCache(TextLayoutShaper* shaper); |
| 266 | |
| 267 | ~TextLayoutCache(); |
| 268 | |
| 269 | bool isInitialized() { |
| 270 | return mInitialized; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Used as a callback when an entry is removed from the cache |
| 275 | * Do not invoke directly |
| 276 | */ |
| 277 | void operator()(TextLayoutCacheKey& text, sp<TextLayoutValue>& desc); |
| 278 | |
| 279 | sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start, |
| 280 | jint count, jint contextCount, jint dirFlags); |
| 281 | |
| 282 | /** |
| 283 | * Clear the cache |
| 284 | */ |
Raph Levien | 13ba4e4 | 2012-09-12 15:15:51 -0700 | [diff] [blame] | 285 | void purgeCaches(); |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 286 | |
| 287 | private: |
| 288 | TextLayoutShaper* mShaper; |
| 289 | Mutex mLock; |
| 290 | bool mInitialized; |
| 291 | |
Raph Levien | d98efca | 2012-10-25 23:17:33 -0700 | [diff] [blame^] | 292 | LruCache<TextLayoutCacheKey, sp<TextLayoutValue> > mCache; |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 293 | |
| 294 | uint32_t mSize; |
| 295 | uint32_t mMaxSize; |
| 296 | |
| 297 | uint32_t mCacheHitCount; |
| 298 | uint64_t mNanosecondsSaved; |
| 299 | |
| 300 | uint64_t mCacheStartTime; |
| 301 | |
| 302 | RtlDebugLevel mDebugLevel; |
| 303 | bool mDebugEnabled; |
| 304 | |
| 305 | /* |
| 306 | * Class initialization |
| 307 | */ |
| 308 | void init(); |
| 309 | |
| 310 | /** |
| 311 | * Dump Cache statistics |
| 312 | */ |
| 313 | void dumpCacheStats(); |
| 314 | |
| 315 | }; // TextLayoutCache |
| 316 | |
| 317 | /** |
| 318 | * The TextLayoutEngine is reponsible for computing TextLayoutValues |
| 319 | */ |
| 320 | class TextLayoutEngine : public Singleton<TextLayoutEngine> { |
| 321 | public: |
| 322 | TextLayoutEngine(); |
| 323 | virtual ~TextLayoutEngine(); |
| 324 | |
Raph Levien | 832815c | 2012-10-02 10:30:41 -0700 | [diff] [blame] | 325 | /** |
| 326 | * Note: this method currently does a defensive copy of the text argument, in case |
| 327 | * there is concurrent mutation of it. The contract may change, and may in the |
| 328 | * future require the caller to guarantee that the contents will not change during |
| 329 | * the call. Be careful of this when doing optimization. |
| 330 | **/ |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 331 | sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start, |
| 332 | jint count, jint contextCount, jint dirFlags); |
Fabrice Di Meglio | 30ca5cd | 2012-05-07 17:45:44 -0700 | [diff] [blame] | 333 | |
| 334 | void purgeCaches(); |
| 335 | |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 336 | private: |
| 337 | TextLayoutCache* mTextLayoutCache; |
| 338 | TextLayoutShaper* mShaper; |
| 339 | }; // TextLayoutEngine |
Fabrice Di Meglio | 0af10b5 | 2011-11-18 17:36:41 -0800 | [diff] [blame] | 340 | |
Fabrice Di Meglio | d313c66 | 2011-02-24 19:56:18 -0800 | [diff] [blame] | 341 | } // namespace android |
| 342 | #endif /* ANDROID_TEXT_LAYOUT_CACHE_H */ |
| 343 | |