• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "property/rs_properties.h"
17 
18 #include <algorithm>
19 #include <math.h>
20 #include <memory>
21 #include <optional>
22 #include <securec.h>
23 
24 #include "src/core/SkOpts.h"
25 
26 #include "animation/rs_render_particle_animation.h"
27 #include "common/rs_common_def.h"
28 #include "common/rs_obj_abs_geometry.h"
29 #include "common/rs_vector4.h"
30 #include "drawable/rs_property_drawable_utils.h"
31 #include "effect/rs_render_filter_base.h"
32 #include "effect/rs_render_shader_base.h"
33 #include "pipeline/rs_canvas_render_node.h"
34 #include "pipeline/rs_context.h"
35 #include "pipeline/rs_screen_render_node.h"
36 #include "pipeline/rs_uni_render_judgement.h"
37 #include "platform/common/rs_log.h"
38 #include "platform/common/rs_system_properties.h"
39 #include "property/rs_point_light_manager.h"
40 #include "property/rs_properties_def.h"
41 #include "render/rs_attraction_effect_filter.h"
42 #include "render/rs_border_light_shader.h"
43 #include "render/rs_colorful_shadow_filter.h"
44 #include "render/rs_distortion_shader_filter.h"
45 #include "render/rs_filter.h"
46 #include "render/rs_fly_out_shader_filter.h"
47 #include "render/rs_foreground_effect_filter.h"
48 #include "render/rs_hdr_ui_brightness_filter.h"
49 #include "render/rs_material_filter.h"
50 #include "render/rs_render_aibar_filter.h"
51 #include "render/rs_render_always_snapshot_filter.h"
52 #include "render/rs_render_filter_base.h"
53 #include "render/rs_render_grey_filter.h"
54 #include "render/rs_render_kawase_blur_filter.h"
55 #include "render/rs_render_light_blur_filter.h"
56 #include "render/rs_render_linear_gradient_blur_filter.h"
57 #include "render/rs_render_magnifier_filter.h"
58 #include "render/rs_render_maskcolor_filter.h"
59 #include "render/rs_render_mesa_blur_filter.h"
60 #include "render/rs_render_water_ripple_filter.h"
61 #include "render/rs_spherize_effect_filter.h"
62 
63 #ifdef USE_M133_SKIA
64 #include "src/core/SkChecksum.h"
65 #else
66 #include "src/core/SkOpts.h"
67 #endif
68 
69 namespace OHOS {
70 namespace Rosen {
71 namespace {
72 constexpr int32_t INDEX_2 = 2;
73 constexpr int32_t INDEX_4 = 4;
74 constexpr int32_t INDEX_5 = 5;
75 constexpr int32_t INDEX_6 = 6;
76 constexpr int32_t INDEX_7 = 7;
77 constexpr int32_t INDEX_9 = 9;
78 constexpr int32_t INDEX_10 = 10;
79 constexpr int32_t INDEX_11 = 11;
80 constexpr int32_t INDEX_12 = 12;
81 constexpr int32_t INDEX_14 = 14;
82 constexpr int32_t INDEX_18 = 18;
83 
84 const Vector4f Vector4fZero { 0.f, 0.f, 0.f, 0.f };
85 const auto EMPTY_RECT = RectF();
86 constexpr float SPHERIZE_VALID_EPSILON = 0.001f; // used to judge if spherize valid
87 constexpr float ATTRACTION_VALID_EPSILON = 0.001f; // used to judge if attraction valid
88 } // namespace
89 
90 #ifdef SUBTREE_PARALLEL_ENABLE
IsFilterNeedForceSubmit(const std::shared_ptr<RSFilter> & filter)91 static inline bool IsFilterNeedForceSubmit(const std::shared_ptr<RSFilter>& filter)
92 {
93     return filter != nullptr && filter->NeedForceSubmit();
94 }
95 #endif
96 
97 // Only enable filter cache when uni-render is enabled and filter cache is enabled
98 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
99 #ifndef ROSEN_ARKUI_X
100 bool RSProperties::filterCacheEnabled_ =
101     RSSystemProperties::GetFilterCacheEnabled() && RSUniRenderJudgement::IsUniRender();
SetFilterCacheEnabledByCCM(bool isCCMFilterCacheEnable)102 void RSProperties::SetFilterCacheEnabledByCCM(bool isCCMFilterCacheEnable)
103 {
104     filterCacheEnabled_ = (RSSystemProperties::GetFilterCacheEnabled() &&
105         isCCMFilterCacheEnable) && RSUniRenderJudgement::IsUniRender();
106 }
107 #else
108 bool RSProperties::filterCacheEnabled_ = false;
109 #endif
110 #endif
111 
112 bool RSProperties::blurAdaptiveAdjustEnabled_ = false;
SetBlurAdaptiveAdjustEnabledByCCM(bool isCCMBlurAdaptiveAdjustEnabled)113 void RSProperties::SetBlurAdaptiveAdjustEnabledByCCM(bool isCCMBlurAdaptiveAdjustEnabled)
114 {
115     blurAdaptiveAdjustEnabled_ = isCCMBlurAdaptiveAdjustEnabled;
116 }
117 
118 const bool RSProperties::IS_UNI_RENDER = RSUniRenderJudgement::IsUniRender();
119 const bool RSProperties::FOREGROUND_FILTER_ENABLED = RSSystemProperties::GetForegroundFilterEnabled();
120 
RSProperties()121 RSProperties::RSProperties()
122 {
123     boundsGeo_ = std::make_shared<RSObjAbsGeometry>();
124 }
125 
126 RSProperties::~RSProperties() = default;
127 
128 
SetBounds(Vector4f bounds)129 void RSProperties::SetBounds(Vector4f bounds)
130 {
131     if (bounds.z_ != boundsGeo_->GetWidth() || bounds.w_ != boundsGeo_->GetHeight()) {
132         contentDirty_ = true;
133     }
134     boundsGeo_->SetRect(bounds.x_, bounds.y_, bounds.z_, bounds.w_);
135     hasBounds_ = true;
136     geoDirty_ = true;
137     SetDirty();
138     if (IsShadowMaskValid()) {
139         filterNeedUpdate_ = true;
140     }
141 }
142 
SetBoundsSize(Vector2f size)143 void RSProperties::SetBoundsSize(Vector2f size)
144 {
145     boundsGeo_->SetSize(size.x_, size.y_);
146     hasBounds_ = true;
147     geoDirty_ = true;
148     contentDirty_ = true;
149     SetDirty();
150 }
151 
SetBoundsWidth(float width)152 void RSProperties::SetBoundsWidth(float width)
153 {
154     boundsGeo_->SetWidth(width);
155     hasBounds_ = true;
156     geoDirty_ = true;
157     contentDirty_ = true;
158     SetDirty();
159 }
160 
SetBoundsHeight(float height)161 void RSProperties::SetBoundsHeight(float height)
162 {
163     boundsGeo_->SetHeight(height);
164     hasBounds_ = true;
165     geoDirty_ = true;
166     contentDirty_ = true;
167     SetDirty();
168 }
169 
SetBoundsPosition(Vector2f position)170 void RSProperties::SetBoundsPosition(Vector2f position)
171 {
172     boundsGeo_->SetPosition(position.x_, position.y_);
173     geoDirty_ = true;
174     SetDirty();
175 }
176 
SetBoundsPositionX(float positionX)177 void RSProperties::SetBoundsPositionX(float positionX)
178 {
179     boundsGeo_->SetX(positionX);
180     geoDirty_ = true;
181     SetDirty();
182 }
183 
SetBoundsPositionY(float positionY)184 void RSProperties::SetBoundsPositionY(float positionY)
185 {
186     boundsGeo_->SetY(positionY);
187     geoDirty_ = true;
188     SetDirty();
189 }
190 
GetBoundsSize() const191 Vector2f RSProperties::GetBoundsSize() const
192 {
193     return { boundsGeo_->GetWidth(), boundsGeo_->GetHeight() };
194 }
195 
GetBoundsPositionX() const196 float RSProperties::GetBoundsPositionX() const
197 {
198     return boundsGeo_->GetX();
199 }
200 
GetBoundsPositionY() const201 float RSProperties::GetBoundsPositionY() const
202 {
203     return boundsGeo_->GetY();
204 }
205 
GetBoundsPosition() const206 Vector2f RSProperties::GetBoundsPosition() const
207 {
208     return { GetBoundsPositionX(), GetBoundsPositionY() };
209 }
210 
SetFrame(Vector4f frame)211 void RSProperties::SetFrame(Vector4f frame)
212 {
213     if (frame.z_ != frameGeo_.GetWidth() || frame.w_ != frameGeo_.GetHeight()) {
214         contentDirty_ = true;
215     }
216     frameGeo_.SetRect(frame.x_, frame.y_, frame.z_, frame.w_);
217     geoDirty_ = true;
218     SetDirty();
219 }
220 
SetFrameSize(Vector2f size)221 void RSProperties::SetFrameSize(Vector2f size)
222 {
223     frameGeo_.SetSize(size.x_, size.y_);
224     geoDirty_ = true;
225     contentDirty_ = true;
226     SetDirty();
227 }
228 
SetFrameWidth(float width)229 void RSProperties::SetFrameWidth(float width)
230 {
231     frameGeo_.SetWidth(width);
232     geoDirty_ = true;
233     contentDirty_ = true;
234     SetDirty();
235 }
236 
SetFrameHeight(float height)237 void RSProperties::SetFrameHeight(float height)
238 {
239     frameGeo_.SetHeight(height);
240     geoDirty_ = true;
241     contentDirty_ = true;
242     SetDirty();
243 }
244 
SetFramePosition(Vector2f position)245 void RSProperties::SetFramePosition(Vector2f position)
246 {
247     frameGeo_.SetPosition(position.x_, position.y_);
248     geoDirty_ = true;
249     SetDirty();
250 }
251 
SetFramePositionX(float positionX)252 void RSProperties::SetFramePositionX(float positionX)
253 {
254     frameGeo_.SetX(positionX);
255     geoDirty_ = true;
256     SetDirty();
257 }
258 
SetFramePositionY(float positionY)259 void RSProperties::SetFramePositionY(float positionY)
260 {
261     frameGeo_.SetY(positionY);
262     geoDirty_ = true;
263     SetDirty();
264 }
265 
GetFrame() const266 Vector4f RSProperties::GetFrame() const
267 {
268     return { frameGeo_.GetX(), frameGeo_.GetY(), frameGeo_.GetWidth(), frameGeo_.GetHeight() };
269 }
270 
GetFrameSize() const271 Vector2f RSProperties::GetFrameSize() const
272 {
273     return { frameGeo_.GetWidth(), frameGeo_.GetHeight() };
274 }
275 
GetFramePositionX() const276 float RSProperties::GetFramePositionX() const
277 {
278     return frameGeo_.GetX();
279 }
280 
GetFramePositionY() const281 float RSProperties::GetFramePositionY() const
282 {
283     return frameGeo_.GetY();
284 }
285 
GetFramePosition() const286 Vector2f RSProperties::GetFramePosition() const
287 {
288     return { GetFramePositionX(), GetFramePositionY() };
289 }
290 
GetFrameGeometry() const291 const RSObjGeometry& RSProperties::GetFrameGeometry() const
292 {
293     return frameGeo_;
294 }
295 
UpdateGeometryByParent(const Drawing::Matrix * parentMatrix,const std::optional<Drawing::Point> & offset)296 bool RSProperties::UpdateGeometryByParent(const Drawing::Matrix* parentMatrix,
297     const std::optional<Drawing::Point>& offset)
298 {
299     static thread_local Drawing::Matrix prevAbsMatrix;
300     prevAbsMatrix.Swap(prevAbsMatrix_);
301     boundsGeo_->UpdateMatrix(parentMatrix, offset);
302     prevAbsMatrix_ = boundsGeo_->GetAbsMatrix();
303     if (!RSSystemProperties::GetSkipGeometryNotChangeEnabled()) {
304         return true;
305     }
306     const auto& rect = boundsGeo_->GetAbsRect();
307     if (!lastRect_.has_value()) {
308         lastRect_ = rect;
309         return true;
310     }
311     auto dirtyFlag = (rect != lastRect_.value()) || !(prevAbsMatrix == prevAbsMatrix_);
312     lastRect_ = rect;
313     bgShaderNeedUpdate_ = true;
314     if (fgNGRenderFilter_ && fgNGRenderFilter_->ContainsType(RSNGEffectType::CONTENT_LIGHT)) {
315         filterNeedUpdate_ = true;
316     }
317     return dirtyFlag;
318 }
319 
UpdateGeometry(const RSProperties * parent,bool dirtyFlag,const std::optional<Drawing::Point> & offset)320 bool RSProperties::UpdateGeometry(
321     const RSProperties* parent, bool dirtyFlag, const std::optional<Drawing::Point>& offset)
322 {
323     if (!dirtyFlag && !geoDirty_) {
324         return false;
325     }
326     auto parentMatrix = parent == nullptr ? nullptr : &(parent->GetBoundsGeometry()->GetAbsMatrix());
327     if (parentMatrix && sandbox_ && sandbox_->matrix_) {
328         parentMatrix = &(sandbox_->matrix_.value());
329     }
330     boundsGeo_->UpdateMatrix(parentMatrix, offset);
331     if (lightSourcePtr_ && lightSourcePtr_->IsLightSourceValid()) {
332         CalculateAbsLightPosition();
333         RSPointLightManager::Instance()->AddDirtyLightSource(backref_);
334     }
335     if (illuminatedPtr_ && illuminatedPtr_->IsIlluminatedValid()) {
336         RSPointLightManager::Instance()->AddDirtyIlluminated(backref_);
337     }
338     if (RSSystemProperties::GetSkipGeometryNotChangeEnabled()) {
339         auto rect = boundsGeo_->GetAbsRect();
340         if (!lastRect_.has_value()) {
341             lastRect_ = rect;
342             return true;
343         }
344         dirtyFlag = dirtyFlag || rect != lastRect_.value();
345         lastRect_ = rect;
346         return dirtyFlag;
347     } else {
348         return true;
349     }
350 }
351 
SetSandBox(const std::optional<Vector2f> & parentPosition)352 void RSProperties::SetSandBox(const std::optional<Vector2f>& parentPosition)
353 {
354     if (!sandbox_) {
355         sandbox_ = std::make_unique<Sandbox>();
356     }
357     sandbox_->position_ = parentPosition;
358     geoDirty_ = true;
359     SetDirty();
360 }
361 
ResetSandBox()362 void RSProperties::ResetSandBox()
363 {
364     sandbox_ = nullptr;
365 }
366 
UpdateSandBoxMatrix(const std::optional<Drawing::Matrix> & rootMatrix)367 void RSProperties::UpdateSandBoxMatrix(const std::optional<Drawing::Matrix>& rootMatrix)
368 {
369     if (!sandbox_) {
370         return;
371     }
372     if (!rootMatrix || !sandbox_->position_) {
373         sandbox_->matrix_ = std::nullopt;
374         return;
375     }
376     auto rootMat = rootMatrix.value();
377     bool hasScale = false;
378     // scaleFactors[0]-minimum scaling factor, scaleFactors[1]-maximum scaling factor
379     Drawing::scalar scaleFactors[2];
380     bool getMinMaxScales = rootMat.GetMinMaxScales(scaleFactors);
381     if (getMinMaxScales) {
382         hasScale = !ROSEN_EQ(scaleFactors[0], 1.f) || !ROSEN_EQ(scaleFactors[1], 1.f);
383     }
384     if (hasScale) {
385         sandbox_->matrix_ = std::nullopt;
386         return;
387     }
388     Drawing::Matrix matrix = rootMatrix.value();
389     matrix.PreTranslate(sandbox_->position_->x_, sandbox_->position_->y_);
390     sandbox_->matrix_ = matrix;
391 }
392 
GetSandBoxMatrix() const393 std::optional<Drawing::Matrix> RSProperties::GetSandBoxMatrix() const
394 {
395     return sandbox_ ? sandbox_->matrix_ : std::nullopt;
396 }
397 
SetPositionZ(float positionZ)398 void RSProperties::SetPositionZ(float positionZ)
399 {
400     boundsGeo_->SetZ(positionZ);
401     frameGeo_.SetZ(positionZ);
402     geoDirty_ = true;
403     SetDirty();
404 }
405 
SetPositionZApplicableCamera3D(bool isApplicable)406 void RSProperties::SetPositionZApplicableCamera3D(bool isApplicable)
407 {
408     boundsGeo_->SetZApplicableCamera3D(isApplicable);
409     geoDirty_ = true;
410     SetDirty();
411 }
412 
GetPositionZApplicableCamera3D() const413 bool RSProperties::GetPositionZApplicableCamera3D() const
414 {
415     return boundsGeo_->GetZApplicableCamera3D();
416 }
417 
SetPivot(Vector2f pivot)418 void RSProperties::SetPivot(Vector2f pivot)
419 {
420     boundsGeo_->SetPivot(pivot.x_, pivot.y_);
421     geoDirty_ = true;
422     SetDirty();
423 }
424 
SetPivotX(float pivotX)425 void RSProperties::SetPivotX(float pivotX)
426 {
427     boundsGeo_->SetPivotX(pivotX);
428     geoDirty_ = true;
429     SetDirty();
430 }
431 
SetPivotY(float pivotY)432 void RSProperties::SetPivotY(float pivotY)
433 {
434     boundsGeo_->SetPivotY(pivotY);
435     geoDirty_ = true;
436     SetDirty();
437 }
438 
SetPivotZ(float pivotZ)439 void RSProperties::SetPivotZ(float pivotZ)
440 {
441     boundsGeo_->SetPivotZ(pivotZ);
442     geoDirty_ = true;
443     SetDirty();
444 }
445 
GetPivotX() const446 float RSProperties::GetPivotX() const
447 {
448     return boundsGeo_->GetPivotX();
449 }
450 
GetPivotY() const451 float RSProperties::GetPivotY() const
452 {
453     return boundsGeo_->GetPivotY();
454 }
455 
GetPivotZ() const456 float RSProperties::GetPivotZ() const
457 {
458     return boundsGeo_->GetPivotZ();
459 }
460 
SetCornerRadius(const Vector4f & cornerRadius)461 void RSProperties::SetCornerRadius(const Vector4f& cornerRadius)
462 {
463     cornerRadius_ = cornerRadius;
464     SetDirty();
465     if (IsShadowMaskValid()) {
466         filterNeedUpdate_ = true;
467     }
468     contentDirty_ = true;
469 }
470 
GetCornerRadius() const471 const Vector4f& RSProperties::GetCornerRadius() const
472 {
473     return cornerRadius_ ? cornerRadius_.value() : Vector4fZero;
474 }
475 
SetQuaternion(Quaternion quaternion)476 void RSProperties::SetQuaternion(Quaternion quaternion)
477 {
478     boundsGeo_->SetQuaternion(quaternion);
479     geoDirty_ = true;
480     SetDirty();
481 }
482 
SetRotation(float degree)483 void RSProperties::SetRotation(float degree)
484 {
485     boundsGeo_->SetRotation(degree);
486     geoDirty_ = true;
487     SetDirty();
488 }
489 
SetRotationX(float degree)490 void RSProperties::SetRotationX(float degree)
491 {
492     boundsGeo_->SetRotationX(degree);
493     geoDirty_ = true;
494     SetDirty();
495 }
496 
SetRotationY(float degree)497 void RSProperties::SetRotationY(float degree)
498 {
499     boundsGeo_->SetRotationY(degree);
500     geoDirty_ = true;
501     SetDirty();
502 }
503 
SetCameraDistance(float cameraDistance)504 void RSProperties::SetCameraDistance(float cameraDistance)
505 {
506     boundsGeo_->SetCameraDistance(cameraDistance);
507     geoDirty_ = true;
508     SetDirty();
509 }
510 
SetScale(Vector2f scale)511 void RSProperties::SetScale(Vector2f scale)
512 {
513     boundsGeo_->SetScale(scale.x_, scale.y_);
514     geoDirty_ = true;
515     SetDirty();
516 }
517 
SetScaleZ(float sz)518 void RSProperties::SetScaleZ(float sz)
519 {
520     boundsGeo_->SetScaleZ(sz);
521     geoDirty_ = true;
522     SetDirty();
523 }
524 
SetScaleX(float sx)525 void RSProperties::SetScaleX(float sx)
526 {
527     boundsGeo_->SetScaleX(sx);
528     geoDirty_ = true;
529     SetDirty();
530 }
531 
SetScaleY(float sy)532 void RSProperties::SetScaleY(float sy)
533 {
534     boundsGeo_->SetScaleY(sy);
535     geoDirty_ = true;
536     SetDirty();
537 }
538 
SetSkew(const Vector3f & skew)539 void RSProperties::SetSkew(const Vector3f& skew)
540 {
541     boundsGeo_->SetSkew(skew.x_, skew.y_, skew.z_);
542     geoDirty_ = true;
543     SetDirty();
544 }
545 
SetSkewX(float skewX)546 void RSProperties::SetSkewX(float skewX)
547 {
548     boundsGeo_->SetSkewX(skewX);
549     geoDirty_ = true;
550     SetDirty();
551 }
552 
SetSkewY(float skewY)553 void RSProperties::SetSkewY(float skewY)
554 {
555     boundsGeo_->SetSkewY(skewY);
556     geoDirty_ = true;
557     SetDirty();
558 }
559 
SetSkewZ(float skewZ)560 void RSProperties::SetSkewZ(float skewZ)
561 {
562     boundsGeo_->SetSkewZ(skewZ);
563     geoDirty_ = true;
564     SetDirty();
565 }
566 
SetPersp(const Vector4f & persp)567 void RSProperties::SetPersp(const Vector4f& persp)
568 {
569     boundsGeo_->SetPersp(persp.x_, persp.y_, persp.z_, persp.w_);
570     geoDirty_ = true;
571     SetDirty();
572 }
573 
SetPerspX(float perspX)574 void RSProperties::SetPerspX(float perspX)
575 {
576     boundsGeo_->SetPerspX(perspX);
577     geoDirty_ = true;
578     SetDirty();
579 }
580 
SetPerspY(float perspY)581 void RSProperties::SetPerspY(float perspY)
582 {
583     boundsGeo_->SetPerspY(perspY);
584     geoDirty_ = true;
585     SetDirty();
586 }
587 
SetPerspZ(float perspZ)588 void RSProperties::SetPerspZ(float perspZ)
589 {
590     boundsGeo_->SetPerspZ(perspZ);
591     geoDirty_ = true;
592     SetDirty();
593 }
594 
SetPerspW(float perspW)595 void RSProperties::SetPerspW(float perspW)
596 {
597     boundsGeo_->SetPerspW(perspW);
598     geoDirty_ = true;
599     SetDirty();
600 }
601 
SetTranslate(Vector2f translate)602 void RSProperties::SetTranslate(Vector2f translate)
603 {
604     boundsGeo_->SetTranslateX(translate[0]);
605     boundsGeo_->SetTranslateY(translate[1]);
606     geoDirty_ = true;
607     SetDirty();
608 }
609 
SetTranslateX(float translate)610 void RSProperties::SetTranslateX(float translate)
611 {
612     boundsGeo_->SetTranslateX(translate);
613     geoDirty_ = true;
614     SetDirty();
615 }
616 
SetTranslateY(float translate)617 void RSProperties::SetTranslateY(float translate)
618 {
619     boundsGeo_->SetTranslateY(translate);
620     geoDirty_ = true;
621     SetDirty();
622 }
623 
SetTranslateZ(float translate)624 void RSProperties::SetTranslateZ(float translate)
625 {
626     boundsGeo_->SetTranslateZ(translate);
627     geoDirty_ = true;
628     SetDirty();
629 }
630 
GetCameraDistance() const631 float RSProperties::GetCameraDistance() const
632 {
633     return boundsGeo_->GetCameraDistance();
634 }
635 
GetSkewX() const636 float RSProperties::GetSkewX() const
637 {
638     return boundsGeo_->GetSkewX();
639 }
640 
GetSkewY() const641 float RSProperties::GetSkewY() const
642 {
643     return boundsGeo_->GetSkewY();
644 }
645 
GetSkewZ() const646 float RSProperties::GetSkewZ() const
647 {
648     return boundsGeo_->GetSkewZ();
649 }
650 
GetPerspX() const651 float RSProperties::GetPerspX() const
652 {
653     return boundsGeo_->GetPerspX();
654 }
655 
GetPerspY() const656 float RSProperties::GetPerspY() const
657 {
658     return boundsGeo_->GetPerspY();
659 }
660 
GetPerspZ() const661 float RSProperties::GetPerspZ() const
662 {
663     return boundsGeo_->GetPerspZ();
664 }
665 
GetPerspW() const666 float RSProperties::GetPerspW() const
667 {
668     return boundsGeo_->GetPerspW();
669 }
670 
SetParticles(const RSRenderParticleVector & particles)671 void RSProperties::SetParticles(const RSRenderParticleVector& particles)
672 {
673     particles_ = particles;
674     if (particles_.GetParticleSize() > 0) {
675         isDrawn_ = true;
676     }
677     SetDirty();
678     contentDirty_ = true;
679 }
680 
GetParticles() const681 const RSRenderParticleVector& RSProperties::GetParticles() const
682 {
683     return particles_;
684 }
685 
SetAlpha(float alpha)686 void RSProperties::SetAlpha(float alpha)
687 {
688     alpha_ = alpha;
689     if (alpha_ < 1.f) {
690         alphaNeedApply_ = true;
691     }
692     SetDirty();
693     // The alpha value of parent node affects all child node
694     subTreeAllDirty_ = true;
695 }
696 
SetAlphaOffscreen(bool alphaOffscreen)697 void RSProperties::SetAlphaOffscreen(bool alphaOffscreen)
698 {
699     alphaOffscreen_ = alphaOffscreen;
700     SetDirty();
701     contentDirty_ = true;
702 }
703 
GetAlphaOffscreen() const704 bool RSProperties::GetAlphaOffscreen() const
705 {
706     return alphaOffscreen_;
707 }
708 
SetLocalMagnificationCap(bool localMagnificationCap)709 void RSProperties::SetLocalMagnificationCap(bool localMagnificationCap)
710 {
711     localMagnificationCap_ = localMagnificationCap;
712     if (localMagnificationCap_) {
713         filterNeedUpdate_ = true;
714     }
715 }
716 
SetSublayerTransform(const std::optional<Matrix3f> & sublayerTransform)717 void RSProperties::SetSublayerTransform(const std::optional<Matrix3f>& sublayerTransform)
718 {
719     sublayerTransform_ = sublayerTransform;
720     SetDirty();
721 }
722 
GetSublayerTransform() const723 const std::optional<Matrix3f>& RSProperties::GetSublayerTransform() const
724 {
725     return sublayerTransform_;
726 }
727 
728 // foreground properties
SetForegroundColor(Color color)729 void RSProperties::SetForegroundColor(Color color)
730 {
731     if (!decoration_) {
732         decoration_ = std::make_optional<Decoration>();
733     }
734     decoration_->foregroundColor_ = color;
735     SetDirty();
736     contentDirty_ = true;
737 }
738 
GetForegroundColor() const739 Color RSProperties::GetForegroundColor() const
740 {
741     return decoration_ ? decoration_->foregroundColor_ : RgbPalette::Transparent();
742 }
743 
744 // background properties
SetBackgroundColor(Color color)745 void RSProperties::SetBackgroundColor(Color color)
746 {
747     if (!decoration_) {
748         decoration_ = std::make_optional<Decoration>();
749     }
750     if (color.GetAlpha() > 0) {
751         isDrawn_ = true;
752     }
753     decoration_->backgroundColor_ = color;
754     SetDirty();
755     contentDirty_ = true;
756 }
757 
SetBackgroundShader(const std::shared_ptr<RSShader> & shader)758 void RSProperties::SetBackgroundShader(const std::shared_ptr<RSShader>& shader)
759 {
760     if (!decoration_) {
761         decoration_ = std::make_optional<Decoration>();
762     }
763     if (shader) {
764         isDrawn_ = true;
765     }
766     decoration_->bgShader_ = shader;
767     bgShaderNeedUpdate_ = true;
768     SetDirty();
769     contentDirty_ = true;
770 }
771 
GetBackgroundShader() const772 std::shared_ptr<RSShader> RSProperties::GetBackgroundShader() const
773 {
774     return decoration_ ? decoration_->bgShader_ : nullptr;
775 }
776 
SetBackgroundShaderProgress(const float & progress)777 void RSProperties::SetBackgroundShaderProgress(const float& progress)
778 {
779     if (!decoration_) {
780         decoration_ = std::make_optional<Decoration>();
781     }
782     isDrawn_ = true;
783     decoration_->bgShaderProgress_ = progress;
784     bgShaderNeedUpdate_ = true;
785     SetDirty();
786     contentDirty_ = true;
787 }
788 
GetBackgroundShaderProgress() const789 float RSProperties::GetBackgroundShaderProgress() const
790 {
791     return decoration_ ? decoration_->bgShaderProgress_ : -1.f;
792 }
793 
794 
SetBgImage(const std::shared_ptr<RSImage> & image)795 void RSProperties::SetBgImage(const std::shared_ptr<RSImage>& image)
796 {
797     if (!decoration_) {
798         decoration_ = std::make_optional<Decoration>();
799     }
800     if (image) {
801         isDrawn_ = true;
802     }
803     decoration_->bgImage_ = image;
804     SetDirty();
805     contentDirty_ = true;
806 }
807 
GetBgImage() const808 std::shared_ptr<RSImage> RSProperties::GetBgImage() const
809 {
810     return decoration_ ? decoration_->bgImage_ : nullptr;
811 }
812 
SetBgImageInnerRect(const Vector4f & rect)813 void RSProperties::SetBgImageInnerRect(const Vector4f& rect)
814 {
815     if (!decoration_) {
816         decoration_ = std::make_optional<Decoration>();
817     }
818     decoration_->bgImageInnerRect_ = rect;
819     SetDirty();
820     contentDirty_ = true;
821 }
822 
GetBgImageInnerRect() const823 Vector4f RSProperties::GetBgImageInnerRect() const
824 {
825     return decoration_ ? decoration_->bgImageInnerRect_ : Vector4f();
826 }
827 
SetBgImageDstRect(const Vector4f & rect)828 void RSProperties::SetBgImageDstRect(const Vector4f& rect)
829 {
830     if (!decoration_) {
831         decoration_ = std::make_optional<Decoration>();
832     }
833     decoration_->bgImageRect_ = RectF(rect);
834     SetDirty();
835     contentDirty_ = true;
836 }
837 
GetBgImageDstRect()838 const Vector4f RSProperties::GetBgImageDstRect()
839 {
840     RectF rect = decoration_ ? decoration_->bgImageRect_ : EMPTY_RECT;
841     return Vector4f(rect.left_, rect.top_, rect.width_, rect.height_);
842 }
843 
GetBgImageRect() const844 const RectF& RSProperties::GetBgImageRect() const
845 {
846     return decoration_ ? decoration_->bgImageRect_ : EMPTY_RECT;
847 }
848 
SetBgImageWidth(float width)849 void RSProperties::SetBgImageWidth(float width)
850 {
851     if (!decoration_) {
852         decoration_ = std::make_optional<Decoration>();
853     }
854     decoration_->bgImageRect_.width_ = width;
855     SetDirty();
856     contentDirty_ = true;
857 }
858 
SetBgImageHeight(float height)859 void RSProperties::SetBgImageHeight(float height)
860 {
861     if (!decoration_) {
862         decoration_ = std::make_optional<Decoration>();
863     }
864     decoration_->bgImageRect_.height_ = height;
865     SetDirty();
866     contentDirty_ = true;
867 }
868 
SetBgImagePositionX(float positionX)869 void RSProperties::SetBgImagePositionX(float positionX)
870 {
871     if (!decoration_) {
872         decoration_ = std::make_optional<Decoration>();
873     }
874     decoration_->bgImageRect_.left_ = positionX;
875     SetDirty();
876     contentDirty_ = true;
877 }
878 
SetBgImagePositionY(float positionY)879 void RSProperties::SetBgImagePositionY(float positionY)
880 {
881     if (!decoration_) {
882         decoration_ = std::make_optional<Decoration>();
883     }
884     decoration_->bgImageRect_.top_ = positionY;
885     SetDirty();
886     contentDirty_ = true;
887 }
888 
GetBgImageWidth() const889 float RSProperties::GetBgImageWidth() const
890 {
891     return decoration_ ? decoration_->bgImageRect_.width_ : 0.f;
892 }
893 
GetBgImageHeight() const894 float RSProperties::GetBgImageHeight() const
895 {
896     return decoration_ ? decoration_->bgImageRect_.height_ : 0.f;
897 }
898 
GetBgImagePositionX() const899 float RSProperties::GetBgImagePositionX() const
900 {
901     return decoration_ ? decoration_->bgImageRect_.left_ : 0.f;
902 }
903 
GetBgImagePositionY() const904 float RSProperties::GetBgImagePositionY() const
905 {
906     return decoration_ ? decoration_->bgImageRect_.top_ : 0.f;
907 }
908 
909 // border properties
SetBorderColor(Vector4<Color> color)910 void RSProperties::SetBorderColor(Vector4<Color> color)
911 {
912     if (!border_) {
913         border_ = std::make_shared<RSBorder>();
914     }
915     border_->SetColorFour(color);
916     if (border_->GetColor().GetAlpha() > 0) {
917         isDrawn_ = true;
918     }
919     SetDirty();
920     contentDirty_ = true;
921 }
922 
SetBorderWidth(Vector4f width)923 void RSProperties::SetBorderWidth(Vector4f width)
924 {
925     if (!border_) {
926         border_ = std::make_shared<RSBorder>();
927     }
928     border_->SetWidthFour(width);
929     if (!width.IsZero()) {
930         isDrawn_ = true;
931     }
932     SetDirty();
933     contentDirty_ = true;
934 }
935 
SetBorderStyle(Vector4<uint32_t> style)936 void RSProperties::SetBorderStyle(Vector4<uint32_t> style)
937 {
938     if (!border_) {
939         border_ = std::make_shared<RSBorder>();
940     }
941     border_->SetStyleFour(style);
942     SetDirty();
943     contentDirty_ = true;
944 }
945 
SetBorderDashWidth(const Vector4f & dashWidth)946 void RSProperties::SetBorderDashWidth(const Vector4f& dashWidth)
947 {
948     if (!border_) {
949         border_ = std::make_shared<RSBorder>();
950     }
951     border_->SetDashWidthFour(dashWidth);
952     SetDirty();
953     contentDirty_ = true;
954 }
955 
SetBorderDashGap(const Vector4f & dashGap)956 void RSProperties::SetBorderDashGap(const Vector4f& dashGap)
957 {
958     if (!border_) {
959         border_ = std::make_shared<RSBorder>();
960     }
961     border_->SetDashGapFour(dashGap);
962     SetDirty();
963     contentDirty_ = true;
964 }
965 
GetBorderColor() const966 Vector4<Color> RSProperties::GetBorderColor() const
967 {
968     return border_ ? border_->GetColorFour() : Vector4<Color>(RgbPalette::Transparent());
969 }
970 
GetBorderWidth() const971 Vector4f RSProperties::GetBorderWidth() const
972 {
973     return border_ ? border_->GetWidthFour() : Vector4f(0.f);
974 }
975 
GetBorderStyle() const976 Vector4<uint32_t> RSProperties::GetBorderStyle() const
977 {
978     return border_ ? border_->GetStyleFour() : Vector4<uint32_t>(static_cast<uint32_t>(BorderStyle::SOLID));
979 }
980 
GetBorderDashWidth() const981 Vector4f RSProperties::GetBorderDashWidth() const
982 {
983     return border_ ? border_->GetDashWidthFour() : Vector4f(0.f);
984 }
985 
GetBorderDashGap() const986 Vector4f RSProperties::GetBorderDashGap() const
987 {
988     return border_ ? border_->GetDashGapFour() : Vector4f(0.f);
989 }
990 
GetBorder() const991 const std::shared_ptr<RSBorder>& RSProperties::GetBorder() const
992 {
993     return border_;
994 }
995 
SetOutlineColor(Vector4<Color> color)996 void RSProperties::SetOutlineColor(Vector4<Color> color)
997 {
998     if (!outline_) {
999         outline_ = std::make_shared<RSBorder>(true);
1000     }
1001     outline_->SetColorFour(color);
1002     if (outline_->GetColor().GetAlpha() > 0) {
1003         isDrawn_ = true;
1004     }
1005     SetDirty();
1006     contentDirty_ = true;
1007 }
1008 
SetOutlineWidth(Vector4f width)1009 void RSProperties::SetOutlineWidth(Vector4f width)
1010 {
1011     if (!outline_) {
1012         outline_ = std::make_shared<RSBorder>(true);
1013     }
1014     outline_->SetWidthFour(width);
1015     if (!width.IsZero()) {
1016         isDrawn_ = true;
1017     }
1018     SetDirty();
1019     contentDirty_ = true;
1020 }
1021 
SetOutlineStyle(Vector4<uint32_t> style)1022 void RSProperties::SetOutlineStyle(Vector4<uint32_t> style)
1023 {
1024     if (!outline_) {
1025         outline_ = std::make_shared<RSBorder>(true);
1026     }
1027     outline_->SetStyleFour(style);
1028     SetDirty();
1029     contentDirty_ = true;
1030 }
1031 
SetOutlineDashWidth(const Vector4f & dashWidth)1032 void RSProperties::SetOutlineDashWidth(const Vector4f& dashWidth)
1033 {
1034     if (!outline_) {
1035         outline_ = std::make_shared<RSBorder>();
1036     }
1037     outline_->SetDashWidthFour(dashWidth);
1038     SetDirty();
1039     contentDirty_ = true;
1040 }
1041 
SetOutlineDashGap(const Vector4f & dashGap)1042 void RSProperties::SetOutlineDashGap(const Vector4f& dashGap)
1043 {
1044     if (!outline_) {
1045         outline_ = std::make_shared<RSBorder>();
1046     }
1047     outline_->SetDashGapFour(dashGap);
1048     SetDirty();
1049     contentDirty_ = true;
1050 }
1051 
SetOutlineRadius(Vector4f radius)1052 void RSProperties::SetOutlineRadius(Vector4f radius)
1053 {
1054     if (!outline_) {
1055         outline_ = std::make_shared<RSBorder>(true);
1056     }
1057     outline_->SetRadiusFour(radius);
1058     isDrawn_ = true;
1059     SetDirty();
1060     contentDirty_ = true;
1061 }
1062 
GetOutlineColor() const1063 Vector4<Color> RSProperties::GetOutlineColor() const
1064 {
1065     return outline_ ? outline_->GetColorFour() : Vector4<Color>(RgbPalette::Transparent());
1066 }
1067 
GetOutlineWidth() const1068 Vector4f RSProperties::GetOutlineWidth() const
1069 {
1070     return outline_ ? outline_->GetWidthFour() : Vector4f(0.f);
1071 }
1072 
GetOutlineStyle() const1073 Vector4<uint32_t> RSProperties::GetOutlineStyle() const
1074 {
1075     return outline_ ? outline_->GetStyleFour() : Vector4<uint32_t>(static_cast<uint32_t>(BorderStyle::NONE));
1076 }
1077 
GetOutlineDashWidth() const1078 Vector4f RSProperties::GetOutlineDashWidth() const
1079 {
1080     return outline_ ? outline_->GetDashWidthFour() : Vector4f(0.f);
1081 }
1082 
GetOutlineDashGap() const1083 Vector4f RSProperties::GetOutlineDashGap() const
1084 {
1085     return outline_ ? outline_->GetDashGapFour() : Vector4f(0.f);
1086 }
1087 
GetOutlineRadius() const1088 Vector4f RSProperties::GetOutlineRadius() const
1089 {
1090     return outline_ ? outline_->GetRadiusFour() : Vector4fZero;
1091 }
1092 
SetForegroundEffectRadius(const float foregroundEffectRadius)1093 void RSProperties::SetForegroundEffectRadius(const float foregroundEffectRadius)
1094 {
1095     foregroundEffectRadius_ = foregroundEffectRadius;
1096     if (IsForegroundEffectRadiusValid()) {
1097         isDrawn_ = true;
1098     }
1099     filterNeedUpdate_ = true;
1100     SetDirty();
1101 }
1102 
GetForegroundEffectRadius() const1103 float RSProperties::GetForegroundEffectRadius() const
1104 {
1105     return foregroundEffectRadius_;
1106 }
1107 
IsForegroundEffectRadiusValid() const1108 bool RSProperties::IsForegroundEffectRadiusValid() const
1109 {
1110     return ROSEN_GNE(foregroundEffectRadius_, 0.999f); // if blur radius < 1, no need to draw
1111 }
1112 
SetForegroundEffectDirty(bool dirty)1113 void RSProperties::SetForegroundEffectDirty(bool dirty)
1114 {
1115     foregroundEffectDirty_ = dirty;
1116 }
1117 
GetForegroundEffectDirty() const1118 bool RSProperties::GetForegroundEffectDirty() const
1119 {
1120     return foregroundEffectDirty_;
1121 }
1122 
SetForegroundFilterCache(const std::shared_ptr<RSFilter> & foregroundFilterCache)1123 void RSProperties::SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache)
1124 {
1125     foregroundFilterCache_ = foregroundFilterCache;
1126     if (foregroundFilterCache) {
1127         isDrawn_ = true;
1128     }
1129     SetDirty();
1130     filterNeedUpdate_ = true;
1131     contentDirty_ = true;
1132 }
1133 
SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara> & para)1134 void RSProperties::SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para)
1135 {
1136     linearGradientBlurPara_ = para;
1137     if (para && para->blurRadius_ > 0.f) {
1138         isDrawn_ = true;
1139     }
1140     filterNeedUpdate_ = true;
1141     SetDirty();
1142     contentDirty_ = true;
1143 }
1144 
SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>> & para)1145 void RSProperties::SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>>& para)
1146 {
1147     emitterUpdater_ = para;
1148     if (!emitterUpdater_.empty()) {
1149         isDrawn_ = true;
1150         auto renderNode = backref_.lock();
1151         if (renderNode == nullptr) {
1152             return;
1153         }
1154         auto animation = renderNode->GetAnimationManager().GetParticleAnimation();
1155         if (animation == nullptr) {
1156             return;
1157         }
1158         auto particleAnimation = std::static_pointer_cast<RSRenderParticleAnimation>(animation);
1159         if (particleAnimation != nullptr) {
1160             particleAnimation->UpdateEmitter(emitterUpdater_);
1161         }
1162     }
1163     filterNeedUpdate_ = true;
1164     SetDirty();
1165     contentDirty_ = true;
1166 }
1167 
SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields> & para)1168 void RSProperties::SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields>& para)
1169 {
1170     particleNoiseFields_ = para;
1171     if (particleNoiseFields_) {
1172         isDrawn_ = true;
1173         auto renderNode = backref_.lock();
1174         if (renderNode == nullptr) {
1175             return;
1176         }
1177         auto animation = renderNode->GetAnimationManager().GetParticleAnimation();
1178         if (animation == nullptr) {
1179             return;
1180         }
1181         auto particleAnimation = std::static_pointer_cast<RSRenderParticleAnimation>(animation);
1182         if (particleAnimation) {
1183             particleAnimation->UpdateNoiseField(particleNoiseFields_);
1184         }
1185     }
1186     filterNeedUpdate_ = true;
1187     SetDirty();
1188     contentDirty_ = true;
1189 }
1190 
SetDynamicLightUpRate(const std::optional<float> & rate)1191 void RSProperties::SetDynamicLightUpRate(const std::optional<float>& rate)
1192 {
1193     dynamicLightUpRate_ = rate;
1194     if (rate.has_value()) {
1195         isDrawn_ = true;
1196     }
1197     filterNeedUpdate_ = true;
1198     SetDirty();
1199     contentDirty_ = true;
1200 }
1201 
SetDynamicLightUpDegree(const std::optional<float> & lightUpDegree)1202 void RSProperties::SetDynamicLightUpDegree(const std::optional<float>& lightUpDegree)
1203 {
1204     dynamicLightUpDegree_ = lightUpDegree;
1205     if (lightUpDegree.has_value()) {
1206         isDrawn_ = true;
1207     }
1208     filterNeedUpdate_ = true;
1209     SetDirty();
1210     contentDirty_ = true;
1211 }
1212 
SetWaterRippleProgress(const float & progress)1213 void RSProperties::SetWaterRippleProgress(const float& progress)
1214 {
1215     waterRippleProgress_ = progress;
1216     isDrawn_ = true;
1217     filterNeedUpdate_ = true;
1218     SetDirty();
1219     contentDirty_ = true;
1220 }
1221 
GetWaterRippleProgress() const1222 float RSProperties::GetWaterRippleProgress() const
1223 {
1224     return waterRippleProgress_;
1225 }
1226 
SetWaterRippleParams(const std::optional<RSWaterRipplePara> & params)1227 void RSProperties::SetWaterRippleParams(const std::optional<RSWaterRipplePara>& params)
1228 {
1229     waterRippleParams_ = params;
1230     if (params.has_value()) {
1231         isDrawn_ = true;
1232     }
1233     filterNeedUpdate_ = true;
1234     SetDirty();
1235     contentDirty_ = true;
1236 }
1237 
GetWaterRippleParams() const1238 std::optional<RSWaterRipplePara> RSProperties::GetWaterRippleParams() const
1239 {
1240     return waterRippleParams_;
1241 }
1242 
IsWaterRippleValid() const1243 bool RSProperties::IsWaterRippleValid() const
1244 {
1245     uint32_t WAVE_COUNT_MAX = 3;
1246     uint32_t WAVE_COUNT_MIN = 1;
1247     return ROSEN_GE(waterRippleProgress_, 0.0f) && ROSEN_LE(waterRippleProgress_, 1.0f) &&
1248            waterRippleParams_.has_value() && waterRippleParams_->waveCount >= WAVE_COUNT_MIN &&
1249            waterRippleParams_->waveCount <= WAVE_COUNT_MAX;
1250 }
1251 
SetFlyOutDegree(const float & degree)1252 void RSProperties::SetFlyOutDegree(const float& degree)
1253 {
1254     flyOutDegree_ = degree;
1255     isDrawn_ = true;
1256     filterNeedUpdate_ = true;
1257     SetDirty();
1258     contentDirty_ = true;
1259 }
1260 
GetFlyOutDegree() const1261 float RSProperties::GetFlyOutDegree() const
1262 {
1263     return flyOutDegree_;
1264 }
1265 
SetFlyOutParams(const std::optional<RSFlyOutPara> & params)1266 void RSProperties::SetFlyOutParams(const std::optional<RSFlyOutPara>& params)
1267 {
1268     flyOutParams_ = params;
1269     if (params.has_value()) {
1270         isDrawn_ = true;
1271     }
1272     filterNeedUpdate_ = true;
1273     SetDirty();
1274     contentDirty_ = true;
1275 }
1276 
GetFlyOutParams() const1277 std::optional<RSFlyOutPara> RSProperties::GetFlyOutParams() const
1278 {
1279     return flyOutParams_;
1280 }
1281 
IsFlyOutValid() const1282 bool RSProperties::IsFlyOutValid() const
1283 {
1284     return ROSEN_GE(flyOutDegree_, 0.0f) && ROSEN_LE(flyOutDegree_, 1.0f) && flyOutParams_.has_value();
1285 }
1286 
SetDistortionK(const std::optional<float> & distortionK)1287 void RSProperties::SetDistortionK(const std::optional<float>& distortionK)
1288 {
1289     distortionK_ = distortionK;
1290     if (distortionK_.has_value()) {
1291         isDrawn_ = true;
1292         distortionEffectDirty_ = ROSEN_GNE(*distortionK_, 0.0f) && ROSEN_LE(*distortionK_, 1.0f);
1293     }
1294     filterNeedUpdate_ = true;
1295     SetDirty();
1296     contentDirty_ = true;
1297 }
1298 
IsDistortionKValid() const1299 bool RSProperties::IsDistortionKValid() const
1300 {
1301     return distortionK_.has_value() && ROSEN_GE(*distortionK_, -1.0f) && ROSEN_LE(*distortionK_, 1.0f);
1302 }
1303 
SetDistortionDirty(bool distortionEffectDirty)1304 void RSProperties::SetDistortionDirty(bool distortionEffectDirty)
1305 {
1306     distortionEffectDirty_ = distortionEffectDirty;
1307 }
1308 
GetDistortionDirty() const1309 bool RSProperties::GetDistortionDirty() const
1310 {
1311     return distortionEffectDirty_;
1312 }
1313 
SetFgBrightnessRates(const Vector4f & rates)1314 void RSProperties::SetFgBrightnessRates(const Vector4f& rates)
1315 {
1316     if (!fgBrightnessParams_.has_value()) {
1317         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1318     }
1319     fgBrightnessParams_->rates_ = rates;
1320     isDrawn_ = true;
1321     filterNeedUpdate_ = true;
1322     SetDirty();
1323     contentDirty_ = true;
1324 }
1325 
GetFgBrightnessRates() const1326 Vector4f RSProperties::GetFgBrightnessRates() const
1327 {
1328     return fgBrightnessParams_ ? fgBrightnessParams_->rates_ : Vector4f();
1329 }
1330 
SetFgBrightnessSaturation(const float & saturation)1331 void RSProperties::SetFgBrightnessSaturation(const float& saturation)
1332 {
1333     if (!fgBrightnessParams_.has_value()) {
1334         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1335     }
1336     fgBrightnessParams_->saturation_ = saturation;
1337     isDrawn_ = true;
1338     filterNeedUpdate_ = true;
1339     SetDirty();
1340     contentDirty_ = true;
1341 }
1342 
GetFgBrightnessSaturation() const1343 float RSProperties::GetFgBrightnessSaturation() const
1344 {
1345     return fgBrightnessParams_ ? fgBrightnessParams_->saturation_ : 0.0f;
1346 }
1347 
SetFgBrightnessPosCoeff(const Vector4f & coeff)1348 void RSProperties::SetFgBrightnessPosCoeff(const Vector4f& coeff)
1349 {
1350     if (!fgBrightnessParams_.has_value()) {
1351         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1352     }
1353     fgBrightnessParams_->posCoeff_ = coeff;
1354     isDrawn_ = true;
1355     filterNeedUpdate_ = true;
1356     SetDirty();
1357     contentDirty_ = true;
1358 }
1359 
GetFgBrightnessPosCoeff() const1360 Vector4f RSProperties::GetFgBrightnessPosCoeff() const
1361 {
1362     return fgBrightnessParams_ ? fgBrightnessParams_->posCoeff_ : Vector4f();
1363 }
1364 
SetFgBrightnessNegCoeff(const Vector4f & coeff)1365 void RSProperties::SetFgBrightnessNegCoeff(const Vector4f& coeff)
1366 {
1367     if (!fgBrightnessParams_.has_value()) {
1368         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1369     }
1370     fgBrightnessParams_->negCoeff_ = coeff;
1371     isDrawn_ = true;
1372     filterNeedUpdate_ = true;
1373     SetDirty();
1374     contentDirty_ = true;
1375 }
1376 
GetFgBrightnessNegCoeff() const1377 Vector4f RSProperties::GetFgBrightnessNegCoeff() const
1378 {
1379     return fgBrightnessParams_ ? fgBrightnessParams_->negCoeff_ : Vector4f();
1380 }
1381 
SetFgBrightnessFract(const float & fraction)1382 void RSProperties::SetFgBrightnessFract(const float& fraction)
1383 {
1384     if (!fgBrightnessParams_.has_value()) {
1385         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1386     }
1387     fgBrightnessParams_->fraction_ = fraction;
1388     isDrawn_ = true;
1389     filterNeedUpdate_ = true;
1390     SetDirty();
1391     contentDirty_ = true;
1392 }
1393 
GetFgBrightnessFract() const1394 float RSProperties::GetFgBrightnessFract() const
1395 {
1396     return fgBrightnessParams_ ? fgBrightnessParams_->fraction_ : 1.0f;
1397 }
1398 
SetFgBrightnessHdr(const bool enableHdr)1399 void RSProperties::SetFgBrightnessHdr(const bool enableHdr)
1400 {
1401     if (!fgBrightnessParams_.has_value()) {
1402         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1403     }
1404     fgBrightnessParams_->enableHdr_ = enableHdr;
1405     isDrawn_ = true;
1406     filterNeedUpdate_ = true;
1407     SetDirty();
1408     contentDirty_ = true;
1409 }
1410 
GetFgBrightnessHdr() const1411 bool RSProperties::GetFgBrightnessHdr() const
1412 {
1413     return fgBrightnessParams_ ? fgBrightnessParams_->enableHdr_ : false;
1414 }
1415 
SetFgBrightnessParams(const std::optional<RSDynamicBrightnessPara> & params)1416 void RSProperties::SetFgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params)
1417 {
1418     fgBrightnessParams_ = params;
1419     if (params.has_value()) {
1420         isDrawn_ = true;
1421     }
1422     filterNeedUpdate_ = true;
1423     SetDirty();
1424     contentDirty_ = true;
1425 }
1426 
GetFgBrightnessParams() const1427 std::optional<RSDynamicBrightnessPara> RSProperties::GetFgBrightnessParams() const
1428 {
1429     return fgBrightnessParams_;
1430 }
1431 
GetFgBrightnessEnableEDR() const1432 bool RSProperties::GetFgBrightnessEnableEDR() const
1433 {
1434     return fgBrightnessParams_.has_value() && fgBrightnessParams_->enableHdr_ && IsFgBrightnessValid();
1435 }
1436 
SetBgBrightnessRates(const Vector4f & rates)1437 void RSProperties::SetBgBrightnessRates(const Vector4f& rates)
1438 {
1439     if (!bgBrightnessParams_.has_value()) {
1440         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1441     }
1442     bgBrightnessParams_->rates_ = rates;
1443     isDrawn_ = true;
1444     filterNeedUpdate_ = true;
1445     SetDirty();
1446     contentDirty_ = true;
1447 }
1448 
GetBgBrightnessRates() const1449 Vector4f RSProperties::GetBgBrightnessRates() const
1450 {
1451     return bgBrightnessParams_ ? bgBrightnessParams_->rates_ : Vector4f();
1452 }
1453 
SetBgBrightnessSaturation(const float & saturation)1454 void RSProperties::SetBgBrightnessSaturation(const float& saturation)
1455 {
1456     if (!bgBrightnessParams_.has_value()) {
1457         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1458     }
1459     bgBrightnessParams_->saturation_ = saturation;
1460     isDrawn_ = true;
1461     filterNeedUpdate_ = true;
1462     SetDirty();
1463     contentDirty_ = true;
1464 }
1465 
GetBgBrightnessSaturation() const1466 float RSProperties::GetBgBrightnessSaturation() const
1467 {
1468     return bgBrightnessParams_ ? bgBrightnessParams_->saturation_ : 0.0f;
1469 }
1470 
SetBgBrightnessPosCoeff(const Vector4f & coeff)1471 void RSProperties::SetBgBrightnessPosCoeff(const Vector4f& coeff)
1472 {
1473     if (!bgBrightnessParams_.has_value()) {
1474         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1475     }
1476     bgBrightnessParams_->posCoeff_ = coeff;
1477     isDrawn_ = true;
1478     filterNeedUpdate_ = true;
1479     SetDirty();
1480     contentDirty_ = true;
1481 }
1482 
GetBgBrightnessPosCoeff() const1483 Vector4f RSProperties::GetBgBrightnessPosCoeff() const
1484 {
1485     return bgBrightnessParams_ ? bgBrightnessParams_->posCoeff_ : Vector4f();
1486 }
1487 
SetBgBrightnessNegCoeff(const Vector4f & coeff)1488 void RSProperties::SetBgBrightnessNegCoeff(const Vector4f& coeff)
1489 {
1490     if (!bgBrightnessParams_.has_value()) {
1491         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1492     }
1493     bgBrightnessParams_->negCoeff_ = coeff;
1494     isDrawn_ = true;
1495     filterNeedUpdate_ = true;
1496     SetDirty();
1497     contentDirty_ = true;
1498 }
1499 
GetBgBrightnessNegCoeff() const1500 Vector4f RSProperties::GetBgBrightnessNegCoeff() const
1501 {
1502     return bgBrightnessParams_ ? bgBrightnessParams_->negCoeff_ : Vector4f();
1503 }
1504 
SetBgBrightnessFract(const float & fraction)1505 void RSProperties::SetBgBrightnessFract(const float& fraction)
1506 {
1507     if (!bgBrightnessParams_.has_value()) {
1508         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1509     }
1510     bgBrightnessParams_->fraction_ = fraction;
1511     isDrawn_ = true;
1512     filterNeedUpdate_ = true;
1513     SetDirty();
1514     contentDirty_ = true;
1515 }
1516 
GetBgBrightnessFract() const1517 float RSProperties::GetBgBrightnessFract() const
1518 {
1519     return bgBrightnessParams_ ? bgBrightnessParams_->fraction_ : 1.0f;
1520 }
1521 
SetBgBrightnessParams(const std::optional<RSDynamicBrightnessPara> & params)1522 void RSProperties::SetBgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params)
1523 {
1524     bgBrightnessParams_ = params;
1525     if (params.has_value()) {
1526         isDrawn_ = true;
1527     }
1528     filterNeedUpdate_ = true;
1529     SetDirty();
1530     contentDirty_ = true;
1531 }
1532 
GetBgBrightnessParams() const1533 std::optional<RSDynamicBrightnessPara> RSProperties::GetBgBrightnessParams() const
1534 {
1535     return bgBrightnessParams_;
1536 }
1537 
GetFgBrightnessDescription() const1538 std::string RSProperties::GetFgBrightnessDescription() const
1539 {
1540     if (!fgBrightnessParams_.has_value()) {
1541         return "fgBrightnessParams_ is nullopt";
1542     }
1543     std::string description =
1544         "ForegroundBrightness, cubicCoeff: " + std::to_string(fgBrightnessParams_->rates_.x_) +
1545         ", quadCoeff: " + std::to_string(fgBrightnessParams_->rates_.y_) +
1546         ", rate: " + std::to_string(fgBrightnessParams_->rates_.z_) +
1547         ", lightUpDegree: " + std::to_string(fgBrightnessParams_->rates_.w_) +
1548         ", saturation: " + std::to_string(fgBrightnessParams_->saturation_) +
1549         ", fgBrightnessFract: " + std::to_string(fgBrightnessParams_->fraction_) +
1550         ", fgBrightnessHdr: " + std::to_string(fgBrightnessParams_->enableHdr_);
1551     return description;
1552 }
1553 
GetBgBrightnessDescription() const1554 std::string RSProperties::GetBgBrightnessDescription() const
1555 {
1556     if (!bgBrightnessParams_.has_value()) {
1557         return "bgBrightnessParams_ is nullopt";
1558     }
1559     std::string description =
1560         "BackgroundBrightnessInternal, cubicCoeff: " + std::to_string(bgBrightnessParams_->rates_.x_) +
1561         ", quadCoeff: " + std::to_string(bgBrightnessParams_->rates_.y_) +
1562         ", rate: " + std::to_string(bgBrightnessParams_->rates_.z_) +
1563         ", lightUpDegree: " + std::to_string(bgBrightnessParams_->rates_.w_) +
1564         ", saturation: " + std::to_string(bgBrightnessParams_->saturation_) +
1565         ", fgBrightnessFract: " + std::to_string(bgBrightnessParams_->fraction_) +
1566         ", fgBrightnessHdr: " + std::to_string(fgBrightnessParams_->enableHdr_);
1567     return description;
1568 }
1569 
SetShadowBlenderParams(const std::optional<RSShadowBlenderPara> & params)1570 void RSProperties::SetShadowBlenderParams(const std::optional<RSShadowBlenderPara>& params)
1571 {
1572     shadowBlenderParams_ = params;
1573     if (shadowBlenderParams_.has_value()) {
1574         isDrawn_ = true;
1575     }
1576     filterNeedUpdate_ = true;
1577     SetDirty();
1578     contentDirty_ = true;
1579 }
1580 
GetShadowBlenderParams() const1581 std::optional<RSShadowBlenderPara> RSProperties::GetShadowBlenderParams() const
1582 {
1583     return shadowBlenderParams_;
1584 }
1585 
IsShadowBlenderValid() const1586 bool RSProperties::IsShadowBlenderValid() const
1587 {
1588     return shadowBlenderParams_.has_value() && shadowBlenderParams_->IsValid();
1589 }
1590 
GetShadowBlenderDescription() const1591 std::string RSProperties::GetShadowBlenderDescription() const
1592 {
1593     if (!shadowBlenderParams_.has_value()) {
1594         return "shadowBlenderParams_ is nullopt";
1595     }
1596     std::string description =
1597         "ShadowBlender, cubic: " + std::to_string(shadowBlenderParams_->cubic_) +
1598         ", quadratic: " + std::to_string(shadowBlenderParams_->quadratic_) +
1599         ", linear: " + std::to_string(shadowBlenderParams_->linear_) +
1600         ", constant: " + std::to_string(shadowBlenderParams_->constant_);
1601     return description;
1602 }
1603 
SetGreyCoef(const std::optional<Vector2f> & greyCoef)1604 void RSProperties::SetGreyCoef(const std::optional<Vector2f>& greyCoef)
1605 {
1606     greyCoef_ = greyCoef;
1607     greyCoefNeedUpdate_ = true;
1608     SetDirty();
1609     contentDirty_ = true;
1610 }
1611 
SetDynamicDimDegree(const std::optional<float> & DimDegree)1612 void RSProperties::SetDynamicDimDegree(const std::optional<float>& DimDegree)
1613 {
1614     dynamicDimDegree_ = DimDegree;
1615     if (DimDegree.has_value()) {
1616         isDrawn_ = true;
1617     }
1618     filterNeedUpdate_ = true;
1619     SetDirty();
1620     contentDirty_ = true;
1621 }
1622 
SetMotionBlurPara(const std::shared_ptr<MotionBlurParam> & para)1623 void RSProperties::SetMotionBlurPara(const std::shared_ptr<MotionBlurParam>& para)
1624 {
1625     motionBlurPara_ = para;
1626 
1627     if (para && para->radius > 0.f) {
1628         isDrawn_ = true;
1629     }
1630     SetDirty();
1631     filterNeedUpdate_ = true;
1632     contentDirty_ = true;
1633 }
1634 
SetMagnifierParams(const std::shared_ptr<RSMagnifierParams> & para)1635 void RSProperties::SetMagnifierParams(const std::shared_ptr<RSMagnifierParams>& para)
1636 {
1637     magnifierPara_ = para;
1638 
1639     if (para) {
1640         isDrawn_ = true;
1641     }
1642     SetDirty();
1643     filterNeedUpdate_ = true;
1644     contentDirty_ = true;
1645 }
1646 
GetMagnifierPara() const1647 const std::shared_ptr<RSMagnifierParams>& RSProperties::GetMagnifierPara() const
1648 {
1649     return magnifierPara_;
1650 }
1651 
GetLinearGradientBlurPara() const1652 const std::shared_ptr<RSLinearGradientBlurPara>& RSProperties::GetLinearGradientBlurPara() const
1653 {
1654     return linearGradientBlurPara_;
1655 }
1656 
GetEmitterUpdater() const1657 const std::vector<std::shared_ptr<EmitterUpdater>>& RSProperties::GetEmitterUpdater() const
1658 {
1659     return emitterUpdater_;
1660 }
1661 
GetParticleNoiseFields() const1662 const std::shared_ptr<ParticleNoiseFields>& RSProperties::GetParticleNoiseFields() const
1663 {
1664     return particleNoiseFields_;
1665 }
1666 
IfLinearGradientBlurInvalid()1667 void RSProperties::IfLinearGradientBlurInvalid()
1668 {
1669     if (linearGradientBlurPara_ != nullptr) {
1670         bool isValid = ROSEN_GE(linearGradientBlurPara_->blurRadius_, 0.0);
1671         if (!isValid) {
1672             linearGradientBlurPara_.reset();
1673         }
1674     }
1675 }
1676 
GetDynamicLightUpRate() const1677 const std::optional<float>& RSProperties::GetDynamicLightUpRate() const
1678 {
1679     return dynamicLightUpRate_;
1680 }
1681 
GetDynamicLightUpDegree() const1682 const std::optional<float>& RSProperties::GetDynamicLightUpDegree() const
1683 {
1684     return dynamicLightUpDegree_;
1685 }
1686 
GetDynamicDimDegree() const1687 const std::optional<float>& RSProperties::GetDynamicDimDegree() const
1688 {
1689     return dynamicDimDegree_;
1690 }
1691 
GetGreyCoef() const1692 const std::optional<Vector2f>& RSProperties::GetGreyCoef() const
1693 {
1694     return greyCoef_;
1695 }
1696 
IsDynamicDimValid() const1697 bool RSProperties::IsDynamicDimValid() const
1698 {
1699     return dynamicDimDegree_.has_value() &&
1700            ROSEN_GE(*dynamicDimDegree_, 0.0) && ROSEN_LNE(*dynamicDimDegree_, 1.0);
1701 }
1702 
GetMotionBlurPara() const1703 const std::shared_ptr<MotionBlurParam>& RSProperties::GetMotionBlurPara() const
1704 {
1705     return motionBlurPara_;
1706 }
1707 
IsDynamicLightUpValid() const1708 bool RSProperties::IsDynamicLightUpValid() const
1709 {
1710     return dynamicLightUpRate_.has_value() && dynamicLightUpDegree_.has_value() &&
1711            ROSEN_GNE(*dynamicLightUpRate_, 0.0) && ROSEN_GE(*dynamicLightUpDegree_, -1.0) &&
1712            ROSEN_LE(*dynamicLightUpDegree_, 1.0);
1713 }
1714 
SetForegroundFilter(const std::shared_ptr<RSFilter> & foregroundFilter)1715 void RSProperties::SetForegroundFilter(const std::shared_ptr<RSFilter>& foregroundFilter)
1716 {
1717     foregroundFilter_ = foregroundFilter;
1718     if (foregroundFilter) {
1719         isDrawn_ = true;
1720     }
1721     SetDirty();
1722     filterNeedUpdate_ = true;
1723     contentDirty_ = true;
1724 }
1725 
1726 // shadow properties
SetShadowColor(Color color)1727 void RSProperties::SetShadowColor(Color color)
1728 {
1729     if (!shadow_.has_value()) {
1730         shadow_ = std::make_optional<RSShadow>();
1731     }
1732     shadow_->SetColor(color);
1733     if (GetShadowMask() == SHADOW_MASK_STRATEGY::MASK_COLOR_BLUR) {
1734         filterNeedUpdate_ = true;
1735     }
1736     SetDirty();
1737     // [planning] if shadow stores as texture and out of node
1738     // node content would not be affected
1739     contentDirty_ = true;
1740 }
1741 
SetShadowOffsetX(float offsetX)1742 void RSProperties::SetShadowOffsetX(float offsetX)
1743 {
1744     if (!shadow_.has_value()) {
1745         shadow_ = std::make_optional<RSShadow>();
1746     }
1747     shadow_->SetOffsetX(offsetX);
1748     SetDirty();
1749     filterNeedUpdate_ = true;
1750     // [planning] if shadow stores as texture and out of node
1751     // node content would not be affected
1752     contentDirty_ = true;
1753 }
1754 
SetShadowOffsetY(float offsetY)1755 void RSProperties::SetShadowOffsetY(float offsetY)
1756 {
1757     if (!shadow_.has_value()) {
1758         shadow_ = std::make_optional<RSShadow>();
1759     }
1760     shadow_->SetOffsetY(offsetY);
1761     SetDirty();
1762     filterNeedUpdate_ = true;
1763     // [planning] if shadow stores as texture and out of node
1764     // node content would not be affected
1765     contentDirty_ = true;
1766 }
1767 
SetShadowAlpha(float alpha)1768 void RSProperties::SetShadowAlpha(float alpha)
1769 {
1770     if (!shadow_.has_value()) {
1771         shadow_ = std::make_optional<RSShadow>();
1772     }
1773     shadow_->SetAlpha(alpha);
1774     if (shadow_->IsValid()) {
1775         isDrawn_ = true;
1776     }
1777     SetDirty();
1778     // [planning] if shadow stores as texture and out of node
1779     // node content would not be affected
1780     contentDirty_ = true;
1781 }
1782 
SetShadowElevation(float elevation)1783 void RSProperties::SetShadowElevation(float elevation)
1784 {
1785     if (!shadow_.has_value()) {
1786         shadow_ = std::make_optional<RSShadow>();
1787     }
1788     shadow_->SetElevation(elevation);
1789     if (shadow_->IsValid()) {
1790         isDrawn_ = true;
1791     }
1792     SetDirty();
1793     // [planning] if shadow stores as texture and out of node
1794     // node content would not be affected
1795     contentDirty_ = true;
1796 }
1797 
SetShadowRadius(float radius)1798 void RSProperties::SetShadowRadius(float radius)
1799 {
1800     if (!shadow_.has_value()) {
1801         shadow_ = std::make_optional<RSShadow>();
1802     }
1803     shadow_->SetRadius(radius);
1804     if (shadow_->IsValid()) {
1805         isDrawn_ = true;
1806     }
1807     SetDirty();
1808     filterNeedUpdate_ = true;
1809     // [planning] if shadow stores as texture and out of node
1810     // node content would not be affected
1811     contentDirty_ = true;
1812 }
1813 
SetShadowPath(std::shared_ptr<RSPath> shadowPath)1814 void RSProperties::SetShadowPath(std::shared_ptr<RSPath> shadowPath)
1815 {
1816     if (!shadow_.has_value()) {
1817         shadow_ = std::make_optional<RSShadow>();
1818     }
1819     shadow_->SetPath(shadowPath);
1820     SetDirty();
1821     if (IsShadowMaskValid()) {
1822         filterNeedUpdate_ = true;
1823     }
1824     // [planning] if shadow stores as texture and out of node
1825     // node content would not be affected
1826     contentDirty_ = true;
1827 }
1828 
SetShadowMask(int shadowMask)1829 void RSProperties::SetShadowMask(int shadowMask)
1830 {
1831     if (!shadow_.has_value()) {
1832         shadow_ = std::make_optional<RSShadow>();
1833     }
1834     shadow_->SetMask(shadowMask);
1835     SetDirty();
1836     filterNeedUpdate_ = true;
1837     // [planning] if shadow stores as texture and out of node
1838     // node content would not be affected
1839     contentDirty_ = true;
1840 }
1841 
SetShadowIsFilled(bool shadowIsFilled)1842 void RSProperties::SetShadowIsFilled(bool shadowIsFilled)
1843 {
1844     if (!shadow_.has_value()) {
1845         shadow_ = std::make_optional<RSShadow>();
1846     }
1847     shadow_->SetIsFilled(shadowIsFilled);
1848     SetDirty();
1849     if (IsShadowMaskValid()) {
1850         filterNeedUpdate_ = true;
1851     }
1852     // [planning] if shadow stores as texture and out of node
1853     // node content would not be affected
1854     contentDirty_ = true;
1855 }
1856 
SetShadowColorStrategy(int shadowColorStrategy)1857 void RSProperties::SetShadowColorStrategy(int shadowColorStrategy)
1858 {
1859     if (!shadow_.has_value()) {
1860         shadow_ = std::make_optional<RSShadow>();
1861     }
1862     shadow_->SetColorStrategy(shadowColorStrategy);
1863     SetDirty();
1864     filterNeedUpdate_ = true;
1865     // [planning] if shadow stores as texture and out of node
1866     // node content would not be affected
1867     contentDirty_ = true;
1868 }
1869 
1870 
GetShadowColor() const1871 const Color& RSProperties::GetShadowColor() const
1872 {
1873     static const auto DEFAULT_SPOT_COLOR_VALUE = Color::FromArgbInt(DEFAULT_SPOT_COLOR);
1874     return shadow_ ? shadow_->GetColor() : DEFAULT_SPOT_COLOR_VALUE;
1875 }
1876 
GetShadowOffsetX() const1877 float RSProperties::GetShadowOffsetX() const
1878 {
1879     return shadow_ ? shadow_->GetOffsetX() : DEFAULT_SHADOW_OFFSET_X;
1880 }
1881 
GetShadowOffsetY() const1882 float RSProperties::GetShadowOffsetY() const
1883 {
1884     return shadow_ ? shadow_->GetOffsetY() : DEFAULT_SHADOW_OFFSET_Y;
1885 }
1886 
GetShadowAlpha() const1887 float RSProperties::GetShadowAlpha() const
1888 {
1889     return shadow_ ? shadow_->GetAlpha() : 1.f;
1890 }
1891 
GetShadowElevation() const1892 float RSProperties::GetShadowElevation() const
1893 {
1894     return shadow_ ? shadow_->GetElevation() : 0.f;
1895 }
1896 
GetShadowRadius() const1897 float RSProperties::GetShadowRadius() const
1898 {
1899     return shadow_ ? shadow_->GetRadius() : DEFAULT_SHADOW_RADIUS;
1900 }
1901 
GetShadowPath() const1902 std::shared_ptr<RSPath> RSProperties::GetShadowPath() const
1903 {
1904     return shadow_ ? shadow_->GetPath() : nullptr;
1905 }
1906 
GetShadowMask() const1907 int RSProperties::GetShadowMask() const
1908 {
1909     return shadow_ ? shadow_->GetMask() : SHADOW_MASK_STRATEGY::MASK_NONE;
1910 }
1911 
IsShadowMaskValid() const1912 bool RSProperties::IsShadowMaskValid() const
1913 {
1914     if (!shadow_.has_value()) {
1915         return false;
1916     }
1917     return (shadow_->GetMask() > SHADOW_MASK_STRATEGY::MASK_NONE) && (
1918         shadow_->GetMask() <= SHADOW_MASK_STRATEGY::MASK_COLOR_BLUR);
1919 }
1920 
GetShadowIsFilled() const1921 bool RSProperties::GetShadowIsFilled() const
1922 {
1923     return shadow_ ? shadow_->GetIsFilled() : false;
1924 }
1925 
GetShadowColorStrategy() const1926 int RSProperties::GetShadowColorStrategy() const
1927 {
1928     return shadow_ ? shadow_->GetColorStrategy() : SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE;
1929 }
1930 
GetShadow() const1931 const std::optional<RSShadow>& RSProperties::GetShadow() const
1932 {
1933     return shadow_;
1934 }
1935 
IsShadowValid() const1936 bool RSProperties::IsShadowValid() const
1937 {
1938     return shadow_ && shadow_->IsValid();
1939 }
1940 
SetFrameGravity(Gravity gravity)1941 void RSProperties::SetFrameGravity(Gravity gravity)
1942 {
1943     if (frameGravity_ != gravity) {
1944         frameGravity_ = gravity;
1945         SetDirty();
1946         contentDirty_ = true;
1947     }
1948 }
1949 
SetDrawRegion(const std::shared_ptr<RectF> & rect)1950 void RSProperties::SetDrawRegion(const std::shared_ptr<RectF>& rect)
1951 {
1952     drawRegion_ = rect;
1953     SetDirty();
1954     geoDirty_ = true;  // since drawRegion affect dirtyRegion, mark it as geoDirty
1955 }
1956 
SetClipRRect(RRect clipRRect)1957 void RSProperties::SetClipRRect(RRect clipRRect)
1958 {
1959     clipRRect_ = clipRRect;
1960     if (GetClipToRRect()) {
1961         isDrawn_ = true;
1962     }
1963     SetDirty();
1964     geoDirty_ = true;  // [planning] all clip ops should be checked
1965 }
1966 
SetClipBounds(const std::shared_ptr<RSPath> & path)1967 void RSProperties::SetClipBounds(const std::shared_ptr<RSPath>& path)
1968 {
1969     if (path) {
1970         isDrawn_ = true;
1971     }
1972     if (clipPath_ != path) {
1973         clipPath_ = path;
1974         SetDirty();
1975         geoDirty_ = true;  // [planning] all clip ops should be checked
1976     }
1977 }
1978 
SetClipToBounds(bool clipToBounds)1979 void RSProperties::SetClipToBounds(bool clipToBounds)
1980 {
1981     if (clipToBounds) {
1982         isDrawn_ = true;
1983     }
1984     if (clipToBounds_ != clipToBounds) {
1985         clipToBounds_ = clipToBounds;
1986         SetDirty();
1987         geoDirty_ = true;  // [planning] all clip ops should be checked
1988     }
1989 }
1990 
SetClipToFrame(bool clipToFrame)1991 void RSProperties::SetClipToFrame(bool clipToFrame)
1992 {
1993     if (clipToFrame) {
1994         isDrawn_ = true;
1995     }
1996     if (clipToFrame_ != clipToFrame) {
1997         clipToFrame_ = clipToFrame;
1998         SetDirty();
1999         geoDirty_ = true;  // [planning] all clip ops should be checked
2000     }
2001 }
2002 
GetLocalBoundsAndFramesRect() const2003 RectF RSProperties::GetLocalBoundsAndFramesRect() const
2004 {
2005     auto rect = GetBoundsRect();
2006     if (!clipToBounds_ && !std::isinf(GetFrameWidth()) && !std::isinf(GetFrameHeight())) {
2007         rect = rect.JoinRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2008     }
2009     return rect;
2010 }
2011 
GetBoundsRect() const2012 RectF RSProperties::GetBoundsRect() const
2013 {
2014     auto rect = RectF();
2015     if (boundsGeo_->IsEmpty()) {
2016         if (!std::isinf(GetFrameWidth()) && !std::isinf(GetFrameHeight())) {
2017             rect = {0, 0, GetFrameWidth(), GetFrameHeight()};
2018         }
2019     } else {
2020         if (!std::isinf(GetBoundsWidth()) && !std::isinf(GetBoundsHeight())) {
2021             rect = {0, 0, GetBoundsWidth(), GetBoundsHeight()};
2022         }
2023     }
2024     return rect;
2025 }
2026 
GetFrameRect() const2027 RectF RSProperties::GetFrameRect() const
2028 {
2029     return {0, 0, GetFrameWidth(), GetFrameHeight()};
2030 }
2031 
SetVisible(bool visible)2032 void RSProperties::SetVisible(bool visible)
2033 {
2034     if (visible_ != visible) {
2035         visible_ = visible;
2036         SetDirty();
2037         contentDirty_ = true;
2038     }
2039 }
2040 
GetRRect() const2041 const RRect& RSProperties::GetRRect() const
2042 {
2043     return rrect_;
2044 }
2045 
GenerateRRect()2046 void RSProperties::GenerateRRect()
2047 {
2048     RectF rect = GetBoundsRect();
2049     rrect_ = RRect(rect, GetCornerRadius());
2050 }
2051 
GetInnerRRect() const2052 RRect RSProperties::GetInnerRRect() const
2053 {
2054     auto rect = GetBoundsRect();
2055     Vector4f cornerRadius = GetCornerRadius();
2056     if (border_) {
2057         rect.left_ += border_->GetWidth(RSBorder::LEFT);
2058         rect.top_ += border_->GetWidth(RSBorder::TOP);
2059         rect.width_ -= border_->GetWidth(RSBorder::LEFT) + border_->GetWidth(RSBorder::RIGHT);
2060         rect.height_ -= border_->GetWidth(RSBorder::TOP) + border_->GetWidth(RSBorder::BOTTOM);
2061     }
2062     RRect rrect = RRect(rect, cornerRadius);
2063     if (border_) {
2064         rrect.radius_[0] -= { border_->GetWidth(RSBorder::LEFT), border_->GetWidth(RSBorder::TOP) };
2065         rrect.radius_[1] -= { border_->GetWidth(RSBorder::RIGHT), border_->GetWidth(RSBorder::TOP) };
2066         rrect.radius_[2] -= { border_->GetWidth(RSBorder::RIGHT), border_->GetWidth(RSBorder::BOTTOM) };
2067         rrect.radius_[3] -= { border_->GetWidth(RSBorder::LEFT), border_->GetWidth(RSBorder::BOTTOM) };
2068     }
2069     return rrect;
2070 }
2071 
NeedFilter() const2072 bool RSProperties::NeedFilter() const
2073 {
2074     return needFilter_;
2075 }
2076 
NeedHwcFilter() const2077 bool RSProperties::NeedHwcFilter() const
2078 {
2079     return needHwcFilter_;
2080 }
2081 
NeedSkipSubtreeParallel() const2082 bool RSProperties::NeedSkipSubtreeParallel() const
2083 {
2084     return foregroundFilter_ || mask_ || IsColorBlendModeValid();
2085 }
2086 
NeedClip() const2087 bool RSProperties::NeedClip() const
2088 {
2089     return clipToBounds_ || clipToFrame_;
2090 }
2091 
SetDirty()2092 void RSProperties::SetDirty()
2093 {
2094     isDirty_ = true;
2095 }
2096 
ResetDirty()2097 void RSProperties::ResetDirty()
2098 {
2099     isDirty_ = false;
2100     geoDirty_ = false;
2101     contentDirty_ = false;
2102     subTreeAllDirty_ = false;
2103 }
2104 
RecordCurDirtyStatus()2105 void RSProperties::RecordCurDirtyStatus()
2106 {
2107     curIsDirty_ = isDirty_;
2108     curGeoDirty_ = geoDirty_;
2109     curContentDirty_ = contentDirty_;
2110     curSubTreeAllDirty_ = subTreeAllDirty_;
2111 }
2112 
AccumulateDirtyStatus()2113 void RSProperties::AccumulateDirtyStatus()
2114 {
2115     isDirty_ = isDirty_ || curIsDirty_;
2116     geoDirty_ = geoDirty_ || curGeoDirty_;
2117     contentDirty_ = contentDirty_ || curContentDirty_;
2118     subTreeAllDirty_ = subTreeAllDirty_ || curSubTreeAllDirty_;
2119 }
2120 
IsDirty() const2121 bool RSProperties::IsDirty() const
2122 {
2123     return isDirty_;
2124 }
2125 
IsGeoDirty() const2126 bool RSProperties::IsGeoDirty() const
2127 {
2128     return geoDirty_;
2129 }
2130 
IsCurGeoDirty() const2131 bool RSProperties::IsCurGeoDirty() const
2132 {
2133     return curGeoDirty_;
2134 }
2135 
IsContentDirty() const2136 bool RSProperties::IsContentDirty() const
2137 {
2138     return contentDirty_;
2139 }
2140 
IsSubTreeAllDirty() const2141 bool RSProperties::IsSubTreeAllDirty() const
2142 {
2143     return subTreeAllDirty_;
2144 }
2145 
GetDirtyRect() const2146 RectI RSProperties::GetDirtyRect() const
2147 {
2148     RectI dirtyRect;
2149     auto boundsGeometry = (boundsGeo_);
2150     if (clipToBounds_ || std::isinf(GetFrameWidth()) || std::isinf(GetFrameHeight())) {
2151         dirtyRect = boundsGeometry->GetAbsRect();
2152     } else {
2153         auto frameRect =
2154             boundsGeometry->MapAbsRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2155         dirtyRect = boundsGeometry->GetAbsRect().JoinRect(frameRect);
2156     }
2157     if (drawRegion_ == nullptr || drawRegion_->IsEmpty()) {
2158         return dirtyRect;
2159     } else {
2160         auto drawRegion = boundsGeo_->MapAbsRect(*drawRegion_);
2161         // this is used to fix the scene with drawRegion problem, which is need to be optimized
2162         drawRegion.SetRight(drawRegion.GetRight() + 1);
2163         drawRegion.SetBottom(drawRegion.GetBottom() + 1);
2164         drawRegion.SetAll(drawRegion.left_ - 1, drawRegion.top_ - 1,
2165             drawRegion.width_ + 1, drawRegion.height_ + 1);
2166         return dirtyRect.JoinRect(drawRegion);
2167     }
2168 }
2169 
GetDirtyRect(RectI & drawRegion) const2170 RectI RSProperties::GetDirtyRect(RectI& drawRegion) const
2171 {
2172     RectI dirtyRect;
2173     if (clipToBounds_ || std::isinf(GetFrameWidth()) || std::isinf(GetFrameHeight())) {
2174         dirtyRect = boundsGeo_->GetAbsRect();
2175     } else {
2176         auto frameRect =
2177             boundsGeo_->MapAbsRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2178         dirtyRect = boundsGeo_->GetAbsRect().JoinRect(frameRect);
2179     }
2180     if (drawRegion_ == nullptr || drawRegion_->IsEmpty()) {
2181         drawRegion = RectI();
2182         return dirtyRect;
2183     } else {
2184         drawRegion = boundsGeo_->MapAbsRect(*drawRegion_);
2185         // this is used to fix the scene with drawRegion problem, which is need to be optimized
2186         drawRegion.SetRight(drawRegion.GetRight() + 1);
2187         drawRegion.SetBottom(drawRegion.GetBottom() + 1);
2188         drawRegion.SetAll(drawRegion.left_ - 1, drawRegion.top_ - 1,
2189             drawRegion.width_ + 1, drawRegion.height_ + 1);
2190         return dirtyRect.JoinRect(drawRegion);
2191     }
2192 }
2193 
CheckEmptyBounds()2194 void RSProperties::CheckEmptyBounds()
2195 {
2196     // [planning] remove this func and fallback to framerect after surfacenode using frame
2197     if (!hasBounds_) {
2198         boundsGeo_->SetRect(frameGeo_.GetX(), frameGeo_.GetY(), frameGeo_.GetWidth(), frameGeo_.GetHeight());
2199     }
2200 }
2201 
2202 // mask properties
SetMask(const std::shared_ptr<RSMask> & mask)2203 void RSProperties::SetMask(const std::shared_ptr<RSMask>& mask)
2204 {
2205     mask_ = mask;
2206     if (mask_) {
2207         isDrawn_ = true;
2208     }
2209     SetDirty();
2210     contentDirty_ = true;
2211 }
2212 
GetMask() const2213 std::shared_ptr<RSMask> RSProperties::GetMask() const
2214 {
2215     return mask_;
2216 }
2217 
SetBackgroundNGFilter(const std::shared_ptr<RSNGRenderFilterBase> & filterProp)2218 void RSProperties::SetBackgroundNGFilter(const std::shared_ptr<RSNGRenderFilterBase>& filterProp)
2219 {
2220     bgNGRenderFilter_ = filterProp;
2221     isDrawn_ = true;
2222     filterNeedUpdate_ = true;
2223     SetDirty();
2224     contentDirty_ = true;
2225 }
2226 
GetBackgroundNGFilter() const2227 std::shared_ptr<RSNGRenderFilterBase> RSProperties::GetBackgroundNGFilter() const
2228 {
2229     return bgNGRenderFilter_;
2230 }
2231 
SetForegroundNGFilter(const std::shared_ptr<RSNGRenderFilterBase> & filterProp)2232 void RSProperties::SetForegroundNGFilter(const std::shared_ptr<RSNGRenderFilterBase>& filterProp)
2233 {
2234     fgNGRenderFilter_ = filterProp;
2235     isDrawn_ = true;
2236     filterNeedUpdate_ = true;
2237     SetDirty();
2238     contentDirty_ = true;
2239 }
2240 
GetForegroundNGFilter() const2241 std::shared_ptr<RSNGRenderFilterBase> RSProperties::GetForegroundNGFilter() const
2242 {
2243     return fgNGRenderFilter_;
2244 }
2245 
SetHDRUIBrightness(float hdrUIBrightness)2246 void RSProperties::SetHDRUIBrightness(float hdrUIBrightness)
2247 {
2248     if (auto node = RSBaseRenderNode::ReinterpretCast<RSCanvasRenderNode>(backref_.lock())) {
2249         bool oldHDRUIStatus = IsHDRUIBrightnessValid();
2250         bool newHDRUIStatus = ROSEN_GNE(hdrUIBrightness, 1.0f);
2251         if ((oldHDRUIStatus != newHDRUIStatus) && node->IsOnTheTree()) {
2252             node->SetHdrNum(newHDRUIStatus, node->GetInstanceRootNodeId(), HDRComponentType::UICOMPONENT);
2253         }
2254     }
2255     hdrUIBrightness_ = hdrUIBrightness;
2256     if (IsHDRUIBrightnessValid()) {
2257         isDrawn_ = true;
2258     }
2259     filterNeedUpdate_ = true;
2260     SetDirty();
2261 }
2262 
GetHDRUIBrightness() const2263 float RSProperties::GetHDRUIBrightness() const
2264 {
2265     return hdrUIBrightness_;
2266 }
2267 
IsHDRUIBrightnessValid() const2268 bool RSProperties::IsHDRUIBrightnessValid() const
2269 {
2270     return ROSEN_GNE(GetHDRUIBrightness(), 1.0f);
2271 }
2272 
CreateHDRUIBrightnessFilter()2273 void RSProperties::CreateHDRUIBrightnessFilter()
2274 {
2275     auto hdrUIBrightnessFilter = std::make_shared<RSHDRUIBrightnessFilter>(hdrUIBrightness_);
2276     if (IS_UNI_RENDER) {
2277         foregroundFilterCache_ = hdrUIBrightnessFilter;
2278     } else {
2279         foregroundFilter_ = hdrUIBrightnessFilter;
2280     }
2281 }
2282 
SetSpherize(float spherizeDegree)2283 void RSProperties::SetSpherize(float spherizeDegree)
2284 {
2285     spherizeDegree_ = spherizeDegree;
2286     isSpherizeValid_ = spherizeDegree_ > SPHERIZE_VALID_EPSILON;
2287     if (isSpherizeValid_) {
2288         isDrawn_ = true;
2289     }
2290     filterNeedUpdate_ = true;
2291     SetDirty();
2292 }
2293 
GetSpherize() const2294 float RSProperties::GetSpherize() const
2295 {
2296     return spherizeDegree_;
2297 }
2298 
IsSpherizeValid() const2299 bool RSProperties::IsSpherizeValid() const
2300 {
2301     return isSpherizeValid_;
2302 }
2303 
CreateFlyOutShaderFilter()2304 void RSProperties::CreateFlyOutShaderFilter()
2305 {
2306     uint32_t flyMode = flyOutParams_->flyMode;
2307     auto flyOutShaderFilter = std::make_shared<RSFlyOutShaderFilter>(flyOutDegree_, flyMode);
2308     foregroundFilter_ = flyOutShaderFilter;
2309 }
2310 
CreateSphereEffectFilter()2311 void RSProperties::CreateSphereEffectFilter()
2312 {
2313     auto spherizeEffectFilter = std::make_shared<RSSpherizeEffectFilter>(spherizeDegree_);
2314     if (IS_UNI_RENDER) {
2315         foregroundFilterCache_ = spherizeEffectFilter;
2316     } else {
2317         foregroundFilter_ = spherizeEffectFilter;
2318     }
2319 }
2320 
CreateAttractionEffectFilter()2321 void RSProperties::CreateAttractionEffectFilter()
2322 {
2323     float canvasWidth = GetBoundsRect().GetWidth();
2324     float canvasHeight = GetBoundsRect().GetHeight();
2325     Vector2f destinationPoint = GetAttractionDstPoint();
2326     float windowLeftPoint = GetFramePositionX();
2327     float windowTopPoint = GetFramePositionY();
2328     auto attractionEffectFilter = std::make_shared<RSAttractionEffectFilter>(attractFraction_);
2329     attractionEffectFilter->CalculateWindowStatus(canvasWidth, canvasHeight, destinationPoint);
2330     attractionEffectFilter->UpdateDirtyRegion(windowLeftPoint, windowTopPoint);
2331     attractionEffectCurrentDirtyRegion_ = attractionEffectFilter->GetAttractionDirtyRegion();
2332     foregroundFilter_ = attractionEffectFilter;
2333 }
2334 
GetAttractionFraction() const2335 float RSProperties::GetAttractionFraction() const
2336 {
2337     return attractFraction_;
2338 }
2339 
SetAttractionDstPoint(Vector2f dstPoint)2340 void RSProperties::SetAttractionDstPoint(Vector2f dstPoint)
2341 {
2342     attractDstPoint_ = dstPoint;
2343 }
2344 
GetAttractionDstPoint() const2345 Vector2f  RSProperties::GetAttractionDstPoint() const
2346 {
2347     return attractDstPoint_;
2348 }
2349 
SetAttractionFraction(float fraction)2350 void RSProperties::SetAttractionFraction(float fraction)
2351 {
2352     attractFraction_ = fraction;
2353     isAttractionValid_ = attractFraction_ > ATTRACTION_VALID_EPSILON;
2354     if (isAttractionValid_) {
2355         isDrawn_ = true;
2356     }
2357     filterNeedUpdate_ = true;
2358     SetDirty();
2359     contentDirty_ = true;
2360 }
2361 
SetHDRBrightnessFactor(float factor)2362 void RSProperties::SetHDRBrightnessFactor(float factor)
2363 {
2364     if (ROSEN_EQ(hdrBrightnessFactor_, factor)) {
2365         return;
2366     }
2367     hdrBrightnessFactor_ = factor;
2368     auto node = RSBaseRenderNode::ReinterpretCast<RSScreenRenderNode>(backref_.lock());
2369     if (node == nullptr) {
2370         return;
2371     }
2372     auto& hdrNodeList = node->GetHDRNodeList();
2373     auto context = node->GetContext().lock();
2374     if (!context) {
2375         ROSEN_LOGE("RSProperties::SetHDRBrightnessFactor Invalid context");
2376         return;
2377     }
2378     EraseIf(hdrNodeList, [context, factor](const auto& nodeId) -> bool {
2379         auto canvasNode = context->GetNodeMap().GetRenderNode(nodeId);
2380         if (!canvasNode) {
2381             return true;
2382         }
2383         canvasNode->SetContentDirty();
2384         canvasNode->GetMutableRenderProperties().SetCanvasNodeHDRBrightnessFactor(factor);
2385         return false;
2386     });
2387 }
2388 
SetCanvasNodeHDRBrightnessFactor(float factor)2389 void RSProperties::SetCanvasNodeHDRBrightnessFactor(float factor)
2390 {
2391     canvasNodeHDRBrightnessFactor_ = factor;
2392 }
2393 
GetCanvasNodeHDRBrightnessFactor() const2394 float RSProperties::GetCanvasNodeHDRBrightnessFactor() const
2395 {
2396     return canvasNodeHDRBrightnessFactor_;
2397 }
2398 
SetLightUpEffect(float lightUpEffectDegree)2399 void RSProperties::SetLightUpEffect(float lightUpEffectDegree)
2400 {
2401     lightUpEffectDegree_ = lightUpEffectDegree;
2402     if (IsLightUpEffectValid()) {
2403         isDrawn_ = true;
2404     }
2405     filterNeedUpdate_ = true;
2406     SetDirty();
2407     contentDirty_ = true;
2408 }
2409 
GetLightUpEffect() const2410 float RSProperties::GetLightUpEffect() const
2411 {
2412     return lightUpEffectDegree_;
2413 }
2414 
IsLightUpEffectValid() const2415 bool RSProperties::IsLightUpEffectValid() const
2416 {
2417     return ROSEN_GE(GetLightUpEffect(), 0.0) && ROSEN_LNE(GetLightUpEffect(), 1.0);
2418 }
2419 
2420 // filter property
SetBackgroundBlurRadius(float backgroundBlurRadius)2421 void RSProperties::SetBackgroundBlurRadius(float backgroundBlurRadius)
2422 {
2423     backgroundBlurRadius_ = backgroundBlurRadius;
2424     if (IsBackgroundBlurRadiusValid()) {
2425         isDrawn_ = true;
2426     }
2427     filterNeedUpdate_ = true;
2428     SetDirty();
2429     contentDirty_ = true;
2430 }
2431 
GetBackgroundBlurRadius() const2432 float RSProperties::GetBackgroundBlurRadius() const
2433 {
2434     return backgroundBlurRadius_;
2435 }
2436 
IsBackgroundBlurRadiusValid() const2437 bool RSProperties::IsBackgroundBlurRadiusValid() const
2438 {
2439     return ROSEN_GNE(GetBackgroundBlurRadius(), 0.9f); // Adjust the materialBlur radius to 0.9 for the spring curve
2440 }
2441 
SetBackgroundBlurSaturation(float backgroundBlurSaturation)2442 void RSProperties::SetBackgroundBlurSaturation(float backgroundBlurSaturation)
2443 {
2444     backgroundBlurSaturation_ = backgroundBlurSaturation;
2445     if (IsBackgroundBlurSaturationValid()) {
2446         isDrawn_ = true;
2447     }
2448     filterNeedUpdate_ = true;
2449     SetDirty();
2450     contentDirty_ = true;
2451 }
2452 
GetBackgroundBlurSaturation() const2453 float RSProperties::GetBackgroundBlurSaturation() const
2454 {
2455     return backgroundBlurSaturation_;
2456 }
2457 
IsBackgroundBlurSaturationValid() const2458 bool RSProperties::IsBackgroundBlurSaturationValid() const
2459 {
2460     return (!ROSEN_EQ(GetBackgroundBlurSaturation(), 1.0f)) && ROSEN_GE(GetBackgroundBlurSaturation(), 0.0f);
2461 }
2462 
SetBackgroundBlurBrightness(float backgroundBlurBrightness)2463 void RSProperties::SetBackgroundBlurBrightness(float backgroundBlurBrightness)
2464 {
2465     backgroundBlurBrightness_ = backgroundBlurBrightness;
2466     if (IsBackgroundBlurBrightnessValid()) {
2467         isDrawn_ = true;
2468     }
2469     filterNeedUpdate_ = true;
2470     SetDirty();
2471     contentDirty_ = true;
2472 }
2473 
GetBackgroundBlurBrightness() const2474 float RSProperties::GetBackgroundBlurBrightness() const
2475 {
2476     return backgroundBlurBrightness_;
2477 }
2478 
IsBackgroundBlurBrightnessValid() const2479 bool RSProperties::IsBackgroundBlurBrightnessValid() const
2480 {
2481     return (!ROSEN_EQ(GetBackgroundBlurBrightness(), 1.0f)) && ROSEN_GE(GetBackgroundBlurBrightness(), 0.0f);
2482 }
2483 
SetBackgroundBlurMaskColor(Color backgroundMaskColor)2484 void RSProperties::SetBackgroundBlurMaskColor(Color backgroundMaskColor)
2485 {
2486     backgroundMaskColor_ = backgroundMaskColor;
2487     if (IsBackgroundBlurMaskColorValid()) {
2488         isDrawn_ = true;
2489     }
2490     filterNeedUpdate_ = true;
2491     SetDirty();
2492     contentDirty_ = true;
2493 }
2494 
GetBackgroundBlurMaskColor() const2495 const Color& RSProperties::GetBackgroundBlurMaskColor() const
2496 {
2497     return backgroundMaskColor_;
2498 }
2499 
IsBackgroundBlurMaskColorValid() const2500 bool RSProperties::IsBackgroundBlurMaskColorValid() const
2501 {
2502     return backgroundMaskColor_ != RSColor();
2503 }
2504 
SetBackgroundBlurColorMode(int backgroundColorMode)2505 void RSProperties::SetBackgroundBlurColorMode(int backgroundColorMode)
2506 {
2507     backgroundColorMode_ = backgroundColorMode;
2508     filterNeedUpdate_ = true;
2509     SetDirty();
2510     contentDirty_ = true;
2511 }
2512 
GetBackgroundBlurColorMode() const2513 int RSProperties::GetBackgroundBlurColorMode() const
2514 {
2515     return backgroundColorMode_;
2516 }
2517 
SetBackgroundBlurRadiusX(float backgroundBlurRadiusX)2518 void RSProperties::SetBackgroundBlurRadiusX(float backgroundBlurRadiusX)
2519 {
2520     backgroundBlurRadiusX_ = backgroundBlurRadiusX;
2521     if (IsBackgroundBlurRadiusXValid()) {
2522         isDrawn_ = true;
2523     }
2524     filterNeedUpdate_ = true;
2525     SetDirty();
2526     contentDirty_ = true;
2527 }
2528 
GetBackgroundBlurRadiusX() const2529 float RSProperties::GetBackgroundBlurRadiusX() const
2530 {
2531     return backgroundBlurRadiusX_;
2532 }
2533 
IsBackgroundBlurRadiusXValid() const2534 bool RSProperties::IsBackgroundBlurRadiusXValid() const
2535 {
2536     return ROSEN_GNE(GetBackgroundBlurRadiusX(), 0.999f);
2537 }
2538 
SetBackgroundBlurRadiusY(float backgroundBlurRadiusY)2539 void RSProperties::SetBackgroundBlurRadiusY(float backgroundBlurRadiusY)
2540 {
2541     backgroundBlurRadiusY_ = backgroundBlurRadiusY;
2542     if (IsBackgroundBlurRadiusYValid()) {
2543         isDrawn_ = true;
2544     }
2545     filterNeedUpdate_ = true;
2546     SetDirty();
2547     contentDirty_ = true;
2548 }
2549 
GetBackgroundBlurRadiusY() const2550 float RSProperties::GetBackgroundBlurRadiusY() const
2551 {
2552     return backgroundBlurRadiusY_;
2553 }
2554 
IsBackgroundBlurRadiusYValid() const2555 bool RSProperties::IsBackgroundBlurRadiusYValid() const
2556 {
2557     return ROSEN_GNE(GetBackgroundBlurRadiusY(), 0.999f);
2558 }
2559 
SetBgBlurDisableSystemAdaptation(bool disableSystemAdaptation)2560 void RSProperties::SetBgBlurDisableSystemAdaptation(bool disableSystemAdaptation)
2561 {
2562     bgBlurDisableSystemAdaptation = disableSystemAdaptation;
2563     isDrawn_ = true;
2564     filterNeedUpdate_ = true;
2565     SetDirty();
2566     contentDirty_ = true;
2567 }
2568 
GetBgBlurDisableSystemAdaptation() const2569 bool RSProperties::GetBgBlurDisableSystemAdaptation() const
2570 {
2571     return bgBlurDisableSystemAdaptation;
2572 }
2573 
SetForegroundBlurRadius(float foregroundBlurRadius)2574 void RSProperties::SetForegroundBlurRadius(float foregroundBlurRadius)
2575 {
2576     foregroundBlurRadius_ = foregroundBlurRadius;
2577     if (IsForegroundBlurRadiusValid()) {
2578         isDrawn_ = true;
2579     }
2580     filterNeedUpdate_ = true;
2581     SetDirty();
2582     contentDirty_ = true;
2583 }
2584 
GetForegroundBlurRadius() const2585 float RSProperties::GetForegroundBlurRadius() const
2586 {
2587     return foregroundBlurRadius_;
2588 }
2589 
IsForegroundBlurRadiusValid() const2590 bool RSProperties::IsForegroundBlurRadiusValid() const
2591 {
2592     return ROSEN_GNE(GetForegroundBlurRadius(), 0.9f); // Adjust the materialBlur radius to 0.9 for the spring curve
2593 }
2594 
SetForegroundBlurSaturation(float foregroundBlurSaturation)2595 void RSProperties::SetForegroundBlurSaturation(float foregroundBlurSaturation)
2596 {
2597     foregroundBlurSaturation_ = foregroundBlurSaturation;
2598     if (IsForegroundBlurSaturationValid()) {
2599         isDrawn_ = true;
2600     }
2601     filterNeedUpdate_ = true;
2602     SetDirty();
2603     contentDirty_ = true;
2604 }
2605 
GetForegroundBlurSaturation() const2606 float RSProperties::GetForegroundBlurSaturation() const
2607 {
2608     return foregroundBlurSaturation_;
2609 }
2610 
IsForegroundBlurSaturationValid() const2611 bool RSProperties::IsForegroundBlurSaturationValid() const
2612 {
2613     return ROSEN_GE(GetForegroundBlurSaturation(), 1.0);
2614 }
2615 
SetForegroundBlurBrightness(float foregroundBlurBrightness)2616 void RSProperties::SetForegroundBlurBrightness(float foregroundBlurBrightness)
2617 {
2618     foregroundBlurBrightness_ = foregroundBlurBrightness;
2619     if (IsForegroundBlurBrightnessValid()) {
2620         isDrawn_ = true;
2621     }
2622     filterNeedUpdate_ = true;
2623     SetDirty();
2624     contentDirty_ = true;
2625 }
2626 
GetForegroundBlurBrightness() const2627 float RSProperties::GetForegroundBlurBrightness() const
2628 {
2629     return foregroundBlurBrightness_;
2630 }
2631 
IsForegroundBlurBrightnessValid() const2632 bool RSProperties::IsForegroundBlurBrightnessValid() const
2633 {
2634     return ROSEN_GE(GetForegroundBlurBrightness(), 1.0);
2635 }
2636 
SetForegroundBlurMaskColor(Color foregroundMaskColor)2637 void RSProperties::SetForegroundBlurMaskColor(Color foregroundMaskColor)
2638 {
2639     foregroundMaskColor_ = foregroundMaskColor;
2640     if (IsForegroundBlurMaskColorValid()) {
2641         isDrawn_ = true;
2642     }
2643     filterNeedUpdate_ = true;
2644     SetDirty();
2645     contentDirty_ = true;
2646 }
2647 
GetForegroundBlurMaskColor() const2648 const Color& RSProperties::GetForegroundBlurMaskColor() const
2649 {
2650     return foregroundMaskColor_;
2651 }
2652 
IsForegroundBlurMaskColorValid() const2653 bool RSProperties::IsForegroundBlurMaskColorValid() const
2654 {
2655     return foregroundMaskColor_ != RSColor();
2656 }
2657 
SetForegroundBlurColorMode(int foregroundColorMode)2658 void RSProperties::SetForegroundBlurColorMode(int foregroundColorMode)
2659 {
2660     foregroundColorMode_ = foregroundColorMode;
2661     filterNeedUpdate_ = true;
2662     SetDirty();
2663     contentDirty_ = true;
2664 }
2665 
GetForegroundBlurColorMode() const2666 int RSProperties::GetForegroundBlurColorMode() const
2667 {
2668     return foregroundColorMode_;
2669 }
2670 
SetForegroundBlurRadiusX(float foregroundBlurRadiusX)2671 void RSProperties::SetForegroundBlurRadiusX(float foregroundBlurRadiusX)
2672 {
2673     foregroundBlurRadiusX_ = foregroundBlurRadiusX;
2674     if (IsForegroundBlurRadiusXValid()) {
2675         isDrawn_ = true;
2676     }
2677     filterNeedUpdate_ = true;
2678     SetDirty();
2679     contentDirty_ = true;
2680 }
2681 
GetForegroundBlurRadiusX() const2682 float RSProperties::GetForegroundBlurRadiusX() const
2683 {
2684     return foregroundBlurRadiusX_;
2685 }
2686 
IsForegroundBlurRadiusXValid() const2687 bool RSProperties::IsForegroundBlurRadiusXValid() const
2688 {
2689     return ROSEN_GNE(GetForegroundBlurRadiusX(), 0.999f);
2690 }
2691 
SetForegroundBlurRadiusY(float foregroundBlurRadiusY)2692 void RSProperties::SetForegroundBlurRadiusY(float foregroundBlurRadiusY)
2693 {
2694     foregroundBlurRadiusY_ = foregroundBlurRadiusY;
2695     if (IsForegroundBlurRadiusYValid()) {
2696         isDrawn_ = true;
2697     }
2698     filterNeedUpdate_ = true;
2699     SetDirty();
2700     contentDirty_ = true;
2701 }
2702 
GetForegroundBlurRadiusY() const2703 float RSProperties::GetForegroundBlurRadiusY() const
2704 {
2705     return foregroundBlurRadiusY_;
2706 }
2707 
IsForegroundBlurRadiusYValid() const2708 bool RSProperties::IsForegroundBlurRadiusYValid() const
2709 {
2710     return ROSEN_GNE(GetForegroundBlurRadiusY(), 0.999f);
2711 }
2712 
SetFgBlurDisableSystemAdaptation(bool disableSystemAdaptation)2713 void RSProperties::SetFgBlurDisableSystemAdaptation(bool disableSystemAdaptation)
2714 {
2715     fgBlurDisableSystemAdaptation = disableSystemAdaptation;
2716     isDrawn_ = true;
2717     filterNeedUpdate_ = true;
2718     SetDirty();
2719     contentDirty_ = true;
2720 }
2721 
GetFgBlurDisableSystemAdaptation() const2722 bool RSProperties::GetFgBlurDisableSystemAdaptation() const
2723 {
2724     return fgBlurDisableSystemAdaptation;
2725 }
2726 
SetAlwaysSnapshot(bool enable)2727 void RSProperties::SetAlwaysSnapshot(bool enable)
2728 {
2729     alwaysSnapshot_ = enable;
2730     isDrawn_ = true;
2731     filterNeedUpdate_ = true;
2732     SetDirty();
2733     contentDirty_ = true;
2734 }
2735 
GetAlwaysSnapshot() const2736 bool RSProperties::GetAlwaysSnapshot() const
2737 {
2738     return alwaysSnapshot_;
2739 }
2740 
SetComplexShaderParam(const std::vector<float> & param)2741 void RSProperties::SetComplexShaderParam(const std::vector<float> &param)
2742 {
2743     complexShaderParam_ = param;
2744     if (!param.empty()) {
2745         isDrawn_ = true;
2746     }
2747     bgShaderNeedUpdate_ = true;
2748     SetDirty();
2749     contentDirty_ = true;
2750 }
2751 
GetComplexShaderParam() const2752 std::optional<std::vector<float>> RSProperties::GetComplexShaderParam() const
2753 {
2754     return complexShaderParam_;
2755 }
2756 
IsBackgroundMaterialFilterValid() const2757 bool RSProperties::IsBackgroundMaterialFilterValid() const
2758 {
2759     return IsBackgroundBlurRadiusValid() || IsBackgroundBlurBrightnessValid() || IsBackgroundBlurSaturationValid();
2760 }
2761 
IsForegroundMaterialFilterVaild() const2762 bool RSProperties::IsForegroundMaterialFilterVaild() const
2763 {
2764     return IsForegroundBlurRadiusValid();
2765 }
2766 
GetMaterialColorFilter(float sat,float brightness)2767 std::shared_ptr<Drawing::ColorFilter> RSProperties::GetMaterialColorFilter(float sat, float brightness)
2768 {
2769     float normalizedDegree = brightness - 1.0;
2770     const float brightnessMat[] = {
2771         1.000000f, 0.000000f, 0.000000f, 0.000000f, normalizedDegree,
2772         0.000000f, 1.000000f, 0.000000f, 0.000000f, normalizedDegree,
2773         0.000000f, 0.000000f, 1.000000f, 0.000000f, normalizedDegree,
2774         0.000000f, 0.000000f, 0.000000f, 1.000000f, 0.000000f,
2775     };
2776     Drawing::ColorMatrix cm;
2777     cm.SetSaturation(sat);
2778     float cmArray[Drawing::ColorMatrix::MATRIX_SIZE];
2779     cm.GetArray(cmArray);
2780     std::shared_ptr<Drawing::ColorFilter> filterCompose =
2781         Drawing::ColorFilter::CreateComposeColorFilter(cmArray, brightnessMat, Drawing::Clamp::NO_CLAMP);
2782     return filterCompose;
2783 }
2784 
NeedLightBlur(bool disableSystemAdaptation)2785 bool RSProperties::NeedLightBlur(bool disableSystemAdaptation)
2786 {
2787     return blurAdaptiveAdjustEnabled_ && !disableSystemAdaptation &&
2788         (NeedBlurFuzed() || RSSystemProperties::GetKawaseEnabled());
2789 }
2790 
GenerateLightBlurFilter(float radius)2791 std::shared_ptr<RSFilter> RSProperties::GenerateLightBlurFilter(float radius)
2792 {
2793     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2794     // Lightblur does not take effect when using grayscale
2795     if (greyCoef_.has_value()) {
2796         ROSEN_LOGD("RSProperties::GenerateLightBlurFilter: Lightblur does not take effect when using grayscale");
2797     }
2798 
2799     std::shared_ptr<RSLightBlurShaderFilter> lightBlurShaderFilter = std::make_shared<RSLightBlurShaderFilter>(radius);
2800     if (originalFilter == nullptr) {
2801         originalFilter = std::make_shared<RSDrawingFilter>(lightBlurShaderFilter);
2802     } else {
2803         originalFilter = originalFilter->Compose(lightBlurShaderFilter);
2804     }
2805     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(radius));
2806     originalFilter->SetFilterType(RSFilter::BLUR);
2807     return originalFilter;
2808 }
2809 
GenerateMaterialLightBlurFilter(std::shared_ptr<Drawing::ColorFilter> colorFilter,uint32_t hash,float radius,int colorMode,const RSColor & color)2810 std::shared_ptr<RSFilter> RSProperties::GenerateMaterialLightBlurFilter(
2811     std::shared_ptr<Drawing::ColorFilter> colorFilter, uint32_t hash, float radius,
2812     int colorMode, const RSColor& color)
2813 {
2814     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2815     // Lightblur does not take effect when using grayscale
2816     if (greyCoef_.has_value()) {
2817         ROSEN_LOGD("RSProperties::GenerateMaterialLightBlurFilter: "
2818            "Lightblur does not take effect when using grayscale");
2819     }
2820     auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
2821     if (originalFilter == nullptr) {
2822         originalFilter = std::make_shared<RSDrawingFilter>(colorImageFilter, hash);
2823     } else {
2824         originalFilter = originalFilter->Compose(colorImageFilter, hash);
2825     }
2826 
2827     std::shared_ptr<RSLightBlurShaderFilter> lightBlurFilter = std::make_shared<RSLightBlurShaderFilter>(radius);
2828     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(lightBlurFilter));
2829 
2830     if (colorMode == BLUR_COLOR_MODE::PRE_DEFINED) {
2831         std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
2832             colorMode, color);
2833         originalFilter =
2834             originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(maskColorShaderFilter));
2835     }
2836 
2837     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(radius));
2838     originalFilter->SetFilterType(RSFilter::MATERIAL);
2839     return originalFilter;
2840 }
2841 
GenerateBackgroundBlurFilter()2842 void RSProperties::GenerateBackgroundBlurFilter()
2843 {
2844     std::shared_ptr<Drawing::ImageFilter> blurFilter = Drawing::ImageFilter::CreateBlurImageFilter(
2845         backgroundBlurRadiusX_, backgroundBlurRadiusY_, Drawing::TileMode::CLAMP, nullptr);
2846 #ifdef USE_M133_SKIA
2847     const auto hashFunc = SkChecksum::Hash32;
2848 #else
2849     const auto hashFunc = SkOpts::hash;
2850 #endif
2851     uint32_t hash = hashFunc(&backgroundBlurRadiusX_, sizeof(backgroundBlurRadiusX_), 0);
2852     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2853 
2854     if (NeedLightBlur(bgBlurDisableSystemAdaptation)) {
2855         backgroundFilter_ = GenerateLightBlurFilter(backgroundBlurRadiusX_);
2856         return;
2857     }
2858 
2859     // fuse grey-adjustment and pixel-stretch with blur filter
2860     if (NeedBlurFuzed()) {
2861         std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
2862         if (greyCoef_.has_value()) {
2863             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadiusX_,
2864                 greyCoef_->x_, greyCoef_->y_);
2865         } else {
2866             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadiusX_);
2867         }
2868         originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
2869         originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadiusX_));
2870         backgroundFilter_ = originalFilter;
2871         backgroundFilter_->SetFilterType(RSFilter::BLUR);
2872         return;
2873     }
2874 
2875     if (greyCoef_.has_value()) {
2876         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2877             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2878         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2879     }
2880 
2881     if (RSSystemProperties::GetKawaseEnabled()) {
2882         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2883             std::make_shared<RSKawaseBlurShaderFilter>(backgroundBlurRadiusX_);
2884         if (originalFilter == nullptr) {
2885             originalFilter = std::make_shared<RSDrawingFilter>(kawaseBlurFilter);
2886         } else {
2887             originalFilter =
2888                 originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(kawaseBlurFilter));
2889         }
2890     } else {
2891         if (originalFilter == nullptr) {
2892             originalFilter = std::make_shared<RSDrawingFilter>(blurFilter, hash);
2893         } else {
2894             originalFilter = originalFilter->Compose(blurFilter, hash);
2895         }
2896     }
2897     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadiusX_));
2898     backgroundFilter_ = originalFilter;
2899     backgroundFilter_->SetFilterType(RSFilter::BLUR);
2900 }
2901 
GenerateBackgroundMaterialBlurFilter()2902 void RSProperties::GenerateBackgroundMaterialBlurFilter()
2903 {
2904     if (backgroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
2905         backgroundColorMode_ = BLUR_COLOR_MODE::AVERAGE;
2906     }
2907 
2908     float radiusForHash = DecreasePrecision(backgroundBlurRadius_);
2909     float saturationForHash = DecreasePrecision(backgroundBlurSaturation_);
2910     float brightnessForHash = DecreasePrecision(backgroundBlurBrightness_);
2911 #ifdef USE_M133_SKIA
2912     const auto hashFunc = SkChecksum::Hash32;
2913 #else
2914     const auto hashFunc = SkOpts::hash;
2915 #endif
2916     uint32_t hash = hashFunc(&radiusForHash, sizeof(radiusForHash), 0);
2917     hash = hashFunc(&saturationForHash, sizeof(saturationForHash), hash);
2918     hash = hashFunc(&brightnessForHash, sizeof(brightnessForHash), hash);
2919 
2920     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
2921         backgroundBlurSaturation_, backgroundBlurBrightness_);
2922     if (NeedLightBlur(bgBlurDisableSystemAdaptation)) {
2923         backgroundFilter_ = GenerateMaterialLightBlurFilter(colorFilter, hash, backgroundBlurRadius_,
2924             backgroundColorMode_, backgroundMaskColor_);
2925         return;
2926     }
2927     std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
2928         Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, backgroundBlurRadius_, backgroundBlurRadius_);
2929 
2930     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2931 
2932     // fuse grey-adjustment and pixel-stretch with blur filter
2933     if (NeedBlurFuzed()) {
2934         GenerateBackgroundMaterialFuzedBlurFilter();
2935         return;
2936     }
2937 
2938     if (greyCoef_.has_value()) {
2939         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2940             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2941         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2942     }
2943 
2944     if (RSSystemProperties::GetKawaseEnabled()) {
2945         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2946             std::make_shared<RSKawaseBlurShaderFilter>(backgroundBlurRadius_);
2947         auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
2948         originalFilter = originalFilter?
2949             originalFilter->Compose(colorImageFilter, hash) : std::make_shared<RSDrawingFilter>(colorImageFilter, hash);
2950         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(kawaseBlurFilter));
2951     } else {
2952         originalFilter = originalFilter?
2953             originalFilter->Compose(blurColorFilter, hash) : std::make_shared<RSDrawingFilter>(blurColorFilter, hash);
2954     }
2955     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter =
2956         std::make_shared<RSMaskColorShaderFilter>(backgroundColorMode_, backgroundMaskColor_);
2957     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(maskColorShaderFilter));
2958     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadius_));
2959     originalFilter->SetSaturationForHPS(backgroundBlurSaturation_);
2960     originalFilter->SetBrightnessForHPS(backgroundBlurBrightness_);
2961     backgroundFilter_ = originalFilter;
2962     backgroundFilter_->SetFilterType(RSFilter::MATERIAL);
2963 }
2964 
GenerateForegroundBlurFilter()2965 void RSProperties::GenerateForegroundBlurFilter()
2966 {
2967     if (NeedLightBlur(fgBlurDisableSystemAdaptation)) {
2968         filter_ = GenerateLightBlurFilter(foregroundBlurRadiusX_);
2969         return;
2970     }
2971 
2972     std::shared_ptr<Drawing::ImageFilter> blurFilter = Drawing::ImageFilter::CreateBlurImageFilter(
2973         foregroundBlurRadiusX_, foregroundBlurRadiusY_, Drawing::TileMode::CLAMP, nullptr);
2974 #ifdef USE_M133_SKIA
2975     const auto hashFunc = SkChecksum::Hash32;
2976 #else
2977     const auto hashFunc = SkOpts::hash;
2978 #endif
2979     uint32_t hash = hashFunc(&foregroundBlurRadiusX_, sizeof(foregroundBlurRadiusX_), 0);
2980     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2981 
2982     // fuse grey-adjustment and pixel-stretch with blur filter
2983     if (NeedBlurFuzed()) {
2984         std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
2985         if (greyCoef_.has_value()) {
2986             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadiusX_,
2987                 greyCoef_->x_, greyCoef_->y_);
2988         } else {
2989             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadiusX_);
2990         }
2991         originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
2992         originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadiusX_));
2993         filter_ = originalFilter;
2994         filter_->SetFilterType(RSFilter::BLUR);
2995         return;
2996     }
2997 
2998     if (greyCoef_.has_value()) {
2999         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
3000             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
3001         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
3002     }
3003     if (RSSystemProperties::GetKawaseEnabled()) {
3004         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
3005             std::make_shared<RSKawaseBlurShaderFilter>(foregroundBlurRadiusX_);
3006         if (originalFilter == nullptr) {
3007             originalFilter = std::make_shared<RSDrawingFilter>(kawaseBlurFilter);
3008         } else {
3009             originalFilter =
3010                 originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(kawaseBlurFilter));
3011         }
3012     } else {
3013         if (originalFilter == nullptr) {
3014             originalFilter = std::make_shared<RSDrawingFilter>(blurFilter, hash);
3015         } else {
3016             originalFilter = originalFilter->Compose(blurFilter, hash);
3017         }
3018     }
3019     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadiusX_));
3020     filter_ = originalFilter;
3021     filter_->SetFilterType(RSFilter::BLUR);
3022 }
3023 
GenerateForegroundMaterialBlurFilter()3024 void RSProperties::GenerateForegroundMaterialBlurFilter()
3025 {
3026     if (foregroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
3027         foregroundColorMode_ = BLUR_COLOR_MODE::AVERAGE;
3028     }
3029 #ifdef USE_M133_SKIA
3030     const auto hashFunc = SkChecksum::Hash32;
3031 #else
3032     const auto hashFunc = SkOpts::hash;
3033 #endif
3034     uint32_t hash = hashFunc(&foregroundBlurRadius_, sizeof(foregroundBlurRadius_), 0);
3035     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
3036         foregroundBlurSaturation_, foregroundBlurBrightness_);
3037     if (NeedLightBlur(fgBlurDisableSystemAdaptation)) {
3038         filter_ = GenerateMaterialLightBlurFilter(colorFilter, hash, foregroundBlurRadius_,
3039             foregroundColorMode_, foregroundMaskColor_);
3040         return;
3041     }
3042     std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
3043         Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, foregroundBlurRadius_, foregroundBlurRadius_);
3044 
3045     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
3046 
3047     // fuse grey-adjustment and pixel-stretch with blur filter
3048     if (NeedBlurFuzed()) {
3049         GenerateCompositingMaterialFuzedBlurFilter();
3050         return;
3051     }
3052 
3053     if (greyCoef_.has_value()) {
3054         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
3055             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
3056         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
3057     }
3058 
3059     if (RSSystemProperties::GetKawaseEnabled()) {
3060         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
3061             std::make_shared<RSKawaseBlurShaderFilter>(foregroundBlurRadius_);
3062         auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
3063         originalFilter = originalFilter?
3064             originalFilter->Compose(colorImageFilter, hash) : std::make_shared<RSDrawingFilter>(colorImageFilter, hash);
3065         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(kawaseBlurFilter));
3066     } else {
3067         hash = hashFunc(&foregroundBlurSaturation_, sizeof(foregroundBlurSaturation_), hash);
3068         hash = hashFunc(&foregroundBlurBrightness_, sizeof(foregroundBlurBrightness_), hash);
3069         originalFilter = originalFilter?
3070             originalFilter->Compose(blurColorFilter, hash) : std::make_shared<RSDrawingFilter>(blurColorFilter, hash);
3071     }
3072     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
3073         foregroundColorMode_, foregroundMaskColor_);
3074     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(maskColorShaderFilter));
3075     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadius_));
3076     originalFilter->SetSaturationForHPS(foregroundBlurSaturation_);
3077     originalFilter->SetBrightnessForHPS(foregroundBlurBrightness_);
3078     filter_ = originalFilter;
3079     filter_->SetFilterType(RSFilter::MATERIAL);
3080 }
3081 
GenerateBackgroundMaterialFuzedBlurFilter()3082 void RSProperties::GenerateBackgroundMaterialFuzedBlurFilter()
3083 {
3084     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
3085     std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
3086     if (greyCoef_.has_value()) {
3087         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadius_,
3088             greyCoef_->x_, greyCoef_->y_);
3089     } else {
3090         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadius_);
3091     }
3092     originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
3093 #ifdef USE_M133_SKIA
3094     const auto hashFunc = SkChecksum::Hash32;
3095 #else
3096     const auto hashFunc = SkOpts::hash;
3097 #endif
3098     uint32_t hash = hashFunc(&backgroundBlurRadius_, sizeof(backgroundBlurRadius_), 0);
3099     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
3100         backgroundBlurSaturation_, backgroundBlurBrightness_);
3101     auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
3102     originalFilter = originalFilter->Compose(colorImageFilter, hash);
3103     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
3104         backgroundColorMode_, backgroundMaskColor_);
3105     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(maskColorShaderFilter));
3106     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadius_));
3107     backgroundFilter_ = originalFilter;
3108     backgroundFilter_->SetFilterType(RSFilter::MATERIAL);
3109 }
3110 
GenerateCompositingMaterialFuzedBlurFilter()3111 void RSProperties::GenerateCompositingMaterialFuzedBlurFilter()
3112 {
3113     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
3114     std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
3115     if (greyCoef_.has_value()) {
3116         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadius_,
3117             greyCoef_->x_, greyCoef_->y_);
3118     } else {
3119         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadius_);
3120     }
3121     originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
3122 #ifdef USE_M133_SKIA
3123     const auto hashFunc = SkChecksum::Hash32;
3124 #else
3125     const auto hashFunc = SkOpts::hash;
3126 #endif
3127     uint32_t hash = hashFunc(&foregroundBlurRadius_, sizeof(foregroundBlurRadius_), 0);
3128     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
3129         foregroundBlurSaturation_, foregroundBlurBrightness_);
3130     auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
3131     originalFilter = originalFilter->Compose(colorImageFilter, hash);
3132     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
3133         foregroundColorMode_, foregroundMaskColor_);
3134     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(maskColorShaderFilter));
3135     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadius_));
3136     filter_ = originalFilter;
3137     filter_->SetFilterType(RSFilter::MATERIAL);
3138 }
3139 
GenerateAIBarFilter()3140 void RSProperties::GenerateAIBarFilter()
3141 {
3142     std::vector<float> aiInvertCoef = RSAIBarShaderFilter::GetAiInvertCoef();
3143     float aiBarRadius = aiInvertCoef[5]; // aiInvertCoef[5] is filter_radius
3144     std::shared_ptr<Drawing::ImageFilter> blurFilter =
3145         Drawing::ImageFilter::CreateBlurImageFilter(aiBarRadius, aiBarRadius, Drawing::TileMode::CLAMP, nullptr);
3146     std::shared_ptr<RSAIBarShaderFilter> aiBarShaderFilter = std::make_shared<RSAIBarShaderFilter>();
3147     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(aiBarShaderFilter);
3148 
3149     if (RSSystemProperties::GetKawaseEnabled()) {
3150         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
3151             std::make_shared<RSKawaseBlurShaderFilter>(aiBarRadius);
3152         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSRenderFilterParaBase>(kawaseBlurFilter));
3153     } else {
3154 #ifdef USE_M133_SKIA
3155         const auto hashFunc = SkChecksum::Hash32;
3156 #else
3157         const auto hashFunc = SkOpts::hash;
3158 #endif
3159         uint32_t hash = hashFunc(&aiBarRadius, sizeof(aiBarRadius), 0);
3160         originalFilter = originalFilter->Compose(blurFilter, hash);
3161     }
3162     backgroundFilter_ = originalFilter;
3163     backgroundFilter_->SetFilterType(RSFilter::AIBAR);
3164 }
3165 
GenerateLinearGradientBlurFilter()3166 void RSProperties::GenerateLinearGradientBlurFilter()
3167 {
3168     auto linearBlurFilter = std::make_shared<RSLinearGradientBlurShaderFilter>(linearGradientBlurPara_,
3169         frameGeo_.GetWidth(), frameGeo_.GetHeight());
3170     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(linearBlurFilter);
3171 
3172     filter_ = originalFilter;
3173     filter_->SetFilterType(RSFilter::LINEAR_GRADIENT_BLUR);
3174 }
3175 
GenerateMagnifierFilter()3176 void RSProperties::GenerateMagnifierFilter()
3177 {
3178     auto magnifierFilter = std::make_shared<RSMagnifierShaderFilter>(magnifierPara_);
3179 
3180     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(magnifierFilter);
3181     backgroundFilter_ = originalFilter;
3182     backgroundFilter_->SetFilterType(RSFilter::MAGNIFIER);
3183 }
3184 
GenerateWaterRippleFilter()3185 void RSProperties::GenerateWaterRippleFilter()
3186 {
3187     if (!waterRippleParams_) {
3188         return;
3189     }
3190     uint32_t waveCount = waterRippleParams_->waveCount;
3191     float rippleCenterX = waterRippleParams_->rippleCenterX;
3192     float rippleCenterY = waterRippleParams_->rippleCenterY;
3193     uint32_t rippleMode = waterRippleParams_->rippleMode;
3194     std::shared_ptr<RSWaterRippleShaderFilter> waterRippleFilter =
3195         std::make_shared<RSWaterRippleShaderFilter>(waterRippleProgress_, waveCount, rippleCenterX, rippleCenterY,
3196             rippleMode);
3197     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(waterRippleFilter);
3198     if (!backgroundFilter_) {
3199         backgroundFilter_ = originalFilter;
3200         backgroundFilter_->SetFilterType(RSFilter::WATER_RIPPLE);
3201     } else {
3202         auto backgroudDrawingFilter = std::static_pointer_cast<RSDrawingFilter>(backgroundFilter_);
3203         backgroudDrawingFilter->Compose(waterRippleFilter);
3204         backgroudDrawingFilter->SetFilterType(RSFilter::COMPOUND_EFFECT);
3205         backgroundFilter_ = backgroudDrawingFilter;
3206     }
3207 }
3208 
GenerateAlwaysSnapshotFilter()3209 void RSProperties::GenerateAlwaysSnapshotFilter()
3210 {
3211     std::shared_ptr<RSAlwaysSnapshotShaderFilter> alwaysSnapshotFilter =
3212         std::make_shared<RSAlwaysSnapshotShaderFilter>();
3213     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(alwaysSnapshotFilter);
3214     backgroundFilter_ = originalFilter;
3215     backgroundFilter_->SetFilterType(RSFilter::ALWAYS_SNAPSHOT);
3216 }
3217 
ComposeNGRenderFilter(std::shared_ptr<RSFilter> & originFilter,std::shared_ptr<RSNGRenderFilterBase> filter)3218 void RSProperties::ComposeNGRenderFilter(
3219     std::shared_ptr<RSFilter>& originFilter, std::shared_ptr<RSNGRenderFilterBase> filter)
3220 {
3221     std::shared_ptr<RSDrawingFilter> originDrawingFilter = nullptr;
3222     if (!originFilter) {
3223         originDrawingFilter = std::make_shared<RSDrawingFilter>();
3224     } else {
3225         originDrawingFilter = std::static_pointer_cast<RSDrawingFilter>(originFilter);
3226     }
3227     originDrawingFilter->SetNGRenderFilter(filter);
3228     if (filter) {
3229         originDrawingFilter->SetFilterType(RSFilter::COMPOUND_EFFECT);
3230         if (filter->ContainsType(RSNGEffectType::CONTENT_LIGHT)) {
3231             Vector3f rotationAngle(boundsGeo_->GetRotationX(), boundsGeo_->GetRotationY(), boundsGeo_->GetRotation());
3232             RSUIFilterHelper::SetRotationAngle(filter, rotationAngle);
3233         }
3234     }
3235     originFilter = originDrawingFilter;
3236 }
3237 
GenerateBackgroundFilter()3238 void RSProperties::GenerateBackgroundFilter()
3239 {
3240     if (aiInvert_.has_value() || systemBarEffect_) {
3241         GenerateAIBarFilter();
3242     } else if (magnifierPara_ && ROSEN_GNE(magnifierPara_->factor_, 0.f)) {
3243         GenerateMagnifierFilter();
3244     } else if (IsBackgroundMaterialFilterValid()) {
3245         GenerateBackgroundMaterialBlurFilter();
3246     } else if (IsBackgroundBlurRadiusXValid() && IsBackgroundBlurRadiusYValid()) {
3247         GenerateBackgroundBlurFilter();
3248     } else {
3249         backgroundFilter_ = nullptr;
3250     }
3251 
3252     if (IsWaterRippleValid()) {
3253         GenerateWaterRippleFilter();
3254     }
3255 
3256     if (bgNGRenderFilter_) {
3257         ComposeNGRenderFilter(backgroundFilter_, bgNGRenderFilter_);
3258     }
3259 
3260     if (alwaysSnapshot_ && backgroundFilter_ == nullptr) {
3261         GenerateAlwaysSnapshotFilter();
3262     }
3263     if (backgroundFilter_ == nullptr) {
3264         ROSEN_LOGD("RSProperties::GenerateBackgroundFilter failed");
3265     }
3266 }
3267 
GenerateForegroundFilter()3268 void RSProperties::GenerateForegroundFilter()
3269 {
3270     IfLinearGradientBlurInvalid();
3271     if (linearGradientBlurPara_) {
3272         GenerateLinearGradientBlurFilter();
3273     } else if (IsForegroundMaterialFilterVaild()) {
3274         GenerateForegroundMaterialBlurFilter();
3275     } else if (IsForegroundBlurRadiusXValid() && IsForegroundBlurRadiusYValid()) {
3276         GenerateForegroundBlurFilter();
3277     } else {
3278         filter_ = nullptr;
3279     }
3280 
3281     if (filter_ == nullptr) {
3282         ROSEN_LOGD("RSProperties::GenerateForegroundFilter failed");
3283     }
3284 }
3285 
SetUseEffect(bool useEffect)3286 void RSProperties::SetUseEffect(bool useEffect)
3287 {
3288     useEffect_ = useEffect;
3289     if (GetUseEffect()) {
3290         isDrawn_ = true;
3291     }
3292     filterNeedUpdate_ = true;
3293     SetDirty();
3294 }
3295 
GetUseEffect() const3296 bool RSProperties::GetUseEffect() const
3297 {
3298     return useEffect_;
3299 }
3300 
SetUseEffectType(int useEffectType)3301 void RSProperties::SetUseEffectType(int useEffectType)
3302 {
3303     useEffectType_ = std::clamp<int>(useEffectType, 0, static_cast<int>(UseEffectType::MAX));
3304     isDrawn_ = true;
3305     filterNeedUpdate_ = true;
3306     SetDirty();
3307     contentDirty_ = true;
3308 }
3309 
GetUseEffectType() const3310 int RSProperties::GetUseEffectType() const
3311 {
3312     return useEffectType_;
3313 }
3314 
SetNeedDrawBehindWindow(bool needDrawBehindWindow)3315 void RSProperties::SetNeedDrawBehindWindow(bool needDrawBehindWindow)
3316 {
3317     needDrawBehindWindow_ = needDrawBehindWindow;
3318     UpdateFilter();
3319 }
3320 
SetUseShadowBatching(bool useShadowBatching)3321 void RSProperties::SetUseShadowBatching(bool useShadowBatching)
3322 {
3323     if (useShadowBatching) {
3324         isDrawn_ = true;
3325     }
3326     useShadowBatching_ = useShadowBatching;
3327     SetDirty();
3328 }
3329 
SetPixelStretch(const std::optional<Vector4f> & stretchSize)3330 void RSProperties::SetPixelStretch(const std::optional<Vector4f>& stretchSize)
3331 {
3332     pixelStretch_ = stretchSize;
3333     SetDirty();
3334     pixelStretchNeedUpdate_ = true;
3335     contentDirty_ = true;
3336     if (pixelStretch_.has_value() && pixelStretch_->IsZero()) {
3337         pixelStretch_ = std::nullopt;
3338     }
3339 }
3340 
GetPixelStretchDirtyRect() const3341 RectI RSProperties::GetPixelStretchDirtyRect() const
3342 {
3343     auto dirtyRect = GetDirtyRect();
3344 
3345     auto scaledBounds = RectF(dirtyRect.left_ - pixelStretch_->x_, dirtyRect.top_ - pixelStretch_->y_,
3346         dirtyRect.width_ + pixelStretch_->x_ + pixelStretch_->z_,
3347         dirtyRect.height_ + pixelStretch_->y_ + pixelStretch_->w_);
3348 
3349     auto scaledIBounds = RectI(std::floor(scaledBounds.left_), std::floor(scaledBounds.top_),
3350         std::ceil(scaledBounds.width_) + 1, std::ceil(scaledBounds.height_) + 1);
3351     return dirtyRect.JoinRect(scaledIBounds);
3352 }
3353 
SetPixelStretchPercent(const std::optional<Vector4f> & stretchPercent)3354 void RSProperties::SetPixelStretchPercent(const std::optional<Vector4f>& stretchPercent)
3355 {
3356     pixelStretchPercent_ = stretchPercent;
3357     SetDirty();
3358     pixelStretchNeedUpdate_ = true;
3359     contentDirty_ = true;
3360     if (pixelStretchPercent_.has_value() && pixelStretchPercent_->IsZero()) {
3361         pixelStretchPercent_ = std::nullopt;
3362     }
3363 }
3364 
SetPixelStretchTileMode(int stretchTileMode)3365 void RSProperties::SetPixelStretchTileMode(int stretchTileMode)
3366 {
3367     pixelStretchTileMode_ = std::clamp<int>(stretchTileMode, static_cast<int>(Drawing::TileMode::CLAMP),
3368         static_cast<int>(Drawing::TileMode::DECAL));
3369     SetDirty();
3370     pixelStretchNeedUpdate_ = true;
3371     contentDirty_ = true;
3372 }
3373 
GetPixelStretchTileMode() const3374 int RSProperties::GetPixelStretchTileMode() const
3375 {
3376     return pixelStretchTileMode_;
3377 }
3378 
3379 // Image effect properties
SetGrayScale(const std::optional<float> & grayScale)3380 void RSProperties::SetGrayScale(const std::optional<float>& grayScale)
3381 {
3382     grayScale_ = grayScale;
3383     colorFilterNeedUpdate_ = true;
3384     SetDirty();
3385     contentDirty_ = true;
3386 }
3387 
SetLightIntensity(float lightIntensity)3388 void RSProperties::SetLightIntensity(float lightIntensity)
3389 {
3390     if (!lightSourcePtr_) {
3391         lightSourcePtr_ = std::make_shared<RSLightSource>();
3392     }
3393     lightSourcePtr_->SetLightIntensity(lightIntensity);
3394     SetDirty();
3395     contentDirty_ = true;
3396 
3397     if (ROSEN_EQ(lightIntensity, INVALID_INTENSITY)) { // skip when resetFunc call
3398         return;
3399     }
3400     auto preIntensity = lightSourcePtr_->GetPreLightIntensity();
3401     auto renderNode = backref_.lock();
3402     bool preIntensityIsZero = ROSEN_EQ(preIntensity, 0.f);
3403     bool curIntensityIsZero = ROSEN_EQ(lightIntensity, 0.f);
3404     if (preIntensityIsZero && !curIntensityIsZero) { // 0 --> non-zero
3405         RSPointLightManager::Instance()->RegisterLightSource(renderNode);
3406     } else if (!preIntensityIsZero && curIntensityIsZero) { // non-zero --> 0
3407         RSPointLightManager::Instance()->UnRegisterLightSource(renderNode);
3408     }
3409 }
3410 
SetLightColor(Color lightColor)3411 void RSProperties::SetLightColor(Color lightColor)
3412 {
3413     if (!lightSourcePtr_) {
3414         lightSourcePtr_ = std::make_shared<RSLightSource>();
3415     }
3416     lightSourcePtr_->SetLightColor(lightColor);
3417     SetDirty();
3418     contentDirty_ = true;
3419 }
3420 
SetLightPosition(const Vector4f & lightPosition)3421 void RSProperties::SetLightPosition(const Vector4f& lightPosition)
3422 {
3423     if (!lightSourcePtr_) {
3424         lightSourcePtr_ = std::make_shared<RSLightSource>();
3425     }
3426     lightSourcePtr_->SetLightPosition(lightPosition);
3427     SetDirty();
3428     contentDirty_ = true;
3429 }
3430 
SetIlluminatedBorderWidth(float illuminatedBorderWidth)3431 void RSProperties::SetIlluminatedBorderWidth(float illuminatedBorderWidth)
3432 {
3433     if (!illuminatedPtr_) {
3434         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3435     }
3436     illuminatedPtr_->SetIlluminatedBorderWidth(illuminatedBorderWidth);
3437     SetDirty();
3438     contentDirty_ = true;
3439 }
3440 
SetIlluminatedType(int illuminatedType)3441 void RSProperties::SetIlluminatedType(int illuminatedType)
3442 {
3443     if (!illuminatedPtr_) {
3444         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3445     }
3446     auto curIlluminateType = IlluminatedType(illuminatedType);
3447     illuminatedPtr_->SetIlluminatedType(curIlluminateType);
3448     isDrawn_ = true;
3449     SetDirty();
3450     contentDirty_ = true;
3451 
3452     if (curIlluminateType == IlluminatedType::INVALID) { // skip when resetFunc call
3453         return;
3454     }
3455     auto renderNode = backref_.lock();
3456     auto preIlluminatedType = illuminatedPtr_->GetPreIlluminatedType();
3457     bool preTypeIsNone = preIlluminatedType == IlluminatedType::NONE;
3458     bool curTypeIsNone = curIlluminateType == IlluminatedType::NONE;
3459     if (preTypeIsNone && !curTypeIsNone) {
3460         RSPointLightManager::Instance()->RegisterIlluminated(renderNode);
3461     } else if (!preTypeIsNone && curTypeIsNone) {
3462         RSPointLightManager::Instance()->UnRegisterIlluminated(renderNode);
3463     }
3464 }
3465 
SetBloom(float bloomIntensity)3466 void RSProperties::SetBloom(float bloomIntensity)
3467 {
3468     if (!illuminatedPtr_) {
3469         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3470     }
3471     illuminatedPtr_->SetBloomIntensity(bloomIntensity);
3472     isDrawn_ = true;
3473     SetDirty();
3474     contentDirty_ = true;
3475 }
3476 
GetLightIntensity() const3477 float RSProperties::GetLightIntensity() const
3478 {
3479     return lightSourcePtr_ ? lightSourcePtr_->GetLightIntensity() : 0.f;
3480 }
3481 
GetLightColor() const3482 Color RSProperties::GetLightColor() const
3483 {
3484     return lightSourcePtr_ ? lightSourcePtr_->GetLightColor() : RgbPalette::White();
3485 }
3486 
GetLightPosition() const3487 Vector4f RSProperties::GetLightPosition() const
3488 {
3489     return lightSourcePtr_ ? lightSourcePtr_->GetLightPosition() : Vector4f(0.f);
3490 }
3491 
GetIlluminatedType() const3492 int RSProperties::GetIlluminatedType() const
3493 {
3494     return illuminatedPtr_ ? static_cast<int>(illuminatedPtr_->GetIlluminatedType()) : 0;
3495 }
3496 
CalculateAbsLightPosition()3497 void RSProperties::CalculateAbsLightPosition()
3498 {
3499     auto lightSourceAbsRect = boundsGeo_->GetAbsRect();
3500     auto rotation = RSPointLightManager::Instance()->GetScreenRotation();
3501     Vector4f lightAbsPosition = Vector4f();
3502     auto lightPos = lightSourcePtr_->GetLightPosition();
3503     switch (rotation) {
3504         case ScreenRotation::ROTATION_0:
3505             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetLeft() + lightPos.x_);
3506             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetTop() + lightPos.y_);
3507             break;
3508         case ScreenRotation::ROTATION_90:
3509             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetBottom() - lightPos.x_);
3510             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetLeft() + lightPos.y_);
3511             break;
3512         case ScreenRotation::ROTATION_180:
3513             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetRight() - lightPos.x_);
3514             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetBottom() - lightPos.y_);
3515             break;
3516         case ScreenRotation::ROTATION_270:
3517             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetTop() + lightPos.x_);
3518             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetRight() - lightPos.y_);
3519             break;
3520         default:
3521             break;
3522     }
3523     lightAbsPosition.z_ = lightPos.z_;
3524     lightAbsPosition.w_ = lightPos.w_;
3525     lightSourcePtr_->SetAbsLightPosition(lightAbsPosition);
3526 }
3527 
SetBrightness(const std::optional<float> & brightness)3528 void RSProperties::SetBrightness(const std::optional<float>& brightness)
3529 {
3530     brightness_ = brightness;
3531     colorFilterNeedUpdate_ = true;
3532     SetDirty();
3533     contentDirty_ = true;
3534 }
3535 
GetBrightness() const3536 const std::optional<float>& RSProperties::GetBrightness() const
3537 {
3538     return brightness_;
3539 }
3540 
SetContrast(const std::optional<float> & contrast)3541 void RSProperties::SetContrast(const std::optional<float>& contrast)
3542 {
3543     contrast_ = contrast;
3544     colorFilterNeedUpdate_ = true;
3545     SetDirty();
3546     contentDirty_ = true;
3547 }
3548 
GetContrast() const3549 const std::optional<float>& RSProperties::GetContrast() const
3550 {
3551     return contrast_;
3552 }
3553 
SetSaturate(const std::optional<float> & saturate)3554 void RSProperties::SetSaturate(const std::optional<float>& saturate)
3555 {
3556     saturate_ = saturate;
3557     colorFilterNeedUpdate_ = true;
3558     SetDirty();
3559     contentDirty_ = true;
3560 }
3561 
GetSaturate() const3562 const std::optional<float>& RSProperties::GetSaturate() const
3563 {
3564     return saturate_;
3565 }
3566 
SetSepia(const std::optional<float> & sepia)3567 void RSProperties::SetSepia(const std::optional<float>& sepia)
3568 {
3569     sepia_ = sepia;
3570     colorFilterNeedUpdate_ = true;
3571     SetDirty();
3572     contentDirty_ = true;
3573 }
3574 
GetSepia() const3575 const std::optional<float>& RSProperties::GetSepia() const
3576 {
3577     return sepia_;
3578 }
3579 
SetInvert(const std::optional<float> & invert)3580 void RSProperties::SetInvert(const std::optional<float>& invert)
3581 {
3582     invert_ = invert;
3583     colorFilterNeedUpdate_ = true;
3584     SetDirty();
3585     contentDirty_ = true;
3586 }
3587 
GetInvert() const3588 const std::optional<float>& RSProperties::GetInvert() const
3589 {
3590     return invert_;
3591 }
3592 
3593 
SetAiInvert(const std::optional<Vector4f> & aiInvert)3594 void RSProperties::SetAiInvert(const std::optional<Vector4f>& aiInvert)
3595 {
3596     aiInvert_ = aiInvert;
3597     colorFilterNeedUpdate_ = true;
3598     SetDirty();
3599     contentDirty_ = true;
3600     isDrawn_ = true;
3601 }
3602 
GetAiInvert() const3603 const std::optional<Vector4f>& RSProperties::GetAiInvert() const
3604 {
3605     return aiInvert_;
3606 }
3607 
SetSystemBarEffect(bool systemBarEffect)3608 void RSProperties::SetSystemBarEffect(bool systemBarEffect)
3609 {
3610     systemBarEffect_ = systemBarEffect;
3611     colorFilterNeedUpdate_ = true;
3612     filterNeedUpdate_ = true;
3613     SetDirty();
3614     contentDirty_ = true;
3615     isDrawn_ = true;
3616 }
3617 
GetSystemBarEffect() const3618 bool RSProperties::GetSystemBarEffect() const
3619 {
3620     return systemBarEffect_;
3621 }
3622 
SetHueRotate(const std::optional<float> & hueRotate)3623 void RSProperties::SetHueRotate(const std::optional<float>& hueRotate)
3624 {
3625     hueRotate_ = hueRotate;
3626     colorFilterNeedUpdate_ = true;
3627     SetDirty();
3628     contentDirty_ = true;
3629 }
3630 
GetHueRotate() const3631 const std::optional<float>& RSProperties::GetHueRotate() const
3632 {
3633     return hueRotate_;
3634 }
3635 
SetColorBlend(const std::optional<Color> & colorBlend)3636 void RSProperties::SetColorBlend(const std::optional<Color>& colorBlend)
3637 {
3638     colorBlend_ = colorBlend;
3639     colorFilterNeedUpdate_ = true;
3640     SetDirty();
3641     contentDirty_ = true;
3642 }
3643 
GetColorBlend() const3644 const std::optional<Color>& RSProperties::GetColorBlend() const
3645 {
3646     return colorBlend_;
3647 }
3648 
GreatNotEqual(double left,double right)3649 static bool GreatNotEqual(double left, double right)
3650 {
3651     constexpr double epsilon = 0.001f;
3652     return (left - right) > epsilon;
3653 }
3654 
NearEqual(const double left,const double right)3655 static bool NearEqual(const double left, const double right)
3656 {
3657     constexpr double epsilon = 0.001f;
3658     return (std::abs(left - right) <= epsilon);
3659 }
3660 
GreatOrEqual(double left,double right)3661 static bool GreatOrEqual(double left, double right)
3662 {
3663     constexpr double epsilon = -0.001f;
3664     return (left - right) > epsilon;
3665 }
3666 
GenerateColorFilter()3667 void RSProperties::GenerateColorFilter()
3668 {
3669     // No update needed if color filter is valid
3670     if (!colorFilterNeedUpdate_) {
3671         return;
3672     }
3673 
3674     colorFilterNeedUpdate_ = false;
3675     colorFilter_ = nullptr;
3676     if (!grayScale_ && !brightness_ && !contrast_ && !saturate_ && !sepia_ && !invert_ && !hueRotate_ && !colorBlend_) {
3677         return;
3678     }
3679 
3680     std::shared_ptr<Drawing::ColorFilter> filter = nullptr;
3681 
3682     if (grayScale_.has_value() && GreatNotEqual(*grayScale_, 0.f)) {
3683         auto grayScale = grayScale_.value();
3684         float matrix[20] = { 0.0f }; // 20 : matrix size
3685         matrix[0] = matrix[INDEX_5] = matrix[INDEX_10] = 0.2126f * grayScale; // 0.2126 : gray scale coefficient
3686         matrix[1] = matrix[INDEX_6] = matrix[INDEX_11] = 0.7152f * grayScale; // 0.7152 : gray scale coefficient
3687         matrix[INDEX_2] = matrix[INDEX_7] = matrix[INDEX_12] = 0.0722f * grayScale; // 0.0722 : gray scale coefficient
3688         matrix[INDEX_18] = 1.0 * grayScale;
3689         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3690         if (colorFilter_) {
3691             filter->Compose(*colorFilter_);
3692         }
3693         colorFilter_ = filter;
3694     }
3695     if (brightness_.has_value() && !NearEqual(*brightness_, 1.0)) {
3696         auto brightness = brightness_.value();
3697         float matrix[20] = { 0.0f }; // 20 : matrix size
3698         // shift brightness to (-1, 1)
3699         brightness = brightness - 1;
3700         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = matrix[INDEX_18] = 1.0f;
3701         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = brightness;
3702         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3703         if (colorFilter_) {
3704             filter->Compose(*colorFilter_);
3705         }
3706         colorFilter_ = filter;
3707     }
3708     if (contrast_.has_value() && !NearEqual(*contrast_, 1.0)) {
3709         auto contrast = contrast_.value();
3710         uint32_t contrastValue128 = 128;
3711         uint32_t contrastValue255 = 255;
3712         float matrix[20] = { 0.0f }; // 20 : matrix size
3713         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = contrast;
3714         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = contrastValue128 * (1 - contrast) / contrastValue255;
3715         matrix[INDEX_18] = 1.0f;
3716         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3717         if (colorFilter_) {
3718             filter->Compose(*colorFilter_);
3719         }
3720         colorFilter_ = filter;
3721     }
3722     if (saturate_.has_value() && !NearEqual(*saturate_, 1.0) && GreatOrEqual(*saturate_, 0.0)) {
3723         auto saturate = saturate_.value();
3724         float matrix[20] = { 0.0f }; // 20 : matrix size
3725         matrix[0] = 0.3086f * (1 - saturate) + saturate; // 0.3086 : saturate coefficient
3726         matrix[1] = matrix[INDEX_11] = 0.6094f * (1 - saturate); // 0.6094 : saturate coefficient
3727         matrix[INDEX_2] = matrix[INDEX_7] = 0.0820f * (1 - saturate); // 0.0820 : saturate coefficient
3728         matrix[INDEX_5] = matrix[INDEX_10] = 0.3086f * (1 - saturate); // 0.3086 : saturate coefficient
3729         matrix[INDEX_6] = 0.6094f * (1 - saturate) + saturate; // 0.6094 : saturate coefficient
3730         matrix[INDEX_12] = 0.0820f * (1 - saturate) + saturate; // 0.0820 : saturate coefficient
3731         matrix[INDEX_18] = 1.0f;
3732         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3733         if (colorFilter_) {
3734             filter->Compose(*colorFilter_);
3735         }
3736         colorFilter_ = filter;
3737     }
3738     if (sepia_.has_value() && GreatNotEqual(*sepia_, 0.0)) {
3739         auto sepia = sepia_.value();
3740         float matrix[20] = { 0.0f }; // 20 : matrix size
3741         matrix[0] = 0.393f * sepia;
3742         matrix[1] = 0.769f * sepia;
3743         matrix[INDEX_2] = 0.189f * sepia;
3744 
3745         matrix[INDEX_5] = 0.349f * sepia;
3746         matrix[INDEX_6] = 0.686f * sepia;
3747         matrix[INDEX_7] = 0.168f * sepia;
3748 
3749         matrix[INDEX_10] = 0.272f * sepia;
3750         matrix[INDEX_11] = 0.534f * sepia;
3751         matrix[INDEX_12] = 0.131f * sepia;
3752         matrix[INDEX_18] = 1.0f * sepia;
3753         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3754         if (colorFilter_) {
3755             filter->Compose(*colorFilter_);
3756         }
3757         colorFilter_ = filter;
3758     }
3759     if (invert_.has_value() && GreatNotEqual(*invert_, 0.0)) {
3760         auto invert = invert_.value();
3761         float matrix[20] = { 0.0f }; // 20 : matrix size
3762         if (invert > 1.0) {
3763             invert = 1.0;
3764         }
3765         // complete color invert when dstRGB = 1 - srcRGB
3766         // map (0, 1) to (1, -1)
3767         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = 1.0 - 2.0 * invert; // 2.0: invert
3768         matrix[INDEX_18] = 1.0f;
3769         // invert = 0.5 -> RGB = (0.5, 0.5, 0.5) -> image completely gray
3770         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = invert;
3771         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3772         if (colorFilter_) {
3773             filter->Compose(*colorFilter_);
3774         }
3775         colorFilter_ = filter;
3776     }
3777     if (hueRotate_.has_value() && GreatNotEqual(*hueRotate_, 0.0)) {
3778         auto hueRotate = hueRotate_.value();
3779         while (GreatOrEqual(hueRotate, 360)) { // 360 : degree
3780             hueRotate -= 360; // 360 : degree
3781         }
3782         float matrix[20] = { 0.0f }; // 20 : matrix size
3783         int32_t type = hueRotate / 120; // 120 : degree
3784         float N = (hueRotate - 120 * type) / 120; // 120 : degree
3785         switch (type) {
3786             case 0:
3787                 // color change = R->G, G->B, B->R
3788                 matrix[INDEX_2] = matrix[INDEX_5] = matrix[INDEX_11] = N;
3789                 matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = 1 - N;
3790                 matrix[INDEX_18] = 1.0f;
3791                 break;
3792             case 1:
3793                 // compare to original: R->B, G->R, B->G
3794                 matrix[1] = matrix[INDEX_7] = matrix[INDEX_10] = N;
3795                 matrix[INDEX_2] = matrix[INDEX_5] = matrix[INDEX_11] = 1 - N;
3796                 matrix[INDEX_18] = 1.0f;
3797                 break;
3798             case 2: // 2: back to normal color
3799                 matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = N;
3800                 matrix[1] = matrix[INDEX_7] = matrix[INDEX_10] = 1 - N;
3801                 matrix[INDEX_18] = 1.0f;
3802                 break;
3803             default:
3804                 break;
3805         }
3806         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3807         if (colorFilter_) {
3808             filter->Compose(*colorFilter_);
3809         }
3810         colorFilter_ = filter;
3811     }
3812     if (colorBlend_.has_value() && *colorBlend_ != RgbPalette::Transparent()) {
3813         auto colorBlend = colorBlend_.value();
3814         filter = Drawing::ColorFilter::CreateBlendModeColorFilter(colorBlend.AsArgbInt(),
3815             Drawing::BlendMode::PLUS);
3816         if (colorFilter_) {
3817             filter->Compose(*colorFilter_);
3818         }
3819         colorFilter_ = filter;
3820     }
3821     isDrawn_ = true;
3822 }
3823 
Dump() const3824 std::string RSProperties::Dump() const
3825 {
3826     std::string dumpInfo;
3827     char buffer[UINT8_MAX] = { 0 };
3828     if (sprintf_s(buffer, UINT8_MAX, "Bounds[%.1f %.1f %.1f %.1f] Frame[%.1f %.1f %.1f %.1f]",
3829         GetBoundsPositionX(), GetBoundsPositionY(), GetBoundsWidth(), GetBoundsHeight(),
3830         GetFramePositionX(), GetFramePositionY(), GetFrameWidth(), GetFrameHeight()) != -1) {
3831         dumpInfo.append(buffer);
3832     }
3833 
3834     errno_t ret;
3835     if (clipToBounds_) {
3836         // clipToBounds
3837         ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3838         if (ret != EOK) {
3839             return "Failed to memset_s for clipToBounds, ret=" + std::to_string(ret);
3840         }
3841         if (sprintf_s(buffer, UINT8_MAX, ", ClipToBounds[True]") != -1) {
3842             dumpInfo.append(buffer);
3843         }
3844     }
3845     if (clipToFrame_) {
3846         // clipToFrame
3847         ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3848         if (ret != EOK) {
3849             return "Failed to memset_s for clipToFrame, ret=" + std::to_string(ret);
3850         }
3851         if (sprintf_s(buffer, UINT8_MAX, ", ClipToFrame[True]") != -1) {
3852             dumpInfo.append(buffer);
3853         }
3854     }
3855 
3856     // PositionZ
3857     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3858     if (ret != EOK) {
3859         return "Failed to memset_s for PositionZ, ret=" + std::to_string(ret);
3860     }
3861     if (!ROSEN_EQ(GetPositionZ(), 0.f) &&
3862         sprintf_s(buffer, UINT8_MAX, ", PositionZ[%.1f]", GetPositionZ()) != -1) {
3863         dumpInfo.append(buffer);
3864     }
3865 
3866     // Pivot
3867     std::unique_ptr<RSTransform> defaultTrans = std::make_unique<RSTransform>();
3868     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3869     if (ret != EOK) {
3870         return "Failed to memset_s for Pivot, ret=" + std::to_string(ret);
3871     }
3872     Vector2f pivot = GetPivot();
3873     if ((!ROSEN_EQ(pivot[0], defaultTrans->pivotX_) || !ROSEN_EQ(pivot[1], defaultTrans->pivotY_)) &&
3874         sprintf_s(buffer, UINT8_MAX, ", Pivot[%.1f,%.1f]", pivot[0], pivot[1]) != -1) {
3875         dumpInfo.append(buffer);
3876     }
3877 
3878     // CornerRadius
3879     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3880     if (ret != EOK) {
3881         return "Failed to memset_s for CornerRadius, ret=" + std::to_string(ret);
3882     }
3883     if (!GetCornerRadius().IsZero() &&
3884         sprintf_s(buffer, UINT8_MAX, ", CornerRadius[%.1f %.1f %.1f %.1f]",
3885             GetCornerRadius().x_, GetCornerRadius().y_, GetCornerRadius().z_, GetCornerRadius().w_) != -1) {
3886         dumpInfo.append(buffer);
3887     }
3888 
3889     // PixelStretch PixelStretchPercent
3890     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3891     if (ret != EOK) {
3892         return "Failed to memset_s for PixelStretch, ret=" + std::to_string(ret);
3893     }
3894     if (pixelStretch_.has_value() &&
3895         sprintf_s(buffer, UINT8_MAX, ", PixelStretch[left:%.1f top:%.1f right:%.1f bottom:%.1f]",
3896             pixelStretch_->x_, pixelStretch_->y_, pixelStretch_->z_, pixelStretch_->w_) != -1) {
3897         dumpInfo.append(buffer);
3898     }
3899 
3900     // Rotation
3901     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3902     if (ret != EOK) {
3903         return "Failed to memset_s for Rotation, ret=" + std::to_string(ret);
3904     }
3905     if (!ROSEN_EQ(GetRotation(), defaultTrans->rotation_) &&
3906         sprintf_s(buffer, UINT8_MAX, ", Rotation[%.1f]", GetRotation()) != -1) {
3907         dumpInfo.append(buffer);
3908     }
3909     // RotationX
3910     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3911     if (ret != EOK) {
3912         return "Failed to memset_s for RotationX, ret=" + std::to_string(ret);
3913     }
3914     if (!ROSEN_EQ(GetRotationX(), defaultTrans->rotationX_) &&
3915         sprintf_s(buffer, UINT8_MAX, ", RotationX[%.1f]", GetRotationX()) != -1) {
3916         dumpInfo.append(buffer);
3917     }
3918     // RotationY
3919     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3920     if (ret != EOK) {
3921         return "Failed to memset_s for RotationY, ret=" + std::to_string(ret);
3922     }
3923     if (!ROSEN_EQ(GetRotationY(), defaultTrans->rotationY_) &&
3924         sprintf_s(buffer, UINT8_MAX, ", RotationY[%.1f]", GetRotationY()) != -1) {
3925         dumpInfo.append(buffer);
3926     }
3927 
3928     // TranslateX
3929     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3930     if (ret != EOK) {
3931         return "Failed to memset_s for TranslateX, ret=" + std::to_string(ret);
3932     }
3933     if (!ROSEN_EQ(GetTranslateX(), defaultTrans->translateX_) &&
3934         sprintf_s(buffer, UINT8_MAX, ", TranslateX[%.1f]", GetTranslateX()) != -1) {
3935         dumpInfo.append(buffer);
3936     }
3937 
3938     // TranslateY
3939     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3940     if (ret != EOK) {
3941         return "Failed to memset_s for TranslateY, ret=" + std::to_string(ret);
3942     }
3943     if (!ROSEN_EQ(GetTranslateY(), defaultTrans->translateY_) &&
3944         sprintf_s(buffer, UINT8_MAX, ", TranslateY[%.1f]", GetTranslateY()) != -1) {
3945         dumpInfo.append(buffer);
3946     }
3947 
3948     // TranslateZ
3949     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3950     if (ret != EOK) {
3951         return "Failed to memset_s for TranslateZ, ret=" + std::to_string(ret);
3952     }
3953     if (!ROSEN_EQ(GetTranslateZ(), defaultTrans->translateZ_) &&
3954         sprintf_s(buffer, UINT8_MAX, ", TranslateZ[%.1f]", GetTranslateZ()) != -1) {
3955         dumpInfo.append(buffer);
3956     }
3957 
3958     // ScaleX
3959     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3960     if (ret != EOK) {
3961         return "Failed to memset_s for ScaleX, ret=" + std::to_string(ret);
3962     }
3963     if (!ROSEN_EQ(GetScaleX(), defaultTrans->scaleX_) &&
3964         sprintf_s(buffer, UINT8_MAX, ", ScaleX[%.1f]", GetScaleX()) != -1) {
3965         dumpInfo.append(buffer);
3966     }
3967 
3968     // ScaleY
3969     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3970     if (ret != EOK) {
3971         return "Failed to memset_s for ScaleY, ret=" + std::to_string(ret);
3972     }
3973     if (!ROSEN_EQ(GetScaleY(), defaultTrans->scaleY_) &&
3974         sprintf_s(buffer, UINT8_MAX, ", ScaleY[%.1f]", GetScaleY()) != -1) {
3975         dumpInfo.append(buffer);
3976     }
3977 
3978     // Alpha
3979     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3980     if (ret != EOK) {
3981         return "Failed to memset_s for Alpha, ret=" + std::to_string(ret);
3982     }
3983     if (!ROSEN_EQ(GetAlpha(), 1.f) &&
3984         sprintf_s(buffer, UINT8_MAX, ", Alpha[%.3f]", GetAlpha()) != -1) {
3985         dumpInfo.append(buffer);
3986     }
3987 
3988     //NeedFilter
3989     if (NeedFilter()) {
3990         dumpInfo.append(", NeedFilter[true]");
3991     }
3992 
3993     // Spherize
3994     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3995     if (ret != EOK) {
3996         return "Failed to memset_s for Spherize, ret=" + std::to_string(ret);
3997     }
3998     if (!ROSEN_EQ(GetSpherize(), 0.f) &&
3999         sprintf_s(buffer, UINT8_MAX, ", Spherize[%.1f]", GetSpherize()) != -1) {
4000         dumpInfo.append(buffer);
4001     }
4002 
4003     // AttractFraction
4004     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4005     if (ret != EOK) {
4006         return "Failed to memset_s for AttractFraction, ret=" + std::to_string(ret);
4007     }
4008     if (!ROSEN_EQ(GetAttractionFraction(), 0.f) &&
4009         sprintf_s(buffer, UINT8_MAX, ", MiniFraction[%.1f]",  GetAttractionFraction()) != -1) {
4010         dumpInfo.append(buffer);
4011     }
4012 
4013     // Attraction Destination Position
4014     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4015     if (ret != EOK) {
4016         return "Failed to memset_s for MiniDstpoint, ret=" + std::to_string(ret);
4017     }
4018     Vector2f attractionDstpoint = GetAttractionDstPoint();
4019     if ((!ROSEN_EQ(attractionDstpoint[0], 0.f) || !ROSEN_EQ(attractionDstpoint[1], 0.f)) &&
4020         sprintf_s(buffer, UINT8_MAX, ", AttractionFraction DstPointY[%.1f,%.1f]",
4021         attractionDstpoint[0], attractionDstpoint[1]) != -1) {
4022         dumpInfo.append(buffer);
4023     }
4024 
4025     // blendmode
4026     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4027     if (ret != EOK) {
4028         return "Failed to memset_s for blendmode, ret=" + std::to_string(ret);
4029     }
4030     if (!ROSEN_EQ(GetColorBlendMode(), 0) &&
4031         sprintf_s(buffer, UINT8_MAX, ", skblendmode[%d], blendType[%d]",
4032         GetColorBlendMode() - 1, GetColorBlendApplyType()) != -1) {
4033         dumpInfo.append(buffer);
4034     }
4035 
4036     // LightUpEffect
4037     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4038     if (ret != EOK) {
4039         return "Failed to memset_s for LightUpEffect, ret=" + std::to_string(ret);
4040     }
4041     if (!ROSEN_EQ(GetLightUpEffect(), 1.f) &&
4042         sprintf_s(buffer, UINT8_MAX, ", LightUpEffect[%.1f]", GetLightUpEffect()) != -1) {
4043         dumpInfo.append(buffer);
4044     }
4045 
4046     // ForegroundColor
4047     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4048     if (ret != EOK) {
4049         return "Failed to memset_s for ForegroundColor, ret=" + std::to_string(ret);
4050     }
4051     if (!ROSEN_EQ(GetForegroundColor(), RgbPalette::Transparent()) &&
4052         sprintf_s(buffer, UINT8_MAX, ", ForegroundColor[#%08X]", GetForegroundColor().AsArgbInt()) != -1) {
4053         dumpInfo.append(buffer);
4054     }
4055 
4056     // BackgroundColor
4057     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4058     if (ret != EOK) {
4059         return "Failed to memset_s for BackgroundColor, ret=" + std::to_string(ret);
4060     }
4061     if (!ROSEN_EQ(GetBackgroundColor(), RgbPalette::Transparent()) &&
4062         sprintf_s(buffer, UINT8_MAX, ", BackgroundColor[#%08X]", GetBackgroundColor().AsArgbInt()) != -1) {
4063         dumpInfo.append(buffer);
4064     }
4065 
4066     // BgImage
4067     std::unique_ptr<Decoration> defaultDecoration = std::make_unique<Decoration>();
4068     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4069     if (ret != EOK) {
4070         return "Failed to memset_s for BgImage, ret=" + std::to_string(ret);
4071     }
4072     if ((!ROSEN_EQ(GetBgImagePositionX(), defaultDecoration->bgImageRect_.left_) ||
4073         !ROSEN_EQ(GetBgImagePositionY(), defaultDecoration->bgImageRect_.top_) ||
4074         !ROSEN_EQ(GetBgImageWidth(), defaultDecoration->bgImageRect_.width_) ||
4075         !ROSEN_EQ(GetBgImageHeight(), defaultDecoration->bgImageRect_.height_)) &&
4076         sprintf_s(buffer, UINT8_MAX, ", BgImage[%.1f %.1f %.1f %.1f]", GetBgImagePositionX(),
4077             GetBgImagePositionY(), GetBgImageWidth(), GetBgImageHeight()) != -1) {
4078         dumpInfo.append(buffer);
4079     }
4080 
4081     // Border
4082     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4083     if (ret != EOK) {
4084         return "Failed to memset_s for Border, ret=" + std::to_string(ret);
4085     }
4086     if (border_ && border_->HasBorder() &&
4087         sprintf_s(buffer, UINT8_MAX, ", Border[%s]", border_->ToString().c_str()) != -1) {
4088         dumpInfo.append(buffer);
4089     }
4090 
4091     // Filter
4092     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4093     if (ret != EOK) {
4094         return "Failed to memset_s for Filter, ret=" + std::to_string(ret);
4095     }
4096     auto filter_ = GetFilter();
4097     if (filter_ && filter_->IsValid() &&
4098         sprintf_s(buffer, UINT8_MAX, ", Filter[%s]", filter_->GetDescription().c_str()) != -1) {
4099         dumpInfo.append(buffer);
4100     }
4101 
4102     // BackgroundFilter
4103     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4104     if (ret != EOK) {
4105         return "Failed to memset_s for BackgroundFilter, ret=" + std::to_string(ret);
4106     }
4107     auto backgroundFilter_ = GetBackgroundFilter();
4108     if (backgroundFilter_ && backgroundFilter_->IsValid() &&
4109         sprintf_s(buffer, UINT8_MAX, ", BackgroundFilter[%s]", backgroundFilter_->GetDescription().c_str()) != -1) {
4110         dumpInfo.append(buffer);
4111     }
4112 
4113     // ForegroundFilter
4114     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4115     if (ret != EOK) {
4116         return "Failed to memset_s for ForegroundFilter, ret=" + std::to_string(ret);
4117     }
4118     auto foregroundFilterCache_ = GetForegroundFilterCache();
4119     if (foregroundFilterCache_ && foregroundFilterCache_->IsValid() &&
4120         sprintf_s(buffer, UINT8_MAX, ", ForegroundFilter[%s]", foregroundFilterCache_->GetDescription().c_str()) !=
4121         -1) {
4122         dumpInfo.append(buffer);
4123     }
4124 
4125     // Outline
4126     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4127     if (ret != EOK) {
4128         return "Failed to memset_s for Outline, ret=" + std::to_string(ret);
4129     }
4130     if (outline_ && outline_->HasBorder() &&
4131         sprintf_s(buffer, UINT8_MAX, ", Outline[%s]", outline_->ToString().c_str()) != -1) {
4132         dumpInfo.append(buffer);
4133     }
4134 
4135     // ShadowColor
4136     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4137     if (ret != EOK) {
4138         return "Failed to memset_s for ShadowColor, ret=" + std::to_string(ret);
4139     }
4140     if (!ROSEN_EQ(GetShadowColor(), Color(DEFAULT_SPOT_COLOR)) &&
4141         sprintf_s(buffer, UINT8_MAX, ", ShadowColor[#%08X]", GetShadowColor().AsArgbInt()) != -1) {
4142         dumpInfo.append(buffer);
4143     }
4144 
4145     // ShadowOffsetX
4146     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4147     if (ret != EOK) {
4148         return "Failed to memset_s for ShadowOffsetX, ret=" + std::to_string(ret);
4149     }
4150     if (!ROSEN_EQ(GetShadowOffsetX(), DEFAULT_SHADOW_OFFSET_X) &&
4151         sprintf_s(buffer, UINT8_MAX, ", ShadowOffsetX[%.1f]", GetShadowOffsetX()) != -1) {
4152         dumpInfo.append(buffer);
4153     }
4154 
4155     // ShadowOffsetY
4156     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4157     if (ret != EOK) {
4158         return "Failed to memset_s for ShadowOffsetY, ret=" + std::to_string(ret);
4159     }
4160     if (!ROSEN_EQ(GetShadowOffsetY(), DEFAULT_SHADOW_OFFSET_Y) &&
4161         sprintf_s(buffer, UINT8_MAX, ", ShadowOffsetY[%.1f]", GetShadowOffsetY()) != -1) {
4162         dumpInfo.append(buffer);
4163     }
4164 
4165     // ShadowAlpha
4166     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4167     if (ret != EOK) {
4168         return "Failed to memset_s for ShadowAlpha, ret=" + std::to_string(ret);
4169     }
4170     if (!ROSEN_EQ(GetShadowAlpha(), 0.f) &&
4171         sprintf_s(buffer, UINT8_MAX, ", ShadowAlpha[%.1f]", GetShadowAlpha()) != -1) {
4172         dumpInfo.append(buffer);
4173     }
4174 
4175     // ShadowElevation
4176     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4177     if (ret != EOK) {
4178         return "Failed to memset_s for ShadowElevation, ret=" + std::to_string(ret);
4179     }
4180     if (!ROSEN_EQ(GetShadowElevation(), 0.f) &&
4181         sprintf_s(buffer, UINT8_MAX, ", ShadowElevation[%.1f]", GetShadowElevation()) != -1) {
4182         dumpInfo.append(buffer);
4183     }
4184 
4185     // ShadowRadius
4186     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4187     if (ret != EOK) {
4188         return "Failed to memset_s for ShadowRadius, ret=" + std::to_string(ret);
4189     }
4190     if (!ROSEN_EQ(GetShadowRadius(), 0.f) &&
4191         sprintf_s(buffer, UINT8_MAX, ", ShadowRadius[%.1f]", GetShadowRadius()) != -1) {
4192         dumpInfo.append(buffer);
4193     }
4194 
4195     // ShadowIsFilled
4196     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4197     if (ret != EOK) {
4198         return "Failed to memset_s for ShadowIsFilled, ret=" + std::to_string(ret);
4199     }
4200     if (!ROSEN_EQ(GetShadowIsFilled(), false) &&
4201         sprintf_s(buffer, UINT8_MAX, ", ShadowIsFilled[%d]", GetShadowIsFilled()) != -1) {
4202         dumpInfo.append(buffer);
4203     }
4204 
4205     // FrameGravity
4206     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4207     if (ret != EOK) {
4208         return "Failed to memset_s for FrameGravity, ret=" + std::to_string(ret);
4209     }
4210     if (!ROSEN_EQ(GetFrameGravity(), Gravity::DEFAULT) &&
4211         sprintf_s(buffer, UINT8_MAX, ", FrameGravity[%d]", GetFrameGravity()) != -1) {
4212         dumpInfo.append(buffer);
4213     }
4214 
4215     // IsVisible
4216     if (!GetVisible()) {
4217         dumpInfo.append(", IsVisible[false]");
4218     }
4219 
4220     // UseEffect
4221     if (GetUseEffect()) {
4222         dumpInfo.append(", GetUseEffect[true]");
4223     }
4224     if (GetAlwaysSnapshot()) {
4225         dumpInfo.append(", AlwaysSnapshot[true]");
4226     }
4227 
4228     // Gray Scale
4229     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4230     if (ret != EOK) {
4231         return "Failed to memset_s for GrayScale, ret=" + std::to_string(ret);
4232     }
4233     auto grayScale = GetGrayScale();
4234     if (grayScale.has_value() && !ROSEN_EQ(*grayScale, 0.f) &&
4235         sprintf_s(buffer, UINT8_MAX, ", GrayScale[%.1f]", *grayScale) != -1) {
4236         dumpInfo.append(buffer);
4237     }
4238 
4239     // DynamicLightUpRate
4240     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4241     if (ret != EOK) {
4242         return "Failed to memset_s for DynamicLightUpRate, ret=" + std::to_string(ret);
4243     }
4244     auto dynamicLightUpRate = GetDynamicLightUpRate();
4245     if (dynamicLightUpRate.has_value() && !ROSEN_EQ(*dynamicLightUpRate, 0.f) &&
4246         sprintf_s(buffer, UINT8_MAX, ", DynamicLightUpRate[%.1f]", *dynamicLightUpRate) != -1) {
4247         dumpInfo.append(buffer);
4248     }
4249 
4250     // DynamicLightUpDegree
4251     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4252     if (ret != EOK) {
4253         return "Failed to memset_s for DynamicLightUpDegree, ret=" + std::to_string(ret);
4254     }
4255     auto dynamicLightUpDegree = GetDynamicLightUpDegree();
4256     if (dynamicLightUpDegree.has_value() && !ROSEN_EQ(*dynamicLightUpDegree, 0.f) &&
4257         sprintf_s(buffer, UINT8_MAX, ", DynamicLightUpDegree[%.1f]", *dynamicLightUpDegree) != -1) {
4258         dumpInfo.append(buffer);
4259     }
4260 
4261     // Brightness
4262     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4263     if (ret != EOK) {
4264         return "Failed to memset_s for Brightness, ret=" + std::to_string(ret);
4265     }
4266     auto brightness = GetBrightness();
4267     if (brightness.has_value() && !ROSEN_EQ(*brightness, 1.f) &&
4268         sprintf_s(buffer, UINT8_MAX, ", Brightness[%.1f]", *brightness) != -1) {
4269         dumpInfo.append(buffer);
4270     }
4271 
4272     // Contrast
4273     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4274     if (ret != EOK) {
4275         return "Failed to memset_s for Contrast, ret=" + std::to_string(ret);
4276     }
4277     auto contrast = GetContrast();
4278     if (contrast.has_value() && !ROSEN_EQ(*contrast, 1.f) &&
4279         sprintf_s(buffer, UINT8_MAX, ", Contrast[%.1f]", *contrast) != -1) {
4280         dumpInfo.append(buffer);
4281     }
4282 
4283     // Saturate
4284     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4285     if (ret != EOK) {
4286         return "Failed to memset_s for Saturate, ret=" + std::to_string(ret);
4287     }
4288     auto saturate = GetSaturate();
4289     if (saturate.has_value() && !ROSEN_EQ(*saturate, 1.f) &&
4290         sprintf_s(buffer, UINT8_MAX, ", Saturate[%.1f]", *saturate) != -1) {
4291         dumpInfo.append(buffer);
4292     }
4293 
4294     // Sepia
4295     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4296     if (ret != EOK) {
4297         return "Failed to memset_s for Sepia, ret=" + std::to_string(ret);
4298     }
4299     auto sepia = GetSepia();
4300     if (sepia.has_value() && !ROSEN_EQ(*sepia, 0.f) &&
4301         sprintf_s(buffer, UINT8_MAX, ", Sepia[%.1f]", *sepia) != -1) {
4302         dumpInfo.append(buffer);
4303     }
4304 
4305     // Invert
4306     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4307     if (ret != EOK) {
4308         return "Failed to memset_s for Invert, ret=" + std::to_string(ret);
4309     }
4310     auto invert = GetInvert();
4311     if (invert.has_value() && !ROSEN_EQ(*invert, 0.f) &&
4312         sprintf_s(buffer, UINT8_MAX, ", Invert[%.1f]", *invert) != -1) {
4313         dumpInfo.append(buffer);
4314     }
4315 
4316     // Hue Rotate
4317     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4318     if (ret != EOK) {
4319         return "Failed to memset_s for HueRotate, ret=" + std::to_string(ret);
4320     }
4321     auto hueRotate = GetHueRotate();
4322     if (hueRotate.has_value() && !ROSEN_EQ(*hueRotate, 0.f) &&
4323         sprintf_s(buffer, UINT8_MAX, ", HueRotate[%.1f]", *hueRotate) != -1) {
4324         dumpInfo.append(buffer);
4325     }
4326 
4327     // Color Blend
4328     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4329     if (ret != EOK) {
4330         return "Failed to memset_s for ColorBlend, ret=" + std::to_string(ret);
4331     }
4332     auto colorBlend = GetColorBlend();
4333     if (colorBlend.has_value() && !ROSEN_EQ(*colorBlend, RgbPalette::Transparent()) &&
4334         sprintf_s(buffer, UINT8_MAX, ", ColorBlend[#%08X]", colorBlend->AsArgbInt()) != -1) {
4335         dumpInfo.append(buffer);
4336     }
4337 
4338     return dumpInfo;
4339 }
4340 
4341 // planning: need to delete, cachemanager moved to filter drawable
4342 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
CreateFilterCacheManagerIfNeed()4343 void RSProperties::CreateFilterCacheManagerIfNeed()
4344 {
4345     if (!filterCacheEnabled_) {
4346         return;
4347     }
4348     if (auto& filter = GetBackgroundFilter()) {
4349         auto& cacheManager = backgroundFilterCacheManager_;
4350         if (cacheManager == nullptr) {
4351             cacheManager = std::make_unique<RSFilterCacheManager>();
4352         }
4353         cacheManager->UpdateCacheStateWithFilterHash(filter);
4354     } else {
4355         backgroundFilterCacheManager_.reset();
4356     }
4357     if (auto& filter = GetFilter()) {
4358         auto& cacheManager = foregroundFilterCacheManager_;
4359         if (cacheManager == nullptr) {
4360             cacheManager = std::make_unique<RSFilterCacheManager>();
4361         }
4362         cacheManager->UpdateCacheStateWithFilterHash(filter);
4363     } else {
4364         foregroundFilterCacheManager_.reset();
4365     }
4366 }
4367 
GetFilterCacheManager(bool isForeground) const4368 const std::unique_ptr<RSFilterCacheManager>& RSProperties::GetFilterCacheManager(bool isForeground) const
4369 {
4370     return isForeground ? foregroundFilterCacheManager_ : backgroundFilterCacheManager_;
4371 }
4372 
ClearFilterCache()4373 void RSProperties::ClearFilterCache()
4374 {
4375     if (foregroundFilterCacheManager_ != nullptr) {
4376         foregroundFilterCacheManager_->ReleaseCacheOffTree();
4377     }
4378     if (backgroundFilterCacheManager_ != nullptr) {
4379         backgroundFilterCacheManager_->ReleaseCacheOffTree();
4380     }
4381     if (backgroundFilter_ != nullptr) {
4382         auto drawingFilter = std::static_pointer_cast<RSDrawingFilter>(backgroundFilter_);
4383         auto rsShaderFilter = drawingFilter->GetShaderFilterWithType(RSUIFilterType::MASK_COLOR);
4384         if (rsShaderFilter != nullptr) {
4385             auto maskColorShaderFilter = std::static_pointer_cast<RSMaskColorShaderFilter>(rsShaderFilter);
4386         }
4387     }
4388     if (filter_ != nullptr) {
4389         auto drawingFilter = std::static_pointer_cast<RSDrawingFilter>(filter_);
4390         auto rsShaderFilter = drawingFilter->GetShaderFilterWithType(RSUIFilterType::MASK_COLOR);
4391         if (rsShaderFilter != nullptr) {
4392             auto maskColorShaderFilter = std::static_pointer_cast<RSMaskColorShaderFilter>(rsShaderFilter);
4393         }
4394     }
4395 }
4396 #endif
4397 
OnApplyModifiers()4398 void RSProperties::OnApplyModifiers()
4399 {
4400     if (geoDirty_) {
4401         if (!hasBounds_) {
4402             CheckEmptyBounds();
4403         } else {
4404             CalculateFrameOffset();
4405         }
4406         // frame and bounds are the same, no need to clip twice
4407         if (clipToFrame_ && clipToBounds_ && frameOffsetX_ == 0 && frameOffsetY_ == 0) {
4408             clipToFrame_ = false;
4409         }
4410         // planning: temporary fix to calculate relative matrix in OnApplyModifiers, later RSRenderNode::Update will
4411         // overwrite it.
4412         boundsGeo_->UpdateByMatrixFromSelf();
4413     }
4414     if (colorFilterNeedUpdate_) {
4415         GenerateColorFilter();
4416         if (colorFilter_ != nullptr) {
4417             needFilter_ = true;
4418             needHwcFilter_ = true;
4419         } else {
4420             // colorFilter generation failed, need to update needFilter
4421             filterNeedUpdate_ = true;
4422         }
4423     }
4424     if (pixelStretchNeedUpdate_ || geoDirty_) {
4425         CalculatePixelStretch();
4426     }
4427 
4428     if (bgShaderNeedUpdate_) {
4429         UpdateBackgroundShader();
4430     }
4431 
4432     if (greyCoefNeedUpdate_) {
4433         CheckGreyCoef();
4434         greyCoefNeedUpdate_ = false;
4435         filterNeedUpdate_ = true;
4436     }
4437     GenerateRRect();
4438     if (filterNeedUpdate_) {
4439         UpdateFilter();
4440     }
4441 }
4442 
UpdateFilter()4443 void RSProperties::UpdateFilter()
4444 {
4445     filterNeedUpdate_ = false;
4446     GenerateBackgroundFilter();
4447     GenerateForegroundFilter();
4448     if (GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE) {
4449         filterNeedUpdate_ = true;
4450     }
4451     if (backgroundFilter_ != nullptr && !backgroundFilter_->IsValid()) {
4452         backgroundFilter_.reset();
4453     }
4454     if (filter_ != nullptr && !filter_->IsValid()) {
4455         filter_.reset();
4456     }
4457 
4458     if (FOREGROUND_FILTER_ENABLED) {
4459         UpdateForegroundFilter();
4460     }
4461 
4462     needFilter_ = backgroundFilter_ != nullptr || filter_ != nullptr || useEffect_ ||
4463                   IsLightUpEffectValid() || IsDynamicLightUpValid() || greyCoef_.has_value() ||
4464                   linearGradientBlurPara_ != nullptr || IsDynamicDimValid() ||
4465                   GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE ||
4466                   foregroundFilter_ != nullptr || IsFgBrightnessValid() || IsBgBrightnessValid() ||
4467                   foregroundFilterCache_ != nullptr || IsWaterRippleValid() || needDrawBehindWindow_ || mask_ ||
4468                   colorFilter_ != nullptr || localMagnificationCap_;
4469 
4470     needHwcFilter_ = backgroundFilter_ != nullptr || filter_ != nullptr || IsLightUpEffectValid() ||
4471                      IsDynamicLightUpValid() || linearGradientBlurPara_ != nullptr ||
4472                      IsDynamicDimValid() || IsFgBrightnessValid() || IsBgBrightnessValid() || IsWaterRippleValid() ||
4473                      needDrawBehindWindow_ || colorFilter_ != nullptr || localMagnificationCap_;
4474 #ifdef SUBTREE_PARALLEL_ENABLE
4475     // needForceSubmit_ is used to determine whether the subtree needs to read/scale pixels
4476     needForceSubmit_ = IsFilterNeedForceSubmit(filter_) ||
4477                        IsFilterNeedForceSubmit(backgroundFilter_) ||
4478                        IsFilterNeedForceSubmit(foregroundFilter_) ||
4479                        IsFilterNeedForceSubmit(foregroundFilterCache_) ||
4480                        GetShadowColotStratergy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE;
4481 #endif
4482 }
4483 
UpdateForegroundFilter()4484 void RSProperties::UpdateForegroundFilter()
4485 {
4486     foregroundFilter_.reset();
4487     foregroundFilterCache_.reset();
4488     if (motionBlurPara_ && ROSEN_GNE(motionBlurPara_->radius, 0.0)) {
4489         auto motionBlurFilter = std::make_shared<RSMotionBlurFilter>(motionBlurPara_);
4490         if (IS_UNI_RENDER) {
4491             foregroundFilterCache_ = motionBlurFilter;
4492         } else {
4493             foregroundFilter_ = motionBlurFilter;
4494         }
4495     } else if (IsForegroundEffectRadiusValid()) {
4496         auto foregroundEffectFilter = std::make_shared<RSForegroundEffectFilter>(foregroundEffectRadius_);
4497         if (IS_UNI_RENDER) {
4498             foregroundFilterCache_ = foregroundEffectFilter;
4499         } else {
4500             foregroundFilter_ = foregroundEffectFilter;
4501         }
4502     } else if (IsSpherizeValid()) {
4503         CreateSphereEffectFilter();
4504     } else if (IsFlyOutValid()) {
4505         CreateFlyOutShaderFilter();
4506     } else if (IsAttractionValid()) {
4507         CreateAttractionEffectFilter();
4508     } else if (IsShadowMaskValid()) {
4509         float elevation = GetShadowElevation();
4510         Drawing::scalar n1 = 0.25f * elevation * (1 + elevation / 128.0f); // 0.25f 128.0f
4511         Drawing::scalar blurRadius = elevation > 0.0f ? n1 : GetShadowRadius();
4512         auto colorfulShadowFilter =
4513             std::make_shared<RSColorfulShadowFilter>(blurRadius, GetShadowOffsetX(), GetShadowOffsetY());
4514         if (GetShadowMask() == SHADOW_MASK_STRATEGY::MASK_COLOR_BLUR) {
4515             colorfulShadowFilter->SetShadowColorMask(GetShadowColor());
4516         }
4517         if (IS_UNI_RENDER) {
4518             foregroundFilterCache_ = colorfulShadowFilter;
4519         } else {
4520             foregroundFilter_ = colorfulShadowFilter;
4521         }
4522     } else if (IsDistortionKValid()) {
4523         foregroundFilter_ = std::make_shared<RSDistortionFilter>(*distortionK_);
4524     } else if (IsHDRUIBrightnessValid()) {
4525         CreateHDRUIBrightnessFilter();
4526     } else if (fgNGRenderFilter_) {
4527         ComposeNGRenderFilter(foregroundFilter_, fgNGRenderFilter_);
4528     }
4529 }
4530 
UpdateBackgroundShader()4531 void RSProperties::UpdateBackgroundShader()
4532 {
4533     bgShaderNeedUpdate_ = false;
4534     const auto& bgShader = GetBackgroundShader();
4535     if (bgShader) {
4536         const auto &param = GetComplexShaderParam();
4537         if (param.has_value()) {
4538             const auto & paramValue = param.value();
4539             bgShader->MakeDrawingShader(GetBoundsRect(), paramValue);
4540         }
4541         bgShader->MakeDrawingShader(GetBoundsRect(), GetBackgroundShaderProgress());
4542     }
4543     if (bgNGRenderShader_ && bgNGRenderShader_->ContainsType(RSNGEffectType::BORDER_LIGHT)) {
4544         Vector3f rotationAngle(boundsGeo_->GetRotationX(), boundsGeo_->GetRotationY(), boundsGeo_->GetRotation());
4545         float cornerRadius = GetCornerRadius().x_;
4546         RSNGRenderShaderHelper::SetRotationAngle(bgNGRenderShader_, rotationAngle);
4547         RSNGRenderShaderHelper::SetCornerRadius(bgNGRenderShader_, cornerRadius);
4548     }
4549 }
4550 
CalculatePixelStretch()4551 void RSProperties::CalculatePixelStretch()
4552 {
4553     pixelStretchNeedUpdate_ = false;
4554     // no pixel stretch
4555     if (!pixelStretch_.has_value() && !pixelStretchPercent_.has_value()) {
4556         return;
4557     }
4558     // convert pixel stretch percent to pixel stretch
4559     if (pixelStretchPercent_) {
4560         auto width = GetBoundsWidth();
4561         auto height = GetBoundsHeight();
4562         if (isinf(width) || isinf(height)) {
4563             return;
4564         }
4565         pixelStretch_ = *pixelStretchPercent_ * Vector4f(width, height, width, height);
4566     }
4567     constexpr static float EPS = 1e-5f;
4568     // parameter check: near zero
4569     if (abs(pixelStretch_->x_) < EPS && abs(pixelStretch_->y_) < EPS && abs(pixelStretch_->z_) < EPS &&
4570         abs(pixelStretch_->w_) < EPS) {
4571         pixelStretch_ = std::nullopt;
4572         return;
4573     }
4574     // parameter check: all >= 0 or all <= 0
4575     if ((pixelStretch_->x_ < EPS && pixelStretch_->y_ < EPS && pixelStretch_->z_ < EPS && pixelStretch_->w_ < EPS) ||
4576         (pixelStretch_->x_ > -EPS && pixelStretch_->y_ > -EPS && pixelStretch_->z_ > -EPS &&
4577             pixelStretch_->w_ > -EPS)) {
4578         isDrawn_ = true;
4579         return;
4580     }
4581     pixelStretch_ = std::nullopt;
4582 }
4583 
NeedBlurFuzed()4584 bool RSProperties::NeedBlurFuzed()
4585 {
4586     if (RSSystemProperties::GetMESABlurFuzedEnabled() && greyCoef_.has_value()) {
4587         return true;
4588     }
4589     return false;
4590 }
4591 
CalculateFrameOffset()4592 void RSProperties::CalculateFrameOffset()
4593 {
4594     frameOffsetX_ = frameGeo_.GetX() - boundsGeo_->GetX();
4595     frameOffsetY_ = frameGeo_.GetY() - boundsGeo_->GetY();
4596     if (isinf(frameOffsetX_)) {
4597         frameOffsetX_ = 0.f;
4598     }
4599     if (isinf(frameOffsetY_)) {
4600         frameOffsetY_ = 0.f;
4601     }
4602     if (frameOffsetX_ != 0.f || frameOffsetY_ != 0.f) {
4603         isDrawn_ = true;
4604     }
4605 }
4606 
CheckGreyCoef()4607 void RSProperties::CheckGreyCoef()
4608 {
4609     if (!greyCoef_.has_value()) {
4610         return;
4611     }
4612     // 127.0 half of 255.0
4613     if (ROSEN_LNE(greyCoef_->x_, 0.f) || ROSEN_GNE(greyCoef_->x_, 127.f) ||
4614         ROSEN_LNE(greyCoef_->y_, 0.f) || ROSEN_GNE(greyCoef_->y_, 127.f) ||
4615         (ROSEN_EQ(greyCoef_->x_, 0.f) && ROSEN_EQ(greyCoef_->y_, 0.f))) {
4616         greyCoef_ = std::nullopt;
4617     }
4618 }
4619 
4620 // blend with background
SetColorBlendMode(int colorBlendMode)4621 void RSProperties::SetColorBlendMode(int colorBlendMode)
4622 {
4623     colorBlendMode_ = std::clamp<int>(colorBlendMode, 0, static_cast<int>(RSColorBlendMode::MAX));
4624     if (colorBlendMode_ != static_cast<int>(RSColorBlendMode::NONE)) {
4625         isDrawn_ = true;
4626     }
4627     SetDirty();
4628     contentDirty_ = true;
4629 }
4630 
SetColorBlendApplyType(int colorBlendApplyType)4631 void RSProperties::SetColorBlendApplyType(int colorBlendApplyType)
4632 {
4633     colorBlendApplyType_ = std::clamp<int>(colorBlendApplyType, 0, static_cast<int>(RSColorBlendApplyType::MAX));
4634     isDrawn_ = true;
4635     SetDirty();
4636     contentDirty_ = true;
4637 }
4638 
GetHaveEffectRegion() const4639 bool RSProperties::GetHaveEffectRegion() const
4640 {
4641     return haveEffectRegion_;
4642 }
4643 
SetHaveEffectRegion(bool haveEffectRegion)4644 void RSProperties::SetHaveEffectRegion(bool haveEffectRegion)
4645 {
4646 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
4647     // clear cache if new region is null or outside current region
4648     if (auto& manager = GetFilterCacheManager(false);
4649         manager && manager->IsCacheValid() && haveEffectRegion == false) {
4650         manager->UpdateCacheStateWithFilterRegion();
4651     }
4652 #endif
4653     haveEffectRegion_ = haveEffectRegion;
4654 }
4655 
ResetBorder(bool isOutline)4656 void RSProperties::ResetBorder(bool isOutline)
4657 {
4658     if (isOutline) {
4659         outline_ = nullptr;
4660     } else {
4661         border_ = nullptr;
4662     }
4663     SetDirty();
4664     contentDirty_ = true;
4665 }
4666 
SetBackgroundNGShader(const std::shared_ptr<RSNGRenderShaderBase> & renderShader)4667 void RSProperties::SetBackgroundNGShader(const std::shared_ptr<RSNGRenderShaderBase>& renderShader)
4668 {
4669     bgNGRenderShader_ = renderShader;
4670     isDrawn_ = true;
4671     SetDirty();
4672     contentDirty_ = true;
4673 }
4674 
GetBackgroundNGShader() const4675 std::shared_ptr<RSNGRenderShaderBase> RSProperties::GetBackgroundNGShader() const
4676 {
4677     return bgNGRenderShader_;
4678 }
4679 
SetForegroundShader(const std::shared_ptr<RSNGRenderShaderBase> & renderShader)4680 void RSProperties::SetForegroundShader(const std::shared_ptr<RSNGRenderShaderBase>& renderShader)
4681 {
4682     fgRenderShader_ = renderShader;
4683     isDrawn_ = true;
4684     SetDirty();
4685     contentDirty_ = true;
4686 }
4687 
GetForegroundShader() const4688 std::shared_ptr<RSNGRenderShaderBase> RSProperties::GetForegroundShader() const
4689 {
4690     return fgRenderShader_;
4691 }
4692 
4693 } // namespace Rosen
4694 } // namespace OHOS
4695