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 #include "display_manager_service_inner.h"
17
18 #include <cinttypes>
19 #include <iservice_registry.h>
20
21 #include "display_manager_service.h"
22 #include "window_manager_hilog.h"
23
24 namespace OHOS::Rosen {
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner)25 WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner)
26
27 DisplayId DisplayManagerServiceInner::GetDefaultDisplayId() const
28 {
29 auto defaultDisplayInfo = DisplayManagerService::GetInstance().GetDefaultDisplayInfo();
30 if (defaultDisplayInfo == nullptr) {
31 TLOGE(WmsLogTag::DMS, "defaultDisplayInfo is nullptr.");
32 return DISPLAY_ID_INVALID;
33 }
34 return defaultDisplayInfo->GetDisplayId();
35 }
36
GetDisplayById(DisplayId displayId) const37 sptr<DisplayInfo> DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) const
38 {
39 sptr<DisplayInfo> display = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
40 if (display == nullptr) {
41 TLOGE(WmsLogTag::DMS, "GetDisplayById can not find corresponding display!\n");
42 }
43 return display;
44 }
45
GetDefaultDisplay() const46 sptr<DisplayInfo> DisplayManagerServiceInner::GetDefaultDisplay() const
47 {
48 return DisplayManagerService::GetInstance().GetDefaultDisplayInfo();
49 }
50
GetAllDisplayIds() const51 std::vector<DisplayId> DisplayManagerServiceInner::GetAllDisplayIds() const
52 {
53 return DisplayManagerService::GetInstance().GetAllDisplayIds();
54 }
55
RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener> & listener)56 void DisplayManagerServiceInner::RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener)
57 {
58 DisplayManagerService::GetInstance().RegisterWindowInfoQueriedListener(listener);
59 }
60
GetAllDisplays() const61 std::vector<sptr<DisplayInfo>> DisplayManagerServiceInner::GetAllDisplays() const
62 {
63 std::vector<sptr<DisplayInfo>> res;
64 auto displayIds = GetAllDisplayIds();
65 for (auto displayId : displayIds) {
66 sptr<DisplayInfo> display = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
67 if (display != nullptr) {
68 res.emplace_back(display);
69 } else {
70 TLOGE(WmsLogTag::DMS, "GetAllDisplays display %" PRIu64" nullptr!", displayId);
71 }
72 }
73 return res;
74 }
75
UpdateRSTree(DisplayId displayId,DisplayId parentDisplayId,std::shared_ptr<RSSurfaceNode> & surfaceNode,bool isAdd,bool isMultiDisplay)76 void DisplayManagerServiceInner::UpdateRSTree(DisplayId displayId, DisplayId parentDisplayId,
77 std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd, bool isMultiDisplay)
78 {
79 DisplayManagerService::GetInstance().UpdateRSTree(displayId, parentDisplayId, surfaceNode, isAdd, isMultiDisplay);
80 }
81
GetScreenInfoByDisplayId(DisplayId displayId) const82 sptr<ScreenInfo> DisplayManagerServiceInner::GetScreenInfoByDisplayId(DisplayId displayId) const
83 {
84 auto displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
85 if (displayInfo == nullptr) {
86 TLOGE(WmsLogTag::DMS, "can not get display.");
87 return nullptr;
88 }
89 return DisplayManagerService::GetInstance().GetScreenInfoById(displayInfo->GetScreenId());
90 }
91
GetScreenGroupIdByDisplayId(DisplayId displayId) const92 ScreenId DisplayManagerServiceInner::GetScreenGroupIdByDisplayId(DisplayId displayId) const
93 {
94 auto displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
95 if (displayInfo == nullptr) {
96 TLOGE(WmsLogTag::DMS, "can not get display.");
97 return INVALID_SCREEN_ID;
98 }
99 return DisplayManagerService::GetInstance().GetScreenGroupIdByScreenId(displayInfo->GetScreenId());
100 }
101
GetScreenModesByDisplayId(DisplayId displayId) const102 sptr<SupportedScreenModes> DisplayManagerServiceInner::GetScreenModesByDisplayId(DisplayId displayId) const
103 {
104 const sptr<ScreenInfo> screenInfo = GetScreenInfoByDisplayId(displayId);
105 if (screenInfo == nullptr) {
106 TLOGE(WmsLogTag::DMS, "can not get display.");
107 return nullptr;
108 }
109 auto modes = screenInfo->GetModes();
110 auto id = screenInfo->GetModeId();
111 if (id >= modes.size()) {
112 TLOGE(WmsLogTag::DMS, "can not get screenMode.");
113 return nullptr;
114 }
115 return modes[id];
116 }
117
GetDisplaySnapshot(DisplayId displayId,DmErrorCode * errorCode,bool isUseDma,bool isCaptureFullOfScreen) const118 std::shared_ptr<Media::PixelMap> DisplayManagerServiceInner::GetDisplaySnapshot(DisplayId displayId,
119 DmErrorCode* errorCode, bool isUseDma, bool isCaptureFullOfScreen) const
120 {
121 return DisplayManagerService::GetInstance().GetDisplaySnapshot(displayId, errorCode, isUseDma,
122 isCaptureFullOfScreen);
123 }
124
RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)125 void DisplayManagerServiceInner::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
126 {
127 DisplayManagerService::GetInstance().RegisterDisplayChangeListener(listener);
128 }
129
SetOrientationFromWindow(DisplayId displayId,Orientation orientation,bool withAnimation)130 DMError DisplayManagerServiceInner::SetOrientationFromWindow(DisplayId displayId, Orientation orientation,
131 bool withAnimation)
132 {
133 auto displayInfo = GetDisplayById(displayId);
134 if (displayInfo == nullptr) {
135 return DMError::DM_ERROR_NULLPTR;
136 }
137 return DisplayManagerService::GetInstance().
138 SetOrientationFromWindow(displayInfo->GetScreenId(), orientation, withAnimation);
139 }
140
SetRotationFromWindow(DisplayId displayId,Rotation targetRotation,bool withAnimation)141 bool DisplayManagerServiceInner::SetRotationFromWindow(DisplayId displayId, Rotation targetRotation, bool withAnimation)
142 {
143 auto displayInfo = GetDisplayById(displayId);
144 if (displayInfo == nullptr) {
145 return false;
146 }
147 return DisplayManagerService::GetInstance().
148 SetRotationFromWindow(displayInfo->GetScreenId(), targetRotation, withAnimation);
149 }
150
SetGravitySensorSubscriptionEnabled()151 void DisplayManagerServiceInner::SetGravitySensorSubscriptionEnabled()
152 {
153 DisplayManagerService::GetInstance().SetGravitySensorSubscriptionEnabled();
154 }
155
GetCutoutInfo(DisplayId displayId) const156 sptr<CutoutInfo> DisplayManagerServiceInner::GetCutoutInfo(DisplayId displayId) const
157 {
158 return DisplayManagerService::GetInstance().GetCutoutInfo(displayId);
159 }
160
NotifyPrivateWindowStateChanged(bool hasPrivate)161 void DisplayManagerServiceInner::NotifyPrivateWindowStateChanged(bool hasPrivate)
162 {
163 return DisplayManagerService::GetInstance().NotifyPrivateWindowStateChanged(hasPrivate);
164 }
165 } // namespace OHOS::Rosen