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 DisplayId GetDefaultDisplayId(); 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 bool WakeUpBegin(PowerStateChangeReason reason); 62 virtual bool WakeUpEnd(); 63 virtual bool SuspendBegin(PowerStateChangeReason reason); 64 virtual bool SuspendEnd(); 65 virtual bool SetDisplayState(DisplayState state); 66 virtual DisplayState GetDisplayState(DisplayId displayId); 67 virtual void NotifyDisplayEvent(DisplayEvent event); 68 virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze); 69 virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId); 70 private: 71 static inline SingletonDelegator<DisplayManagerAdapter> delegator; 72 }; 73 74 class ScreenManagerAdapter : public BaseAdapter { 75 WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter); 76 public: 77 virtual ScreenId CreateVirtualScreen(VirtualScreenOption option); 78 virtual DMError DestroyVirtualScreen(ScreenId screenId); 79 virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 80 virtual bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 81 virtual ScreenPowerState GetScreenPower(ScreenId dmsScreenId); 82 virtual bool SetOrientation(ScreenId screenId, Orientation orientation); 83 virtual sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId); 84 virtual std::vector<sptr<ScreenInfo>> GetAllScreenInfos(); 85 virtual ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId); 86 virtual ScreenId MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoint); 87 virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId>); 88 virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 89 virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId); 90 91 // colorspace, gamut 92 virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 93 virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 94 virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 95 virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 96 virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 97 virtual DMError SetScreenColorTransform(ScreenId screenId); 98 private: 99 static inline SingletonDelegator<ScreenManagerAdapter> delegator; 100 }; 101 } // namespace OHOS::Rosen 102 #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H 103