/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H #define FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H #include #include #include #include #include #include #include #include "abstract_screen.h" #include "agent_death_recipient.h" #include "display_manager_agent_controller.h" #include "dm_common.h" #include "screen.h" #include "zidl/display_manager_agent_interface.h" namespace OHOS::Rosen { class AbstractScreenController : public RefBase { using OnAbstractScreenConnectCb = std::function)>; using OnAbstractScreenChangeCb = std::function, DisplayChangeEvent event)>; public: struct AbstractScreenCallback : public RefBase { OnAbstractScreenConnectCb onConnect_; OnAbstractScreenConnectCb onDisconnect_; OnAbstractScreenChangeCb onChange_; }; explicit AbstractScreenController(std::recursive_mutex& mutex); ~AbstractScreenController(); WM_DISALLOW_COPY_AND_MOVE(AbstractScreenController); void Init(); std::vector GetAllScreenIds() const; sptr GetAbstractScreen(ScreenId dmsScreenId) const; std::vector GetAllValidScreenIds(const std::vector& screenIds) const; sptr GetAbstractScreenGroup(ScreenId dmsScreenId); ScreenId GetDefaultAbstractScreenId(); ScreenId ConvertToRsScreenId(ScreenId dmsScreenId) const; ScreenId ConvertToDmsScreenId(ScreenId rsScreenId) const; void RegisterAbstractScreenCallback(sptr cb); ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr& displayManagerAgent); DMError DestroyVirtualScreen(ScreenId screenId); DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); void SetBuildInDefaultOrientation(Orientation orientation); DMError SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow, bool withAnimation = true); bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow, bool withAnimation = true); DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId); const std::shared_ptr& GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const; void UpdateRSTree(ScreenId dmsScreenId, ScreenId parentScreenId, std::shared_ptr& surfaceNode, bool isAdd, bool isMultiDisplay); DMError AddSurfaceNodeToScreen(ScreenId dmsScreenId, std::shared_ptr& surfaceNode, bool onTop); DMError RemoveSurfaceNodeFromScreen(ScreenId dmsScreenId, std::shared_ptr& surfaceNode); DMError MakeMirror(ScreenId, std::vector screens); bool MakeExpand(std::vector screenIds, std::vector startPoints); DMError StopScreens(const std::vector& screenIds, ScreenCombination stopCombination); void RemoveVirtualScreenFromGroup(std::vector screens); bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason, bool needToNotify = true); ScreenPowerState GetScreenPower(ScreenId dmsScreenId) const; DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); // colorspace, gamut DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts); DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); DMError SetScreenColorTransform(ScreenId screenId); private: static inline bool IsVertical(Rotation rotation) { return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); } void SetScreenRotateAnimation(sptr& screen, ScreenId screenId, Rotation rotationAfter, bool withAnimation); void RegisterRsScreenConnectionChangeListener(); void OnRsScreenConnectionChange(ScreenId rsScreenId, ScreenEvent screenEvent); bool OnRemoteDied(const sptr& agent); void ProcessScreenConnected(ScreenId rsScreenId); void ProcessDefaultScreenReconnected(ScreenId rsScreenId); sptr InitAndGetScreen(ScreenId rsScreenId); void ProcessScreenDisconnected(ScreenId rsScreenId); bool InitAbstractScreenModesInfo(sptr& absScreen); sptr InitVirtualScreen(ScreenId dmsScreenId, ScreenId rsId, VirtualScreenOption option); sptr AddToGroupLocked(sptr newScreen); sptr RemoveFromGroupLocked(sptr screen); void RemoveDefaultScreenFromGroupLocked(sptr screen); bool RemoveChildFromGroup(sptr, sptr); bool CheckScreenInScreenGroup(sptr newScreen) const; sptr AddAsFirstScreenLocked(sptr newScreen); sptr AddAsSuccedentScreenLocked(sptr newScreen); void ProcessScreenModeChanged(ScreenId dmsScreenId); void ChangeScreenGroup(sptr group, const std::vector& screens, const std::vector& startPoints, bool filterScreen, ScreenCombination combination); void AddScreenToGroup(sptr, const std::vector&, const std::vector&, std::map&); void NotifyScreenConnected(sptr) const; void NotifyScreenDisconnected(ScreenId screenId) const; void NotifyScreenChanged(sptr screenInfo, ScreenChangeEvent event) const; void NotifyScreenGroupChanged(const sptr& screenInfo, ScreenGroupChangeEvent event) const; void NotifyScreenGroupChanged(const std::vector>& screenInfo, ScreenGroupChangeEvent event) const; void OpenRotationSyncTransaction(); void CloseRotationSyncTransaction(); void UpdateScreenGroupLayout(sptr screenGroup); void SetDisplayNode(Rotation rotationAfter, const std::shared_ptr& displayNode, struct ScreenRect srect); class ScreenIdManager { public: ScreenIdManager() = default; ~ScreenIdManager() = default; WM_DISALLOW_COPY_AND_MOVE(ScreenIdManager); ScreenId CreateAndGetNewScreenId(ScreenId rsScreenId); bool DeleteScreenId(ScreenId dmsScreenId); bool HasDmsScreenId(ScreenId dmsScreenId) const; bool HasRsScreenId(ScreenId dmsScreenId) const; bool ConvertToRsScreenId(ScreenId, ScreenId&) const; ScreenId ConvertToRsScreenId(ScreenId) const; bool ConvertToDmsScreenId(ScreenId, ScreenId&) const; ScreenId ConvertToDmsScreenId(ScreenId) const; private: std::atomic dmsScreenCount_ {0}; std::map rs2DmsScreenIdMap_; std::map dms2RsScreenIdMap_; }; std::recursive_mutex& mutex_; OHOS::Rosen::RSInterfaces& rsInterface_; ScreenIdManager screenIdManager_; std::map> dmsScreenMap_; std::map> dmsScreenGroupMap_; std::map, std::vector> screenAgentMap_; sptr deathRecipient_ { nullptr }; sptr abstractScreenCallback_; std::shared_ptr controllerHandler_; std::atomic defaultRsScreenId_ {SCREEN_ID_INVALID }; Orientation buildInDefaultOrientation_ { Orientation::UNSPECIFIED }; bool isExpandCombination_ = false; ScreenPowerState powerState_ { ScreenPowerState::INVALID_STATE }; }; struct ScreenRect { float w; float h; float x; float y; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H