1 /*
2 * Copyright (c) 2024 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 "params/rs_screen_render_params.h"
17
18 #include "platform/common/rs_log.h"
19 namespace OHOS::Rosen {
20 using RSRenderNodeDrawableAdapterSharedPtr = DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr;
RSScreenRenderParams(NodeId id)21 RSScreenRenderParams::RSScreenRenderParams(NodeId id) : RSRenderParams(id) {}
22
GetAllMainAndLeashSurfaces()23 std::vector<RSBaseRenderNode::SharedPtr>& RSScreenRenderParams::GetAllMainAndLeashSurfaces()
24 {
25 return allMainAndLeashSurfaces_;
26 }
27
GetAllMainAndLeashSurfaceDrawables()28 std::vector<RSRenderNodeDrawableAdapterSharedPtr>& RSScreenRenderParams::GetAllMainAndLeashSurfaceDrawables()
29 {
30 return allMainAndLeashSurfaceDrawables_;
31 }
32
SetAllMainAndLeashSurfaces(std::vector<RSBaseRenderNode::SharedPtr> & allMainAndLeashSurfaces)33 void RSScreenRenderParams::SetAllMainAndLeashSurfaces(
34 std::vector<RSBaseRenderNode::SharedPtr>& allMainAndLeashSurfaces)
35 {
36 std::swap(allMainAndLeashSurfaces_, allMainAndLeashSurfaces);
37 }
38
SetAllMainAndLeashSurfaceDrawables(std::vector<RSRenderNodeDrawableAdapterSharedPtr> & allMainAndLeashSurfaceDrawables)39 void RSScreenRenderParams::SetAllMainAndLeashSurfaceDrawables(
40 std::vector<RSRenderNodeDrawableAdapterSharedPtr>& allMainAndLeashSurfaceDrawables)
41 {
42 std::swap(allMainAndLeashSurfaceDrawables_, allMainAndLeashSurfaceDrawables);
43 }
44
SetMainAndLeashSurfaceDirty(bool isDirty)45 void RSScreenRenderParams::SetMainAndLeashSurfaceDirty(bool isDirty)
46 {
47 if (isMainAndLeashSurfaceDirty_ == isDirty) {
48 return;
49 }
50 isMainAndLeashSurfaceDirty_ = isDirty;
51 needSync_ = true;
52 }
53
GetMainAndLeashSurfaceDirty() const54 bool RSScreenRenderParams::GetMainAndLeashSurfaceDirty() const
55 {
56 return isMainAndLeashSurfaceDirty_;
57 }
58
SetNeedForceUpdateHwcNodes(bool needForceUpdateHwcNodes)59 void RSScreenRenderParams::SetNeedForceUpdateHwcNodes(bool needForceUpdateHwcNodes)
60 {
61 if (needForceUpdateHwcNodes_ == needForceUpdateHwcNodes) {
62 return;
63 }
64 needForceUpdateHwcNodes_ = needForceUpdateHwcNodes;
65 needSync_ = true;
66 }
67
GetNeedForceUpdateHwcNodes() const68 bool RSScreenRenderParams::GetNeedForceUpdateHwcNodes() const
69 {
70 return needForceUpdateHwcNodes_;
71 }
72
SetGlobalZOrder(float zOrder)73 void RSScreenRenderParams::SetGlobalZOrder(float zOrder)
74 {
75 zOrder_ = zOrder;
76 needSync_ = true;
77 }
78
GetGlobalZOrder() const79 float RSScreenRenderParams::GetGlobalZOrder() const
80 {
81 return zOrder_;
82 }
83
SetFingerprint(bool hasFingerprint)84 void RSScreenRenderParams::SetFingerprint(bool hasFingerprint)
85 {
86 if (hasFingerprint_ == hasFingerprint) {
87 return;
88 }
89 hasFingerprint_ = hasFingerprint;
90 needSync_ = true;
91 }
92
GetFingerprint()93 bool RSScreenRenderParams::GetFingerprint()
94 {
95 return hasFingerprint_;
96 }
97
SetFixVirtualBuffer10Bit(bool isFixVirtualBuffer10Bit)98 void RSScreenRenderParams::SetFixVirtualBuffer10Bit(bool isFixVirtualBuffer10Bit)
99 {
100 if (isFixVirtualBuffer10Bit_ == isFixVirtualBuffer10Bit) {
101 return;
102 }
103 isFixVirtualBuffer10Bit_ = isFixVirtualBuffer10Bit;
104 needSync_ = true;
105 }
106
GetFixVirtualBuffer10Bit() const107 bool RSScreenRenderParams::GetFixVirtualBuffer10Bit() const
108 {
109 return isFixVirtualBuffer10Bit_;
110 }
111
SetExistHWCNode(bool existHWCNode)112 void RSScreenRenderParams::SetExistHWCNode(bool existHWCNode)
113 {
114 if (existHWCNode_ == existHWCNode) {
115 return;
116 }
117 existHWCNode_ = existHWCNode;
118 needSync_ = true;
119 }
120
GetExistHWCNode() const121 bool RSScreenRenderParams::GetExistHWCNode() const
122 {
123 return existHWCNode_;
124 }
125
SetHDRPresent(bool hasHdrPresent)126 void RSScreenRenderParams::SetHDRPresent(bool hasHdrPresent)
127 {
128 if (hasHdrPresent_ == hasHdrPresent) {
129 return;
130 }
131 hasHdrPresent_ = hasHdrPresent;
132 needSync_ = true;
133 }
134
GetHDRPresent() const135 bool RSScreenRenderParams::GetHDRPresent() const
136 {
137 return hasHdrPresent_;
138 }
139
SetHDRStatusChanged(bool isHDRStatusChanged)140 void RSScreenRenderParams::SetHDRStatusChanged(bool isHDRStatusChanged)
141 {
142 if (isHDRStatusChanged_ == isHDRStatusChanged) {
143 return;
144 }
145 isHDRStatusChanged_ = isHDRStatusChanged;
146 needSync_ = true;
147 }
148
IsHDRStatusChanged() const149 bool RSScreenRenderParams::IsHDRStatusChanged() const
150 {
151 return isHDRStatusChanged_;
152 }
153
SetBrightnessRatio(float brightnessRatio)154 void RSScreenRenderParams::SetBrightnessRatio(float brightnessRatio)
155 {
156 if (ROSEN_EQ(brightnessRatio_, brightnessRatio)) {
157 return;
158 }
159 brightnessRatio_ = brightnessRatio;
160 needSync_ = true;
161 }
162
GetBrightnessRatio() const163 float RSScreenRenderParams::GetBrightnessRatio() const
164 {
165 return brightnessRatio_;
166 }
167
SetNewColorSpace(const GraphicColorGamut & newColorSpace)168 void RSScreenRenderParams::SetNewColorSpace(const GraphicColorGamut& newColorSpace)
169 {
170 if (newColorSpace_ == newColorSpace) {
171 return;
172 }
173 needSync_ = true;
174 newColorSpace_ = newColorSpace;
175 }
176
GetNewColorSpace() const177 GraphicColorGamut RSScreenRenderParams::GetNewColorSpace() const
178 {
179 return newColorSpace_;
180 }
181
SetNewPixelFormat(const GraphicPixelFormat & newPixelFormat)182 void RSScreenRenderParams::SetNewPixelFormat(const GraphicPixelFormat& newPixelFormat)
183 {
184 if (newPixelFormat_ == newPixelFormat) {
185 return;
186 }
187 needSync_ = true;
188 newPixelFormat_ = newPixelFormat;
189 }
190
GetNewPixelFormat() const191 GraphicPixelFormat RSScreenRenderParams::GetNewPixelFormat() const
192 {
193 return newPixelFormat_;
194 }
195
SetZoomed(bool isZoomed)196 void RSScreenRenderParams::SetZoomed(bool isZoomed)
197 {
198 if (isZoomed_ == isZoomed) {
199 return;
200 }
201 needSync_ = true;
202 isZoomed_ = isZoomed;
203 }
204
GetZoomed() const205 bool RSScreenRenderParams::GetZoomed() const
206 {
207 return isZoomed_;
208 }
209
SetTargetSurfaceRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)210 void RSScreenRenderParams::SetTargetSurfaceRenderNodeDrawable(
211 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)
212 {
213 if (ROSEN_EQ(targetSurfaceRenderNodeDrawable_, drawable)) {
214 return;
215 }
216 targetSurfaceRenderNodeDrawable_ = drawable;
217 needSync_ = true;
218 }
219
GetTargetSurfaceRenderNodeDrawable() const220 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSScreenRenderParams::GetTargetSurfaceRenderNodeDrawable() const
221 {
222 return targetSurfaceRenderNodeDrawable_;
223 }
224
OnSync(const std::unique_ptr<RSRenderParams> & target)225 void RSScreenRenderParams::OnSync(const std::unique_ptr<RSRenderParams>& target)
226 {
227 auto targetScreenParams = static_cast<RSScreenRenderParams*>(target.get());
228 if (targetScreenParams == nullptr) {
229 RS_LOGE("RSScreenRenderParams::OnSync targetScreenParams is nullptr");
230 return;
231 }
232 allMainAndLeashSurfaceDrawables_.clear();
233 for (auto& surfaceNode : allMainAndLeashSurfaces_) {
234 auto ptr = DrawableV2::RSRenderNodeDrawableAdapter::GetDrawableById(surfaceNode->GetId());
235 if (ptr == nullptr || ptr->GetNodeType() != RSRenderNodeType::SURFACE_NODE) {
236 continue;
237 }
238 allMainAndLeashSurfaceDrawables_.push_back(ptr);
239 }
240 targetScreenParams->allMainAndLeashSurfaceDrawables_ = allMainAndLeashSurfaceDrawables_;
241 targetScreenParams->hasChildCrossNode_ = hasChildCrossNode_;
242 targetScreenParams->isFirstVisitCrossNodeDisplay_ = isFirstVisitCrossNodeDisplay_;
243 targetScreenParams->compositeType_ = compositeType_;
244 targetScreenParams->mirrorSourceDrawable_ = mirrorSourceDrawable_;
245 targetScreenParams->isMirrorScreen_ = isMirrorScreen_;
246 targetScreenParams->screenInfo_ = std::move(screenInfo_);
247 targetScreenParams->isMainAndLeashSurfaceDirty_ = isMainAndLeashSurfaceDirty_;
248 targetScreenParams->hasFingerprint_ = hasFingerprint_;
249 targetScreenParams->newColorSpace_ = newColorSpace_;
250 targetScreenParams->newPixelFormat_ = newPixelFormat_;
251 targetScreenParams->hasHdrPresent_ = hasHdrPresent_;
252 targetScreenParams->isHDRStatusChanged_ = isHDRStatusChanged_;
253 targetScreenParams->brightnessRatio_ = brightnessRatio_;
254 targetScreenParams->isFixVirtualBuffer10Bit_ = isFixVirtualBuffer10Bit_;
255 targetScreenParams->existHWCNode_ = existHWCNode_;
256 targetScreenParams->zOrder_ = zOrder_;
257 targetScreenParams->isZoomed_ = isZoomed_;
258 targetScreenParams->hasMirrorScreen_ = hasMirrorScreen_;
259 targetScreenParams->targetSurfaceRenderNodeDrawable_ = targetSurfaceRenderNodeDrawable_;
260 targetScreenParams->roundCornerSurfaceDrawables_ = roundCornerSurfaceDrawables_;
261 targetScreenParams->needForceUpdateHwcNodes_ = needForceUpdateHwcNodes_;
262 targetScreenParams->childDisplayCount_ = childDisplayCount_;
263 targetScreenParams->logicalDisplayNodeDrawables_ = std::move(logicalDisplayNodeDrawables_);
264 targetScreenParams->forceFreeze_ = forceFreeze_;
265
266 RSRenderParams::OnSync(target);
267 }
268
ToString() const269 std::string RSScreenRenderParams::ToString() const
270 {
271 std::string ret = RSRenderParams::ToString() + ", RSScreenRenderParams: {";
272 ret += RENDER_BASIC_PARAM_TO_STRING(screenInfo_.id);
273 ret += RENDER_BASIC_PARAM_TO_STRING(static_cast<uint32_t>(compositeType_));
274 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaces_.size());
275 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaceDrawables_.size());
276 ret += RENDER_PARAM_TO_STRING(screenInfo_);
277 ret += "}";
278 return ret;
279 }
280
GetMirrorSourceDrawable()281 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSScreenRenderParams::GetMirrorSourceDrawable()
282 {
283 return mirrorSourceDrawable_;
284 }
285
SetHasMirrorScreen(bool hasMirrorScreen)286 void RSScreenRenderParams::SetHasMirrorScreen(bool hasMirrorScreen)
287 {
288 if (hasMirrorScreen) {
289 mirrorDstCount_++;
290 } else {
291 mirrorDstCount_--;
292 }
293 bool ret = (mirrorDstCount_ != 0);
294 if (hasMirrorScreen_ == ret) {
295 return;
296 }
297 needSync_ = true;
298 hasMirrorScreen_ = hasMirrorScreen;
299 }
300
HasMirrorScreen() const301 bool RSScreenRenderParams::HasMirrorScreen() const
302 {
303 return hasMirrorScreen_;
304 }
305
SetDrawnRegion(const Occlusion::Region & region)306 void RSScreenRenderParams::SetDrawnRegion(const Occlusion::Region& region)
307 {
308 drawnRegion_ = region;
309 }
310
GetDrawnRegion() const311 const Occlusion::Region& RSScreenRenderParams::GetDrawnRegion() const
312 {
313 return drawnRegion_;
314 }
315
SetForceFreeze(bool forceFreeze)316 void RSScreenRenderParams::SetForceFreeze(bool forceFreeze)
317 {
318 if (forceFreeze_ == forceFreeze) {
319 return;
320 }
321 forceFreeze_ = forceFreeze;
322 needSync_ = true;
323 }
324
GetForceFreeze() const325 bool RSScreenRenderParams::GetForceFreeze() const
326 {
327 return forceFreeze_ && RSSystemProperties::GetSupportScreenFreezeEnabled();
328 }
329
330 } // namespace OHOS::Rosen
331