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 class DisplayLite::Impl : public RefBase {
31 public:
Impl(const std::string & name,sptr<DisplayInfo> info)32 Impl(const std::string& name, sptr<DisplayInfo> info)
33 {
34 displayInfo_ = info;
35 name_= name;
36 }
37 ~Impl() = default;
38 DEFINE_VAR_FUNC_GET_SET_WITH_LOCK(sptr<DisplayInfo>, DisplayInfo, displayInfo);
39 DEFINE_VAR_FUNC_GET_SET(std::string, Name, name);
40 };
41
DisplayLite(const std::string & name,sptr<DisplayInfo> info)42 DisplayLite::DisplayLite(const std::string& name, sptr<DisplayInfo> info)
43 : pImpl_(new Impl(name, info))
44 {
45 }
46
~DisplayLite()47 DisplayLite::~DisplayLite()
48 {
49 }
50
GetId() const51 DisplayId DisplayLite::GetId() const
52 {
53 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
54 TLOGE(WmsLogTag::DMS, "pImpl_ or pImpl_->GetDisplayInfo is nullptr");
55 return DisplayId(0);
56 }
57 return pImpl_->GetDisplayInfo()->GetDisplayId();
58 }
59
GetDisplayInfo() const60 sptr<DisplayInfo> DisplayLite::GetDisplayInfo() const
61 {
62 UpdateDisplayInfo();
63 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
64 TLOGE(WmsLogTag::DMS, "pImpl_ or pImpl_->GetDisplayInfo is nullptr");
65 return nullptr;
66 }
67 return pImpl_->GetDisplayInfo();
68 }
69
GetWidth() const70 int32_t DisplayLite::GetWidth() const
71 {
72 UpdateDisplayInfo();
73 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
74 TLOGE(WmsLogTag::DMS, "pImpl_ or pImpl_->GetDisplayInfo is nullptr");
75 return 0;
76 }
77 return pImpl_->GetDisplayInfo()->GetWidth();
78 }
79
GetHeight() const80 int32_t DisplayLite::GetHeight() const
81 {
82 UpdateDisplayInfo();
83 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
84 TLOGE(WmsLogTag::DMS, "pImpl_ or pImpl_->GetDisplayInfo is nullptr");
85 return 0;
86 }
87 return pImpl_->GetDisplayInfo()->GetHeight();
88 }
89
GetCutoutInfo() const90 sptr<CutoutInfo> DisplayLite::GetCutoutInfo() const
91 {
92 return SingletonContainer::Get<DisplayManagerAdapterLite>().GetCutoutInfo(GetId());
93 }
94
UpdateDisplayInfo() const95 void DisplayLite::UpdateDisplayInfo() const
96 {
97 auto displayInfo = SingletonContainer::Get<DisplayManagerAdapterLite>().GetDisplayInfo(GetId());
98 UpdateDisplayInfo(displayInfo);
99 }
100
UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const101 void DisplayLite::UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const
102 {
103 if (displayInfo == nullptr) {
104 TLOGE(WmsLogTag::DMS, "displayInfo is nullptr");
105 return;
106 }
107 if (pImpl_ == nullptr) {
108 TLOGE(WmsLogTag::DMS, "pImpl_ is nullptr");
109 return;
110 }
111 pImpl_->SetDisplayInfo(displayInfo);
112 }
113
GetRotation() const114 Rotation DisplayLite::GetRotation() const
115 {
116 UpdateDisplayInfo();
117 if (pImpl_ == nullptr || pImpl_->GetDisplayInfo() == nullptr) {
118 TLOGE(WmsLogTag::DMS, "pImpl_ or pImpl_->GetDisplayInfo is nullptr");
119 return Rotation::ROTATION_0;
120 }
121 return pImpl_->GetDisplayInfo()->GetRotation();
122 }
123 } // namespace OHOS::Rosen
124