From af033caf26ef4eca99c4024e59def7e42c3fa4cd Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Mon, 6 Jun 2011 11:51:46 -0700 Subject: [PATCH] Fix USE_TEXT_LAYOUT_CACHE define - fix compilation issues Change-Id: I3358457d94d2278804e81e4ca96c9633ed76a147 --- core/jni/android/graphics/Canvas.cpp | 26 ++++++++++++++++++------ core/jni/android/graphics/TextLayout.cpp | 20 +++++++++--------- core/jni/android_view_GLES20Canvas.cpp | 18 ++++++++++++---- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp index 4a09232460e0a..942aa8a1d1926 100644 --- a/core/jni/android/graphics/Canvas.cpp +++ b/core/jni/android/graphics/Canvas.cpp @@ -755,32 +755,46 @@ public: jfloat x, jfloat y, int flags, SkPaint* paint) { jint count = end - start; - sp value = gTextLayoutCache.getValue( - paint, textArray, start, count, end, flags); + sp value; +#if USE_TEXT_LAYOUT_CACHE + value = gTextLayoutCache.getValue(paint, textArray, start, count, end, flags); if (value == NULL) { LOGE("Cannot get TextLayoutCache value"); return ; } +#else + value = new TextLayoutCacheValue(); + value->computeValues(paint, textArray, start, count, end, flags); +#endif + #if DEBUG_GLYPHS logGlyphs(value); #endif - doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(), - x, y, flags, paint); + + doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(), + x, y, flags, paint); } static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray, int start, int count, int contextCount, jfloat x, jfloat y, int flags, SkPaint* paint) { - sp value = gTextLayoutCache.getValue( - paint, textArray, start, count, contextCount, flags); + sp value; +#if USE_TEXT_LAYOUT_CACHE + value = gTextLayoutCache.getValue(paint, textArray, start, count, contextCount, flags); if (value == NULL) { LOGE("Cannot get TextLayoutCache value"); return ; } +#else + value = new TextLayoutCacheValue(); + value->computeValues(paint, textArray, start, count, contextCount, flags); +#endif + #if DEBUG_GLYPHS logGlyphs(value); #endif + doDrawGlyphs(canvas, value->getGlyphs(), 0, value->getGlyphsCount(), x, y, flags, paint); } diff --git a/core/jni/android/graphics/TextLayout.cpp b/core/jni/android/graphics/TextLayout.cpp index 46e6c2b3bc616..7e89a37ae8496 100644 --- a/core/jni/android/graphics/TextLayout.cpp +++ b/core/jni/android/graphics/TextLayout.cpp @@ -254,21 +254,21 @@ void TextLayout::drawTextRun(SkPaint* paint, const jchar* chars, void TextLayout::getTextRunAdvances(SkPaint* paint, const jchar* chars, jint start, jint count, jint contextCount, jint dirFlags, jfloat* resultAdvances, jfloat& resultTotalAdvance) { + sp value; #if USE_TEXT_LAYOUT_CACHE // Return advances from the cache. Compute them if needed - sp layout = gTextLayoutCache.getValue( + value = gTextLayoutCache.getValue( paint, chars, start, count, contextCount, dirFlags); - if (layout != NULL) { - if (resultAdvances != NULL) { - memcpy(resultAdvances, layout->getAdvances(), layout->getAdvancesCount() * sizeof(jfloat)); - } - resultTotalAdvance = layout->getTotalAdvance(); - } #else - // Compute advances and return them - TextLayoutCacheValue::computeValuesWithHarfbuzz(paint, chars, start, count, contextCount, - dirFlags, resultAdvances, &resultTotalAdvance, NULL, NULL ); + value = new TextLayoutCacheValue(); + value->computeValues(paint, chars, start, count, contextCount, dirFlags); #endif + if (value != NULL) { + if (resultAdvances != NULL) { + memcpy(resultAdvances, value->getAdvances(), value->getAdvancesCount() * sizeof(jfloat)); + } + resultTotalAdvance = value->getTotalAdvance(); + } } void TextLayout::getTextRunAdvancesHB(SkPaint* paint, const jchar* chars, jint start, diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 31988f710276c..57a97bd895729 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -438,12 +438,17 @@ static void android_view_GLES20Canvas_setupShadow(JNIEnv* env, jobject clazz, static void renderText(OpenGLRenderer* renderer, const jchar* text, int count, jfloat x, jfloat y, int flags, SkPaint* paint) { #if RTL_USE_HARFBUZZ - sp value = gTextLayoutCache.getValue( - paint, text, 0, count, count, flags); + sp value; +#if USE_TEXT_LAYOUT_CACHE + value = gTextLayoutCache.getValue(paint, text, 0, count, count, flags); if (value == NULL) { LOGE("Cannot get TextLayoutCache value"); return ; } +#else + value = new TextLayoutCacheValue(); + value->computeValues(paint, text, 0, count, count, flags); +#endif #if DEBUG_GLYPHS logGlyphs(value); #endif @@ -466,12 +471,17 @@ static void renderTextRun(OpenGLRenderer* renderer, const jchar* text, jint start, jint count, jint contextCount, jfloat x, jfloat y, int flags, SkPaint* paint) { #if RTL_USE_HARFBUZZ - sp value = gTextLayoutCache.getValue( - paint, text, start, count, contextCount, flags); + sp value; +#if USE_TEXT_LAYOUT_CACHE + value = gTextLayoutCache.getValue(paint, text, start, count, contextCount, flags); if (value == NULL) { LOGE("Cannot get TextLayoutCache value"); return ; } +#else + value = new TextLayoutCacheValue(); + value->computeValues(paint, text, start, count, contextCount, flags); +#endif #if DEBUG_GLYPHS logGlyphs(value); #endif