• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_surface_render_params.h"
17 #include "rs_trace.h"
18 
19 namespace OHOS::Rosen {
RSSurfaceRenderParams(NodeId id)20 RSSurfaceRenderParams::RSSurfaceRenderParams(NodeId id) : RSRenderParams(id) {}
21 
SetOcclusionVisible(bool visible)22 void RSSurfaceRenderParams::SetOcclusionVisible(bool visible)
23 {
24     if (occlusionVisible_ == visible) {
25         return;
26     }
27     occlusionVisible_ = visible;
28     needSync_ = true;
29 }
30 
GetOcclusionVisible() const31 bool RSSurfaceRenderParams::GetOcclusionVisible() const
32 {
33     return occlusionVisible_;
34 }
35 
SetOldDirtyInSurface(const RectI & oldDirtyInSurface)36 void RSSurfaceRenderParams::SetOldDirtyInSurface(const RectI& oldDirtyInSurface)
37 {
38     oldDirtyInSurface_ = oldDirtyInSurface;
39 }
40 
GetOldDirtyInSurface() const41 RectI RSSurfaceRenderParams::GetOldDirtyInSurface() const
42 {
43     return oldDirtyInSurface_;
44 }
45 
SetIsParentScaling(bool isParentScaling)46 void RSSurfaceRenderParams::SetIsParentScaling(bool isParentScaling)
47 {
48     isParentScaling_ = isParentScaling;
49 }
50 
IsParentScaling() const51 bool RSSurfaceRenderParams::IsParentScaling() const
52 {
53     return isParentScaling_;
54 }
55 
SetTransparentRegion(const Occlusion::Region & transparentRegion)56 void RSSurfaceRenderParams::SetTransparentRegion(const Occlusion::Region& transparentRegion)
57 {
58     transparentRegion_ = transparentRegion;
59 }
60 
GetTransparentRegion() const61 const Occlusion::Region& RSSurfaceRenderParams::GetTransparentRegion() const
62 {
63     return transparentRegion_;
64 }
65 
GetVisibleRegion() const66 Occlusion::Region RSSurfaceRenderParams::GetVisibleRegion() const
67 {
68     return visibleRegion_;
69 }
70 
SetVisibleRegion(const Occlusion::Region & visibleRegion)71 void RSSurfaceRenderParams::SetVisibleRegion(const Occlusion::Region& visibleRegion)
72 {
73     visibleRegion_ = visibleRegion;
74     needSync_ = true;
75 }
76 
GetVisibleRegionInVirtual() const77 Occlusion::Region RSSurfaceRenderParams::GetVisibleRegionInVirtual() const
78 {
79     return visibleRegionInVirtual_;
80 }
81 
SetVisibleRegionInVirtual(const Occlusion::Region & visibleRegion)82 void RSSurfaceRenderParams::SetVisibleRegionInVirtual(const Occlusion::Region& visibleRegion)
83 {
84     visibleRegionInVirtual_ = visibleRegion;
85     needSync_ = true;
86 }
87 
SetOccludedByFilterCache(bool val)88 void RSSurfaceRenderParams::SetOccludedByFilterCache(bool val)
89 {
90     if (isOccludedByFilterCache_ == val) {
91         return;
92     }
93     isOccludedByFilterCache_ = val;
94     needSync_ = true;
95 }
96 
GetOccludedByFilterCache() const97 bool RSSurfaceRenderParams::GetOccludedByFilterCache() const
98 {
99     return isOccludedByFilterCache_;
100 }
101 
SetFilterCacheFullyCovered(bool val)102 void RSSurfaceRenderParams::SetFilterCacheFullyCovered(bool val)
103 {
104     isFilterCacheFullyCovered_ = val;
105 }
106 
GetFilterCacheFullyCovered() const107 bool RSSurfaceRenderParams::GetFilterCacheFullyCovered() const
108 {
109     return isFilterCacheFullyCovered_;
110 }
111 
GetVisibleFilterChild() const112 const std::vector<NodeId>& RSSurfaceRenderParams::GetVisibleFilterChild() const
113 {
114     return visibleFilterChild_;
115 }
116 
IsTransparent() const117 bool RSSurfaceRenderParams::IsTransparent() const
118 {
119     return isTransparent_;
120 }
121 
CheckValidFilterCacheFullyCoverTarget(bool isFilterCacheValidForOcclusion,const RectI & filterCachedRect,const RectI & targetRect)122 void RSSurfaceRenderParams::CheckValidFilterCacheFullyCoverTarget(
123     bool isFilterCacheValidForOcclusion, const RectI& filterCachedRect, const RectI& targetRect)
124 {
125     if (isFilterCacheFullyCovered_ || !isFilterCacheValidForOcclusion) {
126         return;
127     }
128     // AbsRect may not update here, so use filterCachedRegion to occlude
129     isFilterCacheFullyCovered_ = targetRect.IsInsideOf(filterCachedRect);
130 }
131 
SetLayerInfo(const RSLayerInfo & layerInfo)132 void RSSurfaceRenderParams::SetLayerInfo(const RSLayerInfo& layerInfo)
133 {
134 #ifndef ROSEN_CROSS_PLATFORM
135     layerInfo_ = layerInfo;
136     needSync_ = true;
137     dirtyType_.set(RSRenderParamsDirtyType::LAYER_INFO_DIRTY);
138 #endif
139 }
140 
GetLayerInfo() const141 const RSLayerInfo& RSSurfaceRenderParams::GetLayerInfo() const
142 {
143     return layerInfo_;
144 }
145 
SetHidePrivacyContent(bool needHidePrivacyContent)146 void RSSurfaceRenderParams::SetHidePrivacyContent(bool needHidePrivacyContent)
147 {
148     needHidePrivacyContent_ = needHidePrivacyContent;
149 }
150 
GetHidePrivacyContent() const151 bool RSSurfaceRenderParams::GetHidePrivacyContent() const
152 {
153     return needHidePrivacyContent_;
154 }
155 
SetHardwareEnabled(bool enabled)156 void RSSurfaceRenderParams::SetHardwareEnabled(bool enabled)
157 {
158     if (isHardwareEnabled_ == enabled) {
159         return;
160     }
161     isHardwareEnabled_ = enabled;
162     needSync_ = true;
163 }
164 
GetHardwareEnabled() const165 bool RSSurfaceRenderParams::GetHardwareEnabled() const
166 {
167     return isHardwareEnabled_;
168 }
169 
SetLastFrameHardwareEnabled(bool enabled)170 void RSSurfaceRenderParams::SetLastFrameHardwareEnabled(bool enabled)
171 {
172     if (isLastFrameHardwareEnabled_ == enabled) {
173         return;
174     }
175     isLastFrameHardwareEnabled_ = enabled;
176     needSync_ = true;
177 }
178 
SetLayerSourceTuning(int32_t needSourceTuning)179 void RSSurfaceRenderParams::SetLayerSourceTuning(int32_t needSourceTuning)
180 {
181     if (layerSource_ == needSourceTuning) {
182         return;
183     }
184     layerSource_ = needSourceTuning;
185     needSync_ = true;
186 }
187 
GetLayerSourceTuning() const188 int32_t RSSurfaceRenderParams::GetLayerSourceTuning() const
189 {
190     return layerSource_;
191 }
192 
GetLastFrameHardwareEnabled() const193 bool RSSurfaceRenderParams::GetLastFrameHardwareEnabled() const
194 {
195     return isLastFrameHardwareEnabled_;
196 }
197 
SetFixRotationByUser(bool flag)198 void RSSurfaceRenderParams::SetFixRotationByUser(bool flag)
199 {
200     if (isFixRotationByUser_ == flag) {
201         return;
202     }
203     isFixRotationByUser_ = flag;
204     needSync_ = true;
205 }
206 
GetFixRotationByUser() const207 bool RSSurfaceRenderParams::GetFixRotationByUser() const
208 {
209     return isFixRotationByUser_;
210 }
211 
SetInFixedRotation(bool flag)212 void RSSurfaceRenderParams::SetInFixedRotation(bool flag)
213 {
214     if (isInFixedRotation_ == flag) {
215         return;
216     }
217     isInFixedRotation_ = flag;
218     needSync_ = true;
219 }
220 
IsInFixedRotation() const221 bool RSSurfaceRenderParams::IsInFixedRotation() const
222 {
223     return isInFixedRotation_;
224 }
225 
226 #ifndef ROSEN_CROSS_PLATFORM
SetBuffer(const sptr<SurfaceBuffer> & buffer,const Rect & damageRect)227 void RSSurfaceRenderParams::SetBuffer(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect)
228 {
229     buffer_ = buffer;
230     damageRect_ = damageRect;
231     needSync_ = true;
232     dirtyType_.set(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY);
233 }
234 
GetBuffer() const235 sptr<SurfaceBuffer> RSSurfaceRenderParams::GetBuffer() const
236 {
237     return buffer_;
238 }
239 
GetBufferDamage() const240 const Rect& RSSurfaceRenderParams::GetBufferDamage() const
241 {
242     return damageRect_;
243 }
244 
SetPreBuffer(const sptr<SurfaceBuffer> & preBuffer)245 void RSSurfaceRenderParams::SetPreBuffer(const sptr<SurfaceBuffer>& preBuffer)
246 {
247     preBuffer_ = preBuffer;
248     needSync_ = true;
249     dirtyType_.set(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY);
250 }
251 
GetPreBuffer()252 sptr<SurfaceBuffer> RSSurfaceRenderParams::GetPreBuffer()
253 {
254     return preBuffer_;
255 }
256 
SetAcquireFence(const sptr<SyncFence> & acquireFence)257 void RSSurfaceRenderParams::SetAcquireFence(const sptr<SyncFence>& acquireFence)
258 {
259     acquireFence_ = acquireFence;
260     needSync_ = true;
261     dirtyType_.set(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY);
262 }
263 
GetAcquireFence() const264 sptr<SyncFence> RSSurfaceRenderParams::GetAcquireFence() const
265 {
266     return acquireFence_;
267 }
268 #endif
269 
GetPreSurfaceCacheContentStatic() const270 bool RSSurfaceRenderParams::GetPreSurfaceCacheContentStatic() const
271 {
272     return preSurfaceCacheContentStatic_;
273 }
274 
SetSurfaceCacheContentStatic(bool contentStatic,bool lastFrameSynced)275 void RSSurfaceRenderParams::SetSurfaceCacheContentStatic(bool contentStatic, bool lastFrameSynced)
276 {
277     // 1. don't sync while contentStatic not change
278     if (surfaceCacheContentStatic_ == contentStatic) {
279         return;
280     }
281     // 2. don't sync while last frame isn't static and skip sync
282     if (!surfaceCacheContentStatic_ && !lastFrameSynced) {
283         return;
284     }
285     preSurfaceCacheContentStatic_ = surfaceCacheContentStatic_;
286     surfaceCacheContentStatic_ = contentStatic;
287     needSync_ = true;
288 }
289 
GetSurfaceCacheContentStatic() const290 bool RSSurfaceRenderParams::GetSurfaceCacheContentStatic() const
291 {
292     return surfaceCacheContentStatic_;
293 }
294 
GetPositionZ() const295 float RSSurfaceRenderParams::GetPositionZ() const
296 {
297     return positionZ_;
298 }
299 
SetSurfaceSubTreeDirty(bool isSubTreeDirty)300 void RSSurfaceRenderParams::SetSurfaceSubTreeDirty(bool isSubTreeDirty)
301 {
302     if (isSubTreeDirty_ == isSubTreeDirty) {
303         return;
304     }
305     isSubTreeDirty_ = isSubTreeDirty;
306     needSync_ = true;
307 }
308 
GetSurfaceSubTreeDirty() const309 bool RSSurfaceRenderParams::GetSurfaceSubTreeDirty() const
310 {
311     return isSubTreeDirty_;
312 }
313 
SetGpuOverDrawBufferOptimizeNode(bool overDrawNode)314 void RSSurfaceRenderParams::SetGpuOverDrawBufferOptimizeNode(bool overDrawNode)
315 {
316     if (isGpuOverDrawBufferOptimizeNode_ == overDrawNode) {
317         return;
318     }
319     isGpuOverDrawBufferOptimizeNode_ = overDrawNode;
320     needSync_ = true;
321 }
322 
IsGpuOverDrawBufferOptimizeNode() const323 bool RSSurfaceRenderParams::IsGpuOverDrawBufferOptimizeNode() const
324 {
325     return isGpuOverDrawBufferOptimizeNode_;
326 }
327 
SetOverDrawBufferNodeCornerRadius(const Vector4f & radius)328 void RSSurfaceRenderParams::SetOverDrawBufferNodeCornerRadius(const Vector4f& radius)
329 {
330     if (overDrawBufferNodeCornerRadius_ == radius) {
331         return;
332     }
333     overDrawBufferNodeCornerRadius_ = radius;
334     needSync_ = true;
335 }
336 
GetOverDrawBufferNodeCornerRadius() const337 const Vector4f& RSSurfaceRenderParams::GetOverDrawBufferNodeCornerRadius() const
338 {
339     return overDrawBufferNodeCornerRadius_;
340 }
341 
SetIsSubSurfaceNode(bool isSubSurfaceNode)342 void RSSurfaceRenderParams::SetIsSubSurfaceNode(bool isSubSurfaceNode)
343 {
344     isSubSurfaceNode_ = isSubSurfaceNode;
345 }
346 
IsSubSurfaceNode() const347 bool RSSurfaceRenderParams::IsSubSurfaceNode() const
348 {
349     return isSubSurfaceNode_;
350 }
351 
SetIsNodeToBeCaptured(bool isNodeToBeCaptured)352 void RSSurfaceRenderParams::SetIsNodeToBeCaptured(bool isNodeToBeCaptured)
353 {
354     isNodeToBeCaptured_ = isNodeToBeCaptured;
355 }
356 
IsNodeToBeCaptured() const357 bool RSSurfaceRenderParams::IsNodeToBeCaptured() const
358 {
359     return isNodeToBeCaptured_;
360 }
361 
SetSkipDraw(bool skip)362 void RSSurfaceRenderParams::SetSkipDraw(bool skip)
363 {
364     isSkipDraw_ = skip;
365 }
366 
GetSkipDraw() const367 bool RSSurfaceRenderParams::GetSkipDraw() const
368 {
369     return isSkipDraw_;
370 }
371 
SetLayerTop(bool isTop)372 void RSSurfaceRenderParams::SetLayerTop(bool isTop)
373 {
374     if (isLayerTop_ == isTop) {
375         return;
376     }
377     isLayerTop_ = isTop;
378     needSync_ = true;
379 }
380 
IsLayerTop() const381 bool RSSurfaceRenderParams::IsLayerTop() const
382 {
383     return isLayerTop_;
384 }
385 
OnSync(const std::unique_ptr<RSRenderParams> & target)386 void RSSurfaceRenderParams::OnSync(const std::unique_ptr<RSRenderParams>& target)
387 {
388     auto targetSurfaceParams = static_cast<RSSurfaceRenderParams*>(target.get());
389     if (targetSurfaceParams == nullptr) {
390         RS_LOGE("RSSurfaceRenderParams::OnSync targetSurfaceParams is nullptr");
391         return;
392     }
393 
394     if (dirtyType_.test(RSRenderParamsDirtyType::LAYER_INFO_DIRTY)) {
395         targetSurfaceParams->layerInfo_ = layerInfo_;
396         dirtyType_.reset(RSRenderParamsDirtyType::LAYER_INFO_DIRTY);
397     }
398     targetSurfaceParams->windowInfo_ = windowInfo_;
399 
400 #ifndef ROSEN_CROSS_PLATFORM
401     if (dirtyType_.test(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY)) {
402         targetSurfaceParams->buffer_ = buffer_;
403         targetSurfaceParams->preBuffer_ = preBuffer_;
404         targetSurfaceParams->acquireFence_ = acquireFence_;
405         targetSurfaceParams->damageRect_ = damageRect_;
406         bufferSynced_ = true;
407         dirtyType_.reset(RSRenderParamsDirtyType::BUFFER_INFO_DIRTY);
408     }
409 #endif
410 
411     targetSurfaceParams->rsSurfaceNodeType_ = rsSurfaceNodeType_;
412     targetSurfaceParams->selfDrawingType_ = selfDrawingType_;
413     targetSurfaceParams->ancestorDisplayNode_ = ancestorDisplayNode_;
414     targetSurfaceParams->ancestorDisplayDrawable_ = ancestorDisplayDrawable_;
415     targetSurfaceParams->alpha_ = alpha_;
416     targetSurfaceParams->isSpherizeValid_ = isSpherizeValid_;
417     targetSurfaceParams->isParentScaling_ = isParentScaling_;
418     targetSurfaceParams->needBilinearInterpolation_ = needBilinearInterpolation_;
419     targetSurfaceParams->backgroundColor_ = backgroundColor_;
420     targetSurfaceParams->absDrawRect_ = absDrawRect_;
421     targetSurfaceParams->rrect_ = rrect_;
422     targetSurfaceParams->occlusionVisible_ = occlusionVisible_;
423     targetSurfaceParams->visibleRegion_ = visibleRegion_;
424     targetSurfaceParams->visibleRegionInVirtual_ = visibleRegionInVirtual_;
425     targetSurfaceParams->oldDirtyInSurface_ = oldDirtyInSurface_;
426     targetSurfaceParams->transparentRegion_ = transparentRegion_;
427     targetSurfaceParams->isHardwareEnabled_ = isHardwareEnabled_;
428     targetSurfaceParams->isLastFrameHardwareEnabled_ = isLastFrameHardwareEnabled_;
429     targetSurfaceParams->isFixRotationByUser_ = isFixRotationByUser_;
430     targetSurfaceParams->isInFixedRotation_ = isInFixedRotation_;
431     targetSurfaceParams->uiFirstFlag_ = uiFirstFlag_;
432     targetSurfaceParams->uiFirstParentFlag_ = uiFirstParentFlag_;
433     targetSurfaceParams->uifirstUseStarting_ = uifirstUseStarting_;
434     targetSurfaceParams->childrenDirtyRect_ = childrenDirtyRect_;
435     targetSurfaceParams->isOccludedByFilterCache_ = isOccludedByFilterCache_;
436     targetSurfaceParams->isSecurityLayer_ = isSecurityLayer_;
437     targetSurfaceParams->leashPersistentId_ = leashPersistentId_;
438     targetSurfaceParams->isSkipLayer_ = isSkipLayer_;
439     targetSurfaceParams->isProtectedLayer_ = isProtectedLayer_;
440     targetSurfaceParams->drmCornerRadiusInfo_ = drmCornerRadiusInfo_;
441     targetSurfaceParams->animateState_ = animateState_;
442     targetSurfaceParams->skipLayerIds_= skipLayerIds_;
443     targetSurfaceParams->securityLayerIds_= securityLayerIds_;
444     targetSurfaceParams->protectedLayerIds_ = protectedLayerIds_;
445     targetSurfaceParams->privacyContentLayerIds_ = privacyContentLayerIds_;
446     targetSurfaceParams->name_ = name_;
447     targetSurfaceParams->surfaceCacheContentStatic_ = surfaceCacheContentStatic_;
448     targetSurfaceParams->bufferCacheSet_ = bufferCacheSet_;
449     targetSurfaceParams->positionZ_ = positionZ_;
450     targetSurfaceParams->isSubTreeDirty_ = isSubTreeDirty_;
451     targetSurfaceParams->overDrawBufferNodeCornerRadius_ = overDrawBufferNodeCornerRadius_;
452     targetSurfaceParams->isGpuOverDrawBufferOptimizeNode_ = isGpuOverDrawBufferOptimizeNode_;
453     targetSurfaceParams->isSubSurfaceNode_ = isSubSurfaceNode_;
454     targetSurfaceParams->isNodeToBeCaptured_ = isNodeToBeCaptured_;
455     targetSurfaceParams->dstRect_ = dstRect_;
456     targetSurfaceParams->isSkipDraw_ = isSkipDraw_;
457     targetSurfaceParams->isLayerTop_ = isLayerTop_;
458     targetSurfaceParams->needHidePrivacyContent_ = needHidePrivacyContent_;
459     targetSurfaceParams->isLeashWindowVisibleRegionEmpty_ = isLeashWindowVisibleRegionEmpty_;
460     targetSurfaceParams->opaqueRegion_ = opaqueRegion_;
461     targetSurfaceParams->scalingMode_ = scalingMode_;
462     targetSurfaceParams->needOffscreen_ = needOffscreen_;
463     targetSurfaceParams->totalMatrix_ = totalMatrix_;
464     targetSurfaceParams->visibleFilterChild_ = visibleFilterChild_;
465     targetSurfaceParams->isTransparent_ = isTransparent_;
466     targetSurfaceParams->globalAlpha_ = globalAlpha_;
467     targetSurfaceParams->hasFingerprint_ = hasFingerprint_;
468     targetSurfaceParams->layerSource_ = layerSource_;
469     targetSurfaceParams->sdrNit_ = sdrNit_;
470     targetSurfaceParams->displayNit_ = displayNit_;
471     targetSurfaceParams->brightnessRatio_ = brightnessRatio_;
472     RSRenderParams::OnSync(target);
473 }
474 
ToString() const475 std::string RSSurfaceRenderParams::ToString() const
476 {
477     std::string ret = RSRenderParams::ToString() + ", RSSurfaceRenderParams: {";
478     ret += RENDER_BASIC_PARAM_TO_STRING(int(rsSurfaceNodeType_));
479     ret += RENDER_BASIC_PARAM_TO_STRING(int(selfDrawingType_));
480     ret += RENDER_BASIC_PARAM_TO_STRING(alpha_);
481     ret += RENDER_BASIC_PARAM_TO_STRING(isSpherizeValid_);
482     ret += RENDER_BASIC_PARAM_TO_STRING(needBilinearInterpolation_);
483     ret += RENDER_BASIC_PARAM_TO_STRING(backgroundColor_.GetAlpha());
484     ret += RENDER_RECT_PARAM_TO_STRING(absDrawRect_);
485     ret += RENDER_BASIC_PARAM_TO_STRING(occlusionVisible_);
486     ret += RENDER_BASIC_PARAM_TO_STRING(isOccludedByFilterCache_);
487     ret += "}";
488     return ret;
489 }
490 
IsVisibleDirtyRegionEmpty(const Drawing::Region curSurfaceDrawRegion) const491 bool RSSurfaceRenderParams::IsVisibleDirtyRegionEmpty(const Drawing::Region curSurfaceDrawRegion) const
492 {
493     if (IsMainWindowType()) {
494         return curSurfaceDrawRegion.IsEmpty();
495     }
496     if (IsLeashWindow()) {
497         return GetLeashWindowVisibleRegionEmptyParam();
498     }
499     return false;
500 }
501 
SetOpaqueRegion(const Occlusion::Region & opaqueRegion)502 void RSSurfaceRenderParams::SetOpaqueRegion(const Occlusion::Region& opaqueRegion)
503 {
504     opaqueRegion_ = opaqueRegion;
505 }
506 
GetOpaqueRegion() const507 const Occlusion::Region& RSSurfaceRenderParams::GetOpaqueRegion() const
508 {
509     return opaqueRegion_;
510 }
511 
512 } // namespace OHOS::Rosen
513