am 327cb318: Merge "Yank ResourceCache out of Caches" into lmp-mr1-dev automerge: 9c13b8c

* commit '327cb3184d5f5d9f22db9ab18a07bb71081bb446':
  Yank ResourceCache out of Caches
This commit is contained in:
John Reck
2014-11-06 19:22:28 +00:00
committed by Android Git Automerger
10 changed files with 46 additions and 33 deletions

View File

@@ -17,7 +17,7 @@
#include <jni.h> #include <jni.h>
#include <Caches.h> #include <ResourceCache.h>
#if 0 #if 0
#define TRACE_BITMAP(code) code #define TRACE_BITMAP(code) code
@@ -365,8 +365,8 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) { static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) {
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
#ifdef USE_OPENGL_RENDERER #ifdef USE_OPENGL_RENDERER
if (android::uirenderer::Caches::hasInstance()) { if (android::uirenderer::ResourceCache::hasInstance()) {
android::uirenderer::Caches::getInstance().resourceCache.destructor(bitmap); android::uirenderer::ResourceCache::getInstance().destructor(bitmap);
return; return;
} }
#endif // USE_OPENGL_RENDERER #endif // USE_OPENGL_RENDERER
@@ -376,9 +376,9 @@ static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) {
static jboolean Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) { static jboolean Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) {
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
#ifdef USE_OPENGL_RENDERER #ifdef USE_OPENGL_RENDERER
if (android::uirenderer::Caches::hasInstance()) { if (android::uirenderer::ResourceCache::hasInstance()) {
bool result; bool result;
result = android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap); result = android::uirenderer::ResourceCache::getInstance().recycle(bitmap);
return result ? JNI_TRUE : JNI_FALSE; return result ? JNI_TRUE : JNI_FALSE;
} }
#endif // USE_OPENGL_RENDERER #endif // USE_OPENGL_RENDERER

View File

