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 return DisplayManagerService::GetInstance().GetDefaultDisplayId();
33 }
34
GetDisplayById(DisplayId displayId) const35 sptr<DisplayInfo> DisplayManagerServiceInner::GetDisplayById(DisplayId displayId) const
36 {
37 sptr<DisplayInfo> display = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
38 if (display == nullptr) {
39 WLOGFE("GetDisplayById can not find corresponding display!\n");
40 }
41 return display;
42 }
43
GetDefaultDisplay() const44 sptr<DisplayInfo> DisplayManagerServiceInner::GetDefaultDisplay() const
45 {
46 DisplayId defaultDisplayId = GetDefaultDisplayId();
47 if (defaultDisplayId == DISPLAY_ID_INVALID) {
48 WLOGFE("Fail to get default displayId");
49 return nullptr;
50 }
51 return DisplayManagerService::GetInstance().GetDisplayInfoById(defaultDisplayId);
52 }
53
GetAllDisplayIds() const54 std::vector<DisplayId> DisplayManagerServiceInner::GetAllDisplayIds() const
55 {
56 return DisplayManagerService::GetInstance().GetAllDisplayIds();
57 }
58
GetAllDisplays() const59 std::vector<sptr<DisplayInfo>> DisplayManagerServiceInner::GetAllDisplays() const
60 {
61 std::vector<sptr<DisplayInfo>> res;
62 auto displayIds = GetAllDisplayIds();
63 for (auto displayId: displayIds) {
64 sptr<DisplayInfo> display = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
65 if (display != nullptr) {
66 res.emplace_back(display);
67 } else {
68 WLOGFE("GetAllDisplays display %" PRIu64" nullptr!", displayId);
69 }
70 }
71 return res;
72 }
73
UpdateRSTree(DisplayId displayId,std::shared_ptr<RSSurfaceNode> & surfaceNode,bool isAdd)74 void DisplayManagerServiceInner::UpdateRSTree(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode,
75 bool isAdd)
76 {
77 DisplayManagerService::GetInstance().UpdateRSTree(displayId, surfaceNode, isAdd);
78 }
79
GetRSScreenId(DisplayId displayId) const80 ScreenId DisplayManagerServiceInner::GetRSScreenId(DisplayId displayId) const
81 {
82 return DisplayManagerService::GetInstance().GetRSScreenId(displayId);
83 }
84
GetScreenInfoByDisplayId(DisplayId displayId) const85 sptr<ScreenInfo> DisplayManagerServiceInner::GetScreenInfoByDisplayId(DisplayId displayId) const
86 {
87 auto displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
88 if (displayInfo == nullptr) {
89 WLOGFE("can not get display.");
90 return nullptr;
91 }
92 return DisplayManagerService::GetInstance().GetScreenInfoById(displayInfo->GetScreenId());
93 }
94
GetScreenModesByDisplayId(DisplayId displayId) const95 sptr<SupportedScreenModes> DisplayManagerServiceInner::GetScreenModesByDisplayId(DisplayId displayId) const
96 {
97 const sptr<ScreenInfo> screenInfo = GetScreenInfoByDisplayId(displayId);
98 if (screenInfo == nullptr) {
99 WLOGFE("can not get display.");
100 return nullptr;
101 }
102 auto modes = screenInfo->GetModes();
103 auto id = screenInfo->GetModeId();
104 if (id >= modes.size()) {
105 WLOGFE("can not get screenMode.");
106 return nullptr;
107 }
108 return modes[id];
109 }
110
GetDisplaySnapshot(DisplayId displayId) const111 std::shared_ptr<Media::PixelMap> DisplayManagerServiceInner::GetDisplaySnapshot(DisplayId displayId) const
112 {
113 return DisplayManagerService::GetInstance().GetDisplaySnapshot(displayId);
114 }
115
RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)116 void DisplayManagerServiceInner::RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener)
117 {
118 DisplayManagerService::GetInstance().RegisterDisplayChangeListener(listener);
119 }
120
SetOrientationFromWindow(DisplayId displayId,Orientation orientation)121 bool DisplayManagerServiceInner::SetOrientationFromWindow(DisplayId displayId, Orientation orientation)
122 {
123 auto displayInfo = GetDisplayById(displayId);
124 if (displayInfo == nullptr) {
125 return false;
126 }
127 return DisplayManagerService::GetInstance().
128 SetOrientationFromWindow(displayInfo->GetScreenId(), orientation);
129 }
130 } // namespace OHOS::Rosen