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 OHOS_WINDOW_RATE_MANAGER_H 17 #define OHOS_WINDOW_RATE_MANAGER_H 18 19 #include <atomic> 20 #include <memory> 21 #include <mutex> 22 #include <unordered_map> 23 24 #include "wm_single_instance.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class WindowRateManager { 29 WM_DECLARE_SINGLE_INSTANCE_BASE(WindowRateManager); 30 public: 31 WindowRateManager() = default; 32 ~WindowRateManager() = default; 33 void FlushFrameRate(int32_t id, uint32_t rate); 34 void FlushFrameRateForRootWindow(uint32_t rate); 35 void AddWindowRate(int32_t windowId, uint32_t rate = 0); 36 void RemoveWindowRate(int32_t windowId); 37 uint32_t GetExpectedRate(); 38 39 private: 40 std::mutex mtx_; 41 std::unordered_map<int32_t, uint32_t> windowRateMap_; 42 uint32_t expectedRate_ = 0; 43 uint32_t rootWindowRate_ = 0; 44 }; 45 } // namespace Rosen 46 } // namespace OHOS 47 #endif // OHOS_WINDOW_RATE_MANAGER_H