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