• 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 #include <sys/stat.h>
21 
22 #include <refbase.h>
23 
24 #include "common/include/task_scheduler.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, const int32_t& persistentId);
34     ~ScenePersistence() = default;
35 
36     static bool CreateSnapshotDir(const std::string& directory);
37     static bool CreateUpdatedIconDir(const std::string& directory);
38 
39     bool IsSnapshotExisted() const;
40     std::string GetSnapshotFilePath();
41     std::string GetSnapshotFilePathFromAce();
42     std::pair<uint32_t, uint32_t> GetSnapshotSize() const;
43     void SaveSnapshot(const std::shared_ptr<Media::PixelMap>& pixelMap,
44         const std::function<void()> resetSnapshotCallback = [](){});
45     bool IsSavingSnapshot();
46     void RenameSnapshotFromOldPersistentId(const int32_t& oldPersistentId);
47 
48     void SaveUpdatedIcon(const std::shared_ptr<Media::PixelMap>& pixelMap);
49     std::string GetUpdatedIconPath() const;
50     std::shared_ptr<Media::PixelMap> GetLocalSnapshotPixelMap(const float oriScale, const float newScale) const;
51 
52 private:
53     static std::string snapshotDirectory_;
54     std::string bundleName_;
55     std::string snapshotPath_;
56     std::pair<uint32_t, uint32_t> snapshotSize_;
57 
58     static std::string updatedIconDirectory_;
59     std::string updatedIconPath_;
60 
61     std::atomic<int> savingSnapshotSum_ { 0 };
62     std::atomic<bool> isSavingSnapshot_ { false };
63 
64     static std::shared_ptr<TaskScheduler> snapshotScheduler_;
65 };
66 } // namespace OHOS::Rosen
67 
68 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_PERSISTENCE_H
69