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_display_render_params.h"
17
18 #include "platform/common/rs_log.h"
19 namespace OHOS::Rosen {
20 using RSRenderNodeDrawableAdapterSharedPtr = DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr;
RSDisplayRenderParams(NodeId id)21 RSDisplayRenderParams::RSDisplayRenderParams(NodeId id) : RSRenderParams(id) {}
22
GetAllMainAndLeashSurfaces()23 std::vector<RSBaseRenderNode::SharedPtr>& RSDisplayRenderParams::GetAllMainAndLeashSurfaces()
24 {
25 return allMainAndLeashSurfaces_;
26 }
27
GetAllMainAndLeashSurfaceDrawables()28 std::vector<RSRenderNodeDrawableAdapterSharedPtr>& RSDisplayRenderParams::GetAllMainAndLeashSurfaceDrawables()
29 {
30 return allMainAndLeashSurfaceDrawables_;
31 }
32
SetAllMainAndLeashSurfaces(std::vector<RSBaseRenderNode::SharedPtr> & allMainAndLeashSurfaces)33 void RSDisplayRenderParams::SetAllMainAndLeashSurfaces(
34 std::vector<RSBaseRenderNode::SharedPtr>& allMainAndLeashSurfaces)
35 {
36 std::swap(allMainAndLeashSurfaces_, allMainAndLeashSurfaces);
37 }
38
SetAllMainAndLeashSurfaceDrawables(std::vector<RSRenderNodeDrawableAdapterSharedPtr> & allMainAndLeashSurfaceDrawables)39 void RSDisplayRenderParams::SetAllMainAndLeashSurfaceDrawables(
40 std::vector<RSRenderNodeDrawableAdapterSharedPtr>& allMainAndLeashSurfaceDrawables)
41 {
42 std::swap(allMainAndLeashSurfaceDrawables_, allMainAndLeashSurfaceDrawables);
43 }
44
SetMainAndLeashSurfaceDirty(bool isDirty)45 void RSDisplayRenderParams::SetMainAndLeashSurfaceDirty(bool isDirty)
46 {
47 if (isMainAndLeashSurfaceDirty_ == isDirty) {
48 return;
49 }
50 isMainAndLeashSurfaceDirty_ = isDirty;
51 needSync_ = true;
52 }
53
GetTopSurfaceOpaqueRects() const54 const std::vector<Occlusion::Rect>& RSDisplayRenderParams::GetTopSurfaceOpaqueRects() const
55 {
56 return topSurfaceOpaqueRects_;
57 }
58
GetMainAndLeashSurfaceDirty() const59 bool RSDisplayRenderParams::GetMainAndLeashSurfaceDirty() const
60 {
61 return isMainAndLeashSurfaceDirty_;
62 }
63
SetRotationChanged(bool changed)64 void RSDisplayRenderParams::SetRotationChanged(bool changed)
65 {
66 if (isRotationChanged_ == changed) {
67 return;
68 }
69 isRotationChanged_ = changed;
70 needSync_ = true;
71 }
72
SetGlobalZOrder(float zOrder)73 void RSDisplayRenderParams::SetGlobalZOrder(float zOrder)
74 {
75 zOrder_ = zOrder;
76 needSync_ = true;
77 }
78
GetGlobalZOrder() const79 float RSDisplayRenderParams::GetGlobalZOrder() const
80 {
81 return zOrder_;
82 }
83
IsRotationChanged() const84 bool RSDisplayRenderParams::IsRotationChanged() const
85 {
86 return isRotationChanged_;
87 }
88
IsRotationFinished() const89 bool RSDisplayRenderParams::IsRotationFinished() const
90 {
91 return isRotationFinished_;
92 }
93
SetRotationFinished(bool finished)94 void RSDisplayRenderParams::SetRotationFinished(bool finished)
95 {
96 if (isRotationFinished_ == finished) {
97 return;
98 }
99 isRotationFinished_ = finished;
100 needSync_ = true;
101 }
102
SetFingerprint(bool hasFingerprint)103 void RSDisplayRenderParams::SetFingerprint(bool hasFingerprint)
104 {
105 if (hasFingerprint_ == hasFingerprint) {
106 return;
107 }
108 hasFingerprint_ = hasFingerprint;
109 needSync_ = true;
110 }
111
GetFingerprint()112 bool RSDisplayRenderParams::GetFingerprint()
113 {
114 return hasFingerprint_;
115 }
116
SetHDRPresent(bool hasHdrPresent)117 void RSDisplayRenderParams::SetHDRPresent(bool hasHdrPresent)
118 {
119 if (hasHdrPresent_ == hasHdrPresent) {
120 return;
121 }
122 hasHdrPresent_ = hasHdrPresent;
123 needSync_ = true;
124 }
125
GetHDRPresent() const126 bool RSDisplayRenderParams::GetHDRPresent() const
127 {
128 return hasHdrPresent_;
129 }
130
SetBrightnessRatio(float brightnessRatio)131 void RSDisplayRenderParams::SetBrightnessRatio (float brightnessRatio)
132 {
133 if (ROSEN_EQ(brightnessRatio_, brightnessRatio)) {
134 return;
135 }
136 brightnessRatio_ = brightnessRatio;
137 needSync_ = true;
138 }
139
GetBrightnessRatio() const140 float RSDisplayRenderParams::GetBrightnessRatio() const
141 {
142 return brightnessRatio_;
143 }
144
SetNewColorSpace(const GraphicColorGamut & newColorSpace)145 void RSDisplayRenderParams::SetNewColorSpace(const GraphicColorGamut& newColorSpace)
146 {
147 if (newColorSpace_ == newColorSpace) {
148 return;
149 }
150 needSync_ = true;
151 newColorSpace_ = newColorSpace;
152 }
153
GetNewColorSpace() const154 GraphicColorGamut RSDisplayRenderParams::GetNewColorSpace() const
155 {
156 return newColorSpace_;
157 }
158
SetNewPixelFormat(const GraphicPixelFormat & newPixelFormat)159 void RSDisplayRenderParams::SetNewPixelFormat(const GraphicPixelFormat& newPixelFormat)
160 {
161 if (newPixelFormat_ == newPixelFormat) {
162 return;
163 }
164 needSync_ = true;
165 newPixelFormat_ = newPixelFormat;
166 }
167
GetNewPixelFormat() const168 GraphicPixelFormat RSDisplayRenderParams::GetNewPixelFormat() const
169 {
170 return newPixelFormat_;
171 }
172
SetZoomed(bool isZoomed)173 void RSDisplayRenderParams::SetZoomed(bool isZoomed)
174 {
175 if (isZoomed_ == isZoomed) {
176 return;
177 }
178 needSync_ = true;
179 isZoomed_ = isZoomed;
180 }
181
GetZoomed() const182 bool RSDisplayRenderParams::GetZoomed() const
183 {
184 return isZoomed_;
185 }
186
SetTargetSurfaceRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)187 void RSDisplayRenderParams::SetTargetSurfaceRenderNodeDrawable(
188 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)
189 {
190 if (ROSEN_EQ(targetSurfaceRenderNodeDrawable_, drawable)) {
191 return;
192 }
193 targetSurfaceRenderNodeDrawable_ = drawable;
194 needSync_ = true;
195 }
196
GetTargetSurfaceRenderNodeDrawable() const197 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSDisplayRenderParams::GetTargetSurfaceRenderNodeDrawable() const
198 {
199 return targetSurfaceRenderNodeDrawable_;
200 }
201
OnSync(const std::unique_ptr<RSRenderParams> & target)202 void RSDisplayRenderParams::OnSync(const std::unique_ptr<RSRenderParams>& target)
203 {
204 auto targetDisplayParams = static_cast<RSDisplayRenderParams*>(target.get());
205 if (targetDisplayParams == nullptr) {
206 RS_LOGE("RSDisplayRenderParams::OnSync targetDisplayParams is nullptr");
207 return;
208 }
209 allMainAndLeashSurfaceDrawables_.clear();
210 for (auto& surfaceNode : allMainAndLeashSurfaces_) {
211 auto ptr = DrawableV2::RSRenderNodeDrawableAdapter::GetDrawableById(surfaceNode->GetId());
212 if (ptr == nullptr || ptr->GetNodeType() != RSRenderNodeType::SURFACE_NODE) {
213 continue;
214 }
215 allMainAndLeashSurfaceDrawables_.push_back(ptr);
216 }
217 targetDisplayParams->allMainAndLeashSurfaceDrawables_ = allMainAndLeashSurfaceDrawables_;
218 targetDisplayParams->topSurfaceOpaqueRects_.clear();
219 targetDisplayParams->topSurfaceOpaqueRects_.assign(topSurfaceOpaqueRects_.begin(), topSurfaceOpaqueRects_.end());
220 targetDisplayParams->specialLayerManager_ = specialLayerManager_;
221 targetDisplayParams->displaySpecailSurfaceChanged_ = displaySpecailSurfaceChanged_;
222 targetDisplayParams->hasCaptureWindow_ = hasCaptureWindow_;
223 targetDisplayParams->hasChildCrossNode_ = hasChildCrossNode_;
224 targetDisplayParams->isMirrorScreen_ = isMirrorScreen_;
225 targetDisplayParams->isFirstVisitCrossNodeDisplay_ = isFirstVisitCrossNodeDisplay_;
226 targetDisplayParams->offsetX_ = offsetX_;
227 targetDisplayParams->offsetY_ = offsetY_;
228 targetDisplayParams->nodeRotation_ = nodeRotation_;
229 targetDisplayParams->screenRotation_ = screenRotation_;
230 targetDisplayParams->screenId_ = screenId_;
231 targetDisplayParams->isSecurityDisplay_ = isSecurityDisplay_;
232 targetDisplayParams->isSecurityExemption_ = isSecurityExemption_;
233 targetDisplayParams->hasSecLayerInVisibleRect_ = hasSecLayerInVisibleRect_;
234 targetDisplayParams->hasSecLayerInVisibleRectChanged_ = hasSecLayerInVisibleRectChanged_;
235 targetDisplayParams->mirroredId_ = mirroredId_;
236 targetDisplayParams->compositeType_ = compositeType_;
237 targetDisplayParams->mirrorSourceDrawable_ = mirrorSourceDrawable_;
238 targetDisplayParams->mirrorSourceId_ = mirrorSourceId_;
239 targetDisplayParams->screenInfo_ = std::move(screenInfo_);
240 targetDisplayParams->isMainAndLeashSurfaceDirty_ = isMainAndLeashSurfaceDirty_;
241 targetDisplayParams->needOffscreen_ = needOffscreen_;
242 targetDisplayParams->isRotationChanged_ = isRotationChanged_;
243 targetDisplayParams->isRotationFinished_ = isRotationFinished_;
244 targetDisplayParams->hasFingerprint_ = hasFingerprint_;
245 targetDisplayParams->newColorSpace_ = newColorSpace_;
246 targetDisplayParams->newPixelFormat_ = newPixelFormat_;
247 targetDisplayParams->hasHdrPresent_ = hasHdrPresent_;
248 targetDisplayParams->brightnessRatio_ = brightnessRatio_;
249 targetDisplayParams->zOrder_ = zOrder_;
250 targetDisplayParams->isZoomed_ = isZoomed_;
251 targetDisplayParams->targetSurfaceRenderNodeDrawable_ = targetSurfaceRenderNodeDrawable_;
252 targetDisplayParams->roundCornerSurfaceDrawables_ = roundCornerSurfaceDrawables_;
253 targetDisplayParams->virtualScreenMuteStatus_ = virtualScreenMuteStatus_;
254 RSRenderParams::OnSync(target);
255 }
256
ToString() const257 std::string RSDisplayRenderParams::ToString() const
258 {
259 std::string ret = RSRenderParams::ToString() + ", RSDisplayRenderParams: {";
260 ret += RENDER_BASIC_PARAM_TO_STRING(offsetX_);
261 ret += RENDER_BASIC_PARAM_TO_STRING(offsetY_);
262 ret += RENDER_BASIC_PARAM_TO_STRING(int(nodeRotation_));
263 ret += RENDER_BASIC_PARAM_TO_STRING(int(screenRotation_));
264 ret += RENDER_BASIC_PARAM_TO_STRING(screenId_);
265 ret += RENDER_BASIC_PARAM_TO_STRING(mirroredId_);
266 ret += RENDER_BASIC_PARAM_TO_STRING(compositeType_);
267 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaces_.size());
268 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaceDrawables_.size());
269 ret += RENDER_PARAM_TO_STRING(screenInfo_);
270 ret += "}";
271 return ret;
272 }
273
GetMirrorSourceDrawable()274 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSDisplayRenderParams::GetMirrorSourceDrawable()
275 {
276 return mirrorSourceDrawable_;
277 }
278
HasCaptureWindow() const279 bool RSDisplayRenderParams::HasCaptureWindow() const
280 {
281 bool hasCaptureWindow = false;
282 auto iter = hasCaptureWindow_.find(screenId_);
283 if (iter != hasCaptureWindow_.end()) {
284 hasCaptureWindow = iter->second;
285 }
286 return hasCaptureWindow;
287 }
288
SetNeedOffscreen(bool needOffscreen)289 void RSDisplayRenderParams::SetNeedOffscreen(bool needOffscreen)
290 {
291 if (needOffscreen_ == needOffscreen) {
292 return;
293 }
294 needOffscreen_ = needOffscreen;
295 needSync_ = true;
296 }
297
GetNeedOffscreen() const298 bool RSDisplayRenderParams::GetNeedOffscreen() const
299 {
300 return needOffscreen_;
301 }
302
303 } // namespace OHOS::Rosen
304