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 "transaction/rs_self_drawing_node_rect_data.h" 17 #include "platform/common/rs_log.h" 18 19 namespace OHOS { 20 namespace Rosen { Marshalling(Parcel & parcel) const21bool RSSelfDrawingNodeRectData::Marshalling(Parcel& parcel) const 22 { 23 bool marshallingSuccess = true; 24 marshallingSuccess &= parcel.WriteUint32(rectData_.size()); 25 for (const auto& data : rectData_) { 26 marshallingSuccess &= parcel.WriteUint64(data.first); 27 marshallingSuccess &= parcel.WriteString(data.second.first); 28 marshallingSuccess &= parcel.WriteInt32(data.second.second.GetLeft()); 29 marshallingSuccess &= parcel.WriteInt32(data.second.second.GetTop()); 30 marshallingSuccess &= parcel.WriteInt32(data.second.second.GetWidth()); 31 marshallingSuccess &= parcel.WriteInt32(data.second.second.GetHeight()); 32 } 33 if (!marshallingSuccess) { 34 RS_LOGE("RSSelfDrawingNodeRectData::Marshalling failed"); 35 } 36 return marshallingSuccess; 37 } 38 Unmarshalling(Parcel & parcel)39RSSelfDrawingNodeRectData* RSSelfDrawingNodeRectData::Unmarshalling(Parcel& parcel) 40 { 41 uint32_t mapSize; 42 if (!parcel.ReadUint32(mapSize)) { 43 RS_LOGE("RSSelfDrawingNodeRectData::Unmarshalling read mapSize failed"); 44 return nullptr; 45 } 46 47 auto SelfDrawingNodeRectData = new RSSelfDrawingNodeRectData(); 48 if (!SelfDrawingNodeRectData) { 49 return nullptr; 50 } 51 52 if (mapSize > SelfDrawingNodeRectData->rectData_.max_size()) { 53 RS_LOGE("RSSelfDrawingNodeRectData Unmarshalling failed, map size overflow."); 54 delete SelfDrawingNodeRectData; 55 return nullptr; 56 } 57 58 for (uint32_t index = 0; index < mapSize; ++index) { 59 uint64_t nodeId; 60 std::string nodeName; 61 RectI rect; 62 if (!parcel.ReadUint64(nodeId) || !parcel.ReadString(nodeName) || !parcel.ReadInt32(rect.left_) || 63 !parcel.ReadInt32(rect.top_) || !parcel.ReadInt32(rect.width_) || !parcel.ReadInt32(rect.height_)) { 64 RS_LOGE("RSSelfDrawingNodeRectData::Unmarshalling read rectData failed"); 65 delete SelfDrawingNodeRectData; 66 return nullptr; 67 } 68 SelfDrawingNodeRectData->rectData_.insert(std::make_pair(nodeId, std::make_pair(nodeName, rect))); 69 } 70 return SelfDrawingNodeRectData; 71 } 72 } // namespace Rosen 73 } // namespace OHOS 74