• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "abstract_display.h"
17 
18 #include "abstract_screen_controller.h"
19 #include "display_manager_config.h"
20 #include "display_manager_service.h"
21 #include "window_manager_hilog.h"
22 
23 namespace OHOS::Rosen {
24 namespace {
25     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractDisplay"};
26     constexpr int32_t PAD_SCREEN_WIDTH = 2560;
27     constexpr int32_t PHONE_SCREEN_WIDTH = 2160;
28 }
29 
AbstractDisplay(DisplayId id,std::string name,sptr<SupportedScreenModes> & info,sptr<AbstractScreen> & absScreen)30 AbstractDisplay::AbstractDisplay(DisplayId id, std::string name,
31     sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen)
32     : id_(id),
33       name_(name),
34       screenId_(absScreen->dmsId_),
35       screenGroupId_(absScreen->groupDmsId_),
36       width_(info->width_),
37       height_(info->height_),
38       refreshRate_(info->refreshRate_),
39       orientation_(absScreen->orientation_)
40 {
41     RequestRotation(absScreen->rotation_);
42     auto numbersConfig = DisplayManagerConfig::GetIntNumbersConfig();
43     if (numbersConfig.count("dpi") != 0) {
44         uint32_t densityDpi = static_cast<uint32_t>(numbersConfig["dpi"][0]);
45         if (densityDpi >= DOT_PER_INCH_MINIMUM_VALUE && densityDpi <= DOT_PER_INCH_MAXIMUM_VALUE) {
46             virtualPixelRatio_ = static_cast<float>(densityDpi) / BASELINE_DENSITY;
47             absScreen->SetVirtualPixelRatio(virtualPixelRatio_);
48             return;
49         }
50     }
51     if ((info->width_ >= PHONE_SCREEN_WIDTH) || (info->height_ >= PHONE_SCREEN_WIDTH)) {
52         if ((info->width_ == PAD_SCREEN_WIDTH) || (info->height_ == PAD_SCREEN_WIDTH)) {
53             virtualPixelRatio_ = 2.0f; // Pad is 2.0
54         } else {
55             virtualPixelRatio_ = 3.0f; // Phone is 3.0
56         }
57     } else {
58         virtualPixelRatio_ = 1.0f; // Other is 1.0
59     }
60     absScreen->SetVirtualPixelRatio(virtualPixelRatio_);
61 }
62 
GetId() const63 DisplayId AbstractDisplay::GetId() const
64 {
65     return id_;
66 }
67 
GetWidth() const68 int32_t AbstractDisplay::GetWidth() const
69 {
70     return width_;
71 }
72 
GetHeight() const73 int32_t AbstractDisplay::GetHeight() const
74 {
75     return height_;
76 }
77 
GetRefreshRate() const78 uint32_t AbstractDisplay::GetRefreshRate() const
79 {
80     return refreshRate_;
81 }
82 
GetVirtualPixelRatio() const83 float AbstractDisplay::GetVirtualPixelRatio() const
84 {
85     return virtualPixelRatio_;
86 }
87 
GetOffsetX() const88 int32_t AbstractDisplay::GetOffsetX() const
89 {
90     return offsetX_;
91 }
92 
GetOffsetY() const93 int32_t AbstractDisplay::GetOffsetY() const
94 {
95     return offsetY_;
96 }
97 
SetOffsetX(int32_t offsetX)98 void AbstractDisplay::SetOffsetX(int32_t offsetX)
99 {
100     offsetX_ = offsetX;
101 }
102 
SetOffsetY(int32_t offsetY)103 void AbstractDisplay::SetOffsetY(int32_t offsetY)
104 {
105     offsetY_ = offsetY;
106 }
107 
SetWidth(int32_t width)108 void AbstractDisplay::SetWidth(int32_t width)
109 {
110     width_ = width;
111 }
112 
SetHeight(int32_t height)113 void AbstractDisplay::SetHeight(int32_t height)
114 {
115     height_ = height;
116 }
117 
SetOffset(int32_t offsetX,int32_t offsetY)118 void AbstractDisplay::SetOffset(int32_t offsetX, int32_t offsetY)
119 {
120     offsetX_ = offsetX;
121     offsetY_ = offsetY;
122 }
123 
SetRefreshRate(uint32_t refreshRate)124 void AbstractDisplay::SetRefreshRate(uint32_t refreshRate)
125 {
126     refreshRate_ = refreshRate;
127 }
128 
SetVirtualPixelRatio(float virtualPixelRatio)129 void AbstractDisplay::SetVirtualPixelRatio(float virtualPixelRatio)
130 {
131     virtualPixelRatio_ = virtualPixelRatio;
132 }
133 
SetId(DisplayId id)134 void AbstractDisplay::SetId(DisplayId id)
135 {
136     id_ = id;
137 }
138 
SetOrientation(Orientation orientation)139 void AbstractDisplay::SetOrientation(Orientation orientation)
140 {
141     orientation_ = orientation;
142 }
143 
RequestRotation(Rotation rotation)144 bool AbstractDisplay::RequestRotation(Rotation rotation)
145 {
146     WLOGD("request rotation from %{public}u to %{public}u, display %{public}" PRIu64"", rotation_, rotation, id_);
147     if (rotation_ == rotation) {
148         WLOGFE("rotation not change %{public}u", rotation);
149         return false;
150     }
151     if (IsVertical(rotation) != IsVertical(rotation_)) {
152         std::swap(width_, height_);
153     }
154     rotation_ = rotation;
155     return true;
156 }
157 
GetRotation() const158 Rotation AbstractDisplay::GetRotation() const
159 {
160     return rotation_;
161 }
162 
GetOrientation() const163 Orientation AbstractDisplay::GetOrientation() const
164 {
165     return orientation_;
166 }
167 
SetFreezeFlag(FreezeFlag freezeFlag)168 void AbstractDisplay::SetFreezeFlag(FreezeFlag freezeFlag)
169 {
170     freezeFlag_ = freezeFlag;
171 }
172 
GetFreezeFlag() const173 FreezeFlag AbstractDisplay::GetFreezeFlag() const
174 {
175     return freezeFlag_;
176 }
177 
BindAbstractScreen(sptr<AbstractScreen> abstractScreen)178 bool AbstractDisplay::BindAbstractScreen(sptr<AbstractScreen> abstractScreen)
179 {
180     if (abstractScreen == nullptr) {
181         WLOGE("display bind screen error, cannot get screen. display:%{public}" PRIu64"", id_);
182         return false;
183     }
184     ScreenId dmsScreenId = abstractScreen->dmsId_;
185     sptr<SupportedScreenModes> info = abstractScreen->GetActiveScreenMode();
186     if (info == nullptr) {
187         WLOGE("display bind screen error, cannot get info. display:%{public}" PRIu64", screen:%{public}" PRIu64"",
188             id_, dmsScreenId);
189         return false;
190     }
191 
192     Point point = abstractScreen->GetGroup()->GetChildPosition(dmsScreenId);
193     offsetX_ = point.posX_;
194     offsetY_ = point.posY_;
195     width_ = static_cast<int32_t>(info->width_);
196     height_ = static_cast<int32_t>(info->height_);
197     refreshRate_ = info->refreshRate_;
198     screenId_ = dmsScreenId;
199     WLOGD("display bind to screen. display:%{public}" PRIu64", screen:%{public}" PRIu64"", id_, dmsScreenId);
200     return true;
201 }
202 
GetAbstractScreenId() const203 ScreenId AbstractDisplay::GetAbstractScreenId() const
204 {
205     return screenId_;
206 }
207 
GetAbstractScreenGroupId() const208 ScreenId AbstractDisplay::GetAbstractScreenGroupId() const
209 {
210     return screenGroupId_;
211 }
212 
ConvertToDisplayInfo() const213 sptr<DisplayInfo> AbstractDisplay::ConvertToDisplayInfo() const
214 {
215     sptr<DisplayInfo> displayInfo = new(std::nothrow) DisplayInfo();
216     if (displayInfo == nullptr) {
217         return displayInfo;
218     }
219     displayInfo->name_ = name_;
220     displayInfo->SetOffsetX(offsetX_);
221     displayInfo->SetOffsetY(offsetY_);
222     displayInfo->SetWidth(width_);
223     displayInfo->SetHeight(height_);
224     displayInfo->SetDisplayId(id_);
225     displayInfo->SetRefreshRate(refreshRate_);
226     displayInfo->SetScreenId(screenId_);
227     displayInfo->SetScreenGroupId(screenGroupId_);
228     displayInfo->SetVirtualPixelRatio(virtualPixelRatio_);
229     displayInfo->SetRotation(rotation_);
230     displayInfo->SetOrientation(orientation_);
231     displayInfo->displayState_ = displayState_;
232     displayInfo->SetWaterfallDisplayCompressionStatus(waterfallDisplayCompressionStatus_);
233     return displayInfo;
234 }
235 } // namespace OHOS::Rosen