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 <mutex> 20 #include <vector> 21 22 #include <refbase.h> 23 #include <screen_manager/screen_types.h> 24 #include <ui/rs_display_node.h> 25 26 #include "screen_property.h" 27 #include "dm_common.h" 28 #include "display_info.h" 29 #include "screen.h" 30 #include "screen_info.h" 31 #include "screen_group.h" 32 #include "screen_group_info.h" 33 #include "event_handler.h" 34 #include "session_manager/include/screen_rotation_property.h" 35 36 namespace OHOS::Rosen { 37 class IScreenChangeListener { 38 public: 39 virtual void OnConnect(ScreenId screenId) = 0; 40 virtual void OnDisconnect(ScreenId screenId) = 0; 41 virtual void OnPropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason, 42 ScreenId screenId) = 0; 43 virtual void OnPowerStatusChange(DisplayPowerEvent event, EventStatus status, 44 PowerStateChangeReason reason) = 0; 45 virtual void OnSensorRotationChange(float sensorRotation, ScreenId screenId) = 0; 46 virtual void OnScreenOrientationChange(float screenOrientation, ScreenId screenId) = 0; 47 virtual void OnScreenRotationLockedChange(bool isLocked, ScreenId screenId) = 0; 48 }; 49 50 enum class ScreenState : int32_t { 51 INIT, 52 CONNECTION, 53 DISCONNECTION, 54 }; 55 56 class ScreenSession : public RefBase { 57 public: 58 ScreenSession() = default; 59 ScreenSession(ScreenId screenId, ScreenId rsId, const std::string& name, 60 const ScreenProperty& property, const std::shared_ptr<RSDisplayNode>& displayNode); 61 ScreenSession(ScreenId screenId, const ScreenProperty& property, ScreenId defaultScreenId); 62 ScreenSession(ScreenId screenId, const ScreenProperty& property, NodeId nodeId, ScreenId defaultScreenId); 63 ScreenSession(const std::string& name, ScreenId smsId, ScreenId rsId, ScreenId defaultScreenId); 64 virtual ~ScreenSession() = default; 65 66 void SetDisplayNodeScreenId(ScreenId screenId); 67 void RegisterScreenChangeListener(IScreenChangeListener* screenChangeListener); 68 void UnregisterScreenChangeListener(IScreenChangeListener* screenChangeListener); 69 70 sptr<DisplayInfo> ConvertToDisplayInfo(); 71 sptr<ScreenInfo> ConvertToScreenInfo() const; 72 sptr<SupportedScreenModes> GetActiveScreenMode() const; 73 ScreenSourceMode GetSourceMode() const; 74 void SetScreenCombination(ScreenCombination combination); 75 ScreenCombination GetScreenCombination() const; 76 77 Orientation GetOrientation() const; 78 void SetOrientation(Orientation orientation); 79 Rotation GetRotation() const; 80 void SetRotation(Rotation rotation); 81 void SetScreenRequestedOrientation(Orientation orientation); 82 Orientation GetScreenRequestedOrientation() const; 83 void SetUpdateToInputManagerCallback(std::function<void(float)> updateToInputManagerCallback); 84 85 void SetVirtualPixelRatio(float virtualPixelRatio); 86 void SetDensityInCurResolution(float densityInCurResolution); 87 void SetScreenType(ScreenType type); 88 89 std::string GetName(); 90 ScreenId GetScreenId(); 91 ScreenId GetRSScreenId(); 92 ScreenProperty GetScreenProperty() const; 93 void UpdatePropertyByActiveMode(); 94 std::shared_ptr<RSDisplayNode> GetDisplayNode() const; 95 void ReleaseDisplayNode(); 96 97 Rotation CalcRotation(Orientation orientation, FoldDisplayMode foldDisplayMode) const; 98 DisplayOrientation CalcDisplayOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode) const; 99 void FillScreenInfo(sptr<ScreenInfo> info) const; 100 void InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint); 101 102 DMError GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts); 103 DMError GetScreenColorGamut(ScreenColorGamut& colorGamut); 104 DMError SetScreenColorGamut(int32_t colorGamutIdx); 105 DMError GetScreenGamutMap(ScreenGamutMap& gamutMap); 106 DMError SetScreenGamutMap(ScreenGamutMap gamutMap); 107 DMError SetScreenColorTransform(); 108 109 DMError GetPixelFormat(GraphicPixelFormat& pixelFormat); 110 DMError SetPixelFormat(GraphicPixelFormat pixelFormat); 111 DMError GetSupportedHDRFormats(std::vector<ScreenHDRFormat>& hdrFormats); 112 DMError GetScreenHDRFormat(ScreenHDRFormat& hdrFormat); 113 DMError SetScreenHDRFormat(int32_t modeIdx); 114 DMError GetSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType>& colorSpaces); 115 DMError GetScreenColorSpace(GraphicCM_ColorSpaceType& colorSpace); 116 DMError SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace); 117 118 void HandleSensorRotation(float sensorRotation); 119 float ConvertRotationToFloat(Rotation sensorRotation); 120 121 bool HasPrivateSessionForeground() const; 122 void SetPrivateSessionForeground(bool hasPrivate); 123 void SetDisplayBoundary(const RectF& rect, const uint32_t& offsetY); 124 void SetScreenRotationLocked(bool isLocked); 125 void SetScreenRotationLockedFromJs(bool isLocked); 126 bool IsScreenRotationLocked(); 127 128 void UpdateToInputManager(RRect bounds, int rotation, FoldDisplayMode foldDisplayMode); 129 void UpdatePropertyAfterRotation(RRect bounds, int rotation, FoldDisplayMode foldDisplayMode); 130 void UpdatePropertyByFoldControl(RRect bounds, RRect phyBounds); 131 void UpdateRefreshRate(uint32_t refreshRate); 132 void UpdatePropertyByResolution(uint32_t width, uint32_t height); 133 void SetName(std::string name); 134 void Resize(uint32_t width, uint32_t height); 135 136 void SetHdrFormats(std::vector<uint32_t>&& hdrFormats); 137 void SetColorSpaces(std::vector<uint32_t>&& colorSpaces); 138 139 std::string name_ { "UNKNOW" }; 140 ScreenId screenId_ {}; 141 ScreenId rsId_ {}; 142 ScreenId defaultScreenId_ = SCREEN_ID_INVALID; 143 144 NodeId nodeId_ {}; 145 146 int32_t activeIdx_ { 0 }; 147 std::vector<sptr<SupportedScreenModes>> modes_ = {}; 148 149 bool isScreenGroup_ { false }; 150 ScreenId groupSmsId_ { SCREEN_ID_INVALID }; 151 ScreenId lastGroupSmsId_ { SCREEN_ID_INVALID }; 152 bool isScreenLocked_ = true; 153 154 void Connect(); 155 void Disconnect(); 156 void PropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason); 157 void PowerStatusChange(DisplayPowerEvent event, EventStatus status, PowerStateChangeReason reason); 158 // notify scb 159 void SensorRotationChange(Rotation sensorRotation); 160 void SensorRotationChange(float sensorRotation); 161 void ScreenOrientationChange(Orientation orientation, FoldDisplayMode foldDisplayMode); 162 void ScreenOrientationChange(float orientation); 163 DMRect GetAvailableArea(); 164 void SetAvailableArea(DMRect area); 165 bool UpdateAvailableArea(DMRect area); 166 void SetFoldScreen(bool isFold); 167 std::shared_ptr<Media::PixelMap> GetScreenSnapshot(float scaleX, float scaleY); 168 169 private: 170 Rotation ConvertIntToRotation(int rotation); 171 ScreenProperty property_; 172 std::shared_ptr<RSDisplayNode> displayNode_; 173 ScreenState screenState_ { ScreenState::INIT }; 174 std::vector<IScreenChangeListener*> screenChangeListenerList_; 175 ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; 176 bool hasPrivateWindowForeground_ = false; 177 std::recursive_mutex mutex_; 178 std::function<void(float)> updateToInputManagerCallback_ = nullptr; 179 bool isFold_ = false; 180 std::vector<uint32_t> hdrFormats_; 181 std::vector<uint32_t> colorSpaces_; 182 }; 183 184 class ScreenSessionGroup : public ScreenSession { 185 public: 186 ScreenSessionGroup(ScreenId smsId, ScreenId rsId, std::string name, ScreenCombination combination); 187 ScreenSessionGroup() = delete; 188 WM_DISALLOW_COPY_AND_MOVE(ScreenSessionGroup); 189 ~ScreenSessionGroup(); 190 191 bool AddChild(sptr<ScreenSession>& smsScreen, Point& startPoint); 192 bool AddChild(sptr<ScreenSession>& smsScreen, Point& startPoint, sptr<ScreenSession> defaultScreenSession); 193 bool AddChildren(std::vector<sptr<ScreenSession>>& smsScreens, std::vector<Point>& startPoints); 194 bool RemoveChild(sptr<ScreenSession>& smsScreen); 195 bool HasChild(ScreenId childScreen) const; 196 std::vector<sptr<ScreenSession>> GetChildren() const; 197 std::vector<Point> GetChildrenPosition() const; 198 Point GetChildPosition(ScreenId screenId) const; 199 size_t GetChildCount() const; 200 sptr<ScreenGroupInfo> ConvertToScreenGroupInfo() const; 201 ScreenCombination GetScreenCombination() const; 202 203 ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; 204 ScreenId mirrorScreenId_ { SCREEN_ID_INVALID }; 205 206 private: 207 bool GetRSDisplayNodeConfig(sptr<ScreenSession>& screenSession, struct RSDisplayNodeConfig& config, 208 sptr<ScreenSession> defaultScreenSession); 209 210 std::map<ScreenId, std::pair<sptr<ScreenSession>, Point>> screenSessionMap_; 211 }; 212 213 } // namespace OHOS::Rosen 214 215 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_SESSION_H 216