• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_POINTER_MANAGER_H
17 #define HGM_POINTER_MANAGER_H
18 
19 #include <memory>
20 
21 #include "hgm_command.h"
22 #include "hgm_one_shot_timer.h"
23 #include "hgm_state_machine.h"
24 
25 namespace OHOS::Rosen {
26 enum PointerEvent : int32_t {
27     POINTER_ACTIVE_EVENT,
28     POINTER_ACTIVE_TIMEOUT_EVENT,
29     POINTER_RS_IDLE_TIMEOUT_EVENT,
30 };
31 
32 enum PointerState : int32_t {
33     POINTER_IDLE_STATE,
34     POINTER_ACTIVE_STATE,
35 };
36 
37 struct PointerInfo {
38     std::string pkgName;
39     PointerState pointerState;
40     int32_t upExpectFps;
41 };
42 
43 class HgmFrameRateManager;
44 class HgmPointerManager final : public HgmStateMachine<PointerState, PointerEvent> {
45 public:
46     HgmPointerManager();
47     ~HgmPointerManager() = default;
48 
49     void HandlePointerEvent(PointerEvent event, const std::string& pkgName = "");
50     void HandleRsFrame();
51     void HandleTimerReset();
52 
GetPkgName()53     std::string GetPkgName() const { return pkgName_; }
54 protected:
55     std::string State2String(State state) const override;
56     bool CheckChangeStateValid(State lastState, State newState) override;
57 private:
58     void Vote();
59     void UpdateStrategyByPointer();
60     std::string pkgName_;
61     HgmSimpleTimer activeTimeoutTimer_;
62     HgmSimpleTimer rsIdleTimeoutTimer_;
63     PointerInfo pointerInfo_ = { "", PointerState::POINTER_IDLE_STATE, OLED_120_HZ };
64 };
65 } // OHOS::Rosen
66 #endif // HGM_POINTER_MANAGER_H