• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 "js_runtime_utils.h"
17 #include "picture_in_picture_option.h"
18 #include "window_manager_hilog.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 constexpr uint32_t PIP_LOW_PRIORITY = 0;
23 constexpr uint32_t PIP_HIGH_PRIORITY = 1;
PipOption()24 PipOption::PipOption()
25 {
26 }
27 
ClearNapiRefs(napi_env env)28 void PipOption::ClearNapiRefs(napi_env env)
29 {
30     if (customNodeController_) {
31         napi_delete_reference(env, customNodeController_);
32         customNodeController_ = nullptr;
33     }
34     if (typeNode_) {
35         napi_delete_reference(env, typeNode_);
36         typeNode_ = nullptr;
37     }
38     if (storage_) {
39         napi_delete_reference(env, storage_);
40         storage_ = nullptr;
41     }
42 }
43 
SetContext(void * contextPtr)44 void PipOption::SetContext(void* contextPtr)
45 {
46     contextPtr_ = contextPtr;
47 }
48 
SetNavigationId(const std::string & navigationId)49 void PipOption::SetNavigationId(const std::string& navigationId)
50 {
51     navigationId_ = navigationId;
52 }
53 
SetPipTemplate(uint32_t templateType)54 void PipOption::SetPipTemplate(uint32_t templateType)
55 {
56     templateType_ = templateType;
57 }
58 
SetDefaultWindowSizeType(uint32_t defaultWindowSizeType)59 void PipOption::SetDefaultWindowSizeType(uint32_t defaultWindowSizeType)
60 {
61     defaultWindowSizeType_ = defaultWindowSizeType;
62 }
63 
SetPiPControlStatus(PiPControlType controlType,PiPControlStatus status)64 void PipOption::SetPiPControlStatus(PiPControlType controlType, PiPControlStatus status)
65 {
66     for (auto& controlStatusInfo : pipControlStatusInfoList_) {
67         if (controlType == controlStatusInfo.controlType) {
68             controlStatusInfo.status = status;
69             return;
70         }
71     }
72     PiPControlStatusInfo newPiPControlStatusInfo {controlType, status};
73     pipControlStatusInfoList_.push_back(newPiPControlStatusInfo);
74 }
75 
SetPiPControlEnabled(PiPControlType controlType,PiPControlStatus enabled)76 void PipOption::SetPiPControlEnabled(PiPControlType controlType, PiPControlStatus enabled)
77 {
78     for (auto& controlEnableInfo : pipControlEnableInfoList_) {
79         if (controlType == controlEnableInfo.controlType) {
80             controlEnableInfo.enabled = enabled;
81             return;
82         }
83     }
84     PiPControlEnableInfo newPiPControlEnableInfo {controlType, enabled};
85     pipControlEnableInfoList_.push_back(newPiPControlEnableInfo);
86 }
87 
SetContentSize(uint32_t width,uint32_t height)88 void PipOption::SetContentSize(uint32_t width, uint32_t height)
89 {
90     contentWidth_ = width;
91     contentHeight_ = height;
92 }
93 
94 // LCOV_EXCL_START
SetControlGroup(std::vector<std::uint32_t> controlGroup)95 void PipOption::SetControlGroup(std::vector<std::uint32_t> controlGroup)
96 {
97     controlGroup_ = controlGroup;
98 }
99 
SetNodeControllerRef(napi_ref ref)100 void PipOption::SetNodeControllerRef(napi_ref ref)
101 {
102     customNodeController_ = ref;
103 }
104 
SetStorageRef(napi_ref ref)105 void PipOption::SetStorageRef(napi_ref ref)
106 {
107     storage_ = ref;
108 }
109 
GetNodeControllerRef() const110 napi_ref PipOption::GetNodeControllerRef() const
111 {
112     return customNodeController_;
113 }
114 
GetStorageRef() const115 napi_ref PipOption::GetStorageRef() const
116 {
117     return storage_;
118 }
119 
SetTypeNodeRef(napi_ref ref)120 void PipOption::SetTypeNodeRef(napi_ref ref)
121 {
122     typeNode_ = ref;
123 }
124 
GetTypeNodeRef() const125 napi_ref PipOption::GetTypeNodeRef() const
126 {
127     return typeNode_;
128 }
129 
GetContext() const130 void* PipOption::GetContext() const
131 {
132     return contextPtr_;
133 }
134 // LCOV_EXCL_STOP
135 
GetNavigationId() const136 std::string PipOption::GetNavigationId() const
137 {
138     return navigationId_;
139 }
140 
GetPipTemplate()141 uint32_t PipOption::GetPipTemplate()
142 {
143     return templateType_;
144 }
145 
GetDefaultWindowSizeType() const146 uint32_t PipOption::GetDefaultWindowSizeType() const
147 {
148     return defaultWindowSizeType_;
149 }
150 
GetContentSize(uint32_t & width,uint32_t & height)151 void PipOption::GetContentSize(uint32_t& width, uint32_t& height)
152 {
153     width = contentWidth_;
154     height = contentHeight_;
155 }
156 
157 // LCOV_EXCL_START
GetControlGroup()158 std::vector<std::uint32_t> PipOption::GetControlGroup()
159 {
160     return controlGroup_;
161 }
162 
GetControlStatus()163 std::vector<PiPControlStatusInfo> PipOption::GetControlStatus()
164 {
165     return pipControlStatusInfoList_;
166 }
167 
GetControlEnable()168 std::vector<PiPControlEnableInfo> PipOption::GetControlEnable()
169 {
170     return pipControlEnableInfoList_;
171 }
172 // LCOV_EXCL_STOP
173 
SetXComponentController(std::shared_ptr<XComponentController> xComponentController)174 void PipOption::SetXComponentController(std::shared_ptr<XComponentController> xComponentController)
175 {
176     xComponentController_ = xComponentController;
177 }
178 
GetXComponentController()179 std::shared_ptr<XComponentController> PipOption::GetXComponentController()
180 {
181     return xComponentController_;
182 }
183 
SetTypeNodeEnabled(bool enable)184 void PipOption::SetTypeNodeEnabled(bool enable)
185 {
186     useTypeNode_ = enable;
187 }
188 
IsTypeNodeEnabled() const189 bool PipOption::IsTypeNodeEnabled() const
190 {
191     return useTypeNode_;
192 }
193 
GetPipPriority(uint32_t pipTemplateType) const194 uint32_t PipOption::GetPipPriority(uint32_t pipTemplateType) const
195 {
196     if (pipTemplateType >= static_cast<uint32_t>(PiPTemplateType::END)) {
197         TLOGE(WmsLogTag::WMS_PIP, "param invalid, pipTemplateType is %{public}d", pipTemplateType);
198         return PIP_LOW_PRIORITY;
199     }
200     if (pipTemplateType == static_cast<uint32_t>(PiPTemplateType::VIDEO_PLAY) ||
201         pipTemplateType == static_cast<uint32_t>(PiPTemplateType::VIDEO_LIVE)) {
202         return PIP_LOW_PRIORITY;
203     } else {
204         return PIP_HIGH_PRIORITY;
205     }
206 }
207 
208 // LCOV_EXCL_START
GetPiPTemplateInfo(PiPTemplateInfo & pipTemplateInfo)209 void PipOption::GetPiPTemplateInfo(PiPTemplateInfo& pipTemplateInfo)
210 {
211     pipTemplateInfo.pipTemplateType = templateType_;
212     pipTemplateInfo.controlGroup = controlGroup_;
213     pipTemplateInfo.priority = GetPipPriority(templateType_);
214     pipTemplateInfo.defaultWindowSizeType = defaultWindowSizeType_;
215     pipTemplateInfo.pipControlStatusInfoList = pipControlStatusInfoList_;
216     pipTemplateInfo.pipControlEnableInfoList = pipControlEnableInfoList_;
217 }
218 // LCOV_EXCL_STOP
219 } // namespace Rosen
220 } // namespace OHOS