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 {
25 namespace {
26 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerServiceInner"};
27 }
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner)28 WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner)
29
30 DisplayId DisplayManagerServiceInner::GetDefaultDisplayId() const
31 {
32 auto defaultDisplayInfo = DisplayManagerService::GetInstance().GetDefaultDisplayInfo();
33 if (defaultDisplayInfo == nullptr) {
34 WLOGFE("GetDefaultDisplayId, defaultDisplayInfo is nullptr.");
35 return DISPLAY_ID_INVALID;
36 }
37 return defaultDisplayInfo->GetDisplayId();
38 }
39
GetDisplayById(DisplayId displayId) const40 sptr<DisplayInfo> DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) const
41 {
42 sptr<DisplayInfo> display = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
43 if (display == nullptr) {
44 WLOGFE("GetDisplayById can not find corresponding display!\n");
45 }
46 return display;
47 }
48
GetDefaultDisplay() const49 sptr<DisplayInfo> DisplayManagerServiceInner::GetDefaultDisplay() const
50 {
51 return DisplayManagerService::GetInstance().GetDefaultDisplayInfo();
52 }
53
GetAllDisplayIds() const54 std::vector<DisplayId> DisplayManagerServiceInner::GetAllDisplayIds() const
55 {
56 return DisplayManagerService::GetInstance().GetAllDisplayIds();
57 }
58
RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener> & listener)59 void DisplayManagerServiceInner::RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener)
60 {
61 DisplayManagerService::GetInstance().RegisterWindowInfoQueriedListener(listener);
62 }
63
GetAllDisplays() const64 std::vector<sptr<DisplayInfo>> DisplayManagerServiceInner::GetAllDisplays() const
65 {
66 std::vector<sptr<DisplayInfo>> res;
67 auto displayIds = GetAllDisplayIds();
68 for (auto displayId: displayIds) {
69 sptr<DisplayInfo> display = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
70 if (display != nullptr) {
71 res.emplace_back(display);
72 } else {
73 WLOGFE("GetAllDisplays display %" PRIu64" nullptr!", displayId);
74 }
75 }
76 return res;
77 }
78
UpdateRSTree(DisplayId displayId,DisplayId parentDisplayId,std::shared_ptr<RSSurfaceNode> & surfaceNode,bool isAdd,bool isMultiDisplay)79 void DisplayManagerServiceInner::UpdateRSTree(DisplayId displayId, DisplayId parentDisplayId,
80 std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd, bool isMultiDisplay)
81 {
82 DisplayManagerService::GetInstance().UpdateRSTree(displayId, parentDisplayId, surfaceNode, isAdd, isMultiDisplay);
83 }
84
GetRSScreenNum() const85 uint32_t DisplayManagerServiceInner::GetRSScreenNum() const
86 {
87 return DisplayManagerService::GetInstance().GetRSScreenNum();
88 }
89
GetScreenInfoByDisplayId(DisplayId displayId) const90 sptr<ScreenInfo> DisplayManagerServiceInner::GetScreenInfoByDisplayId(DisplayId displayId) const
91 {
92 auto displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
93 if (displayInfo == nullptr) {
94 WLOGFE("can not get display.");
95 return nullptr;
96 }
97 return DisplayManagerService::GetInstance().GetScreenInfoById(displayInfo->GetScreenId());
98 }
99
GetScreenGroupIdByDisplayId(DisplayId displayId) const100 ScreenId DisplayManagerServiceInner::GetScreenGroupIdByDisplayId(DisplayId displayId) const
101 {
102 auto displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
103 if (displayInfo == nullptr) {
104 WLOGFE("can not get display.");
105 return INVALID_SCREEN_ID;
106 }
107 return DisplayManagerService::GetInstance().GetScreenGroupIdByScreenId(displayInfo->GetScreenId());
108 }
109
GetScreenModesByDisplayId(DisplayId displayId) const110 sptr<SupportedScreenModes> DisplayManagerServiceInner::GetScreenModesByDisplayId(DisplayId displayId) const
111 {
112 const sptr<ScreenInfo> screenInfo = GetScreenInfoByDisplayId(displayId);
113 if (screenInfo == nullptr) {
114 WLOGFE("can not get display.");
115 return nullptr;
116 }
117 auto modes = screenInfo->GetModes();
118 auto id = screenInfo->GetModeId();
119 if (id >= modes.size()) {
120 WLOGFE("can not get screenMode.");
121 return nullptr;
122 }
123 return modes[id];
124 }
125
GetDisplaySnapshot(DisplayId displayId) const126 std::shared_ptr<Media::PixelMap> DisplayManagerServiceInner::GetDisplaySnapshot(DisplayId displayId) const
127 {
128 return DisplayManagerService::GetInstance().GetDisplaySnapshot(displayId);
129 }
130
RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)131 void DisplayManagerServiceInner::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
132 {
133 DisplayManagerService::GetInstance().RegisterDisplayChangeListener(listener);
134 }
135
SetOrientationFromWindow(DisplayId displayId,Orientation orientation)136 bool DisplayManagerServiceInner::SetOrientationFromWindow(DisplayId displayId, Orientation orientation)
137 {
138 auto displayInfo = GetDisplayById(displayId);
139 if (displayInfo == nullptr) {
140 return false;
141 }
142 return DisplayManagerService::GetInstance().
143 SetOrientationFromWindow(displayInfo->GetScreenId(), orientation);
144 }
145
SetRotationFromWindow(DisplayId displayId,Rotation targetRotation)146 bool DisplayManagerServiceInner::SetRotationFromWindow(DisplayId displayId, Rotation targetRotation)
147 {
148 auto displayInfo = GetDisplayById(displayId);
149 if (displayInfo == nullptr) {
150 return false;
151 }
152 return DisplayManagerService::GetInstance().
153 SetRotationFromWindow(displayInfo->GetScreenId(), targetRotation);
154 }
155
SetGravitySensorSubscriptionEnabled()156 void DisplayManagerServiceInner::SetGravitySensorSubscriptionEnabled()
157 {
158 DisplayManagerService::GetInstance().SetGravitySensorSubscriptionEnabled();
159 }
160
RegisterRSScreenChangeListener(const sptr<IRSScreenChangeListener> & listener)161 void DisplayManagerServiceInner::RegisterRSScreenChangeListener(const sptr<IRSScreenChangeListener>& listener)
162 {
163 DisplayManagerService::GetInstance().RegisterRSScreenChangeListener(listener);
164 }
165
GetCutoutInfo(DisplayId displayId) const166 sptr<CutoutInfo> DisplayManagerServiceInner::GetCutoutInfo(DisplayId displayId) const
167 {
168 return DisplayManagerService::GetInstance().GetCutoutInfo(displayId);
169 }
170 } // namespace OHOS::Rosen