1 /*
2 * Copyright (c) 2025 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 "ui_effect/mask/include/mask_para.h"
17
18 #include <unordered_set>
19
20 #include "ui_effect/mask/include/mask_unmarshalling_singleton.h"
21 #include "platform/common/rs_log.h"
22
23 namespace OHOS {
24 namespace Rosen {
25
Marshalling(Parcel & parcel) const26 bool MaskPara::Marshalling(Parcel& parcel) const
27 {
28 RS_LOGE("[ui_effect] MaskPara do not marshalling non-specified type: %{public}d", type_);
29 return false;
30 }
31
RegisterUnmarshallingCallback(uint16_t type,UnmarshallingFunc func)32 bool MaskPara::RegisterUnmarshallingCallback(uint16_t type, UnmarshallingFunc func)
33 {
34 bool isInvalid = (func == nullptr || !MaskPara::IsWhitelistPara(type));
35 if (isInvalid) {
36 RS_LOGE("[ui_effect] MaskPara register unmarshalling type:%{public}hu callback failed", type);
37 return false;
38 }
39 MaskUnmarshallingSingleton::GetInstance().RegisterCallback(type, func);
40 return true;
41 }
42
Unmarshalling(Parcel & parcel,std::shared_ptr<MaskPara> & val)43 bool MaskPara::Unmarshalling(Parcel& parcel, std::shared_ptr<MaskPara>& val)
44 {
45 val.reset();
46 uint16_t type = Type::NONE;
47 if (!parcel.ReadUint16(type)) {
48 RS_LOGE("[ui_effect] MaskPara Unmarshalling read type failed");
49 return false;
50 }
51 bool isInvalid = (!MaskPara::IsWhitelistPara(type));
52 if (isInvalid) {
53 RS_LOGE("[ui_effect] MaskPara Unmarshalling read type invalid");
54 return false;
55 }
56
57 auto func = MaskUnmarshallingSingleton::GetInstance().GetCallback(type);
58 if (func != nullptr) {
59 return func(parcel, val);
60 }
61 RS_LOGE("[ui_effect] MaskPara Unmarshalling func invalid, type is %{public}hu", type);
62 return false;
63 }
64
Clone() const65 std::shared_ptr<MaskPara> MaskPara::Clone() const
66 {
67 RS_LOGE("[ui_effect] MaskPara do not clone non-specified type: %{public}d", type_);
68 return nullptr;
69 }
70
IsWhitelistPara(uint16_t type)71 bool MaskPara::IsWhitelistPara(uint16_t type)
72 {
73 static const std::unordered_set<uint16_t> whitelist = {
74 static_cast<uint16_t>(Type::RADIAL_GRADIENT_MASK),
75 static_cast<uint16_t>(Type::PIXEL_MAP_MASK)
76 };
77
78 auto find = whitelist.find(type);
79 if (find != whitelist.end()) {
80 return true;
81 }
82
83 RS_LOGE("[ui_effect] MaskPara This %{public}hu para is not allowed to be operated", type);
84 return false;
85 }
86
87 } // namespace Rosen
88 } // namespace OHOS