Skip to content

Commit 651e466

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug #5332081 TextLayoutCache needs to be able to have more cache hits"
2 parents 83a559e + 79df532 commit 651e466

File tree

7 files changed

+186
-150
lines changed

7 files changed

+186
-150
lines changed

core/jni/android/graphics/Canvas.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -758,21 +758,7 @@ class SkCanvasGlue {
758758
jfloat x, jfloat y, int flags, SkPaint* paint) {
759759

760760
jint count = end - start;
761-
sp<TextLayoutCacheValue> value;
762-
#if USE_TEXT_LAYOUT_CACHE
763-
value = TextLayoutCache::getInstance().getValue(paint, textArray, start, count,
764-
end, flags);
765-
if (value == NULL) {
766-
LOGE("Cannot get TextLayoutCache value");
767-
return ;
768-
}
769-
#else
770-
value = new TextLayoutCacheValue();
771-
value->computeValues(paint, textArray, start, count, end, flags);
772-
#endif
773-
774-
doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(),
775-
x, y, flags, paint);
761+
drawTextWithGlyphs(canvas, textArray + start, 0, count, count, x, y, flags, paint);
776762
}
777763

778764
static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray,
@@ -781,19 +767,20 @@ class SkCanvasGlue {
781767

782768
sp<TextLayoutCacheValue> value;
783769
#if USE_TEXT_LAYOUT_CACHE
784-
value = TextLayoutCache::getInstance().getValue(paint, textArray, start, count,
785-
contextCount, flags);
770+
value = TextLayoutCache::getInstance().getValue(paint, textArray, contextCount, flags);
786771
if (value == NULL) {
787772
LOGE("Cannot get TextLayoutCache value");
788773
return ;
789774
}
790775
#else
791776
value = new TextLayoutCacheValue();
792-
value->computeValues(paint, textArray, start, count, contextCount, flags);
777+
value->computeValues(paint, textArray, contextCount, flags);
793778
#endif
794-
795-
doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(),
796-
x, y, flags, paint);
779+
size_t startIndex = 0;
780+
size_t glyphsCount = 0;
781+
value->getGlyphsIndexAndCount(start, count, &startIndex, &glyphsCount);
782+
const jchar* glyphs = value->getGlyphs(startIndex, glyphsCount);
783+
doDrawGlyphs(canvas, glyphs, 0, glyphsCount, x, y, flags, paint);
797784
}
798785

799786
static void doDrawGlyphs(SkCanvas* canvas, const jchar* glyphArray, int index, int count,

core/jni/android/graphics/Paint.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class SkPaintGlue {
352352
jfloat result = 0;
353353
#if RTL_USE_HARFBUZZ
354354
TextLayout::getTextRunAdvances(paint, textArray, index, count, textLength,
355-
paint->getFlags(), NULL /* dont need all advances */, result);
355+
paint->getFlags(), NULL /* dont need all advances */, &result);
356356
#else
357357
// we double count, since measureText wants a byteLength
358358
SkScalar width = paint->measureText(textArray + index, count << 1);
@@ -382,7 +382,7 @@ class SkPaintGlue {
382382

383383
#if RTL_USE_HARFBUZZ
384384
TextLayout::getTextRunAdvances(paint, textArray, start, count, textLength,
385-
paint->getFlags(), NULL /* dont need all advances */, width);
385+
paint->getFlags(), NULL /* dont need all advances */, &width);
386386
#else
387387

388388
width = SkScalarToFloat(paint->measureText(textArray + start, count << 1));
@@ -406,7 +406,7 @@ class SkPaintGlue {
406406

407407
#if RTL_USE_HARFBUZZ
408408
TextLayout::getTextRunAdvances(paint, textArray, 0, textLength, textLength,
409-
paint->getFlags(), NULL /* dont need all advances */, width);
409+
paint->getFlags(), NULL /* dont need all advances */, &width);
410410
#else
411411
width = SkScalarToFloat(paint->measureText(textArray, textLength << 1));
412412
#endif
@@ -435,10 +435,8 @@ class SkPaintGlue {
435435
jfloat* widthsArray = autoWidths.ptr();
436436

437437
#if RTL_USE_HARFBUZZ
438-
jfloat totalAdvance;
439-
440438
TextLayout::getTextRunAdvances(paint, text, 0, count, count,
441-
paint->getFlags(), widthsArray, totalAdvance);
439+
paint->getFlags(), widthsArray, NULL /* dont need totalAdvance */);
442440
#else
443441
SkScalar* scalarArray = (SkScalar*)widthsArray;
444442

@@ -533,7 +531,7 @@ class SkPaintGlue {
533531
jfloat totalAdvance = 0;
534532

535533
TextLayout::getTextRunAdvances(paint, text, start, count, contextCount, flags,
536-
advancesArray, totalAdvance);
534+
advancesArray, &totalAdvance);
537535

538536
if (advances != NULL) {
539537
env->SetFloatArrayRegion(advances, advancesIndex, count, advancesArray);
@@ -604,10 +602,9 @@ class SkPaintGlue {
604602
jint count, jint flags, jint offset, jint opt) {
605603
#if RTL_USE_HARFBUZZ
606604
jfloat scalarArray[count];
607-
jfloat totalAdvance = 0;
608605

609606
TextLayout::getTextRunAdvances(paint, text, start, count, count, flags,
610-
scalarArray, totalAdvance);
607+
scalarArray, NULL /* dont need totalAdvance */);
611608
#else
612609
SkScalar scalarArray[count];
613610
jchar buffer[count];

core/jni/android/graphics/TextLayout.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,22 @@ void TextLayout::drawTextRun(SkPaint* paint, const jchar* chars,
253253

254254
void TextLayout::getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start,
255255
jint count, jint contextCount, jint dirFlags,
256-
jfloat* resultAdvances, jfloat& resultTotalAdvance) {
256+
jfloat* resultAdvances, jfloat* resultTotalAdvance) {
257257
sp<TextLayoutCacheValue> value;
258258
#if USE_TEXT_LAYOUT_CACHE
259259
// Return advances from the cache. Compute them if needed
260-
value = TextLayoutCache::getInstance().getValue(
261-
paint, chars, start, count, contextCount, dirFlags);
260+
value = TextLayoutCache::getInstance().getValue(paint, chars, contextCount, dirFlags);
262261
#else
263262
value = new TextLayoutCacheValue();
264-
value->computeValues(paint, chars, start, count, contextCount, dirFlags);
263+
value->computeValues(paint, chars, contextCount, dirFlags);
265264
#endif
266265
if (value != NULL) {
267266
if (resultAdvances != NULL) {
268-
memcpy(resultAdvances, value->getAdvances(), value->getAdvancesCount() * sizeof(jfloat));
267+
value->getAdvances(start, count, resultAdvances);
268+
}
269+
if (resultTotalAdvance) {
270+
*resultTotalAdvance = value->getTotalAdvance(start, count);
269271
}
270-
resultTotalAdvance = value->getTotalAdvance();
271272
}
272273
}
273274

core/jni/android/graphics/TextLayout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TextLayout {
7171

7272
static void getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start,
7373
jint count, jint contextCount, jint dirFlags,
74-
jfloat* resultAdvances, jfloat& resultTotalAdvance);
74+
jfloat* resultAdvances, jfloat* resultTotalAdvance);
7575

7676
static void getTextRunAdvancesICU(SkPaint* paint, const jchar* chars, jint start,
7777
jint count, jint contextCount, jint dirFlags,

0 commit comments

Comments
 (0)