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