TextLayoutCache.h revision 30ca5cd11a23f06f2f8eeaa587685450826f800f
1d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio/* 2d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * Copyright (C) 2011 The Android Open Source Project 3d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * 4d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * Licensed under the Apache License, Version 2.0 (the "License"); 5d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * you may not use this file except in compliance with the License. 6d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * You may obtain a copy of the License at 7d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * 8d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * http://www.apache.org/licenses/LICENSE-2.0 9d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * 10d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * Unless required by applicable law or agreed to in writing, software 11d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * distributed under the License is distributed on an "AS IS" BASIS, 12d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * See the License for the specific language governing permissions and 14d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * limitations under the License. 15d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio */ 16d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 17d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#ifndef ANDROID_TEXT_LAYOUT_CACHE_H 18d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define ANDROID_TEXT_LAYOUT_CACHE_H 19d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 20d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#include "RtlProperties.h" 21d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 22eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <stddef.h> 23d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#include <utils/threads.h> 24d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#include <utils/String16.h> 25eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <utils/GenerationCache.h> 260af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio#include <utils/KeyedVector.h> 27eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <utils/Compare.h> 28fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio#include <utils/RefBase.h> 29163268b3a8d4dd7e650e6c540f832bf60f6bf4c9Fabrice Di Meglio#include <utils/Singleton.h> 30d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 31eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <SkPaint.h> 32eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <SkTemplates.h> 33eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <SkUtils.h> 34eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <SkAutoKern.h> 35d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 36eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <unicode/ubidi.h> 37eee49c699c035ffba188417489f40d34f587d65cFabrice Di Meglio#include <unicode/ushape.h> 38902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio#include <unicode/unistr.h> 39902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio 409f82b580d744ce4baf057b061994394dcf239eedFabrice Di Meglio#include "HarfbuzzSkia.h" 419f82b580d744ce4baf057b061994394dcf239eedFabrice Di Meglio#include "harfbuzz-shaper.h" 42d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 43d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#include <android_runtime/AndroidRuntime.h> 44d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 45d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define UNICODE_NOT_A_CHAR 0xffff 46d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define UNICODE_ZWSP 0x200b 47d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define UNICODE_FIRST_LOW_SURROGATE 0xdc00 48d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define UNICODE_FIRST_HIGH_SURROGATE 0xd800 49d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define UNICODE_FIRST_PRIVATE_USE 0xe000 50d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define UNICODE_FIRST_RTL_CHAR 0x0590 51d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 52d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio// Temporary buffer size 53d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define CHAR_BUFFER_SIZE 80 54d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 55d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio// Converts a number of mega-bytes into bytes 56d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define MB(s) s * 1024 * 1024 57d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 58d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio// Define the default cache size in Mb 59010d5c4e5ba7a229f621f08f5d1c5cbff7643402Fabrice Di Meglio#define DEFAULT_TEXT_LAYOUT_CACHE_SIZE_IN_MB 0.250f 60d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 61d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio// Define the interval in number of cache hits between two statistics dump 62d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#define DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL 100 63d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 64d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglionamespace android { 65d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 66d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio/** 67d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * TextLayoutCacheKey is the Cache key 68d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio */ 69d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglioclass TextLayoutCacheKey { 70d313c665e618af3194f504064bcd284fe5368682Fabrice Di Megliopublic: 7148796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio TextLayoutCacheKey(); 72d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 735c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio TextLayoutCacheKey(const SkPaint* paint, const UChar* text, size_t start, size_t count, 745c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio size_t contextCount, int dirFlags); 75d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 76e74fef3b55dc1b5daf40b3a6aea857582071560fFabrice Di Meglio TextLayoutCacheKey(const TextLayoutCacheKey& other); 77e74fef3b55dc1b5daf40b3a6aea857582071560fFabrice Di Meglio 7848796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio /** 7948796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio * We need to copy the text when we insert the key into the cache itself. 8048796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio * We don't need to copy the text when we are only comparing keys. 8148796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio */ 8248796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio void internalTextCopy(); 83d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 84d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio /** 85d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio * Get the size of the Cache key. 86d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio */ 8706daa7b6b2186cf1e83e14d2adbb0d2050b79c39Jeff Brown size_t getSize() const; 88d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 89717060b076350ea811153290281075396a554fedFabrice Di Meglio static int compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs); 90717060b076350ea811153290281075396a554fedFabrice Di Meglio 91d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglioprivate: 92e74fef3b55dc1b5daf40b3a6aea857582071560fFabrice Di Meglio const UChar* text; // if text is NULL, use textCopy 93d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio String16 textCopy; 945c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio size_t start; 959c418dbc56efd334c68872d281f75138e16eae46Fabrice Di Meglio size_t count; 965c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio size_t contextCount; 97d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio int dirFlags; 98d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio SkTypeface* typeface; 99aabe537f1ed3b64f755af9fc62022d6074eec169Fabrice Di Meglio SkScalar textSize; 100aabe537f1ed3b64f755af9fc62022d6074eec169Fabrice Di Meglio SkScalar textSkewX; 101aabe537f1ed3b64f755af9fc62022d6074eec169Fabrice Di Meglio SkScalar textScaleX; 102aabe537f1ed3b64f755af9fc62022d6074eec169Fabrice Di Meglio uint32_t flags; 103aabe537f1ed3b64f755af9fc62022d6074eec169Fabrice Di Meglio SkPaint::Hinting hinting; 104e74fef3b55dc1b5daf40b3a6aea857582071560fFabrice Di Meglio 105717060b076350ea811153290281075396a554fedFabrice Di Meglio inline const UChar* getText() const { return text ? text : textCopy.string(); } 106717060b076350ea811153290281075396a554fedFabrice Di Meglio 107d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio}; // TextLayoutCacheKey 108d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 109717060b076350ea811153290281075396a554fedFabrice Di Meglioinline int strictly_order_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) { 110717060b076350ea811153290281075396a554fedFabrice Di Meglio return TextLayoutCacheKey::compare(lhs, rhs) < 0; 111717060b076350ea811153290281075396a554fedFabrice Di Meglio} 112717060b076350ea811153290281075396a554fedFabrice Di Meglio 113717060b076350ea811153290281075396a554fedFabrice Di Meglioinline int compare_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) { 114717060b076350ea811153290281075396a554fedFabrice Di Meglio return TextLayoutCacheKey::compare(lhs, rhs); 115717060b076350ea811153290281075396a554fedFabrice Di Meglio} 116717060b076350ea811153290281075396a554fedFabrice Di Meglio 117d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio/* 118a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * TextLayoutValue is the Cache value 119d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio */ 120a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglioclass TextLayoutValue : public RefBase { 121d313c665e618af3194f504064bcd284fe5368682Fabrice Di Megliopublic: 122a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio TextLayoutValue(size_t contextCount); 123d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 12448796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio void setElapsedTime(uint32_t time); 12548796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio uint32_t getElapsedTime(); 126d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 1275c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio inline const jfloat* getAdvances() const { return mAdvances.array(); } 1285c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio inline size_t getAdvancesCount() const { return mAdvances.size(); } 1295c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio inline jfloat getTotalAdvance() const { return mTotalAdvance; } 1305c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio inline const jchar* getGlyphs() const { return mGlyphs.array(); } 1315c863f741e8e484bb39decd516c9fa4c6322e671Fabrice Di Meglio inline size_t getGlyphsCount() const { return mGlyphs.size(); } 132d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 133d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio /** 1344dd99e5912c73d5a9db165cefd4852b51ea438e8Fabrice Di Meglio * Advances vector 135fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio */ 1364dd99e5912c73d5a9db165cefd4852b51ea438e8Fabrice Di Meglio Vector<jfloat> mAdvances; 137d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 138fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio /** 139fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio * Total number of advances 140fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio */ 141fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio jfloat mTotalAdvance; 142fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio 143fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio /** 1444dd99e5912c73d5a9db165cefd4852b51ea438e8Fabrice Di Meglio * Glyphs vector 145fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio */ 1464dd99e5912c73d5a9db165cefd4852b51ea438e8Fabrice Di Meglio Vector<jchar> mGlyphs; 147fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio 148fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio /** 1490af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio * Get the size of the Cache entry 1500af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio */ 1510af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio size_t getSize() const; 1520af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 1530af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglioprivate: 1540af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio /** 155fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio * Time for computing the values (in milliseconds) 156fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio */ 157fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio uint32_t mElapsedTime; 1589f82b580d744ce4baf057b061994394dcf239eedFabrice Di Meglio 15948796a81be31e42ee267347156c94445cb9fb67aFabrice Di Meglio}; // TextLayoutCacheValue 160d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 161fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio/** 162a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * The TextLayoutShaper is responsible for shaping (with the Harfbuzz library) 163fcf2be1846935e7983ea2fe87fdd4d7af27764b6Fabrice Di Meglio */ 164a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglioclass TextLayoutShaper { 165d313c665e618af3194f504064bcd284fe5368682Fabrice Di Megliopublic: 166a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio TextLayoutShaper(); 167a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio virtual ~TextLayoutShaper(); 168d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 169a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio void computeValues(TextLayoutValue* value, const SkPaint* paint, const UChar* chars, 1700af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio size_t start, size_t count, size_t contextCount, int dirFlags); 1710af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 1720af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglioprivate: 1730af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio /** 1740af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio * Harfbuzz shaper item 1750af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio */ 1760af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio HB_ShaperItem mShaperItem; 1770af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 1780af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio /** 1790af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio * Harfbuzz font 1800af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio */ 1810af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio HB_FontRec mFontRec; 1820af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 1830af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio /** 1840af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio * Skia Paint used for shaping 1850af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio */ 1860af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio SkPaint mShapingPaint; 1870af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 1880af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio /** 1890af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio * Skia typefaces cached for shaping 1900af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio */ 1910af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio SkTypeface* mDefaultTypeface; 1920af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio SkTypeface* mArabicTypeface; 1930af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio SkTypeface* mHebrewRegularTypeface; 1940af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio SkTypeface* mHebrewBoldTypeface; 19565194adc9a5174fc88fb579472799e8b4771796bFabrice Di Meglio SkTypeface* mBengaliTypeface; 196a4d077006306b49d85e7609e8f5a061e345f6f6dFabrice Di Meglio SkTypeface* mThaiTypeface; 197ff40ab7a418dd06cfe4758ceda17a775f2d4c776Fabrice Di Meglio SkTypeface* mDevanagariTypeface; 198ff40ab7a418dd06cfe4758ceda17a775f2d4c776Fabrice Di Meglio SkTypeface* mTamilTypeface; 1990af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 200902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio /** 201902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio * Cache of Harfbuzz faces 202902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio */ 2030af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio KeyedVector<SkFontID, HB_Face> mCachedHBFaces; 2040af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 205902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio /** 206902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio * Cache of glyph array size 207902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio */ 2080af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio size_t mShaperItemGlyphArraySize; 2090af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 210902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio /** 211902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio * Buffer for containing the ICU normalized form of a run 212902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio */ 213902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio UnicodeString mNormalizedString; 214902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio 215902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio /** 216902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio * Buffer for normalizing a piece of a run with ICU 217902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio */ 218902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio UnicodeString mBuffer; 219902a5b31c50022a1b7707be4d333e4ce6ec4a8faFabrice Di Meglio 2201637dcd16cd314574a58602337a2c7222130b1b9Raph Levien SkTypeface* typefaceForUnichar(const SkPaint* paint, SkTypeface* typeface, 2211637dcd16cd314574a58602337a2c7222130b1b9Raph Levien SkUnichar unichar, HB_Script script); 2221637dcd16cd314574a58602337a2c7222130b1b9Raph Levien 223bd901dee317d10c6a921922c3d7d788b90306c82Fabrice Di Meglio size_t shapeFontRun(const SkPaint* paint, bool isRTL); 2240af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 225bd901dee317d10c6a921922c3d7d788b90306c82Fabrice Di Meglio void computeValues(const SkPaint* paint, const UChar* chars, 2260af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio size_t start, size_t count, size_t contextCount, int dirFlags, 2270af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance, 2280af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio Vector<jchar>* const outGlyphs); 2290af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 230bd901dee317d10c6a921922c3d7d788b90306c82Fabrice Di Meglio void computeRunValues(const SkPaint* paint, const UChar* chars, 2310af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio size_t count, bool isRTL, 2320af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance, 2330af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio Vector<jchar>* const outGlyphs); 2340af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 2350af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio SkTypeface* getCachedTypeface(SkTypeface** typeface, const char path[]); 2360af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio HB_Face getCachedHBFace(SkTypeface* typeface); 2370af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 2380af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio void ensureShaperItemGlyphArrays(size_t size); 2390af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio void createShaperItemGlyphArrays(size_t size); 2400af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio void deleteShaperItemGlyphArrays(); 2410af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 242a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio}; // TextLayoutShaper 2430af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 244a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio/** 245a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * Cache of text layout information. 246a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio */ 247a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglioclass TextLayoutCache : private OnEntryRemoved<TextLayoutCacheKey, sp<TextLayoutValue> > 248a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio{ 249a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Megliopublic: 250a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio TextLayoutCache(TextLayoutShaper* shaper); 251a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 252a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio ~TextLayoutCache(); 253a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 254a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio bool isInitialized() { 255a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio return mInitialized; 256a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio } 257a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 258a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio /** 259a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * Used as a callback when an entry is removed from the cache 260a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * Do not invoke directly 261a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio */ 262a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio void operator()(TextLayoutCacheKey& text, sp<TextLayoutValue>& desc); 263a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 264a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start, 265a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio jint count, jint contextCount, jint dirFlags); 266a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 267a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio /** 268a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * Clear the cache 269a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio */ 270a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio void clear(); 271a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 272a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglioprivate: 273a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio TextLayoutShaper* mShaper; 274a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio Mutex mLock; 275a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio bool mInitialized; 276a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 277a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio GenerationCache<TextLayoutCacheKey, sp<TextLayoutValue> > mCache; 278a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 279a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio uint32_t mSize; 280a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio uint32_t mMaxSize; 281a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 282a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio uint32_t mCacheHitCount; 283a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio uint64_t mNanosecondsSaved; 284a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 285a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio uint64_t mCacheStartTime; 286a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 287a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio RtlDebugLevel mDebugLevel; 288a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio bool mDebugEnabled; 289a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 290a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio /* 291a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * Class initialization 292a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio */ 293a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio void init(); 294a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 295a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio /** 296a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * Dump Cache statistics 297a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio */ 298a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio void dumpCacheStats(); 299a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 300a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio}; // TextLayoutCache 301a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 302a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio/** 303a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio * The TextLayoutEngine is reponsible for computing TextLayoutValues 304a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio */ 305a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglioclass TextLayoutEngine : public Singleton<TextLayoutEngine> { 306a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Megliopublic: 307a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio TextLayoutEngine(); 308a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio virtual ~TextLayoutEngine(); 309a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio 310a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start, 311a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio jint count, jint contextCount, jint dirFlags); 31230ca5cd11a23f06f2f8eeaa587685450826f800fFabrice Di Meglio 31330ca5cd11a23f06f2f8eeaa587685450826f800fFabrice Di Meglio void purgeCaches(); 31430ca5cd11a23f06f2f8eeaa587685450826f800fFabrice Di Meglio 315a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglioprivate: 316a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio TextLayoutCache* mTextLayoutCache; 317a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio TextLayoutShaper* mShaper; 318a731b082b2c43204e6e9f927ab82fb732934a83bFabrice Di Meglio}; // TextLayoutEngine 3190af10b54bf110653b74cb92793484b412a90b657Fabrice Di Meglio 320d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio} // namespace android 321d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio#endif /* ANDROID_TEXT_LAYOUT_CACHE_H */ 322d313c665e618af3194f504064bcd284fe5368682Fabrice Di Meglio 323