1 /* 2 * Copyright (c) 2023 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 OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H 18 19 #include <vector> 20 21 #include <refbase.h> 22 #include <screen_manager/screen_types.h> 23 #include <ui/rs_display_node.h> 24 25 #include "screen_property.h" 26 #include "dm_common.h" 27 #include "display_info.h" 28 #include "screen.h" 29 #include "screen_info.h" 30 #include "screen_group.h" 31 #include "screen_group_info.h" 32 #include "event_handler.h" 33 34 namespace OHOS::Rosen { 35 class IScreenChangeListener : public RefBase { 36 public: 37 IScreenChangeListener() = default; 38 virtual ~IScreenChangeListener() = default; 39 40 virtual void OnConnect() = 0; 41 virtual void OnDisconnect() = 0; 42 virtual void OnPropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason) = 0; 43 }; 44 45 enum class ScreenState : int32_t { 46 INIT, 47 CONNECTION, 48 DISCONNECTION, 49 }; 50 51 class ScreenSession : public RefBase { 52 public: 53 explicit ScreenSession(ScreenId screenId, const ScreenProperty& property, ScreenId defaultScreenId); 54 ScreenSession(); 55 ScreenSession(const std::string& name, ScreenId smsId, ScreenId rsId, ScreenId defaultScreenId); 56 ~ScreenSession() = default; 57 58 void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener); 59 void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener); 60 61 sptr<DisplayInfo> ConvertToDisplayInfo(); 62 sptr<ScreenInfo> ConvertToScreenInfo() const; 63 sptr<SupportedScreenModes> GetActiveScreenMode() const; 64 ScreenSourceMode GetSourceMode() const; 65 void SetScreenCombination(ScreenCombination combination); 66 ScreenCombination GetScreenCombination() const; 67 68 Orientation GetOrientation() const; 69 void SetOrientation(Orientation orientation); 70 Rotation GetRotation() const; 71 void SetRotation(Rotation rotation); 72 void SetScreenRequestedOrientation(Orientation orientation); 73 Orientation GetScreenRequestedOrientation() const; 74 75 void SetVirtualPixelRatio(float virtualPixelRatio); 76 void SetScreenType(ScreenType type); 77 78 ScreenId GetScreenId(); 79 ScreenProperty GetScreenProperty() const; 80 void UpdatePropertyByActiveMode(); 81 std::shared_ptr<RSDisplayNode> GetDisplayNode() const; 82 void ReleaseDisplayNode(); 83 84 Rotation CalcRotation(Orientation orientation) const; 85 void FillScreenInfo(sptr<ScreenInfo> info) const; 86 void InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint); 87 88 DMError GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts); 89 DMError GetScreenColorGamut(ScreenColorGamut& colorGamut); 90 DMError SetScreenColorGamut(int32_t colorGamutIdx); 91 DMError GetScreenGamutMap(ScreenGamutMap& gamutMap); 92 DMError SetScreenGamutMap(ScreenGamutMap gamutMap); 93 DMError SetScreenColorTransform(); 94 95 int32_t GetPrivateSessionCount() const; 96 DMError SetPrivateSessionCount(int32_t count); 97 bool HasPrivateSession() const; 98 void SetDisplayBoundary(const RectF& rect, const uint32_t& offsetY); 99 100 std::string name_ { "UNKNOW" }; 101 ScreenId screenId_ {}; 102 ScreenId rsId_ {}; 103 ScreenId defaultScreenId_ = SCREEN_ID_INVALID; 104 105 int32_t activeIdx_ { 0 }; 106 std::vector<sptr<SupportedScreenModes>> modes_ = {}; 107 108 bool isScreenGroup_ { false }; 109 ScreenId groupSmsId_ { SCREEN_ID_INVALID }; 110 ScreenId lastGroupSmsId_ { SCREEN_ID_INVALID }; 111 112 void Connect(); 113 void Disconnect(); 114 void PropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason); 115 private: 116 ScreenProperty property_; 117 std::shared_ptr<RSDisplayNode> displayNode_; 118 ScreenState screenState_ { ScreenState::INIT }; 119 std::vector<IScreenChangeListener*> screenChangeListenerList_; 120 ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; 121 int32_t privateSessionCount_ { 0 }; 122 }; 123 124 class ScreenSessionGroup : public ScreenSession { 125 public: 126 ScreenSessionGroup(ScreenId smsId, ScreenId rsId, std::string name, ScreenCombination combination); 127 ScreenSessionGroup() = delete; 128 WM_DISALLOW_COPY_AND_MOVE(ScreenSessionGroup); 129 ~ScreenSessionGroup(); 130 131 bool AddChild(sptr<ScreenSession>& smsScreen, Point& startPoint); 132 bool AddChild(sptr<ScreenSession>& smsScreen, Point& startPoint, sptr<ScreenSession> defaultScreenSession); 133 bool AddChildren(std::vector<sptr<ScreenSession>>& smsScreens, std::vector<Point>& startPoints); 134 bool RemoveChild(sptr<ScreenSession>& smsScreen); 135 bool HasChild(ScreenId childScreen) const; 136 std::vector<sptr<ScreenSession>> GetChildren() const; 137 std::vector<Point> GetChildrenPosition() const; 138 Point GetChildPosition(ScreenId screenId) const; 139 size_t GetChildCount() const; 140 sptr<ScreenGroupInfo> ConvertToScreenGroupInfo() const; 141 ScreenCombination GetScreenCombination() const; 142 143 ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; 144 ScreenId mirrorScreenId_ { SCREEN_ID_INVALID }; 145 146 private: 147 bool GetRSDisplayNodeConfig(sptr<ScreenSession>& screenSession, struct RSDisplayNodeConfig& config, 148 sptr<ScreenSession> defaultScreenSession); 149 150 std::map<ScreenId, std::pair<sptr<ScreenSession>, Point>> screenSessionMap_; 151 }; 152 153 } // namespace OHOS::Rosen 154 155 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H 156