From a4f5aa87c73de7a2581dc4dd72e0f90ccea79a18 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Fri, 18 Nov 2011 14:50:39 -0800 Subject: Fix TextLayoutCache Skia Typeface caching - fix reference passing for globals Change-Id: I806dd4406d455b98c6be733847419b06b6774ccc --- core/jni/android/graphics/TextLayoutCache.cpp | 19 +++++++++++-------- core/jni/android/graphics/TextLayoutCache.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp index e993e2aa195e..5fed2f349f2e 100644 --- a/core/jni/android/graphics/TextLayoutCache.cpp +++ b/core/jni/android/graphics/TextLayoutCache.cpp @@ -416,7 +416,7 @@ unsigned TextLayoutCacheValue::shapeFontRun(HB_ShaperItem& shaperItem, SkPaint* FontData* data = reinterpret_cast(shaperItem.font->userData); switch(shaperItem.item.script) { case HB_Script_Arabic: - data->typeFace = getCachedTypeface(gArabicTypeface, TYPEFACE_ARABIC); + data->typeFace = getCachedTypeface(&gArabicTypeface, TYPEFACE_ARABIC); #if DEBUG_GLYPHS LOGD("Using Arabic Typeface"); #endif @@ -428,21 +428,21 @@ unsigned TextLayoutCacheValue::shapeFontRun(HB_ShaperItem& shaperItem, SkPaint* case SkTypeface::kNormal: case SkTypeface::kItalic: default: - data->typeFace = getCachedTypeface(gHebrewRegularTypeface, TYPE_FACE_HEBREW_REGULAR); + data->typeFace = getCachedTypeface(&gHebrewRegularTypeface, TYPE_FACE_HEBREW_REGULAR); #if DEBUG_GLYPHS LOGD("Using Hebrew Regular/Italic Typeface"); #endif break; case SkTypeface::kBold: case SkTypeface::kBoldItalic: - data->typeFace = getCachedTypeface(gHebrewBoldTypeface, TYPE_FACE_HEBREW_BOLD); + data->typeFace = getCachedTypeface(&gHebrewBoldTypeface, TYPE_FACE_HEBREW_BOLD); #if DEBUG_GLYPHS LOGD("Using Hebrew Bold/BoldItalic Typeface"); #endif break; } } else { - data->typeFace = getCachedTypeface(gHebrewRegularTypeface, TYPE_FACE_HEBREW_REGULAR); + data->typeFace = getCachedTypeface(&gHebrewRegularTypeface, TYPE_FACE_HEBREW_REGULAR); #if DEBUG_GLYPHS LOGD("Using Hebrew Regular Typeface"); #endif @@ -482,11 +482,14 @@ unsigned TextLayoutCacheValue::shapeFontRun(HB_ShaperItem& shaperItem, SkPaint* return result; } -SkTypeface* TextLayoutCacheValue::getCachedTypeface(SkTypeface* typeface, const char path[]) { - if (!typeface) { - typeface = SkTypeface::CreateFromFile(path); +SkTypeface* TextLayoutCacheValue::getCachedTypeface(SkTypeface** typeface, const char path[]) { + if (!*typeface) { + *typeface = SkTypeface::CreateFromFile(path); +#if DEBUG_GLYPHS + LOGD("Created SkTypeface from file: %s", path); +#endif } - return typeface; + return *typeface; } void TextLayoutCacheValue::computeValuesWithHarfbuzz(SkPaint* paint, const UChar* chars, diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h index 06c74fcecefd..5c938f7582a8 100644 --- a/core/jni/android/graphics/TextLayoutCache.h +++ b/core/jni/android/graphics/TextLayoutCache.h @@ -174,7 +174,7 @@ private: static unsigned shapeFontRun(HB_ShaperItem& shaperItem, SkPaint* paint, size_t count, bool isRTL); - static SkTypeface* getCachedTypeface(SkTypeface* typeface, const char path[]); + static SkTypeface* getCachedTypeface(SkTypeface** typeface, const char path[]); static void deleteGlyphArrays(HB_ShaperItem& shaperItem); -- cgit v1.2.3-59-g8ed1b