1 /*
2 * Copyright (c) 2022-2023 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_occlusion_data.h"
17 #include "platform/common/rs_log.h"
18
19 namespace OHOS {
20 namespace Rosen {
~RSOcclusionData()21 RSOcclusionData::~RSOcclusionData() noexcept
22 {
23 }
24
Unmarshalling(Parcel & parcel)25 RSOcclusionData* RSOcclusionData::Unmarshalling(Parcel& parcel)
26 {
27 auto data = new RSOcclusionData();
28 auto size = parcel.ReadUint32();
29 size_t readableSize = parcel.GetReadableBytes() / (sizeof(uint64_t) + sizeof(uint32_t));
30 size_t len = static_cast<size_t>(size);
31 if (len > readableSize || len > data->visibleData_.max_size()) {
32 RS_LOGE("RSOcclusionData Unmarshalling Failed read vector, size:%{public}zu, readableSize:%{public}zu",
33 len, readableSize);
34 return data;
35 }
36 for (uint32_t i = 0; i < size; i++) {
37 uint64_t id = parcel.ReadUint64();
38 uint32_t visibelLevel = parcel.ReadUint32();
39 data->visibleData_.emplace_back(std::make_pair(id, (WINDOW_LAYER_INFO_TYPE)visibelLevel));
40 }
41 return data;
42 }
43
Marshalling(Parcel & parcel) const44 bool RSOcclusionData::Marshalling(Parcel& parcel) const
45 {
46 parcel.WriteUint32(visibleData_.size());
47 for (auto& data : visibleData_) {
48 parcel.WriteUint64(data.first);
49 parcel.WriteUint32(data.second);
50 }
51
52 return true;
53 }
54 } // namespace Rosen
55 } // namespace OHOS
56