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); 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 virtual void DisablePowerOffRenderControl(ScreenId screenId); 97 virtual std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution(); 98 virtual DMError SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid, 99 std::vector<uint64_t>& windowIdList); 100 virtual std::shared_ptr<Media::PixelMap> GetScreenCapture(const CaptureOption& captureOption, 101 DmErrorCode* errorCode = nullptr); 102 virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshotWithOption(const CaptureOption& captureOption, 103 DmErrorCode* errorCode = nullptr); 104 virtual sptr<DisplayInfo> GetPrimaryDisplayInfo(); 105 106 private: 107 static inline SingletonDelegator<DisplayManagerAdapter> delegator; 108 }; 109 110 class ScreenManagerAdapter : public BaseAdapter { 111 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter); 112 public: 113 virtual ScreenId CreateVirtualScreen(VirtualScreenOption option, 114 const sptr<IDisplayManagerAgent>& displayManagerAgent); 115 virtual DMError DestroyVirtualScreen(ScreenId screenId); 116 virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 117 virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation); 118 virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode); 119 virtual bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 120 virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 121 virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId); 122 virtual DMError SetOrientation(ScreenId screenId, Orientation orientation); 123 virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId); 124 virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos); 125 virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId); 126 virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId); 127 virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds); 128 virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds); 129 virtual DMError DisableMirror(bool disableOrNot); 130 virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>); 131 virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 132 virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId); 133 virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); 134 virtual DMError SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio); 135 virtual DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio); 136 virtual DMError GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio); 137 virtual DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height); 138 virtual DMError SetScreenRotationLocked(bool isLocked); 139 virtual DMError SetScreenRotationLockedFromJs(bool isLocked); 140 virtual DMError IsScreenRotationLocked(bool& isLocked); 141 // colorspace, gamut 142 virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 143 virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 144 virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 145 virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 146 virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 147 virtual DMError SetScreenColorTransform(ScreenId screenId); 148 virtual DMError GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat); 149 virtual DMError SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat); 150 virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<ScreenHDRFormat>& hdrFormats); 151 virtual DMError GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat); 152 virtual DMError SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx); 153 virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<GraphicCM_ColorSpaceType>& colorSpaces); 154 virtual DMError GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace); 155 virtual DMError SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace); 156 virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<uint32_t>& hdrFormats); 157 virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<uint32_t>& colorSpaces); 158 // unique screen 159 virtual DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds); 160 virtual VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId); 161 virtual DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag); 162 virtual DMError SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval); 163 virtual DMError SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate, 164 uint32_t& actualRefreshRate); 165 private: 166 static inline SingletonDelegator<ScreenManagerAdapter> delegator; 167 }; 168 } // namespace OHOS::Rosen 169 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H 170