• 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,
63         DmErrorCode* errorCode = nullptr, bool isUseDma = false);
64     virtual std::shared_ptr<Media::PixelMap> GetSnapshotByPicker(Media::Rect &rect, DmErrorCode* errorCode = nullptr);
65     virtual DMError HasImmersiveWindow(ScreenId screenId, bool& immersive);
66     virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
67     virtual bool WakeUpBegin(PowerStateChangeReason reason);
68     virtual bool WakeUpEnd();
69     virtual bool SuspendBegin(PowerStateChangeReason reason);
70     virtual bool SuspendEnd();
71     virtual ScreenId GetInternalScreenId();
72     virtual bool SetScreenPowerById(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason);
73     virtual bool SetDisplayState(DisplayState state);
74     virtual DisplayState GetDisplayState(DisplayId displayId);
75     virtual bool TryToCancelScreenOff();
76     virtual void NotifyDisplayEvent(DisplayEvent event);
77     virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze);
78     virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId);
79     virtual sptr<DisplayInfo> GetVisibleAreaDisplayInfoById(DisplayId displayId);
80     virtual DMError GetExpandAvailableArea(DisplayId displayId, DMRect& area);
81     virtual DMError GetAvailableArea(DisplayId displayId, DMRect& area);
82     virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId);
83     virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode);
84     virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId,
85         std::shared_ptr<class RSSurfaceNode>& surfaceNode);
86     virtual bool ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId);
87     virtual bool IsFoldable();
88     virtual bool IsCaptured();
89     virtual FoldStatus GetFoldStatus();
90     virtual FoldDisplayMode GetFoldDisplayMode();
91     virtual void SetFoldDisplayMode(const FoldDisplayMode);
92     virtual DMError SetFoldDisplayModeFromJs(const FoldDisplayMode, std::string reason = "");
93     virtual void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY);
94     virtual void SetFoldStatusLocked(bool locked);
95     virtual DMError SetFoldStatusLockedFromJs(bool locked);
96     virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion();
97     virtual void SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList,
98         std::vector<uint64_t> surfaceIdList = {});
99     virtual void SetVirtualDisplayMuteFlag(ScreenId screenId, bool muteFlag);
100     virtual void DisablePowerOffRenderControl(ScreenId screenId);
101     virtual DMError ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy);
102     virtual DMError ResetAllFreezeStatus();
103     virtual std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution();
104     virtual DMError GetDisplayCapability(std::string& capabilitInfo);
105     virtual DMError SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid,
106         std::vector<uint64_t>& windowIdList);
107     virtual std::shared_ptr<Media::PixelMap> GetScreenCapture(const CaptureOption& captureOption,
108         DmErrorCode* errorCode = nullptr);
109     virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshotWithOption(const CaptureOption& captureOption,
110         DmErrorCode* errorCode = nullptr);
111     virtual sptr<DisplayInfo> GetPrimaryDisplayInfo();
112 
113 private:
114     static inline SingletonDelegator<DisplayManagerAdapter> delegator;
115 };
116 
117 class ScreenManagerAdapter : public BaseAdapter {
118 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter);
119 public:
120     virtual ScreenId CreateVirtualScreen(VirtualScreenOption option,
121         const sptr<IDisplayManagerAgent>& displayManagerAgent);
122     virtual DMError DestroyVirtualScreen(ScreenId screenId);
123     virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
124     virtual DMError AddVirtualScreenBlockList(const std::vector<int32_t>& persistentIds);
125     virtual DMError RemoveVirtualScreenBlockList(const std::vector<int32_t>& persistentIds);
126     virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId,
127         const std::shared_ptr<Media::PixelMap>& privacyMaskImg);
128     virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation);
129     virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode);
130     virtual bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason);
131     virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason);
132     virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId);
133     virtual DMError SetOrientation(ScreenId screenId, Orientation orientation);
134     virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId);
135     virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos);
136     virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId);
137     virtual DMError MakeMirrorForRecord(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId,
138         ScreenId& screenGroupId);
139     virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, DMRect mainScreenRegion,
140                 ScreenId& screenGroupId);
141     virtual DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId,
142         MultiScreenMode screenMode);
143     virtual DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions,
144         MultiScreenPositionOptions secondScreenOption);
145     virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId);
146     virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds);
147     virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds);
148     virtual DMError DisableMirror(bool disableOrNot);
149     virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>);
150     virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
151     virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId);
152     virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio);
153     virtual DMError SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio);
154     virtual DMError SetDefaultDensityDpi(ScreenId screenId, float virtualPixelRatio);
155     virtual DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio);
156     virtual DMError GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio);
157     virtual DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height);
158     virtual DMError SetScreenRotationLocked(bool isLocked);
159     virtual DMError SetScreenRotationLockedFromJs(bool isLocked);
160     virtual DMError IsScreenRotationLocked(bool& isLocked);
161     // colorspace, gamut
162     virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts);
163     virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut);
164     virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx);
165     virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap);
166     virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap);
167     virtual DMError SetScreenColorTransform(ScreenId screenId);
168     virtual DMError GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat);
169     virtual DMError SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat);
170     virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<ScreenHDRFormat>& hdrFormats);
171     virtual DMError GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat);
172     virtual DMError SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx);
173     virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
174     virtual DMError GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace);
175     virtual DMError SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace);
176     virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<uint32_t>& hdrFormats);
177     virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<uint32_t>& colorSpaces);
178     // unique screen
179     virtual DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds, std::vector<DisplayId>& displayIds);
180     virtual VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId);
181     virtual DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag);
182     virtual DMError SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval);
183     virtual bool SetVirtualScreenStatus(ScreenId screenId, VirtualScreenStatus screenStatus);
184     virtual DMError SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate,
185         uint32_t& actualRefreshRate);
186     virtual ScreenPowerState GetScreenPower();
187     virtual DMError SetScreenSkipProtectedWindow(const std::vector<ScreenId>& screenIds, bool isEnable);
188 private:
189     static inline SingletonDelegator<ScreenManagerAdapter> delegator;
190 };
191 } // namespace OHOS::Rosen
192 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H
193