am 3bfe4b47: am 1cd5afc1: am 9317d0b9: am 1fddd3ef: Merge "Mark isInUse per-window" into mnc-dev

* commit '3bfe4b47c7629fab50e64a62d1fa72ab714aa9e0':
  Mark isInUse per-window
This commit is contained in:
John Reck
2015-07-21 21:45:54 +00:00
committed by Android Git Automerger
7 changed files with 25 additions and 21 deletions

View File

@@ -214,10 +214,10 @@ void RenderNode::pushLayerUpdate(TreeInfo& info) {
info.renderer->pushLayerUpdate(mLayer);
}
if (CC_UNLIKELY(info.canvasContext)) {
// If canvasContext is not null that means there are prefetched layers
// that need to be accounted for. That might be us, so tell CanvasContext
// that this layer is in the tree and should not be destroyed.
if (info.canvasContext) {
// There might be prefetched layers that need to be accounted for.
// That might be us, so tell CanvasContext that this layer is in the
// tree and should not be destroyed.
info.canvasContext->markLayerInUse(this);
}
}
@@ -339,7 +339,8 @@ void RenderNode::prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayL
TextureCache& cache = Caches::getInstance().textureCache;
info.out.hasFunctors |= subtree->functors.size();
for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) {
info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]);
info.prepareTextures = cache.prefetchAndMarkInUse(
info.canvasContext, subtree->bitmapResources[i]);
}
for (size_t i = 0; i < subtree->children().size(); i++) {
DrawRenderNodeOp* op = subtree->children()[i];

View File

@@ -97,7 +97,7 @@ public:
* Whether or not the Texture is marked in use and thus not evictable for
* the current frame. This is reset at the start of a new frame.
*/
bool isInUse = false;
void* isInUse = nullptr;
private:
/**

View File

@@ -122,10 +122,12 @@ void TextureCache::setAssetAtlas(AssetAtlas* assetAtlas) {
mAssetAtlas = assetAtlas;
}
void TextureCache::resetMarkInUse() {
void TextureCache::resetMarkInUse(void* ownerToken) {
LruCache<uint32_t, Texture*>::Iterator iter(mCache);
while (iter.next()) {
iter.value()->isInUse = false;
if (iter.value()->isInUse == ownerToken) {
iter.value()->isInUse = nullptr;
}
}
}
@@ -189,10 +191,10 @@ Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap, AtlasUsageType a
return texture;
}
bool TextureCache::prefetchAndMarkInUse(const SkBitmap* bitmap) {
bool TextureCache::prefetchAndMarkInUse(void* ownerToken, const SkBitmap* bitmap) {
Texture* texture = getCachedTexture(bitmap, AtlasUsageType::Use);
if (texture) {
texture->isInUse = true;
texture->isInUse = ownerToken;
}
return texture;
}

View File

@@ -66,14 +66,14 @@ public:
/**
* Resets all Textures to not be marked as in use
*/
void resetMarkInUse();
void resetMarkInUse(void* ownerToken);
/**
* Attempts to precache the SkBitmap. Returns true if a Texture was successfully
* acquired for the bitmap, false otherwise. If a Texture was acquired it is
* marked as in use.
*/
bool prefetchAndMarkInUse(const SkBitmap* bitmap);
bool prefetchAndMarkInUse(void* ownerToken, const SkBitmap* bitmap);
/**
* Returns the texture associated with the specified bitmap from either within the cache, or

View File

@@ -95,7 +95,7 @@ public:
// layer updates or similar. May be NULL.
OpenGLRenderer* renderer;
ErrorHandler* errorHandler;
// TODO: Remove this? May be NULL
// May be NULL (TODO: can it really?)
renderthread::CanvasContext* canvasContext;
struct Out {

View File

@@ -178,16 +178,13 @@ void CanvasContext::prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t sy
info.damageAccumulator = &mDamageAccumulator;
info.renderer = mCanvas;
if (mPrefetechedLayers.size() && info.mode == TreeInfo::MODE_FULL) {
info.canvasContext = this;
}
info.canvasContext = this;
mAnimationContext->startFrame(info.mode);
mRootRenderNode->prepareTree(info);
mAnimationContext->runRemainingAnimations(info);
if (info.canvasContext) {
freePrefetechedLayers();
}
freePrefetechedLayers();
if (CC_UNLIKELY(!mNativeWindow.get())) {
mCurrentFrameInfo->addFlag(FrameInfoFlags::SkippedFrame);
@@ -369,7 +366,11 @@ void CanvasContext::destroyHardwareResources() {
if (mEglManager.hasEglContext()) {
freePrefetechedLayers();
mRootRenderNode->destroyHardwareResources();
Caches::getInstance().flush(Caches::kFlushMode_Layers);
Caches& caches = Caches::getInstance();
// Make sure to release all the textures we were owning as there won't
// be another draw
caches.textureCache.resetMarkInUse(this);
caches.flush(Caches::kFlushMode_Layers);
}
}

View File

@@ -114,7 +114,7 @@ bool DrawFrameTask::syncFrameState(TreeInfo& info) {
int64_t vsync = mFrameInfo[static_cast<int>(FrameInfoIndex::Vsync)];
mRenderThread->timeLord().vsyncReceived(vsync);
mContext->makeCurrent();
Caches::getInstance().textureCache.resetMarkInUse();
Caches::getInstance().textureCache.resetMarkInUse(mContext);
for (size_t i = 0; i < mLayers.size(); i++) {
mContext->processLayerUpdate(mLayers[i].get());