• 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 HGM_CORE_H
17 #define HGM_CORE_H
18 
19 #include <functional>
20 #include <cinttypes>
21 #include <thread>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include <event_handler.h>
26 
27 #include "hgm_screen.h"
28 #include "hgm_frame_rate_tool.h"
29 #include "xml_parser.h"
30 
31 namespace OHOS::Rosen {
32 class HgmCore final {
33 public:
34     static HgmCore& Instance();
35 
GetScreenIds()36     std::vector<ScreenId> GetScreenIds() const
37     {
38         return screenIds_;
39     }
40 
IsEnabled()41     bool IsEnabled() const
42     {
43         return isEnabled_;
44     }
45 
IsInit()46     bool IsInit() const
47     {
48         return isInit_;
49     }
50 
GetScreenListSize()51     int32_t GetScreenListSize() const
52     {
53         return screenList_.size();
54     }
55 
GetActiveScreenId()56     ScreenId GetActiveScreenId() const
57     {
58         return activeScreenId_;
59     }
60 
61     int32_t SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate);
62     int32_t SetRateAndResolution(ScreenId id, int32_t sceneId, int32_t rate, int32_t width, int32_t height);
63     int32_t SetRefreshRateMode(RefreshRateMode refreshRateMode);
64     int32_t SetDefaultRefreshRateMode();
65     int32_t AddScreen(ScreenId id, int32_t defaultMode);
66     int32_t RemoveScreen(ScreenId id);
67     int32_t AddScreenInfo(ScreenId id, int32_t width, int32_t height, uint32_t rate, int32_t mode);
68     int32_t RefreshBundleName(std::string name);
69     uint32_t GetScreenCurrentRefreshRate(ScreenId id);
70     sptr<HgmScreen> GetScreen(ScreenId id) const;
71     std::vector<uint32_t> GetScreenSupportedRefreshRates(ScreenId id);
72     std::unique_ptr<std::unordered_map<ScreenId, int32_t>> GetModesToApply();
73     int32_t AddScreenProfile(ScreenId id, int32_t width, int32_t height, int32_t phyWidth, int32_t phyHeight);
74     int32_t RemoveScreenProfile(ScreenId id);
75     int32_t CalModifierPreferred(HgmModifierProfile &hgmModifierProfile) const;
76     void SetActiveScreenId(ScreenId id);
77 
78 private:
79     HgmCore();
80     ~HgmCore();
81     HgmCore(const HgmCore&) = delete;
82     HgmCore(const HgmCore&&) = delete;
83     HgmCore& operator=(const HgmCore&) = delete;
84     HgmCore& operator=(const HgmCore&&) = delete;
85 
86     bool Init();
87     int32_t InitXmlConfig();
88     int32_t SetCustomRateMode(RefreshRateMode mode);
89     int32_t SetModeBySettingConfig();
90     int32_t RequestBundlePermission(int32_t rate);
91 
92     bool isEnabled_ = true;
93     bool isInit_ = false;
94     std::unique_ptr<XMLParser> mParser_;
95     std::shared_ptr<ParsedConfigData> mParsedConfigData_ = nullptr;
96 
97     RefreshRateMode customFrameRateMode_ = HGM_REFRESHRATE_MODE_AUTO;
98     std::vector<ScreenId> screenIds_;
99     std::vector<sptr<HgmScreen>> screenList_;
100     mutable std::mutex listMutex_;
101 
102     mutable std::mutex modeListMutex_;
103     std::unique_ptr<std::unordered_map<ScreenId, int32_t>> modeListToApply_ = nullptr;
104 
105     std::string currentBundleName_;
106     std::shared_ptr<HgmFrameRateTool> hgmFrameRateTool_ = nullptr;
107     ScreenId activeScreenId_ = 0;
108 };
109 } // namespace OHOS::Rosen
110 #endif // HGM_CORE_H
111