• 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_render_params.h"
17 
18 #include <string>
19 
20 #include "params/rs_surface_render_params.h"
21 #include "pipeline/rs_render_node.h"
22 #include "property/rs_properties.h"
23 #include "property/rs_properties_painter.h"
24 #include "screen_manager/rs_screen_info.h"
25 namespace OHOS::Rosen {
26 namespace {
27 thread_local Drawing::Matrix parentSurfaceMatrix_;
28 }
SetDirtyType(RSRenderParamsDirtyType dirtyType)29 void RSRenderParams::SetDirtyType(RSRenderParamsDirtyType dirtyType)
30 {
31     dirtyType_.set(dirtyType);
32 }
33 
SetAlpha(float alpha)34 void RSRenderParams::SetAlpha(float alpha)
35 {
36     if (alpha_ == alpha) {
37         return;
38     }
39     alpha_ = alpha;
40     needSync_ = true;
41 }
42 
SetAlphaOffScreen(bool alphaOffScreen)43 void RSRenderParams::SetAlphaOffScreen(bool alphaOffScreen)
44 {
45     if (alphaOffScreen_ == alphaOffScreen) {
46         return;
47     }
48     alphaOffScreen_ = alphaOffScreen;
49     needSync_ = true;
50 }
51 
GetAlphaOffScreen() const52 bool RSRenderParams::GetAlphaOffScreen() const
53 {
54     return alphaOffScreen_;
55 }
56 
SetMatrix(const Drawing::Matrix & matrix)57 void RSRenderParams::SetMatrix(const Drawing::Matrix& matrix)
58 {
59     matrix_ = matrix;
60     needSync_ = true;
61     dirtyType_.set(RSRenderParamsDirtyType::MATRIX_DIRTY);
62 }
63 
ApplyAlphaAndMatrixToCanvas(RSPaintFilterCanvas & canvas,bool applyMatrix) const64 void RSRenderParams::ApplyAlphaAndMatrixToCanvas(RSPaintFilterCanvas& canvas, bool applyMatrix) const
65 {
66     if (UNLIKELY(HasSandBox())) {
67         if (applyMatrix) {
68             canvas.SetMatrix(parentSurfaceMatrix_);
69             canvas.ConcatMatrix(matrix_);
70         }
71         canvas.SetAlpha(alpha_);
72     } else {
73         if (applyMatrix) {
74             canvas.ConcatMatrix(matrix_);
75         }
76         if (alpha_ < 1.0f && (drawingCacheType_ == RSDrawingCacheType::FORCED_CACHE || alphaOffScreen_)) {
77             auto rect = RSPropertiesPainter::Rect2DrawingRect(GetLocalDrawRect());
78             Drawing::Brush brush;
79             brush.SetAlpha(static_cast<uint32_t>(std::clamp(alpha_, 0.f, 1.f) * UINT8_MAX));
80             Drawing::SaveLayerOps slr(&rect, &brush);
81             canvas.SaveLayer(slr);
82         } else {
83             canvas.MultiplyAlpha(alpha_);
84         }
85     }
86 }
87 
SetBoundsRect(const Drawing::RectF & boundsRect)88 void RSRenderParams::SetBoundsRect(const Drawing::RectF& boundsRect)
89 {
90     if (boundsRect_ == boundsRect) {
91         return;
92     }
93     boundsRect_ = boundsRect;
94     needSync_ = true;
95 }
96 
SetFrameRect(const Drawing::RectF & frameRect)97 void RSRenderParams::SetFrameRect(const Drawing::RectF& frameRect)
98 {
99     if (frameRect_ == frameRect) {
100         return;
101     }
102 
103     frameRect_ = frameRect;
104     needSync_ = true;
105 }
106 
SetLocalDrawRect(const RectF & localDrawRect)107 bool RSRenderParams::SetLocalDrawRect(const RectF& localDrawRect)
108 {
109     if (localDrawRect_.IsNearEqual(localDrawRect)) {
110         return false;
111     }
112     localDrawRect_ = localDrawRect;
113     needSync_ = true;
114     return true;
115 }
116 
SetHasSandBox(bool hasSandbox)117 void RSRenderParams::SetHasSandBox(bool hasSandbox)
118 {
119     if (hasSandBox_ == hasSandbox) {
120         return;
121     }
122     hasSandBox_ = hasSandbox;
123     needSync_ = true;
124 }
125 
SetShouldPaint(bool shouldPaint)126 void RSRenderParams::SetShouldPaint(bool shouldPaint)
127 {
128     if (shouldPaint_ == shouldPaint) {
129         return;
130     }
131     shouldPaint_ = shouldPaint;
132     needSync_ = true;
133 }
134 
SetContentEmpty(bool empty)135 void RSRenderParams::SetContentEmpty(bool empty)
136 {
137     if (contentEmpty_ == empty) {
138         return;
139     }
140     contentEmpty_ = empty;
141     needSync_ = true;
142 }
143 
SetChildHasVisibleFilter(bool val)144 void RSRenderParams::SetChildHasVisibleFilter(bool val)
145 {
146     if (childHasVisibleFilter_ == val) {
147         return;
148     }
149     childHasVisibleFilter_ = val;
150     needSync_ = true;
151 }
152 
SetChildHasVisibleEffect(bool val)153 void RSRenderParams::SetChildHasVisibleEffect(bool val)
154 {
155     if (childHasVisibleEffect_ == val) {
156         return;
157     }
158     childHasVisibleEffect_ = val;
159     needSync_ = true;
160 }
161 
SetCacheSize(Vector2f size)162 void RSRenderParams::SetCacheSize(Vector2f size)
163 {
164     if (cacheSize_ == size) {
165         return;
166     }
167     cacheSize_ = size;
168     needSync_ = true;
169 }
170 
SetDrawingCacheChanged(bool isChanged,bool lastFrameSynced)171 void RSRenderParams::SetDrawingCacheChanged(bool isChanged, bool lastFrameSynced)
172 {
173     if (lastFrameSynced) {
174         if (isDrawingCacheChanged_) { // force sync if cache changed
175             needSync_ = true;
176         }
177         if (isDrawingCacheChanged_ == isChanged) {
178             return;
179         }
180         isDrawingCacheChanged_ = isChanged;
181         needSync_ = true;
182     } else {
183         needSync_ = needSync_ || (isDrawingCacheChanged_ || (isDrawingCacheChanged_ != isChanged));
184         isDrawingCacheChanged_ = isDrawingCacheChanged_ || isChanged;
185     }
186 }
187 
SetDrawingCacheType(RSDrawingCacheType cacheType)188 void RSRenderParams::SetDrawingCacheType(RSDrawingCacheType cacheType)
189 {
190     if (drawingCacheType_ == cacheType) {
191         return;
192     }
193     dirtyType_.set(RSRenderParamsDirtyType::DRAWING_CACHE_TYPE_DIRTY);
194     drawingCacheType_ = cacheType;
195     needSync_ = true;
196 }
197 
SetDrawingCacheIncludeProperty(bool includeProperty)198 void RSRenderParams::SetDrawingCacheIncludeProperty(bool includeProperty)
199 {
200     if (drawingCacheIncludeProperty_ == includeProperty) {
201         return;
202     }
203     drawingCacheIncludeProperty_ = includeProperty;
204     needSync_ = true;
205 }
206 
SetRSFreezeFlag(bool freezeFlag)207 void RSRenderParams::SetRSFreezeFlag(bool freezeFlag)
208 {
209     if (freezeFlag_ == freezeFlag) {
210         return;
211     }
212     freezeFlag_ = freezeFlag;
213     needSync_ = true;
214 }
215 
OpincSetIsSuggest(bool isSuggest)216 void RSRenderParams::OpincSetIsSuggest(bool isSuggest)
217 {
218     if (isOpincSuggestFlag_ == isSuggest) {
219         return;
220     }
221     isOpincSuggestFlag_ = isSuggest;
222     needSync_ = true;
223 }
224 
OpincUpdateSupportFlag(bool supportFlag)225 void RSRenderParams::OpincUpdateSupportFlag(bool supportFlag)
226 {
227     if (isOpincSupportFlag_ == supportFlag) {
228         return;
229     }
230     isOpincSupportFlag_ = supportFlag;
231     needSync_ = true;
232 }
233 
OpincUpdateRootFlag(bool suggestFlag)234 void RSRenderParams::OpincUpdateRootFlag(bool suggestFlag)
235 {
236     if (isOpincRootFlag_ == suggestFlag) {
237         return;
238     }
239     isOpincRootFlag_ = suggestFlag;
240     needSync_ = true;
241 }
242 
OpincSetCacheChangeFlag(bool state,bool lastFrameSynced)243 void RSRenderParams::OpincSetCacheChangeFlag(bool state, bool lastFrameSynced)
244 {
245     if (lastFrameSynced) {
246         isOpincStateChanged_ = state;
247         needSync_ = true;
248     } else {
249         needSync_ = needSync_ || (isOpincStateChanged_ || (isOpincStateChanged_ != state));
250         isOpincStateChanged_ = isOpincStateChanged_ || state;
251     }
252 }
253 
SetShadowRect(Drawing::Rect rect)254 void RSRenderParams::SetShadowRect(Drawing::Rect rect)
255 {
256     if (shadowRect_ == rect) {
257         return;
258     }
259     shadowRect_ = rect;
260     needSync_ = true;
261 }
262 
SetNeedSync(bool needSync)263 void RSRenderParams::SetNeedSync(bool needSync)
264 {
265     needSync_ = needSync;
266 }
267 
SetFrameGravity(Gravity gravity)268 void RSRenderParams::SetFrameGravity(Gravity gravity)
269 {
270     if (frameGravity_ == gravity) {
271         return;
272     }
273     frameGravity_ = gravity;
274     needSync_ = true;
275 }
276 
SetHDRBrightness(float hdrBrightness)277 void RSRenderParams::SetHDRBrightness(float hdrBrightness)
278 {
279     if (ROSEN_EQ(hdrBrightness_, hdrBrightness)) {
280         return;
281     }
282     hdrBrightness_ = hdrBrightness;
283     needSync_ = true;
284 }
285 
SetNeedFilter(bool needFilter)286 void RSRenderParams::SetNeedFilter(bool needFilter)
287 {
288     if (needFilter_ == needFilter) {
289         return;
290     }
291     needFilter_ = needFilter;
292     needSync_ = true;
293 }
294 
SetNodeType(RSRenderNodeType type)295 void RSRenderParams::SetNodeType(RSRenderNodeType type)
296 {
297     if (renderNodeType_ == type) {
298         return;
299     }
300     renderNodeType_ = type;
301     needSync_ = true;
302 }
303 
SetEffectNodeShouldPaint(bool effectNodeShouldPaint)304 void RSRenderParams::SetEffectNodeShouldPaint(bool effectNodeShouldPaint)
305 {
306     if (effectNodeShouldPaint_ == effectNodeShouldPaint) {
307         return;
308     }
309     effectNodeShouldPaint_ = effectNodeShouldPaint;
310     needSync_ = true;
311 }
312 
SetHasGlobalCorner(bool hasGlobalCorner)313 void RSRenderParams::SetHasGlobalCorner(bool hasGlobalCorner)
314 {
315     if (hasGlobalCorner_ == hasGlobalCorner) {
316         return;
317     }
318     hasGlobalCorner_ = hasGlobalCorner;
319     needSync_ = true;
320 }
321 
SetHasBlurFilter(bool hasBlurFilter)322 void RSRenderParams::SetHasBlurFilter(bool hasBlurFilter)
323 {
324     if (hasBlurFilter_ == hasBlurFilter) {
325         return;
326     }
327     hasBlurFilter_ = hasBlurFilter;
328     needSync_ = true;
329 }
330 
SetGlobalAlpha(float alpha)331 void RSRenderParams::SetGlobalAlpha(float alpha)
332 {
333     if (ROSEN_EQ(globalAlpha_, alpha)) {
334         return;
335     }
336     globalAlpha_ = alpha;
337     needSync_ = true;
338 }
339 
SetVirtualScreenWhiteListInfo(const std::unordered_map<ScreenId,bool> & info)340 void RSRenderParams::SetVirtualScreenWhiteListInfo(const std::unordered_map<ScreenId, bool>& info)
341 {
342     if (info == hasVirtualScreenWhiteList_) {
343         return;
344     }
345     hasVirtualScreenWhiteList_ = info;
346     needSync_ = true;
347 }
348 
OnCanvasDrawingSurfaceChange(const std::unique_ptr<RSRenderParams> & target)349 void RSRenderParams::OnCanvasDrawingSurfaceChange(const std::unique_ptr<RSRenderParams>& target)
350 {
351     if (!canvasDrawingNodeSurfaceChanged_) {
352         return;
353     }
354     target->canvasDrawingNodeSurfaceChanged_ = true;
355     target->surfaceParams_.width = surfaceParams_.width;
356     target->surfaceParams_.height = surfaceParams_.height;
357     target->surfaceParams_.colorSpace = surfaceParams_.colorSpace;
358     if (GetParamsType() == RSRenderParamsType::RS_PARAM_OWNED_BY_DRAWABLE) {
359         return;
360     }
361     canvasDrawingNodeSurfaceChanged_ = false;
362 }
363 
SetCanvasDrawingSurfaceChanged(bool changeFlag)364 void RSRenderParams::SetCanvasDrawingSurfaceChanged(bool changeFlag)
365 {
366     if (changeFlag) {
367         needSync_ = true;
368     }
369     canvasDrawingNodeSurfaceChanged_ = changeFlag;
370 }
371 
IsRepaintBoundary() const372 bool RSRenderParams::IsRepaintBoundary() const
373 {
374     return isRepaintBoundary_;
375 }
376 
MarkRepaintBoundary(bool isRepaintBoundary)377 void RSRenderParams::MarkRepaintBoundary(bool isRepaintBoundary)
378 {
379     isRepaintBoundary_ = isRepaintBoundary;
380 }
381 
SetForegroundFilterCache(const std::shared_ptr<RSFilter> & foregroundFilterCache)382 void RSRenderParams::SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache)
383 {
384     if (foregroundFilterCache_ == foregroundFilterCache) {
385         return;
386     }
387     foregroundFilterCache_ = foregroundFilterCache;
388     needSync_ = true;
389 }
390 
SetCanvasDrawingSurfaceParams(int width,int height,GraphicColorGamut colorSpace)391 void RSRenderParams::SetCanvasDrawingSurfaceParams(int width, int height, GraphicColorGamut colorSpace)
392 {
393     surfaceParams_.width = width;
394     surfaceParams_.height = height;
395     surfaceParams_.colorSpace = colorSpace;
396 }
397 
OnSync(const std::unique_ptr<RSRenderParams> & target)398 void RSRenderParams::OnSync(const std::unique_ptr<RSRenderParams>& target)
399 {
400     if (dirtyType_.test(RSRenderParamsDirtyType::MATRIX_DIRTY)) {
401         target->matrix_.Swap(matrix_);
402         dirtyType_.reset(RSRenderParamsDirtyType::MATRIX_DIRTY);
403     }
404     if (dirtyType_.test(RSRenderParamsDirtyType::DRAWING_CACHE_TYPE_DIRTY)) {
405         target->drawingCacheType_ = drawingCacheType_;
406         dirtyType_.reset(RSRenderParamsDirtyType::DRAWING_CACHE_TYPE_DIRTY);
407     }
408     target->alpha_ = alpha_;
409     target->boundsRect_ = boundsRect_;
410     target->frameRect_ = frameRect_;
411     target->shouldPaint_ = shouldPaint_;
412     target->contentEmpty_ = contentEmpty_;
413     target->hasSandBox_ = hasSandBox_;
414     target->localDrawRect_ = localDrawRect_;
415     target->id_ = id_;
416     target->cacheSize_ = cacheSize_;
417     target->frameGravity_ = frameGravity_;
418     target->childHasVisibleFilter_ = childHasVisibleFilter_;
419     target->childHasVisibleEffect_ = childHasVisibleEffect_;
420     // use flag in render param and staging render param to determine if cache should be updated
421     // (flag in render param may be not used because of occlusion skip, so we need to update cache in next frame)
422     target->isDrawingCacheChanged_ = target->isDrawingCacheChanged_ || isDrawingCacheChanged_;
423     target->shadowRect_ = shadowRect_;
424     target->drawingCacheIncludeProperty_ = drawingCacheIncludeProperty_;
425     target->isNodeGroupHasChildInBlacklist_ = isNodeGroupHasChildInBlacklist_;
426     target->dirtyRegionInfoForDFX_ = dirtyRegionInfoForDFX_;
427     target->isRepaintBoundary_ = isRepaintBoundary_;
428     target->alphaOffScreen_ = alphaOffScreen_;
429     target->hdrBrightness_ = hdrBrightness_;
430     target->needFilter_ = needFilter_;
431     target->renderNodeType_ = renderNodeType_;
432     target->globalAlpha_ = globalAlpha_;
433     target->effectNodeShouldPaint_ = effectNodeShouldPaint_;
434     target->hasGlobalCorner_ = hasGlobalCorner_;
435     target->hasBlurFilter_ = hasBlurFilter_;
436     target->foregroundFilterCache_ = foregroundFilterCache_;
437     OnCanvasDrawingSurfaceChange(target);
438     target->isOpincSuggestFlag_ = isOpincSuggestFlag_;
439     target->isOpincSupportFlag_ = isOpincSupportFlag_;
440     target->isOpincRootFlag_ = isOpincRootFlag_;
441     target->isOpincStateChanged_ = target->isOpincStateChanged_ || isOpincStateChanged_;
442     target->startingWindowFlag_ = startingWindowFlag_;
443     target->freezeFlag_ = freezeFlag_;
444     target->absDrawRect_ = absDrawRect_;
445     target->firstLevelNodeId_ = firstLevelNodeId_;
446     target->uifirstRootNodeId_ = uifirstRootNodeId_;
447     target->isFirstLevelCrossNode_ = isFirstLevelCrossNode_;
448     target->cloneSourceDrawable_ = cloneSourceDrawable_;
449     target->isCrossNodeOffscreenOn_ = isCrossNodeOffscreenOn_;
450     target->absRotation_ = absRotation_;
451     target->hasUnobscuredUEC_ = hasUnobscuredUEC_;
452 
453     // [Attention] Only used in PC window resize scene now
454     target->windowKeyframeEnabled_ = windowKeyframeEnabled_;
455     target->linkedRootNodeDrawable_ = linkedRootNodeDrawable_;
456     target->needSwapBuffer_ = needSwapBuffer_;
457     target->cacheNodeFrameRect_ = cacheNodeFrameRect_;
458 
459     // used for DFX
460     target->isOnTheTree_ = isOnTheTree_;
461 
462     target->hasVirtualScreenWhiteList_ = hasVirtualScreenWhiteList_;
463     needSync_ = false;
464 }
465 
ToString() const466 std::string RSRenderParams::ToString() const
467 {
468     std::string ret = "RSRenderParams:";
469     ret += RENDER_BASIC_PARAM_TO_STRING(id_);
470     if (alpha_ != 1.0f) {
471         ret += RENDER_BASIC_PARAM_TO_STRING(alpha_);
472     }
473     if (hasSandBox_) {
474         ret += RENDER_BASIC_PARAM_TO_STRING(hasSandBox_);
475     }
476     ret += RENDER_RECT_PARAM_TO_STRING(localDrawRect_);
477     ret += RENDER_BASIC_PARAM_TO_STRING(shouldPaint_);
478     ret += RENDER_BASIC_PARAM_TO_STRING(int(frameGravity_));
479     if (foregroundFilterCache_ != nullptr) {
480         ret += foregroundFilterCache_->GetDescription();
481     }
482     return ret;
483 }
484 
SetParentSurfaceMatrix(const Drawing::Matrix & parentSurfaceMatrix)485 void RSRenderParams::SetParentSurfaceMatrix(const Drawing::Matrix& parentSurfaceMatrix)
486 {
487     parentSurfaceMatrix_ = parentSurfaceMatrix;
488 }
GetParentSurfaceMatrix()489 const Drawing::Matrix& RSRenderParams::GetParentSurfaceMatrix()
490 {
491     return parentSurfaceMatrix_;
492 }
493 
SetFirstLevelNode(NodeId firstLevelNodeId)494 bool RSRenderParams::SetFirstLevelNode(NodeId firstLevelNodeId)
495 {
496     if (firstLevelNodeId_ == firstLevelNodeId) {
497         return false;
498     }
499     firstLevelNodeId_ = firstLevelNodeId;
500     needSync_ = true;
501     return true;
502 }
503 
SetUiFirstRootNode(NodeId uifirstRootNodeId)504 bool RSRenderParams::SetUiFirstRootNode(NodeId uifirstRootNodeId)
505 {
506     if (uifirstRootNodeId_ == uifirstRootNodeId) {
507         return false;
508     }
509     uifirstRootNodeId_ = uifirstRootNodeId;
510     needSync_ = true;
511     return true;
512 }
513 
514 // overrided surface params
GetLayerInfo() const515 const RSLayerInfo& RSRenderParams::GetLayerInfo() const
516 {
517     static const RSLayerInfo defaultLayerInfo = {};
518     return defaultLayerInfo;
519 }
520 
GetTotalMatrix()521 const Drawing::Matrix& RSRenderParams::GetTotalMatrix()
522 {
523     static const Drawing::Matrix defaultMatrix;
524     return defaultMatrix;
525 }
526 // virtual display params
GetMirrorSourceDrawable()527 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSRenderParams::GetMirrorSourceDrawable()
528 {
529     static DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr defaultPtr;
530     return defaultPtr;
531 }
532 
SetCloneSourceDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)533 void RSRenderParams::SetCloneSourceDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)
534 {
535     cloneSourceDrawable_ = drawable;
536 }
537 
538 // [Attention] Only used in PC window resize scene now
EnableWindowKeyFrame(bool enable)539 void RSRenderParams::EnableWindowKeyFrame(bool enable)
540 {
541     if (windowKeyframeEnabled_ == enable) {
542         return;
543     }
544 
545     windowKeyframeEnabled_ = enable;
546     needSync_ = true;
547 }
548 
549 // [Attention] Only used in PC window resize scene now
SetLinkedRootNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)550 void RSRenderParams::SetLinkedRootNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)
551 {
552     linkedRootNodeDrawable_ = drawable;
553     needSync_ = true;
554 }
555 
556 // [Attention] Only used in PC window resize scene now
SetNeedSwapBuffer(bool needSwapBuffer)557 void RSRenderParams::SetNeedSwapBuffer(bool needSwapBuffer)
558 {
559     if (needSwapBuffer_ == needSwapBuffer) {
560         return;
561     }
562     needSwapBuffer_ = needSwapBuffer;
563     needSync_ = true;
564 }
565 
566 // [Attention] Only used in PC window resize scene now
SetCacheNodeFrameRect(const Drawing::RectF & cacheNodeFrameRect)567 void RSRenderParams::SetCacheNodeFrameRect(const Drawing::RectF& cacheNodeFrameRect)
568 {
569     if (cacheNodeFrameRect_ == cacheNodeFrameRect) {
570         return;
571     }
572     cacheNodeFrameRect_ = cacheNodeFrameRect;
573     needSync_ = true;
574 }
575 
576 // used for DFX
SetIsOnTheTree(bool isOnTheTree)577 void RSRenderParams::SetIsOnTheTree(bool isOnTheTree)
578 {
579     isOnTheTree_ = isOnTheTree;
580 }
581 
GetIsOnTheTree() const582 bool RSRenderParams::GetIsOnTheTree() const
583 {
584     return isOnTheTree_;
585 }
586 } // namespace OHOS::Rosen
587