Release buffer immediately if the surface node is checked not on the tree.

Signed-off-by: xxfeng_hw <yuxiaofeng8@huawei.com>
Change-Id: Ib2a436f592f296ed66951ddb2041f69ff72abb92
This commit is contained in:
xxfeng_hw 2022-01-26 14:52:21 +08:00
parent b5d3c39ce7
commit 9c57b9522a
3 changed files with 39 additions and 3 deletions

View File

@ -35,9 +35,37 @@ void RSRenderServiceListener::OnBufferAvailable()
return;
}
ROSEN_LOGE("RsDebug RSRenderServiceListener::OnBufferAvailable node id:%llu", node->GetId());
node->IncreaseAvailableBuffer();
if (!node->IsOnTheTree()) {
RSMainThread::Instance()->PostTask([node]() {
ROSEN_LOGI("RsDebug RSRenderServiceListener::OnBufferAvailable node id:%llu: is not on the tree",
node->GetId());
auto& surfaceConsumer = node->GetConsumer();
if (surfaceConsumer == nullptr) {
ROSEN_LOGE("RsDebug RSRenderServiceListener::OnBufferAvailable: consumer is null!");
return;
}
sptr<SurfaceBuffer> buffer;
int32_t fence = -1;
int64_t timestamp = 0;
Rect damage;
auto ret = surfaceConsumer->AcquireBuffer(buffer, fence, timestamp, damage);
if (buffer == nullptr || ret != SURFACE_ERROR_OK) {
ROSEN_LOGE("RsDebug RSRenderServiceListener::OnBufferAvailable: AcquireBuffer failed!");
return;
}
if (node->GetBuffer() != nullptr && node->GetBuffer() != buffer) {
(void)surfaceConsumer->ReleaseBuffer(node->GetBuffer(), -1);
}
node->SetBuffer(buffer);
node->SetFence(fence);
});
} else {
node->IncreaseAvailableBuffer();
}
RSMainThread::Instance()->RequestNextVSync();
}
} // namespace Rosen
} // namespace OHOS
} // namespace OHOS

View File

@ -52,6 +52,11 @@ public:
return id_;
}
bool IsOnTheTree() const
{
return isOnTheTree_;
}
std::vector<WeakPtr>& GetChildren()
{
return children_;
@ -120,6 +125,7 @@ private:
const std::weak_ptr<RSContext> context_;
NodeDirty dirtyStatus_ = NodeDirty::DIRTY;
bool isOnTheTree_ = false;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -46,6 +46,7 @@ void RSBaseRenderNode::AddChild(const SharedPtr& child, int index)
}
OnAddChild(child);
child->isOnTheTree_ = true;
}
void RSBaseRenderNode::RemoveChild(const SharedPtr& child)
@ -64,6 +65,7 @@ void RSBaseRenderNode::RemoveChild(const SharedPtr& child)
SetDirty();
OnRemoveChild(child);
child->isOnTheTree_ = false;
}
void RSBaseRenderNode::OnAddChild(const SharedPtr& child)