1 /* 2 * Copyright (c) 2021-2025 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 <mutex> 20 #include <surface.h> 21 22 #include "display.h" 23 #include "dm_common.h" 24 #include "fold_screen_info.h" 25 #include "idisplay_manager.h" 26 #include "screen.h" 27 #include "screen_group.h" 28 #include "singleton_delegator.h" 29 #include "zidl/idisplay_manager_agent.h" 30 #include "zidl/screen_session_manager_interface.h" 31 32 namespace OHOS::Rosen { 33 class BaseAdapter { 34 public: 35 virtual ~BaseAdapter(); 36 virtual DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 37 DisplayManagerAgentType type); 38 virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 39 DisplayManagerAgentType type); 40 virtual void Clear(); 41 protected: 42 bool InitDMSProxy(); 43 std::recursive_mutex mutex_; 44 sptr<IScreenSessionManager> screenSessionManagerServiceProxy_ = nullptr; 45 sptr<IDisplayManager> displayManagerServiceProxy_ = nullptr; 46 sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr; 47 bool isProxyValid_ = false; 48 static inline DMError ConvertToDMError(ErrCode errCode, int32_t dmError); 49 }; 50 51 class DMSDeathRecipient : public IRemoteObject::DeathRecipient { 52 public: 53 explicit DMSDeathRecipient(BaseAdapter& adapter); 54 virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 55 private: 56 BaseAdapter& adapter_; 57 }; 58 59 class DisplayManagerAdapter : public BaseAdapter { 60 WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter); 61 public: 62 virtual sptr<DisplayInfo> GetDefaultDisplayInfo(); 63 virtual sptr<DisplayInfo> GetDisplayInfoByScreenId(ScreenId screenId); 64 virtual std::vector<DisplayId> GetAllDisplayIds(); 65 virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId, 66 DmErrorCode* errorCode = nullptr, bool isUseDma = false, bool isCaptureFullOfScreen = false); 67 virtual std::vector<std::shared_ptr<Media::PixelMap>> GetDisplayHDRSnapshot(DisplayId displayId, 68 DmErrorCode& errorCode, bool isUseDma = false, bool isCaptureFullOfScreen = false); 69 virtual std::shared_ptr<Media::PixelMap> GetSnapshotByPicker(Media::Rect &rect, DmErrorCode* errorCode = nullptr); 70 virtual DMError HasImmersiveWindow(ScreenId screenId, bool& immersive); 71 virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow); 72 virtual bool WakeUpBegin(PowerStateChangeReason reason); 73 virtual bool WakeUpEnd(); 74 virtual bool SuspendBegin(PowerStateChangeReason reason); 75 virtual bool SuspendEnd(); 76 virtual ScreenId GetInternalScreenId(); 77 virtual bool SetScreenPowerById(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 78 virtual bool SetDisplayState(DisplayState state); 79 virtual DisplayState GetDisplayState(DisplayId displayId); 80 virtual bool TryToCancelScreenOff(); 81 virtual void NotifyDisplayEvent(DisplayEvent event); 82 virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze); 83 virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId); 84 virtual sptr<DisplayInfo> GetVisibleAreaDisplayInfoById(DisplayId displayId); 85 virtual DMError GetExpandAvailableArea(DisplayId displayId, DMRect& area); 86 virtual DMError GetAvailableArea(DisplayId displayId, DMRect& area); 87 virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId, int32_t width, int32_t height, Rotation rotation); 88 virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode); 89 virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, 90 std::shared_ptr<class RSSurfaceNode>& surfaceNode); 91 virtual bool ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId); 92 virtual bool IsFoldable(); 93 virtual bool IsCaptured(); 94 virtual FoldStatus GetFoldStatus(); 95 virtual FoldDisplayMode GetFoldDisplayMode(); 96 virtual void SetFoldDisplayMode(const FoldDisplayMode); 97 virtual void SetFoldDisplayModeAsync(const FoldDisplayMode); 98 virtual DMError SetFoldDisplayModeFromJs(const FoldDisplayMode, std::string reason = ""); 99 virtual void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY); 100 virtual void SetFoldStatusLocked(bool locked); 101 virtual DMError SetFoldStatusLockedFromJs(bool locked); 102 virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion(); 103 virtual DMError GetLiveCreaseRegion(FoldCreaseRegion& region); 104 virtual void SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList, 105 std::vector<uint64_t> surfaceIdList = {}, std::vector<uint8_t> typeBlackList = {}); 106 virtual void SetVirtualDisplayMuteFlag(ScreenId screenId, bool muteFlag); 107 virtual void DisablePowerOffRenderControl(ScreenId screenId); 108 virtual DMError ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy); 109 virtual DMError ResetAllFreezeStatus(); 110 virtual std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution(); 111 virtual DMError GetDisplayCapability(std::string& capabilitInfo); 112 virtual DMError SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid, 113 std::vector<uint64_t>& windowIdList); 114 virtual std::shared_ptr<Media::PixelMap> GetScreenCapture(const CaptureOption& captureOption, 115 DmErrorCode* errorCode = nullptr); 116 virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshotWithOption(const CaptureOption& captureOption, 117 DmErrorCode* errorCode = nullptr); 118 virtual std::vector<std::shared_ptr<Media::PixelMap>> GetDisplayHDRSnapshotWithOption( 119 const CaptureOption& captureOption, DmErrorCode& errorCode); 120 virtual sptr<DisplayInfo> GetPrimaryDisplayInfo(); 121 virtual DMError GetScreenAreaOfDisplayArea(DisplayId displayId, const DMRect& displayArea, 122 ScreenId& screenId, DMRect& screenArea); 123 virtual bool SetVirtualScreenAsDefault(ScreenId screenId); 124 125 private: 126 static inline SingletonDelegator<DisplayManagerAdapter> delegator; 127 }; 128 129 class ScreenManagerAdapter : public BaseAdapter { 130 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter); 131 public: 132 virtual ScreenId CreateVirtualScreen(VirtualScreenOption option, 133 const sptr<IDisplayManagerAgent>& displayManagerAgent); 134 virtual DMError DestroyVirtualScreen(ScreenId screenId); 135 virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 136 virtual DMError AddVirtualScreenBlockList(const std::vector<int32_t>& persistentIds); 137 virtual DMError RemoveVirtualScreenBlockList(const std::vector<int32_t>& persistentIds); 138 virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId, 139 const std::shared_ptr<Media::PixelMap>& privacyMaskImg); 140 virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation); 141 virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode); 142 virtual bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 143 virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 144 virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId); 145 virtual DMError SetOrientation(ScreenId screenId, Orientation orientation); 146 virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId); 147 virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos); 148 virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId); 149 virtual DMError MakeMirrorForRecord(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, 150 ScreenId& screenGroupId); 151 virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, DMRect mainScreenRegion, 152 ScreenId& screenGroupId); 153 virtual DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId, 154 MultiScreenMode screenMode); 155 virtual DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions, 156 MultiScreenPositionOptions secondScreenOption); 157 virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId); 158 virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds); 159 virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds); 160 virtual DMError DisableMirror(bool disableOrNot); 161 virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>); 162 virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 163 virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId); 164 virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); 165 virtual DMError SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio); 166 virtual DMError SetDefaultDensityDpi(ScreenId screenId, float virtualPixelRatio); 167 virtual DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio); 168 virtual DMError GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio); 169 virtual DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height); 170 virtual DMError SetScreenRotationLocked(bool isLocked); 171 virtual DMError SetScreenRotationLockedFromJs(bool isLocked); 172 virtual DMError IsScreenRotationLocked(bool& isLocked); 173 // colorspace, gamut 174 virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 175 virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 176 virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 177 virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 178 virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 179 virtual DMError SetScreenColorTransform(ScreenId screenId); 180 virtual DMError GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat); 181 virtual DMError SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat); 182 virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<ScreenHDRFormat>& hdrFormats); 183 virtual DMError GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat); 184 virtual DMError SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx); 185 virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<GraphicCM_ColorSpaceType>& colorSpaces); 186 virtual DMError GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace); 187 virtual DMError SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace); 188 virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<uint32_t>& hdrFormats); 189 virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<uint32_t>& colorSpaces); 190 // unique screen 191 virtual DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds, std::vector<DisplayId>& displayIds); 192 virtual VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId); 193 virtual DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag); 194 virtual DMError SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval); 195 virtual bool SetVirtualScreenStatus(ScreenId screenId, VirtualScreenStatus screenStatus); 196 virtual DMError SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate, 197 uint32_t& actualRefreshRate); 198 virtual ScreenPowerState GetScreenPower(); 199 virtual void SetFoldStatusExpandAndLocked(bool locked); 200 virtual DMError SetScreenSkipProtectedWindow(const std::vector<ScreenId>& screenIds, bool isEnable); 201 virtual DMError SetVirtualScreenAutoRotation(ScreenId screenId, bool enable); 202 virtual DMError SetScreenPrivacyWindowTagSwitch(ScreenId screenId, const std::vector<std::string>& privacyWindowTag, 203 bool enable); 204 private: 205 static inline SingletonDelegator<ScreenManagerAdapter> delegator; 206 }; 207 } // namespace OHOS::Rosen 208 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H 209