Merge "Mark isInUse per-window" into mnc-dev

This commit is contained in:
John Reck
2015-07-21 20:50:27 +00:00
committed by Android (Google) Code Review
7 changed files with 25 additions and 21 deletions

View File

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

View File

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

View File

@@ -66,14 +66,14 @@ public:
/** /**
* Resets all Textures to not be marked as in use * 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 * 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 * acquired for the bitmap, false otherwise. If a Texture was acquired it is
* marked as in use. * 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 * 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. // layer updates or similar. May be NULL.
OpenGLRenderer* renderer; OpenGLRenderer* renderer;
ErrorHandler* errorHandler; ErrorHandler* errorHandler;
// TODO: Remove this? May be NULL // May be NULL (TODO: can it really?)
renderthread::CanvasContext* canvasContext; renderthread::CanvasContext* canvasContext;
struct Out { struct Out {

View File

@@ -178,16 +178,13 @@ void CanvasContext::prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t sy
info.damageAccumulator = &mDamageAccumulator; info.damageAccumulator = &mDamageAccumulator;
info.renderer = mCanvas; info.renderer = mCanvas;
if (mPrefetechedLayers.size() && info.mode == TreeInfo::MODE_FULL) { info.canvasContext = this;
info.canvasContext = this;
}
mAnimationContext->startFrame(info.mode); mAnimationContext->startFrame(info.mode);
mRootRenderNode->prepareTree(info); mRootRenderNode->prepareTree(info);
mAnimationContext->runRemainingAnimations(info); mAnimationContext->runRemainingAnimations(info);
if (info.canvasContext) { freePrefetechedLayers();
freePrefetechedLayers();
}
if (CC_UNLIKELY(!mNativeWindow.get())) { if (CC_UNLIKELY(!mNativeWindow.get())) {
mCurrentFrameInfo->addFlag(FrameInfoFlags::SkippedFrame); mCurrentFrameInfo->addFlag(FrameInfoFlags::SkippedFrame);
@@ -369,7 +366,11 @@ void CanvasContext::destroyHardwareResources() {
if (mEglManager.hasEglContext()) { if (mEglManager.hasEglContext()) {
freePrefetechedLayers(); freePrefetechedLayers();
mRootRenderNode->destroyHardwareResources(); 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)]; int64_t vsync = mFrameInfo[static_cast<int>(FrameInfoIndex::Vsync)];
mRenderThread->timeLord().vsyncReceived(vsync); mRenderThread->timeLord().vsyncReceived(vsync);
mContext->makeCurrent(); mContext->makeCurrent();
Caches::getInstance().textureCache.resetMarkInUse(); Caches::getInstance().textureCache.resetMarkInUse(mContext);
for (size_t i = 0; i < mLayers.size(); i++) { for (size_t i = 0; i < mLayers.size(); i++) {
mContext->processLayerUpdate(mLayers[i].get()); mContext->processLayerUpdate(mLayers[i].get());