• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h"
17 #include "platform/common/rs_log.h"
18 
19 namespace OHOS {
20 namespace Rosen {
21 
VisualEffect(const VisualEffect & visualEffect)22 VisualEffect::VisualEffect(const VisualEffect& visualEffect)
23 {
24     const auto& visualEffectParas = visualEffect.GetAllPara();
25     for (const auto& para : visualEffectParas) {
26         bool isInvalid =
27             (para == nullptr || !VisualEffectPara::IsWhitelistPara(static_cast<uint16_t>(para->GetParaType())));
28         if (isInvalid) {
29             RS_LOGE("[ui_effect] VisualEffect para copy failed");
30             continue;
31         }
32         if (auto paraCopy = para->Clone(); paraCopy) {
33             AddPara(paraCopy);
34         }
35     }
36 }
37 
Marshalling(Parcel & parcel) const38 bool VisualEffect::Marshalling(Parcel& parcel) const
39 {
40     const auto& visualEffectParas = GetAllPara();
41     size_t validParaCount = 0;
42     std::vector<std::shared_ptr<VisualEffectPara>> validVisualEffectParas;
43     for (const auto& para : visualEffectParas) {
44         bool isInvalid =
45             (para == nullptr || !VisualEffectPara::IsWhitelistPara(static_cast<uint16_t>(para->GetParaType())));
46         if (!isInvalid) {
47             validParaCount++;
48             validVisualEffectParas.emplace_back(para);
49         }
50     }
51     if (validParaCount > VisualEffectPara::UNMARSHALLING_MAX_VECTOR_SIZE) {
52         RS_LOGE("[ui_effect] VisualEffect Marshalling validParaCount is illegal");
53         return false;
54     }
55     if (!parcel.WriteUint32(validParaCount)) {
56         RS_LOGE("[ui_effect] VisualEffect Marshalling write validParaCount failed");
57         return false;
58     }
59     for (const auto& visualEffectPara : validVisualEffectParas) {
60         if (!visualEffectPara->Marshalling(parcel)) {
61             RS_LOGE("[ui_effect] VisualEffect Marshalling failed, type is %{public}d", visualEffectPara->GetParaType());
62             return false;
63         }
64     }
65     return true;
66 }
67 
Unmarshalling(Parcel & parcel,std::shared_ptr<VisualEffect> & val)68 bool VisualEffect::Unmarshalling(Parcel& parcel, std::shared_ptr<VisualEffect>& val)
69 {
70     uint32_t size = 0;
71     if (!parcel.ReadUint32(size)) {
72         RS_LOGE("[ui_effect] VisualEffect Unmarshalling read size failed");
73         return false;
74     }
75     if (size > VisualEffectPara::UNMARSHALLING_MAX_VECTOR_SIZE) {
76         RS_LOGE("[ui_effect] VisualEffect Unmarshalling read size is illegal");
77         return false;
78     }
79 
80     auto visualEffect = std::make_shared<VisualEffect>();
81     for (uint32_t i = 0; i < size; ++i) {
82         std::shared_ptr<VisualEffectPara> para = nullptr;
83         bool isSuccess = (VisualEffectPara::Unmarshalling(parcel, para) && para != nullptr);
84         if (!isSuccess) {
85             RS_LOGE("[ui_effect] VisualEffect Unmarshalling para failed");
86             return false;
87         }
88         visualEffect->AddPara(para);
89     }
90     val = std::move(visualEffect);
91     return true;
92 }
93 
94 } // namespace Rosen
95 } // namespace OHOS