1 /*
2 * Copyright (c) 2022 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 "screen_manager/rs_screen_hdr_capability.h"
17
18 namespace OHOS {
19 namespace Rosen {
RSScreenHDRCapability(float maxLum,float minLum,float maxAverageLum,const std::vector<ScreenHDRFormat> & formats)20 RSScreenHDRCapability::RSScreenHDRCapability(float maxLum, float minLum, float maxAverageLum,
21 const std::vector<ScreenHDRFormat>& formats) : maxLum_(maxLum), minLum_(minLum),
22 maxAverageLum_(maxAverageLum), hdrFormats_(formats)
23 {
24 }
25
GetMaxLum() const26 float RSScreenHDRCapability::GetMaxLum() const
27 {
28 return maxLum_;
29 }
30
GetMinLum() const31 float RSScreenHDRCapability::GetMinLum() const
32 {
33 return minLum_;
34 }
35
GetMaxAverageLum() const36 float RSScreenHDRCapability::GetMaxAverageLum() const
37 {
38 return maxAverageLum_;
39 }
40
GetHdrFormats() const41 const std::vector<ScreenHDRFormat>& RSScreenHDRCapability::GetHdrFormats() const
42 {
43 return hdrFormats_;
44 }
45
SetMaxLum(float maxLum)46 void RSScreenHDRCapability::SetMaxLum(float maxLum)
47 {
48 maxLum_ = maxLum;
49 }
50
SetMinLum(float minLum)51 void RSScreenHDRCapability::SetMinLum(float minLum)
52 {
53 minLum_ = minLum;
54 }
55
SetMaxAverageLum(float maxAverageLum)56 void RSScreenHDRCapability::SetMaxAverageLum(float maxAverageLum)
57 {
58 maxAverageLum_ = maxAverageLum;
59 }
60
SetHdrFormats(const std::vector<ScreenHDRFormat> & formats)61 void RSScreenHDRCapability::SetHdrFormats(const std::vector<ScreenHDRFormat>& formats)
62 {
63 hdrFormats_ = formats;
64 }
65
WriteVector(const std::vector<ScreenHDRFormat> & formats,Parcel & parcel) const66 bool RSScreenHDRCapability::WriteVector(const std::vector<ScreenHDRFormat>& formats, Parcel &parcel) const
67 {
68 if (!parcel.WriteUint32(static_cast<uint32_t>(formats.size()))) {
69 return false;
70 }
71 for (ScreenHDRFormat format : formats) {
72 if (!parcel.WriteUint32(static_cast<uint32_t>(format))) {
73 return false;
74 }
75 }
76 return true;
77 }
78
ReadVector(std::vector<ScreenHDRFormat> & unmarFormats,Parcel & parcel)79 bool RSScreenHDRCapability::ReadVector(std::vector<ScreenHDRFormat>& unmarFormats, Parcel &parcel)
80 {
81 uint32_t size;
82 if (!parcel.ReadUint32(size)) {
83 return false;
84 }
85 for (uint32_t index = 0; index < size; index++) {
86 uint32_t format;
87 if (!parcel.ReadUint32(format)) {
88 return false;
89 }
90 unmarFormats.push_back(static_cast<ScreenHDRFormat>(format));
91 }
92 return true;
93 }
94
Marshalling(Parcel & parcel) const95 bool RSScreenHDRCapability::Marshalling(Parcel &parcel) const
96 {
97 if (!parcel.WriteFloat(maxLum_)) {
98 return false;
99 }
100 if (!parcel.WriteFloat(minLum_)) {
101 return false;
102 }
103 if (!parcel.WriteFloat(maxAverageLum_)) {
104 return false;
105 }
106 if (!WriteVector(hdrFormats_, parcel)) {
107 return false;
108 }
109 return true;
110 }
111
Unmarshalling(Parcel & parcel)112 RSScreenHDRCapability* RSScreenHDRCapability::Unmarshalling(Parcel &parcel)
113 {
114 float maxLum;
115 float minLum;
116 float maxAverageLum;
117 std::vector<ScreenHDRFormat> formats;
118 if (!parcel.ReadFloat(maxLum)) {
119 return nullptr;
120 }
121 if (!parcel.ReadFloat(minLum)) {
122 return nullptr;
123 }
124 if (!parcel.ReadFloat(maxAverageLum)) {
125 return nullptr;
126 }
127 if (!ReadVector(formats, parcel)) {
128 return nullptr;
129 }
130 RSScreenHDRCapability* screenHdrCapability = new RSScreenHDRCapability(maxLum, minLum, maxAverageLum, formats);
131 return screenHdrCapability;
132 }
133 } // namespace Rosen
134 } // namespace OHOS