Signed-off-by: Laiganlu <laiganlu@huawei.com>
This commit is contained in:
Laiganlu 2025-01-26 16:07:29 +08:00
parent 01f5b158e3
commit 157b87ebc3
6 changed files with 28 additions and 29 deletions

View File

@ -232,7 +232,7 @@ public:
std::shared_ptr<Media::PixelMap> GetSnapshot() const;
std::shared_ptr<Media::PixelMap> Snapshot(
bool runInFfrt = false, float scaleParam = 0.0f, bool useCurWindow = false) const;
void ResetSnapshotCache();
void ResetSnapshot();
void SaveSnapshot(bool useFfrt, bool needPersist = true);
SessionState GetSessionState() const;
virtual void SetSessionState(SessionState state);

View File

@ -66,7 +66,6 @@ ohos_shared_library("scene_session_manager") {
"src/distributed_client.cpp",
"src/extension_session_manager.cpp",
"src/hidump_controller.cpp",
"src/lru.cpp",
"src/publish/scb_dump_subscriber.cpp",
"src/scb_session_handler.cpp",
"src/scene_input_manager.cpp",
@ -79,6 +78,7 @@ ohos_shared_library("scene_session_manager") {
"src/session_manager_agent_controller.cpp",
"src/window_focus_controller.cpp",
"src/window_scene_config.cpp",
"src/window_manager_lru.cpp",
"src/zidl/scene_session_manager_lite_stub.cpp",
"src/zidl/scene_session_manager_stub.cpp",
]

View File

@ -47,7 +47,7 @@
#include "session/host/include/keyboard_session.h"
#include "session/host/include/root_scene_session.h"
#include "session_listener_controller.h"
#include "session_manager/include/lru.h"
#include "session_manager/include/window_manager_lru.h"
#include "session_manager/include/zidl/scene_session_manager_stub.h"
#include "thread_safety_annotations.h"
#include "transaction/rs_interfaces.h"

View File

@ -15,6 +15,7 @@
#ifndef OHOS_ROSEN_LRUCACHE_H
#define OHOS_ROSEN_LRUCACHE_H
#include <list>
#include <unordered_map>
@ -23,13 +24,13 @@ class LRUCache {
public:
LRUCache(int32_t capacity) : capacity_(capacity) {}
bool get(int32_t key);
int32_t put(int32_t key);
bool Check(int32_t key);
int32_t Put(int32_t key);
private:
int32_t capacity_;
std::list<int32_t> cacheList;
std::unordered_map<int32_t, std::list<int32_t>::iterator> cacheMap;
std::list<int32_t> cacheList_;
std::unordered_map<int32_t, std::list<int32_t>::iterator> cacheMap_;
};
} // namespace OHOS::Rosen
#endif // OHOS_ROSEN_LRUCACHE_H

View File

@ -2451,24 +2451,23 @@ bool SceneSessionManager::IsPcSceneSessionLifecycle(const sptr<SceneSession>& sc
void SceneSessionManager::PutSnapshotToCache(int32_t persistentId)
{
TLOGI(WmsLogTag::WMS_PATTERN, "session:%{public}d", persistentId);
int32_t removeFromCacheSessionId = snapshotLRUCache_->put(persistentId);
TLOGD(WmsLogTag::WMS_PATTERN, "session:%{public}d", persistentId);
int32_t removeFromCacheSessionId = snapshotLRUCache_->Put(persistentId);
if (removeFromCacheSessionId != -1) {
auto removeSceneSession = GetSceneSession(removeFromCacheSessionId);
if (removeSceneSession) {
removeSceneSession->ResetSnapshot();
}
else {
TLOGI(WmsLogTag::WMS_PATTERN, "removeSceneSession:%{public}d nullptr", removeFromCacheSessionId);
} else {
TLOGW(WmsLogTag::WMS_PATTERN, "removeSceneSession:%{public}d nullptr", removeFromCacheSessionId);
}
}
}
void SceneSessionManager::GetSnapshotFromCache(int32_t persistentId)
{
TLOGI(WmsLogTag::WMS_PATTERN, "session:%{public}d", persistentId);
if (!snapshotLRUCache_->get(persistentId)) {
TLOGI(WmsLogTag::WMS_PATTERN, "session not in cache");
TLOGD(WmsLogTag::WMS_PATTERN, "session:%{public}d", persistentId);
if (!snapshotLRUCache_->Check(persistentId)) {
TLOGD(WmsLogTag::WMS_PATTERN, "session:%{public}d not in cache", persistentId);
}
}
@ -2494,8 +2493,7 @@ WSError SceneSessionManager::RequestSceneSessionBackground(const sptr<SceneSessi
}
if (sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW &&
!(sceneSession->GetSystemConfig().IsPcWindow() || sceneSession->GetSystemConfig().freeMultiWindowEnable_))
{
!sceneSession->GetSystemConfig().IsPcWindow() && !sceneSession->GetSystemConfig().freeMultiWindowEnable_) {
PutSnapshotToCache(persistentId);
}

View File

@ -13,30 +13,30 @@
* limitations under the License.
*/
#include "lru.h"
#include "window_manager_lru.h"
#include "window_manager_hilog.h"
namespace OHOS::Rosen {
bool LRUCache::get(int32_t key)
bool LRUCache::Check(int32_t key)
{
if (cacheMap.find(key) == cacheMap.end()) {
if (cacheMap_.find(key) == cacheMap_.end()) {
return false;
}
cacheList.splice(cacheList.begin(), cacheList, cacheMap[key]);
cacheList_.splice(cacheList_.begin(), cacheList_, cacheMap_[key]);
return true;
}
int32_t LRUCache::put(int32_t key)
int32_t LRUCache::Put(int32_t key)
{
int32_t lastKey = -1;
if (!get(key)) {
if (cacheList.size() >= capacity_) {
lastKey = cacheList.back();
cacheMap.erase(lastKey);
cacheList.pop_back();
if (!Check(key)) {
if (cacheList_.size() >= capacity_) {
lastKey = cacheList_.back();
cacheMap_.erase(lastKey);
cacheList_.pop_back();
}
cacheList.push_front(key);
cacheMap[key] = cacheList.begin();
cacheList_.push_front(key);
cacheMap_[key] = cacheList_.begin();
}
return lastKey;
}