1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H 17e0dac50fSopenharmony_ci#define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <map> 20e0dac50fSopenharmony_ci#include <mutex> 21e0dac50fSopenharmony_ci#include <surface.h> 22e0dac50fSopenharmony_ci 23e0dac50fSopenharmony_ci#include "display.h" 24e0dac50fSopenharmony_ci#include "screen.h" 25e0dac50fSopenharmony_ci#include "screen_group.h" 26e0dac50fSopenharmony_ci#include "dm_common.h" 27e0dac50fSopenharmony_ci#include "display_manager_interface.h" 28e0dac50fSopenharmony_ci#include "fold_screen_info.h" 29e0dac50fSopenharmony_ci#include "singleton_delegator.h" 30e0dac50fSopenharmony_ci 31e0dac50fSopenharmony_cinamespace OHOS::Rosen { 32e0dac50fSopenharmony_ciclass BaseAdapter { 33e0dac50fSopenharmony_cipublic: 34e0dac50fSopenharmony_ci virtual ~BaseAdapter(); 35e0dac50fSopenharmony_ci virtual DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 36e0dac50fSopenharmony_ci DisplayManagerAgentType type); 37e0dac50fSopenharmony_ci virtual DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 38e0dac50fSopenharmony_ci DisplayManagerAgentType type); 39e0dac50fSopenharmony_ci virtual void Clear(); 40e0dac50fSopenharmony_ciprotected: 41e0dac50fSopenharmony_ci bool InitDMSProxy(); 42e0dac50fSopenharmony_ci std::recursive_mutex mutex_; 43e0dac50fSopenharmony_ci sptr<IDisplayManager> displayManagerServiceProxy_ = nullptr; 44e0dac50fSopenharmony_ci sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr; 45e0dac50fSopenharmony_ci bool isProxyValid_ { false }; 46e0dac50fSopenharmony_ci}; 47e0dac50fSopenharmony_ci 48e0dac50fSopenharmony_ciclass DMSDeathRecipient : public IRemoteObject::DeathRecipient { 49e0dac50fSopenharmony_cipublic: 50e0dac50fSopenharmony_ci explicit DMSDeathRecipient(BaseAdapter& adapter); 51e0dac50fSopenharmony_ci virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 52e0dac50fSopenharmony_ciprivate: 53e0dac50fSopenharmony_ci BaseAdapter& adapter_; 54e0dac50fSopenharmony_ci}; 55e0dac50fSopenharmony_ci 56e0dac50fSopenharmony_ciclass DisplayManagerAdapter : public BaseAdapter { 57e0dac50fSopenharmony_ciWM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter); 58e0dac50fSopenharmony_cipublic: 59e0dac50fSopenharmony_ci virtual sptr<DisplayInfo> GetDefaultDisplayInfo(); 60e0dac50fSopenharmony_ci virtual sptr<DisplayInfo> GetDisplayInfoByScreenId(ScreenId screenId); 61e0dac50fSopenharmony_ci virtual std::vector<DisplayId> GetAllDisplayIds(); 62e0dac50fSopenharmony_ci virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId, DmErrorCode* errorCode = nullptr); 63e0dac50fSopenharmony_ci virtual std::shared_ptr<Media::PixelMap> GetSnapshotByPicker(Media::Rect &rect, DmErrorCode* errorCode = nullptr); 64e0dac50fSopenharmony_ci virtual DMError HasImmersiveWindow(ScreenId screenId, bool& immersive); 65e0dac50fSopenharmony_ci virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow); 66e0dac50fSopenharmony_ci virtual bool WakeUpBegin(PowerStateChangeReason reason); 67e0dac50fSopenharmony_ci virtual bool WakeUpEnd(); 68e0dac50fSopenharmony_ci virtual bool SuspendBegin(PowerStateChangeReason reason); 69e0dac50fSopenharmony_ci virtual bool SuspendEnd(); 70e0dac50fSopenharmony_ci virtual ScreenId GetInternalScreenId(); 71e0dac50fSopenharmony_ci virtual bool SetScreenPowerById(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 72e0dac50fSopenharmony_ci virtual bool SetDisplayState(DisplayState state); 73e0dac50fSopenharmony_ci virtual DisplayState GetDisplayState(DisplayId displayId); 74e0dac50fSopenharmony_ci virtual bool TryToCancelScreenOff(); 75e0dac50fSopenharmony_ci virtual void NotifyDisplayEvent(DisplayEvent event); 76e0dac50fSopenharmony_ci virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze); 77e0dac50fSopenharmony_ci virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId); 78e0dac50fSopenharmony_ci virtual DMError GetAvailableArea(DisplayId displayId, DMRect& area); 79e0dac50fSopenharmony_ci virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId); 80e0dac50fSopenharmony_ci virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode); 81e0dac50fSopenharmony_ci virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, 82e0dac50fSopenharmony_ci std::shared_ptr<class RSSurfaceNode>& surfaceNode); 83e0dac50fSopenharmony_ci virtual bool ConvertScreenIdToRsScreenId(ScreenId screenId, ScreenId& rsScreenId); 84e0dac50fSopenharmony_ci virtual bool IsFoldable(); 85e0dac50fSopenharmony_ci virtual bool IsCaptured(); 86e0dac50fSopenharmony_ci virtual FoldStatus GetFoldStatus(); 87e0dac50fSopenharmony_ci virtual FoldDisplayMode GetFoldDisplayMode(); 88e0dac50fSopenharmony_ci virtual void SetFoldDisplayMode(const FoldDisplayMode); 89e0dac50fSopenharmony_ci virtual DMError SetFoldDisplayModeFromJs(const FoldDisplayMode); 90e0dac50fSopenharmony_ci virtual void SetDisplayScale(ScreenId screenId, float scaleX, float scaleY, float pivotX, float pivotY); 91e0dac50fSopenharmony_ci virtual void SetFoldStatusLocked(bool locked); 92e0dac50fSopenharmony_ci virtual DMError SetFoldStatusLockedFromJs(bool locked); 93e0dac50fSopenharmony_ci virtual sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion(); 94e0dac50fSopenharmony_ci virtual void SetVirtualScreenBlackList(ScreenId screenId, std::vector<uint64_t>& windowIdList); 95e0dac50fSopenharmony_ci virtual void DisablePowerOffRenderControl(ScreenId screenId); 96e0dac50fSopenharmony_ci virtual DMError ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy); 97e0dac50fSopenharmony_ci virtual DMError ResetAllFreezeStatus(); 98e0dac50fSopenharmony_ci virtual std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution(); 99e0dac50fSopenharmony_ci virtual DMError SetVirtualScreenSecurityExemption(ScreenId screenId, uint32_t pid, 100e0dac50fSopenharmony_ci std::vector<uint64_t>& windowIdList); 101e0dac50fSopenharmony_ci 102e0dac50fSopenharmony_ciprivate: 103e0dac50fSopenharmony_ci static inline SingletonDelegator<DisplayManagerAdapter> delegator; 104e0dac50fSopenharmony_ci}; 105e0dac50fSopenharmony_ci 106e0dac50fSopenharmony_ciclass ScreenManagerAdapter : public BaseAdapter { 107e0dac50fSopenharmony_ciWM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter); 108e0dac50fSopenharmony_cipublic: 109e0dac50fSopenharmony_ci virtual ScreenId CreateVirtualScreen(VirtualScreenOption option, 110e0dac50fSopenharmony_ci const sptr<IDisplayManagerAgent>& displayManagerAgent); 111e0dac50fSopenharmony_ci virtual DMError DestroyVirtualScreen(ScreenId screenId); 112e0dac50fSopenharmony_ci virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 113e0dac50fSopenharmony_ci virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation); 114e0dac50fSopenharmony_ci virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode); 115e0dac50fSopenharmony_ci virtual bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 116e0dac50fSopenharmony_ci virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 117e0dac50fSopenharmony_ci virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId); 118e0dac50fSopenharmony_ci virtual DMError SetOrientation(ScreenId screenId, Orientation orientation); 119e0dac50fSopenharmony_ci virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId); 120e0dac50fSopenharmony_ci virtual DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos); 121e0dac50fSopenharmony_ci virtual DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId); 122e0dac50fSopenharmony_ci virtual DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId, 123e0dac50fSopenharmony_ci MultiScreenMode screenMode); 124e0dac50fSopenharmony_ci virtual DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions, 125e0dac50fSopenharmony_ci MultiScreenPositionOptions secondScreenOption); 126e0dac50fSopenharmony_ci virtual DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint, ScreenId& screenGroupId); 127e0dac50fSopenharmony_ci virtual DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds); 128e0dac50fSopenharmony_ci virtual DMError StopExpand(const std::vector<ScreenId>& expandScreenIds); 129e0dac50fSopenharmony_ci virtual DMError DisableMirror(bool disableOrNot); 130e0dac50fSopenharmony_ci virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>); 131e0dac50fSopenharmony_ci virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 132e0dac50fSopenharmony_ci virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId); 133e0dac50fSopenharmony_ci virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); 134e0dac50fSopenharmony_ci virtual DMError SetVirtualPixelRatioSystem(ScreenId screenId, float virtualPixelRatio); 135e0dac50fSopenharmony_ci virtual DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height, float virtualPixelRatio); 136e0dac50fSopenharmony_ci virtual DMError GetDensityInCurResolution(ScreenId screenId, float& virtualPixelRatio); 137e0dac50fSopenharmony_ci virtual DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height); 138e0dac50fSopenharmony_ci virtual DMError SetScreenRotationLocked(bool isLocked); 139e0dac50fSopenharmony_ci virtual DMError SetScreenRotationLockedFromJs(bool isLocked); 140e0dac50fSopenharmony_ci virtual DMError IsScreenRotationLocked(bool& isLocked); 141e0dac50fSopenharmony_ci // colorspace, gamut 142e0dac50fSopenharmony_ci virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 143e0dac50fSopenharmony_ci virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 144e0dac50fSopenharmony_ci virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 145e0dac50fSopenharmony_ci virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 146e0dac50fSopenharmony_ci virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 147e0dac50fSopenharmony_ci virtual DMError SetScreenColorTransform(ScreenId screenId); 148e0dac50fSopenharmony_ci virtual DMError GetPixelFormat(ScreenId screenId, GraphicPixelFormat& pixelFormat); 149e0dac50fSopenharmony_ci virtual DMError SetPixelFormat(ScreenId screenId, GraphicPixelFormat pixelFormat); 150e0dac50fSopenharmony_ci virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<ScreenHDRFormat>& hdrFormats); 151e0dac50fSopenharmony_ci virtual DMError GetScreenHDRFormat(ScreenId screenId, ScreenHDRFormat& hdrFormat); 152e0dac50fSopenharmony_ci virtual DMError SetScreenHDRFormat(ScreenId screenId, int32_t modeIdx); 153e0dac50fSopenharmony_ci virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<GraphicCM_ColorSpaceType>& colorSpaces); 154e0dac50fSopenharmony_ci virtual DMError GetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType& colorSpace); 155e0dac50fSopenharmony_ci virtual DMError SetScreenColorSpace(ScreenId screenId, GraphicCM_ColorSpaceType colorSpace); 156e0dac50fSopenharmony_ci virtual DMError GetSupportedHDRFormats(ScreenId screenId, std::vector<uint32_t>& hdrFormats); 157e0dac50fSopenharmony_ci virtual DMError GetSupportedColorSpaces(ScreenId screenId, std::vector<uint32_t>& colorSpaces); 158e0dac50fSopenharmony_ci // unique screen 159e0dac50fSopenharmony_ci virtual DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds); 160e0dac50fSopenharmony_ci virtual VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId); 161e0dac50fSopenharmony_ci virtual DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag); 162e0dac50fSopenharmony_ci virtual DMError SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval); 163e0dac50fSopenharmony_ci virtual bool SetVirtualScreenStatus(ScreenId screenId, VirtualScreenStatus screenStatus); 164e0dac50fSopenharmony_ci virtual DMError SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate, 165e0dac50fSopenharmony_ci uint32_t& actualRefreshRate); 166e0dac50fSopenharmony_ciprivate: 167e0dac50fSopenharmony_ci static inline SingletonDelegator<ScreenManagerAdapter> delegator; 168e0dac50fSopenharmony_ci}; 169e0dac50fSopenharmony_ci} // namespace OHOS::Rosen 170e0dac50fSopenharmony_ci#endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H 171