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_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H 17e0dac50fSopenharmony_ci#define FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <map> 20e0dac50fSopenharmony_ci#include <vector> 21e0dac50fSopenharmony_ci 22e0dac50fSopenharmony_ci#include <event_handler.h> 23e0dac50fSopenharmony_ci#include <refbase.h> 24e0dac50fSopenharmony_ci#include <surface.h> 25e0dac50fSopenharmony_ci#include <transaction/rs_interfaces.h> 26e0dac50fSopenharmony_ci#include <transaction/rs_sync_transaction_controller.h> 27e0dac50fSopenharmony_ci 28e0dac50fSopenharmony_ci#include "abstract_screen.h" 29e0dac50fSopenharmony_ci#include "agent_death_recipient.h" 30e0dac50fSopenharmony_ci#include "display_manager_agent_controller.h" 31e0dac50fSopenharmony_ci#include "dm_common.h" 32e0dac50fSopenharmony_ci#include "screen.h" 33e0dac50fSopenharmony_ci#include "zidl/display_manager_agent_interface.h" 34e0dac50fSopenharmony_ci 35e0dac50fSopenharmony_cinamespace OHOS::Rosen { 36e0dac50fSopenharmony_ciclass AbstractScreenController : public RefBase { 37e0dac50fSopenharmony_ciusing OnAbstractScreenConnectCb = std::function<void(sptr<AbstractScreen>)>; 38e0dac50fSopenharmony_ciusing OnAbstractScreenChangeCb = std::function<void(sptr<AbstractScreen>, DisplayChangeEvent event)>; 39e0dac50fSopenharmony_cipublic: 40e0dac50fSopenharmony_ci struct AbstractScreenCallback : public RefBase { 41e0dac50fSopenharmony_ci OnAbstractScreenConnectCb onConnect_; 42e0dac50fSopenharmony_ci OnAbstractScreenConnectCb onDisconnect_; 43e0dac50fSopenharmony_ci OnAbstractScreenChangeCb onChange_; 44e0dac50fSopenharmony_ci }; 45e0dac50fSopenharmony_ci 46e0dac50fSopenharmony_ci explicit AbstractScreenController(std::recursive_mutex& mutex); 47e0dac50fSopenharmony_ci ~AbstractScreenController(); 48e0dac50fSopenharmony_ci WM_DISALLOW_COPY_AND_MOVE(AbstractScreenController); 49e0dac50fSopenharmony_ci 50e0dac50fSopenharmony_ci void Init(); 51e0dac50fSopenharmony_ci std::vector<ScreenId> GetAllScreenIds() const; 52e0dac50fSopenharmony_ci sptr<AbstractScreen> GetAbstractScreen(ScreenId dmsScreenId) const; 53e0dac50fSopenharmony_ci std::vector<ScreenId> GetAllValidScreenIds(const std::vector<ScreenId>& screenIds) const; 54e0dac50fSopenharmony_ci sptr<AbstractScreenGroup> GetAbstractScreenGroup(ScreenId dmsScreenId); 55e0dac50fSopenharmony_ci ScreenId GetDefaultAbstractScreenId(); 56e0dac50fSopenharmony_ci ScreenId ConvertToRsScreenId(ScreenId dmsScreenId) const; 57e0dac50fSopenharmony_ci ScreenId ConvertToDmsScreenId(ScreenId rsScreenId) const; 58e0dac50fSopenharmony_ci void RegisterAbstractScreenCallback(sptr<AbstractScreenCallback> cb); 59e0dac50fSopenharmony_ci ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr<IRemoteObject>& displayManagerAgent); 60e0dac50fSopenharmony_ci DMError DestroyVirtualScreen(ScreenId screenId); 61e0dac50fSopenharmony_ci DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 62e0dac50fSopenharmony_ci void SetBuildInDefaultOrientation(Orientation orientation); 63e0dac50fSopenharmony_ci DMError SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow, bool withAnimation = true); 64e0dac50fSopenharmony_ci bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow, bool withAnimation = true); 65e0dac50fSopenharmony_ci 66e0dac50fSopenharmony_ci DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 67e0dac50fSopenharmony_ci const std::shared_ptr<RSDisplayNode>& GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const; 68e0dac50fSopenharmony_ci void UpdateRSTree(ScreenId dmsScreenId, ScreenId parentScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode, 69e0dac50fSopenharmony_ci bool isAdd, bool isMultiDisplay); 70e0dac50fSopenharmony_ci DMError AddSurfaceNodeToScreen(ScreenId dmsScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop); 71e0dac50fSopenharmony_ci DMError RemoveSurfaceNodeFromScreen(ScreenId dmsScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode); 72e0dac50fSopenharmony_ci DMError MakeMirror(ScreenId, std::vector<ScreenId> screens); 73e0dac50fSopenharmony_ci bool MakeExpand(std::vector<ScreenId> screenIds, std::vector<Point> startPoints); 74e0dac50fSopenharmony_ci DMError StopScreens(const std::vector<ScreenId>& screenIds, ScreenCombination stopCombination); 75e0dac50fSopenharmony_ci void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens); 76e0dac50fSopenharmony_ci bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason, bool needToNotify = true); 77e0dac50fSopenharmony_ci ScreenPowerState GetScreenPower(ScreenId dmsScreenId) const; 78e0dac50fSopenharmony_ci DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); 79e0dac50fSopenharmony_ci 80e0dac50fSopenharmony_ci // colorspace, gamut 81e0dac50fSopenharmony_ci DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 82e0dac50fSopenharmony_ci DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 83e0dac50fSopenharmony_ci DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 84e0dac50fSopenharmony_ci DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 85e0dac50fSopenharmony_ci DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 86e0dac50fSopenharmony_ci DMError SetScreenColorTransform(ScreenId screenId); 87e0dac50fSopenharmony_ci 88e0dac50fSopenharmony_ciprivate: 89e0dac50fSopenharmony_ci static inline bool IsVertical(Rotation rotation) 90e0dac50fSopenharmony_ci { 91e0dac50fSopenharmony_ci return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 92e0dac50fSopenharmony_ci } 93e0dac50fSopenharmony_ci void SetScreenRotateAnimation(sptr<AbstractScreen>& screen, ScreenId screenId, 94e0dac50fSopenharmony_ci Rotation rotationAfter, bool withAnimation); 95e0dac50fSopenharmony_ci void RegisterRsScreenConnectionChangeListener(); 96e0dac50fSopenharmony_ci void OnRsScreenConnectionChange(ScreenId rsScreenId, ScreenEvent screenEvent); 97e0dac50fSopenharmony_ci bool OnRemoteDied(const sptr<IRemoteObject>& agent); 98e0dac50fSopenharmony_ci void ProcessScreenConnected(ScreenId rsScreenId); 99e0dac50fSopenharmony_ci void ProcessDefaultScreenReconnected(ScreenId rsScreenId); 100e0dac50fSopenharmony_ci sptr<AbstractScreen> InitAndGetScreen(ScreenId rsScreenId); 101e0dac50fSopenharmony_ci void ProcessScreenDisconnected(ScreenId rsScreenId); 102e0dac50fSopenharmony_ci bool InitAbstractScreenModesInfo(sptr<AbstractScreen>& absScreen); 103e0dac50fSopenharmony_ci sptr<AbstractScreen> InitVirtualScreen(ScreenId dmsScreenId, ScreenId rsId, VirtualScreenOption option); 104e0dac50fSopenharmony_ci sptr<AbstractScreenGroup> AddToGroupLocked(sptr<AbstractScreen> newScreen); 105e0dac50fSopenharmony_ci sptr<AbstractScreenGroup> RemoveFromGroupLocked(sptr<AbstractScreen> screen); 106e0dac50fSopenharmony_ci void RemoveDefaultScreenFromGroupLocked(sptr<AbstractScreen> screen); 107e0dac50fSopenharmony_ci bool RemoveChildFromGroup(sptr<AbstractScreen>, sptr<AbstractScreenGroup>); 108e0dac50fSopenharmony_ci bool CheckScreenInScreenGroup(sptr<AbstractScreen> newScreen) const; 109e0dac50fSopenharmony_ci sptr<AbstractScreenGroup> AddAsFirstScreenLocked(sptr<AbstractScreen> newScreen); 110e0dac50fSopenharmony_ci sptr<AbstractScreenGroup> AddAsSuccedentScreenLocked(sptr<AbstractScreen> newScreen); 111e0dac50fSopenharmony_ci void ProcessScreenModeChanged(ScreenId dmsScreenId); 112e0dac50fSopenharmony_ci void ChangeScreenGroup(sptr<AbstractScreenGroup> group, const std::vector<ScreenId>& screens, 113e0dac50fSopenharmony_ci const std::vector<Point>& startPoints, bool filterScreen, ScreenCombination combination); 114e0dac50fSopenharmony_ci void AddScreenToGroup(sptr<AbstractScreenGroup>, const std::vector<ScreenId>&, 115e0dac50fSopenharmony_ci const std::vector<Point>&, std::map<ScreenId, bool>&); 116e0dac50fSopenharmony_ci void NotifyScreenConnected(sptr<ScreenInfo>) const; 117e0dac50fSopenharmony_ci void NotifyScreenDisconnected(ScreenId screenId) const; 118e0dac50fSopenharmony_ci void NotifyScreenChanged(sptr<ScreenInfo> screenInfo, ScreenChangeEvent event) const; 119e0dac50fSopenharmony_ci void NotifyScreenGroupChanged(const sptr<ScreenInfo>& screenInfo, ScreenGroupChangeEvent event) const; 120e0dac50fSopenharmony_ci void NotifyScreenGroupChanged(const std::vector<sptr<ScreenInfo>>& screenInfo, ScreenGroupChangeEvent event) const; 121e0dac50fSopenharmony_ci void OpenRotationSyncTransaction(); 122e0dac50fSopenharmony_ci void CloseRotationSyncTransaction(); 123e0dac50fSopenharmony_ci void UpdateScreenGroupLayout(sptr<AbstractScreenGroup> screenGroup); 124e0dac50fSopenharmony_ci void SetDisplayNode(Rotation rotationAfter, const std::shared_ptr<RSDisplayNode>& displayNode, 125e0dac50fSopenharmony_ci struct ScreenRect srect); 126e0dac50fSopenharmony_ci 127e0dac50fSopenharmony_ci class ScreenIdManager { 128e0dac50fSopenharmony_ci public: 129e0dac50fSopenharmony_ci ScreenIdManager() = default; 130e0dac50fSopenharmony_ci ~ScreenIdManager() = default; 131e0dac50fSopenharmony_ci WM_DISALLOW_COPY_AND_MOVE(ScreenIdManager); 132e0dac50fSopenharmony_ci ScreenId CreateAndGetNewScreenId(ScreenId rsScreenId); 133e0dac50fSopenharmony_ci bool DeleteScreenId(ScreenId dmsScreenId); 134e0dac50fSopenharmony_ci bool HasDmsScreenId(ScreenId dmsScreenId) const; 135e0dac50fSopenharmony_ci bool HasRsScreenId(ScreenId dmsScreenId) const; 136e0dac50fSopenharmony_ci bool ConvertToRsScreenId(ScreenId, ScreenId&) const; 137e0dac50fSopenharmony_ci ScreenId ConvertToRsScreenId(ScreenId) const; 138e0dac50fSopenharmony_ci bool ConvertToDmsScreenId(ScreenId, ScreenId&) const; 139e0dac50fSopenharmony_ci ScreenId ConvertToDmsScreenId(ScreenId) const; 140e0dac50fSopenharmony_ci private: 141e0dac50fSopenharmony_ci std::atomic<ScreenId> dmsScreenCount_ {0}; 142e0dac50fSopenharmony_ci std::map<ScreenId, ScreenId> rs2DmsScreenIdMap_; 143e0dac50fSopenharmony_ci std::map<ScreenId, ScreenId> dms2RsScreenIdMap_; 144e0dac50fSopenharmony_ci }; 145e0dac50fSopenharmony_ci 146e0dac50fSopenharmony_ci std::recursive_mutex& mutex_; 147e0dac50fSopenharmony_ci OHOS::Rosen::RSInterfaces& rsInterface_; 148e0dac50fSopenharmony_ci ScreenIdManager screenIdManager_; 149e0dac50fSopenharmony_ci std::map<ScreenId, sptr<AbstractScreen>> dmsScreenMap_; 150e0dac50fSopenharmony_ci std::map<ScreenId, sptr<AbstractScreenGroup>> dmsScreenGroupMap_; 151e0dac50fSopenharmony_ci std::map<sptr<IRemoteObject>, std::vector<ScreenId>> screenAgentMap_; 152e0dac50fSopenharmony_ci sptr<AgentDeathRecipient> deathRecipient_ { nullptr }; 153e0dac50fSopenharmony_ci sptr<AbstractScreenCallback> abstractScreenCallback_; 154e0dac50fSopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> controllerHandler_; 155e0dac50fSopenharmony_ci std::atomic<ScreenId> defaultRsScreenId_ {SCREEN_ID_INVALID }; 156e0dac50fSopenharmony_ci Orientation buildInDefaultOrientation_ { Orientation::UNSPECIFIED }; 157e0dac50fSopenharmony_ci bool isExpandCombination_ = false; 158e0dac50fSopenharmony_ci ScreenPowerState powerState_ { ScreenPowerState::INVALID_STATE }; 159e0dac50fSopenharmony_ci}; 160e0dac50fSopenharmony_ci 161e0dac50fSopenharmony_cistruct ScreenRect { 162e0dac50fSopenharmony_ci float w; 163e0dac50fSopenharmony_ci float h; 164e0dac50fSopenharmony_ci float x; 165e0dac50fSopenharmony_ci float y; 166e0dac50fSopenharmony_ci}; 167e0dac50fSopenharmony_ci 168e0dac50fSopenharmony_ci} // namespace OHOS::Rosen 169e0dac50fSopenharmony_ci#endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H