1 /* 2 * Copyright (c) 2021-2025 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 FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H 17 #define FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H 18 19 #include <map> 20 #include <mutex> 21 22 #include <surface.h> 23 #include <system_ability.h> 24 #include <ui/rs_display_node.h> 25 26 #include "abstract_display.h" 27 #include "abstract_display_controller.h" 28 #include "abstract_screen_controller.h" 29 #include "atomic_map.h" 30 #include "display_change_listener.h" 31 #include "display_cutout_controller.h" 32 #include "display_dumper.h" 33 #include "display_manager_stub.h" 34 #include "display_power_controller.h" 35 #include "dm_common.h" 36 #include "screen.h" 37 #include "singleton_delegator.h" 38 #include "window_info_queried_listener.h" 39 40 namespace OHOS::Rosen { 41 class DisplayManagerService { 42 WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); 43 44 public: 45 DisplayManagerService(); 46 bool Init(); 47 int Dump(int fd, const std::vector<std::u16string>& args); 48 ScreenId CreateVirtualScreen(VirtualScreenOption option, 49 const sptr<IRemoteObject>& displayManagerAgent); 50 DMError DestroyVirtualScreen(ScreenId screenId); 51 DMError SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface); 52 DMError IsScreenRotationLocked(bool& isLocked); 53 DMError SetScreenRotationLocked(bool isLocked); 54 DMError SetScreenRotationLockedFromJs(bool isLocked); 55 56 sptr<DisplayInfo> GetDefaultDisplayInfo(); 57 sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId); 58 sptr<DisplayInfo> GetVisibleAreaDisplayInfoById(DisplayId displayId); 59 sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId); 60 sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId); 61 DMError SetOrientation(ScreenId screenId, Orientation orientation); 62 DMError SetOrientationFromWindow(ScreenId screenId, Orientation orientation, bool withAnimation); 63 bool SetRotationFromWindow(ScreenId screenId, Rotation targetRotation, bool withAnimation); 64 void SetGravitySensorSubscriptionEnabled(); 65 std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId, 66 DmErrorCode* errorCode, bool isUseDma, bool isCaptureFullOfScreen = false); 67 DMError HasPrivateWindow(DisplayId id, bool& hasPrivateWindow); 68 // colorspace, gamut 69 DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 70 DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 71 DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 72 DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 73 DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 74 DMError SetScreenColorTransform(ScreenId screenId); 75 76 DMError RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 77 DisplayManagerAgentType type); 78 DMError UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent, 79 DisplayManagerAgentType type); 80 bool WakeUpBegin(PowerStateChangeReason reason); 81 bool WakeUpEnd(); 82 bool SuspendBegin(PowerStateChangeReason reason); 83 bool SuspendEnd(); 84 bool SetSpecifiedScreenPower(ScreenId, ScreenPowerState, PowerStateChangeReason); 85 bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 86 ScreenPowerState GetScreenPower(ScreenId dmsScreenId); 87 bool SetDisplayState(DisplayState state); 88 void UpdateRSTree(DisplayId displayId, DisplayId parentDisplayId, std::shared_ptr<RSSurfaceNode>& surfaceNode, 89 bool isAdd, bool isMultiDisplay); 90 DMError AddSurfaceNodeToDisplay(DisplayId displayId, 91 std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop = true); 92 DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode); 93 DisplayState GetDisplayState(DisplayId displayId); 94 bool TryToCancelScreenOff(); 95 bool SetScreenBrightness(uint64_t screenId, uint32_t level); 96 uint32_t GetScreenBrightness(uint64_t screenId); 97 void NotifyDisplayEvent(DisplayEvent event); 98 bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze); 99 100 DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenIds, ScreenId& screenGroupId); 101 DMError MakeExpand(std::vector<ScreenId> screenId, std::vector<Point> startPoints, 102 ScreenId& screenGroupId); 103 DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds); 104 DMError StopExpand(const std::vector<ScreenId>& expandScreenIds); 105 void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens); 106 sptr<ScreenInfo> GetScreenInfoById(ScreenId screenId); 107 sptr<ScreenGroupInfo> GetScreenGroupInfoById(ScreenId screenId); 108 sptr<DisplayInfo> GetDisplayInfoByScreenId(ScreenId screenId) const; 109 ScreenId GetScreenGroupIdByScreenId(ScreenId screenId); 110 DMError GetAllScreenInfos(std::vector<sptr<ScreenInfo>>& screenInfos); 111 112 std::vector<DisplayId> GetAllDisplayIds(); 113 DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 114 DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); SetResolution(ScreenId screenId,uint32_t width,uint32_t height,float virtualPixelRatio)115 DMError SetResolution(ScreenId screenId, uint32_t width, uint32_t height, 116 float virtualPixelRatio) { return DMError::DM_OK; } GetDensityInCurResolution(ScreenId screenId,float & virtualPixelRatio)117 DMError GetDensityInCurResolution(ScreenId screenId, 118 float& virtualPixelRatio) { return DMError::DM_OK; } 119 void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener); 120 void RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener); 121 void NotifyPrivateWindowStateChanged(bool hasPrivate); 122 std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalResolution(); 123 bool SetVirtualScreenAsDefault(ScreenId screenId); 124 125 private: 126 void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 127 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 128 void NotifyScreenshot(DisplayId displayId); 129 ScreenId GetScreenIdByDisplayId(DisplayId displayId) const; 130 void ConfigureDisplayManagerService(); 131 void ConfigureWaterfallDisplayCompressionParams(); 132 133 std::recursive_mutex mutex_; 134 static inline SingletonDelegator<DisplayManagerService> delegator_; 135 sptr<AbstractDisplayController> abstractDisplayController_; 136 sptr<AbstractScreenController> abstractScreenController_; 137 sptr<DisplayPowerController> displayPowerController_; 138 sptr<DisplayCutoutController> displayCutoutController_; 139 sptr<IDisplayChangeListener> displayChangeListener_; 140 sptr<IWindowInfoQueriedListener> windowInfoQueriedListener_; 141 sptr<DisplayDumper> displayDumper_; 142 AtomicMap<ScreenId, uint32_t> accessTokenIdMaps_; 143 bool isAutoRotationOpen_; 144 std::vector<DisplayPhysicalResolution> allDisplayPhysicalResolution_ {}; 145 }; 146 } // namespace OHOS::Rosen 147 148 #endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_SERVICE_H 149