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/pixel_map_mask_para.h"
17 #include "platform/common/rs_log.h"
18
19 #ifdef ROSEN_OHOS
20 #include "media_errors.h"
21 #endif
22
23 namespace OHOS {
24 namespace Rosen {
25
PixelMapMaskPara(const PixelMapMaskPara & other)26 PixelMapMaskPara::PixelMapMaskPara(const PixelMapMaskPara& other)
27 : MaskPara(other), pixelMap_(nullptr), src_(other.src_), dst_(other.dst_), fillColor_(other.fillColor_)
28 {
29 #ifdef ROSEN_OHOS
30 if (other.pixelMap_ != nullptr) {
31 int32_t errorCode = Media::ERR_MEDIA_INVALID_VALUE;
32 auto pixelMap = other.pixelMap_->Clone(errorCode);
33 pixelMap_ = std::move(pixelMap);
34 if (errorCode != Media::SUCCESS || pixelMap_ == nullptr) {
35 RS_LOGE("[ui_effect] PixelMapMaskPara clone pixelMap failed");
36 }
37 }
38 #endif
39 }
40
Marshalling(Parcel & parcel) const41 bool PixelMapMaskPara::Marshalling(Parcel& parcel) const
42 {
43 bool isSuccess = parcel.WriteUint16(static_cast<uint16_t>(type_)) &&
44 parcel.WriteUint16(static_cast<uint16_t>(type_)) &&
45 pixelMap_ != nullptr && pixelMap_->Marshalling(parcel) &&
46 parcel.WriteFloat(src_.x_) && parcel.WriteFloat(src_.y_) &&
47 parcel.WriteFloat(src_.z_) && parcel.WriteFloat(src_.w_) &&
48 parcel.WriteFloat(dst_.x_) && parcel.WriteFloat(dst_.y_) &&
49 parcel.WriteFloat(dst_.z_) && parcel.WriteFloat(dst_.w_) &&
50 parcel.WriteFloat(fillColor_.x_) && parcel.WriteFloat(fillColor_.y_) &&
51 parcel.WriteFloat(fillColor_.z_) && parcel.WriteFloat(fillColor_.w_);
52 if (!isSuccess) {
53 RS_LOGE("[ui_effect] PixelMapMaskPara Marshalling write para failed");
54 return false;
55 }
56 return true;
57 }
58
RegisterUnmarshallingCallback()59 void PixelMapMaskPara::RegisterUnmarshallingCallback()
60 {
61 MaskPara::RegisterUnmarshallingCallback(MaskPara::Type::PIXEL_MAP_MASK, OnUnmarshalling);
62 }
63
OnUnmarshalling(Parcel & parcel,std::shared_ptr<MaskPara> & val)64 bool PixelMapMaskPara::OnUnmarshalling(Parcel& parcel, std::shared_ptr<MaskPara>& val)
65 {
66 uint16_t type = MaskPara::Type::NONE;
67 if (!parcel.ReadUint16(type) || type != MaskPara::Type::PIXEL_MAP_MASK) {
68 RS_LOGE("[ui_effect] PixelMapMaskPara OnUnmarshalling read type failed");
69 return false;
70 }
71
72 auto para = std::make_shared<PixelMapMaskPara>();
73 auto pixelMap = Media::PixelMap::Unmarshalling(parcel);
74 if (pixelMap == nullptr) {
75 RS_LOGE("[ui_effect] PixelMapMaskPara OnUnmarshalling pixelMap failed");
76 return false;
77 }
78 auto pixelMapTmp = std::shared_ptr<Media::PixelMap>(pixelMap);
79 para->SetPixelMap(pixelMapTmp);
80
81 Vector4f src;
82 Vector4f dst;
83 Vector4f fillColor;
84 auto isSuccess = parcel.ReadFloat(src.x_) && parcel.ReadFloat(src.y_) &&
85 parcel.ReadFloat(src.z_) && parcel.ReadFloat(src.w_) &&
86 parcel.ReadFloat(dst.x_) && parcel.ReadFloat(dst.y_) &&
87 parcel.ReadFloat(dst.z_) && parcel.ReadFloat(dst.w_) &&
88 parcel.ReadFloat(fillColor.x_) && parcel.ReadFloat(fillColor.y_) &&
89 parcel.ReadFloat(fillColor.z_) && parcel.ReadFloat(fillColor.w_);
90 if (!isSuccess) {
91 RS_LOGE("[ui_effect] PixelMapMaskPara OnUnmarshalling read para failed");
92 return false;
93 }
94 para->SetSrc(src);
95 para->SetDst(dst);
96 para->SetFillColor(fillColor);
97 val = std::move(para);
98 return true;
99 }
100
Clone() const101 std::shared_ptr<MaskPara> PixelMapMaskPara::Clone() const
102 {
103 return std::make_shared<PixelMapMaskPara>(*this);
104 }
105
106 } // namespace Rosen
107 } // namespace OHOS