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