1 /*
2 * Copyright (c) 2021-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_mode_info.h"
17 #include "platform/common/rs_log.h"
18
19 namespace OHOS {
20 namespace Rosen {
RSScreenModeInfo(int32_t width,int32_t height,uint32_t refreshRate,int32_t id)21 RSScreenModeInfo::RSScreenModeInfo(int32_t width, int32_t height, uint32_t refreshRate, int32_t id)
22 : width_(width), height_(height), refreshRate_(refreshRate), modeId_(id)
23 {
24 }
25
RSScreenModeInfo(const RSScreenModeInfo & other)26 RSScreenModeInfo::RSScreenModeInfo(const RSScreenModeInfo& other)
27 {
28 int32_t width = other.width_;
29 int32_t height = other.height_;
30 uint32_t refreshRate = other.refreshRate_;
31 int32_t modeId = other.modeId_;
32 width_ = width;
33 height_ = height;
34 refreshRate_ = refreshRate;
35 modeId_ = modeId;
36 }
37
operator =(const RSScreenModeInfo & other)38 RSScreenModeInfo& RSScreenModeInfo::operator=(const RSScreenModeInfo& other)
39 {
40 int32_t width = other.width_;
41 int32_t height = other.height_;
42 uint32_t refreshRate = other.refreshRate_;
43 int32_t modeId = other.modeId_;
44 width_ = width;
45 height_ = height;
46 refreshRate_ = refreshRate;
47 modeId_ = modeId;
48 return *this;
49 }
50
Marshalling(Parcel & parcel) const51 bool RSScreenModeInfo::Marshalling(Parcel& parcel) const
52 {
53 bool flag = parcel.WriteInt32(width_) && parcel.WriteInt32(height_) &&
54 parcel.WriteUint32(refreshRate_) && parcel.WriteInt32(modeId_);
55 if (!flag) {
56 ROSEN_LOGE("RSScreenModeInfo::Marshalling failed");
57 }
58 return flag;
59 }
60
Unmarshalling(Parcel & parcel)61 RSScreenModeInfo* RSScreenModeInfo::Unmarshalling(Parcel& parcel)
62 {
63 int32_t width;
64 int32_t height;
65 uint32_t refreshRate;
66 int32_t id;
67 if (!(parcel.ReadInt32(width) && parcel.ReadInt32(height) && parcel.ReadUint32(refreshRate)
68 && parcel.ReadInt32(id))) {
69 ROSEN_LOGE("RSScreenModeInfo::Unmarshalling failed");
70 return nullptr;
71 }
72
73 RSScreenModeInfo* screenModeInfo = new RSScreenModeInfo(width, height, refreshRate, id);
74 return screenModeInfo;
75 }
76
GetScreenWidth() const77 int32_t RSScreenModeInfo::GetScreenWidth() const
78 {
79 return width_;
80 }
81
GetScreenHeight() const82 int32_t RSScreenModeInfo::GetScreenHeight() const
83 {
84 return height_;
85 }
86
GetScreenRefreshRate() const87 uint32_t RSScreenModeInfo::GetScreenRefreshRate() const
88 {
89 return refreshRate_;
90 }
91
GetScreenModeId() const92 int32_t RSScreenModeInfo::GetScreenModeId() const
93 {
94 return modeId_;
95 }
96
SetScreenWidth(int32_t width)97 void RSScreenModeInfo::SetScreenWidth(int32_t width)
98 {
99 width_ = width;
100 }
101
SetScreenHeight(int32_t height)102 void RSScreenModeInfo::SetScreenHeight(int32_t height)
103 {
104 height_ = height;
105 }
106
SetScreenRefreshRate(uint32_t refreshRate)107 void RSScreenModeInfo::SetScreenRefreshRate(uint32_t refreshRate)
108 {
109 refreshRate_ = refreshRate;
110 }
111
SetScreenModeId(int32_t id)112 void RSScreenModeInfo::SetScreenModeId(int32_t id)
113 {
114 modeId_ = id;
115 }
116 } // namespace Rosen
117 } // namespace OHOS