• 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 DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
35         DisplayManagerAgentType type);
36     virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
37         DisplayManagerAgentType type);
38     virtual void Clear();
39 protected:
40     bool InitDMSProxy();
41     bool InitSMSProxy();
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 HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
64     virtual bool WakeUpBegin(PowerStateChangeReason reason);
65     virtual bool WakeUpEnd();
66     virtual bool SuspendBegin(PowerStateChangeReason reason);
67     virtual bool SuspendEnd();
68     virtual bool SetDisplayState(DisplayState state);
69     virtual DisplayState GetDisplayState(DisplayId displayId);
70     virtual void NotifyDisplayEvent(DisplayEvent event);
71     virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze);
72     virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId);
73     virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId);
74     virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode);
75     virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId,
76         std::shared_ptr<class RSSurfaceNode>& surfaceNode);
77 
78     virtual bool IsFoldable();
79 
80     virtual FoldStatus GetFoldStatus();
81 
82     virtual FoldDisplayMode GetFoldDisplayMode();
83 
84     virtual void SetFoldDisplayMode(const FoldDisplayMode);
85 
86     virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion();
87 private:
88     static inline SingletonDelegator<DisplayManagerAdapter> delegator;
89 };
90 
91 class ScreenManagerAdapter : public BaseAdapter {
92 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter);
93 public:
94     virtual ScreenId CreateVirtualScreen(VirtualScreenOption option,
95         const sptr<IDisplayManagerAgent>& displayManagerAgent);
96     virtual DMError DestroyVirtualScreen(ScreenId screenId);
97     virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
98     virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason);
99     virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId);
100     virtual DMError SetOrientation(ScreenId screenId, Orientation orientation);
101     virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId);
102     virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos);
103     virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId);
104     virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId);
105     virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds);
106     virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds);
107     virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>);
108     virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
109     virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId);
110     virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio);
111     virtual DMError SetScreenRotationLocked(bool isLocked);
112     virtual DMError IsScreenRotationLocked(bool& isLocked);
113 
114     // colorspace, gamut
115     virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts);
116     virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut);
117     virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx);
118     virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap);
119     virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap);
120     virtual DMError SetScreenColorTransform(ScreenId screenId);
121 private:
122     static inline SingletonDelegator<ScreenManagerAdapter> delegator;
123 };
124 } // namespace OHOS::Rosen
125 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H
126