summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2012-10-02 13:02:30 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-10-02 13:02:31 -0700
commit217ca3b0d310472e4df1aa4af72769d7c7a5becb (patch)
tree2541b12f7587fe29fc6c3c7b2b5594d610247b0d /core
parentf175525be4107649581259d04711f9ead905d447 (diff)
parent832815cb53e951485ff5a0e6c705446d0bfb5883 (diff)
downloadframeworks_base-217ca3b0d310472e4df1aa4af72769d7c7a5becb.zip
frameworks_base-217ca3b0d310472e4df1aa4af72769d7c7a5becb.tar.gz
frameworks_base-217ca3b0d310472e4df1aa4af72769d7c7a5becb.tar.bz2
Merge "Fix for bug 7234184 F/TextLayoutCache: Failed to put an entry..." into jb-mr1-dev
Diffstat (limited to 'core')
-rw-r--r--core/jni/android/graphics/TextLayoutCache.cpp27
-rw-r--r--core/jni/android/graphics/TextLayoutCache.h17
2 files changed, 16 insertions, 28 deletions
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index ba8cea4..4669c37 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -111,7 +111,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
// Compute advances and store them
mShaper->computeValues(value.get(), paint,
- reinterpret_cast<const UChar*>(text), start, count,
+ reinterpret_cast<const UChar*>(key.getText()), start, count,
size_t(contextCount), int(dirFlags));
if (mDebugEnabled) {
@@ -139,15 +139,12 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
// Update current cache size
mSize += size;
- // Copy the text when we insert the new entry
- key.internalTextCopy();
-
bool putOne = mCache.put(key, value);
LOG_ALWAYS_FATAL_IF(!putOne, "Failed to put an entry into the cache. "
"This indicates that the cache already has an entry with the "
"same key but it should not since we checked earlier!"
" - start = %d, count = %d, contextCount = %d - Text = '%s'",
- start, count, contextCount, String8(text + start, count).string());
+ start, count, contextCount, String8(key.getText() + start, count).string());
if (mDebugEnabled) {
nsecs_t totalTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime;
@@ -158,7 +155,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
value.get(), start, count, contextCount, size, mMaxSize - mSize,
value->getElapsedTime() * 0.000001f,
(totalTime - value->getElapsedTime()) * 0.000001f,
- String8(text + start, count).string());
+ String8(key.getText() + start, count).string());
}
} else {
if (mDebugEnabled) {
@@ -168,7 +165,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
" - Compute time %0.6f ms - Text = '%s'",
start, count, contextCount, size, mMaxSize - mSize,
value->getElapsedTime() * 0.000001f,
- String8(text + start, count).string());
+ String8(key.getText() + start, count).string());
}
}
} else {
@@ -188,7 +185,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
value->getElapsedTime() * 0.000001f,
elapsedTimeThruCacheGet * 0.000001f,
deltaPercent,
- String8(text + start, count).string());
+ String8(key.getText() + start, count).string());
}
if (mCacheHitCount % DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL == 0) {
dumpCacheStats();
@@ -225,15 +222,16 @@ void TextLayoutCache::dumpCacheStats() {
/**
* TextLayoutCacheKey
*/
-TextLayoutCacheKey::TextLayoutCacheKey(): text(NULL), start(0), count(0), contextCount(0),
+TextLayoutCacheKey::TextLayoutCacheKey(): start(0), count(0), contextCount(0),
dirFlags(0), typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(0),
hinting(SkPaint::kNo_Hinting), variant(SkPaint::kDefault_Variant), language() {
}
TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
size_t start, size_t count, size_t contextCount, int dirFlags) :
- text(text), start(start), count(count), contextCount(contextCount),
+ start(start), count(count), contextCount(contextCount),
dirFlags(dirFlags) {
+ textCopy.setTo(text, contextCount);
typeface = paint->getTypeface();
textSize = paint->getTextSize();
textSkewX = paint->getTextSkewX();
@@ -245,7 +243,6 @@ TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
}
TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
- text(NULL),
textCopy(other.textCopy),
start(other.start),
count(other.count),
@@ -259,9 +256,6 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
hinting(other.hinting),
variant(other.variant),
language(other.language) {
- if (other.text) {
- textCopy.setTo(other.text, other.contextCount);
- }
}
int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
@@ -304,11 +298,6 @@ int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutC
return memcmp(lhs.getText(), rhs.getText(), lhs.contextCount * sizeof(UChar));
}
-void TextLayoutCacheKey::internalTextCopy() {
- textCopy.setTo(text, contextCount);
- text = NULL;
-}
-
size_t TextLayoutCacheKey::getSize() const {
return sizeof(TextLayoutCacheKey) + sizeof(UChar) * contextCount;
}
diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h
index 1f4e22c..9994393 100644
--- a/core/jni/android/graphics/TextLayoutCache.h
+++ b/core/jni/android/graphics/TextLayoutCache.h
@@ -77,20 +77,15 @@ public:
TextLayoutCacheKey(const TextLayoutCacheKey& other);
/**
- * We need to copy the text when we insert the key into the cache itself.
- * We don't need to copy the text when we are only comparing keys.
- */
- void internalTextCopy();
-
- /**
* Get the size of the Cache key.
*/
size_t getSize() const;
static int compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs);
+ inline const UChar* getText() const { return textCopy.string(); }
+
private:
- const UChar* text; // if text is NULL, use textCopy
String16 textCopy;
size_t start;
size_t count;
@@ -105,8 +100,6 @@ private:
SkPaint::FontVariant variant;
SkLanguage language;
- inline const UChar* getText() const { return text ? text : textCopy.string(); }
-
}; // TextLayoutCacheKey
inline int strictly_order_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
@@ -316,6 +309,12 @@ public:
TextLayoutEngine();
virtual ~TextLayoutEngine();
+ /**
+ * Note: this method currently does a defensive copy of the text argument, in case
+ * there is concurrent mutation of it. The contract may change, and may in the
+ * future require the caller to guarantee that the contents will not change during
+ * the call. Be careful of this when doing optimization.
+ **/
sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start,
jint count, jint contextCount, jint dirFlags);