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/effect/include/visual_effect_para.h"
17
18 #include <unordered_set>
19
20 #include "ui_effect/effect/include/visual_effect_unmarshalling_singleton.h"
21 #include "platform/common/rs_log.h"
22
23 namespace OHOS {
24 namespace Rosen {
25
Marshalling(Parcel & parcel) const26 bool VisualEffectPara::Marshalling(Parcel& parcel) const
27 {
28 RS_LOGE("[ui_effect] VisualEffectPara do not marshalling non-specified type: %{public}d", type_);
29 return false;
30 }
31
RegisterUnmarshallingCallback(uint16_t type,UnmarshallingFunc func)32 bool VisualEffectPara::RegisterUnmarshallingCallback(uint16_t type, UnmarshallingFunc func)
33 {
34 bool isInvalid = (func == nullptr || !VisualEffectPara::IsWhitelistPara(type));
35 if (isInvalid) {
36 RS_LOGE("[ui_effect] VisualEffectPara register unmarshalling type:%{public}hu callback failed", type);
37 return false;
38 }
39 VisualEffectUnmarshallingSingleton::GetInstance().RegisterCallback(type, func);
40 return true;
41 }
42
Unmarshalling(Parcel & parcel,std::shared_ptr<VisualEffectPara> & val)43 bool VisualEffectPara::Unmarshalling(Parcel& parcel, std::shared_ptr<VisualEffectPara>& val)
44 {
45 val.reset();
46 uint16_t type = ParaType::NONE;
47 if (!parcel.ReadUint16(type)) {
48 RS_LOGE("[ui_effect] VisualEffectPara Unmarshalling read type failed");
49 return false;
50 }
51 bool isInvalid = (!VisualEffectPara::IsWhitelistPara(type));
52 if (isInvalid) {
53 RS_LOGE("[ui_effect] VisualEffectPara Unmarshalling read type invalid");
54 return false;
55 }
56
57 auto func = VisualEffectUnmarshallingSingleton::GetInstance().GetCallback(type);
58 if (func != nullptr) {
59 return func(parcel, val);
60 }
61 RS_LOGE("[ui_effect] VisualEffectPara Unmarshalling func invalid, type is %{public}hu", type);
62 return false;
63 }
64
Clone() const65 std::shared_ptr<VisualEffectPara> VisualEffectPara::Clone() const
66 {
67 RS_LOGE("[ui_effect] VisualEffectPara do not clone non-specified type: %{public}d", type_);
68 return nullptr;
69 }
70
IsWhitelistPara(uint16_t type)71 bool VisualEffectPara::IsWhitelistPara(uint16_t type)
72 {
73 return (type == static_cast<uint16_t>(ParaType::HDS_EFFECT_BEGIN));
74 }
75
76 } // namespace Rosen
77 } // namespace OHOS