• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     uint32_t size;
34     uint32_t pageNameSize;
35     if (!parcel.ReadFloat(data->ppi_) || !parcel.ReadFloat(data->xDpi_) || !parcel.ReadFloat(data->yDpi_) ||
36         !parcel.ReadUint32(size)) {
37         RS_LOGE("RSHgmConfigData Unmarshalling read failed");
38         return data;
39     }
40     size_t readableSize = parcel.GetReadableBytes() / sizeof(uint64_t);
41     size_t len = static_cast<size_t>(size);
42     if (len > readableSize || len > data->configData_.max_size()) {
43         RS_LOGE("RSHgmConfigData Unmarshalling Failed read vector, size:%zu, readableSize:%zu", len, readableSize);
44         return data;
45     }
46     std::string type;
47     std::string name;
48     int32_t minSpeed;
49     int32_t maxSpeed;
50     int32_t preferredFps;
51     for (uint32_t i = 0; i < size; i++) {
52         if (!parcel.ReadString(type) || !parcel.ReadString(name) || !parcel.ReadInt32(minSpeed) ||
53             !parcel.ReadInt32(maxSpeed) || !parcel.ReadInt32(preferredFps)) {
54             RS_LOGE("RSHgmConfigData Unmarshalling read data failed");
55             return data;
56         }
57         AnimDynamicItem item = {type, name, minSpeed, maxSpeed, preferredFps};
58         data->AddAnimDynamicItem(item);
59     }
60 
61     if (!parcel.ReadUint32(pageNameSize)) {
62         RS_LOGE("RSHgmConfigData Unmarshalling read data failed");
63         return data;
64     }
65     for (uint32_t i = 0; i < pageNameSize; i++) {
66         std::string pageName;
67         if (!parcel.ReadString(pageName)) {
68             RS_LOGE("RSHgmConfigData Unmarshalling read data failed");
69             return data;
70         }
71         data->AddPageName(pageName);
72     }
73     return data;
74 }
75 
Marshalling(Parcel & parcel) const76 bool RSHgmConfigData::Marshalling(Parcel& parcel) const
77 {
78     parcel.SetMaxCapacity(PARCEL_MAX_CAPACITY);
79     bool flag = parcel.WriteFloat(ppi_) && parcel.WriteFloat(xDpi_) && parcel.WriteFloat(yDpi_) &&
80         parcel.WriteUint32(configData_.size());
81     if (!flag) {
82         RS_LOGE("RSHgmConfigData::Marshalling parse dpi failed");
83         return flag;
84     }
85 
86     for (auto& item : configData_) {
87         flag = parcel.WriteString(item.animType) && parcel.WriteString(item.animName) &&
88                parcel.WriteInt32(item.minSpeed) && parcel.WriteInt32(item.maxSpeed) &&
89                parcel.WriteInt32(item.preferredFps);
90         if (!flag) {
91             RS_LOGE("RSHgmConfigData::Marshalling parse config item failed");
92             return flag;
93         }
94     }
95 
96     parcel.WriteUint32(pageNameList_.size());
97     for (auto& item : pageNameList_) {
98         parcel.WriteString(item);
99     }
100 
101     return flag;
102 }
103 } // namespace Rosen
104 } // namespace OHOS
105