From 0bcf027ad3c8aaf014c2048323c649ef3e301a74 Mon Sep 17 00:00:00 2001 From: c00607827 Date: Thu, 4 Jan 2024 21:26:59 +0800 Subject: [PATCH] optimize system scene Signed-off-by: c00607827 --- .../vsync/include/vsync_distributor.h | 1 + .../composer/vsync/src/vsync_distributor.cpp | 47 ++++++++++++----- .../core/pipeline/rs_main_thread.cpp | 52 ++++++++++++++----- .../core/pipeline/rs_main_thread.h | 6 ++- .../include/pipeline/rs_surface_render_node.h | 2 +- .../src/pipeline/rs_surface_render_node.cpp | 9 ++-- 6 files changed, 83 insertions(+), 34 deletions(-) diff --git a/rosen/modules/composer/vsync/include/vsync_distributor.h b/rosen/modules/composer/vsync/include/vsync_distributor.h index 68dbdbde06..fa80fc94c7 100644 --- a/rosen/modules/composer/vsync/include/vsync_distributor.h +++ b/rosen/modules/composer/vsync/include/vsync_distributor.h @@ -134,6 +134,7 @@ private: std::mutex mutex_; std::condition_variable con_; std::vector > connections_; + std::map>> connectionsMap_; VSyncEvent event_; bool vsyncEnabled_; std::string name_; diff --git a/rosen/modules/composer/vsync/src/vsync_distributor.cpp b/rosen/modules/composer/vsync/src/vsync_distributor.cpp index 2423be95e9..bbe1c00b6f 100644 --- a/rosen/modules/composer/vsync/src/vsync_distributor.cpp +++ b/rosen/modules/composer/vsync/src/vsync_distributor.cpp @@ -251,6 +251,10 @@ VsyncError VSyncDistributor::AddConnection(const sptr& connecti ScopedBytrace func("Add VSyncConnection: " + connection->info_.name_); connections_.push_back(connection); connectionCounter_[proxyPid]++; + uint32_t tmpPid; + if (QosGetPidByName(connection->info_.name_, tmpPid) == VSYNC_ERROR_OK) { + connectionsMap_[tmpPid].push_back(connection); + } return VSYNC_ERROR_OK; } @@ -271,6 +275,18 @@ VsyncError VSyncDistributor::RemoveConnection(const sptr& conne if (connectionCounter_[proxyPid] == 0) { connectionCounter_.erase(proxyPid); } + uint32_t tmpPid; + if (QosGetPidByName(connection->info_.name_, tmpPid) == VSYNC_ERROR_OK) { + auto iter = connectionsMap_.find(tmpPid); + if (iter == connectionsMap_.end()) { + return VSYNC_ERROR_OK; + } + auto connIter = find(iter->second.begin(), iter->second.end(), connection); + iter->second.erase(connIter); + if (iter->second.empty()) { + connectionsMap_.erase(iter); + } + } return VSYNC_ERROR_OK; } @@ -518,7 +534,7 @@ VsyncError VSyncDistributor::GetVSyncConnectionInfos(std::vector VsyncError VSyncDistributor::QosGetPidByName(const std::string& name, uint32_t& pid) { - if (name.find("WM") == std::string::npos) { + if (name.find("WM") == std::string::npos && name.find("NWeb") == std::string::npos) { return VSYNC_ERROR_INVALID_ARGUMENTS; } std::string::size_type pos = name.find("_"); @@ -532,23 +548,28 @@ VsyncError VSyncDistributor::QosGetPidByName(const std::string& name, uint32_t& VsyncError VSyncDistributor::SetQosVSyncRate(uint32_t pid, int32_t rate) { std::lock_guard locker(mutex_); - for (auto connection : connections_) { + auto iter = connectionsMap_.find(pid); + if (iter == connectionsMap_.end()) { + VLOGD("%{public}s:%{public}d pid[%{public}u] can not found", __func__, __LINE__, pid); + return VSYNC_ERROR_INVALID_ARGUMENTS; + } + bool isNeedNotify = false; + for (auto connection : iter->second) { uint32_t tmpPid; - if (QosGetPidByName(connection->info_.name_, tmpPid) != VSYNC_ERROR_OK) { + if (QosGetPidByName(connection->info_.name_, tmpPid) != VSYNC_ERROR_OK || tmpPid != pid) { continue; } - - if (tmpPid == pid) { - if (connection->highPriorityRate_ != rate) { - connection->highPriorityRate_ = rate; - connection->highPriorityState_ = true; - VLOGD("in, conn name:%{public}s, highPriorityRate:%{public}d", connection->info_.name_.c_str(), - connection->highPriorityRate_); - con_.notify_all(); - } - break; + if (connection->highPriorityRate_ != rate) { + connection->highPriorityRate_ = rate; + connection->highPriorityState_ = true; + VLOGD("in, conn name:%{public}s, highPriorityRate:%{public}d", connection->info_.name_.c_str(), + connection->highPriorityRate_); + isNeedNotify = true; } } + if (isNeedNotify) { + con_.notify_all(); + } return VSYNC_ERROR_OK; } diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp index 57bf215f45..b0099868b5 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -124,6 +124,7 @@ constexpr uint64_t CLEAN_CACHE_FREQ = 60; constexpr uint64_t SKIP_COMMAND_FREQ_LIMIT = 30; constexpr uint64_t PERF_PERIOD_BLUR = 80000000; constexpr uint64_t MAX_DYNAMIC_STATUS_TIME = 5000000000; +constexpr uint64_t MAX_SYSTEM_SCENE_STATUS_TIME = 800000000; constexpr uint64_t PERF_PERIOD_MULTI_WINDOW = 80000000; constexpr uint32_t MULTI_WINDOW_PERF_START_NUM = 2; constexpr uint32_t MULTI_WINDOW_PERF_END_NUM = 4; @@ -133,7 +134,7 @@ constexpr uint32_t HARDWARE_THREAD_TASK_NUM = 2; constexpr int32_t SIMI_VISIBLE_RATE = 2; constexpr int32_t DEFAULT_RATE = 1; constexpr int32_t INVISBLE_WINDOW_RATE = INT32_MAX; -constexpr int32_t SYSTEM_ANIMATED_SECNES_RATE = 3; +constexpr int32_t SYSTEM_ANIMATED_SECNES_RATE = 2; constexpr uint32_t WAIT_FOR_MEM_MGR_SERVICE = 100; constexpr uint32_t CAL_NODE_PREFERRED_FPS_LIMIT = 50; constexpr const char* WALLPAPER_VIEW = "WallpaperView"; @@ -1521,9 +1522,29 @@ void RSMainThread::Render() renderEngine_->ShrinkCachesIfNeeded(); } CallbackDrawContextStatusToWMS(); + CheckSystemSceneStatus(); PerfForBlurIfNeeded(); } +void RSMainThread::CheckSystemSceneStatus() +{ + std::lock_guard lock(systemAnimatedScenesMutex_); + while (!systemAnimatedScenesList_.empty()) { + if (timestamp_ - systemAnimatedScenesList_.front().second > MAX_SYSTEM_SCENE_STATUS_TIME) { + systemAnimatedScenesList_.pop_front(); + } else { + break; + } + } + while (!threeFingerScenesList_.empty()) { + if (timestamp_ - threeFingerScenesList_.front().second > MAX_SYSTEM_SCENE_STATUS_TIME) { + threeFingerScenesList_.pop_front(); + } else { + break; + } + } +} + void RSMainThread::CallbackDrawContextStatusToWMS() { VisibleData drawStatusVec; @@ -1623,7 +1644,7 @@ void RSMainThread::CalcOcclusionImplementation(std::vectorIsLeashWindow()) { continue; } - curSurface->SetOcclusionInSpecificScenes(deviceType_ == DeviceType::PC && threeFingerCnt_); + curSurface->SetOcclusionInSpecificScenes(deviceType_ == DeviceType::PC && !threeFingerScenesList_.empty()); Occlusion::Rect occlusionRect = curSurface->GetSurfaceOcclusionRect(isUniRender_); curSurface->setQosCal(vsyncControlEnabled_); if (CheckSurfaceNeedProcess(occlusionSurfaces, curSurface)) { @@ -1633,7 +1654,7 @@ void RSMainThread::CalcOcclusionImplementation(std::vectorGetId(), visibleLevel); curSurface->SetVisibleRegionRecursive(subResult, curVisVec, pidVisMap, true, visibleLevel, - systemAnimatedScenesCnt_); + !systemAnimatedScenesList_.empty()); curSurface->AccumulateOcclusionRegion(accumulatedRegion, curRegion, hasFilterCacheOcclusion, isUniRender_, filterCacheOcclusionEnabled); } else { @@ -1661,7 +1682,7 @@ void RSMainThread::CalcOcclusionImplementation(std::vectorSetVisibleRegionRecursive(subResult, curVisVec, pidVisMap, false, visibleLevel, - systemAnimatedScenesCnt_); + !systemAnimatedScenesList_.empty()); curSurface->AccumulateOcclusionRegion(accumulatedRegion, curRegion, hasFilterCacheOcclusion, isUniRender_, false); } else { @@ -1737,19 +1758,20 @@ void RSMainThread::CalcOcclusion() surface->CleanDirtyRegionUpdated(); } } - if (!winDirty) { + if (!winDirty && !(systemAnimatedScenesList_.empty() && isReduceVSyncBySystemAnimatedScenes_)) { if (SurfaceOcclusionCallBackIfOnTreeStateChanged()) { SurfaceOcclusionCallback(); } return; } + isReduceVSyncBySystemAnimatedScenes_ = false; CalcOcclusionImplementation(curAllSurfaces); } bool RSMainThread::CheckSurfaceVisChanged(std::map& pidVisMap, std::vector& curAllSurfaces) { - if (systemAnimatedScenesCnt_ > 0) { + if (!systemAnimatedScenesList_.empty()) { pidVisMap.clear(); for (auto it = curAllSurfaces.rbegin(); it != curAllSurfaces.rend(); ++it) { auto curSurface = RSBaseRenderNode::ReinterpretCast(*it); @@ -1759,6 +1781,7 @@ bool RSMainThread::CheckSurfaceVisChanged(std::map& pi uint32_t tmpPid = ExtractPid(curSurface->GetId()); pidVisMap[tmpPid] = RSVisibleLevel::RS_SYSTEM_ANIMATE_SCENE; } + isReduceVSyncBySystemAnimatedScenes_ = true; } bool isVisibleChanged = pidVisMap.size() != lastPidVisMap_.size(); if (!isVisibleChanged) { @@ -2646,8 +2669,9 @@ void RSMainThread::SetAppWindowNum(uint32_t num) bool RSMainThread::SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes) { - RS_OPTIONAL_TRACE_NAME_FMT("%s systemAnimatedScenes[%u] systemAnimatedScenes_[%u]", __func__, - systemAnimatedScenes, systemAnimatedScenes_); + RS_OPTIONAL_TRACE_NAME_FMT("%s systemAnimatedScenes[%u] systemAnimatedScenes_[%u] threeFingerScenesListSize[%d] " + "systemAnimatedScenesListSize_[%d]", __func__, systemAnimatedScenes, + systemAnimatedScenes_, threeFingerScenesList_.size(), systemAnimatedScenesList_.size()); if (systemAnimatedScenes < SystemAnimatedScenes::ENTER_MISSION_CENTER || systemAnimatedScenes > SystemAnimatedScenes::OTHERS) { RS_LOGD("RSMainThread::SetSystemAnimatedScenes Out of range."); @@ -2660,17 +2684,19 @@ bool RSMainThread::SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedSc { std::lock_guard lock(systemAnimatedScenesMutex_); if (systemAnimatedScenes == SystemAnimatedScenes::OTHERS) { - if (threeFingerCnt_ > 0) { - --threeFingerCnt_; + if (!threeFingerScenesList_.empty()) { + threeFingerScenesList_.pop_front(); + } + if (!systemAnimatedScenesList_.empty()) { + systemAnimatedScenesList_.pop_front(); } - --systemAnimatedScenesCnt_; } else { if (systemAnimatedScenes == SystemAnimatedScenes::ENTER_TFS_WINDOW || systemAnimatedScenes == SystemAnimatedScenes::EXIT_TFU_WINDOW) { - ++threeFingerCnt_; + threeFingerScenesList_.push_back(std::make_pair(systemAnimatedScenes, timestamp_)); } if (systemAnimatedScenes != SystemAnimatedScenes::APPEAR_MISSION_CENTER) { - ++systemAnimatedScenesCnt_; + systemAnimatedScenesList_.push_back(std::make_pair(systemAnimatedScenes, timestamp_)); } } } diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.h b/rosen/modules/render_service/core/pipeline/rs_main_thread.h index 810fe798cd..a607d81422 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.h +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.h @@ -295,6 +295,7 @@ private: void SetRSEventDetectorLoopStartTag(); void SetRSEventDetectorLoopFinishTag(); void CallbackDrawContextStatusToWMS(); + void CheckSystemSceneStatus(); void UpdateUIFirstSwitch(); // ROG: Resolution Online Government void UpdateRogSizeIfNeeded(); @@ -499,8 +500,9 @@ private: std::mutex surfaceOcclusionMutex_; std::vector lastRegisteredSurfaceOnTree_; std::mutex systemAnimatedScenesMutex_; - int32_t threeFingerCnt_ = 0; - int32_t systemAnimatedScenesCnt_ = 0; + std::list> systemAnimatedScenesList_; + std::list> threeFingerScenesList_; + bool isReduceVSyncBySystemAnimatedScenes_ = false; std::unordered_map> std::tuple, std::vector, uint8_t>> surfaceOcclusionListeners_; diff --git a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h index df8b80c318..8f2cc31e13 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h @@ -466,7 +466,7 @@ public: std::map& pidVisMap, bool needSetVisibleRegion = true, RSVisibleLevel visibleLevel = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL, - int32_t systemAnimatedScenesCnt = 0); + bool isSystemAnimatedScenes = false); const Occlusion::Region& GetVisibleDirtyRegion() const { diff --git a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp index 3980188f9b..327bc660a3 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp @@ -888,7 +888,7 @@ void RSSurfaceRenderNode::SetVisibleRegionRecursive(const Occlusion::Region& reg std::map& pidVisMap, bool needSetVisibleRegion, RSVisibleLevel visibleLevel, - int32_t systemAnimatedScenesCnt) + bool isSystemAnimatedScenes) { if (nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE || IsAbilityComponent()) { SetOcclusionVisible(true); @@ -902,10 +902,9 @@ void RSSurfaceRenderNode::SetVisibleRegionRecursive(const Occlusion::Region& reg } // collect visible changed pid - if (qosPidCal_ && GetType() == RSRenderNodeType::SURFACE_NODE && - systemAnimatedScenesCnt == 0 && !IsMultiInstance()) { + if (qosPidCal_ && GetType() == RSRenderNodeType::SURFACE_NODE && !isSystemAnimatedScenes) { uint32_t tmpPid = ExtractPid(GetId()); - pidVisMap[tmpPid] = visibleLevel; + pidVisMap[tmpPid] = IsMultiInstance() ? RSVisibleLevel::RS_ALL_VISIBLE : visibleLevel; } visibleRegionForCallBack_ = region; @@ -919,7 +918,7 @@ void RSSurfaceRenderNode::SetVisibleRegionRecursive(const Occlusion::Region& reg for (auto& child : GetChildren()) { if (auto surfaceChild = RSBaseRenderNode::ReinterpretCast(child)) { surfaceChild->SetVisibleRegionRecursive(region, visibleVec, pidVisMap, needSetVisibleRegion, - visibleLevel, systemAnimatedScenesCnt); + visibleLevel, isSystemAnimatedScenes); } } } -- Gitee