1 /*
2 * Copyright (c) 2023-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_hgm_config_data.h"
17 #include "platform/common/rs_log.h"
18
19 namespace {
20 static constexpr size_t PARCEL_MAX_CAPACITY = 2000 * 1024;
21 }
22
23 namespace OHOS {
24 namespace Rosen {
~RSHgmConfigData()25 RSHgmConfigData::~RSHgmConfigData() noexcept
26 {
27 configData_.clear();
28 }
29
Unmarshalling(Parcel & parcel)30 RSHgmConfigData* RSHgmConfigData::Unmarshalling(Parcel& parcel)
31 {
32 auto data = new RSHgmConfigData();
33 data->ppi_ = parcel.ReadFloat();
34 data->xDpi_ = parcel.ReadFloat();
35 data->yDpi_ = parcel.ReadFloat();
36 auto size = parcel.ReadUint32();
37 size_t readableSize = parcel.GetReadableBytes() / sizeof(uint64_t);
38 size_t len = static_cast<size_t>(size);
39 if (len > readableSize || len > data->configData_.max_size()) {
40 RS_LOGE("RSHgmConfigData Unmarshalling Failed read vector, size:%zu, readableSize:%zu", len, readableSize);
41 return data;
42 }
43 for (uint32_t i = 0; i < size; i++) {
44 std::string type = parcel.ReadString();
45 std::string name = parcel.ReadString();
46 auto minSpeed = parcel.ReadInt32();
47 auto maxSpeed = parcel.ReadInt32();
48 auto preferredFps = parcel.ReadInt32();
49 AnimDynamicItem item = {type, name, minSpeed, maxSpeed, preferredFps};
50 data->AddAnimDynamicItem(item);
51 }
52 return data;
53 }
54
Marshalling(Parcel & parcel) const55 bool RSHgmConfigData::Marshalling(Parcel& parcel) const
56 {
57 parcel.SetMaxCapacity(PARCEL_MAX_CAPACITY);
58 parcel.WriteFloat(ppi_);
59 parcel.WriteFloat(xDpi_);
60 parcel.WriteFloat(yDpi_);
61 parcel.WriteUint32(configData_.size());
62
63 for (auto& item : configData_) {
64 parcel.WriteString(item.animType);
65 parcel.WriteString(item.animName);
66 parcel.WriteInt32(item.minSpeed);
67 parcel.WriteInt32(item.maxSpeed);
68 parcel.WriteInt32(item.preferredFps);
69 }
70
71 return true;
72 }
73 } // namespace Rosen
74 } // namespace OHOS
75