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 "singleton_delegator.h" 29 30 namespace OHOS::Rosen { 31 class BaseAdapter { 32 public: 33 virtual bool RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 34 DisplayManagerAgentType type); 35 virtual bool UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 36 DisplayManagerAgentType type); 37 virtual void Clear(); 38 protected: 39 bool InitDMSProxy(); 40 std::recursive_mutex mutex_; 41 sptr<IDisplayManager> displayManagerServiceProxy_ = nullptr; 42 sptr<IRemoteObject::DeathRecipient> dmsDeath_ = nullptr; 43 bool isProxyValid_ { false }; 44 }; 45 46 class DMSDeathRecipient : public IRemoteObject::DeathRecipient { 47 public: 48 DMSDeathRecipient(BaseAdapter& adapter); 49 virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override; 50 private: 51 BaseAdapter& adapter_; 52 }; 53 54 class DisplayManagerAdapter : public BaseAdapter { 55 WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter); 56 public: 57 virtual sptr<DisplayInfo> GetDefaultDisplayInfo(); 58 virtual sptr<DisplayInfo> GetDisplayInfoByScreenId(ScreenId screenId); 59 virtual std::vector<DisplayId> GetAllDisplayIds(); 60 virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId); 61 virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow); 62 virtual bool WakeUpBegin(PowerStateChangeReason reason); 63 virtual bool WakeUpEnd(); 64 virtual bool SuspendBegin(PowerStateChangeReason reason); 65 virtual bool SuspendEnd(); 66 virtual bool SetDisplayState(DisplayState state); 67 virtual DisplayState GetDisplayState(DisplayId displayId); 68 virtual void NotifyDisplayEvent(DisplayEvent event); 69 virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze); 70 virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId); 71 virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId); 72 private: 73 static inline SingletonDelegator<DisplayManagerAdapter> delegator; 74 }; 75 76 class ScreenManagerAdapter : public BaseAdapter { 77 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter); 78 public: 79 virtual ScreenId CreateVirtualScreen(VirtualScreenOption option, 80 const sptr<IDisplayManagerAgent>& displayManagerAgent); 81 virtual DMError DestroyVirtualScreen(ScreenId screenId); 82 virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 83 virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 84 virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId); 85 virtual bool SetOrientation(ScreenId screenId, Orientation orientation); 86 virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId); 87 virtual std::vector<sptr<ScreenInfo>> GetAllScreenInfos(); 88 virtual ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId); 89 virtual ScreenId MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint); 90 virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>); 91 virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 92 virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId); 93 virtual bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); 94 virtual void SetScreenRotationLocked(bool isLocked); 95 virtual bool IsScreenRotationLocked(); 96 97 // colorspace, gamut 98 virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 99 virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 100 virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 101 virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 102 virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 103 virtual DMError SetScreenColorTransform(ScreenId screenId); 104 private: 105 static inline SingletonDelegator<ScreenManagerAdapter> delegator; 106 }; 107 } // namespace OHOS::Rosen 108 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H 109