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_CONFIG_CALLBACK_MANAGER_H 17 #define HGM_CONFIG_CALLBACK_MANAGER_H 18 19 #include <list> 20 #include <mutex> 21 #include <unordered_map> 22 23 #include "ipc_callbacks/rs_ihgm_config_change_callback.h" 24 #include "refbase.h" 25 26 namespace OHOS::Rosen { 27 class HgmConfigCallbackManager : public RefBase { 28 public: 29 static sptr<HgmConfigCallbackManager> GetInstance() noexcept; 30 31 // non-copyable 32 HgmConfigCallbackManager(const HgmConfigCallbackManager &) = delete; 33 HgmConfigCallbackManager &operator=(const HgmConfigCallbackManager &) = delete; 34 35 void RegisterHgmConfigChangeCallback(pid_t pid, const sptr<RSIHgmConfigChangeCallback>& callback); 36 void RegisterHgmRefreshRateModeChangeCallback(pid_t pid, const sptr<RSIHgmConfigChangeCallback>& callback); 37 void RegisterHgmRefreshRateUpdateCallback(pid_t pid, const sptr<RSIHgmConfigChangeCallback>& callback); 38 void SyncHgmConfigChangeCallback(); 39 void SyncRefreshRateModeChangeCallback(int32_t refreshRateMode); 40 void SyncRefreshRateUpdateCallback(int32_t refreshRate); 41 void UnRegisterHgmConfigChangeCallback(pid_t pid); 42 43 private: 44 HgmConfigCallbackManager(); 45 ~HgmConfigCallbackManager() noexcept override; 46 std::mutex mtx_; 47 static std::once_flag createFlag_; 48 static sptr<HgmConfigCallbackManager> instance_; 49 std::unordered_map<pid_t, sptr<RSIHgmConfigChangeCallback>> animDynamicCfgCallbacks_; 50 std::unordered_map<pid_t, sptr<RSIHgmConfigChangeCallback>> refreshRateModeCallbacks_; 51 std::unordered_map<pid_t, sptr<RSIHgmConfigChangeCallback>> refreshRateUpdateCallbacks_; 52 }; 53 } // namespace OHOS::Rosen 54 #endif // HGM_CONFIG_CALLBACK_MANAGER_H