@@ -21,7 +21,7 @@
#include <androidfw/ResourceTypes.h> #include <androidfw/ResourceTypes.h>
#include <utils/Log.h> #include <utils/Log.h>
#include <Caches.h> #include <ResourceCache.h>
#include "Paint.h" #include "Paint.h"
#include "Canvas.h" #include "Canvas.h"
@@ -80,9 +80,9 @@ public:
static void finalize(JNIEnv* env, jobject, jlong patchHandle) { static void finalize(JNIEnv* env, jobject, jlong patchHandle) {
int8_t* patch = reinterpret_cast<int8_t*>(patchHandle); int8_t* patch = reinterpret_cast<int8_t*>(patchHandle);
#ifdef USE_OPENGL_RENDERER #ifdef USE_OPENGL_RENDERER
if (android::uirenderer::Caches::hasInstance()) { if (android::uirenderer::ResourceCache::hasInstance()) {
Res_png_9patch* p = (Res_png_9patch*) patch; Res_png_9patch* p = (Res_png_9patch*) patch;
android::uirenderer::Caches::getInstance().resourceCache.destructor(p); android::uirenderer::ResourceCache::getInstance().destructor(p);
return; return;
} }
#endif // USE_OPENGL_RENDERER #endif // USE_OPENGL_RENDERER

View File

@@ -27,7 +27,7 @@
#include "SkPath.h" #include "SkPath.h"
#include "SkPathOps.h" #include "SkPathOps.h"
#include <Caches.h> #include <ResourceCache.h>
#include <vector> #include <vector>
#include <map> #include <map>
@@ -39,8 +39,8 @@ public:
static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) { static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
SkPath* obj = reinterpret_cast<SkPath*>(objHandle); SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
#ifdef USE_OPENGL_RENDERER #ifdef USE_OPENGL_RENDERER
if (android::uirenderer::Caches::hasInstance()) { if (android::uirenderer::ResourceCache::hasInstance()) {
android::uirenderer::Caches::getInstance().resourceCache.destructor(obj); android::uirenderer::ResourceCache::getInstance().destructor(obj);
return; return;
} }
#endif #endif

View File

@@ -340,7 +340,6 @@ public:
TessellationCache tessellationCache; TessellationCache tessellationCache;
TextDropShadowCache dropShadowCache; TextDropShadowCache dropShadowCache;
FboCache fboCache; FboCache fboCache;
ResourceCache resourceCache;
GammaFontRenderer* fontRenderer; GammaFontRenderer* fontRenderer;

View File

@@ -39,29 +39,28 @@ DisplayListData::~DisplayListData() {
} }
void DisplayListData::cleanupResources() { void DisplayListData::cleanupResources() {
Caches& caches = Caches::getInstance(); ResourceCache& resourceCache = ResourceCache::getInstance();
caches.unregisterFunctors(functors.size()); resourceCache.lock();
caches.resourceCache.lock();
for (size_t i = 0; i < bitmapResources.size(); i++) { for (size_t i = 0; i < bitmapResources.size(); i++) {
caches.resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i)); resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
} }
for (size_t i = 0; i < ownedBitmapResources.size(); i++) { for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
const SkBitmap* bitmap = ownedBitmapResources.itemAt(i); const SkBitmap* bitmap = ownedBitmapResources.itemAt(i);
caches.resourceCache.decrementRefcountLocked(bitmap); resourceCache.decrementRefcountLocked(bitmap);
caches.resourceCache.destructorLocked(bitmap); resourceCache.destructorLocked(bitmap);
} }
for (size_t i = 0; i < patchResources.size(); i++) { for (size_t i = 0; i < patchResources.size(); i++) {
caches.resourceCache.decrementRefcountLocked(patchResources.itemAt(i)); resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
} }
for (size_t i = 0; i < sourcePaths.size(); i++) { for (size_t i = 0; i < sourcePaths.size(); i++) {
caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i)); resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
} }
caches.resourceCache.unlock(); resourceCache.unlock();
for (size_t i = 0; i < paints.size(); i++) { for (size_t i = 0; i < paints.size(); i++) {
delete paints.itemAt(i); delete paints.itemAt(i);

View File

@@ -21,7 +21,7 @@
#include <private/hwui/DrawGlInfo.h> #include <private/hwui/DrawGlInfo.h>
#include "Caches.h" #include "ResourceCache.h"
#include "DeferredDisplayList.h" #include "DeferredDisplayList.h"
#include "DisplayListLogBuffer.h" #include "DisplayListLogBuffer.h"
#include "DisplayListOp.h" #include "DisplayListOp.h"
@@ -32,7 +32,7 @@ namespace android {
namespace uirenderer { namespace uirenderer {
DisplayListRenderer::DisplayListRenderer() DisplayListRenderer::DisplayListRenderer()
: mCaches(Caches::getInstance()) : mResourceCache(ResourceCache::getInstance())
, mDisplayListData(NULL) , mDisplayListData(NULL)
, mTranslateX(0.0f) , mTranslateX(0.0f)
, mTranslateY(0.0f) , mTranslateY(0.0f)

View File

@@ -24,6 +24,7 @@
#include "DisplayListLogBuffer.h" #include "DisplayListLogBuffer.h"
#include "RenderNode.h" #include "RenderNode.h"
#include "ResourceCache.h"
namespace android { namespace android {
namespace uirenderer { namespace uirenderer {
@@ -209,7 +210,7 @@ private:
mDisplayListData->paths.add(pathCopy); mDisplayListData->paths.add(pathCopy);
} }
if (mDisplayListData->sourcePaths.indexOf(path) < 0) { if (mDisplayListData->sourcePaths.indexOf(path) < 0) {
mCaches.resourceCache.incrementRefcount(path); mResourceCache.incrementRefcount(path);
mDisplayListData->sourcePaths.add(path); mDisplayListData->sourcePaths.add(path);
} }
return pathCopy; return pathCopy;
@@ -273,19 +274,19 @@ private:
// contents, and drawing again. The only fix would be to always copy it the first time, // contents, and drawing again. The only fix would be to always copy it the first time,
// which doesn't seem worth the extra cycles for this unlikely case. // which doesn't seem worth the extra cycles for this unlikely case.
mDisplayListData->bitmapResources.add(bitmap); mDisplayListData->bitmapResources.add(bitmap);
mCaches.resourceCache.incrementRefcount(bitmap); mResourceCache.incrementRefcount(bitmap);
return bitmap; return bitmap;
} }
inline const SkBitmap* refBitmapData(const SkBitmap* bitmap) { inline const SkBitmap* refBitmapData(const SkBitmap* bitmap) {
mDisplayListData->ownedBitmapResources.add(bitmap); mDisplayListData->ownedBitmapResources.add(bitmap);
mCaches.resourceCache.incrementRefcount(bitmap); mResourceCache.incrementRefcount(bitmap);
return bitmap; return bitmap;
} }
inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) { inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
mDisplayListData->patchResources.add(patch); mDisplayListData->patchResources.add(patch);
mCaches.resourceCache.incrementRefcount(patch); mResourceCache.incrementRefcount(patch);
return patch; return patch;
} }
@@ -293,7 +294,7 @@ private:
DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap; DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap; DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
Caches& mCaches; ResourceCache& mResourceCache;
DisplayListData* mDisplayListData; DisplayListData* mDisplayListData;
float mTranslateX; float mTranslateX;

View File

@@ -98,9 +98,6 @@ void RenderNode::setStagingDisplayList(DisplayListData* data) {
mNeedsDisplayListDataSync = true; mNeedsDisplayListDataSync = true;
delete mStagingDisplayListData; delete mStagingDisplayListData;
mStagingDisplayListData = data; mStagingDisplayListData = data;
if (mStagingDisplayListData) {
Caches::getInstance().registerFunctors(mStagingDisplayListData->functors.size());
}
} }
/** /**
@@ -305,6 +302,10 @@ void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) {
// changes in isRenderable or, in the future, bounds // changes in isRenderable or, in the future, bounds
damageSelf(info); damageSelf(info);
deleteDisplayListData(); deleteDisplayListData();
// TODO: Remove this caches stuff
if (mStagingDisplayListData && mStagingDisplayListData->functors.size()) {
Caches::getInstance().registerFunctors(mStagingDisplayListData->functors.size());
}
mDisplayListData = mStagingDisplayListData; mDisplayListData = mStagingDisplayListData;
mStagingDisplayListData = NULL; mStagingDisplayListData = NULL;
if (mDisplayListData) { if (mDisplayListData) {
@@ -321,6 +322,9 @@ void RenderNode::deleteDisplayListData() {
for (size_t i = 0; i < mDisplayListData->children().size(); i++) { for (size_t i = 0; i < mDisplayListData->children().size(); i++) {
mDisplayListData->children()[i]->mRenderNode->decParentRefCount(); mDisplayListData->children()[i]->mRenderNode->decParentRefCount();
} }
if (mDisplayListData->functors.size()) {
Caches::getInstance().unregisterFunctors(mDisplayListData->functors.size());
}
} }
delete mDisplayListData; delete mDisplayListData;
mDisplayListData = NULL; mDisplayListData = NULL;

View File

@@ -21,6 +21,12 @@
#include "Caches.h" #include "Caches.h"
namespace android { namespace android {
#ifdef USE_OPENGL_RENDERER
using namespace uirenderer;
ANDROID_SINGLETON_STATIC_INSTANCE(ResourceCache);
#endif
namespace uirenderer { namespace uirenderer {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@@ -22,6 +22,7 @@
#include <SkBitmap.h> #include <SkBitmap.h>
#include <utils/KeyedVector.h> #include <utils/KeyedVector.h>
#include <utils/Singleton.h>
#include <androidfw/ResourceTypes.h> #include <androidfw/ResourceTypes.h>
@@ -53,11 +54,14 @@ public:
ResourceType resourceType; ResourceType resourceType;
}; };
class ANDROID_API ResourceCache { class ANDROID_API ResourceCache: public Singleton<ResourceCache> {
public:
ResourceCache(); ResourceCache();
~ResourceCache(); ~ResourceCache();
friend class Singleton<ResourceCache>;
public:
/** /**
* When using these two methods, make sure to only invoke the *Locked() * When using these two methods, make sure to only invoke the *Locked()
* variants of increment/decrementRefcount(), recyle() and destructor() * variants of increment/decrementRefcount(), recyle() and destructor()