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