• 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_FRAME_RATE_TOOL_H
17 #define HGM_FRAME_RATE_TOOL_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 #include <cmath>
23 #include <refbase.h>
24 #include <unordered_map>
25 
26 #include "screen_manager/screen_types.h"
27 #include "animation/rs_frame_rate_range.h"
28 
29 #include "hgm_command.h"
30 
31 namespace OHOS::Rosen {
32 constexpr float INCH_2_MM = 25.4f;
33 
34 class HgmFrameRateTool final {
35 public:
36     static std::shared_ptr<HgmFrameRateTool> GetInstance();
37 
38     ~HgmFrameRateTool() noexcept;
39     // noncopyable
40     HgmFrameRateTool(const HgmFrameRateTool &) = delete;
41     HgmFrameRateTool &operator=(const HgmFrameRateTool &) = delete;
42     int32_t AddScreenProfile(ScreenId id, int32_t width, int32_t height, int32_t phyWidth, int32_t phyHeight);
43     int32_t RemoveScreenProfile(ScreenId id);
44     int32_t CalModifierPreferred(
45         ScreenId id, HgmModifierProfile &hgmModifierProfile, std::shared_ptr<ParsedConfigData> parsedConfigData) const;
46 private:
47     class ScreenProfile {
48     public:
ScreenProfile(ScreenId id,int32_t width,int32_t height,int32_t phyWidth,int32_t phyHeight)49         ScreenProfile(ScreenId id, int32_t width, int32_t height, int32_t phyWidth, int32_t phyHeight)
50             : id_(id), width_(width), height_(height), phyWidth_(phyWidth), phyHeight_(phyHeight)
51         {
52             auto screenSize = sqrt(pow(width, 2) + pow(height, 2));
53             auto phyScreenSize = sqrt(pow(phyWidth, 2) + pow(phyHeight, 2));
54             ppi_ = screenSize / (phyScreenSize / INCH_2_MM);
55             xDpi_ = width / (phyWidth / INCH_2_MM);
56             yDpi_ = height / (phyHeight / INCH_2_MM);
57         }
58 
59         ~ScreenProfile() = default;
60 
GetWidth()61         int32_t GetWidth() const
62         {
63             return width_;
64         }
65 
GetHeight()66         int32_t GetHeight() const
67         {
68             return height_;
69         }
70 
GetPhyWidth()71         int32_t GetPhyWidth() const
72         {
73             return phyWidth_;
74         }
75 
GetPhyHeight()76         int32_t GetPhyHeight() const
77         {
78             return phyHeight_;
79         }
80 
GetPpi()81         float GetPpi() const
82         {
83             return ppi_;
84         }
85 
GetXDpi()86         float GetXDpi() const
87         {
88             return xDpi_;
89         }
90 
GetYDpi()91         float GetYDpi() const
92         {
93             return yDpi_;
94         }
95 
GetId()96         ScreenId GetId() const
97         {
98             return id_;
99         }
100 
101     private:
102         ScreenId id_;
103         int32_t width_;
104         int32_t height_;
105         int32_t phyWidth_;
106         int32_t phyHeight_;
107         float ppi_;
108         float xDpi_;
109         float yDpi_;
110     };
111 
112     std::vector<std::shared_ptr<ScreenProfile>> screenProfileList_;
113     HgmFrameRateTool();
114     std::shared_ptr<ScreenProfile> GetScreenProfile(ScreenId id) const;
115     static std::pair<float, float> applyDimension(
116         SpeedTransType speedTransType, float xSpeed, float ySpeed, std::shared_ptr<ScreenProfile> screenProfile);
117     mutable std::mutex listMutex_;
118 };
119 } // namespace OHOS::Rosen
120 #endif // HGM_FRAME_RATE