1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License.
5e0dac50fSopenharmony_ci * You may obtain a copy of the License at
6e0dac50fSopenharmony_ci *
7e0dac50fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0dac50fSopenharmony_ci *
9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and
13e0dac50fSopenharmony_ci * limitations under the License.
14e0dac50fSopenharmony_ci */
15e0dac50fSopenharmony_ci
16e0dac50fSopenharmony_ci#ifndef FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H
17e0dac50fSopenharmony_ci#define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H
18e0dac50fSopenharmony_ci
19e0dac50fSopenharmony_ci#include <map>
20e0dac50fSopenharmony_ci#include <mutex>
21e0dac50fSopenharmony_ci
22e0dac50fSopenharmony_ci#include <system_ability.h>
23e0dac50fSopenharmony_ci#include <surface.h>
24e0dac50fSopenharmony_ci#include <ui/rs_display_node.h>
25e0dac50fSopenharmony_ci
26e0dac50fSopenharmony_ci#include "atomic_map.h"
27e0dac50fSopenharmony_ci#include "dm_common.h"
28e0dac50fSopenharmony_ci#include "display_dumper.h"
29e0dac50fSopenharmony_ci#include "screen.h"
30e0dac50fSopenharmony_ci#include "abstract_display.h"
31e0dac50fSopenharmony_ci#include "abstract_display_controller.h"
32e0dac50fSopenharmony_ci#include "abstract_screen_controller.h"
33e0dac50fSopenharmony_ci#include "display_change_listener.h"
34e0dac50fSopenharmony_ci#include "display_cutout_controller.h"
35e0dac50fSopenharmony_ci#include "display_manager_stub.h"
36e0dac50fSopenharmony_ci#include "display_power_controller.h"
37e0dac50fSopenharmony_ci#include "singleton_delegator.h"
38e0dac50fSopenharmony_ci#include "window_info_queried_listener.h"
39e0dac50fSopenharmony_ci
40e0dac50fSopenharmony_cinamespace OHOS::Rosen {
41e0dac50fSopenharmony_ciclass DisplayManagerService : public SystemAbility, public DisplayManagerStub {
42e0dac50fSopenharmony_ciDECLARE_SYSTEM_ABILITY(DisplayManagerService);
43e0dac50fSopenharmony_ciWM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService);
44e0dac50fSopenharmony_ci
45e0dac50fSopenharmony_cipublic:
46e0dac50fSopenharmony_ci    int Dump(int fd, const std::vector<std::u16string>& args) override;
47e0dac50fSopenharmony_ci    void OnStart() override;
48e0dac50fSopenharmony_ci    void OnStop() override;
49e0dac50fSopenharmony_ci    ScreenId CreateVirtualScreen(VirtualScreenOption option,
50e0dac50fSopenharmony_ci        const sptr<IRemoteObject>& displayManagerAgent) override;
51e0dac50fSopenharmony_ci    DMError DestroyVirtualScreen(ScreenId screenId) override;
52e0dac50fSopenharmony_ci    DMError SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface) override;
53e0dac50fSopenharmony_ci    DMError IsScreenRotationLocked(bool& isLocked) override;
54e0dac50fSopenharmony_ci    DMError SetScreenRotationLocked(bool isLocked) override;
55e0dac50fSopenharmony_ci    DMError SetScreenRotationLockedFromJs(bool isLocked) override;
56e0dac50fSopenharmony_ci
57e0dac50fSopenharmony_ci    sptr<DisplayInfo> GetDefaultDisplayInfo() override;
58e0dac50fSopenharmony_ci    sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
59e0dac50fSopenharmony_ci    sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) override;
60e0dac50fSopenharmony_ci    sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId) override;
61e0dac50fSopenharmony_ci    DMError SetOrientation(ScreenId screenId, Orientation orientation) override;
62e0dac50fSopenharmony_ci    DMError SetOrientationFromWindow(ScreenId screenId, Orientation orientation, bool withAnimation);
63e0dac50fSopenharmony_ci    bool SetRotationFromWindow(ScreenId screenId, Rotation targetRotation, bool withAnimation);
64e0dac50fSopenharmony_ci    void SetGravitySensorSubscriptionEnabled();
65e0dac50fSopenharmony_ci    std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode) override;
66e0dac50fSopenharmony_ci    DMError HasPrivateWindow(DisplayId id, bool& hasPrivateWindow) override;
67e0dac50fSopenharmony_ci    // colorspace, gamut
68e0dac50fSopenharmony_ci    DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) override;
69e0dac50fSopenharmony_ci    DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut) override;
70e0dac50fSopenharmony_ci    DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx) override;
71e0dac50fSopenharmony_ci    DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap) override;
72e0dac50fSopenharmony_ci    DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap) override;
73e0dac50fSopenharmony_ci    DMError SetScreenColorTransform(ScreenId screenId) override;
74e0dac50fSopenharmony_ci
75e0dac50fSopenharmony_ci    DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
76e0dac50fSopenharmony_ci        DisplayManagerAgentType type) override;
77e0dac50fSopenharmony_ci    DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
78e0dac50fSopenharmony_ci        DisplayManagerAgentType type) override;
79e0dac50fSopenharmony_ci    bool WakeUpBegin(PowerStateChangeReason reason) override;
80e0dac50fSopenharmony_ci    bool WakeUpEnd() override;
81e0dac50fSopenharmony_ci    bool SuspendBegin(PowerStateChangeReason reason) override;
82e0dac50fSopenharmony_ci    bool SuspendEnd() override;
83e0dac50fSopenharmony_ci    bool SetSpecifiedScreenPower(ScreenId, ScreenPowerState, PowerStateChangeReason) override;
84e0dac50fSopenharmony_ci    bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason) override;
85e0dac50fSopenharmony_ci    ScreenPowerState GetScreenPower(ScreenId dmsScreenId) override;
86e0dac50fSopenharmony_ci    bool SetDisplayState(DisplayState state) override;
87e0dac50fSopenharmony_ci    void UpdateRSTree(DisplayId displayId, DisplayId parentDisplayId, std::shared_ptr<RSSurfaceNode>& surfaceNode,
88e0dac50fSopenharmony_ci        bool isAdd, bool isMultiDisplay);
89e0dac50fSopenharmony_ci    DMError AddSurfaceNodeToDisplay(DisplayId displayId,
90e0dac50fSopenharmony_ci        std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop = true) override;
91e0dac50fSopenharmony_ci    DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode) override;
92e0dac50fSopenharmony_ci    DisplayState GetDisplayState(DisplayId displayId) override;
93e0dac50fSopenharmony_ci    bool TryToCancelScreenOff() override;
94e0dac50fSopenharmony_ci    bool SetScreenBrightness(uint64_t screenId, uint32_t level) override;
95e0dac50fSopenharmony_ci    uint32_t GetScreenBrightness(uint64_t screenId) override;
96e0dac50fSopenharmony_ci    void NotifyDisplayEvent(DisplayEvent event) override;
97e0dac50fSopenharmony_ci    bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze) override;
98e0dac50fSopenharmony_ci
99e0dac50fSopenharmony_ci    DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds, ScreenId& screenGroupId) override;
100e0dac50fSopenharmony_ci    DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoints,
101e0dac50fSopenharmony_ci        ScreenId& screenGroupId) override;
102e0dac50fSopenharmony_ci    DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds) override;
103e0dac50fSopenharmony_ci    DMError StopExpand(const std::vector<ScreenId>& expandScreenIds) override;
104e0dac50fSopenharmony_ci    void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens) override;
105e0dac50fSopenharmony_ci    sptr<ScreenInfo> GetScreenInfoById(ScreenId screenId) override;
106e0dac50fSopenharmony_ci    sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId) override;
107e0dac50fSopenharmony_ci    ScreenId GetScreenGroupIdByScreenId(ScreenId screenId);
108e0dac50fSopenharmony_ci    DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos) override;
109e0dac50fSopenharmony_ci
110e0dac50fSopenharmony_ci    std::vector<DisplayId> GetAllDisplayIds() override;
111e0dac50fSopenharmony_ci    DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override;
112e0dac50fSopenharmony_ci    DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override;
113e0dac50fSopenharmony_ci    DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height,
114e0dac50fSopenharmony_ci        float virtualPixelRatio) override { return DMError::DM_OK; }
115e0dac50fSopenharmony_ci    DMError GetDensityInCurResolution(ScreenId screenId,
116e0dac50fSopenharmony_ci        float& virtualPixelRatio) override { return DMError::DM_OK; }
117e0dac50fSopenharmony_ci    void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
118e0dac50fSopenharmony_ci    void RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener);
119e0dac50fSopenharmony_ci    void NotifyPrivateWindowStateChanged(bool hasPrivate);
120e0dac50fSopenharmony_ci    std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution() override;
121e0dac50fSopenharmony_ci
122e0dac50fSopenharmony_ciprivate:
123e0dac50fSopenharmony_ci    DisplayManagerService();
124e0dac50fSopenharmony_ci    ~DisplayManagerService() = default;
125e0dac50fSopenharmony_ci    bool Init();
126e0dac50fSopenharmony_ci    void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
127e0dac50fSopenharmony_ci        const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
128e0dac50fSopenharmony_ci    void NotifyScreenshot(DisplayId displayId);
129e0dac50fSopenharmony_ci    ScreenId GetScreenIdByDisplayId(DisplayId displayId) const;
130e0dac50fSopenharmony_ci    void ConfigureDisplayManagerService();
131e0dac50fSopenharmony_ci    void ConfigureWaterfallDisplayCompressionParams();
132e0dac50fSopenharmony_ci
133e0dac50fSopenharmony_ci    std::recursive_mutex mutex_;
134e0dac50fSopenharmony_ci    static inline SingletonDelegator<DisplayManagerService> delegator_;
135e0dac50fSopenharmony_ci    sptr<AbstractDisplayController> abstractDisplayController_;
136e0dac50fSopenharmony_ci    sptr<AbstractScreenController> abstractScreenController_;
137e0dac50fSopenharmony_ci    sptr<DisplayPowerController> displayPowerController_;
138e0dac50fSopenharmony_ci    sptr<DisplayCutoutController> displayCutoutController_;
139e0dac50fSopenharmony_ci    sptr<IDisplayChangeListener> displayChangeListener_;
140e0dac50fSopenharmony_ci    sptr<IWindowInfoQueriedListener> windowInfoQueriedListener_;
141e0dac50fSopenharmony_ci    sptr<DisplayDumper> displayDumper_;
142e0dac50fSopenharmony_ci    AtomicMap<ScreenId, uint32_t> accessTokenIdMaps_;
143e0dac50fSopenharmony_ci    bool isAutoRotationOpen_;
144e0dac50fSopenharmony_ci    std::vector<DisplayPhysicalResolution> allDisplayPhysicalResolution_ {};
145e0dac50fSopenharmony_ci};
146e0dac50fSopenharmony_ci} // namespace OHOS::Rosen
147e0dac50fSopenharmony_ci
148e0dac50fSopenharmony_ci#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H