• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H
17 #define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <surface.h>
22 
23 #include "display.h"
24 #include "screen.h"
25 #include "screen_group.h"
26 #include "dm_common.h"
27 #include "display_manager_interface.h"
28 #include "fold_screen_info.h"
29 #include "singleton_delegator.h"
30 
31 namespace OHOS::Rosen {
32 class BaseAdapter {
33 public:
34     virtual ~BaseAdapter();
35     virtual DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
36         DisplayManagerAgentType type);
37     virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
38         DisplayManagerAgentType type);
39     virtual void Clear();
40 protected:
41     bool InitDMSProxy();
42     std::recursive_mutex mutex_;
43     sptr<IDisplayManager> displayManagerServiceProxy_ = nullptr;
44     sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr;
45     bool isProxyValid_ { false };
46 };
47 
48 class DMSDeathRecipient : public IRemoteObject::DeathRecipient {
49 public:
50     explicit DMSDeathRecipient(BaseAdapter& adapter);
51     virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
52 private:
53     BaseAdapter& adapter_;
54 };
55 
56 class DisplayManagerAdapter : public BaseAdapter {
57 WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter);
58 public:
59     virtual sptr<DisplayInfo> GetDefaultDisplayInfo();
60     virtual sptr<DisplayInfo> GetDisplayInfoByScreenId(ScreenId screenId);
61     virtual std::vector<DisplayId> GetAllDisplayIds();
62     virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode = nullptr);
63     virtual DMError HasImmersiveWindow(bool& immersive);
64     virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
65     virtual bool WakeUpBegin(PowerStateChangeReason reason);
66     virtual bool WakeUpEnd();
67     virtual bool SuspendBegin(PowerStateChangeReason reason);
68     virtual bool SuspendEnd();
69     virtual bool SetDisplayState(DisplayState state);
70     virtual DisplayState GetDisplayState(DisplayId displayId);
71     virtual void NotifyDisplayEvent(DisplayEvent event);
72     virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze);
73     virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId);
74     virtual DMError GetAvailableArea(DisplayId displayId, DMRect& area);
75     virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId);
76     virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode);
77     virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId,
78         std::shared_ptr<class RSSurfaceNode>& surfaceNode);
79     virtual bool ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId);
80     virtual bool IsFoldable();
81 
82     virtual FoldStatus GetFoldStatus();
83 
84     virtual FoldDisplayMode GetFoldDisplayMode();
85 
86     virtual void SetFoldDisplayMode(const FoldDisplayMode);
87 
88     virtual void SetFoldStatusLocked(bool locked);
89 
90     virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion();
91 private:
92     static inline SingletonDelegator<DisplayManagerAdapter> delegator;
93 };
94 
95 class ScreenManagerAdapter : public BaseAdapter {
96 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter);
97 public:
98     virtual ScreenId CreateVirtualScreen(VirtualScreenOption option,
99         const sptr<IDisplayManagerAgent>& displayManagerAgent);
100     virtual DMError DestroyVirtualScreen(ScreenId screenId);
101     virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
102     virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation);
103     virtual bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason);
104     virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason);
105     virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId);
106     virtual DMError SetOrientation(ScreenId screenId, Orientation orientation);
107     virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId);
108     virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos);
109     virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId);
110     virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId);
111     virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds);
112     virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds);
113     virtual DMError DisableMirror(bool disableOrNot);
114     virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>);
115     virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
116     virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId);
117     virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio);
118     virtual DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio);
119     virtual DMError GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio);
120     virtual DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height);
121     virtual DMError SetScreenRotationLocked(bool isLocked);
122     virtual DMError IsScreenRotationLocked(bool& isLocked);
123 
124     // colorspace, gamut
125     virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts);
126     virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut);
127     virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx);
128     virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap);
129     virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap);
130     virtual DMError SetScreenColorTransform(ScreenId screenId);
131 
132     virtual DMError GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat);
133     virtual DMError SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat);
134     virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<ScreenHDRFormat>& hdrFormats);
135     virtual DMError GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat);
136     virtual DMError SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx);
137     virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
138     virtual DMError GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace);
139     virtual DMError SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace);
140     virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<uint32_t>& hdrFormats);
141     virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<uint32_t>& colorSpaces);
142 
143     // unique screen
144     virtual DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds);
145 private:
146     static inline SingletonDelegator<ScreenManagerAdapter> delegator;
147 };
148 } // namespace OHOS::Rosen
149 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H
150