am 217ca3b0: Merge "Fix for bug 7234184 F/TextLayoutCache: Failed to put an entry..." into jb-mr1-dev
* commit '217ca3b0d310472e4df1aa4af72769d7c7a5becb': Fix for bug 7234184 F/TextLayoutCache: Failed to put an entry...
This commit is contained in:
@@ -111,7 +111,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
|
|||||||
|
|
||||||
// Compute advances and store them
|
// Compute advances and store them
|
||||||
mShaper->computeValues(value.get(), paint,
|
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));
|
size_t(contextCount), int(dirFlags));
|
||||||
|
|
||||||
if (mDebugEnabled) {
|
if (mDebugEnabled) {
|
||||||
@@ -139,15 +139,12 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
|
|||||||
// Update current cache size
|
// Update current cache size
|
||||||
mSize += size;
|
mSize += size;
|
||||||
|
|
||||||
// Copy the text when we insert the new entry
|
|
||||||
key.internalTextCopy();
|
|
||||||
|
|
||||||
bool putOne = mCache.put(key, value);
|
bool putOne = mCache.put(key, value);
|
||||||
LOG_ALWAYS_FATAL_IF(!putOne, "Failed to put an entry into the cache. "
|
LOG_ALWAYS_FATAL_IF(!putOne, "Failed to put an entry into the cache. "
|
||||||
"This indicates that the cache already has an entry with the "
|
"This indicates that the cache already has an entry with the "
|
||||||
"same key but it should not since we checked earlier!"
|
"same key but it should not since we checked earlier!"
|
||||||
" - start = %d, count = %d, contextCount = %d - Text = '%s'",
|
" - 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) {
|
if (mDebugEnabled) {
|
||||||
nsecs_t totalTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime;
|
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.get(), start, count, contextCount, size, mMaxSize - mSize,
|
||||||
value->getElapsedTime() * 0.000001f,
|
value->getElapsedTime() * 0.000001f,
|
||||||
(totalTime - value->getElapsedTime()) * 0.000001f,
|
(totalTime - value->getElapsedTime()) * 0.000001f,
|
||||||
String8(text + start, count).string());
|
String8(key.getText() + start, count).string());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mDebugEnabled) {
|
if (mDebugEnabled) {
|
||||||
@@ -168,7 +165,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
|
|||||||
" - Compute time %0.6f ms - Text = '%s'",
|
" - Compute time %0.6f ms - Text = '%s'",
|
||||||
start, count, contextCount, size, mMaxSize - mSize,
|
start, count, contextCount, size, mMaxSize - mSize,
|
||||||
value->getElapsedTime() * 0.000001f,
|
value->getElapsedTime() * 0.000001f,
|
||||||
String8(text + start, count).string());
|
String8(key.getText() + start, count).string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -188,7 +185,7 @@ sp<TextLayoutValue> TextLayoutCache::getValue(const SkPaint* paint,
|
|||||||
value->getElapsedTime() * 0.000001f,
|
value->getElapsedTime() * 0.000001f,
|
||||||
elapsedTimeThruCacheGet * 0.000001f,
|
elapsedTimeThruCacheGet * 0.000001f,
|
||||||
deltaPercent,
|
deltaPercent,
|
||||||
String8(text + start, count).string());
|
String8(key.getText() + start, count).string());
|
||||||
}
|
}
|
||||||
if (mCacheHitCount % DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL == 0) {
|
if (mCacheHitCount % DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL == 0) {
|
||||||
dumpCacheStats();
|
dumpCacheStats();
|
||||||
@@ -225,15 +222,16 @@ void TextLayoutCache::dumpCacheStats() {
|
|||||||
/**
|
/**
|
||||||
* TextLayoutCacheKey
|
* 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),
|
dirFlags(0), typeface(NULL), textSize(0), textSkewX(0), textScaleX(0), flags(0),
|
||||||
hinting(SkPaint::kNo_Hinting), variant(SkPaint::kDefault_Variant), language() {
|
hinting(SkPaint::kNo_Hinting), variant(SkPaint::kDefault_Variant), language() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
|
TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
|
||||||
size_t start, size_t count, size_t contextCount, int dirFlags) :
|
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) {
|
dirFlags(dirFlags) {
|
||||||
|
textCopy.setTo(text, contextCount);
|
||||||
typeface = paint->getTypeface();
|
typeface = paint->getTypeface();
|
||||||
textSize = paint->getTextSize();
|
textSize = paint->getTextSize();
|
||||||
textSkewX = paint->getTextSkewX();
|
textSkewX = paint->getTextSkewX();
|
||||||
@@ -245,7 +243,6 @@ TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint, const UChar* text,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
|
TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
|
||||||
text(NULL),
|
|
||||||
textCopy(other.textCopy),
|
textCopy(other.textCopy),
|
||||||
start(other.start),
|
start(other.start),
|
||||||
count(other.count),
|
count(other.count),
|
||||||
@@ -259,9 +256,6 @@ TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
|
|||||||
hinting(other.hinting),
|
hinting(other.hinting),
|
||||||
variant(other.variant),
|
variant(other.variant),
|
||||||
language(other.language) {
|
language(other.language) {
|
||||||
if (other.text) {
|
|
||||||
textCopy.setTo(other.text, other.contextCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TextLayoutCacheKey::compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
|
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));
|
return memcmp(lhs.getText(), rhs.getText(), lhs.contextCount * sizeof(UChar));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextLayoutCacheKey::internalTextCopy() {
|
|
||||||
textCopy.setTo(text, contextCount);
|
|
||||||
text = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t TextLayoutCacheKey::getSize() const {
|
size_t TextLayoutCacheKey::getSize() const {
|
||||||
return sizeof(TextLayoutCacheKey) + sizeof(UChar) * contextCount;
|
return sizeof(TextLayoutCacheKey) + sizeof(UChar) * contextCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,12 +76,6 @@ public:
|
|||||||
|
|
||||||
TextLayoutCacheKey(const TextLayoutCacheKey& other);
|
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.
|
* Get the size of the Cache key.
|
||||||
*/
|
*/
|
||||||
@@ -89,8 +83,9 @@ public:
|
|||||||
|
|
||||||
static int compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs);
|
static int compare(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs);
|
||||||
|
|
||||||
|
inline const UChar* getText() const { return textCopy.string(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const UChar* text; // if text is NULL, use textCopy
|
|
||||||
String16 textCopy;
|
String16 textCopy;
|
||||||
size_t start;
|
size_t start;
|
||||||
size_t count;
|
size_t count;
|
||||||
@@ -105,8 +100,6 @@ private:
|
|||||||
SkPaint::FontVariant variant;
|
SkPaint::FontVariant variant;
|
||||||
SkLanguage language;
|
SkLanguage language;
|
||||||
|
|
||||||
inline const UChar* getText() const { return text ? text : textCopy.string(); }
|
|
||||||
|
|
||||||
}; // TextLayoutCacheKey
|
}; // TextLayoutCacheKey
|
||||||
|
|
||||||
inline int strictly_order_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
|
inline int strictly_order_type(const TextLayoutCacheKey& lhs, const TextLayoutCacheKey& rhs) {
|
||||||
@@ -316,6 +309,12 @@ public:
|
|||||||
TextLayoutEngine();
|
TextLayoutEngine();
|
||||||
virtual ~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,
|
sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start,
|
||||||
jint count, jint contextCount, jint dirFlags);
|
jint count, jint contextCount, jint dirFlags);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user