Merge "Fix bug #5274332 TextLayoutCache is having multiple instances"
This commit is contained in:
committed by
Android (Google) Code Review
commit
9f443fb6e7
@@ -760,7 +760,8 @@ public:
|
|||||||
jint count = end - start;
|
jint count = end - start;
|
||||||
sp<TextLayoutCacheValue> value;
|
sp<TextLayoutCacheValue> value;
|
||||||
#if USE_TEXT_LAYOUT_CACHE
|
#if USE_TEXT_LAYOUT_CACHE
|
||||||
value = gTextLayoutCache.getValue(paint, textArray, start, count, end, flags);
|
value = TextLayoutCache::getInstance().getValue(paint, textArray, start, count,
|
||||||
|
end, flags);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
LOGE("Cannot get TextLayoutCache value");
|
LOGE("Cannot get TextLayoutCache value");
|
||||||
return ;
|
return ;
|
||||||
@@ -780,7 +781,8 @@ public:
|
|||||||
|
|
||||||
sp<TextLayoutCacheValue> value;
|
sp<TextLayoutCacheValue> value;
|
||||||
#if USE_TEXT_LAYOUT_CACHE
|
#if USE_TEXT_LAYOUT_CACHE
|
||||||
value = gTextLayoutCache.getValue(paint, textArray, start, count, contextCount, flags);
|
value = TextLayoutCache::getInstance().getValue(paint, textArray, start, count,
|
||||||
|
contextCount, flags);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
LOGE("Cannot get TextLayoutCache value");
|
LOGE("Cannot get TextLayoutCache value");
|
||||||
return ;
|
return ;
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ void TextLayout::getTextRunAdvances(SkPaint* paint, const jchar* chars, jint sta
|
|||||||
sp<TextLayoutCacheValue> value;
|
sp<TextLayoutCacheValue> value;
|
||||||
#if USE_TEXT_LAYOUT_CACHE
|
#if USE_TEXT_LAYOUT_CACHE
|
||||||
// Return advances from the cache. Compute them if needed
|
// Return advances from the cache. Compute them if needed
|
||||||
value = gTextLayoutCache.getValue(
|
value = TextLayoutCache::getInstance().getValue(
|
||||||
paint, chars, start, count, contextCount, dirFlags);
|
paint, chars, start, count, contextCount, dirFlags);
|
||||||
#else
|
#else
|
||||||
value = new TextLayoutCacheValue();
|
value = new TextLayoutCacheValue();
|
||||||
|
|||||||
@@ -41,11 +41,6 @@ namespace android {
|
|||||||
*/
|
*/
|
||||||
#define USE_TEXT_LAYOUT_CACHE 1
|
#define USE_TEXT_LAYOUT_CACHE 1
|
||||||
|
|
||||||
|
|
||||||
#if USE_TEXT_LAYOUT_CACHE
|
|
||||||
static TextLayoutCache gTextLayoutCache;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kBidi_LTR = 0,
|
kBidi_LTR = 0,
|
||||||
kBidi_RTL = 1,
|
kBidi_RTL = 1,
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define LOG_TAG "TextLayoutCache"
|
||||||
|
|
||||||
#include "TextLayoutCache.h"
|
#include "TextLayoutCache.h"
|
||||||
#include "TextLayout.h"
|
#include "TextLayout.h"
|
||||||
|
|
||||||
@@ -23,6 +25,12 @@ extern "C" {
|
|||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
#if USE_TEXT_LAYOUT_CACHE
|
||||||
|
ANDROID_SINGLETON_STATIC_INSTANCE(TextLayoutCache);
|
||||||
|
#endif
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
TextLayoutCache::TextLayoutCache() :
|
TextLayoutCache::TextLayoutCache() :
|
||||||
mCache(GenerationCache<TextLayoutCacheKey, sp<TextLayoutCacheValue> >::kUnlimitedCapacity),
|
mCache(GenerationCache<TextLayoutCacheKey, sp<TextLayoutCacheValue> >::kUnlimitedCapacity),
|
||||||
mSize(0), mMaxSize(MB(DEFAULT_TEXT_LAYOUT_CACHE_SIZE_IN_MB)),
|
mSize(0), mMaxSize(MB(DEFAULT_TEXT_LAYOUT_CACHE_SIZE_IN_MB)),
|
||||||
@@ -30,13 +38,6 @@ TextLayoutCache::TextLayoutCache() :
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextLayoutCache::TextLayoutCache(uint32_t max):
|
|
||||||
mCache(GenerationCache<TextLayoutCacheKey, sp<TextLayoutCacheValue> >::kUnlimitedCapacity),
|
|
||||||
mSize(0), mMaxSize(max),
|
|
||||||
mCacheHitCount(0), mNanosecondsSaved(0) {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
TextLayoutCache::~TextLayoutCache() {
|
TextLayoutCache::~TextLayoutCache() {
|
||||||
mCache.clear();
|
mCache.clear();
|
||||||
}
|
}
|
||||||
@@ -46,25 +47,21 @@ void TextLayoutCache::init() {
|
|||||||
|
|
||||||
mDebugLevel = readRtlDebugLevel();
|
mDebugLevel = readRtlDebugLevel();
|
||||||
mDebugEnabled = mDebugLevel & kRtlDebugCaches;
|
mDebugEnabled = mDebugLevel & kRtlDebugCaches;
|
||||||
LOGD("Using TextLayoutCache debug level: %d - Debug Enabled: %d", mDebugLevel, mDebugEnabled);
|
LOGD("Using debug level: %d - Debug Enabled: %d", mDebugLevel, mDebugEnabled);
|
||||||
|
|
||||||
mCacheStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
|
mCacheStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||||
if (mDebugEnabled) {
|
|
||||||
LOGD("TextLayoutCache start time: %lld", mCacheStartTime);
|
|
||||||
}
|
|
||||||
mInitialized = true;
|
|
||||||
|
|
||||||
if (mDebugEnabled) {
|
if (mDebugEnabled) {
|
||||||
|
LOGD("Start time: %lld", mCacheStartTime);
|
||||||
#if RTL_USE_HARFBUZZ
|
#if RTL_USE_HARFBUZZ
|
||||||
LOGD("TextLayoutCache is using HARFBUZZ");
|
LOGD("Using HARFBUZZ");
|
||||||
#else
|
#else
|
||||||
LOGD("TextLayoutCache is using ICU");
|
LOGD("Using ICU");
|
||||||
#endif
|
#endif
|
||||||
|
LOGD("Initialization is done");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDebugEnabled) {
|
mInitialized = true;
|
||||||
LOGD("TextLayoutCache initialization is done");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -147,8 +144,7 @@ sp<TextLayoutCacheValue> TextLayoutCache::getValue(SkPaint* paint,
|
|||||||
// Cleanup to make some room if needed
|
// Cleanup to make some room if needed
|
||||||
if (mSize + size > mMaxSize) {
|
if (mSize + size > mMaxSize) {
|
||||||
if (mDebugEnabled) {
|
if (mDebugEnabled) {
|
||||||
LOGD("TextLayoutCache: need to clean some entries "
|
LOGD("Need to clean some entries for making some room for a new entry");
|
||||||
"for making some room for a new entry");
|
|
||||||
}
|
}
|
||||||
while (mSize + size > mMaxSize) {
|
while (mSize + size > mMaxSize) {
|
||||||
// This will call the callback
|
// This will call the callback
|
||||||
@@ -213,7 +209,7 @@ void TextLayoutCache::dumpCacheStats() {
|
|||||||
float remainingPercent = 100 * ((mMaxSize - mSize) / ((float)mMaxSize));
|
float remainingPercent = 100 * ((mMaxSize - mSize) / ((float)mMaxSize));
|
||||||
float timeRunningInSec = (systemTime(SYSTEM_TIME_MONOTONIC) - mCacheStartTime) / 1000000000;
|
float timeRunningInSec = (systemTime(SYSTEM_TIME_MONOTONIC) - mCacheStartTime) / 1000000000;
|
||||||
LOGD("------------------------------------------------");
|
LOGD("------------------------------------------------");
|
||||||
LOGD("TextLayoutCache stats");
|
LOGD("Cache stats");
|
||||||
LOGD("------------------------------------------------");
|
LOGD("------------------------------------------------");
|
||||||
LOGD("pid : %d", getpid());
|
LOGD("pid : %d", getpid());
|
||||||
LOGD("running : %.0f seconds", timeRunningInSec);
|
LOGD("running : %.0f seconds", timeRunningInSec);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <utils/GenerationCache.h>
|
#include <utils/GenerationCache.h>
|
||||||
#include <utils/Compare.h>
|
#include <utils/Compare.h>
|
||||||
#include <utils/RefBase.h>
|
#include <utils/RefBase.h>
|
||||||
|
#include <utils/Singleton.h>
|
||||||
|
|
||||||
#include <SkPaint.h>
|
#include <SkPaint.h>
|
||||||
#include <SkTemplates.h>
|
#include <SkTemplates.h>
|
||||||
@@ -187,11 +188,11 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Cache of text layout information.
|
* Cache of text layout information.
|
||||||
*/
|
*/
|
||||||
class TextLayoutCache : public OnEntryRemoved<TextLayoutCacheKey, sp<TextLayoutCacheValue> >
|
class TextLayoutCache : public OnEntryRemoved<TextLayoutCacheKey, sp<TextLayoutCacheValue> >,
|
||||||
|
public Singleton<TextLayoutCache>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextLayoutCache();
|
TextLayoutCache();
|
||||||
TextLayoutCache(uint32_t maxByteSize);
|
|
||||||
|
|
||||||
virtual ~TextLayoutCache();
|
virtual ~TextLayoutCache();
|
||||||
|
|
||||||
|
|||||||
@@ -477,7 +477,7 @@ static void renderText(OpenGLRenderer* renderer, const jchar* text, int count,
|
|||||||
#if RTL_USE_HARFBUZZ
|
#if RTL_USE_HARFBUZZ
|
||||||
sp<TextLayoutCacheValue> value;
|
sp<TextLayoutCacheValue> value;
|
||||||
#if USE_TEXT_LAYOUT_CACHE
|
#if USE_TEXT_LAYOUT_CACHE
|
||||||
value = gTextLayoutCache.getValue(paint, text, 0, count, count, flags);
|
value = TextLayoutCache::getInstance().getValue(paint, text, 0, count, count, flags);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
LOGE("Cannot get TextLayoutCache value");
|
LOGE("Cannot get TextLayoutCache value");
|
||||||
return ;
|
return ;
|
||||||
@@ -507,7 +507,7 @@ static void renderTextRun(OpenGLRenderer* renderer, const jchar* text,
|
|||||||
#if RTL_USE_HARFBUZZ
|
#if RTL_USE_HARFBUZZ
|
||||||
sp<TextLayoutCacheValue> value;
|
sp<TextLayoutCacheValue> value;
|
||||||
#if USE_TEXT_LAYOUT_CACHE
|
#if USE_TEXT_LAYOUT_CACHE
|
||||||
value = gTextLayoutCache.getValue(paint, text, start, count, contextCount, flags);
|
value = TextLayoutCache::getInstance().getValue(paint, text, start, count, contextCount, flags);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
LOGE("Cannot get TextLayoutCache value");
|
LOGE("Cannot get TextLayoutCache value");
|
||||||
return ;
|
return ;
|
||||||
|
|||||||
Reference in New Issue
Block a user