Skip to content

Commit 46e327c

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug #5504346 Hung in native_getTextRunAdvances - DO NOT MERGE" into ics-mr0
2 parents 9eb4c89 + 26e9ee2 commit 46e327c

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,10 @@ void TextLayoutCacheValue::computeValuesWithHarfbuzz(SkPaint* paint, const UChar
425425
// Initialize Harfbuzz Shaper
426426
initShaperItem(shaperItem, &font, &fontData, paint, chars, contextCount);
427427

428+
bool useSingleRun = false;
429+
bool isRTL = forceRTL;
428430
if (forceLTR || forceRTL) {
429-
#if DEBUG_GLYPHS
430-
LOGD("computeValuesWithHarfbuzz -- forcing run with LTR=%d RTL=%d",
431-
forceLTR, forceRTL);
432-
#endif
433-
computeRunValuesWithHarfbuzz(shaperItem, paint,
434-
start, count, forceRTL,
435-
outAdvances, outTotalAdvance, outGlyphs);
431+
useSingleRun = true;
436432
} else {
437433
UBiDi* bidi = ubidi_open();
438434
if (bidi) {
@@ -443,43 +439,50 @@ void TextLayoutCacheValue::computeValuesWithHarfbuzz(SkPaint* paint, const UChar
443439
ubidi_setPara(bidi, chars, contextCount, bidiReq, NULL, &status);
444440
if (U_SUCCESS(status)) {
445441
int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; // 0 if ltr, 1 if rtl
446-
size_t rc = ubidi_countRuns(bidi, &status);
442+
ssize_t rc = ubidi_countRuns(bidi, &status);
447443
#if DEBUG_GLYPHS
448444
LOGD("computeValuesWithHarfbuzz -- dirFlags=%d run-count=%d paraDir=%d",
449445
dirFlags, rc, paraDir);
450446
#endif
451-
if (rc == 1 || !U_SUCCESS(status)) {
452-
bool isRTL = (paraDir == 1);
453-
#if DEBUG_GLYPHS
454-
LOGD("computeValuesWithHarfbuzz -- processing SINGLE run "
455-
"-- run-start=%d run-len=%d isRTL=%d", start, count, isRTL);
456-
#endif
457-
computeRunValuesWithHarfbuzz(shaperItem, paint,
458-
start, count, isRTL,
459-
outAdvances, outTotalAdvance, outGlyphs);
447+
if (!U_SUCCESS(status) || rc <= 1) {
448+
LOGW("computeValuesWithHarfbuzz -- need to force to single run");
449+
isRTL = (paraDir == 1);
450+
useSingleRun = true;
460451
} else {
461452
int32_t end = start + count;
462-
for (size_t i = 0; i < rc; ++i) {
463-
int32_t startRun;
464-
int32_t lengthRun;
453+
for (size_t i = 0; i < size_t(rc); ++i) {
454+
int32_t startRun = -1;
455+
int32_t lengthRun = -1;
465456
UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun);
466457

458+
if (startRun == -1 || lengthRun == -1) {
459+
// Something went wrong when getting the visual run, need to clear
460+
// already computed data before doing a single run pass
461+
LOGW("computeValuesWithHarfbuzz -- visual run is not valid");
462+
outGlyphs->clear();
463+
outAdvances->clear();
464+
*outTotalAdvance = 0;
465+
isRTL = (paraDir == 1);
466+
useSingleRun = true;
467+
break;
468+
}
469+
467470
if (startRun >= end) {
468471
continue;
469472
}
470473
int32_t endRun = startRun + lengthRun;
471-
if (endRun <= start) {
474+
if (endRun <= int32_t(start)) {
472475
continue;
473476
}
474-
if (startRun < start) {
475-
startRun = start;
477+
if (startRun < int32_t(start)) {
478+
startRun = int32_t(start);
476479
}
477480
if (endRun > end) {
478481
endRun = end;
479482
}
480483

481484
lengthRun = endRun - startRun;
482-
bool isRTL = (runDir == UBIDI_RTL);
485+
isRTL = (runDir == UBIDI_RTL);
483486
jfloat runTotalAdvance = 0;
484487
#if DEBUG_GLYPHS
485488
LOGD("computeValuesWithHarfbuzz -- run-start=%d run-len=%d isRTL=%d",
@@ -492,19 +495,28 @@ void TextLayoutCacheValue::computeValuesWithHarfbuzz(SkPaint* paint, const UChar
492495
*outTotalAdvance += runTotalAdvance;
493496
}
494497
}
498+
} else {
499+
LOGW("computeValuesWithHarfbuzz -- cannot set Para");
500+
useSingleRun = true;
501+
isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL);
495502
}
496503
ubidi_close(bidi);
497504
} else {
498-
// Cannot run BiDi, just consider one Run
499-
bool isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL);
505+
LOGW("computeValuesWithHarfbuzz -- cannot ubidi_open()");
506+
useSingleRun = true;
507+
isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL);
508+
}
509+
}
510+
511+
// Default single run case
512+
if (useSingleRun){
500513
#if DEBUG_GLYPHS
501-
LOGD("computeValuesWithHarfbuzz -- cannot run BiDi, considering a SINGLE Run "
502-
"-- run-start=%d run-len=%d isRTL=%d", start, count, isRTL);
514+
LOGD("computeValuesWithHarfbuzz -- Using a SINGLE Run "
515+
"-- run-start=%d run-len=%d isRTL=%d", start, count, isRTL);
503516
#endif
504-
computeRunValuesWithHarfbuzz(shaperItem, paint,
505-
start, count, isRTL,
506-
outAdvances, outTotalAdvance, outGlyphs);
507-
}
517+
computeRunValuesWithHarfbuzz(shaperItem, paint,
518+
start, count, isRTL,
519+
outAdvances, outTotalAdvance, outGlyphs);
508520
}
509521

510522
// Cleaning

0 commit comments

Comments
 (0)