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