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 57 void UpdateAceAnimatorExpectedFrameRate(int32_t aceAnimatorExpectedFrameRate); 58 ResetAceAnimatorExpectedFrameRate()59 void ResetAceAnimatorExpectedFrameRate() 60 { 61 aceAnimatorExpectedFrameRate_ = ANIMATOR_NOT_RUNNING; 62 } 63 64 void UpdateSurfaceTime(const std::string& surfaceName, uint64_t timestamp, 65 pid_t pid, UIFWKType uiFwkType = UIFWKType::FROM_UNKNOWN); 66 67 void UpdateSurfaceState(uint64_t timestamp); 68 GetSurfaceIdleState()69 bool GetSurfaceIdleState() const 70 { 71 return surfaceTimeMap_.empty(); 72 } 73 74 private: 75 bool GetUnknownFrameworkState(const std::string& surfaceName, 76 std::string& uiFwkType); 77 bool GetSurfaceFrameworkState(const std::string& surfaceName, 78 std::string& validSurfaceName); 79 bool appSupported_ = false; 80 bool aceAnimatorIdleState_ = true; 81 int32_t aceAnimatorExpectedFrameRate_ = ANIMATOR_NOT_RUNNING; 82 83 // FORMAT: <buffername, time> 84 std::unordered_map<std::string, uint64_t> surfaceTimeMap_; 85 // FORMAT: <buffername, fps> 86 std::unordered_map<std::string, int32_t> bufferFpsMap_; 87 }; 88 } // namespace Rosen 89 } // namespace OHOS 90 #endif // HGM_IDLE_DETECTOR_H 91