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