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 uint32_t size{0};
29 if (!parcel.ReadUint32(size)) {
30 ROSEN_LOGE("RSOcclusionData::Unmarshalling Read size failed");
31 return nullptr;
32 }
33 size_t readableSize = parcel.GetReadableBytes() / (sizeof(uint64_t) + sizeof(uint32_t));
34 size_t len = static_cast<size_t>(size);
35 if (len > readableSize || len > data->visibleData_.max_size()) {
36 RS_LOGE("RSOcclusionData Unmarshalling Failed read vector, size:%{public}zu, readableSize:%{public}zu",
37 len, readableSize);
38 return data;
39 }
40 for (uint32_t i = 0; i < size; i++) {
41 uint64_t id{0};
42 uint32_t visibelLevel{0};
43 if (!parcel.ReadUint64(id) || !parcel.ReadUint32(visibelLevel)) {
44 ROSEN_LOGE("RSOcclusionData::Unmarshalling Read parcel failed");
45 return nullptr;
46 }
47 data->visibleData_.emplace_back(std::make_pair(id, (WINDOW_LAYER_INFO_TYPE)visibelLevel));
48 }
49 return data;
50 }
51
Marshalling(Parcel & parcel) const52 bool RSOcclusionData::Marshalling(Parcel& parcel) const
53 {
54 parcel.WriteUint32(visibleData_.size());
55 for (auto& data : visibleData_) {
56 if (!parcel.WriteUint64(data.first)) {
57 RS_LOGE("RSOcclusionData::Marshalling WriteUint64 first failed");
58 return false;
59 }
60 if (!parcel.WriteUint32(data.second)) {
61 RS_LOGE("RSOcclusionData::Marshalling WriteUint32 second failed");
62 return false;
63 }
64 }
65
66 return true;
67 }
68 } // namespace Rosen
69 } // namespace OHOS
70