• 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 <securec.h>
20 
21 #include "animation/rs_render_particle_animation.h"
22 #include "common/rs_common_def.h"
23 #include "common/rs_obj_abs_geometry.h"
24 #include "render/rs_mesa_blur_shader_filter.h"
25 #include "common/rs_vector4.h"
26 #include "pipeline/rs_uni_render_judgement.h"
27 #include "platform/common/rs_log.h"
28 #include "platform/common/rs_system_properties.h"
29 #include "property/rs_point_light_manager.h"
30 #include "property/rs_properties_def.h"
31 #include "render/rs_aibar_shader_filter.h"
32 #include "render/rs_colorful_shadow_filter.h"
33 #include "render/rs_filter.h"
34 #include "render/rs_foreground_effect_filter.h"
35 #include "render/rs_grey_shader_filter.h"
36 #include "render/rs_kawase_blur_shader_filter.h"
37 #include "render/rs_linear_gradient_blur_shader_filter.h"
38 #include "render/rs_magnifier_shader_filter.h"
39 #include "render/rs_maskcolor_shader_filter.h"
40 #include "render/rs_spherize_effect_filter.h"
41 #include "src/core/SkOpts.h"
42 #include "render/rs_water_ripple_shader_filter.h"
43 #include "render/rs_fly_out_shader_filter.h"
44 #include "render/rs_distortion_shader_filter.h"
45 
46 namespace OHOS {
47 namespace Rosen {
48 namespace {
49 constexpr int32_t INDEX_2 = 2;
50 constexpr int32_t INDEX_4 = 4;
51 constexpr int32_t INDEX_5 = 5;
52 constexpr int32_t INDEX_6 = 6;
53 constexpr int32_t INDEX_7 = 7;
54 constexpr int32_t INDEX_9 = 9;
55 constexpr int32_t INDEX_10 = 10;
56 constexpr int32_t INDEX_11 = 11;
57 constexpr int32_t INDEX_12 = 12;
58 constexpr int32_t INDEX_14 = 14;
59 constexpr int32_t INDEX_18 = 18;
60 
61 const Vector4f Vector4fZero { 0.f, 0.f, 0.f, 0.f };
62 const auto EMPTY_RECT = RectF();
63 constexpr float SPHERIZE_VALID_EPSILON = 0.001f; // used to judge if spherize valid
64 constexpr uint8_t BORDER_TYPE_NONE = (uint32_t)BorderStyle::NONE;
65 constexpr int BORDER_NUM = 4;
66 constexpr int16_t BORDER_TRANSPARENT = 255;
67 
68 using ResetPropertyFunc = void (*)(RSProperties* prop);
69 // Every modifier before RSModifierType::CUSTOM is property modifier, and it should have a ResetPropertyFunc
70 // NOTE: alway add new resetter when adding new property modifier
71 constexpr static std::array<ResetPropertyFunc, static_cast<int>(RSModifierType::CUSTOM)> g_propertyResetterLUT = {
72     nullptr,                                                             // INVALID
73     nullptr,                                                             // BOUNDS
74     nullptr,                                                             // FRAME
__anon0d1045820202() 75     [](RSProperties* prop) { prop->SetPositionZ(0.f); },                 // POSITION_Z
__anon0d1045820302() 76     [](RSProperties* prop) { prop->SetPivot(Vector2f(0.5f, 0.5f)); },    // PIVOT
__anon0d1045820402() 77     [](RSProperties* prop) { prop->SetPivotZ(0.f); },                    // PIVOT_Z
__anon0d1045820502() 78     [](RSProperties* prop) { prop->SetQuaternion(Quaternion()); },       // QUATERNION
__anon0d1045820602() 79     [](RSProperties* prop) { prop->SetRotation(0.f); },                  // ROTATION
__anon0d1045820702() 80     [](RSProperties* prop) { prop->SetRotationX(0.f); },                 // ROTATION_X
__anon0d1045820802() 81     [](RSProperties* prop) { prop->SetRotationY(0.f); },                 // ROTATION_Y
__anon0d1045820902() 82     [](RSProperties* prop) { prop->SetCameraDistance(0.f); },            // CAMERA_DISTANCE
__anon0d1045820a02() 83     [](RSProperties* prop) { prop->SetScale(Vector2f(1.f, 1.f)); },      // SCALE
__anon0d1045820b02() 84     [](RSProperties* prop) { prop->SetSkew(Vector2f(0.f, 0.f)); },       // SKEW
__anon0d1045820c02() 85     [](RSProperties* prop) { prop->SetPersp(Vector2f(0.f, 0.f)); },      // PERSP
__anon0d1045820d02() 86     [](RSProperties* prop) { prop->SetTranslate(Vector2f(0.f, 0.f)); },  // TRANSLATE
__anon0d1045820e02() 87     [](RSProperties* prop) { prop->SetTranslateZ(0.f); },                // TRANSLATE_Z
__anon0d1045820f02() 88     [](RSProperties* prop) { prop->SetSublayerTransform({}); },          // SUBLAYER_TRANSFORM
__anon0d1045821002() 89     [](RSProperties* prop) { prop->SetCornerRadius(0.f); },              // CORNER_RADIUS
__anon0d1045821102() 90     [](RSProperties* prop) { prop->SetAlpha(1.f); },                     // ALPHA
__anon0d1045821202() 91     [](RSProperties* prop) { prop->SetAlphaOffscreen(false); },          // ALPHA_OFFSCREEN
__anon0d1045821302() 92     [](RSProperties* prop) { prop->SetForegroundColor({}); },            // FOREGROUND_COLOR
__anon0d1045821402() 93     [](RSProperties* prop) { prop->SetBackgroundColor({}); },            // BACKGROUND_COLOR
__anon0d1045821502() 94     [](RSProperties* prop) { prop->SetBackgroundShader({}); },           // BACKGROUND_SHADER
__anon0d1045821602() 95     [](RSProperties* prop) { prop->SetBgImage({}); },                    // BG_IMAGE
__anon0d1045821702() 96     [](RSProperties* prop) { prop->SetBgImageInnerRect({}); },           // Bg_Image_Inner_Rect
__anon0d1045821802() 97     [](RSProperties* prop) { prop->SetBgImageWidth(0.f); },              // BG_IMAGE_WIDTH
__anon0d1045821902() 98     [](RSProperties* prop) { prop->SetBgImageHeight(0.f); },             // BG_IMAGE_HEIGHT
__anon0d1045821a02() 99     [](RSProperties* prop) { prop->SetBgImagePositionX(0.f); },          // BG_IMAGE_POSITION_X
__anon0d1045821b02() 100     [](RSProperties* prop) { prop->SetBgImagePositionY(0.f); },          // BG_IMAGE_POSITION_Y
101     nullptr,                                                             // SURFACE_BG_COLOR
__anon0d1045821c02() 102     [](RSProperties* prop) { prop->SetBorderColor(RSColor()); },         // BORDER_COLOR
__anon0d1045821d02() 103     [](RSProperties* prop) { prop->SetBorderWidth(0.f); },               // BORDER_WIDTH
__anon0d1045821e02() 104     [](RSProperties* prop) { prop->SetBorderStyle(BORDER_TYPE_NONE); },  // BORDER_STYLE
__anon0d1045821f02() 105     [](RSProperties* prop) { prop->SetBorderDashWidth({-1.f}); },        // BORDER_DASH_WIDTH
__anon0d1045822002() 106     [](RSProperties* prop) { prop->SetBorderDashGap({-1.f}); },          // BORDER_DASH_GAP
__anon0d1045822102() 107     [](RSProperties* prop) { prop->SetFilter({}); },                     // FILTER
__anon0d1045822202() 108     [](RSProperties* prop) { prop->SetBackgroundFilter({}); },           // BACKGROUND_FILTER
__anon0d1045822302() 109     [](RSProperties* prop) { prop->SetLinearGradientBlurPara({}); },     // LINEAR_GRADIENT_BLUR_PARA
__anon0d1045822402() 110     [](RSProperties* prop) { prop->SetDynamicLightUpRate({}); },         // DYNAMIC_LIGHT_UP_RATE
__anon0d1045822502() 111     [](RSProperties* prop) { prop->SetDynamicLightUpDegree({}); },       // DYNAMIC_LIGHT_UP_DEGREE
__anon0d1045822602() 112     [](RSProperties* prop) { prop->SetFgBrightnessRates({}); },          // FG_BRIGHTNESS_PARAMS
__anon0d1045822702() 113     [](RSProperties* prop) { prop->SetFgBrightnessSaturation(0.0); },     // FG_BRIGHTNESS_PARAMS
__anon0d1045822802() 114     [](RSProperties* prop) { prop->SetFgBrightnessPosCoeff({}); },       // FG_BRIGHTNESS_PARAMS
__anon0d1045822902() 115     [](RSProperties* prop) { prop->SetFgBrightnessNegCoeff({}); },       // FG_BRIGHTNESS_PARAMS
__anon0d1045822a02() 116     [](RSProperties* prop) { prop->SetFgBrightnessFract({}); },          // FG_BRIGHTNESS_FRACTION
__anon0d1045822b02() 117     [](RSProperties* prop) { prop->SetBgBrightnessRates({}); },          // BG_BRIGHTNESS_PARAMS
__anon0d1045822c02() 118     [](RSProperties* prop) { prop->SetBgBrightnessSaturation(0.0); },     // BG_BRIGHTNESS_PARAMS
__anon0d1045822d02() 119     [](RSProperties* prop) { prop->SetBgBrightnessPosCoeff({}); },       // BG_BRIGHTNESS_PARAMS
__anon0d1045822e02() 120     [](RSProperties* prop) { prop->SetBgBrightnessNegCoeff({}); },       // BG_BRIGHTNESS_PARAMS
__anon0d1045822f02() 121     [](RSProperties* prop) { prop->SetBgBrightnessFract(1.0); },          // BG_BRIGHTNESS_FRACTION
__anon0d1045823002() 122     [](RSProperties* prop) { prop->SetFrameGravity(Gravity::DEFAULT); }, // FRAME_GRAVITY
__anon0d1045823102() 123     [](RSProperties* prop) { prop->SetClipRRect({}); },                  // CLIP_RRECT
__anon0d1045823202() 124     [](RSProperties* prop) { prop->SetClipBounds({}); },                 // CLIP_BOUNDS
__anon0d1045823302() 125     [](RSProperties* prop) { prop->SetClipToBounds(false); },            // CLIP_TO_BOUNDS
__anon0d1045823402() 126     [](RSProperties* prop) { prop->SetClipToFrame(false); },             // CLIP_TO_FRAME
__anon0d1045823502() 127     [](RSProperties* prop) { prop->SetVisible(true); },                  // VISIBLE
__anon0d1045823602() 128     [](RSProperties* prop) { prop->SetShadowColor({}); },                // SHADOW_COLOR
__anon0d1045823702() 129     [](RSProperties* prop) { prop->SetShadowOffsetX(0.f); },             // SHADOW_OFFSET_X
__anon0d1045823802() 130     [](RSProperties* prop) { prop->SetShadowOffsetY(0.f); },             // SHADOW_OFFSET_Y
__anon0d1045823902() 131     [](RSProperties* prop) { prop->SetShadowAlpha(0.f); },               // SHADOW_ALPHA
__anon0d1045823a02() 132     [](RSProperties* prop) { prop->SetShadowElevation(0.f); },           // SHADOW_ELEVATION
__anon0d1045823b02() 133     [](RSProperties* prop) { prop->SetShadowRadius(0.f); },              // SHADOW_RADIUS
__anon0d1045823c02() 134     [](RSProperties* prop) { prop->SetShadowPath({}); },                 // SHADOW_PATH
__anon0d1045823d02() 135     [](RSProperties* prop) { prop->SetShadowMask(false); },              // SHADOW_MASK
__anon0d1045823e02() 136     [](RSProperties* prop) { prop->SetShadowColorStrategy(0); },         // ShadowColorStrategy
__anon0d1045823f02() 137     [](RSProperties* prop) { prop->SetMask({}); },                       // MASK
__anon0d1045824002() 138     [](RSProperties* prop) { prop->SetSpherize(0.f); },                  // SPHERIZE
__anon0d1045824102() 139     [](RSProperties* prop) { prop->SetLightUpEffect(1.f); },             // LIGHT_UP_EFFECT
__anon0d1045824202() 140     [](RSProperties* prop) { prop->SetPixelStretch({}); },               // PIXEL_STRETCH
__anon0d1045824302() 141     [](RSProperties* prop) { prop->SetPixelStretch({});
142                              prop->SetPixelStretchPercent({}); },        // PIXEL_STRETCH_PERCENT
__anon0d1045824402() 143     [](RSProperties* prop) { prop->SetPixelStretchTileMode(0); },        // PIXEL_STRETCH_TILE_MODE
__anon0d1045824502() 144     [](RSProperties* prop) { prop->SetUseEffect(false); },               // USE_EFFECT
__anon0d1045824602() 145     [](RSProperties* prop) { prop->SetColorBlendMode(0); },              // COLOR_BLENDMODE
__anon0d1045824702() 146     [](RSProperties* prop) { prop->SetColorBlendApplyType(0); },         // COLOR_BLENDAPPLY_TYPE
__anon0d1045824802() 147     [](RSProperties* prop) { prop->ResetSandBox(); },                    // SANDBOX
__anon0d1045824902() 148     [](RSProperties* prop) { prop->SetGrayScale({}); },                  // GRAY_SCALE
__anon0d1045824a02() 149     [](RSProperties* prop) { prop->SetBrightness({}); },                 // BRIGHTNESS
__anon0d1045824b02() 150     [](RSProperties* prop) { prop->SetContrast({}); },                   // CONTRAST
__anon0d1045824c02() 151     [](RSProperties* prop) { prop->SetSaturate({}); },                   // SATURATE
__anon0d1045824d02() 152     [](RSProperties* prop) { prop->SetSepia({}); },                      // SEPIA
__anon0d1045824e02() 153     [](RSProperties* prop) { prop->SetInvert({}); },                     // INVERT
__anon0d1045824f02() 154     [](RSProperties* prop) { prop->SetAiInvert({}); },                   // AIINVERT
__anon0d1045825002() 155     [](RSProperties* prop) { prop->SetSystemBarEffect({}); },            // SYSTEMBAREFFECT
__anon0d1045825102() 156     [](RSProperties* prop) { prop->SetWaterRippleProgress(0.0f); },      // WATER_RIPPLE_PROGRESS
__anon0d1045825202() 157     [](RSProperties* prop) { prop->SetWaterRippleParams({}); },          // WATER_RIPPLE_PARAMS
__anon0d1045825302() 158     [](RSProperties* prop) { prop->SetHueRotate({}); },                  // HUE_ROTATE
__anon0d1045825402() 159     [](RSProperties* prop) { prop->SetColorBlend({}); },                 // COLOR_BLEND
__anon0d1045825502() 160     [](RSProperties* prop) { prop->SetParticles({}); },                  // PARTICLE
__anon0d1045825602() 161     [](RSProperties* prop) { prop->SetShadowIsFilled(false); },          // SHADOW_IS_FILLED
__anon0d1045825702() 162     [](RSProperties* prop) { prop->SetOutlineColor(RSColor()); },        // OUTLINE_COLOR
__anon0d1045825802() 163     [](RSProperties* prop) { prop->SetOutlineWidth(0.f); },              // OUTLINE_WIDTH
__anon0d1045825902() 164     [](RSProperties* prop) { prop->SetOutlineStyle(BORDER_TYPE_NONE); }, // OUTLINE_STYLE
__anon0d1045825a02() 165     [](RSProperties* prop) { prop->SetOutlineDashWidth({-1.f}); },       // OUTLINE_DASH_WIDTH
__anon0d1045825b02() 166     [](RSProperties* prop) { prop->SetOutlineDashGap({-1.f}); },         // OUTLINE_DASH_GAP
__anon0d1045825c02() 167     [](RSProperties* prop) { prop->SetOutlineRadius(0.f); },             // OUTLINE_RADIUS
__anon0d1045825d02() 168     [](RSProperties* prop) { prop->SetUseShadowBatching(false); },       // USE_SHADOW_BATCHING
__anon0d1045825e02() 169     [](RSProperties* prop) { prop->SetGreyCoef(std::nullopt); },         // GREY_COEF
__anon0d1045825f02() 170     [](RSProperties* prop) { prop->SetLightIntensity(-1.f); },           // LIGHT_INTENSITY
__anon0d1045826002() 171     [](RSProperties* prop) { prop->SetLightColor({}); },                 // LIGHT_COLOR
__anon0d1045826102() 172     [](RSProperties* prop) { prop->SetLightPosition({}); },              // LIGHT_POSITION
__anon0d1045826202() 173     [](RSProperties* prop) { prop->SetIlluminatedBorderWidth({}); },     // ILLUMINATED_BORDER_WIDTH
__anon0d1045826302() 174     [](RSProperties* prop) { prop->SetIlluminatedType(-1); },            // ILLUMINATED_TYPE
__anon0d1045826402() 175     [](RSProperties* prop) { prop->SetBloom({}); },                      // BLOOM
__anon0d1045826502() 176     [](RSProperties* prop) { prop->SetEmitterUpdater({}); },             // PARTICLE_EMITTER_UPDATER
__anon0d1045826602() 177     [](RSProperties* prop) { prop->SetParticleNoiseFields({}); },         // PARTICLE_NOISE_FIELD
__anon0d1045826702() 178     [](RSProperties* prop) { prop->SetForegroundEffectRadius(0.f); },    // FOREGROUND_EFFECT_RADIUS
__anon0d1045826802() 179     [](RSProperties* prop) { prop->SetMotionBlurPara({}); },             // MOTION_BLUR_PARA
__anon0d1045826902() 180     [](RSProperties* prop) { prop->SetFlyOutDegree(0.0f); },              // FLY_OUT_DEGREE
__anon0d1045826a02() 181     [](RSProperties* prop) { prop->SetFlyOutParams({}); },               // FLY_OUT_PARAMS
__anon0d1045826b02() 182     [](RSProperties* prop) { prop->SetDistortionK(0.0f); },              // DISTORTION_K
__anon0d1045826c02() 183     [](RSProperties* prop) { prop->SetDynamicDimDegree({}); },           // DYNAMIC_LIGHT_UP_DEGREE
__anon0d1045826d02() 184     [](RSProperties* prop) { prop->SetMagnifierParams({}); },            // MAGNIFIER_PARA
__anon0d1045826e02() 185     [](RSProperties* prop) { prop->SetBackgroundBlurRadius(0.f); },      // BACKGROUND_BLUR_RADIUS
__anon0d1045826f02() 186     [](RSProperties* prop) { prop->SetBackgroundBlurSaturation({}); },   // BACKGROUND_BLUR_SATURATION
__anon0d1045827002() 187     [](RSProperties* prop) { prop->SetBackgroundBlurBrightness({}); },   // BACKGROUND_BLUR_BRIGHTNESS
__anon0d1045827102() 188     [](RSProperties* prop) { prop->SetBackgroundBlurMaskColor(RSColor()); }, // BACKGROUND_BLUR_MASKCOLOR
__anon0d1045827202() 189     [](RSProperties* prop) { prop->SetBackgroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT); }, // BACKGROUND_BLUR_COLORMODE
__anon0d1045827302() 190     [](RSProperties* prop) { prop->SetBackgroundBlurRadiusX(0.f); },     // BACKGROUND_BLUR_RADIUS_X
__anon0d1045827402() 191     [](RSProperties* prop) { prop->SetBackgroundBlurRadiusY(0.f); },     // BACKGROUND_BLUR_RADIUS_Y
__anon0d1045827502() 192     [](RSProperties* prop) { prop->SetForegroundBlurRadius(0.f); },      // FOREGROUND_BLUR_RADIUS
__anon0d1045827602() 193     [](RSProperties* prop) { prop->SetForegroundBlurSaturation({}); },   // FOREGROUND_BLUR_SATURATION
__anon0d1045827702() 194     [](RSProperties* prop) { prop->SetForegroundBlurBrightness({}); },   // FOREGROUND_BLUR_BRIGHTNESS
__anon0d1045827802() 195     [](RSProperties* prop) { prop->SetForegroundBlurMaskColor(RSColor()); }, // FOREGROUND_BLUR_MASKCOLOR
__anon0d1045827902() 196     [](RSProperties* prop) { prop->SetForegroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT); }, // FOREGROUND_BLUR_COLORMODE
__anon0d1045827a02() 197     [](RSProperties* prop) { prop->SetForegroundBlurRadiusX(0.f); },     // FOREGROUND_BLUR_RADIUS_X
__anon0d1045827b02() 198     [](RSProperties* prop) { prop->SetForegroundBlurRadiusY(0.f); },     // FOREGROUND_BLUR_RADIUS_Y
199 };
200 
201 // Check if g_propertyResetterLUT size match and is fully initialized (the last element should never be nullptr)
202 static_assert(g_propertyResetterLUT.size() == static_cast<size_t>(RSModifierType::CUSTOM));
203 static_assert(g_propertyResetterLUT.back() != nullptr);
204 } // namespace
205 
206 // Only enable filter cache when uni-render is enabled and filter cache is enabled
207 
208 #if defined(NEW_SKIA) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
209 #ifndef ROSEN_ARKUI_X
210 const bool RSProperties::FilterCacheEnabled =
211     RSSystemProperties::GetFilterCacheEnabled() && RSUniRenderJudgement::IsUniRender();
212 #else
213 const bool RSProperties::FilterCacheEnabled = false;
214 #endif
215 #endif
216 
217 const bool RSProperties::IS_UNI_RENDER = RSUniRenderJudgement::IsUniRender();
218 const bool RSProperties::FOREGROUND_FILTER_ENABLED = RSSystemProperties::GetForegroundFilterEnabled();
219 
RSProperties()220 RSProperties::RSProperties()
221 {
222     boundsGeo_ = std::make_shared<RSObjAbsGeometry>();
223     frameGeo_ = std::make_shared<RSObjGeometry>();
224 }
225 
226 RSProperties::~RSProperties() = default;
227 
ResetProperty(const ModifierDirtyTypes & dirtyTypes)228 void RSProperties::ResetProperty(const ModifierDirtyTypes& dirtyTypes)
229 {
230     if (dirtyTypes.none()) {
231         return;
232     }
233     for (uint8_t type = 0; type < static_cast<size_t>(RSModifierType::CUSTOM); type++) {
234         if (dirtyTypes.test(type)) {
235             if (auto& resetFunc = g_propertyResetterLUT[type]) {
236                 resetFunc(this);
237             }
238         }
239     }
240 }
241 
SetBounds(Vector4f bounds)242 void RSProperties::SetBounds(Vector4f bounds)
243 {
244     if (bounds.z_ != boundsGeo_->GetWidth() || bounds.w_ != boundsGeo_->GetHeight()) {
245         contentDirty_ = true;
246     }
247     boundsGeo_->SetRect(bounds.x_, bounds.y_, bounds.z_, bounds.w_);
248     hasBounds_ = true;
249     geoDirty_ = true;
250     SetDirty();
251 }
252 
SetBoundsSize(Vector2f size)253 void RSProperties::SetBoundsSize(Vector2f size)
254 {
255     boundsGeo_->SetSize(size.x_, size.y_);
256     hasBounds_ = true;
257     geoDirty_ = true;
258     contentDirty_ = true;
259     SetDirty();
260 }
261 
SetBoundsWidth(float width)262 void RSProperties::SetBoundsWidth(float width)
263 {
264     boundsGeo_->SetWidth(width);
265     hasBounds_ = true;
266     geoDirty_ = true;
267     contentDirty_ = true;
268     SetDirty();
269 }
270 
SetBoundsHeight(float height)271 void RSProperties::SetBoundsHeight(float height)
272 {
273     boundsGeo_->SetHeight(height);
274     hasBounds_ = true;
275     geoDirty_ = true;
276     contentDirty_ = true;
277     SetDirty();
278 }
279 
SetBoundsPosition(Vector2f position)280 void RSProperties::SetBoundsPosition(Vector2f position)
281 {
282     boundsGeo_->SetPosition(position.x_, position.y_);
283     geoDirty_ = true;
284     SetDirty();
285 }
286 
SetBoundsPositionX(float positionX)287 void RSProperties::SetBoundsPositionX(float positionX)
288 {
289     boundsGeo_->SetX(positionX);
290     geoDirty_ = true;
291     SetDirty();
292 }
293 
SetBoundsPositionY(float positionY)294 void RSProperties::SetBoundsPositionY(float positionY)
295 {
296     boundsGeo_->SetY(positionY);
297     geoDirty_ = true;
298     SetDirty();
299 }
300 
GetBounds() const301 Vector4f RSProperties::GetBounds() const
302 {
303     return { boundsGeo_->GetX(), boundsGeo_->GetY(), boundsGeo_->GetWidth(), boundsGeo_->GetHeight() };
304 }
305 
GetBoundsSize() const306 Vector2f RSProperties::GetBoundsSize() const
307 {
308     return { boundsGeo_->GetWidth(), boundsGeo_->GetHeight() };
309 }
310 
GetBoundsWidth() const311 float RSProperties::GetBoundsWidth() const
312 {
313     return boundsGeo_->GetWidth();
314 }
315 
GetBoundsHeight() const316 float RSProperties::GetBoundsHeight() const
317 {
318     return boundsGeo_->GetHeight();
319 }
320 
GetBoundsPositionX() const321 float RSProperties::GetBoundsPositionX() const
322 {
323     return boundsGeo_->GetX();
324 }
325 
GetBoundsPositionY() const326 float RSProperties::GetBoundsPositionY() const
327 {
328     return boundsGeo_->GetY();
329 }
330 
GetBoundsPosition() const331 Vector2f RSProperties::GetBoundsPosition() const
332 {
333     return { GetBoundsPositionX(), GetBoundsPositionY() };
334 }
335 
SetFrame(Vector4f frame)336 void RSProperties::SetFrame(Vector4f frame)
337 {
338     if (frame.z_ != frameGeo_->GetWidth() || frame.w_ != frameGeo_->GetHeight()) {
339         contentDirty_ = true;
340     }
341     frameGeo_->SetRect(frame.x_, frame.y_, frame.z_, frame.w_);
342     geoDirty_ = true;
343     SetDirty();
344 }
345 
SetFrameSize(Vector2f size)346 void RSProperties::SetFrameSize(Vector2f size)
347 {
348     frameGeo_->SetSize(size.x_, size.y_);
349     geoDirty_ = true;
350     contentDirty_ = true;
351     SetDirty();
352 }
353 
SetFrameWidth(float width)354 void RSProperties::SetFrameWidth(float width)
355 {
356     frameGeo_->SetWidth(width);
357     geoDirty_ = true;
358     contentDirty_ = true;
359     SetDirty();
360 }
361 
SetFrameHeight(float height)362 void RSProperties::SetFrameHeight(float height)
363 {
364     frameGeo_->SetHeight(height);
365     geoDirty_ = true;
366     contentDirty_ = true;
367     SetDirty();
368 }
369 
SetFramePosition(Vector2f position)370 void RSProperties::SetFramePosition(Vector2f position)
371 {
372     frameGeo_->SetPosition(position.x_, position.y_);
373     geoDirty_ = true;
374     SetDirty();
375 }
376 
SetFramePositionX(float positionX)377 void RSProperties::SetFramePositionX(float positionX)
378 {
379     frameGeo_->SetX(positionX);
380     geoDirty_ = true;
381     SetDirty();
382 }
383 
SetFramePositionY(float positionY)384 void RSProperties::SetFramePositionY(float positionY)
385 {
386     frameGeo_->SetY(positionY);
387     geoDirty_ = true;
388     SetDirty();
389 }
390 
GetFrame() const391 Vector4f RSProperties::GetFrame() const
392 {
393     return { frameGeo_->GetX(), frameGeo_->GetY(), frameGeo_->GetWidth(), frameGeo_->GetHeight() };
394 }
395 
GetFrameSize() const396 Vector2f RSProperties::GetFrameSize() const
397 {
398     return { frameGeo_->GetWidth(), frameGeo_->GetHeight() };
399 }
400 
GetFrameWidth() const401 float RSProperties::GetFrameWidth() const
402 {
403     return frameGeo_->GetWidth();
404 }
405 
GetFrameHeight() const406 float RSProperties::GetFrameHeight() const
407 {
408     return frameGeo_->GetHeight();
409 }
410 
GetFramePositionX() const411 float RSProperties::GetFramePositionX() const
412 {
413     return frameGeo_->GetX();
414 }
415 
GetFramePositionY() const416 float RSProperties::GetFramePositionY() const
417 {
418     return frameGeo_->GetY();
419 }
420 
GetFramePosition() const421 Vector2f RSProperties::GetFramePosition() const
422 {
423     return { GetFramePositionX(), GetFramePositionY() };
424 }
425 
GetFrameOffsetX() const426 float RSProperties::GetFrameOffsetX() const
427 {
428     return frameOffsetX_;
429 }
430 
GetFrameOffsetY() const431 float RSProperties::GetFrameOffsetY() const
432 {
433     return frameOffsetY_;
434 }
435 
GetBoundsGeometry() const436 const std::shared_ptr<RSObjAbsGeometry>& RSProperties::GetBoundsGeometry() const
437 {
438     return boundsGeo_;
439 }
440 
GetFrameGeometry() const441 const std::shared_ptr<RSObjGeometry>& RSProperties::GetFrameGeometry() const
442 {
443     return frameGeo_;
444 }
445 
UpdateGeometryByParent(const Drawing::Matrix * parentMatrix,const std::optional<Drawing::Point> & offset)446 bool RSProperties::UpdateGeometryByParent(const Drawing::Matrix* parentMatrix,
447     const std::optional<Drawing::Point>& offset)
448 {
449     static thread_local Drawing::Matrix prevAbsMatrix;
450     prevAbsMatrix.Swap(prevAbsMatrix_);
451     boundsGeo_->UpdateMatrix(parentMatrix, offset);
452     prevAbsMatrix_ = boundsGeo_->GetAbsMatrix();
453     if (!RSSystemProperties::GetSkipGeometryNotChangeEnabled()) {
454         return true;
455     }
456     const auto& rect = boundsGeo_->GetAbsRect();
457     if (!lastRect_.has_value()) {
458         lastRect_ = rect;
459         return true;
460     }
461     auto dirtyFlag = (rect != lastRect_.value()) || !(prevAbsMatrix == prevAbsMatrix_);
462     lastRect_ = rect;
463     return dirtyFlag;
464 }
465 
UpdateGeometry(const RSProperties * parent,bool dirtyFlag,const std::optional<Drawing::Point> & offset)466 bool RSProperties::UpdateGeometry(
467     const RSProperties* parent, bool dirtyFlag, const std::optional<Drawing::Point>& offset)
468 {
469     if (!dirtyFlag && !geoDirty_) {
470         return false;
471     }
472     auto parentMatrix = parent == nullptr ? nullptr : &(parent->GetBoundsGeometry()->GetAbsMatrix());
473     if (parentMatrix && sandbox_ && sandbox_->matrix_) {
474         parentMatrix = &(sandbox_->matrix_.value());
475     }
476     CheckEmptyBounds();
477     boundsGeo_->UpdateMatrix(parentMatrix, offset);
478     if (lightSourcePtr_ && lightSourcePtr_->IsLightSourceValid()) {
479         CalculateAbsLightPosition();
480         RSPointLightManager::Instance()->AddDirtyLightSource(backref_);
481     }
482     if (illuminatedPtr_ && illuminatedPtr_->IsIlluminatedValid()) {
483         RSPointLightManager::Instance()->AddDirtyIlluminated(backref_);
484     }
485     if (RSSystemProperties::GetSkipGeometryNotChangeEnabled()) {
486         auto rect = boundsGeo_->GetAbsRect();
487         if (!lastRect_.has_value()) {
488             lastRect_ = rect;
489             return true;
490         }
491         dirtyFlag = dirtyFlag || rect != lastRect_.value();
492         lastRect_ = rect;
493         return dirtyFlag;
494     } else {
495         return true;
496     }
497 }
498 
SetSandBox(const std::optional<Vector2f> & parentPosition)499 void RSProperties::SetSandBox(const std::optional<Vector2f>& parentPosition)
500 {
501     if (!sandbox_) {
502         sandbox_ = std::make_unique<Sandbox>();
503     }
504     sandbox_->position_ = parentPosition;
505     geoDirty_ = true;
506     SetDirty();
507 }
508 
GetSandBox() const509 std::optional<Vector2f> RSProperties::GetSandBox() const
510 {
511     return sandbox_ ? sandbox_->position_ : std::nullopt;
512 }
513 
ResetSandBox()514 void RSProperties::ResetSandBox()
515 {
516     sandbox_ = nullptr;
517 }
518 
UpdateSandBoxMatrix(const std::optional<Drawing::Matrix> & rootMatrix)519 void RSProperties::UpdateSandBoxMatrix(const std::optional<Drawing::Matrix>& rootMatrix)
520 {
521     if (!sandbox_) {
522         return;
523     }
524     if (!rootMatrix || !sandbox_->position_) {
525         sandbox_->matrix_ = std::nullopt;
526         return;
527     }
528     auto rootMat = rootMatrix.value();
529     bool hasScale = false;
530     // scaleFactors[0]-minimum scaling factor, scaleFactors[1]-maximum scaling factor
531     Drawing::scalar scaleFactors[2];
532     bool getMinMaxScales = rootMat.GetMinMaxScales(scaleFactors);
533     if (getMinMaxScales) {
534         hasScale = !ROSEN_EQ(scaleFactors[0], 1.f) || !ROSEN_EQ(scaleFactors[1], 1.f);
535     }
536     if (hasScale) {
537         sandbox_->matrix_ = std::nullopt;
538         return;
539     }
540     Drawing::Matrix matrix = rootMatrix.value();
541     matrix.PreTranslate(sandbox_->position_->x_, sandbox_->position_->y_);
542     sandbox_->matrix_ = matrix;
543 }
544 
GetSandBoxMatrix() const545 std::optional<Drawing::Matrix> RSProperties::GetSandBoxMatrix() const
546 {
547     return sandbox_ ? sandbox_->matrix_ : std::nullopt;
548 }
549 
SetPositionZ(float positionZ)550 void RSProperties::SetPositionZ(float positionZ)
551 {
552     boundsGeo_->SetZ(positionZ);
553     frameGeo_->SetZ(positionZ);
554     geoDirty_ = true;
555     SetDirty();
556 }
557 
GetPositionZ() const558 float RSProperties::GetPositionZ() const
559 {
560     return boundsGeo_->GetZ();
561 }
562 
SetPivot(Vector2f pivot)563 void RSProperties::SetPivot(Vector2f pivot)
564 {
565     boundsGeo_->SetPivot(pivot.x_, pivot.y_);
566     geoDirty_ = true;
567     SetDirty();
568 }
569 
SetPivotX(float pivotX)570 void RSProperties::SetPivotX(float pivotX)
571 {
572     boundsGeo_->SetPivotX(pivotX);
573     geoDirty_ = true;
574     SetDirty();
575 }
576 
SetPivotY(float pivotY)577 void RSProperties::SetPivotY(float pivotY)
578 {
579     boundsGeo_->SetPivotY(pivotY);
580     geoDirty_ = true;
581     SetDirty();
582 }
583 
SetPivotZ(float pivotZ)584 void RSProperties::SetPivotZ(float pivotZ)
585 {
586     boundsGeo_->SetPivotZ(pivotZ);
587     geoDirty_ = true;
588     SetDirty();
589 }
590 
GetPivot() const591 Vector2f RSProperties::GetPivot() const
592 {
593     return { boundsGeo_->GetPivotX(), boundsGeo_->GetPivotY() };
594 }
595 
GetPivotX() const596 float RSProperties::GetPivotX() const
597 {
598     return boundsGeo_->GetPivotX();
599 }
600 
GetPivotY() const601 float RSProperties::GetPivotY() const
602 {
603     return boundsGeo_->GetPivotY();
604 }
605 
GetPivotZ() const606 float RSProperties::GetPivotZ() const
607 {
608     return boundsGeo_->GetPivotZ();
609 }
610 
SetCornerRadius(const Vector4f & cornerRadius)611 void RSProperties::SetCornerRadius(const Vector4f& cornerRadius)
612 {
613     cornerRadius_ = cornerRadius;
614     SetDirty();
615 }
616 
GetCornerRadius() const617 const Vector4f& RSProperties::GetCornerRadius() const
618 {
619     return cornerRadius_ ? cornerRadius_.value() : Vector4fZero;
620 }
621 
SetQuaternion(Quaternion quaternion)622 void RSProperties::SetQuaternion(Quaternion quaternion)
623 {
624     boundsGeo_->SetQuaternion(quaternion);
625     geoDirty_ = true;
626     SetDirty();
627 }
628 
SetRotation(float degree)629 void RSProperties::SetRotation(float degree)
630 {
631     boundsGeo_->SetRotation(degree);
632     geoDirty_ = true;
633     SetDirty();
634 }
635 
SetRotationX(float degree)636 void RSProperties::SetRotationX(float degree)
637 {
638     boundsGeo_->SetRotationX(degree);
639     geoDirty_ = true;
640     SetDirty();
641 }
642 
SetRotationY(float degree)643 void RSProperties::SetRotationY(float degree)
644 {
645     boundsGeo_->SetRotationY(degree);
646     geoDirty_ = true;
647     SetDirty();
648 }
649 
SetCameraDistance(float cameraDistance)650 void RSProperties::SetCameraDistance(float cameraDistance)
651 {
652     boundsGeo_->SetCameraDistance(cameraDistance);
653     geoDirty_ = true;
654     SetDirty();
655 }
656 
SetScale(Vector2f scale)657 void RSProperties::SetScale(Vector2f scale)
658 {
659     boundsGeo_->SetScale(scale.x_, scale.y_);
660     geoDirty_ = true;
661     SetDirty();
662 }
663 
SetScaleX(float sx)664 void RSProperties::SetScaleX(float sx)
665 {
666     boundsGeo_->SetScaleX(sx);
667     geoDirty_ = true;
668     SetDirty();
669 }
670 
SetScaleY(float sy)671 void RSProperties::SetScaleY(float sy)
672 {
673     boundsGeo_->SetScaleY(sy);
674     geoDirty_ = true;
675     SetDirty();
676 }
677 
SetSkew(Vector2f skew)678 void RSProperties::SetSkew(Vector2f skew)
679 {
680     boundsGeo_->SetSkew(skew.x_, skew.y_);
681     geoDirty_ = true;
682     SetDirty();
683 }
684 
SetSkewX(float skewX)685 void RSProperties::SetSkewX(float skewX)
686 {
687     boundsGeo_->SetSkewX(skewX);
688     geoDirty_ = true;
689     SetDirty();
690 }
691 
SetSkewY(float skewY)692 void RSProperties::SetSkewY(float skewY)
693 {
694     boundsGeo_->SetSkewY(skewY);
695     geoDirty_ = true;
696     SetDirty();
697 }
698 
SetPersp(Vector2f persp)699 void RSProperties::SetPersp(Vector2f persp)
700 {
701     boundsGeo_->SetPersp(persp.x_, persp.y_);
702     geoDirty_ = true;
703     SetDirty();
704 }
705 
SetPerspX(float perspX)706 void RSProperties::SetPerspX(float perspX)
707 {
708     boundsGeo_->SetPerspX(perspX);
709     geoDirty_ = true;
710     SetDirty();
711 }
712 
SetPerspY(float perspY)713 void RSProperties::SetPerspY(float perspY)
714 {
715     boundsGeo_->SetPerspY(perspY);
716     geoDirty_ = true;
717     SetDirty();
718 }
719 
SetTranslate(Vector2f translate)720 void RSProperties::SetTranslate(Vector2f translate)
721 {
722     boundsGeo_->SetTranslateX(translate[0]);
723     boundsGeo_->SetTranslateY(translate[1]);
724     geoDirty_ = true;
725     SetDirty();
726 }
727 
SetTranslateX(float translate)728 void RSProperties::SetTranslateX(float translate)
729 {
730     boundsGeo_->SetTranslateX(translate);
731     geoDirty_ = true;
732     SetDirty();
733 }
734 
SetTranslateY(float translate)735 void RSProperties::SetTranslateY(float translate)
736 {
737     boundsGeo_->SetTranslateY(translate);
738     geoDirty_ = true;
739     SetDirty();
740 }
741 
SetTranslateZ(float translate)742 void RSProperties::SetTranslateZ(float translate)
743 {
744     boundsGeo_->SetTranslateZ(translate);
745     geoDirty_ = true;
746     SetDirty();
747 }
748 
GetQuaternion() const749 Quaternion RSProperties::GetQuaternion() const
750 {
751     return boundsGeo_->GetQuaternion();
752 }
753 
GetRotation() const754 float RSProperties::GetRotation() const
755 {
756     return boundsGeo_->GetRotation();
757 }
758 
GetRotationX() const759 float RSProperties::GetRotationX() const
760 {
761     return boundsGeo_->GetRotationX();
762 }
763 
GetRotationY() const764 float RSProperties::GetRotationY() const
765 {
766     return boundsGeo_->GetRotationY();
767 }
768 
GetCameraDistance() const769 float RSProperties::GetCameraDistance() const
770 {
771     return boundsGeo_->GetCameraDistance();
772 }
773 
GetScaleX() const774 float RSProperties::GetScaleX() const
775 {
776     return boundsGeo_->GetScaleX();
777 }
778 
GetScaleY() const779 float RSProperties::GetScaleY() const
780 {
781     return boundsGeo_->GetScaleY();
782 }
783 
GetScale() const784 Vector2f RSProperties::GetScale() const
785 {
786     return { boundsGeo_->GetScaleX(), boundsGeo_->GetScaleY() };
787 }
788 
GetSkewX() const789 float RSProperties::GetSkewX() const
790 {
791     return boundsGeo_->GetSkewX();
792 }
793 
GetSkewY() const794 float RSProperties::GetSkewY() const
795 {
796     return boundsGeo_->GetSkewY();
797 }
798 
GetSkew() const799 Vector2f RSProperties::GetSkew() const
800 {
801     return { boundsGeo_->GetSkewX(), boundsGeo_->GetSkewY() };
802 }
803 
GetPerspX() const804 float RSProperties::GetPerspX() const
805 {
806     return boundsGeo_->GetPerspX();
807 }
808 
GetPerspY() const809 float RSProperties::GetPerspY() const
810 {
811     return boundsGeo_->GetPerspY();
812 }
813 
GetPersp() const814 Vector2f RSProperties::GetPersp() const
815 {
816     return { boundsGeo_->GetPerspX(), boundsGeo_->GetPerspY() };
817 }
818 
GetTranslate() const819 Vector2f RSProperties::GetTranslate() const
820 {
821     return Vector2f(GetTranslateX(), GetTranslateY());
822 }
823 
GetTranslateX() const824 float RSProperties::GetTranslateX() const
825 {
826     return boundsGeo_->GetTranslateX();
827 }
828 
GetTranslateY() const829 float RSProperties::GetTranslateY() const
830 {
831     return boundsGeo_->GetTranslateY();
832 }
833 
GetTranslateZ() const834 float RSProperties::GetTranslateZ() const
835 {
836     return boundsGeo_->GetTranslateZ();
837 }
838 
SetParticles(const RSRenderParticleVector & particles)839 void RSProperties::SetParticles(const RSRenderParticleVector& particles)
840 {
841     particles_ = particles;
842     if (particles_.GetParticleSize() > 0) {
843         isDrawn_ = true;
844     }
845     SetDirty();
846     contentDirty_ = true;
847 }
848 
GetParticles() const849 const RSRenderParticleVector& RSProperties::GetParticles() const
850 {
851     return particles_;
852 }
853 
SetAlpha(float alpha)854 void RSProperties::SetAlpha(float alpha)
855 {
856     alpha_ = alpha;
857     if (alpha_ < 1.f) {
858         alphaNeedApply_ = true;
859     }
860     SetDirty();
861 }
862 
GetAlpha() const863 float RSProperties::GetAlpha() const
864 {
865     return alpha_;
866 }
SetAlphaOffscreen(bool alphaOffscreen)867 void RSProperties::SetAlphaOffscreen(bool alphaOffscreen)
868 {
869     alphaOffscreen_ = alphaOffscreen;
870     SetDirty();
871     contentDirty_ = true;
872 }
873 
GetAlphaOffscreen() const874 bool RSProperties::GetAlphaOffscreen() const
875 {
876     return alphaOffscreen_;
877 }
878 
SetSublayerTransform(const std::optional<Matrix3f> & sublayerTransform)879 void RSProperties::SetSublayerTransform(const std::optional<Matrix3f>& sublayerTransform)
880 {
881     sublayerTransform_ = sublayerTransform;
882     SetDirty();
883 }
884 
GetSublayerTransform() const885 const std::optional<Matrix3f>& RSProperties::GetSublayerTransform() const
886 {
887     return sublayerTransform_;
888 }
889 
890 // foreground properties
SetForegroundColor(Color color)891 void RSProperties::SetForegroundColor(Color color)
892 {
893     if (!decoration_) {
894         decoration_ = std::make_optional<Decoration>();
895     }
896     decoration_->foregroundColor_ = color;
897     SetDirty();
898     contentDirty_ = true;
899 }
900 
GetForegroundColor() const901 Color RSProperties::GetForegroundColor() const
902 {
903     return decoration_ ? decoration_->foregroundColor_ : RgbPalette::Transparent();
904 }
905 
906 // background properties
SetBackgroundColor(Color color)907 void RSProperties::SetBackgroundColor(Color color)
908 {
909     if (!decoration_) {
910         decoration_ = std::make_optional<Decoration>();
911     }
912     if (color.GetAlpha() > 0) {
913         isDrawn_ = true;
914     }
915     decoration_->backgroundColor_ = color;
916     SetDirty();
917     contentDirty_ = true;
918 }
919 
GetBackgroundColor() const920 const Color& RSProperties::GetBackgroundColor() const
921 {
922     return decoration_ ? decoration_->backgroundColor_ : RgbPalette::Transparent();
923 }
924 
SetBackgroundShader(const std::shared_ptr<RSShader> & shader)925 void RSProperties::SetBackgroundShader(const std::shared_ptr<RSShader>& shader)
926 {
927     if (!decoration_) {
928         decoration_ = std::make_optional<Decoration>();
929     }
930     if (shader) {
931         isDrawn_ = true;
932     }
933     decoration_->bgShader_ = shader;
934     SetDirty();
935     contentDirty_ = true;
936 }
937 
GetBackgroundShader() const938 std::shared_ptr<RSShader> RSProperties::GetBackgroundShader() const
939 {
940     return decoration_ ? decoration_->bgShader_ : nullptr;
941 }
942 
SetBgImage(const std::shared_ptr<RSImage> & image)943 void RSProperties::SetBgImage(const std::shared_ptr<RSImage>& image)
944 {
945     if (!decoration_) {
946         decoration_ = std::make_optional<Decoration>();
947     }
948     if (image) {
949         isDrawn_ = true;
950     }
951     decoration_->bgImage_ = image;
952     SetDirty();
953     contentDirty_ = true;
954 }
955 
GetBgImage() const956 std::shared_ptr<RSImage> RSProperties::GetBgImage() const
957 {
958     return decoration_ ? decoration_->bgImage_ : nullptr;
959 }
960 
SetBgImageInnerRect(const Vector4f & rect)961 void RSProperties::SetBgImageInnerRect(const Vector4f& rect)
962 {
963     if (!decoration_) {
964         decoration_ = std::make_optional<Decoration>();
965     }
966     decoration_->bgImageInnerRect_ = rect;
967     SetDirty();
968     contentDirty_ = true;
969 }
970 
GetBgImageInnerRect() const971 Vector4f RSProperties::GetBgImageInnerRect() const
972 {
973     return decoration_ ? decoration_->bgImageInnerRect_ : Vector4f();
974 }
975 
SetBgImageWidth(float width)976 void RSProperties::SetBgImageWidth(float width)
977 {
978     if (!decoration_) {
979         decoration_ = std::make_optional<Decoration>();
980     }
981     decoration_->bgImageRect_.width_ = width;
982     SetDirty();
983     contentDirty_ = true;
984 }
985 
SetBgImageHeight(float height)986 void RSProperties::SetBgImageHeight(float height)
987 {
988     if (!decoration_) {
989         decoration_ = std::make_optional<Decoration>();
990     }
991     decoration_->bgImageRect_.height_ = height;
992     SetDirty();
993     contentDirty_ = true;
994 }
995 
SetBgImagePositionX(float positionX)996 void RSProperties::SetBgImagePositionX(float positionX)
997 {
998     if (!decoration_) {
999         decoration_ = std::make_optional<Decoration>();
1000     }
1001     decoration_->bgImageRect_.left_ = positionX;
1002     SetDirty();
1003     contentDirty_ = true;
1004 }
1005 
SetBgImagePositionY(float positionY)1006 void RSProperties::SetBgImagePositionY(float positionY)
1007 {
1008     if (!decoration_) {
1009         decoration_ = std::make_optional<Decoration>();
1010     }
1011     decoration_->bgImageRect_.top_ = positionY;
1012     SetDirty();
1013     contentDirty_ = true;
1014 }
1015 
GetBgImageWidth() const1016 float RSProperties::GetBgImageWidth() const
1017 {
1018     return decoration_ ? decoration_->bgImageRect_.width_ : 0.f;
1019 }
1020 
GetBgImageHeight() const1021 float RSProperties::GetBgImageHeight() const
1022 {
1023     return decoration_ ? decoration_->bgImageRect_.height_ : 0.f;
1024 }
1025 
GetBgImagePositionX() const1026 float RSProperties::GetBgImagePositionX() const
1027 {
1028     return decoration_ ? decoration_->bgImageRect_.left_ : 0.f;
1029 }
1030 
GetBgImagePositionY() const1031 float RSProperties::GetBgImagePositionY() const
1032 {
1033     return decoration_ ? decoration_->bgImageRect_.top_ : 0.f;
1034 }
1035 
1036 // border properties
SetBorderColor(Vector4<Color> color)1037 void RSProperties::SetBorderColor(Vector4<Color> color)
1038 {
1039     if (!border_) {
1040         border_ = std::make_shared<RSBorder>();
1041     }
1042     border_->SetColorFour(color);
1043     if (border_->GetColor().GetAlpha() > 0) {
1044         isDrawn_ = true;
1045     }
1046     SetDirty();
1047     contentDirty_ = true;
1048 }
1049 
SetBorderWidth(Vector4f width)1050 void RSProperties::SetBorderWidth(Vector4f width)
1051 {
1052     if (!border_) {
1053         border_ = std::make_shared<RSBorder>();
1054     }
1055     border_->SetWidthFour(width);
1056     if (!width.IsZero()) {
1057         isDrawn_ = true;
1058     }
1059     SetDirty();
1060     contentDirty_ = true;
1061 }
1062 
SetBorderStyle(Vector4<uint32_t> style)1063 void RSProperties::SetBorderStyle(Vector4<uint32_t> style)
1064 {
1065     if (!border_) {
1066         border_ = std::make_shared<RSBorder>();
1067     }
1068     border_->SetStyleFour(style);
1069     SetDirty();
1070     contentDirty_ = true;
1071 }
1072 
SetBorderDashWidth(const Vector4f & dashWidth)1073 void RSProperties::SetBorderDashWidth(const Vector4f& dashWidth)
1074 {
1075     if (!border_) {
1076         border_ = std::make_shared<RSBorder>();
1077     }
1078     border_->SetDashWidthFour(dashWidth);
1079     SetDirty();
1080     contentDirty_ = true;
1081 }
1082 
SetBorderDashGap(const Vector4f & dashGap)1083 void RSProperties::SetBorderDashGap(const Vector4f& dashGap)
1084 {
1085     if (!border_) {
1086         border_ = std::make_shared<RSBorder>();
1087     }
1088     border_->SetDashGapFour(dashGap);
1089     SetDirty();
1090     contentDirty_ = true;
1091 }
1092 
GetBorderColor() const1093 Vector4<Color> RSProperties::GetBorderColor() const
1094 {
1095     return border_ ? border_->GetColorFour() : Vector4<Color>(RgbPalette::Transparent());
1096 }
1097 
GetBorderWidth() const1098 Vector4f RSProperties::GetBorderWidth() const
1099 {
1100     return border_ ? border_->GetWidthFour() : Vector4f(0.f);
1101 }
1102 
GetBorderStyle() const1103 Vector4<uint32_t> RSProperties::GetBorderStyle() const
1104 {
1105     return border_ ? border_->GetStyleFour() : Vector4<uint32_t>(static_cast<uint32_t>(BorderStyle::NONE));
1106 }
1107 
GetBorderDashWidth() const1108 Vector4f RSProperties::GetBorderDashWidth() const
1109 {
1110     return border_ ? border_->GetDashWidthFour() : Vector4f(0.f);
1111 }
1112 
GetBorderDashGap() const1113 Vector4f RSProperties::GetBorderDashGap() const
1114 {
1115     return border_ ? border_->GetDashGapFour() : Vector4f(0.f);
1116 }
1117 
GetBorder() const1118 const std::shared_ptr<RSBorder>& RSProperties::GetBorder() const
1119 {
1120     return border_;
1121 }
1122 
GetBorderColorIsTransparent() const1123 bool RSProperties::GetBorderColorIsTransparent() const
1124 {
1125     if (border_) {
1126         for (int i = 0; i < BORDER_NUM; i++) {
1127             auto alpha = border_->GetColorFour()[i].GetAlpha();
1128             if (alpha < BORDER_TRANSPARENT) {
1129                 return true;
1130             }
1131         }
1132     }
1133     return false;
1134 }
1135 
SetOutlineColor(Vector4<Color> color)1136 void RSProperties::SetOutlineColor(Vector4<Color> color)
1137 {
1138     if (!outline_) {
1139         outline_ = std::make_shared<RSBorder>(true);
1140     }
1141     outline_->SetColorFour(color);
1142     if (outline_->GetColor().GetAlpha() > 0) {
1143         isDrawn_ = true;
1144     }
1145     SetDirty();
1146     contentDirty_ = true;
1147 }
1148 
SetOutlineWidth(Vector4f width)1149 void RSProperties::SetOutlineWidth(Vector4f width)
1150 {
1151     if (!outline_) {
1152         outline_ = std::make_shared<RSBorder>(true);
1153     }
1154     outline_->SetWidthFour(width);
1155     if (!width.IsZero()) {
1156         isDrawn_ = true;
1157     }
1158     SetDirty();
1159     contentDirty_ = true;
1160 }
1161 
SetOutlineStyle(Vector4<uint32_t> style)1162 void RSProperties::SetOutlineStyle(Vector4<uint32_t> style)
1163 {
1164     if (!outline_) {
1165         outline_ = std::make_shared<RSBorder>(true);
1166     }
1167     outline_->SetStyleFour(style);
1168     SetDirty();
1169     contentDirty_ = true;
1170 }
1171 
SetOutlineDashWidth(const Vector4f & dashWidth)1172 void RSProperties::SetOutlineDashWidth(const Vector4f& dashWidth)
1173 {
1174     if (!outline_) {
1175         outline_ = std::make_shared<RSBorder>();
1176     }
1177     outline_->SetDashWidthFour(dashWidth);
1178     SetDirty();
1179     contentDirty_ = true;
1180 }
1181 
SetOutlineDashGap(const Vector4f & dashGap)1182 void RSProperties::SetOutlineDashGap(const Vector4f& dashGap)
1183 {
1184     if (!outline_) {
1185         outline_ = std::make_shared<RSBorder>();
1186     }
1187     outline_->SetDashGapFour(dashGap);
1188     SetDirty();
1189     contentDirty_ = true;
1190 }
1191 
SetOutlineRadius(Vector4f radius)1192 void RSProperties::SetOutlineRadius(Vector4f radius)
1193 {
1194     if (!outline_) {
1195         outline_ = std::make_shared<RSBorder>(true);
1196     }
1197     outline_->SetRadiusFour(radius);
1198     isDrawn_ = true;
1199     SetDirty();
1200     contentDirty_ = true;
1201 }
1202 
GetOutlineColor() const1203 Vector4<Color> RSProperties::GetOutlineColor() const
1204 {
1205     return outline_ ? outline_->GetColorFour() : Vector4<Color>(RgbPalette::Transparent());
1206 }
1207 
GetOutlineWidth() const1208 Vector4f RSProperties::GetOutlineWidth() const
1209 {
1210     return outline_ ? outline_->GetWidthFour() : Vector4f(0.f);
1211 }
1212 
GetOutlineStyle() const1213 Vector4<uint32_t> RSProperties::GetOutlineStyle() const
1214 {
1215     return outline_ ? outline_->GetStyleFour() : Vector4<uint32_t>(static_cast<uint32_t>(BorderStyle::NONE));
1216 }
1217 
GetOutlineDashWidth() const1218 Vector4f RSProperties::GetOutlineDashWidth() const
1219 {
1220     return outline_ ? outline_->GetDashWidthFour() : Vector4f(0.f);
1221 }
1222 
GetOutlineDashGap() const1223 Vector4f RSProperties::GetOutlineDashGap() const
1224 {
1225     return outline_ ? outline_->GetDashGapFour() : Vector4f(0.f);
1226 }
1227 
GetOutlineRadius() const1228 Vector4f RSProperties::GetOutlineRadius() const
1229 {
1230     return outline_ ? outline_->GetRadiusFour() : Vector4fZero;
1231 }
1232 
GetOutline() const1233 const std::shared_ptr<RSBorder>& RSProperties::GetOutline() const
1234 {
1235     return outline_;
1236 }
1237 
SetForegroundEffectRadius(const float foregroundEffectRadius)1238 void RSProperties::SetForegroundEffectRadius(const float foregroundEffectRadius)
1239 {
1240     foregroundEffectRadius_ = foregroundEffectRadius;
1241     if (IsForegroundEffectRadiusValid()) {
1242         isDrawn_ = true;
1243     }
1244     filterNeedUpdate_ = true;
1245     SetDirty();
1246 }
1247 
GetForegroundEffectRadius() const1248 float RSProperties::GetForegroundEffectRadius() const
1249 {
1250     return foregroundEffectRadius_;
1251 }
1252 
IsForegroundEffectRadiusValid() const1253 bool RSProperties::IsForegroundEffectRadiusValid() const
1254 {
1255     return ROSEN_GNE(foregroundEffectRadius_, 0.0);
1256 }
1257 
SetForegroundEffectDirty(bool dirty)1258 void RSProperties::SetForegroundEffectDirty(bool dirty)
1259 {
1260     foregroundEffectDirty_ = dirty;
1261 }
1262 
GetForegroundEffectDirty() const1263 bool RSProperties::GetForegroundEffectDirty() const
1264 {
1265     return foregroundEffectDirty_;
1266 }
1267 
GetForegroundFilterCache() const1268 const std::shared_ptr<RSFilter>& RSProperties::GetForegroundFilterCache() const
1269 {
1270     return foregroundFilterCache_;
1271 }
1272 
SetForegroundFilterCache(const std::shared_ptr<RSFilter> & foregroundFilterCache)1273 void RSProperties::SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache)
1274 {
1275     foregroundFilterCache_ = foregroundFilterCache;
1276     if (foregroundFilterCache) {
1277         isDrawn_ = true;
1278     }
1279     SetDirty();
1280     filterNeedUpdate_ = true;
1281     contentDirty_ = true;
1282 }
1283 
SetBackgroundFilter(const std::shared_ptr<RSFilter> & backgroundFilter)1284 void RSProperties::SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter)
1285 {
1286     backgroundFilter_ = backgroundFilter;
1287     if (backgroundFilter_) {
1288         isDrawn_ = true;
1289     }
1290     SetDirty();
1291     filterNeedUpdate_ = true;
1292     contentDirty_ = true;
1293 }
1294 
SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara> & para)1295 void RSProperties::SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para)
1296 {
1297     linearGradientBlurPara_ = para;
1298     if (para && para->blurRadius_ > 0.f) {
1299         isDrawn_ = true;
1300     }
1301     filterNeedUpdate_ = true;
1302     SetDirty();
1303     contentDirty_ = true;
1304 }
1305 
SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>> & para)1306 void RSProperties::SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>>& para)
1307 {
1308     emitterUpdater_ = para;
1309     if (!emitterUpdater_.empty()) {
1310         isDrawn_ = true;
1311         auto renderNode = backref_.lock();
1312         if (renderNode == nullptr) {
1313             return;
1314         }
1315         auto animation = renderNode->GetAnimationManager().GetParticleAnimation();
1316         if (animation == nullptr) {
1317             return;
1318         }
1319         auto particleAnimation = std::static_pointer_cast<RSRenderParticleAnimation>(animation);
1320         if (particleAnimation) {
1321             particleAnimation->UpdateEmitter(emitterUpdater_);
1322         }
1323     }
1324     filterNeedUpdate_ = true;
1325     SetDirty();
1326     contentDirty_ = true;
1327 }
1328 
SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields> & para)1329 void RSProperties::SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields>& para)
1330 {
1331     particleNoiseFields_ = para;
1332     if (particleNoiseFields_) {
1333         isDrawn_ = true;
1334         auto renderNode = backref_.lock();
1335         if (renderNode == nullptr) {
1336             return;
1337         }
1338         auto animation = renderNode->GetAnimationManager().GetParticleAnimation();
1339         if (animation == nullptr) {
1340             return;
1341         }
1342         auto particleAnimation = std::static_pointer_cast<RSRenderParticleAnimation>(animation);
1343         if (particleAnimation) {
1344             particleAnimation->UpdateNoiseField(particleNoiseFields_);
1345         }
1346     }
1347     filterNeedUpdate_ = true;
1348     SetDirty();
1349     contentDirty_ = true;
1350 }
1351 
SetDynamicLightUpRate(const std::optional<float> & rate)1352 void RSProperties::SetDynamicLightUpRate(const std::optional<float>& rate)
1353 {
1354     dynamicLightUpRate_ = rate;
1355     if (rate.has_value()) {
1356         isDrawn_ = true;
1357     }
1358     filterNeedUpdate_ = true;
1359     SetDirty();
1360     contentDirty_ = true;
1361 }
1362 
SetDynamicLightUpDegree(const std::optional<float> & lightUpDegree)1363 void RSProperties::SetDynamicLightUpDegree(const std::optional<float>& lightUpDegree)
1364 {
1365     dynamicLightUpDegree_ = lightUpDegree;
1366     if (lightUpDegree.has_value()) {
1367         isDrawn_ = true;
1368     }
1369     filterNeedUpdate_ = true;
1370     SetDirty();
1371     contentDirty_ = true;
1372 }
1373 
SetWaterRippleProgress(const float & progress)1374 void RSProperties::SetWaterRippleProgress(const float& progress)
1375 {
1376     waterRippleProgress_ = progress;
1377     isDrawn_ = true;
1378     filterNeedUpdate_ = true;
1379     SetDirty();
1380     contentDirty_ = true;
1381 }
1382 
GetWaterRippleProgress() const1383 float RSProperties::GetWaterRippleProgress() const
1384 {
1385     return waterRippleProgress_;
1386 }
1387 
SetWaterRippleParams(const std::optional<RSWaterRipplePara> & params)1388 void RSProperties::SetWaterRippleParams(const std::optional<RSWaterRipplePara>& params)
1389 {
1390     waterRippleParams_ = params;
1391     if (params.has_value()) {
1392         isDrawn_ = true;
1393     }
1394     filterNeedUpdate_ = true;
1395     SetDirty();
1396     contentDirty_ = true;
1397 }
1398 
GetWaterRippleParams() const1399 std::optional<RSWaterRipplePara> RSProperties::GetWaterRippleParams() const
1400 {
1401     return waterRippleParams_;
1402 }
1403 
IsWaterRippleValid() const1404 bool RSProperties::IsWaterRippleValid() const
1405 {
1406     uint32_t WAVE_COUNT_MAX = 3;
1407     uint32_t WAVE_COUNT_MIN = 1;
1408     return ROSEN_GE(waterRippleProgress_, 0.0f) && ROSEN_LE(waterRippleProgress_, 1.0f) &&
1409            waterRippleParams_.has_value() && waterRippleParams_->waveCount >= WAVE_COUNT_MIN &&
1410            waterRippleParams_->waveCount <= WAVE_COUNT_MAX;
1411 }
1412 
SetFlyOutDegree(const float & degree)1413 void RSProperties::SetFlyOutDegree(const float& degree)
1414 {
1415     flyOutDegree_ = degree;
1416     isDrawn_ = true;
1417     filterNeedUpdate_ = true;
1418     SetDirty();
1419     contentDirty_ = true;
1420 }
1421 
GetFlyOutDegree() const1422 float RSProperties::GetFlyOutDegree() const
1423 {
1424     return flyOutDegree_;
1425 }
1426 
SetFlyOutParams(const std::optional<RSFlyOutPara> & params)1427 void RSProperties::SetFlyOutParams(const std::optional<RSFlyOutPara>& params)
1428 {
1429     flyOutParams_ = params;
1430     if (params.has_value()) {
1431         isDrawn_ = true;
1432     }
1433     filterNeedUpdate_ = true;
1434     SetDirty();
1435     contentDirty_ = true;
1436 }
1437 
GetFlyOutParams() const1438 std::optional<RSFlyOutPara> RSProperties::GetFlyOutParams() const
1439 {
1440     return flyOutParams_;
1441 }
1442 
IsFlyOutValid() const1443 bool RSProperties::IsFlyOutValid() const
1444 {
1445     return ROSEN_GE(flyOutDegree_, 0.0f) && ROSEN_LE(flyOutDegree_, 1.0f) && flyOutParams_.has_value();
1446 }
1447 
SetDistortionK(const std::optional<float> & distortionK)1448 void RSProperties::SetDistortionK(const std::optional<float>& distortionK)
1449 {
1450     distortionK_ = distortionK;
1451     if (distortionK_.has_value()) {
1452         isDrawn_ = true;
1453         distortionEffectDirty_ = ROSEN_GNE(*distortionK_, 0.0f) && ROSEN_LE(*distortionK_, 1.0f);
1454     }
1455     filterNeedUpdate_ = true;
1456     SetDirty();
1457     contentDirty_ = true;
1458 }
1459 
GetDistortionK() const1460 const std::optional<float>& RSProperties::GetDistortionK() const
1461 {
1462     return distortionK_;
1463 }
1464 
IsDistortionKValid() const1465 bool RSProperties::IsDistortionKValid() const
1466 {
1467     return distortionK_.has_value() && ROSEN_GE(*distortionK_, -1.0f) && ROSEN_LE(*distortionK_, 1.0f);
1468 }
1469 
SetDistortionDirty(bool distortionEffectDirty)1470 void RSProperties::SetDistortionDirty(bool distortionEffectDirty)
1471 {
1472     distortionEffectDirty_ = distortionEffectDirty;
1473 }
1474 
GetDistortionDirty() const1475 bool RSProperties::GetDistortionDirty() const
1476 {
1477     return distortionEffectDirty_;
1478 }
1479 
SetFgBrightnessRates(const Vector4f & rates)1480 void RSProperties::SetFgBrightnessRates(const Vector4f& rates)
1481 {
1482     if (!fgBrightnessParams_.has_value()) {
1483         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1484     }
1485     fgBrightnessParams_->rates_ = rates;
1486     isDrawn_ = true;
1487     filterNeedUpdate_ = true;
1488     SetDirty();
1489     contentDirty_ = true;
1490 }
1491 
GetFgBrightnessRates() const1492 Vector4f RSProperties::GetFgBrightnessRates() const
1493 {
1494     return fgBrightnessParams_ ? fgBrightnessParams_->rates_ : Vector4f();
1495 }
1496 
SetFgBrightnessSaturation(const float & saturation)1497 void RSProperties::SetFgBrightnessSaturation(const float& saturation)
1498 {
1499     if (!fgBrightnessParams_.has_value()) {
1500         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1501     }
1502     fgBrightnessParams_->saturation_ = saturation;
1503     isDrawn_ = true;
1504     filterNeedUpdate_ = true;
1505     SetDirty();
1506     contentDirty_ = true;
1507 }
1508 
GetFgBrightnessSaturation() const1509 float RSProperties::GetFgBrightnessSaturation() const
1510 {
1511     return fgBrightnessParams_ ? fgBrightnessParams_->saturation_ : 0.0f;
1512 }
1513 
SetFgBrightnessPosCoeff(const Vector4f & coeff)1514 void RSProperties::SetFgBrightnessPosCoeff(const Vector4f& coeff)
1515 {
1516     if (!fgBrightnessParams_.has_value()) {
1517         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1518     }
1519     fgBrightnessParams_->posCoeff_ = coeff;
1520     isDrawn_ = true;
1521     filterNeedUpdate_ = true;
1522     SetDirty();
1523     contentDirty_ = true;
1524 }
1525 
GetFgBrightnessPosCoeff() const1526 Vector4f RSProperties::GetFgBrightnessPosCoeff() const
1527 {
1528     return fgBrightnessParams_ ? fgBrightnessParams_->posCoeff_ : Vector4f();
1529 }
1530 
SetFgBrightnessNegCoeff(const Vector4f & coeff)1531 void RSProperties::SetFgBrightnessNegCoeff(const Vector4f& coeff)
1532 {
1533     if (!fgBrightnessParams_.has_value()) {
1534         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1535     }
1536     fgBrightnessParams_->negCoeff_ = coeff;
1537     isDrawn_ = true;
1538     filterNeedUpdate_ = true;
1539     SetDirty();
1540     contentDirty_ = true;
1541 }
1542 
GetFgBrightnessNegCoeff() const1543 Vector4f RSProperties::GetFgBrightnessNegCoeff() const
1544 {
1545     return fgBrightnessParams_ ? fgBrightnessParams_->negCoeff_ : Vector4f();
1546 }
1547 
SetFgBrightnessFract(const float & fraction)1548 void RSProperties::SetFgBrightnessFract(const float& fraction)
1549 {
1550     if (!fgBrightnessParams_.has_value()) {
1551         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1552     }
1553     fgBrightnessParams_->fraction_ = fraction;
1554     isDrawn_ = true;
1555     filterNeedUpdate_ = true;
1556     SetDirty();
1557     contentDirty_ = true;
1558 }
1559 
GetFgBrightnessFract() const1560 float RSProperties::GetFgBrightnessFract() const
1561 {
1562     return fgBrightnessParams_ ? fgBrightnessParams_->fraction_ : 1.0f;
1563 }
1564 
SetFgBrightnessParams(const std::optional<RSDynamicBrightnessPara> & params)1565 void RSProperties::SetFgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params)
1566 {
1567     fgBrightnessParams_ = params;
1568     if (params.has_value()) {
1569         isDrawn_ = true;
1570     }
1571     filterNeedUpdate_ = true;
1572     SetDirty();
1573     contentDirty_ = true;
1574 }
1575 
GetFgBrightnessParams() const1576 std::optional<RSDynamicBrightnessPara> RSProperties::GetFgBrightnessParams() const
1577 {
1578     return fgBrightnessParams_;
1579 }
1580 
SetBgBrightnessRates(const Vector4f & rates)1581 void RSProperties::SetBgBrightnessRates(const Vector4f& rates)
1582 {
1583     if (!bgBrightnessParams_.has_value()) {
1584         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1585     }
1586     bgBrightnessParams_->rates_ = rates;
1587     isDrawn_ = true;
1588     filterNeedUpdate_ = true;
1589     SetDirty();
1590     contentDirty_ = true;
1591 }
1592 
GetBgBrightnessRates() const1593 Vector4f RSProperties::GetBgBrightnessRates() const
1594 {
1595     return bgBrightnessParams_ ? bgBrightnessParams_->rates_ : Vector4f();
1596 }
1597 
SetBgBrightnessSaturation(const float & saturation)1598 void RSProperties::SetBgBrightnessSaturation(const float& saturation)
1599 {
1600     if (!bgBrightnessParams_.has_value()) {
1601         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1602     }
1603     bgBrightnessParams_->saturation_ = saturation;
1604     isDrawn_ = true;
1605     filterNeedUpdate_ = true;
1606     SetDirty();
1607     contentDirty_ = true;
1608 }
1609 
GetBgBrightnessSaturation() const1610 float RSProperties::GetBgBrightnessSaturation() const
1611 {
1612     return bgBrightnessParams_ ? bgBrightnessParams_->saturation_ : 0.0f;
1613 }
1614 
SetBgBrightnessPosCoeff(const Vector4f & coeff)1615 void RSProperties::SetBgBrightnessPosCoeff(const Vector4f& coeff)
1616 {
1617     if (!bgBrightnessParams_.has_value()) {
1618         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1619     }
1620     bgBrightnessParams_->posCoeff_ = coeff;
1621     isDrawn_ = true;
1622     filterNeedUpdate_ = true;
1623     SetDirty();
1624     contentDirty_ = true;
1625 }
1626 
GetBgBrightnessPosCoeff() const1627 Vector4f RSProperties::GetBgBrightnessPosCoeff() const
1628 {
1629     return bgBrightnessParams_ ? bgBrightnessParams_->posCoeff_ : Vector4f();
1630 }
1631 
SetBgBrightnessNegCoeff(const Vector4f & coeff)1632 void RSProperties::SetBgBrightnessNegCoeff(const Vector4f& coeff)
1633 {
1634     if (!bgBrightnessParams_.has_value()) {
1635         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1636     }
1637     bgBrightnessParams_->negCoeff_ = coeff;
1638     isDrawn_ = true;
1639     filterNeedUpdate_ = true;
1640     SetDirty();
1641     contentDirty_ = true;
1642 }
1643 
GetBgBrightnessNegCoeff() const1644 Vector4f RSProperties::GetBgBrightnessNegCoeff() const
1645 {
1646     return bgBrightnessParams_ ? bgBrightnessParams_->negCoeff_ : Vector4f();
1647 }
1648 
SetBgBrightnessFract(const float & fraction)1649 void RSProperties::SetBgBrightnessFract(const float& fraction)
1650 {
1651     if (!bgBrightnessParams_.has_value()) {
1652         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1653     }
1654     bgBrightnessParams_->fraction_ = fraction;
1655     isDrawn_ = true;
1656     filterNeedUpdate_ = true;
1657     SetDirty();
1658     contentDirty_ = true;
1659 }
1660 
GetBgBrightnessFract() const1661 float RSProperties::GetBgBrightnessFract() const
1662 {
1663     return bgBrightnessParams_ ? bgBrightnessParams_->fraction_ : 1.0f;
1664 }
1665 
SetBgBrightnessParams(const std::optional<RSDynamicBrightnessPara> & params)1666 void RSProperties::SetBgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params)
1667 {
1668     bgBrightnessParams_ = params;
1669     if (params.has_value()) {
1670         isDrawn_ = true;
1671     }
1672     filterNeedUpdate_ = true;
1673     SetDirty();
1674     contentDirty_ = true;
1675 }
1676 
GetBgBrightnessParams() const1677 std::optional<RSDynamicBrightnessPara> RSProperties::GetBgBrightnessParams() const
1678 {
1679     return bgBrightnessParams_;
1680 }
1681 
IsFgBrightnessValid() const1682 bool RSProperties::IsFgBrightnessValid() const
1683 {
1684     return fgBrightnessParams_.has_value() && fgBrightnessParams_->IsValid();
1685 }
1686 
IsBgBrightnessValid() const1687 bool RSProperties::IsBgBrightnessValid() const
1688 {
1689     return bgBrightnessParams_.has_value() && bgBrightnessParams_->IsValid();
1690 }
1691 
GetFgBrightnessDescription() const1692 std::string RSProperties::GetFgBrightnessDescription() const
1693 {
1694     if (!fgBrightnessParams_.has_value()) {
1695         return "fgBrightnessParams_ is nullopt";
1696     }
1697     std::string description =
1698         "ForegroundBrightness, cubicCoeff: " + std::to_string(fgBrightnessParams_->rates_.x_) +
1699         ", quadCoeff: " + std::to_string(fgBrightnessParams_->rates_.y_) +
1700         ", rate: " + std::to_string(fgBrightnessParams_->rates_.z_) +
1701         ", lightUpDegree: " + std::to_string(fgBrightnessParams_->rates_.w_) +
1702         ", saturation: " + std::to_string(fgBrightnessParams_->saturation_) +
1703         ", fgBrightnessFract: " + std::to_string(fgBrightnessParams_->fraction_);
1704     return description;
1705 }
1706 
GetBgBrightnessDescription() const1707 std::string RSProperties::GetBgBrightnessDescription() const
1708 {
1709     if (!bgBrightnessParams_.has_value()) {
1710         return "bgBrightnessParams_ is nullopt";
1711     }
1712     std::string description =
1713         "BackgroundBrightnessInternal, cubicCoeff: " + std::to_string(bgBrightnessParams_->rates_.x_) +
1714         ", quadCoeff: " + std::to_string(bgBrightnessParams_->rates_.y_) +
1715         ", rate: " + std::to_string(bgBrightnessParams_->rates_.z_) +
1716         ", lightUpDegree: " + std::to_string(bgBrightnessParams_->rates_.w_) +
1717         ", saturation: " + std::to_string(bgBrightnessParams_->saturation_) +
1718         ", fgBrightnessFract: " + std::to_string(bgBrightnessParams_->fraction_);
1719     return description;
1720 }
1721 
SetGreyCoef(const std::optional<Vector2f> & greyCoef)1722 void RSProperties::SetGreyCoef(const std::optional<Vector2f>& greyCoef)
1723 {
1724     greyCoef_ = greyCoef;
1725     greyCoefNeedUpdate_ = true;
1726     SetDirty();
1727     contentDirty_ = true;
1728 }
1729 
SetDynamicDimDegree(const std::optional<float> & DimDegree)1730 void RSProperties::SetDynamicDimDegree(const std::optional<float>& DimDegree)
1731 {
1732     dynamicDimDegree_ = DimDegree;
1733     if (DimDegree.has_value()) {
1734         isDrawn_ = true;
1735     }
1736     filterNeedUpdate_ = true;
1737     SetDirty();
1738     contentDirty_ = true;
1739 }
1740 
SetFilter(const std::shared_ptr<RSFilter> & filter)1741 void RSProperties::SetFilter(const std::shared_ptr<RSFilter>& filter)
1742 {
1743     filter_ = filter;
1744     if (filter) {
1745         isDrawn_ = true;
1746     }
1747     SetDirty();
1748     filterNeedUpdate_ = true;
1749     contentDirty_ = true;
1750 }
1751 
SetMotionBlurPara(const std::shared_ptr<MotionBlurParam> & para)1752 void RSProperties::SetMotionBlurPara(const std::shared_ptr<MotionBlurParam>& para)
1753 {
1754     motionBlurPara_ = para;
1755 
1756     if (para && para->radius > 0.f) {
1757         isDrawn_ = true;
1758     }
1759     SetDirty();
1760     filterNeedUpdate_ = true;
1761     contentDirty_ = true;
1762 }
1763 
SetMagnifierParams(const std::shared_ptr<RSMagnifierParams> & para)1764 void RSProperties::SetMagnifierParams(const std::shared_ptr<RSMagnifierParams>& para)
1765 {
1766     magnifierPara_ = para;
1767 
1768     if (para) {
1769         isDrawn_ = true;
1770     }
1771     SetDirty();
1772     filterNeedUpdate_ = true;
1773     contentDirty_ = true;
1774 }
1775 
GetMagnifierPara() const1776 const std::shared_ptr<RSMagnifierParams>& RSProperties::GetMagnifierPara() const
1777 {
1778     return magnifierPara_;
1779 }
1780 
GetBackgroundFilter() const1781 const std::shared_ptr<RSFilter>& RSProperties::GetBackgroundFilter() const
1782 {
1783     return backgroundFilter_;
1784 }
1785 
GetLinearGradientBlurPara() const1786 const std::shared_ptr<RSLinearGradientBlurPara>& RSProperties::GetLinearGradientBlurPara() const
1787 {
1788     return linearGradientBlurPara_;
1789 }
1790 
GetEmitterUpdater() const1791 const std::vector<std::shared_ptr<EmitterUpdater>>& RSProperties::GetEmitterUpdater() const
1792 {
1793     return emitterUpdater_;
1794 }
1795 
GetParticleNoiseFields() const1796 const std::shared_ptr<ParticleNoiseFields>& RSProperties::GetParticleNoiseFields() const
1797 {
1798     return particleNoiseFields_;
1799 }
1800 
IfLinearGradientBlurInvalid()1801 void RSProperties::IfLinearGradientBlurInvalid()
1802 {
1803     if (linearGradientBlurPara_ != nullptr) {
1804         bool isValid = ROSEN_GE(linearGradientBlurPara_->blurRadius_, 0.0);
1805         if (!isValid) {
1806             linearGradientBlurPara_.reset();
1807         }
1808     }
1809 }
1810 
GetDynamicLightUpRate() const1811 const std::optional<float>& RSProperties::GetDynamicLightUpRate() const
1812 {
1813     return dynamicLightUpRate_;
1814 }
1815 
GetDynamicLightUpDegree() const1816 const std::optional<float>& RSProperties::GetDynamicLightUpDegree() const
1817 {
1818     return dynamicLightUpDegree_;
1819 }
1820 
GetDynamicDimDegree() const1821 const std::optional<float>& RSProperties::GetDynamicDimDegree() const
1822 {
1823     return dynamicDimDegree_;
1824 }
1825 
GetGreyCoef() const1826 const std::optional<Vector2f>& RSProperties::GetGreyCoef() const
1827 {
1828     return greyCoef_;
1829 }
1830 
IsDynamicDimValid() const1831 bool RSProperties::IsDynamicDimValid() const
1832 {
1833     return dynamicDimDegree_.has_value() &&
1834            ROSEN_GE(*dynamicDimDegree_, 0.0) && ROSEN_LNE(*dynamicDimDegree_, 1.0);
1835 }
1836 
GetFilter() const1837 const std::shared_ptr<RSFilter>& RSProperties::GetFilter() const
1838 {
1839     return filter_;
1840 }
1841 
GetMotionBlurPara() const1842 const std::shared_ptr<MotionBlurParam>& RSProperties::GetMotionBlurPara() const
1843 {
1844     return motionBlurPara_;
1845 }
1846 
IsDynamicLightUpValid() const1847 bool RSProperties::IsDynamicLightUpValid() const
1848 {
1849     return dynamicLightUpRate_.has_value() && dynamicLightUpDegree_.has_value() &&
1850            ROSEN_GNE(*dynamicLightUpRate_, 0.0) && ROSEN_GE(*dynamicLightUpDegree_, -1.0) &&
1851            ROSEN_LE(*dynamicLightUpDegree_, 1.0);
1852 }
1853 
GetForegroundFilter() const1854 const std::shared_ptr<RSFilter>& RSProperties::GetForegroundFilter() const
1855 {
1856     return foregroundFilter_;
1857 }
1858 
SetForegroundFilter(const std::shared_ptr<RSFilter> & foregroundFilter)1859 void RSProperties::SetForegroundFilter(const std::shared_ptr<RSFilter>& foregroundFilter)
1860 {
1861     foregroundFilter_ = foregroundFilter;
1862     if (foregroundFilter) {
1863         isDrawn_ = true;
1864     }
1865     SetDirty();
1866     filterNeedUpdate_ = true;
1867     contentDirty_ = true;
1868 }
1869 
1870 // shadow properties
SetShadowColor(Color color)1871 void RSProperties::SetShadowColor(Color color)
1872 {
1873     if (!shadow_.has_value()) {
1874         shadow_ = std::make_optional<RSShadow>();
1875     }
1876     shadow_->SetColor(color);
1877     SetDirty();
1878     // [planning] if shadow stores as texture and out of node
1879     // node content would not be affected
1880     contentDirty_ = true;
1881 }
1882 
SetShadowOffsetX(float offsetX)1883 void RSProperties::SetShadowOffsetX(float offsetX)
1884 {
1885     if (!shadow_.has_value()) {
1886         shadow_ = std::make_optional<RSShadow>();
1887     }
1888     shadow_->SetOffsetX(offsetX);
1889     SetDirty();
1890     filterNeedUpdate_ = true;
1891     // [planning] if shadow stores as texture and out of node
1892     // node content would not be affected
1893     contentDirty_ = true;
1894 }
1895 
SetShadowOffsetY(float offsetY)1896 void RSProperties::SetShadowOffsetY(float offsetY)
1897 {
1898     if (!shadow_.has_value()) {
1899         shadow_ = std::make_optional<RSShadow>();
1900     }
1901     shadow_->SetOffsetY(offsetY);
1902     SetDirty();
1903     filterNeedUpdate_ = true;
1904     // [planning] if shadow stores as texture and out of node
1905     // node content would not be affected
1906     contentDirty_ = true;
1907 }
1908 
SetShadowAlpha(float alpha)1909 void RSProperties::SetShadowAlpha(float alpha)
1910 {
1911     if (!shadow_.has_value()) {
1912         shadow_ = std::make_optional<RSShadow>();
1913     }
1914     shadow_->SetAlpha(alpha);
1915     if (shadow_->IsValid()) {
1916         isDrawn_ = true;
1917     }
1918     SetDirty();
1919     // [planning] if shadow stores as texture and out of node
1920     // node content would not be affected
1921     contentDirty_ = true;
1922 }
1923 
SetShadowElevation(float elevation)1924 void RSProperties::SetShadowElevation(float elevation)
1925 {
1926     if (!shadow_.has_value()) {
1927         shadow_ = std::make_optional<RSShadow>();
1928     }
1929     shadow_->SetElevation(elevation);
1930     if (shadow_->IsValid()) {
1931         isDrawn_ = true;
1932     }
1933     SetDirty();
1934     // [planning] if shadow stores as texture and out of node
1935     // node content would not be affected
1936     contentDirty_ = true;
1937 }
1938 
SetShadowRadius(float radius)1939 void RSProperties::SetShadowRadius(float radius)
1940 {
1941     if (!shadow_.has_value()) {
1942         shadow_ = std::make_optional<RSShadow>();
1943     }
1944     shadow_->SetRadius(radius);
1945     if (shadow_->IsValid()) {
1946         isDrawn_ = true;
1947     }
1948     SetDirty();
1949     filterNeedUpdate_ = true;
1950     // [planning] if shadow stores as texture and out of node
1951     // node content would not be affected
1952     contentDirty_ = true;
1953 }
1954 
SetShadowPath(std::shared_ptr<RSPath> shadowPath)1955 void RSProperties::SetShadowPath(std::shared_ptr<RSPath> shadowPath)
1956 {
1957     if (!shadow_.has_value()) {
1958         shadow_ = std::make_optional<RSShadow>();
1959     }
1960     shadow_->SetPath(shadowPath);
1961     SetDirty();
1962     // [planning] if shadow stores as texture and out of node
1963     // node content would not be affected
1964     contentDirty_ = true;
1965 }
1966 
SetShadowMask(bool shadowMask)1967 void RSProperties::SetShadowMask(bool shadowMask)
1968 {
1969     if (!shadow_.has_value()) {
1970         shadow_ = std::make_optional<RSShadow>();
1971     }
1972     shadow_->SetMask(shadowMask);
1973     SetDirty();
1974     filterNeedUpdate_ = true;
1975     // [planning] if shadow stores as texture and out of node
1976     // node content would not be affected
1977     contentDirty_ = true;
1978 }
1979 
SetShadowIsFilled(bool shadowIsFilled)1980 void RSProperties::SetShadowIsFilled(bool shadowIsFilled)
1981 {
1982     if (!shadow_.has_value()) {
1983         shadow_ = std::make_optional<RSShadow>();
1984     }
1985     shadow_->SetIsFilled(shadowIsFilled);
1986     SetDirty();
1987     // [planning] if shadow stores as texture and out of node
1988     // node content would not be affected
1989     contentDirty_ = true;
1990 }
1991 
SetShadowColorStrategy(int shadowColorStrategy)1992 void RSProperties::SetShadowColorStrategy(int shadowColorStrategy)
1993 {
1994     if (!shadow_.has_value()) {
1995         shadow_ = std::make_optional<RSShadow>();
1996     }
1997     shadow_->SetColorStrategy(shadowColorStrategy);
1998     SetDirty();
1999     filterNeedUpdate_ = true;
2000     // [planning] if shadow stores as texture and out of node
2001     // node content would not be affected
2002     contentDirty_ = true;
2003 }
2004 
GetShadowColor() const2005 const Color& RSProperties::GetShadowColor() const
2006 {
2007     static const auto DEFAULT_SPOT_COLOR_VALUE = Color::FromArgbInt(DEFAULT_SPOT_COLOR);
2008     return shadow_ ? shadow_->GetColor() : DEFAULT_SPOT_COLOR_VALUE;
2009 }
2010 
GetShadowOffsetX() const2011 float RSProperties::GetShadowOffsetX() const
2012 {
2013     return shadow_ ? shadow_->GetOffsetX() : DEFAULT_SHADOW_OFFSET_X;
2014 }
2015 
GetShadowOffsetY() const2016 float RSProperties::GetShadowOffsetY() const
2017 {
2018     return shadow_ ? shadow_->GetOffsetY() : DEFAULT_SHADOW_OFFSET_Y;
2019 }
2020 
GetShadowAlpha() const2021 float RSProperties::GetShadowAlpha() const
2022 {
2023     return shadow_ ? shadow_->GetAlpha() : 0.f;
2024 }
2025 
GetShadowElevation() const2026 float RSProperties::GetShadowElevation() const
2027 {
2028     return shadow_ ? shadow_->GetElevation() : 0.f;
2029 }
2030 
GetShadowRadius() const2031 float RSProperties::GetShadowRadius() const
2032 {
2033     return shadow_ ? shadow_->GetRadius() : DEFAULT_SHADOW_RADIUS;
2034 }
2035 
GetShadowPath() const2036 std::shared_ptr<RSPath> RSProperties::GetShadowPath() const
2037 {
2038     return shadow_ ? shadow_->GetPath() : nullptr;
2039 }
2040 
GetShadowMask() const2041 bool RSProperties::GetShadowMask() const
2042 {
2043     return shadow_ ? shadow_->GetMask() : false;
2044 }
2045 
GetShadowIsFilled() const2046 bool RSProperties::GetShadowIsFilled() const
2047 {
2048     return shadow_ ? shadow_->GetIsFilled() : false;
2049 }
2050 
GetShadowColorStrategy() const2051 int RSProperties::GetShadowColorStrategy() const
2052 {
2053     return shadow_ ? shadow_->GetColorStrategy() : SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE;
2054 }
2055 
GetShadow() const2056 const std::optional<RSShadow>& RSProperties::GetShadow() const
2057 {
2058     return shadow_;
2059 }
2060 
IsShadowValid() const2061 bool RSProperties::IsShadowValid() const
2062 {
2063     return shadow_ && shadow_->IsValid();
2064 }
2065 
SetFrameGravity(Gravity gravity)2066 void RSProperties::SetFrameGravity(Gravity gravity)
2067 {
2068     if (frameGravity_ != gravity) {
2069         frameGravity_ = gravity;
2070         SetDirty();
2071         contentDirty_ = true;
2072     }
2073 }
2074 
GetFrameGravity() const2075 Gravity RSProperties::GetFrameGravity() const
2076 {
2077     return frameGravity_;
2078 }
2079 
SetDrawRegion(const std::shared_ptr<RectF> & rect)2080 void RSProperties::SetDrawRegion(const std::shared_ptr<RectF>& rect)
2081 {
2082     drawRegion_ = rect;
2083     SetDirty();
2084     geoDirty_ = true;  // since drawRegion affect dirtyRegion, mark it as geoDirty
2085 }
2086 
GetDrawRegion() const2087 std::shared_ptr<RectF> RSProperties::GetDrawRegion() const
2088 {
2089     return drawRegion_;
2090 }
2091 
SetClipRRect(RRect clipRRect)2092 void RSProperties::SetClipRRect(RRect clipRRect)
2093 {
2094     clipRRect_ = clipRRect;
2095     if (GetClipToRRect()) {
2096         isDrawn_ = true;
2097     }
2098     SetDirty();
2099     geoDirty_ = true;  // [planning] all clip ops should be checked
2100 }
2101 
GetClipRRect() const2102 RRect RSProperties::GetClipRRect() const
2103 {
2104     return clipRRect_ ? *clipRRect_ : RRect();
2105 }
2106 
GetClipToRRect() const2107 bool RSProperties::GetClipToRRect() const
2108 {
2109     return clipRRect_.has_value() && !clipRRect_->rect_.IsEmpty();
2110 }
2111 
SetClipBounds(const std::shared_ptr<RSPath> & path)2112 void RSProperties::SetClipBounds(const std::shared_ptr<RSPath>& path)
2113 {
2114     if (path) {
2115         isDrawn_ = true;
2116     }
2117     if (clipPath_ != path) {
2118         clipPath_ = path;
2119         SetDirty();
2120         geoDirty_ = true;  // [planning] all clip ops should be checked
2121     }
2122 }
2123 
GetClipBounds() const2124 const std::shared_ptr<RSPath>& RSProperties::GetClipBounds() const
2125 {
2126     return clipPath_;
2127 }
2128 
SetClipToBounds(bool clipToBounds)2129 void RSProperties::SetClipToBounds(bool clipToBounds)
2130 {
2131     if (clipToBounds) {
2132         isDrawn_ = true;
2133     }
2134     if (clipToBounds_ != clipToBounds) {
2135         clipToBounds_ = clipToBounds;
2136         SetDirty();
2137         geoDirty_ = true;  // [planning] all clip ops should be checked
2138     }
2139 }
2140 
GetClipToBounds() const2141 bool RSProperties::GetClipToBounds() const
2142 {
2143     return clipToBounds_;
2144 }
2145 
SetClipToFrame(bool clipToFrame)2146 void RSProperties::SetClipToFrame(bool clipToFrame)
2147 {
2148     if (clipToFrame) {
2149         isDrawn_ = true;
2150     }
2151     if (clipToFrame_ != clipToFrame) {
2152         clipToFrame_ = clipToFrame;
2153         SetDirty();
2154         geoDirty_ = true;  // [planning] all clip ops should be checked
2155     }
2156 }
2157 
GetClipToFrame() const2158 bool RSProperties::GetClipToFrame() const
2159 {
2160     return clipToFrame_;
2161 }
2162 
GetLocalBoundsAndFramesRect() const2163 RectF RSProperties::GetLocalBoundsAndFramesRect() const
2164 {
2165     auto rect = GetBoundsRect();
2166     if (!clipToBounds_ && !std::isinf(GetFrameWidth()) && !std::isinf(GetFrameHeight())) {
2167         rect = rect.JoinRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2168     }
2169     return rect;
2170 }
2171 
GetBoundsRect() const2172 RectF RSProperties::GetBoundsRect() const
2173 {
2174     auto rect = RectF();
2175     if (boundsGeo_->IsEmpty()) {
2176         if (!std::isinf(GetFrameWidth()) && !std::isinf(GetFrameHeight())) {
2177             return {0, 0, GetFrameWidth(), GetFrameHeight()};
2178         }
2179     } else {
2180         if (!std::isinf(GetBoundsWidth()) && !std::isinf(GetBoundsHeight())) {
2181             return {0, 0, GetBoundsWidth(), GetBoundsHeight()};
2182         }
2183     }
2184     return rect;
2185 }
2186 
GetFrameRect() const2187 RectF RSProperties::GetFrameRect() const
2188 {
2189     return {0, 0, GetFrameWidth(), GetFrameHeight()};
2190 }
2191 
GetBgImageRect() const2192 const RectF& RSProperties::GetBgImageRect() const
2193 {
2194     return decoration_ ? decoration_->bgImageRect_ : EMPTY_RECT;
2195 }
2196 
SetVisible(bool visible)2197 void RSProperties::SetVisible(bool visible)
2198 {
2199     if (visible_ != visible) {
2200         visible_ = visible;
2201         SetDirty();
2202         contentDirty_ = true;
2203     }
2204 }
2205 
GetVisible() const2206 bool RSProperties::GetVisible() const
2207 {
2208     return visible_;
2209 }
2210 
GetRRect() const2211 const RRect& RSProperties::GetRRect() const
2212 {
2213     return rrect_;
2214 }
2215 
GenerateRRect()2216 void RSProperties::GenerateRRect()
2217 {
2218     RectF rect = GetBoundsRect();
2219     rrect_ = RRect(rect, GetCornerRadius());
2220 }
2221 
GetInnerRRect() const2222 RRect RSProperties::GetInnerRRect() const
2223 {
2224     auto rect = GetBoundsRect();
2225     Vector4f cornerRadius = GetCornerRadius();
2226     if (border_) {
2227         rect.left_ += border_->GetWidth(RSBorder::LEFT);
2228         rect.top_ += border_->GetWidth(RSBorder::TOP);
2229         rect.width_ -= border_->GetWidth(RSBorder::LEFT) + border_->GetWidth(RSBorder::RIGHT);
2230         rect.height_ -= border_->GetWidth(RSBorder::TOP) + border_->GetWidth(RSBorder::BOTTOM);
2231     }
2232     RRect rrect = RRect(rect, cornerRadius);
2233     if (border_) {
2234         rrect.radius_[0] -= { border_->GetWidth(RSBorder::LEFT), border_->GetWidth(RSBorder::TOP) };
2235         rrect.radius_[1] -= { border_->GetWidth(RSBorder::RIGHT), border_->GetWidth(RSBorder::TOP) };
2236         rrect.radius_[2] -= { border_->GetWidth(RSBorder::RIGHT), border_->GetWidth(RSBorder::BOTTOM) };
2237         rrect.radius_[3] -= { border_->GetWidth(RSBorder::LEFT), border_->GetWidth(RSBorder::BOTTOM) };
2238     }
2239     return rrect;
2240 }
2241 
NeedFilter() const2242 bool RSProperties::NeedFilter() const
2243 {
2244     return needFilter_;
2245 }
2246 
NeedClip() const2247 bool RSProperties::NeedClip() const
2248 {
2249     return clipToBounds_ || clipToFrame_;
2250 }
2251 
SetDirty()2252 void RSProperties::SetDirty()
2253 {
2254     isDirty_ = true;
2255 }
2256 
ResetDirty()2257 void RSProperties::ResetDirty()
2258 {
2259     isDirty_ = false;
2260     geoDirty_ = false;
2261     contentDirty_ = false;
2262 }
2263 
RecordCurDirtyStatus()2264 void RSProperties::RecordCurDirtyStatus()
2265 {
2266     curIsDirty_ = isDirty_;
2267     curGeoDirty_ = geoDirty_;
2268     curContentDirty_ = contentDirty_;
2269 }
2270 
AccmulateDirtyStatus()2271 void RSProperties::AccmulateDirtyStatus()
2272 {
2273     isDirty_ = isDirty_ || curIsDirty_;
2274     geoDirty_ = geoDirty_ || curGeoDirty_;
2275     contentDirty_ = contentDirty_ || curContentDirty_;
2276 }
2277 
IsDirty() const2278 bool RSProperties::IsDirty() const
2279 {
2280     return isDirty_;
2281 }
2282 
IsGeoDirty() const2283 bool RSProperties::IsGeoDirty() const
2284 {
2285     return geoDirty_;
2286 }
2287 
IsCurGeoDirty() const2288 bool RSProperties::IsCurGeoDirty() const
2289 {
2290     return curGeoDirty_;
2291 }
2292 
IsContentDirty() const2293 bool RSProperties::IsContentDirty() const
2294 {
2295     return contentDirty_;
2296 }
2297 
GetDirtyRect() const2298 RectI RSProperties::GetDirtyRect() const
2299 {
2300     RectI dirtyRect = boundsGeo_->MapAbsRect(GetLocalBoundsAndFramesRect());
2301     if (drawRegion_ == nullptr || drawRegion_->IsEmpty()) {
2302         return dirtyRect;
2303     } else {
2304         auto drawRegion = boundsGeo_->MapAbsRect(*drawRegion_);
2305         // this is used to fix the scene with drawRegion problem, which is need to be optimized
2306         drawRegion.SetRight(drawRegion.GetRight() + 1);
2307         drawRegion.SetBottom(drawRegion.GetBottom() + 1);
2308         drawRegion.SetAll(drawRegion.left_ - 1, drawRegion.top_ - 1,
2309             drawRegion.width_ + 1, drawRegion.height_ + 1);
2310         return dirtyRect.JoinRect(drawRegion);
2311     }
2312 }
2313 
GetDirtyRect(RectI & drawRegion) const2314 RectI RSProperties::GetDirtyRect(RectI& drawRegion) const
2315 {
2316     RectI dirtyRect;
2317     if (clipToBounds_ || std::isinf(GetFrameWidth()) || std::isinf(GetFrameHeight())) {
2318         dirtyRect = boundsGeo_->GetAbsRect();
2319     } else {
2320         auto frameRect =
2321             boundsGeo_->MapAbsRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2322         dirtyRect = boundsGeo_->GetAbsRect().JoinRect(frameRect);
2323     }
2324     if (drawRegion_ == nullptr || drawRegion_->IsEmpty()) {
2325         drawRegion = RectI();
2326         return dirtyRect;
2327     } else {
2328         drawRegion = boundsGeo_->MapAbsRect(*drawRegion_);
2329         // this is used to fix the scene with drawRegion problem, which is need to be optimized
2330         drawRegion.SetRight(drawRegion.GetRight() + 1);
2331         drawRegion.SetBottom(drawRegion.GetBottom() + 1);
2332         drawRegion.SetAll(drawRegion.left_ - 1, drawRegion.top_ - 1,
2333             drawRegion.width_ + 1, drawRegion.height_ + 1);
2334         return dirtyRect.JoinRect(drawRegion);
2335     }
2336 }
2337 
CheckEmptyBounds()2338 void RSProperties::CheckEmptyBounds()
2339 {
2340     // [planning] remove this func and fallback to framerect after surfacenode using frame
2341     if (!hasBounds_) {
2342         boundsGeo_->SetRect(frameGeo_->GetX(), frameGeo_->GetY(), frameGeo_->GetWidth(), frameGeo_->GetHeight());
2343     }
2344 }
2345 
2346 // mask properties
SetMask(const std::shared_ptr<RSMask> & mask)2347 void RSProperties::SetMask(const std::shared_ptr<RSMask>& mask)
2348 {
2349     mask_ = mask;
2350     if (mask_) {
2351         isDrawn_ = true;
2352     }
2353     SetDirty();
2354     contentDirty_ = true;
2355 }
2356 
GetMask() const2357 std::shared_ptr<RSMask> RSProperties::GetMask() const
2358 {
2359     return mask_;
2360 }
2361 
SetSpherize(float spherizeDegree)2362 void RSProperties::SetSpherize(float spherizeDegree)
2363 {
2364     spherizeDegree_ = spherizeDegree;
2365     isSpherizeValid_ = spherizeDegree_ > SPHERIZE_VALID_EPSILON;
2366     if (isSpherizeValid_) {
2367         isDrawn_ = true;
2368     }
2369     filterNeedUpdate_ = true;
2370     SetDirty();
2371 }
2372 
GetSpherize() const2373 float RSProperties::GetSpherize() const
2374 {
2375     return spherizeDegree_;
2376 }
2377 
IsSpherizeValid() const2378 bool RSProperties::IsSpherizeValid() const
2379 {
2380     return isSpherizeValid_;
2381 }
2382 
CreateFlyOutShaderFilter()2383 void RSProperties::CreateFlyOutShaderFilter()
2384 {
2385     uint32_t flyMode = flyOutParams_->flyMode;
2386     auto flyOutShaderFilter = std::make_shared<RSFlyOutShaderFilter>(flyOutDegree_, flyMode);
2387     foregroundFilter_ = flyOutShaderFilter;
2388 }
2389 
SetLightUpEffect(float lightUpEffectDegree)2390 void RSProperties::SetLightUpEffect(float lightUpEffectDegree)
2391 {
2392     lightUpEffectDegree_ = lightUpEffectDegree;
2393     if (IsLightUpEffectValid()) {
2394         isDrawn_ = true;
2395     }
2396     filterNeedUpdate_ = true;
2397     SetDirty();
2398     contentDirty_ = true;
2399 }
2400 
GetLightUpEffect() const2401 float RSProperties::GetLightUpEffect() const
2402 {
2403     return lightUpEffectDegree_;
2404 }
2405 
IsLightUpEffectValid() const2406 bool RSProperties::IsLightUpEffectValid() const
2407 {
2408     return ROSEN_GE(GetLightUpEffect(), 0.0) && ROSEN_LNE(GetLightUpEffect(), 1.0);
2409 }
2410 
2411 // filter property
SetBackgroundBlurRadius(float backgroundBlurRadius)2412 void RSProperties::SetBackgroundBlurRadius(float backgroundBlurRadius)
2413 {
2414     backgroundBlurRadius_ = backgroundBlurRadius;
2415     if (IsBackgroundBlurRadiusValid()) {
2416         isDrawn_ = true;
2417     }
2418     filterNeedUpdate_ = true;
2419     SetDirty();
2420     contentDirty_ = true;
2421 }
2422 
GetBackgroundBlurRadius() const2423 float RSProperties::GetBackgroundBlurRadius() const
2424 {
2425     return backgroundBlurRadius_;
2426 }
2427 
IsBackgroundBlurRadiusValid() const2428 bool RSProperties::IsBackgroundBlurRadiusValid() const
2429 {
2430     return ROSEN_GNE(GetBackgroundBlurRadius(), 0.9f); // Adjust the materialBlur radius to 0.9 for the spring curve
2431 }
2432 
SetBackgroundBlurSaturation(float backgroundBlurSaturation)2433 void RSProperties::SetBackgroundBlurSaturation(float backgroundBlurSaturation)
2434 {
2435     backgroundBlurSaturation_ = backgroundBlurSaturation;
2436     if (IsBackgroundBlurSaturationValid()) {
2437         isDrawn_ = true;
2438     }
2439     filterNeedUpdate_ = true;
2440     SetDirty();
2441     contentDirty_ = true;
2442 }
2443 
GetBackgroundBlurSaturation() const2444 float RSProperties::GetBackgroundBlurSaturation() const
2445 {
2446     return backgroundBlurSaturation_;
2447 }
2448 
IsBackgroundBlurSaturationValid() const2449 bool RSProperties::IsBackgroundBlurSaturationValid() const
2450 {
2451     return (!ROSEN_EQ(GetBackgroundBlurSaturation(), 1.0f)) && ROSEN_GE(GetBackgroundBlurSaturation(), 0.0f);
2452 }
2453 
SetBackgroundBlurBrightness(float backgroundBlurBrightness)2454 void RSProperties::SetBackgroundBlurBrightness(float backgroundBlurBrightness)
2455 {
2456     backgroundBlurBrightness_ = backgroundBlurBrightness;
2457     if (IsBackgroundBlurBrightnessValid()) {
2458         isDrawn_ = true;
2459     }
2460     filterNeedUpdate_ = true;
2461     SetDirty();
2462     contentDirty_ = true;
2463 }
2464 
GetBackgroundBlurBrightness() const2465 float RSProperties::GetBackgroundBlurBrightness() const
2466 {
2467     return backgroundBlurBrightness_;
2468 }
2469 
IsBackgroundBlurBrightnessValid() const2470 bool RSProperties::IsBackgroundBlurBrightnessValid() const
2471 {
2472     return (!ROSEN_EQ(GetBackgroundBlurBrightness(), 1.0f)) && ROSEN_GE(GetBackgroundBlurBrightness(), 0.0f);
2473 }
2474 
SetBackgroundBlurMaskColor(Color backgroundMaskColor)2475 void RSProperties::SetBackgroundBlurMaskColor(Color backgroundMaskColor)
2476 {
2477     backgroundMaskColor_ = backgroundMaskColor;
2478     if (IsBackgroundBlurMaskColorValid()) {
2479         isDrawn_ = true;
2480     }
2481     filterNeedUpdate_ = true;
2482     SetDirty();
2483     contentDirty_ = true;
2484 }
2485 
GetBackgroundBlurMaskColor() const2486 const Color& RSProperties::GetBackgroundBlurMaskColor() const
2487 {
2488     return backgroundMaskColor_;
2489 }
2490 
IsBackgroundBlurMaskColorValid() const2491 bool RSProperties::IsBackgroundBlurMaskColorValid() const
2492 {
2493     return backgroundMaskColor_ != RSColor();
2494 }
2495 
SetBackgroundBlurColorMode(int backgroundColorMode)2496 void RSProperties::SetBackgroundBlurColorMode(int backgroundColorMode)
2497 {
2498     backgroundColorMode_ = backgroundColorMode;
2499     filterNeedUpdate_ = true;
2500     SetDirty();
2501     contentDirty_ = true;
2502 }
2503 
GetBackgroundBlurColorMode() const2504 int RSProperties::GetBackgroundBlurColorMode() const
2505 {
2506     return backgroundColorMode_;
2507 }
2508 
SetBackgroundBlurRadiusX(float backgroundBlurRadiusX)2509 void RSProperties::SetBackgroundBlurRadiusX(float backgroundBlurRadiusX)
2510 {
2511     backgroundBlurRadiusX_ = backgroundBlurRadiusX;
2512     if (IsBackgroundBlurRadiusXValid()) {
2513         isDrawn_ = true;
2514     }
2515     filterNeedUpdate_ = true;
2516     SetDirty();
2517     contentDirty_ = true;
2518 }
2519 
GetBackgroundBlurRadiusX() const2520 float RSProperties::GetBackgroundBlurRadiusX() const
2521 {
2522     return backgroundBlurRadiusX_;
2523 }
2524 
IsBackgroundBlurRadiusXValid() const2525 bool RSProperties::IsBackgroundBlurRadiusXValid() const
2526 {
2527     return ROSEN_GNE(GetBackgroundBlurRadiusX(), 0.999f);
2528 }
2529 
SetBackgroundBlurRadiusY(float backgroundBlurRadiusY)2530 void RSProperties::SetBackgroundBlurRadiusY(float backgroundBlurRadiusY)
2531 {
2532     backgroundBlurRadiusY_ = backgroundBlurRadiusY;
2533     if (IsBackgroundBlurRadiusYValid()) {
2534         isDrawn_ = true;
2535     }
2536     filterNeedUpdate_ = true;
2537     SetDirty();
2538     contentDirty_ = true;
2539 }
2540 
GetBackgroundBlurRadiusY() const2541 float RSProperties::GetBackgroundBlurRadiusY() const
2542 {
2543     return backgroundBlurRadiusY_;
2544 }
2545 
IsBackgroundBlurRadiusYValid() const2546 bool RSProperties::IsBackgroundBlurRadiusYValid() const
2547 {
2548     return ROSEN_GNE(GetBackgroundBlurRadiusY(), 0.999f);
2549 }
2550 
SetForegroundBlurRadius(float foregroundBlurRadius)2551 void RSProperties::SetForegroundBlurRadius(float foregroundBlurRadius)
2552 {
2553     foregroundBlurRadius_ = foregroundBlurRadius;
2554     if (IsForegroundBlurRadiusValid()) {
2555         isDrawn_ = true;
2556     }
2557     filterNeedUpdate_ = true;
2558     SetDirty();
2559     contentDirty_ = true;
2560 }
2561 
GetForegroundBlurRadius() const2562 float RSProperties::GetForegroundBlurRadius() const
2563 {
2564     return foregroundBlurRadius_;
2565 }
2566 
IsForegroundBlurRadiusValid() const2567 bool RSProperties::IsForegroundBlurRadiusValid() const
2568 {
2569     return ROSEN_GNE(GetForegroundBlurRadius(), 0.9f); // Adjust the materialBlur radius to 0.9 for the spring curve
2570 }
2571 
SetForegroundBlurSaturation(float foregroundBlurSaturation)2572 void RSProperties::SetForegroundBlurSaturation(float foregroundBlurSaturation)
2573 {
2574     foregroundBlurSaturation_ = foregroundBlurSaturation;
2575     if (IsForegroundBlurSaturationValid()) {
2576         isDrawn_ = true;
2577     }
2578     filterNeedUpdate_ = true;
2579     SetDirty();
2580     contentDirty_ = true;
2581 }
2582 
GetForegroundBlurSaturation() const2583 float RSProperties::GetForegroundBlurSaturation() const
2584 {
2585     return foregroundBlurSaturation_;
2586 }
2587 
IsForegroundBlurSaturationValid() const2588 bool RSProperties::IsForegroundBlurSaturationValid() const
2589 {
2590     return ROSEN_GE(GetForegroundBlurSaturation(), 1.0);
2591 }
2592 
SetForegroundBlurBrightness(float foregroundBlurBrightness)2593 void RSProperties::SetForegroundBlurBrightness(float foregroundBlurBrightness)
2594 {
2595     foregroundBlurBrightness_ = foregroundBlurBrightness;
2596     if (IsForegroundBlurBrightnessValid()) {
2597         isDrawn_ = true;
2598     }
2599     filterNeedUpdate_ = true;
2600     SetDirty();
2601     contentDirty_ = true;
2602 }
2603 
GetForegroundBlurBrightness() const2604 float RSProperties::GetForegroundBlurBrightness() const
2605 {
2606     return foregroundBlurBrightness_;
2607 }
2608 
IsForegroundBlurBrightnessValid() const2609 bool RSProperties::IsForegroundBlurBrightnessValid() const
2610 {
2611     return ROSEN_GE(GetForegroundBlurBrightness(), 1.0);
2612 }
2613 
SetForegroundBlurMaskColor(Color foregroundMaskColor)2614 void RSProperties::SetForegroundBlurMaskColor(Color foregroundMaskColor)
2615 {
2616     foregroundMaskColor_ = foregroundMaskColor;
2617     if (IsForegroundBlurMaskColorValid()) {
2618         isDrawn_ = true;
2619     }
2620     filterNeedUpdate_ = true;
2621     SetDirty();
2622     contentDirty_ = true;
2623 }
2624 
GetForegroundBlurMaskColor() const2625 const Color& RSProperties::GetForegroundBlurMaskColor() const
2626 {
2627     return foregroundMaskColor_;
2628 }
2629 
IsForegroundBlurMaskColorValid() const2630 bool RSProperties::IsForegroundBlurMaskColorValid() const
2631 {
2632     return foregroundMaskColor_ != RSColor();
2633 }
2634 
SetForegroundBlurColorMode(int foregroundColorMode)2635 void RSProperties::SetForegroundBlurColorMode(int foregroundColorMode)
2636 {
2637     foregroundColorMode_ = foregroundColorMode;
2638     filterNeedUpdate_ = true;
2639     SetDirty();
2640     contentDirty_ = true;
2641 }
2642 
GetForegroundBlurColorMode() const2643 int RSProperties::GetForegroundBlurColorMode() const
2644 {
2645     return foregroundColorMode_;
2646 }
2647 
SetForegroundBlurRadiusX(float foregroundBlurRadiusX)2648 void RSProperties::SetForegroundBlurRadiusX(float foregroundBlurRadiusX)
2649 {
2650     foregroundBlurRadiusX_ = foregroundBlurRadiusX;
2651     if (IsForegroundBlurRadiusXValid()) {
2652         isDrawn_ = true;
2653     }
2654     filterNeedUpdate_ = true;
2655     SetDirty();
2656     contentDirty_ = true;
2657 }
2658 
GetForegroundBlurRadiusX() const2659 float RSProperties::GetForegroundBlurRadiusX() const
2660 {
2661     return foregroundBlurRadiusX_;
2662 }
2663 
IsForegroundBlurRadiusXValid() const2664 bool RSProperties::IsForegroundBlurRadiusXValid() const
2665 {
2666     return ROSEN_GNE(GetForegroundBlurRadiusX(), 0.999f);
2667 }
2668 
SetForegroundBlurRadiusY(float foregroundBlurRadiusY)2669 void RSProperties::SetForegroundBlurRadiusY(float foregroundBlurRadiusY)
2670 {
2671     foregroundBlurRadiusY_ = foregroundBlurRadiusY;
2672     if (IsForegroundBlurRadiusYValid()) {
2673         isDrawn_ = true;
2674     }
2675     filterNeedUpdate_ = true;
2676     SetDirty();
2677     contentDirty_ = true;
2678 }
2679 
GetForegroundBlurRadiusY() const2680 float RSProperties::GetForegroundBlurRadiusY() const
2681 {
2682     return foregroundBlurRadiusY_;
2683 }
2684 
IsForegroundBlurRadiusYValid() const2685 bool RSProperties::IsForegroundBlurRadiusYValid() const
2686 {
2687     return ROSEN_GNE(GetForegroundBlurRadiusY(), 0.999f);
2688 }
2689 
IsBackgroundMaterialFilterValid() const2690 bool RSProperties::IsBackgroundMaterialFilterValid() const
2691 {
2692     return IsBackgroundBlurRadiusValid() || IsBackgroundBlurBrightnessValid() || IsBackgroundBlurSaturationValid();
2693 }
2694 
IsForegroundMaterialFilterVaild() const2695 bool RSProperties::IsForegroundMaterialFilterVaild() const
2696 {
2697     return IsForegroundBlurRadiusValid();
2698 }
2699 
GetMaterialColorFilter(float sat,float brightness)2700 std::shared_ptr<Drawing::ColorFilter> RSProperties::GetMaterialColorFilter(float sat, float brightness)
2701 {
2702     float normalizedDegree = brightness - 1.0;
2703     const float brightnessMat[] = {
2704         1.000000f, 0.000000f, 0.000000f, 0.000000f, normalizedDegree,
2705         0.000000f, 1.000000f, 0.000000f, 0.000000f, normalizedDegree,
2706         0.000000f, 0.000000f, 1.000000f, 0.000000f, normalizedDegree,
2707         0.000000f, 0.000000f, 0.000000f, 1.000000f, 0.000000f,
2708     };
2709     Drawing::ColorMatrix cm;
2710     cm.SetSaturation(sat);
2711     float cmArray[Drawing::ColorMatrix::MATRIX_SIZE];
2712     cm.GetArray(cmArray);
2713     std::shared_ptr<Drawing::ColorFilter> filterCompose =
2714         Drawing::ColorFilter::CreateComposeColorFilter(cmArray, brightnessMat, Drawing::Clamp::NO_CLAMP);
2715     return filterCompose;
2716 }
2717 
GenerateBackgroundBlurFilter()2718 void RSProperties::GenerateBackgroundBlurFilter()
2719 {
2720     std::shared_ptr<Drawing::ImageFilter> blurFilter = Drawing::ImageFilter::CreateBlurImageFilter(
2721         backgroundBlurRadiusX_, backgroundBlurRadiusY_, Drawing::TileMode::CLAMP, nullptr);
2722     uint32_t hash = SkOpts::hash(&backgroundBlurRadiusX_, sizeof(backgroundBlurRadiusX_), 0);
2723     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2724 
2725     // fuse grey-adjustment and pixel-stretch with blur filter
2726     if (NeedBlurFuzed()) {
2727         std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
2728         if (greyCoef_.has_value()) {
2729             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadiusX_,
2730                 greyCoef_->x_, greyCoef_->y_);
2731         } else {
2732             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadiusX_);
2733         }
2734         originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
2735         originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadiusX_));
2736         backgroundFilter_ = originalFilter;
2737         backgroundFilter_->SetFilterType(RSFilter::BLUR);
2738         return;
2739     }
2740 
2741     if (greyCoef_.has_value()) {
2742         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2743             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2744         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2745     }
2746 
2747     if (RSSystemProperties::GetKawaseEnabled()) {
2748         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2749             std::make_shared<RSKawaseBlurShaderFilter>(backgroundBlurRadiusX_);
2750         if (originalFilter == nullptr) {
2751             originalFilter = std::make_shared<RSDrawingFilter>(kawaseBlurFilter);
2752         } else {
2753             originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
2754         }
2755     } else {
2756         if (originalFilter == nullptr) {
2757             originalFilter = std::make_shared<RSDrawingFilter>(blurFilter, hash);
2758         } else {
2759             originalFilter = originalFilter->Compose(blurFilter, hash);
2760         }
2761     }
2762     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadiusX_));
2763     backgroundFilter_ = originalFilter;
2764     backgroundFilter_->SetFilterType(RSFilter::BLUR);
2765 }
2766 
GenerateBackgroundMaterialBlurFilter()2767 void RSProperties::GenerateBackgroundMaterialBlurFilter()
2768 {
2769     if (backgroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
2770         backgroundColorMode_ = BLUR_COLOR_MODE::AVERAGE;
2771     }
2772     uint32_t hash = SkOpts::hash(&backgroundBlurRadius_, sizeof(backgroundBlurRadius_), 0);
2773     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
2774         backgroundBlurSaturation_, backgroundBlurBrightness_);
2775     std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
2776         Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, backgroundBlurRadius_, backgroundBlurRadius_);
2777 
2778     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2779 
2780     // fuse grey-adjustment and pixel-stretch with blur filter
2781     if (NeedBlurFuzed()) {
2782         GenerateBackgroundMaterialFuzedBlurFilter();
2783         return;
2784     }
2785 
2786     if (greyCoef_.has_value()) {
2787         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2788             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2789         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2790     }
2791 
2792     if (RSSystemProperties::GetKawaseEnabled()) {
2793         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2794             std::make_shared<RSKawaseBlurShaderFilter>(backgroundBlurRadius_);
2795         auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
2796         originalFilter = originalFilter?
2797             originalFilter->Compose(colorImageFilter, hash) : std::make_shared<RSDrawingFilter>(colorImageFilter, hash);
2798         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
2799     } else {
2800         hash = SkOpts::hash(&backgroundBlurSaturation_, sizeof(backgroundBlurSaturation_), hash);
2801         hash = SkOpts::hash(&backgroundBlurBrightness_, sizeof(backgroundBlurBrightness_), hash);
2802         originalFilter = originalFilter?
2803             originalFilter->Compose(blurColorFilter, hash) : std::make_shared<RSDrawingFilter>(blurColorFilter, hash);
2804     }
2805     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
2806         backgroundColorMode_, backgroundMaskColor_);
2807     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
2808     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadius_));
2809     originalFilter->SetSaturationForHPS(backgroundBlurSaturation_);
2810     originalFilter->SetBrightnessForHPS(backgroundBlurBrightness_);
2811     backgroundFilter_ = originalFilter;
2812     backgroundFilter_->SetFilterType(RSFilter::MATERIAL);
2813 }
2814 
GenerateForegroundBlurFilter()2815 void RSProperties::GenerateForegroundBlurFilter()
2816 {
2817     std::shared_ptr<Drawing::ImageFilter> blurFilter = Drawing::ImageFilter::CreateBlurImageFilter(
2818         foregroundBlurRadiusX_, foregroundBlurRadiusY_, Drawing::TileMode::CLAMP, nullptr);
2819     uint32_t hash = SkOpts::hash(&foregroundBlurRadiusX_, sizeof(foregroundBlurRadiusX_), 0);
2820     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2821 
2822     // fuse grey-adjustment and pixel-stretch with blur filter
2823     if (NeedBlurFuzed()) {
2824         std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
2825         if (greyCoef_.has_value()) {
2826             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadiusX_,
2827                 greyCoef_->x_, greyCoef_->y_);
2828         } else {
2829             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadiusX_);
2830         }
2831         originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
2832         originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadiusX_));
2833         filter_ = originalFilter;
2834         filter_->SetFilterType(RSFilter::BLUR);
2835         return;
2836     }
2837 
2838     if (greyCoef_.has_value()) {
2839         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2840             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2841         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2842     }
2843     if (RSSystemProperties::GetKawaseEnabled()) {
2844         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2845             std::make_shared<RSKawaseBlurShaderFilter>(foregroundBlurRadiusX_);
2846         if (originalFilter == nullptr) {
2847             originalFilter = std::make_shared<RSDrawingFilter>(kawaseBlurFilter);
2848         } else {
2849             originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
2850         }
2851     } else {
2852         if (originalFilter == nullptr) {
2853             originalFilter = std::make_shared<RSDrawingFilter>(blurFilter, hash);
2854         } else {
2855             originalFilter = originalFilter->Compose(blurFilter, hash);
2856         }
2857     }
2858     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadiusX_));
2859     filter_ = originalFilter;
2860     filter_->SetFilterType(RSFilter::BLUR);
2861 }
2862 
GenerateForegroundMaterialBlurFilter()2863 void RSProperties::GenerateForegroundMaterialBlurFilter()
2864 {
2865     if (foregroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
2866         foregroundColorMode_ = BLUR_COLOR_MODE::AVERAGE;
2867     }
2868     uint32_t hash = SkOpts::hash(&foregroundBlurRadius_, sizeof(foregroundBlurRadius_), 0);
2869     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
2870         foregroundBlurSaturation_, foregroundBlurBrightness_);
2871     std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
2872         Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, foregroundBlurRadius_, foregroundBlurRadius_);
2873 
2874     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2875 
2876     // fuse grey-adjustment and pixel-stretch with blur filter
2877     if (NeedBlurFuzed()) {
2878         GenerateCompositingMaterialFuzedBlurFilter();
2879         return;
2880     }
2881 
2882     if (greyCoef_.has_value()) {
2883         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2884             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2885         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2886     }
2887 
2888     if (RSSystemProperties::GetKawaseEnabled()) {
2889         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2890             std::make_shared<RSKawaseBlurShaderFilter>(foregroundBlurRadius_);
2891         auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
2892         originalFilter = originalFilter?
2893             originalFilter->Compose(colorImageFilter, hash) : std::make_shared<RSDrawingFilter>(colorImageFilter, hash);
2894         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
2895     } else {
2896         hash = SkOpts::hash(&foregroundBlurSaturation_, sizeof(foregroundBlurSaturation_), hash);
2897         hash = SkOpts::hash(&foregroundBlurBrightness_, sizeof(foregroundBlurBrightness_), hash);
2898         originalFilter = originalFilter?
2899             originalFilter->Compose(blurColorFilter, hash) : std::make_shared<RSDrawingFilter>(blurColorFilter, hash);
2900     }
2901     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
2902         foregroundColorMode_, foregroundMaskColor_);
2903     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
2904     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadius_));
2905     originalFilter->SetSaturationForHPS(foregroundBlurSaturation_);
2906     originalFilter->SetBrightnessForHPS(foregroundBlurBrightness_);
2907     filter_ = originalFilter;
2908     filter_->SetFilterType(RSFilter::MATERIAL);
2909 }
2910 
GenerateBackgroundMaterialFuzedBlurFilter()2911 void RSProperties::GenerateBackgroundMaterialFuzedBlurFilter()
2912 {
2913     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2914     std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
2915     if (greyCoef_.has_value()) {
2916         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadius_,
2917             greyCoef_->x_, greyCoef_->y_);
2918     } else {
2919         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadius_);
2920     }
2921     originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
2922     uint32_t hash = SkOpts::hash(&backgroundBlurRadius_, sizeof(backgroundBlurRadius_), 0);
2923     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
2924         backgroundBlurSaturation_, backgroundBlurBrightness_);
2925     auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
2926     originalFilter = originalFilter->Compose(colorImageFilter, hash);
2927     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
2928         backgroundColorMode_, backgroundMaskColor_);
2929     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
2930     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadius_));
2931     backgroundFilter_ = originalFilter;
2932     backgroundFilter_->SetFilterType(RSFilter::MATERIAL);
2933 }
2934 
GenerateCompositingMaterialFuzedBlurFilter()2935 void RSProperties::GenerateCompositingMaterialFuzedBlurFilter()
2936 {
2937     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2938     std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
2939     if (greyCoef_.has_value()) {
2940         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadius_,
2941             greyCoef_->x_, greyCoef_->y_);
2942     } else {
2943         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadius_);
2944     }
2945     originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
2946     uint32_t hash = SkOpts::hash(&foregroundBlurRadius_, sizeof(foregroundBlurRadius_), 0);
2947     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
2948         foregroundBlurSaturation_, foregroundBlurBrightness_);
2949     auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
2950     originalFilter = originalFilter->Compose(colorImageFilter, hash);
2951     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
2952         foregroundColorMode_, foregroundMaskColor_);
2953     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
2954     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadius_));
2955     filter_ = originalFilter;
2956     filter_->SetFilterType(RSFilter::MATERIAL);
2957 }
2958 
GenerateAIBarFilter()2959 void RSProperties::GenerateAIBarFilter()
2960 {
2961     std::vector<float> aiInvertCoef = RSAIBarShaderFilter::GetAiInvertCoef();
2962     float aiBarRadius = aiInvertCoef[5]; // aiInvertCoef[5] is filter_radius
2963     std::shared_ptr<Drawing::ImageFilter> blurFilter =
2964         Drawing::ImageFilter::CreateBlurImageFilter(aiBarRadius, aiBarRadius, Drawing::TileMode::CLAMP, nullptr);
2965     std::shared_ptr<RSAIBarShaderFilter> aiBarShaderFilter = std::make_shared<RSAIBarShaderFilter>();
2966     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(aiBarShaderFilter);
2967 
2968     if (RSSystemProperties::GetKawaseEnabled()) {
2969         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2970             std::make_shared<RSKawaseBlurShaderFilter>(aiBarRadius);
2971         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
2972     } else {
2973         uint32_t hash = SkOpts::hash(&aiBarRadius, sizeof(aiBarRadius), 0);
2974         originalFilter = originalFilter->Compose(blurFilter, hash);
2975     }
2976     backgroundFilter_ = originalFilter;
2977     backgroundFilter_->SetFilterType(RSFilter::AIBAR);
2978 }
2979 
GenerateLinearGradientBlurFilter()2980 void RSProperties::GenerateLinearGradientBlurFilter()
2981 {
2982     auto linearBlurFilter = std::make_shared<RSLinearGradientBlurShaderFilter>(linearGradientBlurPara_,
2983         frameGeo_->GetWidth(), frameGeo_->GetHeight());
2984     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(linearBlurFilter);
2985 
2986     filter_ = originalFilter;
2987     filter_->SetFilterType(RSFilter::LINEAR_GRADIENT_BLUR);
2988 }
2989 
GenerateMagnifierFilter()2990 void RSProperties::GenerateMagnifierFilter()
2991 {
2992     auto magnifierFilter = std::make_shared<RSMagnifierShaderFilter>(magnifierPara_);
2993 
2994     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(magnifierFilter);
2995     backgroundFilter_ = originalFilter;
2996     backgroundFilter_->SetFilterType(RSFilter::MAGNIFIER);
2997 }
2998 
GenerateWaterRippleFilter()2999 void RSProperties::GenerateWaterRippleFilter()
3000 {
3001     uint32_t waveCount = waterRippleParams_->waveCount;
3002     float rippleCenterX = waterRippleParams_->rippleCenterX;
3003     float rippleCenterY = waterRippleParams_->rippleCenterY;
3004     uint32_t rippleMode = waterRippleParams_->rippleMode;
3005     std::shared_ptr<RSWaterRippleShaderFilter> waterRippleFilter =
3006         std::make_shared<RSWaterRippleShaderFilter>(waterRippleProgress_, waveCount, rippleCenterX, rippleCenterY,
3007             rippleMode);
3008     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(waterRippleFilter);
3009     if (!backgroundFilter_) {
3010         backgroundFilter_ = originalFilter;
3011         backgroundFilter_->SetFilterType(RSFilter::WATER_RIPPLE);
3012     } else {
3013         auto backgroudDrawingFilter = std::static_pointer_cast<RSDrawingFilter>(backgroundFilter_);
3014         backgroudDrawingFilter->Compose(waterRippleFilter);
3015         backgroudDrawingFilter->SetFilterType(RSFilter::COMPOUND_EFFECT);
3016         backgroundFilter_ = backgroudDrawingFilter;
3017     }
3018 }
3019 
GenerateBackgroundFilter()3020 void RSProperties::GenerateBackgroundFilter()
3021 {
3022     if (aiInvert_.has_value() || systemBarEffect_) {
3023         GenerateAIBarFilter();
3024     } else if (magnifierPara_ && ROSEN_GNE(magnifierPara_->factor_, 0.f)) {
3025         GenerateMagnifierFilter();
3026     } else if (IsBackgroundMaterialFilterValid()) {
3027         GenerateBackgroundMaterialBlurFilter();
3028     } else if (IsBackgroundBlurRadiusXValid() && IsBackgroundBlurRadiusYValid()) {
3029         GenerateBackgroundBlurFilter();
3030     } else {
3031         backgroundFilter_ = nullptr;
3032     }
3033     if (IsWaterRippleValid()) {
3034         GenerateWaterRippleFilter();
3035     }
3036     if (backgroundFilter_ == nullptr) {
3037         ROSEN_LOGD("RSProperties::GenerateBackgroundFilter failed");
3038     }
3039 }
3040 
GenerateForegroundFilter()3041 void RSProperties::GenerateForegroundFilter()
3042 {
3043     IfLinearGradientBlurInvalid();
3044     if (linearGradientBlurPara_) {
3045         GenerateLinearGradientBlurFilter();
3046     } else if (IsForegroundMaterialFilterVaild()) {
3047         GenerateForegroundMaterialBlurFilter();
3048     } else if (IsForegroundBlurRadiusXValid() && IsForegroundBlurRadiusYValid()) {
3049         GenerateForegroundBlurFilter();
3050     } else {
3051         filter_ = nullptr;
3052     }
3053     if (filter_ == nullptr) {
3054         ROSEN_LOGD("RSProperties::GenerateForegroundFilter failed");
3055     }
3056 }
3057 
SetUseEffect(bool useEffect)3058 void RSProperties::SetUseEffect(bool useEffect)
3059 {
3060     useEffect_ = useEffect;
3061     if (GetUseEffect()) {
3062         isDrawn_ = true;
3063     }
3064     filterNeedUpdate_ = true;
3065     SetDirty();
3066 }
3067 
GetUseEffect() const3068 bool RSProperties::GetUseEffect() const
3069 {
3070     return useEffect_;
3071 }
3072 
SetUseShadowBatching(bool useShadowBatching)3073 void RSProperties::SetUseShadowBatching(bool useShadowBatching)
3074 {
3075     if (useShadowBatching) {
3076         isDrawn_ = true;
3077     }
3078     useShadowBatching_ = useShadowBatching;
3079     SetDirty();
3080 }
3081 
SetPixelStretch(const std::optional<Vector4f> & stretchSize)3082 void RSProperties::SetPixelStretch(const std::optional<Vector4f>& stretchSize)
3083 {
3084     pixelStretch_ = stretchSize;
3085     SetDirty();
3086     pixelStretchNeedUpdate_ = true;
3087     contentDirty_ = true;
3088     if (pixelStretch_.has_value() && pixelStretch_->IsZero()) {
3089         pixelStretch_ = std::nullopt;
3090     }
3091 }
3092 
GetPixelStretchDirtyRect() const3093 RectI RSProperties::GetPixelStretchDirtyRect() const
3094 {
3095     auto dirtyRect = GetDirtyRect();
3096 
3097     auto scaledBounds = RectF(dirtyRect.left_ - pixelStretch_->x_, dirtyRect.top_ - pixelStretch_->y_,
3098         dirtyRect.width_ + pixelStretch_->x_ + pixelStretch_->z_,
3099         dirtyRect.height_ + pixelStretch_->y_ + pixelStretch_->w_);
3100 
3101     auto scaledIBounds = RectI(std::floor(scaledBounds.left_), std::floor(scaledBounds.top_),
3102         std::ceil(scaledBounds.width_) + 1, std::ceil(scaledBounds.height_) + 1);
3103     return dirtyRect.JoinRect(scaledIBounds);
3104 }
3105 
SetPixelStretchPercent(const std::optional<Vector4f> & stretchPercent)3106 void RSProperties::SetPixelStretchPercent(const std::optional<Vector4f>& stretchPercent)
3107 {
3108     pixelStretchPercent_ = stretchPercent;
3109     SetDirty();
3110     pixelStretchNeedUpdate_ = true;
3111     contentDirty_ = true;
3112     if (pixelStretchPercent_.has_value() && pixelStretchPercent_->IsZero()) {
3113         pixelStretchPercent_ = std::nullopt;
3114     }
3115 }
3116 
SetPixelStretchTileMode(int stretchTileMode)3117 void RSProperties::SetPixelStretchTileMode(int stretchTileMode)
3118 {
3119     pixelStretchTileMode_ = std::clamp<int>(stretchTileMode, static_cast<int>(Drawing::TileMode::CLAMP),
3120         static_cast<int>(Drawing::TileMode::DECAL));
3121     SetDirty();
3122     pixelStretchNeedUpdate_ = true;
3123     contentDirty_ = true;
3124 }
3125 
GetPixelStretchTileMode() const3126 int RSProperties::GetPixelStretchTileMode() const
3127 {
3128     return pixelStretchTileMode_;
3129 }
3130 
3131 // Image effect properties
SetGrayScale(const std::optional<float> & grayScale)3132 void RSProperties::SetGrayScale(const std::optional<float>& grayScale)
3133 {
3134     grayScale_ = grayScale;
3135     colorFilterNeedUpdate_ = true;
3136     SetDirty();
3137     contentDirty_ = true;
3138 }
3139 
SetLightIntensity(float lightIntensity)3140 void RSProperties::SetLightIntensity(float lightIntensity)
3141 {
3142     if (!lightSourcePtr_) {
3143         lightSourcePtr_ = std::make_shared<RSLightSource>();
3144     }
3145     lightSourcePtr_->SetLightIntensity(lightIntensity);
3146     SetDirty();
3147     contentDirty_ = true;
3148 
3149     if (ROSEN_EQ(lightIntensity, INVALID_INTENSITY)) { // skip when resetFunc call
3150         return;
3151     }
3152     auto preIntensity = lightSourcePtr_->GetPreLightIntensity();
3153     auto renderNode = backref_.lock();
3154     bool preIntensityIsZero = ROSEN_EQ(preIntensity, 0.f);
3155     bool curIntensityIsZero = ROSEN_EQ(lightIntensity, 0.f);
3156     if (preIntensityIsZero && !curIntensityIsZero) { // 0 --> non-zero
3157         RSPointLightManager::Instance()->RegisterLightSource(renderNode);
3158     } else if (!preIntensityIsZero && curIntensityIsZero) { // non-zero --> 0
3159         RSPointLightManager::Instance()->UnRegisterLightSource(renderNode);
3160     }
3161 }
3162 
SetLightColor(Color lightColor)3163 void RSProperties::SetLightColor(Color lightColor)
3164 {
3165     if (!lightSourcePtr_) {
3166         lightSourcePtr_ = std::make_shared<RSLightSource>();
3167     }
3168     lightSourcePtr_->SetLightColor(lightColor);
3169     SetDirty();
3170     contentDirty_ = true;
3171 }
3172 
SetLightPosition(const Vector4f & lightPosition)3173 void RSProperties::SetLightPosition(const Vector4f& lightPosition)
3174 {
3175     if (!lightSourcePtr_) {
3176         lightSourcePtr_ = std::make_shared<RSLightSource>();
3177     }
3178     lightSourcePtr_->SetLightPosition(lightPosition);
3179     SetDirty();
3180     contentDirty_ = true;
3181 }
3182 
SetIlluminatedBorderWidth(float illuminatedBorderWidth)3183 void RSProperties::SetIlluminatedBorderWidth(float illuminatedBorderWidth)
3184 {
3185     if (!illuminatedPtr_) {
3186         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3187     }
3188     illuminatedPtr_->SetIlluminatedBorderWidth(illuminatedBorderWidth);
3189     SetDirty();
3190     contentDirty_ = true;
3191 }
3192 
SetIlluminatedType(int illuminatedType)3193 void RSProperties::SetIlluminatedType(int illuminatedType)
3194 {
3195     if (!illuminatedPtr_) {
3196         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3197     }
3198     auto curIlluminateType = IlluminatedType(illuminatedType);
3199     illuminatedPtr_->SetIlluminatedType(curIlluminateType);
3200     isDrawn_ = true;
3201     SetDirty();
3202     contentDirty_ = true;
3203 
3204     if (curIlluminateType == IlluminatedType::INVALID) { // skip when resetFunc call
3205         return;
3206     }
3207     auto renderNode = backref_.lock();
3208     auto preIlluminatedType = illuminatedPtr_->GetPreIlluminatedType();
3209     bool preTypeIsNone = preIlluminatedType == IlluminatedType::NONE;
3210     bool curTypeIsNone = curIlluminateType == IlluminatedType::NONE;
3211     if (preTypeIsNone && !curTypeIsNone) {
3212         RSPointLightManager::Instance()->RegisterIlluminated(renderNode);
3213     } else if (!preTypeIsNone && curTypeIsNone) {
3214         RSPointLightManager::Instance()->UnRegisterIlluminated(renderNode);
3215     }
3216 }
3217 
SetBloom(float bloomIntensity)3218 void RSProperties::SetBloom(float bloomIntensity)
3219 {
3220     if (!illuminatedPtr_) {
3221         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3222     }
3223     illuminatedPtr_->SetBloomIntensity(bloomIntensity);
3224     isDrawn_ = true;
3225     SetDirty();
3226     contentDirty_ = true;
3227 }
3228 
GetLightIntensity() const3229 float RSProperties::GetLightIntensity() const
3230 {
3231     return lightSourcePtr_ ? lightSourcePtr_->GetLightIntensity() : 0.f;
3232 }
3233 
GetLightColor() const3234 Color RSProperties::GetLightColor() const
3235 {
3236     return lightSourcePtr_ ? lightSourcePtr_->GetLightColor() : RgbPalette::White();
3237 }
3238 
GetLightPosition() const3239 Vector4f RSProperties::GetLightPosition() const
3240 {
3241     return lightSourcePtr_ ? lightSourcePtr_->GetLightPosition() : Vector4f(0.f);
3242 }
3243 
GetIlluminatedType() const3244 int RSProperties::GetIlluminatedType() const
3245 {
3246     return illuminatedPtr_ ? static_cast<int>(illuminatedPtr_->GetIlluminatedType()) : 0;
3247 }
3248 
CalculateAbsLightPosition()3249 void RSProperties::CalculateAbsLightPosition()
3250 {
3251     auto lightSourceAbsRect = boundsGeo_->GetAbsRect();
3252     auto rotation = RSPointLightManager::Instance()->GetScreenRotation();
3253     Vector4f lightAbsPosition = Vector4f();
3254     auto lightPos = lightSourcePtr_->GetLightPosition();
3255     switch (rotation) {
3256         case ScreenRotation::ROTATION_0:
3257             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetLeft() + lightPos.x_);
3258             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetTop() + lightPos.y_);
3259             break;
3260         case ScreenRotation::ROTATION_90:
3261             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetBottom() - lightPos.x_);
3262             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetLeft() + lightPos.y_);
3263             break;
3264         case ScreenRotation::ROTATION_180:
3265             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetRight() - lightPos.x_);
3266             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetBottom() - lightPos.y_);
3267             break;
3268         case ScreenRotation::ROTATION_270:
3269             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetTop() + lightPos.x_);
3270             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetRight() - lightPos.y_);
3271             break;
3272         default:
3273             break;
3274     }
3275     lightAbsPosition.z_ = lightPos.z_;
3276     lightAbsPosition.w_ = lightPos.w_;
3277     lightSourcePtr_->SetAbsLightPosition(lightAbsPosition);
3278 }
3279 
SetBrightness(const std::optional<float> & brightness)3280 void RSProperties::SetBrightness(const std::optional<float>& brightness)
3281 {
3282     brightness_ = brightness;
3283     colorFilterNeedUpdate_ = true;
3284     SetDirty();
3285     contentDirty_ = true;
3286 }
3287 
GetBrightness() const3288 const std::optional<float>& RSProperties::GetBrightness() const
3289 {
3290     return brightness_;
3291 }
3292 
SetContrast(const std::optional<float> & contrast)3293 void RSProperties::SetContrast(const std::optional<float>& contrast)
3294 {
3295     contrast_ = contrast;
3296     colorFilterNeedUpdate_ = true;
3297     SetDirty();
3298     contentDirty_ = true;
3299 }
3300 
GetContrast() const3301 const std::optional<float>& RSProperties::GetContrast() const
3302 {
3303     return contrast_;
3304 }
3305 
SetSaturate(const std::optional<float> & saturate)3306 void RSProperties::SetSaturate(const std::optional<float>& saturate)
3307 {
3308     saturate_ = saturate;
3309     colorFilterNeedUpdate_ = true;
3310     SetDirty();
3311     contentDirty_ = true;
3312 }
3313 
GetSaturate() const3314 const std::optional<float>& RSProperties::GetSaturate() const
3315 {
3316     return saturate_;
3317 }
3318 
SetSepia(const std::optional<float> & sepia)3319 void RSProperties::SetSepia(const std::optional<float>& sepia)
3320 {
3321     sepia_ = sepia;
3322     colorFilterNeedUpdate_ = true;
3323     SetDirty();
3324     contentDirty_ = true;
3325 }
3326 
GetSepia() const3327 const std::optional<float>& RSProperties::GetSepia() const
3328 {
3329     return sepia_;
3330 }
3331 
SetInvert(const std::optional<float> & invert)3332 void RSProperties::SetInvert(const std::optional<float>& invert)
3333 {
3334     invert_ = invert;
3335     colorFilterNeedUpdate_ = true;
3336     SetDirty();
3337     contentDirty_ = true;
3338 }
3339 
GetInvert() const3340 const std::optional<float>& RSProperties::GetInvert() const
3341 {
3342     return invert_;
3343 }
3344 
3345 
SetAiInvert(const std::optional<Vector4f> & aiInvert)3346 void RSProperties::SetAiInvert(const std::optional<Vector4f>& aiInvert)
3347 {
3348     aiInvert_ = aiInvert;
3349     colorFilterNeedUpdate_ = true;
3350     SetDirty();
3351     contentDirty_ = true;
3352     isDrawn_ = true;
3353 }
3354 
GetAiInvert() const3355 const std::optional<Vector4f>& RSProperties::GetAiInvert() const
3356 {
3357     return aiInvert_;
3358 }
3359 
SetSystemBarEffect(bool systemBarEffect)3360 void RSProperties::SetSystemBarEffect(bool systemBarEffect)
3361 {
3362     systemBarEffect_ = systemBarEffect;
3363     colorFilterNeedUpdate_ = true;
3364     filterNeedUpdate_ = true;
3365     SetDirty();
3366     contentDirty_ = true;
3367     isDrawn_ = true;
3368 }
3369 
GetSystemBarEffect() const3370 bool RSProperties::GetSystemBarEffect() const
3371 {
3372     return systemBarEffect_;
3373 }
3374 
SetHueRotate(const std::optional<float> & hueRotate)3375 void RSProperties::SetHueRotate(const std::optional<float>& hueRotate)
3376 {
3377     hueRotate_ = hueRotate;
3378     colorFilterNeedUpdate_ = true;
3379     SetDirty();
3380     contentDirty_ = true;
3381 }
3382 
GetHueRotate() const3383 const std::optional<float>& RSProperties::GetHueRotate() const
3384 {
3385     return hueRotate_;
3386 }
3387 
SetColorBlend(const std::optional<Color> & colorBlend)3388 void RSProperties::SetColorBlend(const std::optional<Color>& colorBlend)
3389 {
3390     colorBlend_ = colorBlend;
3391     colorFilterNeedUpdate_ = true;
3392     SetDirty();
3393     contentDirty_ = true;
3394 }
3395 
GetColorBlend() const3396 const std::optional<Color>& RSProperties::GetColorBlend() const
3397 {
3398     return colorBlend_;
3399 }
3400 
GreatNotEqual(double left,double right)3401 static bool GreatNotEqual(double left, double right)
3402 {
3403     constexpr double epsilon = 0.001f;
3404     return (left - right) > epsilon;
3405 }
3406 
NearEqual(const double left,const double right)3407 static bool NearEqual(const double left, const double right)
3408 {
3409     constexpr double epsilon = 0.001f;
3410     return (std::abs(left - right) <= epsilon);
3411 }
3412 
GreatOrEqual(double left,double right)3413 static bool GreatOrEqual(double left, double right)
3414 {
3415     constexpr double epsilon = -0.001f;
3416     return (left - right) > epsilon;
3417 }
3418 
GetColorFilter() const3419 const std::shared_ptr<Drawing::ColorFilter>& RSProperties::GetColorFilter() const
3420 {
3421     return colorFilter_;
3422 }
3423 
GenerateColorFilter()3424 void RSProperties::GenerateColorFilter()
3425 {
3426     // No update needed if color filter is valid
3427     if (!colorFilterNeedUpdate_) {
3428         return;
3429     }
3430 
3431     colorFilterNeedUpdate_ = false;
3432     colorFilter_ = nullptr;
3433     if (!grayScale_ && !brightness_ && !contrast_ && !saturate_ && !sepia_ && !invert_ && !hueRotate_ && !colorBlend_) {
3434         return;
3435     }
3436 
3437     std::shared_ptr<Drawing::ColorFilter> filter = nullptr;
3438 
3439     if (grayScale_.has_value() && GreatNotEqual(*grayScale_, 0.f)) {
3440         auto grayScale = grayScale_.value();
3441         float matrix[20] = { 0.0f }; // 20 : matrix size
3442         matrix[0] = matrix[INDEX_5] = matrix[INDEX_10] = 0.2126f * grayScale; // 0.2126 : gray scale coefficient
3443         matrix[1] = matrix[INDEX_6] = matrix[INDEX_11] = 0.7152f * grayScale; // 0.7152 : gray scale coefficient
3444         matrix[INDEX_2] = matrix[INDEX_7] = matrix[INDEX_12] = 0.0722f * grayScale; // 0.0722 : gray scale coefficient
3445         matrix[INDEX_18] = 1.0 * grayScale;
3446         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3447         if (colorFilter_) {
3448             filter->Compose(*colorFilter_);
3449         }
3450         colorFilter_ = filter;
3451     }
3452     if (brightness_.has_value() && !NearEqual(*brightness_, 1.0)) {
3453         auto brightness = brightness_.value();
3454         float matrix[20] = { 0.0f }; // 20 : matrix size
3455         // shift brightness to (-1, 1)
3456         brightness = brightness - 1;
3457         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = matrix[INDEX_18] = 1.0f;
3458         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = brightness;
3459         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3460         if (colorFilter_) {
3461             filter->Compose(*colorFilter_);
3462         }
3463         colorFilter_ = filter;
3464     }
3465     if (contrast_.has_value() && !NearEqual(*contrast_, 1.0)) {
3466         auto contrast = contrast_.value();
3467         uint32_t contrastValue128 = 128;
3468         uint32_t contrastValue255 = 255;
3469         float matrix[20] = { 0.0f }; // 20 : matrix size
3470         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = contrast;
3471         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = contrastValue128 * (1 - contrast) / contrastValue255;
3472         matrix[INDEX_18] = 1.0f;
3473         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3474         if (colorFilter_) {
3475             filter->Compose(*colorFilter_);
3476         }
3477         colorFilter_ = filter;
3478     }
3479     if (saturate_.has_value() && !NearEqual(*saturate_, 1.0) && GreatOrEqual(*saturate_, 0.0)) {
3480         auto saturate = saturate_.value();
3481         float matrix[20] = { 0.0f }; // 20 : matrix size
3482         matrix[0] = 0.3086f * (1 - saturate) + saturate; // 0.3086 : saturate coefficient
3483         matrix[1] = matrix[INDEX_11] = 0.6094f * (1 - saturate); // 0.6094 : saturate coefficient
3484         matrix[INDEX_2] = matrix[INDEX_7] = 0.0820f * (1 - saturate); // 0.0820 : saturate coefficient
3485         matrix[INDEX_5] = matrix[INDEX_10] = 0.3086f * (1 - saturate); // 0.3086 : saturate coefficient
3486         matrix[INDEX_6] = 0.6094f * (1 - saturate) + saturate; // 0.6094 : saturate coefficient
3487         matrix[INDEX_12] = 0.0820f * (1 - saturate) + saturate; // 0.0820 : saturate coefficient
3488         matrix[INDEX_18] = 1.0f;
3489         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3490         if (colorFilter_) {
3491             filter->Compose(*colorFilter_);
3492         }
3493         colorFilter_ = filter;
3494     }
3495     if (sepia_.has_value() && GreatNotEqual(*sepia_, 0.0)) {
3496         auto sepia = sepia_.value();
3497         float matrix[20] = { 0.0f }; // 20 : matrix size
3498         matrix[0] = 0.393f * sepia;
3499         matrix[1] = 0.769f * sepia;
3500         matrix[INDEX_2] = 0.189f * sepia;
3501 
3502         matrix[INDEX_5] = 0.349f * sepia;
3503         matrix[INDEX_6] = 0.686f * sepia;
3504         matrix[INDEX_7] = 0.168f * sepia;
3505 
3506         matrix[INDEX_10] = 0.272f * sepia;
3507         matrix[INDEX_11] = 0.534f * sepia;
3508         matrix[INDEX_12] = 0.131f * sepia;
3509         matrix[INDEX_18] = 1.0f * sepia;
3510         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3511         if (colorFilter_) {
3512             filter->Compose(*colorFilter_);
3513         }
3514         colorFilter_ = filter;
3515     }
3516     if (invert_.has_value() && GreatNotEqual(*invert_, 0.0)) {
3517         auto invert = invert_.value();
3518         float matrix[20] = { 0.0f }; // 20 : matrix size
3519         if (invert > 1.0) {
3520             invert = 1.0;
3521         }
3522         // complete color invert when dstRGB = 1 - srcRGB
3523         // map (0, 1) to (1, -1)
3524         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = 1.0 - 2.0 * invert; // 2.0: invert
3525         matrix[INDEX_18] = 1.0f;
3526         // invert = 0.5 -> RGB = (0.5, 0.5, 0.5) -> image completely gray
3527         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = invert;
3528         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3529         if (colorFilter_) {
3530             filter->Compose(*colorFilter_);
3531         }
3532         colorFilter_ = filter;
3533     }
3534     if (hueRotate_.has_value() && GreatNotEqual(*hueRotate_, 0.0)) {
3535         auto hueRotate = hueRotate_.value();
3536         while (GreatOrEqual(hueRotate, 360)) { // 360 : degree
3537             hueRotate -= 360; // 360 : degree
3538         }
3539         float matrix[20] = { 0.0f }; // 20 : matrix size
3540         int32_t type = hueRotate / 120; // 120 : degree
3541         float N = (hueRotate - 120 * type) / 120; // 120 : degree
3542         switch (type) {
3543             case 0:
3544                 // color change = R->G, G->B, B->R
3545                 matrix[INDEX_2] = matrix[INDEX_5] = matrix[INDEX_11] = N;
3546                 matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = 1 - N;
3547                 matrix[INDEX_18] = 1.0f;
3548                 break;
3549             case 1:
3550                 // compare to original: R->B, G->R, B->G
3551                 matrix[1] = matrix[INDEX_7] = matrix[INDEX_10] = N;
3552                 matrix[INDEX_2] = matrix[INDEX_5] = matrix[INDEX_11] = 1 - N;
3553                 matrix[INDEX_18] = 1.0f;
3554                 break;
3555             case 2: // 2: back to normal color
3556                 matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = N;
3557                 matrix[1] = matrix[INDEX_7] = matrix[INDEX_10] = 1 - N;
3558                 matrix[INDEX_18] = 1.0f;
3559                 break;
3560             default:
3561                 break;
3562         }
3563         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3564         if (colorFilter_) {
3565             filter->Compose(*colorFilter_);
3566         }
3567         colorFilter_ = filter;
3568     }
3569     if (colorBlend_.has_value() && *colorBlend_ != RgbPalette::Transparent()) {
3570         auto colorBlend = colorBlend_.value();
3571         filter = Drawing::ColorFilter::CreateBlendModeColorFilter(Drawing::Color::ColorQuadSetARGB(
3572             colorBlend.GetAlpha(), colorBlend.GetRed(), colorBlend.GetGreen(), colorBlend.GetBlue()),
3573             Drawing::BlendMode::PLUS);
3574         if (colorFilter_) {
3575             filter->Compose(*colorFilter_);
3576         }
3577         colorFilter_ = filter;
3578     }
3579     isDrawn_ = true;
3580 }
3581 
Dump() const3582 std::string RSProperties::Dump() const
3583 {
3584     std::string dumpInfo;
3585     char buffer[UINT8_MAX] = { 0 };
3586     if (sprintf_s(buffer, UINT8_MAX, "Bounds[%.1f %.1f %.1f %.1f] Frame[%.1f %.1f %.1f %.1f]",
3587         GetBoundsPositionX(), GetBoundsPositionY(), GetBoundsWidth(), GetBoundsHeight(),
3588         GetFramePositionX(), GetFramePositionY(), GetFrameWidth(), GetFrameHeight()) != -1) {
3589         dumpInfo.append(buffer);
3590     }
3591 
3592     errno_t ret;
3593     if (clipToBounds_) {
3594         // clipToBounds
3595         ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3596         if (ret != EOK) {
3597             return "Failed to memset_s for clipToBounds, ret=" + std::to_string(ret);
3598         }
3599         if (sprintf_s(buffer, UINT8_MAX, ", ClipToBounds[True]") != -1) {
3600             dumpInfo.append(buffer);
3601         }
3602     }
3603     if (clipToFrame_) {
3604         // clipToFrame
3605         ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3606         if (ret != EOK) {
3607             return "Failed to memset_s for clipToFrame, ret=" + std::to_string(ret);
3608         }
3609         if (sprintf_s(buffer, UINT8_MAX, ", ClipToFrame[True]") != -1) {
3610             dumpInfo.append(buffer);
3611         }
3612     }
3613 
3614     // PositionZ
3615     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3616     if (ret != EOK) {
3617         return "Failed to memset_s for PositionZ, ret=" + std::to_string(ret);
3618     }
3619     if (!ROSEN_EQ(GetPositionZ(), 0.f) &&
3620         sprintf_s(buffer, UINT8_MAX, ", PositionZ[%.1f]", GetPositionZ()) != -1) {
3621         dumpInfo.append(buffer);
3622     }
3623 
3624     // Pivot
3625     std::unique_ptr<RSTransform> defaultTrans = std::make_unique<RSTransform>();
3626     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3627     if (ret != EOK) {
3628         return "Failed to memset_s for Pivot, ret=" + std::to_string(ret);
3629     }
3630     Vector2f pivot = GetPivot();
3631     if ((!ROSEN_EQ(pivot[0], defaultTrans->pivotX_) || !ROSEN_EQ(pivot[1], defaultTrans->pivotY_)) &&
3632         sprintf_s(buffer, UINT8_MAX, ", Pivot[%.1f,%.1f]", pivot[0], pivot[1]) != -1) {
3633         dumpInfo.append(buffer);
3634     }
3635 
3636     // CornerRadius
3637     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3638     if (ret != EOK) {
3639         return "Failed to memset_s for CornerRadius, ret=" + std::to_string(ret);
3640     }
3641     if (!GetCornerRadius().IsZero() &&
3642         sprintf_s(buffer, UINT8_MAX, ", CornerRadius[%.1f %.1f %.1f %.1f]",
3643             GetCornerRadius().x_, GetCornerRadius().y_, GetCornerRadius().z_, GetCornerRadius().w_) != -1) {
3644         dumpInfo.append(buffer);
3645     }
3646 
3647     // PixelStretch PixelStretchPercent
3648     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3649     if (ret != EOK) {
3650         return "Failed to memset_s for PixelStretch, ret=" + std::to_string(ret);
3651     }
3652     if (pixelStretch_.has_value() &&
3653         sprintf_s(buffer, UINT8_MAX, ", PixelStretch[left:%.1f top:%.1f right:%.1f bottom:%.1f]",
3654             pixelStretch_->x_, pixelStretch_->y_, pixelStretch_->z_, pixelStretch_->w_) != -1) {
3655         dumpInfo.append(buffer);
3656     }
3657 
3658     // Rotation
3659     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3660     if (ret != EOK) {
3661         return "Failed to memset_s for Rotation, ret=" + std::to_string(ret);
3662     }
3663     if (!ROSEN_EQ(GetRotation(), defaultTrans->rotation_) &&
3664         sprintf_s(buffer, UINT8_MAX, ", Rotation[%.1f]", GetRotation()) != -1) {
3665         dumpInfo.append(buffer);
3666     }
3667     // RotationX
3668     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3669     if (ret != EOK) {
3670         return "Failed to memset_s for RotationX, ret=" + std::to_string(ret);
3671     }
3672     if (!ROSEN_EQ(GetRotationX(), defaultTrans->rotationX_) &&
3673         sprintf_s(buffer, UINT8_MAX, ", RotationX[%.1f]", GetRotationX()) != -1) {
3674         dumpInfo.append(buffer);
3675     }
3676     // RotationY
3677     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3678     if (ret != EOK) {
3679         return "Failed to memset_s for RotationY, ret=" + std::to_string(ret);
3680     }
3681     if (!ROSEN_EQ(GetRotationY(), defaultTrans->rotationY_) &&
3682         sprintf_s(buffer, UINT8_MAX, ", RotationY[%.1f]", GetRotationY()) != -1) {
3683         dumpInfo.append(buffer);
3684     }
3685 
3686     // TranslateX
3687     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3688     if (ret != EOK) {
3689         return "Failed to memset_s for TranslateX, ret=" + std::to_string(ret);
3690     }
3691     if (!ROSEN_EQ(GetTranslateX(), defaultTrans->translateX_) &&
3692         sprintf_s(buffer, UINT8_MAX, ", TranslateX[%.1f]", GetTranslateX()) != -1) {
3693         dumpInfo.append(buffer);
3694     }
3695 
3696     // TranslateY
3697     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3698     if (ret != EOK) {
3699         return "Failed to memset_s for TranslateY, ret=" + std::to_string(ret);
3700     }
3701     if (!ROSEN_EQ(GetTranslateY(), defaultTrans->translateY_) &&
3702         sprintf_s(buffer, UINT8_MAX, ", TranslateY[%.1f]", GetTranslateY()) != -1) {
3703         dumpInfo.append(buffer);
3704     }
3705 
3706     // TranslateZ
3707     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3708     if (ret != EOK) {
3709         return "Failed to memset_s for TranslateZ, ret=" + std::to_string(ret);
3710     }
3711     if (!ROSEN_EQ(GetTranslateZ(), defaultTrans->translateZ_) &&
3712         sprintf_s(buffer, UINT8_MAX, ", TranslateZ[%.1f]", GetTranslateZ()) != -1) {
3713         dumpInfo.append(buffer);
3714     }
3715 
3716     // ScaleX
3717     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3718     if (ret != EOK) {
3719         return "Failed to memset_s for ScaleX, ret=" + std::to_string(ret);
3720     }
3721     if (!ROSEN_EQ(GetScaleX(), defaultTrans->scaleX_) &&
3722         sprintf_s(buffer, UINT8_MAX, ", ScaleX[%.1f]", GetScaleX()) != -1) {
3723         dumpInfo.append(buffer);
3724     }
3725 
3726     // ScaleY
3727     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3728     if (ret != EOK) {
3729         return "Failed to memset_s for ScaleY, ret=" + std::to_string(ret);
3730     }
3731     if (!ROSEN_EQ(GetScaleY(), defaultTrans->scaleY_) &&
3732         sprintf_s(buffer, UINT8_MAX, ", ScaleY[%.1f]", GetScaleY()) != -1) {
3733         dumpInfo.append(buffer);
3734     }
3735 
3736     // Alpha
3737     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3738     if (ret != EOK) {
3739         return "Failed to memset_s for Alpha, ret=" + std::to_string(ret);
3740     }
3741     if (!ROSEN_EQ(GetAlpha(), 1.f) &&
3742         sprintf_s(buffer, UINT8_MAX, ", Alpha[%.3f]", GetAlpha()) != -1) {
3743         dumpInfo.append(buffer);
3744     }
3745 
3746     // Spherize
3747     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3748     if (ret != EOK) {
3749         return "Failed to memset_s for Spherize, ret=" + std::to_string(ret);
3750     }
3751     if (!ROSEN_EQ(GetSpherize(), 0.f) &&
3752         sprintf_s(buffer, UINT8_MAX, ", Spherize[%.1f]", GetSpherize()) != -1) {
3753         dumpInfo.append(buffer);
3754     }
3755 
3756     // blendmode
3757     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3758     if (ret != EOK) {
3759         return "Failed to memset_s for blendmode, ret=" + std::to_string(ret);
3760     }
3761     if (!ROSEN_EQ(GetColorBlendMode(), 0) &&
3762         sprintf_s(buffer, UINT8_MAX, ", skblendmode[%d], blendType[%d]",
3763         GetColorBlendMode() - 1, GetColorBlendApplyType()) != -1) {
3764         dumpInfo.append(buffer);
3765     }
3766 
3767     // LightUpEffect
3768     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3769     if (ret != EOK) {
3770         return "Failed to memset_s for LightUpEffect, ret=" + std::to_string(ret);
3771     }
3772     if (!ROSEN_EQ(GetLightUpEffect(), 1.f) &&
3773         sprintf_s(buffer, UINT8_MAX, ", LightUpEffect[%.1f]", GetLightUpEffect()) != -1) {
3774         dumpInfo.append(buffer);
3775     }
3776 
3777     // ForegroundColor
3778     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3779     if (ret != EOK) {
3780         return "Failed to memset_s for ForegroundColor, ret=" + std::to_string(ret);
3781     }
3782     if (!ROSEN_EQ(GetForegroundColor(), RgbPalette::Transparent()) &&
3783         sprintf_s(buffer, UINT8_MAX, ", ForegroundColor[#%08X]", GetForegroundColor().AsArgbInt()) != -1) {
3784         dumpInfo.append(buffer);
3785     }
3786 
3787     // BackgroundColor
3788     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3789     if (ret != EOK) {
3790         return "Failed to memset_s for BackgroundColor, ret=" + std::to_string(ret);
3791     }
3792     if (!ROSEN_EQ(GetBackgroundColor(), RgbPalette::Transparent()) &&
3793         sprintf_s(buffer, UINT8_MAX, ", BackgroundColor[#%08X]", GetBackgroundColor().AsArgbInt()) != -1) {
3794         dumpInfo.append(buffer);
3795     }
3796 
3797     // BgImage
3798     std::unique_ptr<Decoration> defaultDecoration = std::make_unique<Decoration>();
3799     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3800     if (ret != EOK) {
3801         return "Failed to memset_s for BgImage, ret=" + std::to_string(ret);
3802     }
3803     if ((!ROSEN_EQ(GetBgImagePositionX(), defaultDecoration->bgImageRect_.left_) ||
3804         !ROSEN_EQ(GetBgImagePositionY(), defaultDecoration->bgImageRect_.top_) ||
3805         !ROSEN_EQ(GetBgImageWidth(), defaultDecoration->bgImageRect_.width_) ||
3806         !ROSEN_EQ(GetBgImageHeight(), defaultDecoration->bgImageRect_.height_)) &&
3807         sprintf_s(buffer, UINT8_MAX, ", BgImage[%.1f %.1f %.1f %.1f]", GetBgImagePositionX(),
3808             GetBgImagePositionY(), GetBgImageWidth(), GetBgImageHeight()) != -1) {
3809         dumpInfo.append(buffer);
3810     }
3811 
3812     // Border
3813     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3814     if (ret != EOK) {
3815         return "Failed to memset_s for Border, ret=" + std::to_string(ret);
3816     }
3817     if (border_ && border_->HasBorder() &&
3818         sprintf_s(buffer, UINT8_MAX, ", Border[%s]", border_->ToString().c_str()) != -1) {
3819         dumpInfo.append(buffer);
3820     }
3821 
3822     // Filter
3823     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3824     if (ret != EOK) {
3825         return "Failed to memset_s for Filter, ret=" + std::to_string(ret);
3826     }
3827     auto filter_ = GetFilter();
3828     if (filter_ && filter_->IsValid() &&
3829         sprintf_s(buffer, UINT8_MAX, ", Filter[%s]", filter_->GetDescription().c_str()) != -1) {
3830         dumpInfo.append(buffer);
3831     }
3832 
3833     // BackgroundFilter
3834     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3835     if (ret != EOK) {
3836         return "Failed to memset_s for BackgroundFilter, ret=" + std::to_string(ret);
3837     }
3838     auto backgroundFilter_ = GetBackgroundFilter();
3839     if (backgroundFilter_ && backgroundFilter_->IsValid() &&
3840         sprintf_s(buffer, UINT8_MAX, ", BackgroundFilter[%s]", backgroundFilter_->GetDescription().c_str()) != -1) {
3841         dumpInfo.append(buffer);
3842     }
3843 
3844     // ForegroundFilter
3845     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3846     if (ret != EOK) {
3847         return "Failed to memset_s for ForegroundFilter, ret=" + std::to_string(ret);
3848     }
3849     auto foregroundFilterCache_ = GetForegroundFilterCache();
3850     if (foregroundFilterCache_ && foregroundFilterCache_->IsValid() &&
3851         sprintf_s(buffer, UINT8_MAX, ", ForegroundFilter[%s]", foregroundFilterCache_->GetDescription().c_str()) !=
3852         -1) {
3853         dumpInfo.append(buffer);
3854     }
3855 
3856     // Outline
3857     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3858     if (ret != EOK) {
3859         return "Failed to memset_s for Outline, ret=" + std::to_string(ret);
3860     }
3861     if (outline_ && outline_->HasBorder() &&
3862         sprintf_s(buffer, UINT8_MAX, ", Outline[%s]", outline_->ToString().c_str()) != -1) {
3863         dumpInfo.append(buffer);
3864     }
3865 
3866     // ShadowColor
3867     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3868     if (ret != EOK) {
3869         return "Failed to memset_s for ShadowColor, ret=" + std::to_string(ret);
3870     }
3871     if (!ROSEN_EQ(GetShadowColor(), Color(DEFAULT_SPOT_COLOR)) &&
3872         sprintf_s(buffer, UINT8_MAX, ", ShadowColor[#%08X]", GetShadowColor().AsArgbInt()) != -1) {
3873         dumpInfo.append(buffer);
3874     }
3875 
3876     // ShadowOffsetX
3877     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3878     if (ret != EOK) {
3879         return "Failed to memset_s for ShadowOffsetX, ret=" + std::to_string(ret);
3880     }
3881     if (!ROSEN_EQ(GetShadowOffsetX(), DEFAULT_SHADOW_OFFSET_X) &&
3882         sprintf_s(buffer, UINT8_MAX, ", ShadowOffsetX[%.1f]", GetShadowOffsetX()) != -1) {
3883         dumpInfo.append(buffer);
3884     }
3885 
3886     // ShadowOffsetY
3887     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3888     if (ret != EOK) {
3889         return "Failed to memset_s for ShadowOffsetY, ret=" + std::to_string(ret);
3890     }
3891     if (!ROSEN_EQ(GetShadowOffsetY(), DEFAULT_SHADOW_OFFSET_Y) &&
3892         sprintf_s(buffer, UINT8_MAX, ", ShadowOffsetY[%.1f]", GetShadowOffsetY()) != -1) {
3893         dumpInfo.append(buffer);
3894     }
3895 
3896     // ShadowAlpha
3897     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3898     if (ret != EOK) {
3899         return "Failed to memset_s for ShadowAlpha, ret=" + std::to_string(ret);
3900     }
3901     if (!ROSEN_EQ(GetShadowAlpha(), 0.f) &&
3902         sprintf_s(buffer, UINT8_MAX, ", ShadowAlpha[%.1f]", GetShadowAlpha()) != -1) {
3903         dumpInfo.append(buffer);
3904     }
3905 
3906     // ShadowElevation
3907     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3908     if (ret != EOK) {
3909         return "Failed to memset_s for ShadowElevation, ret=" + std::to_string(ret);
3910     }
3911     if (!ROSEN_EQ(GetShadowElevation(), 0.f) &&
3912         sprintf_s(buffer, UINT8_MAX, ", ShadowElevation[%.1f]", GetShadowElevation()) != -1) {
3913         dumpInfo.append(buffer);
3914     }
3915 
3916     // ShadowRadius
3917     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3918     if (ret != EOK) {
3919         return "Failed to memset_s for ShadowRadius, ret=" + std::to_string(ret);
3920     }
3921     if (!ROSEN_EQ(GetShadowRadius(), 0.f) &&
3922         sprintf_s(buffer, UINT8_MAX, ", ShadowRadius[%.1f]", GetShadowRadius()) != -1) {
3923         dumpInfo.append(buffer);
3924     }
3925 
3926     // ShadowIsFilled
3927     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3928     if (ret != EOK) {
3929         return "Failed to memset_s for ShadowIsFilled, ret=" + std::to_string(ret);
3930     }
3931     if (!ROSEN_EQ(GetShadowIsFilled(), false) &&
3932         sprintf_s(buffer, UINT8_MAX, ", ShadowIsFilled[%d]", GetShadowIsFilled()) != -1) {
3933         dumpInfo.append(buffer);
3934     }
3935 
3936     // FrameGravity
3937     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3938     if (ret != EOK) {
3939         return "Failed to memset_s for FrameGravity, ret=" + std::to_string(ret);
3940     }
3941     if (!ROSEN_EQ(GetFrameGravity(), Gravity::DEFAULT) &&
3942         sprintf_s(buffer, UINT8_MAX, ", FrameGravity[%d]", GetFrameGravity()) != -1) {
3943         dumpInfo.append(buffer);
3944     }
3945 
3946     // IsVisible
3947     if (!GetVisible()) {
3948         dumpInfo.append(", IsVisible[false]");
3949     }
3950 
3951     // UseEffect
3952     if (GetUseEffect()) {
3953         dumpInfo.append(", GetUseEffect[true]");
3954     }
3955 
3956     // Gray Scale
3957     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3958     if (ret != EOK) {
3959         return "Failed to memset_s for GrayScale, ret=" + std::to_string(ret);
3960     }
3961     auto grayScale = GetGrayScale();
3962     if (grayScale.has_value() && !ROSEN_EQ(*grayScale, 0.f) &&
3963         sprintf_s(buffer, UINT8_MAX, ", GrayScale[%.1f]", *grayScale) != -1) {
3964         dumpInfo.append(buffer);
3965     }
3966 
3967     // DynamicLightUpRate
3968     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3969     if (ret != EOK) {
3970         return "Failed to memset_s for DynamicLightUpRate, ret=" + std::to_string(ret);
3971     }
3972     auto dynamicLightUpRate = GetDynamicLightUpRate();
3973     if (dynamicLightUpRate.has_value() && !ROSEN_EQ(*dynamicLightUpRate, 0.f) &&
3974         sprintf_s(buffer, UINT8_MAX, ", DynamicLightUpRate[%.1f]", *dynamicLightUpRate) != -1) {
3975         dumpInfo.append(buffer);
3976     }
3977 
3978     // DynamicLightUpDegree
3979     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3980     if (ret != EOK) {
3981         return "Failed to memset_s for DynamicLightUpDegree, ret=" + std::to_string(ret);
3982     }
3983     auto dynamicLightUpDegree = GetDynamicLightUpDegree();
3984     if (dynamicLightUpDegree.has_value() && !ROSEN_EQ(*dynamicLightUpDegree, 0.f) &&
3985         sprintf_s(buffer, UINT8_MAX, ", DynamicLightUpDegree[%.1f]", *dynamicLightUpDegree) != -1) {
3986         dumpInfo.append(buffer);
3987     }
3988 
3989     // Brightness
3990     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3991     if (ret != EOK) {
3992         return "Failed to memset_s for Brightness, ret=" + std::to_string(ret);
3993     }
3994     auto brightness = GetBrightness();
3995     if (brightness.has_value() && !ROSEN_EQ(*brightness, 1.f) &&
3996         sprintf_s(buffer, UINT8_MAX, ", Brightness[%.1f]", *brightness) != -1) {
3997         dumpInfo.append(buffer);
3998     }
3999 
4000     // Contrast
4001     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4002     if (ret != EOK) {
4003         return "Failed to memset_s for Contrast, ret=" + std::to_string(ret);
4004     }
4005     auto contrast = GetContrast();
4006     if (contrast.has_value() && !ROSEN_EQ(*contrast, 1.f) &&
4007         sprintf_s(buffer, UINT8_MAX, ", Contrast[%.1f]", *contrast) != -1) {
4008         dumpInfo.append(buffer);
4009     }
4010 
4011     // Saturate
4012     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4013     if (ret != EOK) {
4014         return "Failed to memset_s for Saturate, ret=" + std::to_string(ret);
4015     }
4016     auto saturate = GetSaturate();
4017     if (saturate.has_value() && !ROSEN_EQ(*saturate, 1.f) &&
4018         sprintf_s(buffer, UINT8_MAX, ", Saturate[%.1f]", *saturate) != -1) {
4019         dumpInfo.append(buffer);
4020     }
4021 
4022     // Sepia
4023     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4024     if (ret != EOK) {
4025         return "Failed to memset_s for Sepia, ret=" + std::to_string(ret);
4026     }
4027     auto sepia = GetSepia();
4028     if (sepia.has_value() && !ROSEN_EQ(*sepia, 0.f) &&
4029         sprintf_s(buffer, UINT8_MAX, ", Sepia[%.1f]", *sepia) != -1) {
4030         dumpInfo.append(buffer);
4031     }
4032 
4033     // Invert
4034     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4035     if (ret != EOK) {
4036         return "Failed to memset_s for Invert, ret=" + std::to_string(ret);
4037     }
4038     auto invert = GetInvert();
4039     if (invert.has_value() && !ROSEN_EQ(*invert, 0.f) &&
4040         sprintf_s(buffer, UINT8_MAX, ", Invert[%.1f]", *invert) != -1) {
4041         dumpInfo.append(buffer);
4042     }
4043 
4044     // Hue Rotate
4045     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4046     if (ret != EOK) {
4047         return "Failed to memset_s for HueRotate, ret=" + std::to_string(ret);
4048     }
4049     auto hueRotate = GetHueRotate();
4050     if (hueRotate.has_value() && !ROSEN_EQ(*hueRotate, 0.f) &&
4051         sprintf_s(buffer, UINT8_MAX, ", HueRotate[%.1f]", *hueRotate) != -1) {
4052         dumpInfo.append(buffer);
4053     }
4054 
4055     // Color Blend
4056     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4057     if (ret != EOK) {
4058         return "Failed to memset_s for ColorBlend, ret=" + std::to_string(ret);
4059     }
4060     auto colorBlend = GetColorBlend();
4061     if (colorBlend.has_value() && !ROSEN_EQ(*colorBlend, RgbPalette::Transparent()) &&
4062         sprintf_s(buffer, UINT8_MAX, ", ColorBlend[#%08X]", colorBlend->AsArgbInt()) != -1) {
4063         dumpInfo.append(buffer);
4064     }
4065 
4066     return dumpInfo;
4067 }
4068 
4069 // planning: need to delete, cachemanager moved to filter drawable
4070 #if defined(NEW_SKIA) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
CreateFilterCacheManagerIfNeed()4071 void RSProperties::CreateFilterCacheManagerIfNeed()
4072 {
4073     if (!FilterCacheEnabled) {
4074         return;
4075     }
4076     if (auto& filter = GetBackgroundFilter()) {
4077         auto& cacheManager = backgroundFilterCacheManager_;
4078         if (cacheManager == nullptr) {
4079             cacheManager = std::make_unique<RSFilterCacheManager>();
4080         }
4081         cacheManager->UpdateCacheStateWithFilterHash(filter);
4082     } else {
4083         backgroundFilterCacheManager_.reset();
4084     }
4085     if (auto& filter = GetFilter()) {
4086         auto& cacheManager = foregroundFilterCacheManager_;
4087         if (cacheManager == nullptr) {
4088             cacheManager = std::make_unique<RSFilterCacheManager>();
4089         }
4090         cacheManager->UpdateCacheStateWithFilterHash(filter);
4091     } else {
4092         foregroundFilterCacheManager_.reset();
4093     }
4094 }
4095 
GetFilterCacheManager(bool isForeground) const4096 const std::unique_ptr<RSFilterCacheManager>& RSProperties::GetFilterCacheManager(bool isForeground) const
4097 {
4098     return isForeground ? foregroundFilterCacheManager_ : backgroundFilterCacheManager_;
4099 }
4100 
ClearFilterCache()4101 void RSProperties::ClearFilterCache()
4102 {
4103     if (foregroundFilterCacheManager_ != nullptr) {
4104         foregroundFilterCacheManager_->ReleaseCacheOffTree();
4105     }
4106     if (backgroundFilterCacheManager_ != nullptr) {
4107         backgroundFilterCacheManager_->ReleaseCacheOffTree();
4108     }
4109     if (backgroundFilter_ != nullptr) {
4110         auto drawingFilter = std::static_pointer_cast<RSDrawingFilter>(backgroundFilter_);
4111         std::shared_ptr<RSShaderFilter> rsShaderFilter =
4112             drawingFilter->GetShaderFilterWithType(RSShaderFilter::MASK_COLOR);
4113         if (rsShaderFilter != nullptr) {
4114             auto maskColorShaderFilter = std::static_pointer_cast<RSMaskColorShaderFilter>(rsShaderFilter);
4115         }
4116     }
4117     if (filter_ != nullptr) {
4118         auto drawingFilter = std::static_pointer_cast<RSDrawingFilter>(filter_);
4119         std::shared_ptr<RSShaderFilter> rsShaderFilter =
4120             drawingFilter->GetShaderFilterWithType(RSShaderFilter::MASK_COLOR);
4121         if (rsShaderFilter != nullptr) {
4122             auto maskColorShaderFilter = std::static_pointer_cast<RSMaskColorShaderFilter>(rsShaderFilter);
4123         }
4124     }
4125 }
4126 #endif
4127 
OnApplyModifiers()4128 void RSProperties::OnApplyModifiers()
4129 {
4130     if (geoDirty_) {
4131         if (!hasBounds_) {
4132             CheckEmptyBounds();
4133         } else {
4134             CalculateFrameOffset();
4135         }
4136         // frame and bounds are the same, no need to clip twice
4137         if (clipToFrame_ && clipToBounds_ && frameOffsetX_ == 0 && frameOffsetY_ == 0) {
4138             clipToFrame_ = false;
4139         }
4140         // planning: temporary fix to calculate relative matrix in OnApplyModifiers, later RSRenderNode::Update will
4141         // overwrite it.
4142         boundsGeo_->UpdateByMatrixFromSelf();
4143     }
4144     if (colorFilterNeedUpdate_) {
4145         GenerateColorFilter();
4146         needFilter_ = needFilter_ || (colorFilter_ != nullptr);
4147     }
4148     if (pixelStretchNeedUpdate_ || geoDirty_) {
4149         CalculatePixelStretch();
4150     }
4151     if (greyCoefNeedUpdate_) {
4152         CheckGreyCoef();
4153         greyCoefNeedUpdate_ = false;
4154         filterNeedUpdate_ = true;
4155     }
4156     if (filterNeedUpdate_) {
4157         UpdateFilter();
4158     }
4159     GenerateRRect();
4160 }
4161 
UpdateFilter()4162 void RSProperties::UpdateFilter()
4163 {
4164     filterNeedUpdate_ = false;
4165     GenerateBackgroundFilter();
4166     GenerateForegroundFilter();
4167     if (GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE) {
4168         filterNeedUpdate_ = true;
4169     }
4170     if (backgroundFilter_ != nullptr && !backgroundFilter_->IsValid()) {
4171         backgroundFilter_.reset();
4172     }
4173     if (filter_ != nullptr && !filter_->IsValid()) {
4174         filter_.reset();
4175     }
4176 
4177     if (FOREGROUND_FILTER_ENABLED) {
4178         UpdateForegroundFilter();
4179     }
4180 
4181     needFilter_ = backgroundFilter_ != nullptr || filter_ != nullptr || useEffect_ || IsLightUpEffectValid() ||
4182                   IsDynamicLightUpValid() || greyCoef_.has_value() || linearGradientBlurPara_ != nullptr ||
4183                   IsDynamicDimValid() || GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE ||
4184                   foregroundFilter_ != nullptr || IsFgBrightnessValid() ||
4185                   IsBgBrightnessValid() || foregroundFilterCache_ != nullptr || IsWaterRippleValid();
4186 }
4187 
UpdateForegroundFilter()4188 void RSProperties::UpdateForegroundFilter()
4189 {
4190     if (motionBlurPara_ && ROSEN_GNE(motionBlurPara_->radius, 0.0)) {
4191         auto motionBlurFilter = std::make_shared<RSMotionBlurFilter>(motionBlurPara_);
4192         if (IS_UNI_RENDER) {
4193             foregroundFilterCache_ = motionBlurFilter;
4194         } else {
4195             foregroundFilter_ = motionBlurFilter;
4196         }
4197     } else if (IsForegroundEffectRadiusValid()) {
4198         auto foregroundEffectFilter = std::make_shared<RSForegroundEffectFilter>(foregroundEffectRadius_);
4199         if (IS_UNI_RENDER) {
4200             foregroundFilterCache_ = foregroundEffectFilter;
4201         } else {
4202             foregroundFilter_ = foregroundEffectFilter;
4203         }
4204     } else if (IsSpherizeValid()) {
4205         auto spherizeEffectFilter = std::make_shared<RSSpherizeEffectFilter>(spherizeDegree_);
4206         if (IS_UNI_RENDER) {
4207             foregroundFilterCache_ = spherizeEffectFilter;
4208         } else {
4209             foregroundFilter_ = spherizeEffectFilter;
4210         }
4211     } else if (IsFlyOutValid()) {
4212         CreateFlyOutShaderFilter();
4213     } else if (GetShadowMask()) {
4214         float elevation = GetShadowElevation();
4215         Drawing::scalar n1 = 0.25f * elevation * (1 + elevation / 128.0f);  // 0.25f 128.0f
4216         Drawing::scalar blurRadius = elevation > 0.0f ? n1 : GetShadowRadius();
4217         auto colorfulShadowFilter =
4218             std::make_shared<RSColorfulShadowFilter>(blurRadius, GetShadowOffsetX(), GetShadowOffsetY());
4219         if (IS_UNI_RENDER) {
4220             foregroundFilterCache_ = colorfulShadowFilter;
4221         } else {
4222             foregroundFilter_ = colorfulShadowFilter;
4223         }
4224     } else if (IsDistortionKValid()) {
4225         foregroundFilter_ = std::make_shared<RSDistortionFilter>(*distortionK_);
4226     } else {
4227         foregroundFilter_.reset();
4228         foregroundFilterCache_.reset();
4229     }
4230 }
4231 
CalculatePixelStretch()4232 void RSProperties::CalculatePixelStretch()
4233 {
4234     pixelStretchNeedUpdate_ = false;
4235     // no pixel stretch
4236     if (!pixelStretch_.has_value() && !pixelStretchPercent_.has_value()) {
4237         return;
4238     }
4239     // convert pixel stretch percent to pixel stretch
4240     if (pixelStretchPercent_) {
4241         auto width = GetBoundsWidth();
4242         auto height = GetBoundsHeight();
4243         if (isinf(width) || isinf(height)) {
4244             return;
4245         }
4246         pixelStretch_ = *pixelStretchPercent_ * Vector4f(width, height, width, height);
4247     }
4248     constexpr static float EPS = 1e-5f;
4249     // parameter check: near zero
4250     if (abs(pixelStretch_->x_) < EPS && abs(pixelStretch_->y_) < EPS && abs(pixelStretch_->z_) < EPS &&
4251         abs(pixelStretch_->w_) < EPS) {
4252         pixelStretch_ = std::nullopt;
4253         return;
4254     }
4255     // parameter check: all >= 0 or all <= 0
4256     if ((pixelStretch_->x_ < EPS && pixelStretch_->y_ < EPS && pixelStretch_->z_ < EPS && pixelStretch_->w_ < EPS) ||
4257         (pixelStretch_->x_ > -EPS && pixelStretch_->y_ > -EPS && pixelStretch_->z_ > -EPS &&
4258             pixelStretch_->w_ > -EPS)) {
4259         isDrawn_ = true;
4260         return;
4261     }
4262     pixelStretch_ = std::nullopt;
4263 }
4264 
NeedBlurFuzed()4265 bool RSProperties::NeedBlurFuzed()
4266 {
4267     if (RSSystemProperties::GetMESABlurFuzedEnabled() && greyCoef_.has_value()) {
4268         return true;
4269     }
4270     return false;
4271 }
4272 
CalculateFrameOffset()4273 void RSProperties::CalculateFrameOffset()
4274 {
4275     frameOffsetX_ = frameGeo_->GetX() - boundsGeo_->GetX();
4276     frameOffsetY_ = frameGeo_->GetY() - boundsGeo_->GetY();
4277     if (isinf(frameOffsetX_)) {
4278         frameOffsetX_ = 0.;
4279     }
4280     if (isinf(frameOffsetY_)) {
4281         frameOffsetY_ = 0.;
4282     }
4283     if (frameOffsetX_ != 0. || frameOffsetY_ != 0.) {
4284         isDrawn_ = true;
4285     }
4286 }
4287 
CheckGreyCoef()4288 void RSProperties::CheckGreyCoef()
4289 {
4290     if (!greyCoef_.has_value()) {
4291         return;
4292     }
4293     // 127.0 half of 255.0
4294     if (greyCoef_->x_ < 0.0f || greyCoef_->x_ > 127.0f || greyCoef_->y_ < 0.0f || greyCoef_->y_ > 127.0f) {
4295         greyCoef_ = std::nullopt;
4296     }
4297 }
4298 
4299 // blend with background
SetColorBlendMode(int colorBlendMode)4300 void RSProperties::SetColorBlendMode(int colorBlendMode)
4301 {
4302     colorBlendMode_ = std::clamp<int>(colorBlendMode, 0, static_cast<int>(RSColorBlendMode::MAX));
4303     if (colorBlendMode_ != static_cast<int>(RSColorBlendMode::NONE)) {
4304         isDrawn_ = true;
4305     }
4306     SetDirty();
4307     contentDirty_ = true;
4308 }
4309 
GetColorBlendMode() const4310 int RSProperties::GetColorBlendMode() const
4311 {
4312     return colorBlendMode_;
4313 }
4314 
SetColorBlendApplyType(int colorBlendApplyType)4315 void RSProperties::SetColorBlendApplyType(int colorBlendApplyType)
4316 {
4317     colorBlendApplyType_ = std::clamp<int>(colorBlendApplyType, 0, static_cast<int>(RSColorBlendApplyType::MAX));
4318     isDrawn_ = true;
4319     SetDirty();
4320     contentDirty_ = true;
4321 }
4322 
GetColorBlendApplyType() const4323 int RSProperties::GetColorBlendApplyType() const
4324 {
4325     return colorBlendApplyType_;
4326 }
4327 
GetHaveEffectRegion() const4328 bool RSProperties::GetHaveEffectRegion() const
4329 {
4330     return haveEffectRegion_;
4331 }
4332 
SetHaveEffectRegion(bool haveEffectRegion)4333 void RSProperties::SetHaveEffectRegion(bool haveEffectRegion)
4334 {
4335     // clear cache if new region is null or outside current region
4336     if (auto& manager = GetFilterCacheManager(false);
4337         manager && manager->IsCacheValid() && haveEffectRegion == false) {
4338         manager->UpdateCacheStateWithFilterRegion();
4339     }
4340     haveEffectRegion_ = haveEffectRegion;
4341 }
4342 } // namespace Rosen
4343 } // namespace OHOS
4344