• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_IDLE_DETECTOR_H
17 #define HGM_IDLE_DETECTOR_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 #include "pipeline/rs_render_node.h"
23 namespace OHOS {
24 namespace Rosen {
25 
26 enum class UIFWKType : int32_t {
27     FROM_UNKNOWN = 0,
28     FROM_SURFACE = 1,
29 };
30 
31 class HgmIdleDetector {
32 public:
33     static constexpr int32_t ANIMATOR_NOT_RUNNING = -1;
34 
35     HgmIdleDetector() = default;
36     ~HgmIdleDetector() = default;
37 
38     void SetAppSupportedState(bool appSupported);
GetAppSupportedState()39     bool GetAppSupportedState() const
40     {
41         return appSupported_;
42     }
43 
SetBufferFpsMap(std::unordered_map<std::string,int32_t> bufferFpsMap)44     void SetBufferFpsMap(std::unordered_map<std::string, int32_t> bufferFpsMap)
45     {
46         bufferFpsMap_ = std::move(bufferFpsMap);
47     }
48 
49     int32_t GetTouchUpExpectedFPS();
50 
51     void SetAceAnimatorIdleState(bool aceAnimatorIdleState);
GetAceAnimatorIdleState()52     bool GetAceAnimatorIdleState() const
53     {
54         return aceAnimatorIdleState_;
55     }
56 
UpdateAceAnimatorExpectedFrameRate(int32_t aceAnimatorExpectedFrameRate)57     void UpdateAceAnimatorExpectedFrameRate(int32_t aceAnimatorExpectedFrameRate)
58     {
59         if (aceAnimatorExpectedFrameRate > aceAnimatorExpectedFrameRate_) {
60             aceAnimatorExpectedFrameRate_ = aceAnimatorExpectedFrameRate;
61         }
62     }
63 
ResetAceAnimatorExpectedFrameRate()64     void ResetAceAnimatorExpectedFrameRate()
65     {
66         aceAnimatorExpectedFrameRate_ = ANIMATOR_NOT_RUNNING;
67     }
68 
69     void UpdateSurfaceTime(const std::string& surfaceName, uint64_t timestamp,
70         pid_t pid, UIFWKType uiFwkType = UIFWKType::FROM_UNKNOWN);
71 
72     void UpdateSurfaceState(uint64_t timestamp);
73 
GetSurfaceIdleState()74     bool GetSurfaceIdleState() const
75     {
76         return surfaceTimeMap_.empty();
77     }
78 
79 private:
80     bool GetUnknownFrameworkState(const std::string& surfaceName,
81         std::string& uiFwkType);
82     bool GetSurfaceFrameworkState(const std::string& surfaceName,
83         std::string& validSurfaceName);
84     bool appSupported_ = false;
85     bool aceAnimatorIdleState_ = true;
86     int32_t aceAnimatorExpectedFrameRate_ = ANIMATOR_NOT_RUNNING;
87 
88     // FORMAT: <buffername, time>
89     std::unordered_map<std::string, uint64_t> surfaceTimeMap_;
90     // FORMAT: <buffername, fps>
91     std::unordered_map<std::string, int32_t> bufferFpsMap_;
92 };
93 } // namespace Rosen
94 } // namespace OHOS
95 #endif // HGM_IDLE_DETECTOR_H
96