1 /*
2 * Copyright (c) 2023 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 #include "display_lite.h"
16
17 #include <cstdint>
18 #include <new>
19 #include <refbase.h>
20
21 #include "class_var_definition.h"
22 #include "display_info.h"
23 #include "display_manager_adapter_lite.h"
24 #include "dm_common.h"
25 #include "singleton_container.h"
26 #include "window_manager_hilog.h"
27
28 namespace OHOS::Rosen {
29 namespace {
30 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayLite"};
31 }
32 class DisplayLite::Impl : public RefBase {
33 public:
Impl(const std::string & name,sptr<DisplayInfo> info)34 Impl(const std::string& name, sptr<DisplayInfo> info)
35 {
36 displayInfo_ = info;
37 name_= name;
38 }
39 ~Impl() = default;
40 DEFINE_VAR_FUNC_GET_SET_WITH_LOCK(sptr<DisplayInfo>, DisplayInfo, displayInfo);
41 DEFINE_VAR_FUNC_GET_SET(std::string, Name, name);
42 };
43
DisplayLite(const std::string & name,sptr<DisplayInfo> info)44 DisplayLite::DisplayLite(const std::string& name, sptr<DisplayInfo> info)
45 : pImpl_(new Impl(name, info))
46 {
47 }
48
~DisplayLite()49 DisplayLite::~DisplayLite()
50 {
51 }
52
GetId() const53 DisplayId DisplayLite::GetId() const
54 {
55 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
56 WLOGFE("pImpl_ or pImpl_->GetDisplayInfo is nullptr");
57 return DisplayId(0);
58 }
59 return pImpl_->GetDisplayInfo()->GetDisplayId();
60 }
61
GetDisplayInfo() const62 sptr<DisplayInfo> DisplayLite::GetDisplayInfo() const
63 {
64 UpdateDisplayInfo();
65 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
66 WLOGFE("pImpl_ or pImpl_->GetDisplayInfo is nullptr");
67 return nullptr;
68 }
69 return pImpl_->GetDisplayInfo();
70 }
71
GetWidth() const72 int32_t DisplayLite::GetWidth() const
73 {
74 UpdateDisplayInfo();
75 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
76 WLOGFE("pImpl_ or pImpl_->GetDisplayInfo is nullptr");
77 return 0;
78 }
79 return pImpl_->GetDisplayInfo()->GetWidth();
80 }
81
GetHeight() const82 int32_t DisplayLite::GetHeight() const
83 {
84 UpdateDisplayInfo();
85 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
86 WLOGFE("pImpl_ or pImpl_->GetDisplayInfo is nullptr");
87 return 0;
88 }
89 return pImpl_->GetDisplayInfo()->GetHeight();
90 }
91
GetCutoutInfo() const92 sptr<CutoutInfo> DisplayLite::GetCutoutInfo() const
93 {
94 return SingletonContainer::Get<DisplayManagerAdapterLite>().GetCutoutInfo(GetId());
95 }
96
UpdateDisplayInfo() const97 void DisplayLite::UpdateDisplayInfo() const
98 {
99 auto displayInfo = SingletonContainer::Get<DisplayManagerAdapterLite>().GetDisplayInfo(GetId());
100 UpdateDisplayInfo(displayInfo);
101 }
102
UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const103 void DisplayLite::UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const
104 {
105 if (displayInfo == nullptr) {
106 WLOGFE("displayInfo is nullptr");
107 return;
108 }
109 if (pImpl_ == nullptr) {
110 WLOGFE("pImpl_ is nullptr");
111 return;
112 }
113 pImpl_->SetDisplayInfo(displayInfo);
114 }
115
GetRotation() const116 Rotation DisplayLite::GetRotation() const
117 {
118 UpdateDisplayInfo();
119 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
120 WLOGFE("pImpl_ or pImpl_->GetDisplayInfo is nullptr");
121 return Rotation::ROTATION_0;
122 }
123 return pImpl_->GetDisplayInfo()->GetRotation();
124 }
125 } // namespace OHOS::Rosen
126