!16506 优化pixelmap的内存释放时机 cherry-pick

Merge pull request !16506 from chuchengcheng/cherry-pick-1730190336
This commit is contained in:
openharmony_ci 2024-10-30 08:02:54 +00:00 committed by Gitee
commit 1f09e6d4a1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 26 additions and 5 deletions

View File

@ -48,6 +48,7 @@ public:
RSImageCache() = default;
~RSImageCache() = default;
bool CheckUniqueIdIsEmpty();
void CollectUniqueId(uint64_t uniqueId);
void ReleaseUniqueIdList();
private:

View File

@ -45,11 +45,7 @@ RSImageBase::~RSImageBase()
if (pixelMap_) {
pixelMap_ = nullptr;
if (uniqueId_ > 0) {
if (renderServiceImage_) {
RSImageCache::Instance().CollectUniqueId(uniqueId_);
} else {
RSImageCache::Instance().ReleasePixelMapCache(uniqueId_);
}
RSImageCache::Instance().CollectUniqueId(uniqueId_);
}
#if defined(ROSEN_OHOS) && defined(RS_ENABLE_VK)
if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||

View File

@ -122,6 +122,18 @@ void RSImageCache::ReleaseUniqueIdList()
}
}
bool RSImageCache::CheckUniqueIdIsEmpty()
{
if (uniqueIdListMutex_.try_lock()) {
if (uniqueIdList_.empty()) {
uniqueIdListMutex_.unlock();
return true;
}
uniqueIdListMutex_.unlock();
}
return false;
}
void RSImageCache::ReleasePixelMapCache(uint64_t uniqueId)
{
std::shared_ptr<Media::PixelMap> pixelMap = nullptr;

View File

@ -22,6 +22,7 @@
#include "animation/rs_animation_fraction.h"
#include "command/rs_surface_node_command.h"
#include "common/rs_background_thread.h"
#include "delegate/rs_functional_delegate.h"
#include "pipeline/rs_draw_cmd_list.h"
#include "pipeline/rs_node_map.h"
@ -32,6 +33,7 @@
#include "platform/common/rs_log.h"
#include "platform/common/rs_system_properties.h"
#include "property/rs_property_trace.h"
#include "render/rs_image_cache.h"
#include "render/rs_typeface_cache.h"
#include "render_context/shader_cache.h"
#include "rs_frame_report.h"
@ -125,6 +127,7 @@ RSRenderThread::RSRenderThread()
context_->activeNodesInRoot_.clear();
}
RSRenderNodeGC::Instance().ReleaseNodeMemory();
ReleasePixelMapInBackgroundThread();
context_->pendingSyncNodes_.clear();
#ifdef ROSEN_OHOS
FRAME_TRACE::RenderFrameTrace::GetInstance().RenderEndFrameTrace(RT_INTERVAL_NAME);
@ -171,6 +174,14 @@ void RSRenderThread::Start()
}
}
void RSRenderThread::ReleasePixelMapInBackgroundThread()
{
if (!RSImageCache::Instance().CheckUniqueIdIsEmpty()) {
static std::function<void()> task = []() -> void { RSImageCache::Instance().ReleaseUniqueIdList(); };
RSBackgroundThread::Instance().PostTask(task);
}
}
void RSRenderThread::Stop()
{
running_.store(false);

View File

@ -141,6 +141,7 @@ private:
void Animate(uint64_t timestamp);
void Render();
void SendCommands();
void ReleasePixelMapInBackgroundThread();
std::atomic_bool running_ = false;
std::atomic_bool hasSkipVsync_ = false;