• 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_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_iframe_rate_linker_expected_fps_update_callback.h"
24 #include "ipc_callbacks/rs_ihgm_config_change_callback.h"
25 #include "refbase.h"
26 
27 namespace OHOS::Rosen {
28 class HgmConfigCallbackManager : public RefBase {
29 public:
30     static sptr<HgmConfigCallbackManager> GetInstance() noexcept;
31 
32     // non-copyable
33     HgmConfigCallbackManager(const HgmConfigCallbackManager&) = delete;
34     HgmConfigCallbackManager& operator=(const HgmConfigCallbackManager&) = delete;
35 
36     void RegisterHgmConfigChangeCallback(pid_t pid, const sptr<RSIHgmConfigChangeCallback>& callback);
37     void RegisterHgmRefreshRateModeChangeCallback(pid_t pid, const sptr<RSIHgmConfigChangeCallback>& callback);
38     void RegisterHgmRefreshRateUpdateCallback(pid_t pid, const sptr<RSIHgmConfigChangeCallback>& callback);
39     void RegisterXComponentExpectedFrameRateCallback(pid_t listenerPid, pid_t dstPid,
40         const sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback>& callback);
41     void SyncHgmConfigChangeCallback();
42     void SyncHgmConfigChangeCallback(const std::unordered_map<pid_t, std::pair<int32_t, std::string>>& pids);
43     void SyncRefreshRateModeChangeCallback(int32_t refreshRateMode);
44     void SyncRefreshRateUpdateCallback(int32_t refreshRate);
45     void SyncXComponentExpectedFrameRateCallback(pid_t pid, const std::string& xcomponentId, int32_t expectedFrameRate);
46     void UnRegisterHgmConfigChangeCallback(pid_t pid);
47 
48 private:
49     HgmConfigCallbackManager();
50     ~HgmConfigCallbackManager() noexcept override;
51     void DestroyXComponent(pid_t pid, const std::string& xcomponentId);
52 
53     static std::once_flag createFlag_;
54     static sptr<HgmConfigCallbackManager> instance_;
55     std::unordered_map<pid_t, sptr<RSIHgmConfigChangeCallback>> animDynamicCfgCallbacks_;
56     std::unordered_map<pid_t, sptr<RSIHgmConfigChangeCallback>> pendingAnimDynamicCfgCallbacks_;
57     std::unordered_map<pid_t, sptr<RSIHgmConfigChangeCallback>> refreshRateModeCallbacks_;
58     std::unordered_map<pid_t, sptr<RSIHgmConfigChangeCallback>> refreshRateUpdateCallbacks_;
59     // <dstPid, <listenerPid, cb>>
60     std::unordered_map<pid_t, std::unordered_map<pid_t,
61         sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback>>> xcomponentExpectedFrameRateCallbacks_;
62     // <dstPid, <xcomponentId, frameRate>>
63     std::unordered_map<pid_t, std::unordered_map<std::string, int32_t>> xcomponentExpectedFrameRate_;
64 };
65 } // namespace OHOS::Rosen
66 #endif // HGM_CONFIG_CALLBACK_MANAGER_H