1414 * limitations under the License.
1515 */
1616
17+ #define LOG_TAG " TextLayoutCache"
18+
1719#include " TextLayoutCache.h"
1820#include " TextLayout.h"
1921
@@ -23,20 +25,19 @@ extern "C" {
2325
2426namespace android {
2527
28+ // --------------------------------------------------------------------------------------------------
29+ #if USE_TEXT_LAYOUT_CACHE
30+ ANDROID_SINGLETON_STATIC_INSTANCE (TextLayoutCache);
31+ #endif
32+ // --------------------------------------------------------------------------------------------------
33+
2634TextLayoutCache::TextLayoutCache () :
2735 mCache (GenerationCache<TextLayoutCacheKey, sp<TextLayoutCacheValue> >::kUnlimitedCapacity ),
2836 mSize (0 ), mMaxSize (MB(DEFAULT_TEXT_LAYOUT_CACHE_SIZE_IN_MB)),
2937 mCacheHitCount (0 ), mNanosecondsSaved (0 ) {
3038 init ();
3139}
3240
33- TextLayoutCache::TextLayoutCache (uint32_t max):
34- mCache (GenerationCache<TextLayoutCacheKey, sp<TextLayoutCacheValue> >::kUnlimitedCapacity ),
35- mSize (0 ), mMaxSize (max),
36- mCacheHitCount (0 ), mNanosecondsSaved (0 ) {
37- init ();
38- }
39-
4041TextLayoutCache::~TextLayoutCache () {
4142 mCache .clear ();
4243}
@@ -46,25 +47,21 @@ void TextLayoutCache::init() {
4647
4748 mDebugLevel = readRtlDebugLevel ();
4849 mDebugEnabled = mDebugLevel & kRtlDebugCaches ;
49- LOGD (" Using TextLayoutCache debug level: %d - Debug Enabled: %d" , mDebugLevel , mDebugEnabled );
50+ LOGD (" Using debug level: %d - Debug Enabled: %d" , mDebugLevel , mDebugEnabled );
5051
5152 mCacheStartTime = systemTime (SYSTEM_TIME_MONOTONIC);
52- if (mDebugEnabled ) {
53- LOGD (" TextLayoutCache start time: %lld" , mCacheStartTime );
54- }
55- mInitialized = true ;
5653
5754 if (mDebugEnabled ) {
55+ LOGD (" Start time: %lld" , mCacheStartTime );
5856#if RTL_USE_HARFBUZZ
59- LOGD (" TextLayoutCache is using HARFBUZZ" );
57+ LOGD (" Using HARFBUZZ" );
6058#else
61- LOGD (" TextLayoutCache is using ICU" );
59+ LOGD (" Using ICU" );
6260#endif
61+ LOGD (" Initialization is done" );
6362 }
6463
65- if (mDebugEnabled ) {
66- LOGD (" TextLayoutCache initialization is done" );
67- }
64+ mInitialized = true ;
6865}
6966
7067/*
@@ -147,8 +144,7 @@ sp<TextLayoutCacheValue> TextLayoutCache::getValue(SkPaint* paint,
147144 // Cleanup to make some room if needed
148145 if (mSize + size > mMaxSize ) {
149146 if (mDebugEnabled ) {
150- LOGD (" TextLayoutCache: need to clean some entries "
151- " for making some room for a new entry" );
147+ LOGD (" Need to clean some entries for making some room for a new entry" );
152148 }
153149 while (mSize + size > mMaxSize ) {
154150 // This will call the callback
@@ -213,7 +209,7 @@ void TextLayoutCache::dumpCacheStats() {
213209 float remainingPercent = 100 * ((mMaxSize - mSize ) / ((float )mMaxSize ));
214210 float timeRunningInSec = (systemTime (SYSTEM_TIME_MONOTONIC) - mCacheStartTime ) / 1000000000 ;
215211 LOGD (" ------------------------------------------------" );
216- LOGD (" TextLayoutCache stats" );
212+ LOGD (" Cache stats" );
217213 LOGD (" ------------------------------------------------" );
218214 LOGD (" pid : %d" , getpid ());
219215 LOGD (" running : %.0f seconds" , timeRunningInSec);
0 commit comments