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 OHOS_ROSEN_SESSION_DISPLAY_POWER_CONTROLLER_H
17 #define OHOS_ROSEN_SESSION_DISPLAY_POWER_CONTROLLER_H
18 
19 #include <atomic>
20 #include <map>
21 #include <mutex>
22 #include <refbase.h>
23 #include "display.h"
24 #include "display_change_listener.h"
25 #include "dm_common.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 class SessionDisplayPowerController : public RefBase {
30 using SessionDisplayStateChangeListener = std::function<void(DisplayId, sptr<DisplayInfo>,
31     const std::map<DisplayId, sptr<DisplayInfo>>&, DisplayStateChangeType)>;
32 public:
SessionDisplayPowerController(SessionDisplayStateChangeListener listener)33     SessionDisplayPowerController(SessionDisplayStateChangeListener listener)
34         : displayStateChangeListener_(listener)
35     {
36     }
37     virtual ~SessionDisplayPowerController() = default;
38 
39     bool SuspendBegin(PowerStateChangeReason reason);
40     bool SetDisplayState(DisplayState state);
41     DisplayState GetDisplayState(DisplayId displayId);
42     void NotifyDisplayEvent(DisplayEvent event);
43 
44     bool needCancelNotify_ { false };
45     bool canceledSuspend_ { false };
46     bool canCancelSuspendNotify_ { false };
47     bool skipScreenOffBlock_ { false };
48     std::mutex notifyMutex_;
49 
50 private:
51     void WaitScreenOffNotify(DisplayState& state);
52     void SetDisplayStateToOn(DisplayState& state);
53     std::atomic<DisplayState> displayState_ { DisplayState::UNKNOWN };
54     SessionDisplayStateChangeListener displayStateChangeListener_;
55 };
56 }
57 }
58 #endif // OHOS_ROSEN_DISPLAY_POWER_CONTROLLER_H