• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ROSEN_WINDOW_SCENE_SCENE_PERSISTENCE_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SCENE_PERSISTENCE_H
18 
19 #include <string>
20 
21 #include <refbase.h>
22 
23 #include "common/include/task_scheduler.h"
24 #include "session/host/include/ws_ffrt_helper.h"
25 
26 namespace OHOS::Media {
27 class PixelMap;
28 } // namespace OHOS::Media
29 
30 namespace OHOS::Rosen {
31 class ScenePersistence : public RefBase {
32 public:
33     ScenePersistence(const std::string& bundleName, int32_t persistentId);
34     virtual ~ScenePersistence();
35 
36     static bool CreateSnapshotDir(const std::string& directory);
37     static bool CreateUpdatedIconDir(const std::string& directory);
38 
39     static bool IsAstcEnabled();
40     void SetHasSnapshot(bool hasSnapshot);
41     bool HasSnapshot() const;
42     bool IsSnapshotExisted() const;
43     std::string GetSnapshotFilePath();
44     std::pair<uint32_t, uint32_t> GetSnapshotSize() const;
45     std::shared_ptr<WSFFRTHelper> GetSnapshotFfrtHelper() const;
46 
47     void SaveSnapshot(const std::shared_ptr<Media::PixelMap>& pixelMap,
48         const std::function<void()> resetSnapshotCallback = [](){});
49     bool IsSavingSnapshot();
50     void ResetSnapshotCache();
51     void RenameSnapshotFromOldPersistentId(const int32_t& oldPersistentId);
52 
53     void SaveUpdatedIcon(const std::shared_ptr<Media::PixelMap>& pixelMap);
54     std::string GetUpdatedIconPath() const;
55     std::shared_ptr<Media::PixelMap> GetLocalSnapshotPixelMap(const float oriScale, const float newScale) const;
56 
57 private:
58     static std::string snapshotDirectory_;
59     std::string bundleName_;
60     int32_t persistentId_;
61     std::string snapshotPath_;
62     std::pair<uint32_t, uint32_t> snapshotSize_;
63     bool hasSnapshot_ = false;
64 
65     static std::string updatedIconDirectory_;
66     std::string updatedIconPath_;
67 
68     std::atomic<int> savingSnapshotSum_ { 0 };
69     std::atomic<bool> isSavingSnapshot_ { false };
70 
71     static std::shared_ptr<WSFFRTHelper> snapshotFfrtHelper_;
72     mutable std::mutex savingSnapshotMutex_;
73 };
74 } // namespace OHOS::Rosen
75 
76 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_PERSISTENCE_H
77