Skip to content

Commit 4444573

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix some TextLayoutCache issues"
2 parents a4102b9 + 51f383d commit 4444573

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

core/jni/android/graphics/Paint.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,26 +366,22 @@ class SkPaintGlue {
366366
NPE_CHECK_RETURN_ZERO(env, jpaint);
367367
NPE_CHECK_RETURN_ZERO(env, text);
368368

369+
size_t textLength = env->GetStringLength(text);
369370
int count = end - start;
370-
if ((start | count) < 0) {
371+
if ((start | count) < 0 || (size_t)end > textLength) {
371372
doThrowAIOOBE(env);
372373
return 0;
373374
}
374375
if (count == 0) {
375376
return 0;
376377
}
377-
size_t textLength = env->GetStringLength(text);
378-
if ((size_t)count > textLength) {
379-
doThrowAIOOBE(env);
380-
return 0;
381-
}
382378

383379
const jchar* textArray = env->GetStringChars(text, NULL);
384380
SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint);
385381
jfloat width = 0;
386382

387383
#if RTL_USE_HARFBUZZ
388-
TextLayout::getTextRunAdvances(paint, textArray, start, count, end,
384+
TextLayout::getTextRunAdvances(paint, textArray, start, count, textLength,
389385
paint->getFlags(), NULL /* dont need all advances */, width);
390386
#else
391387

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,20 @@ sp<TextLayoutCacheValue> TextLayoutCache::getValue(SkPaint* paint,
163163
// Update timing information for statistics
164164
value->setElapsedTime(endTime - startTime);
165165

166-
LOGD("CACHE MISS: Added entry for text='%s' with start=%d, count=%d, "
166+
LOGD("CACHE MISS: Added entry with start=%d, count=%d, "
167167
"contextCount=%d, entry size %d bytes, remaining space %d bytes"
168-
" - Compute time in nanos: %d",
169-
String8(text, contextCount).string(), start, count, contextCount,
170-
size, mMaxSize - mSize, value->getElapsedTime());
168+
" - Compute time in nanos: %d - Text='%s' ",
169+
start, count, contextCount, size, mMaxSize - mSize, value->getElapsedTime(),
170+
String8(text, contextCount).string());
171171
}
172172
} else {
173173
if (mDebugEnabled) {
174174
LOGD("CACHE MISS: Calculated but not storing entry because it is too big "
175-
"for text='%s' with start=%d, count=%d, contextCount=%d, "
175+
"with start=%d, count=%d, contextCount=%d, "
176176
"entry size %d bytes, remaining space %d bytes"
177-
" - Compute time in nanos: %lld",
178-
String8(text, contextCount).string(), start, count, contextCount,
179-
size, mMaxSize - mSize, endTime);
177+
" - Compute time in nanos: %lld - Text='%s'",
178+
start, count, contextCount, size, mMaxSize - mSize, endTime,
179+
String8(text, contextCount).string());
180180
}
181181
value.clear();
182182
}
@@ -190,12 +190,12 @@ sp<TextLayoutCacheValue> TextLayoutCache::getValue(SkPaint* paint,
190190
if (value->getElapsedTime() > 0) {
191191
float deltaPercent = 100 * ((value->getElapsedTime() - elapsedTimeThruCacheGet)
192192
/ ((float)value->getElapsedTime()));
193-
LOGD("CACHE HIT #%d for text='%s' with start=%d, count=%d, contextCount=%d "
193+
LOGD("CACHE HIT #%d with start=%d, count=%d, contextCount=%d "
194194
"- Compute time in nanos: %d - "
195-
"Cache get time in nanos: %lld - Gain in percent: %2.2f",
196-
mCacheHitCount, String8(text, contextCount).string(), start, count,
197-
contextCount,
198-
value->getElapsedTime(), elapsedTimeThruCacheGet, deltaPercent);
195+
"Cache get time in nanos: %lld - Gain in percent: %2.2f - Text='%s' ",
196+
mCacheHitCount, start, count, contextCount,
197+
value->getElapsedTime(), elapsedTimeThruCacheGet, deltaPercent,
198+
String8(text, contextCount).string());
199199
}
200200
if (mCacheHitCount % DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL == 0) {
201201
dumpCacheStats();

0 commit comments

Comments
 (0)