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_SCREEN_SESSION_MANAGER_CLIENT_H 17 #define OHOS_ROSEN_SCREEN_SESSION_MANAGER_CLIENT_H 18 19 #include <map> 20 #include <mutex> 21 22 #include <common/rs_rect.h> 23 24 #include "display_change_listener.h" 25 #include "display_change_info.h" 26 #include "dm_common.h" 27 #include "session/screen/include/screen_session.h" 28 #include "wm_single_instance.h" 29 #include "zidl/screen_session_manager_client_stub.h" 30 #include "zidl/screen_session_manager_interface.h" 31 32 namespace OHOS::Rosen { 33 using ScreenInfoChangeClientListener = std::function<void(uint64_t)>; 34 35 class IScreenConnectionListener { 36 public: 37 virtual void OnScreenConnected(const sptr<ScreenSession>& screenSession) = 0; 38 virtual void OnScreenDisconnected(const sptr<ScreenSession>& screenSession) = 0; 39 }; 40 41 class ScreenSessionManagerClient : public ScreenSessionManagerClientStub { 42 WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenSessionManagerClient) 43 44 public: 45 void RegisterScreenConnectionListener(IScreenConnectionListener* listener); 46 void RegisterDisplayChangeListener(const sptr<IDisplayChangeListener>& listener); 47 48 sptr<ScreenSession> GetScreenSession(ScreenId screenId) const; 49 std::unordered_map<ScreenId, ScreenProperty> GetAllScreensProperties() const; 50 FoldDisplayMode GetFoldDisplayMode() const; 51 52 void UpdateScreenRotationProperty(ScreenId screenId, const RRect& bounds, float rotation); 53 uint32_t GetCurvedCompressionArea(); 54 ScreenProperty GetPhyScreenProperty(ScreenId screenId); 55 void SetScreenPrivacyState(bool hasPrivate); 56 void NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo>& info); 57 void OnDisplayStateChanged(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 58 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override; 59 void OnScreenshot(DisplayId displayId) override; 60 void OnImmersiveStateChanged(bool& immersive) override; 61 void OnGetSurfaceNodeIdsFromMissionIdsChanged(std::vector<uint64_t>& missionIds, 62 std::vector<uint64_t>& surfaceNodeIds) override; 63 void UpdateAvailableArea(ScreenId screenId, DMRect area); 64 void NotifyFoldToExpandCompletion(bool foldToExpand); 65 FoldStatus GetFoldStatus(); 66 std::shared_ptr<Media::PixelMap> GetScreenSnapshot(ScreenId screenId, float scaleX, float scaleY); 67 sptr<ScreenSession> GetScreenSessionById(const ScreenId id); 68 69 protected: 70 ScreenSessionManagerClient() = default; 71 virtual ~ScreenSessionManagerClient() = default; 72 73 private: 74 void ConnectToServer(); 75 bool CheckIfNeedCennectScreen(ScreenId screenId, ScreenId rsId, const std::string& name); 76 void OnScreenConnectionChanged(ScreenId screenId, ScreenEvent screenEvent, 77 ScreenId rsId, const std::string& name) override; 78 void OnPropertyChanged(ScreenId screenId, 79 const ScreenProperty& property, ScreenPropertyChangeReason reason) override; 80 void OnPowerStatusChanged(DisplayPowerEvent event, EventStatus status, 81 PowerStateChangeReason reason) override; 82 void OnSensorRotationChanged(ScreenId screenId, float sensorRotation) override; 83 void OnScreenOrientationChanged(ScreenId screenId, float screenOrientation) override; 84 void OnScreenRotationLockedChanged(ScreenId screenId, bool isLocked) override; 85 86 void SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId) override; 87 88 mutable std::mutex screenSessionMapMutex_; 89 std::map<ScreenId, sptr<ScreenSession>> screenSessionMap_; 90 91 sptr<IScreenSessionManager> screenSessionManager_; 92 93 IScreenConnectionListener* screenConnectionListener_; 94 sptr<IDisplayChangeListener> displayChangeListener_; 95 }; 96 } // namespace OHOS::Rosen 97 98 #endif // OHOS_ROSEN_SCREEN_SESSION_MANAGER_CLIENT_STUB_H 99