• 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 "render/rs_mesa_blur_shader_filter.h"
24 #include "common/rs_obj_abs_geometry.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_material_filter.h"
38 #include "render/rs_linear_gradient_blur_shader_filter.h"
39 #include "render/rs_magnifier_shader_filter.h"
40 #include "render/rs_maskcolor_shader_filter.h"
41 #include "render/rs_spherize_effect_filter.h"
42 #include "render/rs_attraction_effect_filter.h"
43 #include "src/core/SkOpts.h"
44 #include "render/rs_water_ripple_shader_filter.h"
45 #include "render/rs_fly_out_shader_filter.h"
46 #include "render/rs_distortion_shader_filter.h"
47 #include "drawable/rs_property_drawable_utils.h"
48 
49 namespace OHOS {
50 namespace Rosen {
51 namespace {
52 constexpr int32_t INDEX_2 = 2;
53 constexpr int32_t INDEX_4 = 4;
54 constexpr int32_t INDEX_5 = 5;
55 constexpr int32_t INDEX_6 = 6;
56 constexpr int32_t INDEX_7 = 7;
57 constexpr int32_t INDEX_9 = 9;
58 constexpr int32_t INDEX_10 = 10;
59 constexpr int32_t INDEX_11 = 11;
60 constexpr int32_t INDEX_12 = 12;
61 constexpr int32_t INDEX_14 = 14;
62 constexpr int32_t INDEX_18 = 18;
63 
64 const Vector4f Vector4fZero { 0.f, 0.f, 0.f, 0.f };
65 const auto EMPTY_RECT = RectF();
66 constexpr float SPHERIZE_VALID_EPSILON = 0.001f; // used to judge if spherize valid
67 constexpr float ATTRACTION_VALID_EPSILON = 0.001f; // used to judge if attraction valid
68 constexpr uint8_t BORDER_TYPE_NONE = (uint32_t)BorderStyle::NONE;
69 
70 using ResetPropertyFunc = void (*)(RSProperties* prop);
71 // Every modifier before RSModifierType::CUSTOM is property modifier, and it should have a ResetPropertyFunc
72 // NOTE: alway add new resetter when adding new property modifier
73 constexpr static std::array<ResetPropertyFunc, static_cast<int>(RSModifierType::CUSTOM)> g_propertyResetterLUT = {
74     nullptr,                                                             // INVALID
75     nullptr,                                                             // BOUNDS
76     nullptr,                                                             // FRAME
__anon167c01c20202() 77     [](RSProperties* prop) { prop->SetPositionZ(0.f); },                 // POSITION_Z
__anon167c01c20302() 78     [](RSProperties* prop) { prop->SetPositionZApplicableCamera3D(true); },   // POSITION_Z_APPLICABLE_CAMERA3D
__anon167c01c20402() 79     [](RSProperties* prop) { prop->SetPivot(Vector2f(0.5f, 0.5f)); },    // PIVOT
__anon167c01c20502() 80     [](RSProperties* prop) { prop->SetPivotZ(0.f); },                    // PIVOT_Z
__anon167c01c20602() 81     [](RSProperties* prop) { prop->SetQuaternion(Quaternion()); },       // QUATERNION
__anon167c01c20702() 82     [](RSProperties* prop) { prop->SetRotation(0.f); },                  // ROTATION
__anon167c01c20802() 83     [](RSProperties* prop) { prop->SetRotationX(0.f); },                 // ROTATION_X
__anon167c01c20902() 84     [](RSProperties* prop) { prop->SetRotationY(0.f); },                 // ROTATION_Y
__anon167c01c20a02() 85     [](RSProperties* prop) { prop->SetCameraDistance(0.f); },            // CAMERA_DISTANCE
__anon167c01c20b02() 86     [](RSProperties* prop) { prop->SetScale(Vector2f(1.f, 1.f)); },      // SCALE
__anon167c01c20c02() 87     [](RSProperties* prop) { prop->SetScaleZ(1.f); },                    // SCALE_Z
__anon167c01c20d02() 88     [](RSProperties* prop) { prop->SetSkew({0.f, 0.f, 0.f}); },          // SKEW
__anon167c01c20e02() 89     [](RSProperties* prop) { prop->SetPersp({0.f, 0.f, 0.f, 1.f}); },    // PERSP
__anon167c01c20f02() 90     [](RSProperties* prop) { prop->SetTranslate(Vector2f(0.f, 0.f)); },  // TRANSLATE
__anon167c01c21002() 91     [](RSProperties* prop) { prop->SetTranslateZ(0.f); },                // TRANSLATE_Z
__anon167c01c21102() 92     [](RSProperties* prop) { prop->SetSublayerTransform({}); },          // SUBLAYER_TRANSFORM
__anon167c01c21202() 93     [](RSProperties* prop) { prop->SetCornerRadius(0.f); },              // CORNER_RADIUS
__anon167c01c21302() 94     [](RSProperties* prop) { prop->SetAlpha(1.f); },                     // ALPHA
__anon167c01c21402() 95     [](RSProperties* prop) { prop->SetAlphaOffscreen(false); },          // ALPHA_OFFSCREEN
__anon167c01c21502() 96     [](RSProperties* prop) { prop->SetForegroundColor({}); },            // FOREGROUND_COLOR
__anon167c01c21602() 97     [](RSProperties* prop) { prop->SetBackgroundColor({}); },            // BACKGROUND_COLOR
__anon167c01c21702() 98     [](RSProperties* prop) { prop->SetBackgroundShader({}); },           // BACKGROUND_SHADER
__anon167c01c21802() 99     [](RSProperties* prop) { prop->SetBackgroundShaderProgress(0.f); },  // BACKGROUND_SHADER_PROGRESS
__anon167c01c21902() 100     [](RSProperties* prop) { prop->SetBgImage({}); },                    // BG_IMAGE
__anon167c01c21a02() 101     [](RSProperties* prop) { prop->SetBgImageInnerRect({}); },           // BG_IMAGE_INNER_RECT
__anon167c01c21b02() 102     [](RSProperties* prop) { prop->SetBgImageWidth(0.f); },              // BG_IMAGE_WIDTH
__anon167c01c21c02() 103     [](RSProperties* prop) { prop->SetBgImageHeight(0.f); },             // BG_IMAGE_HEIGHT
__anon167c01c21d02() 104     [](RSProperties* prop) { prop->SetBgImagePositionX(0.f); },          // BG_IMAGE_POSITION_X
__anon167c01c21e02() 105     [](RSProperties* prop) { prop->SetBgImagePositionY(0.f); },          // BG_IMAGE_POSITION_Y
106     nullptr,                                                             // SURFACE_BG_COLOR
__anon167c01c21f02() 107     [](RSProperties* prop) { prop->SetBorderColor(RSColor()); },         // BORDER_COLOR
__anon167c01c22002() 108     [](RSProperties* prop) { prop->SetBorderWidth(0.f); },               // BORDER_WIDTH
__anon167c01c22102() 109     [](RSProperties* prop) { prop->SetBorderStyle(BORDER_TYPE_NONE); },  // BORDER_STYLE
__anon167c01c22202() 110     [](RSProperties* prop) { prop->SetBorderDashWidth({-1.f}); },        // BORDER_DASH_WIDTH
__anon167c01c22302() 111     [](RSProperties* prop) { prop->SetBorderDashGap({-1.f}); },          // BORDER_DASH_GAP
__anon167c01c22402() 112     [](RSProperties* prop) { prop->SetFilter({}); },                     // FILTER
__anon167c01c22502() 113     [](RSProperties* prop) { prop->SetBackgroundFilter({}); },           // BACKGROUND_FILTER
__anon167c01c22602() 114     [](RSProperties* prop) { prop->SetLinearGradientBlurPara({}); },     // LINEAR_GRADIENT_BLUR_PARA
__anon167c01c22702() 115     [](RSProperties* prop) { prop->SetDynamicLightUpRate({}); },         // DYNAMIC_LIGHT_UP_RATE
__anon167c01c22802() 116     [](RSProperties* prop) { prop->SetDynamicLightUpDegree({}); },       // DYNAMIC_LIGHT_UP_DEGREE
__anon167c01c22902() 117     [](RSProperties* prop) { prop->SetFgBrightnessRates({}); },          // FG_BRIGHTNESS_PARAMS
__anon167c01c22a02() 118     [](RSProperties* prop) { prop->SetFgBrightnessSaturation(0.0); },     // FG_BRIGHTNESS_PARAMS
__anon167c01c22b02() 119     [](RSProperties* prop) { prop->SetFgBrightnessPosCoeff({}); },       // FG_BRIGHTNESS_PARAMS
__anon167c01c22c02() 120     [](RSProperties* prop) { prop->SetFgBrightnessNegCoeff({}); },       // FG_BRIGHTNESS_PARAMS
__anon167c01c22d02() 121     [](RSProperties* prop) { prop->SetFgBrightnessFract({}); },          // FG_BRIGHTNESS_FRACTION
__anon167c01c22e02() 122     [](RSProperties* prop) { prop->SetBgBrightnessRates({}); },          // BG_BRIGHTNESS_PARAMS
__anon167c01c22f02() 123     [](RSProperties* prop) { prop->SetBgBrightnessSaturation(0.0); },     // BG_BRIGHTNESS_PARAMS
__anon167c01c23002() 124     [](RSProperties* prop) { prop->SetBgBrightnessPosCoeff({}); },       // BG_BRIGHTNESS_PARAMS
__anon167c01c23102() 125     [](RSProperties* prop) { prop->SetBgBrightnessNegCoeff({}); },       // BG_BRIGHTNESS_PARAMS
__anon167c01c23202() 126     [](RSProperties* prop) { prop->SetBgBrightnessFract(1.0); },          // BG_BRIGHTNESS_FRACTION
__anon167c01c23302() 127     [](RSProperties* prop) { prop->SetFrameGravity(Gravity::DEFAULT); }, // FRAME_GRAVITY
__anon167c01c23402() 128     [](RSProperties* prop) { prop->SetClipRRect({}); },                  // CLIP_RRECT
__anon167c01c23502() 129     [](RSProperties* prop) { prop->SetClipBounds({}); },                 // CLIP_BOUNDS
__anon167c01c23602() 130     [](RSProperties* prop) { prop->SetClipToBounds(false); },            // CLIP_TO_BOUNDS
__anon167c01c23702() 131     [](RSProperties* prop) { prop->SetClipToFrame(false); },             // CLIP_TO_FRAME
__anon167c01c23802() 132     [](RSProperties* prop) { prop->SetVisible(true); },                  // VISIBLE
__anon167c01c23902() 133     [](RSProperties* prop) { prop->SetShadowColor({}); },                // SHADOW_COLOR
__anon167c01c23a02() 134     [](RSProperties* prop) { prop->SetShadowOffsetX(0.f); },             // SHADOW_OFFSET_X
__anon167c01c23b02() 135     [](RSProperties* prop) { prop->SetShadowOffsetY(0.f); },             // SHADOW_OFFSET_Y
__anon167c01c23c02() 136     [](RSProperties* prop) { prop->SetShadowAlpha(0.f); },               // SHADOW_ALPHA
__anon167c01c23d02() 137     [](RSProperties* prop) { prop->SetShadowElevation(0.f); },           // SHADOW_ELEVATION
__anon167c01c23e02() 138     [](RSProperties* prop) { prop->SetShadowRadius(0.f); },              // SHADOW_RADIUS
__anon167c01c23f02() 139     [](RSProperties* prop) { prop->SetShadowPath({}); },                 // SHADOW_PATH
__anon167c01c24002() 140     [](RSProperties* prop) { prop->SetShadowMask(false); },              // SHADOW_MASK
__anon167c01c24102() 141     [](RSProperties* prop) {
142         prop->SetShadowColorStrategy(SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE);    // SHADOW_COLOR_STRATEGY
143     },
__anon167c01c24202() 144     [](RSProperties* prop) { prop->SetMask({}); },                       // MASK
__anon167c01c24302() 145     [](RSProperties* prop) { prop->SetSpherize(0.f); },                  // SPHERIZE
__anon167c01c24402() 146     [](RSProperties* prop) { prop->SetLightUpEffect(1.f); },             // LIGHT_UP_EFFECT
__anon167c01c24502() 147     [](RSProperties* prop) { prop->SetPixelStretch({}); },               // PIXEL_STRETCH
__anon167c01c24602() 148     [](RSProperties* prop) { prop->SetPixelStretch({});
149                              prop->SetPixelStretchPercent({}); },        // PIXEL_STRETCH_PERCENT
__anon167c01c24702() 150     [](RSProperties* prop) { prop->SetPixelStretchTileMode(0); },        // PIXEL_STRETCH_TILE_MODE
__anon167c01c24802() 151     [](RSProperties* prop) { prop->SetUseEffect(false); },               // USE_EFFECT
__anon167c01c24902() 152     [](RSProperties* prop) { prop->SetUseEffectType(0); },               // USE_EFFECT_TYPE
__anon167c01c24a02() 153     [](RSProperties* prop) { prop->SetColorBlendMode(0); },              // COLOR_BLEND_MODE
__anon167c01c24b02() 154     [](RSProperties* prop) { prop->SetColorBlendApplyType(0); },         // COLOR_BLEND_APPLY_TYPE
__anon167c01c24c02() 155     [](RSProperties* prop) { prop->ResetSandBox(); },                    // SANDBOX
__anon167c01c24d02() 156     [](RSProperties* prop) { prop->SetGrayScale({}); },                  // GRAY_SCALE
__anon167c01c24e02() 157     [](RSProperties* prop) { prop->SetBrightness({}); },                 // BRIGHTNESS
__anon167c01c24f02() 158     [](RSProperties* prop) { prop->SetContrast({}); },                   // CONTRAST
__anon167c01c25002() 159     [](RSProperties* prop) { prop->SetSaturate({}); },                   // SATURATE
__anon167c01c25102() 160     [](RSProperties* prop) { prop->SetSepia({}); },                      // SEPIA
__anon167c01c25202() 161     [](RSProperties* prop) { prop->SetInvert({}); },                     // INVERT
__anon167c01c25302() 162     [](RSProperties* prop) { prop->SetAiInvert({}); },                   // AIINVERT
__anon167c01c25402() 163     [](RSProperties* prop) { prop->SetSystemBarEffect({}); },            // SYSTEMBAREFFECT
__anon167c01c25502() 164     [](RSProperties* prop) { prop->SetWaterRippleProgress(0.0f); },      // WATER_RIPPLE_PROGRESS
__anon167c01c25602() 165     [](RSProperties* prop) { prop->SetWaterRippleParams({}); },          // WATER_RIPPLE_PARAMS
__anon167c01c25702() 166     [](RSProperties* prop) { prop->SetHueRotate({}); },                  // HUE_ROTATE
__anon167c01c25802() 167     [](RSProperties* prop) { prop->SetColorBlend({}); },                 // COLOR_BLEND
__anon167c01c25902() 168     [](RSProperties* prop) { prop->SetParticles({}); },                  // PARTICLE
__anon167c01c25a02() 169     [](RSProperties* prop) { prop->SetShadowIsFilled(false); },          // SHADOW_IS_FILLED
__anon167c01c25b02() 170     [](RSProperties* prop) { prop->SetOutlineColor(RSColor()); },        // OUTLINE_COLOR
__anon167c01c25c02() 171     [](RSProperties* prop) { prop->SetOutlineWidth(0.f); },              // OUTLINE_WIDTH
__anon167c01c25d02() 172     [](RSProperties* prop) { prop->SetOutlineStyle(BORDER_TYPE_NONE); }, // OUTLINE_STYLE
__anon167c01c25e02() 173     [](RSProperties* prop) { prop->SetOutlineDashWidth({-1.f}); },       // OUTLINE_DASH_WIDTH
__anon167c01c25f02() 174     [](RSProperties* prop) { prop->SetOutlineDashGap({-1.f}); },         // OUTLINE_DASH_GAP
__anon167c01c26002() 175     [](RSProperties* prop) { prop->SetOutlineRadius(0.f); },             // OUTLINE_RADIUS
__anon167c01c26102() 176     [](RSProperties* prop) { prop->SetGreyCoef(std::nullopt); },         // GREY_COEF
__anon167c01c26202() 177     [](RSProperties* prop) { prop->SetLightIntensity(-1.f); },           // LIGHT_INTENSITY
__anon167c01c26302() 178     [](RSProperties* prop) { prop->SetLightColor({}); },                 // LIGHT_COLOR
__anon167c01c26402() 179     [](RSProperties* prop) { prop->SetLightPosition({}); },              // LIGHT_POSITION
__anon167c01c26502() 180     [](RSProperties* prop) { prop->SetIlluminatedBorderWidth({}); },     // ILLUMINATED_BORDER_WIDTH
__anon167c01c26602() 181     [](RSProperties* prop) { prop->SetIlluminatedType(-1); },            // ILLUMINATED_TYPE
__anon167c01c26702() 182     [](RSProperties* prop) { prop->SetBloom({}); },                      // BLOOM
__anon167c01c26802() 183     [](RSProperties* prop) { prop->SetForegroundEffectRadius(0.f); },    // FOREGROUND_EFFECT_RADIUS
__anon167c01c26902() 184     [](RSProperties* prop) { prop->SetUseShadowBatching(false); },       // USE_SHADOW_BATCHING
__anon167c01c26a02() 185     [](RSProperties* prop) { prop->SetMotionBlurPara({}); },             // MOTION_BLUR_PARA
__anon167c01c26b02() 186     [](RSProperties* prop) { prop->SetEmitterUpdater({}); },             // PARTICLE_EMITTER_UPDATER
__anon167c01c26c02() 187     [](RSProperties* prop) { prop->SetParticleNoiseFields({}); },        // PARTICLE_NOISE_FIELD
__anon167c01c26d02() 188     [](RSProperties* prop) { prop->SetFlyOutDegree(0.0f); },             // FLY_OUT_DEGREE
__anon167c01c26e02() 189     [](RSProperties* prop) { prop->SetFlyOutParams({}); },               // FLY_OUT_PARAMS
__anon167c01c26f02() 190     [](RSProperties* prop) { prop->SetDistortionK(0.0f); },              // DISTORTION_K
__anon167c01c27002() 191     [](RSProperties* prop) { prop->SetDynamicDimDegree({}); },           // DYNAMIC_DIM_DEGREE
__anon167c01c27102() 192     [](RSProperties* prop) { prop->SetMagnifierParams({}); },            // MAGNIFIER_PARA
__anon167c01c27202() 193     [](RSProperties* prop) { prop->SetBackgroundBlurRadius(0.f); },      // BACKGROUND_BLUR_RADIUS
__anon167c01c27302() 194     [](RSProperties* prop) { prop->SetBackgroundBlurSaturation({}); },   // BACKGROUND_BLUR_SATURATION
__anon167c01c27402() 195     [](RSProperties* prop) { prop->SetBackgroundBlurBrightness({}); },   // BACKGROUND_BLUR_BRIGHTNESS
__anon167c01c27502() 196     [](RSProperties* prop) { prop->SetBackgroundBlurMaskColor(RSColor()); }, // BACKGROUND_BLUR_MASKCOLOR
__anon167c01c27602() 197     [](RSProperties* prop) { prop->SetBackgroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT); }, // BACKGROUND_BLUR_COLORMODE
__anon167c01c27702() 198     [](RSProperties* prop) { prop->SetBackgroundBlurRadiusX(0.f); },     // BACKGROUND_BLUR_RADIUS_X
__anon167c01c27802() 199     [](RSProperties* prop) { prop->SetBackgroundBlurRadiusY(0.f); },     // BACKGROUND_BLUR_RADIUS_Y
__anon167c01c27902() 200     [](RSProperties* prop) { prop->SetForegroundBlurRadius(0.f); },      // FOREGROUND_BLUR_RADIUS
__anon167c01c27a02() 201     [](RSProperties* prop) { prop->SetForegroundBlurSaturation({}); },   // FOREGROUND_BLUR_SATURATION
__anon167c01c27b02() 202     [](RSProperties* prop) { prop->SetForegroundBlurBrightness({}); },   // FOREGROUND_BLUR_BRIGHTNESS
__anon167c01c27c02() 203     [](RSProperties* prop) { prop->SetForegroundBlurMaskColor(RSColor()); }, // FOREGROUND_BLUR_MASKCOLOR
__anon167c01c27d02() 204     [](RSProperties* prop) { prop->SetForegroundBlurColorMode(BLUR_COLOR_MODE::DEFAULT); }, // FOREGROUND_BLUR_COLORMODE
__anon167c01c27e02() 205     [](RSProperties* prop) { prop->SetForegroundBlurRadiusX(0.f); },     // FOREGROUND_BLUR_RADIUS_X
__anon167c01c27f02() 206     [](RSProperties* prop) { prop->SetForegroundBlurRadiusY(0.f); },     // FOREGROUND_BLUR_RADIUS_Y
__anon167c01c28002() 207     [](RSProperties* prop) { prop->SetAttractionFraction(0.f); },        // ATTRACTION_FRACTION
__anon167c01c28102() 208     [](RSProperties* prop) { prop->SetAttractionDstPoint({}); },         // ATTRACTION_DSTPOINT
209 };
210 
211 // Check if g_propertyResetterLUT size match and is fully initialized (the last element should never be nullptr)
212 static_assert(g_propertyResetterLUT.size() == static_cast<size_t>(RSModifierType::CUSTOM));
213 static_assert(g_propertyResetterLUT.back() != nullptr);
214 } // namespace
215 
216 // Only enable filter cache when uni-render is enabled and filter cache is enabled
217 #if defined(NEW_SKIA) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
218 #ifndef ROSEN_ARKUI_X
219 bool RSProperties::filterCacheEnabled_ =
220     RSSystemProperties::GetFilterCacheEnabled() && RSUniRenderJudgement::IsUniRender();
SetFilterCacheEnabledByCCM(bool isCCMFilterCacheEnable)221 void RSProperties::SetFilterCacheEnabledByCCM(bool isCCMFilterCacheEnable)
222 {
223     filterCacheEnabled_ = (RSSystemProperties::GetFilterCacheEnabled() &&
224         isCCMFilterCacheEnable) && RSUniRenderJudgement::IsUniRender();
225 }
226 #else
227 bool RSProperties::filterCacheEnabled_ = false;
228 #endif
229 #endif
230 
231 const bool RSProperties::IS_UNI_RENDER = RSUniRenderJudgement::IsUniRender();
232 const bool RSProperties::FOREGROUND_FILTER_ENABLED = RSSystemProperties::GetForegroundFilterEnabled();
233 
RSProperties()234 RSProperties::RSProperties()
235 {
236     boundsGeo_ = std::make_shared<RSObjAbsGeometry>();
237 }
238 
239 RSProperties::~RSProperties() = default;
240 
ResetProperty(const ModifierDirtyTypes & dirtyTypes)241 void RSProperties::ResetProperty(const ModifierDirtyTypes& dirtyTypes)
242 {
243     if (dirtyTypes.none()) {
244         return;
245     }
246     for (uint8_t type = 0; type < static_cast<size_t>(RSModifierType::CUSTOM); type++) {
247         if (dirtyTypes.test(type)) {
248             if (auto& resetFunc = g_propertyResetterLUT[type]) {
249                 resetFunc(this);
250             }
251         }
252     }
253 }
254 
SetBounds(Vector4f bounds)255 void RSProperties::SetBounds(Vector4f bounds)
256 {
257     if (bounds.z_ != boundsGeo_->GetWidth() || bounds.w_ != boundsGeo_->GetHeight()) {
258         contentDirty_ = true;
259     }
260     boundsGeo_->SetRect(bounds.x_, bounds.y_, bounds.z_, bounds.w_);
261     hasBounds_ = true;
262     geoDirty_ = true;
263     SetDirty();
264     if (GetShadowMask()) {
265         filterNeedUpdate_ = true;
266     }
267 }
268 
SetBoundsSize(Vector2f size)269 void RSProperties::SetBoundsSize(Vector2f size)
270 {
271     boundsGeo_->SetSize(size.x_, size.y_);
272     hasBounds_ = true;
273     geoDirty_ = true;
274     contentDirty_ = true;
275     SetDirty();
276 }
277 
SetBoundsWidth(float width)278 void RSProperties::SetBoundsWidth(float width)
279 {
280     boundsGeo_->SetWidth(width);
281     hasBounds_ = true;
282     geoDirty_ = true;
283     contentDirty_ = true;
284     SetDirty();
285 }
286 
SetBoundsHeight(float height)287 void RSProperties::SetBoundsHeight(float height)
288 {
289     boundsGeo_->SetHeight(height);
290     hasBounds_ = true;
291     geoDirty_ = true;
292     contentDirty_ = true;
293     SetDirty();
294 }
295 
SetBoundsPosition(Vector2f position)296 void RSProperties::SetBoundsPosition(Vector2f position)
297 {
298     boundsGeo_->SetPosition(position.x_, position.y_);
299     geoDirty_ = true;
300     SetDirty();
301 }
302 
SetBoundsPositionX(float positionX)303 void RSProperties::SetBoundsPositionX(float positionX)
304 {
305     boundsGeo_->SetX(positionX);
306     geoDirty_ = true;
307     SetDirty();
308 }
309 
SetBoundsPositionY(float positionY)310 void RSProperties::SetBoundsPositionY(float positionY)
311 {
312     boundsGeo_->SetY(positionY);
313     geoDirty_ = true;
314     SetDirty();
315 }
316 
GetBounds() const317 Vector4f RSProperties::GetBounds() const
318 {
319     return { boundsGeo_->GetX(), boundsGeo_->GetY(), boundsGeo_->GetWidth(), boundsGeo_->GetHeight() };
320 }
321 
GetBoundsSize() const322 Vector2f RSProperties::GetBoundsSize() const
323 {
324     return { boundsGeo_->GetWidth(), boundsGeo_->GetHeight() };
325 }
326 
GetBoundsWidth() const327 float RSProperties::GetBoundsWidth() const
328 {
329     return boundsGeo_->GetWidth();
330 }
331 
GetBoundsHeight() const332 float RSProperties::GetBoundsHeight() const
333 {
334     return boundsGeo_->GetHeight();
335 }
336 
GetBoundsPositionX() const337 float RSProperties::GetBoundsPositionX() const
338 {
339     return boundsGeo_->GetX();
340 }
341 
GetBoundsPositionY() const342 float RSProperties::GetBoundsPositionY() const
343 {
344     return boundsGeo_->GetY();
345 }
346 
GetBoundsPosition() const347 Vector2f RSProperties::GetBoundsPosition() const
348 {
349     return { GetBoundsPositionX(), GetBoundsPositionY() };
350 }
351 
SetFrame(Vector4f frame)352 void RSProperties::SetFrame(Vector4f frame)
353 {
354     if (frame.z_ != frameGeo_.GetWidth() || frame.w_ != frameGeo_.GetHeight()) {
355         contentDirty_ = true;
356     }
357     frameGeo_.SetRect(frame.x_, frame.y_, frame.z_, frame.w_);
358     geoDirty_ = true;
359     SetDirty();
360 }
361 
SetFrameSize(Vector2f size)362 void RSProperties::SetFrameSize(Vector2f size)
363 {
364     frameGeo_.SetSize(size.x_, size.y_);
365     geoDirty_ = true;
366     contentDirty_ = true;
367     SetDirty();
368 }
369 
SetFrameWidth(float width)370 void RSProperties::SetFrameWidth(float width)
371 {
372     frameGeo_.SetWidth(width);
373     geoDirty_ = true;
374     contentDirty_ = true;
375     SetDirty();
376 }
377 
SetFrameHeight(float height)378 void RSProperties::SetFrameHeight(float height)
379 {
380     frameGeo_.SetHeight(height);
381     geoDirty_ = true;
382     contentDirty_ = true;
383     SetDirty();
384 }
385 
SetFramePosition(Vector2f position)386 void RSProperties::SetFramePosition(Vector2f position)
387 {
388     frameGeo_.SetPosition(position.x_, position.y_);
389     geoDirty_ = true;
390     SetDirty();
391 }
392 
SetFramePositionX(float positionX)393 void RSProperties::SetFramePositionX(float positionX)
394 {
395     frameGeo_.SetX(positionX);
396     geoDirty_ = true;
397     SetDirty();
398 }
399 
SetFramePositionY(float positionY)400 void RSProperties::SetFramePositionY(float positionY)
401 {
402     frameGeo_.SetY(positionY);
403     geoDirty_ = true;
404     SetDirty();
405 }
406 
GetFrame() const407 Vector4f RSProperties::GetFrame() const
408 {
409     return { frameGeo_.GetX(), frameGeo_.GetY(), frameGeo_.GetWidth(), frameGeo_.GetHeight() };
410 }
411 
GetFrameSize() const412 Vector2f RSProperties::GetFrameSize() const
413 {
414     return { frameGeo_.GetWidth(), frameGeo_.GetHeight() };
415 }
416 
GetFrameWidth() const417 float RSProperties::GetFrameWidth() const
418 {
419     return frameGeo_.GetWidth();
420 }
421 
GetFrameHeight() const422 float RSProperties::GetFrameHeight() const
423 {
424     return frameGeo_.GetHeight();
425 }
426 
GetFramePositionX() const427 float RSProperties::GetFramePositionX() const
428 {
429     return frameGeo_.GetX();
430 }
431 
GetFramePositionY() const432 float RSProperties::GetFramePositionY() const
433 {
434     return frameGeo_.GetY();
435 }
436 
GetFramePosition() const437 Vector2f RSProperties::GetFramePosition() const
438 {
439     return { GetFramePositionX(), GetFramePositionY() };
440 }
441 
GetFrameOffsetX() const442 float RSProperties::GetFrameOffsetX() const
443 {
444     return frameOffsetX_;
445 }
446 
GetFrameOffsetY() const447 float RSProperties::GetFrameOffsetY() const
448 {
449     return frameOffsetY_;
450 }
451 
GetBoundsGeometry() const452 const std::shared_ptr<RSObjAbsGeometry>& RSProperties::GetBoundsGeometry() const
453 {
454     return boundsGeo_;
455 }
456 
GetFrameGeometry() const457 const RSObjGeometry& RSProperties::GetFrameGeometry() const
458 {
459     return frameGeo_;
460 }
461 
UpdateGeometryByParent(const Drawing::Matrix * parentMatrix,const std::optional<Drawing::Point> & offset)462 bool RSProperties::UpdateGeometryByParent(const Drawing::Matrix* parentMatrix,
463     const std::optional<Drawing::Point>& offset)
464 {
465     static thread_local Drawing::Matrix prevAbsMatrix;
466     prevAbsMatrix.Swap(prevAbsMatrix_);
467     boundsGeo_->UpdateMatrix(parentMatrix, offset);
468     prevAbsMatrix_ = boundsGeo_->GetAbsMatrix();
469     if (!RSSystemProperties::GetSkipGeometryNotChangeEnabled()) {
470         return true;
471     }
472     const auto& rect = boundsGeo_->GetAbsRect();
473     if (!lastRect_.has_value()) {
474         lastRect_ = rect;
475         return true;
476     }
477     auto dirtyFlag = (rect != lastRect_.value()) || !(prevAbsMatrix == prevAbsMatrix_);
478     lastRect_ = rect;
479     return dirtyFlag;
480 }
481 
UpdateGeometry(const RSProperties * parent,bool dirtyFlag,const std::optional<Drawing::Point> & offset)482 bool RSProperties::UpdateGeometry(
483     const RSProperties* parent, bool dirtyFlag, const std::optional<Drawing::Point>& offset)
484 {
485     if (!dirtyFlag && !geoDirty_) {
486         return false;
487     }
488     auto parentMatrix = parent == nullptr ? nullptr : &(parent->GetBoundsGeometry()->GetAbsMatrix());
489     if (parentMatrix && sandbox_ && sandbox_->matrix_) {
490         parentMatrix = &(sandbox_->matrix_.value());
491     }
492     boundsGeo_->UpdateMatrix(parentMatrix, offset);
493     if (lightSourcePtr_ && lightSourcePtr_->IsLightSourceValid()) {
494         CalculateAbsLightPosition();
495         RSPointLightManager::Instance()->AddDirtyLightSource(backref_);
496     }
497     if (illuminatedPtr_ && illuminatedPtr_->IsIlluminatedValid()) {
498         RSPointLightManager::Instance()->AddDirtyIlluminated(backref_);
499     }
500     if (RSSystemProperties::GetSkipGeometryNotChangeEnabled()) {
501         auto rect = boundsGeo_->GetAbsRect();
502         if (!lastRect_.has_value()) {
503             lastRect_ = rect;
504             return true;
505         }
506         dirtyFlag = dirtyFlag || rect != lastRect_.value();
507         lastRect_ = rect;
508         return dirtyFlag;
509     } else {
510         return true;
511     }
512 }
513 
SetSandBox(const std::optional<Vector2f> & parentPosition)514 void RSProperties::SetSandBox(const std::optional<Vector2f>& parentPosition)
515 {
516     if (!sandbox_) {
517         sandbox_ = std::make_unique<Sandbox>();
518     }
519     sandbox_->position_ = parentPosition;
520     geoDirty_ = true;
521     SetDirty();
522 }
523 
GetSandBox() const524 std::optional<Vector2f> RSProperties::GetSandBox() const
525 {
526     return sandbox_ ? sandbox_->position_ : std::nullopt;
527 }
528 
ResetSandBox()529 void RSProperties::ResetSandBox()
530 {
531     sandbox_ = nullptr;
532 }
533 
UpdateSandBoxMatrix(const std::optional<Drawing::Matrix> & rootMatrix)534 void RSProperties::UpdateSandBoxMatrix(const std::optional<Drawing::Matrix>& rootMatrix)
535 {
536     if (!sandbox_) {
537         return;
538     }
539     if (!rootMatrix || !sandbox_->position_) {
540         sandbox_->matrix_ = std::nullopt;
541         return;
542     }
543     auto rootMat = rootMatrix.value();
544     bool hasScale = false;
545     // scaleFactors[0]-minimum scaling factor, scaleFactors[1]-maximum scaling factor
546     Drawing::scalar scaleFactors[2];
547     bool getMinMaxScales = rootMat.GetMinMaxScales(scaleFactors);
548     if (getMinMaxScales) {
549         hasScale = !ROSEN_EQ(scaleFactors[0], 1.f) || !ROSEN_EQ(scaleFactors[1], 1.f);
550     }
551     if (hasScale) {
552         sandbox_->matrix_ = std::nullopt;
553         return;
554     }
555     Drawing::Matrix matrix = rootMatrix.value();
556     matrix.PreTranslate(sandbox_->position_->x_, sandbox_->position_->y_);
557     sandbox_->matrix_ = matrix;
558 }
559 
GetSandBoxMatrix() const560 std::optional<Drawing::Matrix> RSProperties::GetSandBoxMatrix() const
561 {
562     return sandbox_ ? sandbox_->matrix_ : std::nullopt;
563 }
564 
SetPositionZ(float positionZ)565 void RSProperties::SetPositionZ(float positionZ)
566 {
567     boundsGeo_->SetZ(positionZ);
568     frameGeo_.SetZ(positionZ);
569     geoDirty_ = true;
570     SetDirty();
571 }
572 
GetPositionZ() const573 float RSProperties::GetPositionZ() const
574 {
575     return boundsGeo_->GetZ();
576 }
577 
SetPositionZApplicableCamera3D(bool isApplicable)578 void RSProperties::SetPositionZApplicableCamera3D(bool isApplicable)
579 {
580     boundsGeo_->SetZApplicableCamera3D(isApplicable);
581     geoDirty_ = true;
582     SetDirty();
583 }
584 
GetPositionZApplicableCamera3D() const585 bool RSProperties::GetPositionZApplicableCamera3D() const
586 {
587     return boundsGeo_->GetZApplicableCamera3D();
588 }
589 
SetPivot(Vector2f pivot)590 void RSProperties::SetPivot(Vector2f pivot)
591 {
592     boundsGeo_->SetPivot(pivot.x_, pivot.y_);
593     geoDirty_ = true;
594     SetDirty();
595 }
596 
SetPivotX(float pivotX)597 void RSProperties::SetPivotX(float pivotX)
598 {
599     boundsGeo_->SetPivotX(pivotX);
600     geoDirty_ = true;
601     SetDirty();
602 }
603 
SetPivotY(float pivotY)604 void RSProperties::SetPivotY(float pivotY)
605 {
606     boundsGeo_->SetPivotY(pivotY);
607     geoDirty_ = true;
608     SetDirty();
609 }
610 
SetPivotZ(float pivotZ)611 void RSProperties::SetPivotZ(float pivotZ)
612 {
613     boundsGeo_->SetPivotZ(pivotZ);
614     geoDirty_ = true;
615     SetDirty();
616 }
617 
GetPivot() const618 Vector2f RSProperties::GetPivot() const
619 {
620     return { boundsGeo_->GetPivotX(), boundsGeo_->GetPivotY() };
621 }
622 
GetPivotX() const623 float RSProperties::GetPivotX() const
624 {
625     return boundsGeo_->GetPivotX();
626 }
627 
GetPivotY() const628 float RSProperties::GetPivotY() const
629 {
630     return boundsGeo_->GetPivotY();
631 }
632 
GetPivotZ() const633 float RSProperties::GetPivotZ() const
634 {
635     return boundsGeo_->GetPivotZ();
636 }
637 
SetCornerRadius(const Vector4f & cornerRadius)638 void RSProperties::SetCornerRadius(const Vector4f& cornerRadius)
639 {
640     cornerRadius_ = cornerRadius;
641     SetDirty();
642     if (GetShadowMask()) {
643         filterNeedUpdate_ = true;
644     }
645     contentDirty_ = true;
646 }
647 
GetCornerRadius() const648 const Vector4f& RSProperties::GetCornerRadius() const
649 {
650     return cornerRadius_ ? cornerRadius_.value() : Vector4fZero;
651 }
652 
SetQuaternion(Quaternion quaternion)653 void RSProperties::SetQuaternion(Quaternion quaternion)
654 {
655     boundsGeo_->SetQuaternion(quaternion);
656     geoDirty_ = true;
657     SetDirty();
658 }
659 
SetRotation(float degree)660 void RSProperties::SetRotation(float degree)
661 {
662     boundsGeo_->SetRotation(degree);
663     geoDirty_ = true;
664     SetDirty();
665 }
666 
SetRotationX(float degree)667 void RSProperties::SetRotationX(float degree)
668 {
669     boundsGeo_->SetRotationX(degree);
670     geoDirty_ = true;
671     SetDirty();
672 }
673 
SetRotationY(float degree)674 void RSProperties::SetRotationY(float degree)
675 {
676     boundsGeo_->SetRotationY(degree);
677     geoDirty_ = true;
678     SetDirty();
679 }
680 
SetCameraDistance(float cameraDistance)681 void RSProperties::SetCameraDistance(float cameraDistance)
682 {
683     boundsGeo_->SetCameraDistance(cameraDistance);
684     geoDirty_ = true;
685     SetDirty();
686 }
687 
SetScale(Vector2f scale)688 void RSProperties::SetScale(Vector2f scale)
689 {
690     boundsGeo_->SetScale(scale.x_, scale.y_);
691     geoDirty_ = true;
692     SetDirty();
693 }
694 
SetScaleZ(float sz)695 void RSProperties::SetScaleZ(float sz)
696 {
697     boundsGeo_->SetScaleZ(sz);
698     geoDirty_ = true;
699     SetDirty();
700 }
701 
SetScaleX(float sx)702 void RSProperties::SetScaleX(float sx)
703 {
704     boundsGeo_->SetScaleX(sx);
705     geoDirty_ = true;
706     SetDirty();
707 }
708 
SetScaleY(float sy)709 void RSProperties::SetScaleY(float sy)
710 {
711     boundsGeo_->SetScaleY(sy);
712     geoDirty_ = true;
713     SetDirty();
714 }
715 
SetSkew(const Vector3f & skew)716 void RSProperties::SetSkew(const Vector3f& skew)
717 {
718     boundsGeo_->SetSkew(skew.x_, skew.y_, skew.z_);
719     geoDirty_ = true;
720     SetDirty();
721 }
722 
SetSkewX(float skewX)723 void RSProperties::SetSkewX(float skewX)
724 {
725     boundsGeo_->SetSkewX(skewX);
726     geoDirty_ = true;
727     SetDirty();
728 }
729 
SetSkewY(float skewY)730 void RSProperties::SetSkewY(float skewY)
731 {
732     boundsGeo_->SetSkewY(skewY);
733     geoDirty_ = true;
734     SetDirty();
735 }
736 
SetSkewZ(float skewZ)737 void RSProperties::SetSkewZ(float skewZ)
738 {
739     boundsGeo_->SetSkewZ(skewZ);
740     geoDirty_ = true;
741     SetDirty();
742 }
743 
SetPersp(const Vector4f & persp)744 void RSProperties::SetPersp(const Vector4f& persp)
745 {
746     boundsGeo_->SetPersp(persp.x_, persp.y_, persp.z_, persp.w_);
747     geoDirty_ = true;
748     SetDirty();
749 }
750 
SetPerspX(float perspX)751 void RSProperties::SetPerspX(float perspX)
752 {
753     boundsGeo_->SetPerspX(perspX);
754     geoDirty_ = true;
755     SetDirty();
756 }
757 
SetPerspY(float perspY)758 void RSProperties::SetPerspY(float perspY)
759 {
760     boundsGeo_->SetPerspY(perspY);
761     geoDirty_ = true;
762     SetDirty();
763 }
764 
SetPerspZ(float perspZ)765 void RSProperties::SetPerspZ(float perspZ)
766 {
767     boundsGeo_->SetPerspZ(perspZ);
768     geoDirty_ = true;
769     SetDirty();
770 }
771 
SetPerspW(float perspW)772 void RSProperties::SetPerspW(float perspW)
773 {
774     boundsGeo_->SetPerspW(perspW);
775     geoDirty_ = true;
776     SetDirty();
777 }
778 
SetTranslate(Vector2f translate)779 void RSProperties::SetTranslate(Vector2f translate)
780 {
781     boundsGeo_->SetTranslateX(translate[0]);
782     boundsGeo_->SetTranslateY(translate[1]);
783     geoDirty_ = true;
784     SetDirty();
785 }
786 
SetTranslateX(float translate)787 void RSProperties::SetTranslateX(float translate)
788 {
789     boundsGeo_->SetTranslateX(translate);
790     geoDirty_ = true;
791     SetDirty();
792 }
793 
SetTranslateY(float translate)794 void RSProperties::SetTranslateY(float translate)
795 {
796     boundsGeo_->SetTranslateY(translate);
797     geoDirty_ = true;
798     SetDirty();
799 }
800 
SetTranslateZ(float translate)801 void RSProperties::SetTranslateZ(float translate)
802 {
803     boundsGeo_->SetTranslateZ(translate);
804     geoDirty_ = true;
805     SetDirty();
806 }
807 
GetQuaternion() const808 Quaternion RSProperties::GetQuaternion() const
809 {
810     return boundsGeo_->GetQuaternion();
811 }
812 
GetRotation() const813 float RSProperties::GetRotation() const
814 {
815     return boundsGeo_->GetRotation();
816 }
817 
GetRotationX() const818 float RSProperties::GetRotationX() const
819 {
820     return boundsGeo_->GetRotationX();
821 }
822 
GetRotationY() const823 float RSProperties::GetRotationY() const
824 {
825     return boundsGeo_->GetRotationY();
826 }
827 
GetCameraDistance() const828 float RSProperties::GetCameraDistance() const
829 {
830     return boundsGeo_->GetCameraDistance();
831 }
832 
GetScaleX() const833 float RSProperties::GetScaleX() const
834 {
835     return boundsGeo_->GetScaleX();
836 }
837 
GetScaleY() const838 float RSProperties::GetScaleY() const
839 {
840     return boundsGeo_->GetScaleY();
841 }
842 
GetScaleZ() const843 float RSProperties::GetScaleZ() const
844 {
845     return boundsGeo_->GetScaleZ();
846 }
847 
GetScale() const848 Vector2f RSProperties::GetScale() const
849 {
850     return { boundsGeo_->GetScaleX(), boundsGeo_->GetScaleY() };
851 }
852 
GetSkewX() const853 float RSProperties::GetSkewX() const
854 {
855     return boundsGeo_->GetSkewX();
856 }
857 
GetSkewY() const858 float RSProperties::GetSkewY() const
859 {
860     return boundsGeo_->GetSkewY();
861 }
862 
GetSkewZ() const863 float RSProperties::GetSkewZ() const
864 {
865     return boundsGeo_->GetSkewZ();
866 }
867 
GetSkew() const868 Vector3f RSProperties::GetSkew() const
869 {
870     return { boundsGeo_->GetSkewX(), boundsGeo_->GetSkewY(), boundsGeo_->GetSkewZ() };
871 }
872 
GetPerspX() const873 float RSProperties::GetPerspX() const
874 {
875     return boundsGeo_->GetPerspX();
876 }
877 
GetPerspY() const878 float RSProperties::GetPerspY() const
879 {
880     return boundsGeo_->GetPerspY();
881 }
882 
GetPerspZ() const883 float RSProperties::GetPerspZ() const
884 {
885     return boundsGeo_->GetPerspZ();
886 }
887 
GetPerspW() const888 float RSProperties::GetPerspW() const
889 {
890     return boundsGeo_->GetPerspW();
891 }
892 
GetPersp() const893 Vector4f RSProperties::GetPersp() const
894 {
895     return { boundsGeo_->GetPerspX(), boundsGeo_->GetPerspY(), boundsGeo_->GetPerspZ(), boundsGeo_->GetPerspW() };
896 }
897 
GetTranslate() const898 Vector2f RSProperties::GetTranslate() const
899 {
900     return Vector2f(GetTranslateX(), GetTranslateY());
901 }
902 
GetTranslateX() const903 float RSProperties::GetTranslateX() const
904 {
905     return boundsGeo_->GetTranslateX();
906 }
907 
GetTranslateY() const908 float RSProperties::GetTranslateY() const
909 {
910     return boundsGeo_->GetTranslateY();
911 }
912 
GetTranslateZ() const913 float RSProperties::GetTranslateZ() const
914 {
915     return boundsGeo_->GetTranslateZ();
916 }
917 
SetParticles(const RSRenderParticleVector & particles)918 void RSProperties::SetParticles(const RSRenderParticleVector& particles)
919 {
920     particles_ = particles;
921     if (particles_.GetParticleSize() > 0) {
922         isDrawn_ = true;
923     }
924     SetDirty();
925     contentDirty_ = true;
926 }
927 
GetParticles() const928 const RSRenderParticleVector& RSProperties::GetParticles() const
929 {
930     return particles_;
931 }
932 
SetAlpha(float alpha)933 void RSProperties::SetAlpha(float alpha)
934 {
935     alpha_ = alpha;
936     if (alpha_ < 1.f) {
937         alphaNeedApply_ = true;
938     }
939     SetDirty();
940 }
941 
GetAlpha() const942 float RSProperties::GetAlpha() const
943 {
944     return alpha_;
945 }
SetAlphaOffscreen(bool alphaOffscreen)946 void RSProperties::SetAlphaOffscreen(bool alphaOffscreen)
947 {
948     alphaOffscreen_ = alphaOffscreen;
949     SetDirty();
950     contentDirty_ = true;
951 }
952 
GetAlphaOffscreen() const953 bool RSProperties::GetAlphaOffscreen() const
954 {
955     return alphaOffscreen_;
956 }
957 
SetSublayerTransform(const std::optional<Matrix3f> & sublayerTransform)958 void RSProperties::SetSublayerTransform(const std::optional<Matrix3f>& sublayerTransform)
959 {
960     sublayerTransform_ = sublayerTransform;
961     SetDirty();
962 }
963 
GetSublayerTransform() const964 const std::optional<Matrix3f>& RSProperties::GetSublayerTransform() const
965 {
966     return sublayerTransform_;
967 }
968 
969 // foreground properties
SetForegroundColor(Color color)970 void RSProperties::SetForegroundColor(Color color)
971 {
972     if (!decoration_) {
973         decoration_ = std::make_optional<Decoration>();
974     }
975     decoration_->foregroundColor_ = color;
976     SetDirty();
977     contentDirty_ = true;
978 }
979 
GetForegroundColor() const980 Color RSProperties::GetForegroundColor() const
981 {
982     return decoration_ ? decoration_->foregroundColor_ : RgbPalette::Transparent();
983 }
984 
985 // background properties
SetBackgroundColor(Color color)986 void RSProperties::SetBackgroundColor(Color color)
987 {
988     if (!decoration_) {
989         decoration_ = std::make_optional<Decoration>();
990     }
991     if (color.GetAlpha() > 0) {
992         isDrawn_ = true;
993     }
994     decoration_->backgroundColor_ = color;
995     SetDirty();
996     contentDirty_ = true;
997 }
998 
GetBackgroundColor() const999 const Color& RSProperties::GetBackgroundColor() const
1000 {
1001     return decoration_ ? decoration_->backgroundColor_ : RgbPalette::Transparent();
1002 }
1003 
SetBackgroundShader(const std::shared_ptr<RSShader> & shader)1004 void RSProperties::SetBackgroundShader(const std::shared_ptr<RSShader>& shader)
1005 {
1006     if (!decoration_) {
1007         decoration_ = std::make_optional<Decoration>();
1008     }
1009     if (shader) {
1010         isDrawn_ = true;
1011     }
1012     decoration_->bgShader_ = shader;
1013     bgShaderNeedUpdate_ = true;
1014     SetDirty();
1015     contentDirty_ = true;
1016 }
1017 
GetBackgroundShader() const1018 std::shared_ptr<RSShader> RSProperties::GetBackgroundShader() const
1019 {
1020     return decoration_ ? decoration_->bgShader_ : nullptr;
1021 }
1022 
SetBackgroundShaderProgress(const float & progress)1023 void RSProperties::SetBackgroundShaderProgress(const float& progress)
1024 {
1025     if (!decoration_) {
1026         decoration_ = std::make_optional<Decoration>();
1027     }
1028     isDrawn_ = true;
1029     decoration_->bgShaderProgress_ = progress;
1030     bgShaderNeedUpdate_ = true;
1031     SetDirty();
1032     contentDirty_ = true;
1033 }
1034 
GetBackgroundShaderProgress() const1035 float RSProperties::GetBackgroundShaderProgress() const
1036 {
1037     return decoration_ ? decoration_->bgShaderProgress_ : -1.f;
1038 }
1039 
1040 
SetBgImage(const std::shared_ptr<RSImage> & image)1041 void RSProperties::SetBgImage(const std::shared_ptr<RSImage>& image)
1042 {
1043     if (!decoration_) {
1044         decoration_ = std::make_optional<Decoration>();
1045     }
1046     if (image) {
1047         isDrawn_ = true;
1048     }
1049     decoration_->bgImage_ = image;
1050     SetDirty();
1051     contentDirty_ = true;
1052 }
1053 
GetBgImage() const1054 std::shared_ptr<RSImage> RSProperties::GetBgImage() const
1055 {
1056     return decoration_ ? decoration_->bgImage_ : nullptr;
1057 }
1058 
SetBgImageInnerRect(const Vector4f & rect)1059 void RSProperties::SetBgImageInnerRect(const Vector4f& rect)
1060 {
1061     if (!decoration_) {
1062         decoration_ = std::make_optional<Decoration>();
1063     }
1064     decoration_->bgImageInnerRect_ = rect;
1065     SetDirty();
1066     contentDirty_ = true;
1067 }
1068 
GetBgImageInnerRect() const1069 Vector4f RSProperties::GetBgImageInnerRect() const
1070 {
1071     return decoration_ ? decoration_->bgImageInnerRect_ : Vector4f();
1072 }
1073 
SetBgImageWidth(float width)1074 void RSProperties::SetBgImageWidth(float width)
1075 {
1076     if (!decoration_) {
1077         decoration_ = std::make_optional<Decoration>();
1078     }
1079     decoration_->bgImageRect_.width_ = width;
1080     SetDirty();
1081     contentDirty_ = true;
1082 }
1083 
SetBgImageHeight(float height)1084 void RSProperties::SetBgImageHeight(float height)
1085 {
1086     if (!decoration_) {
1087         decoration_ = std::make_optional<Decoration>();
1088     }
1089     decoration_->bgImageRect_.height_ = height;
1090     SetDirty();
1091     contentDirty_ = true;
1092 }
1093 
SetBgImagePositionX(float positionX)1094 void RSProperties::SetBgImagePositionX(float positionX)
1095 {
1096     if (!decoration_) {
1097         decoration_ = std::make_optional<Decoration>();
1098     }
1099     decoration_->bgImageRect_.left_ = positionX;
1100     SetDirty();
1101     contentDirty_ = true;
1102 }
1103 
SetBgImagePositionY(float positionY)1104 void RSProperties::SetBgImagePositionY(float positionY)
1105 {
1106     if (!decoration_) {
1107         decoration_ = std::make_optional<Decoration>();
1108     }
1109     decoration_->bgImageRect_.top_ = positionY;
1110     SetDirty();
1111     contentDirty_ = true;
1112 }
1113 
GetBgImageWidth() const1114 float RSProperties::GetBgImageWidth() const
1115 {
1116     return decoration_ ? decoration_->bgImageRect_.width_ : 0.f;
1117 }
1118 
GetBgImageHeight() const1119 float RSProperties::GetBgImageHeight() const
1120 {
1121     return decoration_ ? decoration_->bgImageRect_.height_ : 0.f;
1122 }
1123 
GetBgImagePositionX() const1124 float RSProperties::GetBgImagePositionX() const
1125 {
1126     return decoration_ ? decoration_->bgImageRect_.left_ : 0.f;
1127 }
1128 
GetBgImagePositionY() const1129 float RSProperties::GetBgImagePositionY() const
1130 {
1131     return decoration_ ? decoration_->bgImageRect_.top_ : 0.f;
1132 }
1133 
1134 // border properties
SetBorderColor(Vector4<Color> color)1135 void RSProperties::SetBorderColor(Vector4<Color> color)
1136 {
1137     if (!border_) {
1138         border_ = std::make_shared<RSBorder>();
1139     }
1140     border_->SetColorFour(color);
1141     if (border_->GetColor().GetAlpha() > 0) {
1142         isDrawn_ = true;
1143     }
1144     SetDirty();
1145     contentDirty_ = true;
1146 }
1147 
SetBorderWidth(Vector4f width)1148 void RSProperties::SetBorderWidth(Vector4f width)
1149 {
1150     if (!border_) {
1151         border_ = std::make_shared<RSBorder>();
1152     }
1153     border_->SetWidthFour(width);
1154     if (!width.IsZero()) {
1155         isDrawn_ = true;
1156     }
1157     SetDirty();
1158     contentDirty_ = true;
1159 }
1160 
SetBorderStyle(Vector4<uint32_t> style)1161 void RSProperties::SetBorderStyle(Vector4<uint32_t> style)
1162 {
1163     if (!border_) {
1164         border_ = std::make_shared<RSBorder>();
1165     }
1166     border_->SetStyleFour(style);
1167     SetDirty();
1168     contentDirty_ = true;
1169 }
1170 
SetBorderDashWidth(const Vector4f & dashWidth)1171 void RSProperties::SetBorderDashWidth(const Vector4f& dashWidth)
1172 {
1173     if (!border_) {
1174         border_ = std::make_shared<RSBorder>();
1175     }
1176     border_->SetDashWidthFour(dashWidth);
1177     SetDirty();
1178     contentDirty_ = true;
1179 }
1180 
SetBorderDashGap(const Vector4f & dashGap)1181 void RSProperties::SetBorderDashGap(const Vector4f& dashGap)
1182 {
1183     if (!border_) {
1184         border_ = std::make_shared<RSBorder>();
1185     }
1186     border_->SetDashGapFour(dashGap);
1187     SetDirty();
1188     contentDirty_ = true;
1189 }
1190 
GetBorderColor() const1191 Vector4<Color> RSProperties::GetBorderColor() const
1192 {
1193     return border_ ? border_->GetColorFour() : Vector4<Color>(RgbPalette::Transparent());
1194 }
1195 
GetBorderWidth() const1196 Vector4f RSProperties::GetBorderWidth() const
1197 {
1198     return border_ ? border_->GetWidthFour() : Vector4f(0.f);
1199 }
1200 
GetBorderStyle() const1201 Vector4<uint32_t> RSProperties::GetBorderStyle() const
1202 {
1203     return border_ ? border_->GetStyleFour() : Vector4<uint32_t>(static_cast<uint32_t>(BorderStyle::NONE));
1204 }
1205 
GetBorderDashWidth() const1206 Vector4f RSProperties::GetBorderDashWidth() const
1207 {
1208     return border_ ? border_->GetDashWidthFour() : Vector4f(0.f);
1209 }
1210 
GetBorderDashGap() const1211 Vector4f RSProperties::GetBorderDashGap() const
1212 {
1213     return border_ ? border_->GetDashGapFour() : Vector4f(0.f);
1214 }
1215 
GetBorder() const1216 const std::shared_ptr<RSBorder>& RSProperties::GetBorder() const
1217 {
1218     return border_;
1219 }
1220 
SetOutlineColor(Vector4<Color> color)1221 void RSProperties::SetOutlineColor(Vector4<Color> color)
1222 {
1223     if (!outline_) {
1224         outline_ = std::make_shared<RSBorder>(true);
1225     }
1226     outline_->SetColorFour(color);
1227     if (outline_->GetColor().GetAlpha() > 0) {
1228         isDrawn_ = true;
1229     }
1230     SetDirty();
1231     contentDirty_ = true;
1232 }
1233 
SetOutlineWidth(Vector4f width)1234 void RSProperties::SetOutlineWidth(Vector4f width)
1235 {
1236     if (!outline_) {
1237         outline_ = std::make_shared<RSBorder>(true);
1238     }
1239     outline_->SetWidthFour(width);
1240     if (!width.IsZero()) {
1241         isDrawn_ = true;
1242     }
1243     SetDirty();
1244     contentDirty_ = true;
1245 }
1246 
SetOutlineStyle(Vector4<uint32_t> style)1247 void RSProperties::SetOutlineStyle(Vector4<uint32_t> style)
1248 {
1249     if (!outline_) {
1250         outline_ = std::make_shared<RSBorder>(true);
1251     }
1252     outline_->SetStyleFour(style);
1253     SetDirty();
1254     contentDirty_ = true;
1255 }
1256 
SetOutlineDashWidth(const Vector4f & dashWidth)1257 void RSProperties::SetOutlineDashWidth(const Vector4f& dashWidth)
1258 {
1259     if (!outline_) {
1260         outline_ = std::make_shared<RSBorder>();
1261     }
1262     outline_->SetDashWidthFour(dashWidth);
1263     SetDirty();
1264     contentDirty_ = true;
1265 }
1266 
SetOutlineDashGap(const Vector4f & dashGap)1267 void RSProperties::SetOutlineDashGap(const Vector4f& dashGap)
1268 {
1269     if (!outline_) {
1270         outline_ = std::make_shared<RSBorder>();
1271     }
1272     outline_->SetDashGapFour(dashGap);
1273     SetDirty();
1274     contentDirty_ = true;
1275 }
1276 
SetOutlineRadius(Vector4f radius)1277 void RSProperties::SetOutlineRadius(Vector4f radius)
1278 {
1279     if (!outline_) {
1280         outline_ = std::make_shared<RSBorder>(true);
1281     }
1282     outline_->SetRadiusFour(radius);
1283     isDrawn_ = true;
1284     SetDirty();
1285     contentDirty_ = true;
1286 }
1287 
GetOutlineColor() const1288 Vector4<Color> RSProperties::GetOutlineColor() const
1289 {
1290     return outline_ ? outline_->GetColorFour() : Vector4<Color>(RgbPalette::Transparent());
1291 }
1292 
GetOutlineWidth() const1293 Vector4f RSProperties::GetOutlineWidth() const
1294 {
1295     return outline_ ? outline_->GetWidthFour() : Vector4f(0.f);
1296 }
1297 
GetOutlineStyle() const1298 Vector4<uint32_t> RSProperties::GetOutlineStyle() const
1299 {
1300     return outline_ ? outline_->GetStyleFour() : Vector4<uint32_t>(static_cast<uint32_t>(BorderStyle::NONE));
1301 }
1302 
GetOutlineDashWidth() const1303 Vector4f RSProperties::GetOutlineDashWidth() const
1304 {
1305     return outline_ ? outline_->GetDashWidthFour() : Vector4f(0.f);
1306 }
1307 
GetOutlineDashGap() const1308 Vector4f RSProperties::GetOutlineDashGap() const
1309 {
1310     return outline_ ? outline_->GetDashGapFour() : Vector4f(0.f);
1311 }
1312 
GetOutlineRadius() const1313 Vector4f RSProperties::GetOutlineRadius() const
1314 {
1315     return outline_ ? outline_->GetRadiusFour() : Vector4fZero;
1316 }
1317 
GetOutline() const1318 const std::shared_ptr<RSBorder>& RSProperties::GetOutline() const
1319 {
1320     return outline_;
1321 }
1322 
SetForegroundEffectRadius(const float foregroundEffectRadius)1323 void RSProperties::SetForegroundEffectRadius(const float foregroundEffectRadius)
1324 {
1325     foregroundEffectRadius_ = foregroundEffectRadius;
1326     if (IsForegroundEffectRadiusValid()) {
1327         isDrawn_ = true;
1328     }
1329     filterNeedUpdate_ = true;
1330     SetDirty();
1331 }
1332 
GetForegroundEffectRadius() const1333 float RSProperties::GetForegroundEffectRadius() const
1334 {
1335     return foregroundEffectRadius_;
1336 }
1337 
IsForegroundEffectRadiusValid() const1338 bool RSProperties::IsForegroundEffectRadiusValid() const
1339 {
1340     return ROSEN_GNE(foregroundEffectRadius_, 0.999f); // if blur radius < 1, no need to draw
1341 }
1342 
SetForegroundEffectDirty(bool dirty)1343 void RSProperties::SetForegroundEffectDirty(bool dirty)
1344 {
1345     foregroundEffectDirty_ = dirty;
1346 }
1347 
GetForegroundEffectDirty() const1348 bool RSProperties::GetForegroundEffectDirty() const
1349 {
1350     return foregroundEffectDirty_;
1351 }
1352 
GetForegroundFilterCache() const1353 const std::shared_ptr<RSFilter>& RSProperties::GetForegroundFilterCache() const
1354 {
1355     return foregroundFilterCache_;
1356 }
1357 
SetForegroundFilterCache(const std::shared_ptr<RSFilter> & foregroundFilterCache)1358 void RSProperties::SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache)
1359 {
1360     foregroundFilterCache_ = foregroundFilterCache;
1361     if (foregroundFilterCache) {
1362         isDrawn_ = true;
1363     }
1364     SetDirty();
1365     filterNeedUpdate_ = true;
1366     contentDirty_ = true;
1367 }
1368 
SetBackgroundFilter(const std::shared_ptr<RSFilter> & backgroundFilter)1369 void RSProperties::SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter)
1370 {
1371     backgroundFilter_ = backgroundFilter;
1372     if (backgroundFilter_) {
1373         isDrawn_ = true;
1374     }
1375     SetDirty();
1376     filterNeedUpdate_ = true;
1377     contentDirty_ = true;
1378 }
1379 
SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara> & para)1380 void RSProperties::SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para)
1381 {
1382     linearGradientBlurPara_ = para;
1383     if (para && para->blurRadius_ > 0.f) {
1384         isDrawn_ = true;
1385     }
1386     filterNeedUpdate_ = true;
1387     SetDirty();
1388     contentDirty_ = true;
1389 }
1390 
SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>> & para)1391 void RSProperties::SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>>& para)
1392 {
1393     emitterUpdater_ = para;
1394     if (!emitterUpdater_.empty()) {
1395         isDrawn_ = true;
1396         auto renderNode = backref_.lock();
1397         if (renderNode == nullptr) {
1398             return;
1399         }
1400         auto animation = renderNode->GetAnimationManager().GetParticleAnimation();
1401         if (animation == nullptr) {
1402             return;
1403         }
1404         auto particleAnimation = std::static_pointer_cast<RSRenderParticleAnimation>(animation);
1405         if (particleAnimation != nullptr) {
1406             particleAnimation->UpdateEmitter(emitterUpdater_);
1407         }
1408     }
1409     filterNeedUpdate_ = true;
1410     SetDirty();
1411     contentDirty_ = true;
1412 }
1413 
SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields> & para)1414 void RSProperties::SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields>& para)
1415 {
1416     particleNoiseFields_ = para;
1417     if (particleNoiseFields_) {
1418         isDrawn_ = true;
1419         auto renderNode = backref_.lock();
1420         if (renderNode == nullptr) {
1421             return;
1422         }
1423         auto animation = renderNode->GetAnimationManager().GetParticleAnimation();
1424         if (animation == nullptr) {
1425             return;
1426         }
1427         auto particleAnimation = std::static_pointer_cast<RSRenderParticleAnimation>(animation);
1428         if (particleAnimation) {
1429             particleAnimation->UpdateNoiseField(particleNoiseFields_);
1430         }
1431     }
1432     filterNeedUpdate_ = true;
1433     SetDirty();
1434     contentDirty_ = true;
1435 }
1436 
SetDynamicLightUpRate(const std::optional<float> & rate)1437 void RSProperties::SetDynamicLightUpRate(const std::optional<float>& rate)
1438 {
1439     dynamicLightUpRate_ = rate;
1440     if (rate.has_value()) {
1441         isDrawn_ = true;
1442     }
1443     filterNeedUpdate_ = true;
1444     SetDirty();
1445     contentDirty_ = true;
1446 }
1447 
SetDynamicLightUpDegree(const std::optional<float> & lightUpDegree)1448 void RSProperties::SetDynamicLightUpDegree(const std::optional<float>& lightUpDegree)
1449 {
1450     dynamicLightUpDegree_ = lightUpDegree;
1451     if (lightUpDegree.has_value()) {
1452         isDrawn_ = true;
1453     }
1454     filterNeedUpdate_ = true;
1455     SetDirty();
1456     contentDirty_ = true;
1457 }
1458 
SetWaterRippleProgress(const float & progress)1459 void RSProperties::SetWaterRippleProgress(const float& progress)
1460 {
1461     waterRippleProgress_ = progress;
1462     isDrawn_ = true;
1463     filterNeedUpdate_ = true;
1464     SetDirty();
1465     contentDirty_ = true;
1466 }
1467 
GetWaterRippleProgress() const1468 float RSProperties::GetWaterRippleProgress() const
1469 {
1470     return waterRippleProgress_;
1471 }
1472 
SetWaterRippleParams(const std::optional<RSWaterRipplePara> & params)1473 void RSProperties::SetWaterRippleParams(const std::optional<RSWaterRipplePara>& params)
1474 {
1475     waterRippleParams_ = params;
1476     if (params.has_value()) {
1477         isDrawn_ = true;
1478     }
1479     filterNeedUpdate_ = true;
1480     SetDirty();
1481     contentDirty_ = true;
1482 }
1483 
GetWaterRippleParams() const1484 std::optional<RSWaterRipplePara> RSProperties::GetWaterRippleParams() const
1485 {
1486     return waterRippleParams_;
1487 }
1488 
IsWaterRippleValid() const1489 bool RSProperties::IsWaterRippleValid() const
1490 {
1491     uint32_t WAVE_COUNT_MAX = 3;
1492     uint32_t WAVE_COUNT_MIN = 1;
1493     return ROSEN_GE(waterRippleProgress_, 0.0f) && ROSEN_LE(waterRippleProgress_, 1.0f) &&
1494            waterRippleParams_.has_value() && waterRippleParams_->waveCount >= WAVE_COUNT_MIN &&
1495            waterRippleParams_->waveCount <= WAVE_COUNT_MAX;
1496 }
1497 
SetFlyOutDegree(const float & degree)1498 void RSProperties::SetFlyOutDegree(const float& degree)
1499 {
1500     flyOutDegree_ = degree;
1501     isDrawn_ = true;
1502     filterNeedUpdate_ = true;
1503     SetDirty();
1504     contentDirty_ = true;
1505 }
1506 
GetFlyOutDegree() const1507 float RSProperties::GetFlyOutDegree() const
1508 {
1509     return flyOutDegree_;
1510 }
1511 
SetFlyOutParams(const std::optional<RSFlyOutPara> & params)1512 void RSProperties::SetFlyOutParams(const std::optional<RSFlyOutPara>& params)
1513 {
1514     flyOutParams_ = params;
1515     if (params.has_value()) {
1516         isDrawn_ = true;
1517     }
1518     filterNeedUpdate_ = true;
1519     SetDirty();
1520     contentDirty_ = true;
1521 }
1522 
GetFlyOutParams() const1523 std::optional<RSFlyOutPara> RSProperties::GetFlyOutParams() const
1524 {
1525     return flyOutParams_;
1526 }
1527 
IsFlyOutValid() const1528 bool RSProperties::IsFlyOutValid() const
1529 {
1530     return ROSEN_GE(flyOutDegree_, 0.0f) && ROSEN_LE(flyOutDegree_, 1.0f) && flyOutParams_.has_value();
1531 }
1532 
SetDistortionK(const std::optional<float> & distortionK)1533 void RSProperties::SetDistortionK(const std::optional<float>& distortionK)
1534 {
1535     distortionK_ = distortionK;
1536     if (distortionK_.has_value()) {
1537         isDrawn_ = true;
1538         distortionEffectDirty_ = ROSEN_GNE(*distortionK_, 0.0f) && ROSEN_LE(*distortionK_, 1.0f);
1539     }
1540     filterNeedUpdate_ = true;
1541     SetDirty();
1542     contentDirty_ = true;
1543 }
1544 
GetDistortionK() const1545 const std::optional<float>& RSProperties::GetDistortionK() const
1546 {
1547     return distortionK_;
1548 }
1549 
IsDistortionKValid() const1550 bool RSProperties::IsDistortionKValid() const
1551 {
1552     return distortionK_.has_value() && ROSEN_GE(*distortionK_, -1.0f) && ROSEN_LE(*distortionK_, 1.0f);
1553 }
1554 
SetDistortionDirty(bool distortionEffectDirty)1555 void RSProperties::SetDistortionDirty(bool distortionEffectDirty)
1556 {
1557     distortionEffectDirty_ = distortionEffectDirty;
1558 }
1559 
GetDistortionDirty() const1560 bool RSProperties::GetDistortionDirty() const
1561 {
1562     return distortionEffectDirty_;
1563 }
1564 
SetFgBrightnessRates(const Vector4f & rates)1565 void RSProperties::SetFgBrightnessRates(const Vector4f& rates)
1566 {
1567     if (!fgBrightnessParams_.has_value()) {
1568         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1569     }
1570     fgBrightnessParams_->rates_ = rates;
1571     isDrawn_ = true;
1572     filterNeedUpdate_ = true;
1573     SetDirty();
1574     contentDirty_ = true;
1575 }
1576 
GetFgBrightnessRates() const1577 Vector4f RSProperties::GetFgBrightnessRates() const
1578 {
1579     return fgBrightnessParams_ ? fgBrightnessParams_->rates_ : Vector4f();
1580 }
1581 
SetFgBrightnessSaturation(const float & saturation)1582 void RSProperties::SetFgBrightnessSaturation(const float& saturation)
1583 {
1584     if (!fgBrightnessParams_.has_value()) {
1585         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1586     }
1587     fgBrightnessParams_->saturation_ = saturation;
1588     isDrawn_ = true;
1589     filterNeedUpdate_ = true;
1590     SetDirty();
1591     contentDirty_ = true;
1592 }
1593 
GetFgBrightnessSaturation() const1594 float RSProperties::GetFgBrightnessSaturation() const
1595 {
1596     return fgBrightnessParams_ ? fgBrightnessParams_->saturation_ : 0.0f;
1597 }
1598 
SetFgBrightnessPosCoeff(const Vector4f & coeff)1599 void RSProperties::SetFgBrightnessPosCoeff(const Vector4f& coeff)
1600 {
1601     if (!fgBrightnessParams_.has_value()) {
1602         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1603     }
1604     fgBrightnessParams_->posCoeff_ = coeff;
1605     isDrawn_ = true;
1606     filterNeedUpdate_ = true;
1607     SetDirty();
1608     contentDirty_ = true;
1609 }
1610 
GetFgBrightnessPosCoeff() const1611 Vector4f RSProperties::GetFgBrightnessPosCoeff() const
1612 {
1613     return fgBrightnessParams_ ? fgBrightnessParams_->posCoeff_ : Vector4f();
1614 }
1615 
SetFgBrightnessNegCoeff(const Vector4f & coeff)1616 void RSProperties::SetFgBrightnessNegCoeff(const Vector4f& coeff)
1617 {
1618     if (!fgBrightnessParams_.has_value()) {
1619         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1620     }
1621     fgBrightnessParams_->negCoeff_ = coeff;
1622     isDrawn_ = true;
1623     filterNeedUpdate_ = true;
1624     SetDirty();
1625     contentDirty_ = true;
1626 }
1627 
GetFgBrightnessNegCoeff() const1628 Vector4f RSProperties::GetFgBrightnessNegCoeff() const
1629 {
1630     return fgBrightnessParams_ ? fgBrightnessParams_->negCoeff_ : Vector4f();
1631 }
1632 
SetFgBrightnessFract(const float & fraction)1633 void RSProperties::SetFgBrightnessFract(const float& fraction)
1634 {
1635     if (!fgBrightnessParams_.has_value()) {
1636         fgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1637     }
1638     fgBrightnessParams_->fraction_ = fraction;
1639     isDrawn_ = true;
1640     filterNeedUpdate_ = true;
1641     SetDirty();
1642     contentDirty_ = true;
1643 }
1644 
GetFgBrightnessFract() const1645 float RSProperties::GetFgBrightnessFract() const
1646 {
1647     return fgBrightnessParams_ ? fgBrightnessParams_->fraction_ : 1.0f;
1648 }
1649 
SetFgBrightnessParams(const std::optional<RSDynamicBrightnessPara> & params)1650 void RSProperties::SetFgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params)
1651 {
1652     fgBrightnessParams_ = params;
1653     if (params.has_value()) {
1654         isDrawn_ = true;
1655     }
1656     filterNeedUpdate_ = true;
1657     SetDirty();
1658     contentDirty_ = true;
1659 }
1660 
GetFgBrightnessParams() const1661 std::optional<RSDynamicBrightnessPara> RSProperties::GetFgBrightnessParams() const
1662 {
1663     return fgBrightnessParams_;
1664 }
1665 
SetBgBrightnessRates(const Vector4f & rates)1666 void RSProperties::SetBgBrightnessRates(const Vector4f& rates)
1667 {
1668     if (!bgBrightnessParams_.has_value()) {
1669         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1670     }
1671     bgBrightnessParams_->rates_ = rates;
1672     isDrawn_ = true;
1673     filterNeedUpdate_ = true;
1674     SetDirty();
1675     contentDirty_ = true;
1676 }
1677 
GetBgBrightnessRates() const1678 Vector4f RSProperties::GetBgBrightnessRates() const
1679 {
1680     return bgBrightnessParams_ ? bgBrightnessParams_->rates_ : Vector4f();
1681 }
1682 
SetBgBrightnessSaturation(const float & saturation)1683 void RSProperties::SetBgBrightnessSaturation(const float& saturation)
1684 {
1685     if (!bgBrightnessParams_.has_value()) {
1686         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1687     }
1688     bgBrightnessParams_->saturation_ = saturation;
1689     isDrawn_ = true;
1690     filterNeedUpdate_ = true;
1691     SetDirty();
1692     contentDirty_ = true;
1693 }
1694 
GetBgBrightnessSaturation() const1695 float RSProperties::GetBgBrightnessSaturation() const
1696 {
1697     return bgBrightnessParams_ ? bgBrightnessParams_->saturation_ : 0.0f;
1698 }
1699 
SetBgBrightnessPosCoeff(const Vector4f & coeff)1700 void RSProperties::SetBgBrightnessPosCoeff(const Vector4f& coeff)
1701 {
1702     if (!bgBrightnessParams_.has_value()) {
1703         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1704     }
1705     bgBrightnessParams_->posCoeff_ = coeff;
1706     isDrawn_ = true;
1707     filterNeedUpdate_ = true;
1708     SetDirty();
1709     contentDirty_ = true;
1710 }
1711 
GetBgBrightnessPosCoeff() const1712 Vector4f RSProperties::GetBgBrightnessPosCoeff() const
1713 {
1714     return bgBrightnessParams_ ? bgBrightnessParams_->posCoeff_ : Vector4f();
1715 }
1716 
SetBgBrightnessNegCoeff(const Vector4f & coeff)1717 void RSProperties::SetBgBrightnessNegCoeff(const Vector4f& coeff)
1718 {
1719     if (!bgBrightnessParams_.has_value()) {
1720         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1721     }
1722     bgBrightnessParams_->negCoeff_ = coeff;
1723     isDrawn_ = true;
1724     filterNeedUpdate_ = true;
1725     SetDirty();
1726     contentDirty_ = true;
1727 }
1728 
GetBgBrightnessNegCoeff() const1729 Vector4f RSProperties::GetBgBrightnessNegCoeff() const
1730 {
1731     return bgBrightnessParams_ ? bgBrightnessParams_->negCoeff_ : Vector4f();
1732 }
1733 
SetBgBrightnessFract(const float & fraction)1734 void RSProperties::SetBgBrightnessFract(const float& fraction)
1735 {
1736     if (!bgBrightnessParams_.has_value()) {
1737         bgBrightnessParams_ = std::make_optional<RSDynamicBrightnessPara>();
1738     }
1739     bgBrightnessParams_->fraction_ = fraction;
1740     isDrawn_ = true;
1741     filterNeedUpdate_ = true;
1742     SetDirty();
1743     contentDirty_ = true;
1744 }
1745 
GetBgBrightnessFract() const1746 float RSProperties::GetBgBrightnessFract() const
1747 {
1748     return bgBrightnessParams_ ? bgBrightnessParams_->fraction_ : 1.0f;
1749 }
1750 
SetBgBrightnessParams(const std::optional<RSDynamicBrightnessPara> & params)1751 void RSProperties::SetBgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params)
1752 {
1753     bgBrightnessParams_ = params;
1754     if (params.has_value()) {
1755         isDrawn_ = true;
1756     }
1757     filterNeedUpdate_ = true;
1758     SetDirty();
1759     contentDirty_ = true;
1760 }
1761 
GetBgBrightnessParams() const1762 std::optional<RSDynamicBrightnessPara> RSProperties::GetBgBrightnessParams() const
1763 {
1764     return bgBrightnessParams_;
1765 }
1766 
IsFgBrightnessValid() const1767 bool RSProperties::IsFgBrightnessValid() const
1768 {
1769     return fgBrightnessParams_.has_value() && fgBrightnessParams_->IsValid();
1770 }
1771 
IsBgBrightnessValid() const1772 bool RSProperties::IsBgBrightnessValid() const
1773 {
1774     return bgBrightnessParams_.has_value() && bgBrightnessParams_->IsValid();
1775 }
1776 
GetFgBrightnessDescription() const1777 std::string RSProperties::GetFgBrightnessDescription() const
1778 {
1779     if (!fgBrightnessParams_.has_value()) {
1780         return "fgBrightnessParams_ is nullopt";
1781     }
1782     std::string description =
1783         "ForegroundBrightness, cubicCoeff: " + std::to_string(fgBrightnessParams_->rates_.x_) +
1784         ", quadCoeff: " + std::to_string(fgBrightnessParams_->rates_.y_) +
1785         ", rate: " + std::to_string(fgBrightnessParams_->rates_.z_) +
1786         ", lightUpDegree: " + std::to_string(fgBrightnessParams_->rates_.w_) +
1787         ", saturation: " + std::to_string(fgBrightnessParams_->saturation_) +
1788         ", fgBrightnessFract: " + std::to_string(fgBrightnessParams_->fraction_);
1789     return description;
1790 }
1791 
GetBgBrightnessDescription() const1792 std::string RSProperties::GetBgBrightnessDescription() const
1793 {
1794     if (!bgBrightnessParams_.has_value()) {
1795         return "bgBrightnessParams_ is nullopt";
1796     }
1797     std::string description =
1798         "BackgroundBrightnessInternal, cubicCoeff: " + std::to_string(bgBrightnessParams_->rates_.x_) +
1799         ", quadCoeff: " + std::to_string(bgBrightnessParams_->rates_.y_) +
1800         ", rate: " + std::to_string(bgBrightnessParams_->rates_.z_) +
1801         ", lightUpDegree: " + std::to_string(bgBrightnessParams_->rates_.w_) +
1802         ", saturation: " + std::to_string(bgBrightnessParams_->saturation_) +
1803         ", fgBrightnessFract: " + std::to_string(bgBrightnessParams_->fraction_);
1804     return description;
1805 }
1806 
SetGreyCoef(const std::optional<Vector2f> & greyCoef)1807 void RSProperties::SetGreyCoef(const std::optional<Vector2f>& greyCoef)
1808 {
1809     greyCoef_ = greyCoef;
1810     greyCoefNeedUpdate_ = true;
1811     SetDirty();
1812     contentDirty_ = true;
1813 }
1814 
SetDynamicDimDegree(const std::optional<float> & DimDegree)1815 void RSProperties::SetDynamicDimDegree(const std::optional<float>& DimDegree)
1816 {
1817     dynamicDimDegree_ = DimDegree;
1818     if (DimDegree.has_value()) {
1819         isDrawn_ = true;
1820     }
1821     filterNeedUpdate_ = true;
1822     SetDirty();
1823     contentDirty_ = true;
1824 }
1825 
SetFilter(const std::shared_ptr<RSFilter> & filter)1826 void RSProperties::SetFilter(const std::shared_ptr<RSFilter>& filter)
1827 {
1828     filter_ = filter;
1829     if (filter) {
1830         isDrawn_ = true;
1831     }
1832     SetDirty();
1833     filterNeedUpdate_ = true;
1834     contentDirty_ = true;
1835 }
1836 
SetMotionBlurPara(const std::shared_ptr<MotionBlurParam> & para)1837 void RSProperties::SetMotionBlurPara(const std::shared_ptr<MotionBlurParam>& para)
1838 {
1839     motionBlurPara_ = para;
1840 
1841     if (para && para->radius > 0.f) {
1842         isDrawn_ = true;
1843     }
1844     SetDirty();
1845     filterNeedUpdate_ = true;
1846     contentDirty_ = true;
1847 }
1848 
SetMagnifierParams(const std::shared_ptr<RSMagnifierParams> & para)1849 void RSProperties::SetMagnifierParams(const std::shared_ptr<RSMagnifierParams>& para)
1850 {
1851     magnifierPara_ = para;
1852 
1853     if (para) {
1854         isDrawn_ = true;
1855     }
1856     SetDirty();
1857     filterNeedUpdate_ = true;
1858     contentDirty_ = true;
1859 }
1860 
GetMagnifierPara() const1861 const std::shared_ptr<RSMagnifierParams>& RSProperties::GetMagnifierPara() const
1862 {
1863     return magnifierPara_;
1864 }
1865 
GetBackgroundFilter() const1866 const std::shared_ptr<RSFilter>& RSProperties::GetBackgroundFilter() const
1867 {
1868     return backgroundFilter_;
1869 }
1870 
GetLinearGradientBlurPara() const1871 const std::shared_ptr<RSLinearGradientBlurPara>& RSProperties::GetLinearGradientBlurPara() const
1872 {
1873     return linearGradientBlurPara_;
1874 }
1875 
GetEmitterUpdater() const1876 const std::vector<std::shared_ptr<EmitterUpdater>>& RSProperties::GetEmitterUpdater() const
1877 {
1878     return emitterUpdater_;
1879 }
1880 
GetParticleNoiseFields() const1881 const std::shared_ptr<ParticleNoiseFields>& RSProperties::GetParticleNoiseFields() const
1882 {
1883     return particleNoiseFields_;
1884 }
1885 
IfLinearGradientBlurInvalid()1886 void RSProperties::IfLinearGradientBlurInvalid()
1887 {
1888     if (linearGradientBlurPara_ != nullptr) {
1889         bool isValid = ROSEN_GE(linearGradientBlurPara_->blurRadius_, 0.0);
1890         if (!isValid) {
1891             linearGradientBlurPara_.reset();
1892         }
1893     }
1894 }
1895 
GetDynamicLightUpRate() const1896 const std::optional<float>& RSProperties::GetDynamicLightUpRate() const
1897 {
1898     return dynamicLightUpRate_;
1899 }
1900 
GetDynamicLightUpDegree() const1901 const std::optional<float>& RSProperties::GetDynamicLightUpDegree() const
1902 {
1903     return dynamicLightUpDegree_;
1904 }
1905 
GetDynamicDimDegree() const1906 const std::optional<float>& RSProperties::GetDynamicDimDegree() const
1907 {
1908     return dynamicDimDegree_;
1909 }
1910 
GetGreyCoef() const1911 const std::optional<Vector2f>& RSProperties::GetGreyCoef() const
1912 {
1913     return greyCoef_;
1914 }
1915 
IsDynamicDimValid() const1916 bool RSProperties::IsDynamicDimValid() const
1917 {
1918     return dynamicDimDegree_.has_value() &&
1919            ROSEN_GE(*dynamicDimDegree_, 0.0) && ROSEN_LNE(*dynamicDimDegree_, 1.0);
1920 }
1921 
GetFilter() const1922 const std::shared_ptr<RSFilter>& RSProperties::GetFilter() const
1923 {
1924     return filter_;
1925 }
1926 
GetMotionBlurPara() const1927 const std::shared_ptr<MotionBlurParam>& RSProperties::GetMotionBlurPara() const
1928 {
1929     return motionBlurPara_;
1930 }
1931 
IsDynamicLightUpValid() const1932 bool RSProperties::IsDynamicLightUpValid() const
1933 {
1934     return dynamicLightUpRate_.has_value() && dynamicLightUpDegree_.has_value() &&
1935            ROSEN_GNE(*dynamicLightUpRate_, 0.0) && ROSEN_GE(*dynamicLightUpDegree_, -1.0) &&
1936            ROSEN_LE(*dynamicLightUpDegree_, 1.0);
1937 }
1938 
GetForegroundFilter() const1939 const std::shared_ptr<RSFilter>& RSProperties::GetForegroundFilter() const
1940 {
1941     return foregroundFilter_;
1942 }
1943 
SetForegroundFilter(const std::shared_ptr<RSFilter> & foregroundFilter)1944 void RSProperties::SetForegroundFilter(const std::shared_ptr<RSFilter>& foregroundFilter)
1945 {
1946     foregroundFilter_ = foregroundFilter;
1947     if (foregroundFilter) {
1948         isDrawn_ = true;
1949     }
1950     SetDirty();
1951     filterNeedUpdate_ = true;
1952     contentDirty_ = true;
1953 }
1954 
1955 // shadow properties
SetShadowColor(Color color)1956 void RSProperties::SetShadowColor(Color color)
1957 {
1958     if (!shadow_.has_value()) {
1959         shadow_ = std::make_optional<RSShadow>();
1960     }
1961     shadow_->SetColor(color);
1962     SetDirty();
1963     // [planning] if shadow stores as texture and out of node
1964     // node content would not be affected
1965     contentDirty_ = true;
1966 }
1967 
SetShadowOffsetX(float offsetX)1968 void RSProperties::SetShadowOffsetX(float offsetX)
1969 {
1970     if (!shadow_.has_value()) {
1971         shadow_ = std::make_optional<RSShadow>();
1972     }
1973     shadow_->SetOffsetX(offsetX);
1974     SetDirty();
1975     filterNeedUpdate_ = true;
1976     // [planning] if shadow stores as texture and out of node
1977     // node content would not be affected
1978     contentDirty_ = true;
1979 }
1980 
SetShadowOffsetY(float offsetY)1981 void RSProperties::SetShadowOffsetY(float offsetY)
1982 {
1983     if (!shadow_.has_value()) {
1984         shadow_ = std::make_optional<RSShadow>();
1985     }
1986     shadow_->SetOffsetY(offsetY);
1987     SetDirty();
1988     filterNeedUpdate_ = true;
1989     // [planning] if shadow stores as texture and out of node
1990     // node content would not be affected
1991     contentDirty_ = true;
1992 }
1993 
SetShadowAlpha(float alpha)1994 void RSProperties::SetShadowAlpha(float alpha)
1995 {
1996     if (!shadow_.has_value()) {
1997         shadow_ = std::make_optional<RSShadow>();
1998     }
1999     shadow_->SetAlpha(alpha);
2000     if (shadow_->IsValid()) {
2001         isDrawn_ = true;
2002     }
2003     SetDirty();
2004     // [planning] if shadow stores as texture and out of node
2005     // node content would not be affected
2006     contentDirty_ = true;
2007 }
2008 
SetShadowElevation(float elevation)2009 void RSProperties::SetShadowElevation(float elevation)
2010 {
2011     if (!shadow_.has_value()) {
2012         shadow_ = std::make_optional<RSShadow>();
2013     }
2014     shadow_->SetElevation(elevation);
2015     if (shadow_->IsValid()) {
2016         isDrawn_ = true;
2017     }
2018     SetDirty();
2019     // [planning] if shadow stores as texture and out of node
2020     // node content would not be affected
2021     contentDirty_ = true;
2022 }
2023 
SetShadowRadius(float radius)2024 void RSProperties::SetShadowRadius(float radius)
2025 {
2026     if (!shadow_.has_value()) {
2027         shadow_ = std::make_optional<RSShadow>();
2028     }
2029     shadow_->SetRadius(radius);
2030     if (shadow_->IsValid()) {
2031         isDrawn_ = true;
2032     }
2033     SetDirty();
2034     filterNeedUpdate_ = true;
2035     // [planning] if shadow stores as texture and out of node
2036     // node content would not be affected
2037     contentDirty_ = true;
2038 }
2039 
SetShadowPath(std::shared_ptr<RSPath> shadowPath)2040 void RSProperties::SetShadowPath(std::shared_ptr<RSPath> shadowPath)
2041 {
2042     if (!shadow_.has_value()) {
2043         shadow_ = std::make_optional<RSShadow>();
2044     }
2045     shadow_->SetPath(shadowPath);
2046     SetDirty();
2047     if (GetShadowMask()) {
2048         filterNeedUpdate_ = true;
2049     }
2050     // [planning] if shadow stores as texture and out of node
2051     // node content would not be affected
2052     contentDirty_ = true;
2053 }
2054 
SetShadowMask(bool shadowMask)2055 void RSProperties::SetShadowMask(bool shadowMask)
2056 {
2057     if (!shadow_.has_value()) {
2058         shadow_ = std::make_optional<RSShadow>();
2059     }
2060     shadow_->SetMask(shadowMask);
2061     SetDirty();
2062     filterNeedUpdate_ = true;
2063     // [planning] if shadow stores as texture and out of node
2064     // node content would not be affected
2065     contentDirty_ = true;
2066 }
2067 
SetShadowIsFilled(bool shadowIsFilled)2068 void RSProperties::SetShadowIsFilled(bool shadowIsFilled)
2069 {
2070     if (!shadow_.has_value()) {
2071         shadow_ = std::make_optional<RSShadow>();
2072     }
2073     shadow_->SetIsFilled(shadowIsFilled);
2074     SetDirty();
2075     if (GetShadowMask()) {
2076         filterNeedUpdate_ = true;
2077     }
2078     // [planning] if shadow stores as texture and out of node
2079     // node content would not be affected
2080     contentDirty_ = true;
2081 }
2082 
SetShadowColorStrategy(int shadowColorStrategy)2083 void RSProperties::SetShadowColorStrategy(int shadowColorStrategy)
2084 {
2085     if (!shadow_.has_value()) {
2086         shadow_ = std::make_optional<RSShadow>();
2087     }
2088     shadow_->SetColorStrategy(shadowColorStrategy);
2089     SetDirty();
2090     filterNeedUpdate_ = true;
2091     // [planning] if shadow stores as texture and out of node
2092     // node content would not be affected
2093     contentDirty_ = true;
2094 }
2095 
2096 
GetShadowColor() const2097 const Color& RSProperties::GetShadowColor() const
2098 {
2099     static const auto DEFAULT_SPOT_COLOR_VALUE = Color::FromArgbInt(DEFAULT_SPOT_COLOR);
2100     return shadow_ ? shadow_->GetColor() : DEFAULT_SPOT_COLOR_VALUE;
2101 }
2102 
GetShadowOffsetX() const2103 float RSProperties::GetShadowOffsetX() const
2104 {
2105     return shadow_ ? shadow_->GetOffsetX() : DEFAULT_SHADOW_OFFSET_X;
2106 }
2107 
GetShadowOffsetY() const2108 float RSProperties::GetShadowOffsetY() const
2109 {
2110     return shadow_ ? shadow_->GetOffsetY() : DEFAULT_SHADOW_OFFSET_Y;
2111 }
2112 
GetShadowAlpha() const2113 float RSProperties::GetShadowAlpha() const
2114 {
2115     return shadow_ ? shadow_->GetAlpha() : 0.f;
2116 }
2117 
GetShadowElevation() const2118 float RSProperties::GetShadowElevation() const
2119 {
2120     return shadow_ ? shadow_->GetElevation() : 0.f;
2121 }
2122 
GetShadowRadius() const2123 float RSProperties::GetShadowRadius() const
2124 {
2125     return shadow_ ? shadow_->GetRadius() : DEFAULT_SHADOW_RADIUS;
2126 }
2127 
GetShadowPath() const2128 std::shared_ptr<RSPath> RSProperties::GetShadowPath() const
2129 {
2130     return shadow_ ? shadow_->GetPath() : nullptr;
2131 }
2132 
GetShadowMask() const2133 bool RSProperties::GetShadowMask() const
2134 {
2135     return shadow_ ? shadow_->GetMask() : false;
2136 }
2137 
GetShadowIsFilled() const2138 bool RSProperties::GetShadowIsFilled() const
2139 {
2140     return shadow_ ? shadow_->GetIsFilled() : false;
2141 }
2142 
GetShadowColorStrategy() const2143 int RSProperties::GetShadowColorStrategy() const
2144 {
2145     return shadow_ ? shadow_->GetColorStrategy() : SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE;
2146 }
2147 
GetShadow() const2148 const std::optional<RSShadow>& RSProperties::GetShadow() const
2149 {
2150     return shadow_;
2151 }
2152 
IsShadowValid() const2153 bool RSProperties::IsShadowValid() const
2154 {
2155     return shadow_ && shadow_->IsValid();
2156 }
2157 
SetFrameGravity(Gravity gravity)2158 void RSProperties::SetFrameGravity(Gravity gravity)
2159 {
2160     if (frameGravity_ != gravity) {
2161         frameGravity_ = gravity;
2162         SetDirty();
2163         contentDirty_ = true;
2164     }
2165 }
2166 
GetFrameGravity() const2167 Gravity RSProperties::GetFrameGravity() const
2168 {
2169     return frameGravity_;
2170 }
2171 
SetDrawRegion(const std::shared_ptr<RectF> & rect)2172 void RSProperties::SetDrawRegion(const std::shared_ptr<RectF>& rect)
2173 {
2174     drawRegion_ = rect;
2175     SetDirty();
2176     geoDirty_ = true;  // since drawRegion affect dirtyRegion, mark it as geoDirty
2177 }
2178 
GetDrawRegion() const2179 std::shared_ptr<RectF> RSProperties::GetDrawRegion() const
2180 {
2181     return drawRegion_;
2182 }
2183 
SetClipRRect(RRect clipRRect)2184 void RSProperties::SetClipRRect(RRect clipRRect)
2185 {
2186     clipRRect_ = clipRRect;
2187     if (GetClipToRRect()) {
2188         isDrawn_ = true;
2189     }
2190     SetDirty();
2191     geoDirty_ = true;  // [planning] all clip ops should be checked
2192 }
2193 
GetClipRRect() const2194 RRect RSProperties::GetClipRRect() const
2195 {
2196     return clipRRect_ ? *clipRRect_ : RRect();
2197 }
2198 
GetClipToRRect() const2199 bool RSProperties::GetClipToRRect() const
2200 {
2201     return clipRRect_.has_value() && !clipRRect_->rect_.IsEmpty();
2202 }
2203 
SetClipBounds(const std::shared_ptr<RSPath> & path)2204 void RSProperties::SetClipBounds(const std::shared_ptr<RSPath>& path)
2205 {
2206     if (path) {
2207         isDrawn_ = true;
2208     }
2209     if (clipPath_ != path) {
2210         clipPath_ = path;
2211         SetDirty();
2212         geoDirty_ = true;  // [planning] all clip ops should be checked
2213     }
2214 }
2215 
GetClipBounds() const2216 const std::shared_ptr<RSPath>& RSProperties::GetClipBounds() const
2217 {
2218     return clipPath_;
2219 }
2220 
SetClipToBounds(bool clipToBounds)2221 void RSProperties::SetClipToBounds(bool clipToBounds)
2222 {
2223     if (clipToBounds) {
2224         isDrawn_ = true;
2225     }
2226     if (clipToBounds_ != clipToBounds) {
2227         clipToBounds_ = clipToBounds;
2228         SetDirty();
2229         geoDirty_ = true;  // [planning] all clip ops should be checked
2230     }
2231 }
2232 
GetClipToBounds() const2233 bool RSProperties::GetClipToBounds() const
2234 {
2235     return clipToBounds_;
2236 }
2237 
SetClipToFrame(bool clipToFrame)2238 void RSProperties::SetClipToFrame(bool clipToFrame)
2239 {
2240     if (clipToFrame) {
2241         isDrawn_ = true;
2242     }
2243     if (clipToFrame_ != clipToFrame) {
2244         clipToFrame_ = clipToFrame;
2245         SetDirty();
2246         geoDirty_ = true;  // [planning] all clip ops should be checked
2247     }
2248 }
2249 
GetClipToFrame() const2250 bool RSProperties::GetClipToFrame() const
2251 {
2252     return clipToFrame_;
2253 }
2254 
GetLocalBoundsAndFramesRect() const2255 RectF RSProperties::GetLocalBoundsAndFramesRect() const
2256 {
2257     auto rect = GetBoundsRect();
2258     if (!clipToBounds_ && !std::isinf(GetFrameWidth()) && !std::isinf(GetFrameHeight())) {
2259         rect = rect.JoinRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2260     }
2261     return rect;
2262 }
2263 
GetBoundsRect() const2264 RectF RSProperties::GetBoundsRect() const
2265 {
2266     auto rect = RectF();
2267     if (boundsGeo_->IsEmpty()) {
2268         if (!std::isinf(GetFrameWidth()) && !std::isinf(GetFrameHeight())) {
2269             rect = {0, 0, GetFrameWidth(), GetFrameHeight()};
2270         }
2271     } else {
2272         if (!std::isinf(GetBoundsWidth()) && !std::isinf(GetBoundsHeight())) {
2273             rect = {0, 0, GetBoundsWidth(), GetBoundsHeight()};
2274         }
2275     }
2276     return rect;
2277 }
2278 
GetFrameRect() const2279 RectF RSProperties::GetFrameRect() const
2280 {
2281     return {0, 0, GetFrameWidth(), GetFrameHeight()};
2282 }
2283 
GetBgImageRect() const2284 const RectF& RSProperties::GetBgImageRect() const
2285 {
2286     return decoration_ ? decoration_->bgImageRect_ : EMPTY_RECT;
2287 }
2288 
SetVisible(bool visible)2289 void RSProperties::SetVisible(bool visible)
2290 {
2291     if (visible_ != visible) {
2292         visible_ = visible;
2293         SetDirty();
2294         contentDirty_ = true;
2295     }
2296 }
2297 
GetVisible() const2298 bool RSProperties::GetVisible() const
2299 {
2300     return visible_;
2301 }
2302 
GetRRect() const2303 const RRect& RSProperties::GetRRect() const
2304 {
2305     return rrect_;
2306 }
2307 
GenerateRRect()2308 void RSProperties::GenerateRRect()
2309 {
2310     RectF rect = GetBoundsRect();
2311     rrect_ = RRect(rect, GetCornerRadius());
2312 }
2313 
GetInnerRRect() const2314 RRect RSProperties::GetInnerRRect() const
2315 {
2316     auto rect = GetBoundsRect();
2317     Vector4f cornerRadius = GetCornerRadius();
2318     if (border_) {
2319         rect.left_ += border_->GetWidth(RSBorder::LEFT);
2320         rect.top_ += border_->GetWidth(RSBorder::TOP);
2321         rect.width_ -= border_->GetWidth(RSBorder::LEFT) + border_->GetWidth(RSBorder::RIGHT);
2322         rect.height_ -= border_->GetWidth(RSBorder::TOP) + border_->GetWidth(RSBorder::BOTTOM);
2323     }
2324     RRect rrect = RRect(rect, cornerRadius);
2325     if (border_) {
2326         rrect.radius_[0] -= { border_->GetWidth(RSBorder::LEFT), border_->GetWidth(RSBorder::TOP) };
2327         rrect.radius_[1] -= { border_->GetWidth(RSBorder::RIGHT), border_->GetWidth(RSBorder::TOP) };
2328         rrect.radius_[2] -= { border_->GetWidth(RSBorder::RIGHT), border_->GetWidth(RSBorder::BOTTOM) };
2329         rrect.radius_[3] -= { border_->GetWidth(RSBorder::LEFT), border_->GetWidth(RSBorder::BOTTOM) };
2330     }
2331     return rrect;
2332 }
2333 
NeedFilter() const2334 bool RSProperties::NeedFilter() const
2335 {
2336     return needFilter_;
2337 }
2338 
NeedClip() const2339 bool RSProperties::NeedClip() const
2340 {
2341     return clipToBounds_ || clipToFrame_;
2342 }
2343 
SetDirty()2344 void RSProperties::SetDirty()
2345 {
2346     isDirty_ = true;
2347 }
2348 
ResetDirty()2349 void RSProperties::ResetDirty()
2350 {
2351     isDirty_ = false;
2352     geoDirty_ = false;
2353     contentDirty_ = false;
2354 }
2355 
RecordCurDirtyStatus()2356 void RSProperties::RecordCurDirtyStatus()
2357 {
2358     curIsDirty_ = isDirty_;
2359     curGeoDirty_ = geoDirty_;
2360     curContentDirty_ = contentDirty_;
2361 }
2362 
AccmulateDirtyStatus()2363 void RSProperties::AccmulateDirtyStatus()
2364 {
2365     isDirty_ = isDirty_ || curIsDirty_;
2366     geoDirty_ = geoDirty_ || curGeoDirty_;
2367     contentDirty_ = contentDirty_ || curContentDirty_;
2368 }
2369 
IsDirty() const2370 bool RSProperties::IsDirty() const
2371 {
2372     return isDirty_;
2373 }
2374 
IsGeoDirty() const2375 bool RSProperties::IsGeoDirty() const
2376 {
2377     return geoDirty_;
2378 }
2379 
IsCurGeoDirty() const2380 bool RSProperties::IsCurGeoDirty() const
2381 {
2382     return curGeoDirty_;
2383 }
2384 
IsContentDirty() const2385 bool RSProperties::IsContentDirty() const
2386 {
2387     return contentDirty_;
2388 }
2389 
GetDirtyRect() const2390 RectI RSProperties::GetDirtyRect() const
2391 {
2392     RectI dirtyRect;
2393     auto boundsGeometry = (boundsGeo_);
2394     if (clipToBounds_ || std::isinf(GetFrameWidth()) || std::isinf(GetFrameHeight())) {
2395         dirtyRect = boundsGeometry->GetAbsRect();
2396     } else {
2397         auto frameRect =
2398             boundsGeometry->MapAbsRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2399         dirtyRect = boundsGeometry->GetAbsRect().JoinRect(frameRect);
2400     }
2401     if (drawRegion_ == nullptr || drawRegion_->IsEmpty()) {
2402         return dirtyRect;
2403     } else {
2404         auto drawRegion = boundsGeo_->MapAbsRect(*drawRegion_);
2405         // this is used to fix the scene with drawRegion problem, which is need to be optimized
2406         drawRegion.SetRight(drawRegion.GetRight() + 1);
2407         drawRegion.SetBottom(drawRegion.GetBottom() + 1);
2408         drawRegion.SetAll(drawRegion.left_ - 1, drawRegion.top_ - 1,
2409             drawRegion.width_ + 1, drawRegion.height_ + 1);
2410         return dirtyRect.JoinRect(drawRegion);
2411     }
2412 }
2413 
GetDirtyRect(RectI & drawRegion) const2414 RectI RSProperties::GetDirtyRect(RectI& drawRegion) const
2415 {
2416     RectI dirtyRect;
2417     if (clipToBounds_ || std::isinf(GetFrameWidth()) || std::isinf(GetFrameHeight())) {
2418         dirtyRect = boundsGeo_->GetAbsRect();
2419     } else {
2420         auto frameRect =
2421             boundsGeo_->MapAbsRect(RectF(GetFrameOffsetX(), GetFrameOffsetY(), GetFrameWidth(), GetFrameHeight()));
2422         dirtyRect = boundsGeo_->GetAbsRect().JoinRect(frameRect);
2423     }
2424     if (drawRegion_ == nullptr || drawRegion_->IsEmpty()) {
2425         drawRegion = RectI();
2426         return dirtyRect;
2427     } else {
2428         drawRegion = boundsGeo_->MapAbsRect(*drawRegion_);
2429         // this is used to fix the scene with drawRegion problem, which is need to be optimized
2430         drawRegion.SetRight(drawRegion.GetRight() + 1);
2431         drawRegion.SetBottom(drawRegion.GetBottom() + 1);
2432         drawRegion.SetAll(drawRegion.left_ - 1, drawRegion.top_ - 1,
2433             drawRegion.width_ + 1, drawRegion.height_ + 1);
2434         return dirtyRect.JoinRect(drawRegion);
2435     }
2436 }
2437 
CheckEmptyBounds()2438 void RSProperties::CheckEmptyBounds()
2439 {
2440     // [planning] remove this func and fallback to framerect after surfacenode using frame
2441     if (!hasBounds_) {
2442         boundsGeo_->SetRect(frameGeo_.GetX(), frameGeo_.GetY(), frameGeo_.GetWidth(), frameGeo_.GetHeight());
2443     }
2444 }
2445 
2446 // mask properties
SetMask(const std::shared_ptr<RSMask> & mask)2447 void RSProperties::SetMask(const std::shared_ptr<RSMask>& mask)
2448 {
2449     mask_ = mask;
2450     if (mask_) {
2451         isDrawn_ = true;
2452     }
2453     SetDirty();
2454     contentDirty_ = true;
2455 }
2456 
GetMask() const2457 std::shared_ptr<RSMask> RSProperties::GetMask() const
2458 {
2459     return mask_;
2460 }
2461 
SetSpherize(float spherizeDegree)2462 void RSProperties::SetSpherize(float spherizeDegree)
2463 {
2464     spherizeDegree_ = spherizeDegree;
2465     isSpherizeValid_ = spherizeDegree_ > SPHERIZE_VALID_EPSILON;
2466     if (isSpherizeValid_) {
2467         isDrawn_ = true;
2468     }
2469     filterNeedUpdate_ = true;
2470     SetDirty();
2471 }
2472 
GetSpherize() const2473 float RSProperties::GetSpherize() const
2474 {
2475     return spherizeDegree_;
2476 }
2477 
IsSpherizeValid() const2478 bool RSProperties::IsSpherizeValid() const
2479 {
2480     return isSpherizeValid_;
2481 }
2482 
CreateFlyOutShaderFilter()2483 void RSProperties::CreateFlyOutShaderFilter()
2484 {
2485     uint32_t flyMode = flyOutParams_->flyMode;
2486     auto flyOutShaderFilter = std::make_shared<RSFlyOutShaderFilter>(flyOutDegree_, flyMode);
2487     foregroundFilter_ = flyOutShaderFilter;
2488 }
2489 
CreateSphereEffectFilter()2490 void RSProperties::CreateSphereEffectFilter()
2491 {
2492     auto spherizeEffectFilter = std::make_shared<RSSpherizeEffectFilter>(spherizeDegree_);
2493     if (IS_UNI_RENDER) {
2494         foregroundFilterCache_ = spherizeEffectFilter;
2495     } else {
2496         foregroundFilter_ = spherizeEffectFilter;
2497     }
2498 }
2499 
CreateAttractionEffectFilter()2500 void RSProperties::CreateAttractionEffectFilter()
2501 {
2502     float canvasWidth = GetBoundsRect().GetWidth();
2503     float canvasHeight = GetBoundsRect().GetHeight();
2504     Vector2f destinationPoint = GetAttractionDstPoint();
2505     float windowLeftPoint = GetFramePositionX();
2506     float windowTopPoint = GetFramePositionY();
2507     auto attractionEffectFilter = std::make_shared<RSAttractionEffectFilter>(attractFraction_);
2508     attractionEffectFilter->CalculateWindowStatus(canvasWidth, canvasHeight, destinationPoint);
2509     attractionEffectFilter->UpdateDirtyRegion(windowLeftPoint, windowTopPoint);
2510     attractionEffectCurrentDirtyRegion_ = attractionEffectFilter->GetAttractionDirtyRegion();
2511     foregroundFilter_ = attractionEffectFilter;
2512 }
2513 
CreateColorfulShadowFilter()2514 void RSProperties::CreateColorfulShadowFilter()
2515 {
2516     float elevation = GetShadowElevation();
2517     Drawing::scalar n1 = 0.25f * elevation * (1 + elevation / 128.0f); // 0.25f 128.0f
2518     Drawing::scalar blurRadius = elevation > 0.0f ? n1 : GetShadowRadius();
2519     Drawing::Path path = RSPropertyDrawableUtils::CreateShadowPath(GetShadowPath(), GetClipBounds(), GetRRect());
2520     auto colorfulShadowFilter = std::make_shared<RSColorfulShadowFilter>(
2521         blurRadius, GetShadowOffsetX(), GetShadowOffsetY(), path, GetShadowIsFilled());
2522     if (IS_UNI_RENDER) {
2523         foregroundFilterCache_ = colorfulShadowFilter;
2524     } else {
2525         foregroundFilter_ = colorfulShadowFilter;
2526     }
2527 }
2528 
GetAttractionEffectCurrentDirtyRegion() const2529 RectI RSProperties::GetAttractionEffectCurrentDirtyRegion() const
2530 {
2531     return attractionEffectCurrentDirtyRegion_;
2532 }
2533 
GetAttractionFraction() const2534 float RSProperties::GetAttractionFraction() const
2535 {
2536     return attractFraction_;
2537 }
2538 
SetAttractionDstPoint(Vector2f dstPoint)2539 void RSProperties::SetAttractionDstPoint(Vector2f dstPoint)
2540 {
2541     attractDstPoint_ = dstPoint;
2542 }
2543 
GetAttractionDstPoint() const2544 Vector2f  RSProperties::GetAttractionDstPoint() const
2545 {
2546     return attractDstPoint_;
2547 }
2548 
SetAttractionFraction(float fraction)2549 void RSProperties::SetAttractionFraction(float fraction)
2550 {
2551     attractFraction_ = fraction;
2552     isAttractionValid_ = attractFraction_ > ATTRACTION_VALID_EPSILON;
2553     if (isAttractionValid_) {
2554         isDrawn_ = true;
2555     }
2556     filterNeedUpdate_ = true;
2557     SetDirty();
2558     contentDirty_ = true;
2559 }
2560 
IsAttractionValid() const2561 bool RSProperties::IsAttractionValid() const
2562 {
2563     return isAttractionValid_;
2564 }
2565 
SetLightUpEffect(float lightUpEffectDegree)2566 void RSProperties::SetLightUpEffect(float lightUpEffectDegree)
2567 {
2568     lightUpEffectDegree_ = lightUpEffectDegree;
2569     if (IsLightUpEffectValid()) {
2570         isDrawn_ = true;
2571     }
2572     filterNeedUpdate_ = true;
2573     SetDirty();
2574     contentDirty_ = true;
2575 }
2576 
GetLightUpEffect() const2577 float RSProperties::GetLightUpEffect() const
2578 {
2579     return lightUpEffectDegree_;
2580 }
2581 
IsLightUpEffectValid() const2582 bool RSProperties::IsLightUpEffectValid() const
2583 {
2584     return ROSEN_GE(GetLightUpEffect(), 0.0) && ROSEN_LNE(GetLightUpEffect(), 1.0);
2585 }
2586 
2587 // filter property
SetBackgroundBlurRadius(float backgroundBlurRadius)2588 void RSProperties::SetBackgroundBlurRadius(float backgroundBlurRadius)
2589 {
2590     backgroundBlurRadius_ = backgroundBlurRadius;
2591     if (IsBackgroundBlurRadiusValid()) {
2592         isDrawn_ = true;
2593     }
2594     filterNeedUpdate_ = true;
2595     SetDirty();
2596     contentDirty_ = true;
2597 }
2598 
GetBackgroundBlurRadius() const2599 float RSProperties::GetBackgroundBlurRadius() const
2600 {
2601     return backgroundBlurRadius_;
2602 }
2603 
IsBackgroundBlurRadiusValid() const2604 bool RSProperties::IsBackgroundBlurRadiusValid() const
2605 {
2606     return ROSEN_GNE(GetBackgroundBlurRadius(), 0.9f); // Adjust the materialBlur radius to 0.9 for the spring curve
2607 }
2608 
SetBackgroundBlurSaturation(float backgroundBlurSaturation)2609 void RSProperties::SetBackgroundBlurSaturation(float backgroundBlurSaturation)
2610 {
2611     backgroundBlurSaturation_ = backgroundBlurSaturation;
2612     if (IsBackgroundBlurSaturationValid()) {
2613         isDrawn_ = true;
2614     }
2615     filterNeedUpdate_ = true;
2616     SetDirty();
2617     contentDirty_ = true;
2618 }
2619 
GetBackgroundBlurSaturation() const2620 float RSProperties::GetBackgroundBlurSaturation() const
2621 {
2622     return backgroundBlurSaturation_;
2623 }
2624 
IsBackgroundBlurSaturationValid() const2625 bool RSProperties::IsBackgroundBlurSaturationValid() const
2626 {
2627     return (!ROSEN_EQ(GetBackgroundBlurSaturation(), 1.0f)) && ROSEN_GE(GetBackgroundBlurSaturation(), 0.0f);
2628 }
2629 
SetBackgroundBlurBrightness(float backgroundBlurBrightness)2630 void RSProperties::SetBackgroundBlurBrightness(float backgroundBlurBrightness)
2631 {
2632     backgroundBlurBrightness_ = backgroundBlurBrightness;
2633     if (IsBackgroundBlurBrightnessValid()) {
2634         isDrawn_ = true;
2635     }
2636     filterNeedUpdate_ = true;
2637     SetDirty();
2638     contentDirty_ = true;
2639 }
2640 
GetBackgroundBlurBrightness() const2641 float RSProperties::GetBackgroundBlurBrightness() const
2642 {
2643     return backgroundBlurBrightness_;
2644 }
2645 
IsBackgroundBlurBrightnessValid() const2646 bool RSProperties::IsBackgroundBlurBrightnessValid() const
2647 {
2648     return (!ROSEN_EQ(GetBackgroundBlurBrightness(), 1.0f)) && ROSEN_GE(GetBackgroundBlurBrightness(), 0.0f);
2649 }
2650 
SetBackgroundBlurMaskColor(Color backgroundMaskColor)2651 void RSProperties::SetBackgroundBlurMaskColor(Color backgroundMaskColor)
2652 {
2653     backgroundMaskColor_ = backgroundMaskColor;
2654     if (IsBackgroundBlurMaskColorValid()) {
2655         isDrawn_ = true;
2656     }
2657     filterNeedUpdate_ = true;
2658     SetDirty();
2659     contentDirty_ = true;
2660 }
2661 
GetBackgroundBlurMaskColor() const2662 const Color& RSProperties::GetBackgroundBlurMaskColor() const
2663 {
2664     return backgroundMaskColor_;
2665 }
2666 
IsBackgroundBlurMaskColorValid() const2667 bool RSProperties::IsBackgroundBlurMaskColorValid() const
2668 {
2669     return backgroundMaskColor_ != RSColor();
2670 }
2671 
SetBackgroundBlurColorMode(int backgroundColorMode)2672 void RSProperties::SetBackgroundBlurColorMode(int backgroundColorMode)
2673 {
2674     backgroundColorMode_ = backgroundColorMode;
2675     filterNeedUpdate_ = true;
2676     SetDirty();
2677     contentDirty_ = true;
2678 }
2679 
GetBackgroundBlurColorMode() const2680 int RSProperties::GetBackgroundBlurColorMode() const
2681 {
2682     return backgroundColorMode_;
2683 }
2684 
SetBackgroundBlurRadiusX(float backgroundBlurRadiusX)2685 void RSProperties::SetBackgroundBlurRadiusX(float backgroundBlurRadiusX)
2686 {
2687     backgroundBlurRadiusX_ = backgroundBlurRadiusX;
2688     if (IsBackgroundBlurRadiusXValid()) {
2689         isDrawn_ = true;
2690     }
2691     filterNeedUpdate_ = true;
2692     SetDirty();
2693     contentDirty_ = true;
2694 }
2695 
GetBackgroundBlurRadiusX() const2696 float RSProperties::GetBackgroundBlurRadiusX() const
2697 {
2698     return backgroundBlurRadiusX_;
2699 }
2700 
IsBackgroundBlurRadiusXValid() const2701 bool RSProperties::IsBackgroundBlurRadiusXValid() const
2702 {
2703     return ROSEN_GNE(GetBackgroundBlurRadiusX(), 0.999f);
2704 }
2705 
SetBackgroundBlurRadiusY(float backgroundBlurRadiusY)2706 void RSProperties::SetBackgroundBlurRadiusY(float backgroundBlurRadiusY)
2707 {
2708     backgroundBlurRadiusY_ = backgroundBlurRadiusY;
2709     if (IsBackgroundBlurRadiusYValid()) {
2710         isDrawn_ = true;
2711     }
2712     filterNeedUpdate_ = true;
2713     SetDirty();
2714     contentDirty_ = true;
2715 }
2716 
GetBackgroundBlurRadiusY() const2717 float RSProperties::GetBackgroundBlurRadiusY() const
2718 {
2719     return backgroundBlurRadiusY_;
2720 }
2721 
IsBackgroundBlurRadiusYValid() const2722 bool RSProperties::IsBackgroundBlurRadiusYValid() const
2723 {
2724     return ROSEN_GNE(GetBackgroundBlurRadiusY(), 0.999f);
2725 }
2726 
SetForegroundBlurRadius(float foregroundBlurRadius)2727 void RSProperties::SetForegroundBlurRadius(float foregroundBlurRadius)
2728 {
2729     foregroundBlurRadius_ = foregroundBlurRadius;
2730     if (IsForegroundBlurRadiusValid()) {
2731         isDrawn_ = true;
2732     }
2733     filterNeedUpdate_ = true;
2734     SetDirty();
2735     contentDirty_ = true;
2736 }
2737 
GetForegroundBlurRadius() const2738 float RSProperties::GetForegroundBlurRadius() const
2739 {
2740     return foregroundBlurRadius_;
2741 }
2742 
IsForegroundBlurRadiusValid() const2743 bool RSProperties::IsForegroundBlurRadiusValid() const
2744 {
2745     return ROSEN_GNE(GetForegroundBlurRadius(), 0.9f); // Adjust the materialBlur radius to 0.9 for the spring curve
2746 }
2747 
SetForegroundBlurSaturation(float foregroundBlurSaturation)2748 void RSProperties::SetForegroundBlurSaturation(float foregroundBlurSaturation)
2749 {
2750     foregroundBlurSaturation_ = foregroundBlurSaturation;
2751     if (IsForegroundBlurSaturationValid()) {
2752         isDrawn_ = true;
2753     }
2754     filterNeedUpdate_ = true;
2755     SetDirty();
2756     contentDirty_ = true;
2757 }
2758 
GetForegroundBlurSaturation() const2759 float RSProperties::GetForegroundBlurSaturation() const
2760 {
2761     return foregroundBlurSaturation_;
2762 }
2763 
IsForegroundBlurSaturationValid() const2764 bool RSProperties::IsForegroundBlurSaturationValid() const
2765 {
2766     return ROSEN_GE(GetForegroundBlurSaturation(), 1.0);
2767 }
2768 
SetForegroundBlurBrightness(float foregroundBlurBrightness)2769 void RSProperties::SetForegroundBlurBrightness(float foregroundBlurBrightness)
2770 {
2771     foregroundBlurBrightness_ = foregroundBlurBrightness;
2772     if (IsForegroundBlurBrightnessValid()) {
2773         isDrawn_ = true;
2774     }
2775     filterNeedUpdate_ = true;
2776     SetDirty();
2777     contentDirty_ = true;
2778 }
2779 
GetForegroundBlurBrightness() const2780 float RSProperties::GetForegroundBlurBrightness() const
2781 {
2782     return foregroundBlurBrightness_;
2783 }
2784 
IsForegroundBlurBrightnessValid() const2785 bool RSProperties::IsForegroundBlurBrightnessValid() const
2786 {
2787     return ROSEN_GE(GetForegroundBlurBrightness(), 1.0);
2788 }
2789 
SetForegroundBlurMaskColor(Color foregroundMaskColor)2790 void RSProperties::SetForegroundBlurMaskColor(Color foregroundMaskColor)
2791 {
2792     foregroundMaskColor_ = foregroundMaskColor;
2793     if (IsForegroundBlurMaskColorValid()) {
2794         isDrawn_ = true;
2795     }
2796     filterNeedUpdate_ = true;
2797     SetDirty();
2798     contentDirty_ = true;
2799 }
2800 
GetForegroundBlurMaskColor() const2801 const Color& RSProperties::GetForegroundBlurMaskColor() const
2802 {
2803     return foregroundMaskColor_;
2804 }
2805 
IsForegroundBlurMaskColorValid() const2806 bool RSProperties::IsForegroundBlurMaskColorValid() const
2807 {
2808     return foregroundMaskColor_ != RSColor();
2809 }
2810 
SetForegroundBlurColorMode(int foregroundColorMode)2811 void RSProperties::SetForegroundBlurColorMode(int foregroundColorMode)
2812 {
2813     foregroundColorMode_ = foregroundColorMode;
2814     filterNeedUpdate_ = true;
2815     SetDirty();
2816     contentDirty_ = true;
2817 }
2818 
GetForegroundBlurColorMode() const2819 int RSProperties::GetForegroundBlurColorMode() const
2820 {
2821     return foregroundColorMode_;
2822 }
2823 
SetForegroundBlurRadiusX(float foregroundBlurRadiusX)2824 void RSProperties::SetForegroundBlurRadiusX(float foregroundBlurRadiusX)
2825 {
2826     foregroundBlurRadiusX_ = foregroundBlurRadiusX;
2827     if (IsForegroundBlurRadiusXValid()) {
2828         isDrawn_ = true;
2829     }
2830     filterNeedUpdate_ = true;
2831     SetDirty();
2832     contentDirty_ = true;
2833 }
2834 
GetForegroundBlurRadiusX() const2835 float RSProperties::GetForegroundBlurRadiusX() const
2836 {
2837     return foregroundBlurRadiusX_;
2838 }
2839 
IsForegroundBlurRadiusXValid() const2840 bool RSProperties::IsForegroundBlurRadiusXValid() const
2841 {
2842     return ROSEN_GNE(GetForegroundBlurRadiusX(), 0.999f);
2843 }
2844 
SetForegroundBlurRadiusY(float foregroundBlurRadiusY)2845 void RSProperties::SetForegroundBlurRadiusY(float foregroundBlurRadiusY)
2846 {
2847     foregroundBlurRadiusY_ = foregroundBlurRadiusY;
2848     if (IsForegroundBlurRadiusYValid()) {
2849         isDrawn_ = true;
2850     }
2851     filterNeedUpdate_ = true;
2852     SetDirty();
2853     contentDirty_ = true;
2854 }
2855 
GetForegroundBlurRadiusY() const2856 float RSProperties::GetForegroundBlurRadiusY() const
2857 {
2858     return foregroundBlurRadiusY_;
2859 }
2860 
IsForegroundBlurRadiusYValid() const2861 bool RSProperties::IsForegroundBlurRadiusYValid() const
2862 {
2863     return ROSEN_GNE(GetForegroundBlurRadiusY(), 0.999f);
2864 }
2865 
IsBackgroundMaterialFilterValid() const2866 bool RSProperties::IsBackgroundMaterialFilterValid() const
2867 {
2868     return IsBackgroundBlurRadiusValid() || IsBackgroundBlurBrightnessValid() || IsBackgroundBlurSaturationValid();
2869 }
2870 
IsForegroundMaterialFilterVaild() const2871 bool RSProperties::IsForegroundMaterialFilterVaild() const
2872 {
2873     return IsForegroundBlurRadiusValid();
2874 }
2875 
GetMaterialColorFilter(float sat,float brightness)2876 std::shared_ptr<Drawing::ColorFilter> RSProperties::GetMaterialColorFilter(float sat, float brightness)
2877 {
2878     float normalizedDegree = brightness - 1.0;
2879     const float brightnessMat[] = {
2880         1.000000f, 0.000000f, 0.000000f, 0.000000f, normalizedDegree,
2881         0.000000f, 1.000000f, 0.000000f, 0.000000f, normalizedDegree,
2882         0.000000f, 0.000000f, 1.000000f, 0.000000f, normalizedDegree,
2883         0.000000f, 0.000000f, 0.000000f, 1.000000f, 0.000000f,
2884     };
2885     Drawing::ColorMatrix cm;
2886     cm.SetSaturation(sat);
2887     float cmArray[Drawing::ColorMatrix::MATRIX_SIZE];
2888     cm.GetArray(cmArray);
2889     std::shared_ptr<Drawing::ColorFilter> filterCompose =
2890         Drawing::ColorFilter::CreateComposeColorFilter(cmArray, brightnessMat, Drawing::Clamp::NO_CLAMP);
2891     return filterCompose;
2892 }
2893 
GenerateBackgroundBlurFilter()2894 void RSProperties::GenerateBackgroundBlurFilter()
2895 {
2896     std::shared_ptr<Drawing::ImageFilter> blurFilter = Drawing::ImageFilter::CreateBlurImageFilter(
2897         backgroundBlurRadiusX_, backgroundBlurRadiusY_, Drawing::TileMode::CLAMP, nullptr);
2898     uint32_t hash = SkOpts::hash(&backgroundBlurRadiusX_, sizeof(backgroundBlurRadiusX_), 0);
2899     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2900 
2901     // fuse grey-adjustment and pixel-stretch with blur filter
2902     if (NeedBlurFuzed()) {
2903         std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
2904         if (greyCoef_.has_value()) {
2905             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadiusX_,
2906                 greyCoef_->x_, greyCoef_->y_);
2907         } else {
2908             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadiusX_);
2909         }
2910         originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
2911         originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadiusX_));
2912         backgroundFilter_ = originalFilter;
2913         backgroundFilter_->SetFilterType(RSFilter::BLUR);
2914         return;
2915     }
2916 
2917     if (greyCoef_.has_value()) {
2918         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2919             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2920         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2921     }
2922 
2923     if (RSSystemProperties::GetKawaseEnabled()) {
2924         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2925             std::make_shared<RSKawaseBlurShaderFilter>(backgroundBlurRadiusX_);
2926         if (originalFilter == nullptr) {
2927             originalFilter = std::make_shared<RSDrawingFilter>(kawaseBlurFilter);
2928         } else {
2929             originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
2930         }
2931     } else {
2932         if (originalFilter == nullptr) {
2933             originalFilter = std::make_shared<RSDrawingFilter>(blurFilter, hash);
2934         } else {
2935             originalFilter = originalFilter->Compose(blurFilter, hash);
2936         }
2937     }
2938     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadiusX_));
2939     backgroundFilter_ = originalFilter;
2940     backgroundFilter_->SetFilterType(RSFilter::BLUR);
2941 }
2942 
GenerateBackgroundMaterialBlurFilter()2943 void RSProperties::GenerateBackgroundMaterialBlurFilter()
2944 {
2945     if (backgroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
2946         backgroundColorMode_ = BLUR_COLOR_MODE::AVERAGE;
2947     }
2948 
2949     float radiusForHash = DecreasePrecision(backgroundBlurRadius_);
2950     float saturationForHash = DecreasePrecision(backgroundBlurSaturation_);
2951     float brightnessForHash = DecreasePrecision(backgroundBlurBrightness_);
2952     uint32_t hash = SkOpts::hash(&radiusForHash, sizeof(radiusForHash), 0);
2953     hash = SkOpts::hash(&saturationForHash, sizeof(saturationForHash), hash);
2954     hash = SkOpts::hash(&brightnessForHash, sizeof(brightnessForHash), hash);
2955 
2956     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
2957         backgroundBlurSaturation_, backgroundBlurBrightness_);
2958     std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
2959         Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, backgroundBlurRadius_, backgroundBlurRadius_);
2960 
2961     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
2962 
2963     // fuse grey-adjustment and pixel-stretch with blur filter
2964     if (NeedBlurFuzed()) {
2965         GenerateBackgroundMaterialFuzedBlurFilter();
2966         return;
2967     }
2968 
2969     if (greyCoef_.has_value()) {
2970         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
2971             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
2972         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
2973     }
2974 
2975     if (RSSystemProperties::GetKawaseEnabled()) {
2976         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
2977             std::make_shared<RSKawaseBlurShaderFilter>(backgroundBlurRadius_);
2978         auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
2979         originalFilter = originalFilter?
2980             originalFilter->Compose(colorImageFilter, hash) : std::make_shared<RSDrawingFilter>(colorImageFilter, hash);
2981         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
2982     } else {
2983         originalFilter = originalFilter?
2984             originalFilter->Compose(blurColorFilter, hash) : std::make_shared<RSDrawingFilter>(blurColorFilter, hash);
2985     }
2986     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
2987         backgroundColorMode_, backgroundMaskColor_);
2988     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
2989     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadius_));
2990     originalFilter->SetSaturationForHPS(backgroundBlurSaturation_);
2991     originalFilter->SetBrightnessForHPS(backgroundBlurBrightness_);
2992     backgroundFilter_ = originalFilter;
2993     backgroundFilter_->SetFilterType(RSFilter::MATERIAL);
2994 }
2995 
GenerateForegroundBlurFilter()2996 void RSProperties::GenerateForegroundBlurFilter()
2997 {
2998     std::shared_ptr<Drawing::ImageFilter> blurFilter = Drawing::ImageFilter::CreateBlurImageFilter(
2999         foregroundBlurRadiusX_, foregroundBlurRadiusY_, Drawing::TileMode::CLAMP, nullptr);
3000     uint32_t hash = SkOpts::hash(&foregroundBlurRadiusX_, sizeof(foregroundBlurRadiusX_), 0);
3001     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
3002 
3003     // fuse grey-adjustment and pixel-stretch with blur filter
3004     if (NeedBlurFuzed()) {
3005         std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
3006         if (greyCoef_.has_value()) {
3007             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadiusX_,
3008                 greyCoef_->x_, greyCoef_->y_);
3009         } else {
3010             mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadiusX_);
3011         }
3012         originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
3013         originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadiusX_));
3014         filter_ = originalFilter;
3015         filter_->SetFilterType(RSFilter::BLUR);
3016         return;
3017     }
3018 
3019     if (greyCoef_.has_value()) {
3020         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
3021             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
3022         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
3023     }
3024     if (RSSystemProperties::GetKawaseEnabled()) {
3025         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
3026             std::make_shared<RSKawaseBlurShaderFilter>(foregroundBlurRadiusX_);
3027         if (originalFilter == nullptr) {
3028             originalFilter = std::make_shared<RSDrawingFilter>(kawaseBlurFilter);
3029         } else {
3030             originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
3031         }
3032     } else {
3033         if (originalFilter == nullptr) {
3034             originalFilter = std::make_shared<RSDrawingFilter>(blurFilter, hash);
3035         } else {
3036             originalFilter = originalFilter->Compose(blurFilter, hash);
3037         }
3038     }
3039     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadiusX_));
3040     filter_ = originalFilter;
3041     filter_->SetFilterType(RSFilter::BLUR);
3042 }
3043 
GenerateForegroundMaterialBlurFilter()3044 void RSProperties::GenerateForegroundMaterialBlurFilter()
3045 {
3046     if (foregroundColorMode_ == BLUR_COLOR_MODE::FASTAVERAGE) {
3047         foregroundColorMode_ = BLUR_COLOR_MODE::AVERAGE;
3048     }
3049     uint32_t hash = SkOpts::hash(&foregroundBlurRadius_, sizeof(foregroundBlurRadius_), 0);
3050     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
3051         foregroundBlurSaturation_, foregroundBlurBrightness_);
3052     std::shared_ptr<Drawing::ImageFilter> blurColorFilter =
3053         Drawing::ImageFilter::CreateColorBlurImageFilter(*colorFilter, foregroundBlurRadius_, foregroundBlurRadius_);
3054 
3055     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
3056 
3057     // fuse grey-adjustment and pixel-stretch with blur filter
3058     if (NeedBlurFuzed()) {
3059         GenerateCompositingMaterialFuzedBlurFilter();
3060         return;
3061     }
3062 
3063     if (greyCoef_.has_value()) {
3064         std::shared_ptr<RSGreyShaderFilter> greyShaderFilter =
3065             std::make_shared<RSGreyShaderFilter>(greyCoef_->x_, greyCoef_->y_);
3066         originalFilter = std::make_shared<RSDrawingFilter>(greyShaderFilter);
3067     }
3068 
3069     if (RSSystemProperties::GetKawaseEnabled()) {
3070         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
3071             std::make_shared<RSKawaseBlurShaderFilter>(foregroundBlurRadius_);
3072         auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
3073         originalFilter = originalFilter?
3074             originalFilter->Compose(colorImageFilter, hash) : std::make_shared<RSDrawingFilter>(colorImageFilter, hash);
3075         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
3076     } else {
3077         hash = SkOpts::hash(&foregroundBlurSaturation_, sizeof(foregroundBlurSaturation_), hash);
3078         hash = SkOpts::hash(&foregroundBlurBrightness_, sizeof(foregroundBlurBrightness_), hash);
3079         originalFilter = originalFilter?
3080             originalFilter->Compose(blurColorFilter, hash) : std::make_shared<RSDrawingFilter>(blurColorFilter, hash);
3081     }
3082     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
3083         foregroundColorMode_, foregroundMaskColor_);
3084     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
3085     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadius_));
3086     originalFilter->SetSaturationForHPS(foregroundBlurSaturation_);
3087     originalFilter->SetBrightnessForHPS(foregroundBlurBrightness_);
3088     filter_ = originalFilter;
3089     filter_->SetFilterType(RSFilter::MATERIAL);
3090 }
3091 
GenerateBackgroundMaterialFuzedBlurFilter()3092 void RSProperties::GenerateBackgroundMaterialFuzedBlurFilter()
3093 {
3094     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
3095     std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
3096     if (greyCoef_.has_value()) {
3097         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadius_,
3098             greyCoef_->x_, greyCoef_->y_);
3099     } else {
3100         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(backgroundBlurRadius_);
3101     }
3102     originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
3103     uint32_t hash = SkOpts::hash(&backgroundBlurRadius_, sizeof(backgroundBlurRadius_), 0);
3104     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
3105         backgroundBlurSaturation_, backgroundBlurBrightness_);
3106     auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
3107     originalFilter = originalFilter->Compose(colorImageFilter, hash);
3108     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
3109         backgroundColorMode_, backgroundMaskColor_);
3110     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
3111     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(backgroundBlurRadius_));
3112     backgroundFilter_ = originalFilter;
3113     backgroundFilter_->SetFilterType(RSFilter::MATERIAL);
3114 }
3115 
GenerateCompositingMaterialFuzedBlurFilter()3116 void RSProperties::GenerateCompositingMaterialFuzedBlurFilter()
3117 {
3118     std::shared_ptr<RSDrawingFilter> originalFilter = nullptr;
3119     std::shared_ptr<RSMESABlurShaderFilter> mesaBlurShaderFilter;
3120     if (greyCoef_.has_value()) {
3121         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadius_,
3122             greyCoef_->x_, greyCoef_->y_);
3123     } else {
3124         mesaBlurShaderFilter = std::make_shared<RSMESABlurShaderFilter>(foregroundBlurRadius_);
3125     }
3126     originalFilter = std::make_shared<RSDrawingFilter>(mesaBlurShaderFilter);
3127     uint32_t hash = SkOpts::hash(&foregroundBlurRadius_, sizeof(foregroundBlurRadius_), 0);
3128     std::shared_ptr<Drawing::ColorFilter> colorFilter = GetMaterialColorFilter(
3129         foregroundBlurSaturation_, foregroundBlurBrightness_);
3130     auto colorImageFilter = Drawing::ImageFilter::CreateColorFilterImageFilter(*colorFilter, nullptr);
3131     originalFilter = originalFilter->Compose(colorImageFilter, hash);
3132     std::shared_ptr<RSMaskColorShaderFilter> maskColorShaderFilter = std::make_shared<RSMaskColorShaderFilter>(
3133         foregroundColorMode_, foregroundMaskColor_);
3134     originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(maskColorShaderFilter));
3135     originalFilter->SetSkipFrame(RSDrawingFilter::CanSkipFrame(foregroundBlurRadius_));
3136     filter_ = originalFilter;
3137     filter_->SetFilterType(RSFilter::MATERIAL);
3138 }
3139 
GenerateAIBarFilter()3140 void RSProperties::GenerateAIBarFilter()
3141 {
3142     std::vector<float> aiInvertCoef = RSAIBarShaderFilter::GetAiInvertCoef();
3143     float aiBarRadius = aiInvertCoef[5]; // aiInvertCoef[5] is filter_radius
3144     std::shared_ptr<Drawing::ImageFilter> blurFilter =
3145         Drawing::ImageFilter::CreateBlurImageFilter(aiBarRadius, aiBarRadius, Drawing::TileMode::CLAMP, nullptr);
3146     std::shared_ptr<RSAIBarShaderFilter> aiBarShaderFilter = std::make_shared<RSAIBarShaderFilter>();
3147     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(aiBarShaderFilter);
3148 
3149     if (RSSystemProperties::GetKawaseEnabled()) {
3150         std::shared_ptr<RSKawaseBlurShaderFilter> kawaseBlurFilter =
3151             std::make_shared<RSKawaseBlurShaderFilter>(aiBarRadius);
3152         originalFilter = originalFilter->Compose(std::static_pointer_cast<RSShaderFilter>(kawaseBlurFilter));
3153     } else {
3154         uint32_t hash = SkOpts::hash(&aiBarRadius, sizeof(aiBarRadius), 0);
3155         originalFilter = originalFilter->Compose(blurFilter, hash);
3156     }
3157     backgroundFilter_ = originalFilter;
3158     backgroundFilter_->SetFilterType(RSFilter::AIBAR);
3159 }
3160 
GenerateLinearGradientBlurFilter()3161 void RSProperties::GenerateLinearGradientBlurFilter()
3162 {
3163     auto linearBlurFilter = std::make_shared<RSLinearGradientBlurShaderFilter>(linearGradientBlurPara_,
3164         frameGeo_.GetWidth(), frameGeo_.GetHeight());
3165     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(linearBlurFilter);
3166 
3167     filter_ = originalFilter;
3168     filter_->SetFilterType(RSFilter::LINEAR_GRADIENT_BLUR);
3169 }
3170 
GenerateMagnifierFilter()3171 void RSProperties::GenerateMagnifierFilter()
3172 {
3173     auto magnifierFilter = std::make_shared<RSMagnifierShaderFilter>(magnifierPara_);
3174 
3175     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(magnifierFilter);
3176     backgroundFilter_ = originalFilter;
3177     backgroundFilter_->SetFilterType(RSFilter::MAGNIFIER);
3178 }
3179 
GenerateWaterRippleFilter()3180 void RSProperties::GenerateWaterRippleFilter()
3181 {
3182     if (!waterRippleParams_) {
3183         return;
3184     }
3185     uint32_t waveCount = waterRippleParams_->waveCount;
3186     float rippleCenterX = waterRippleParams_->rippleCenterX;
3187     float rippleCenterY = waterRippleParams_->rippleCenterY;
3188     uint32_t rippleMode = waterRippleParams_->rippleMode;
3189     std::shared_ptr<RSWaterRippleShaderFilter> waterRippleFilter =
3190         std::make_shared<RSWaterRippleShaderFilter>(waterRippleProgress_, waveCount, rippleCenterX, rippleCenterY,
3191             rippleMode);
3192     std::shared_ptr<RSDrawingFilter> originalFilter = std::make_shared<RSDrawingFilter>(waterRippleFilter);
3193     if (!backgroundFilter_) {
3194         backgroundFilter_ = originalFilter;
3195         backgroundFilter_->SetFilterType(RSFilter::WATER_RIPPLE);
3196     } else {
3197         auto backgroudDrawingFilter = std::static_pointer_cast<RSDrawingFilter>(backgroundFilter_);
3198         backgroudDrawingFilter->Compose(waterRippleFilter);
3199         backgroudDrawingFilter->SetFilterType(RSFilter::COMPOUND_EFFECT);
3200         backgroundFilter_ = backgroudDrawingFilter;
3201     }
3202 }
3203 
GenerateBackgroundFilter()3204 void RSProperties::GenerateBackgroundFilter()
3205 {
3206     if (aiInvert_.has_value() || systemBarEffect_) {
3207         GenerateAIBarFilter();
3208     } else if (magnifierPara_ && ROSEN_GNE(magnifierPara_->factor_, 0.f)) {
3209         GenerateMagnifierFilter();
3210     } else if (IsBackgroundMaterialFilterValid()) {
3211         GenerateBackgroundMaterialBlurFilter();
3212     } else if (IsBackgroundBlurRadiusXValid() && IsBackgroundBlurRadiusYValid()) {
3213         GenerateBackgroundBlurFilter();
3214     } else {
3215         backgroundFilter_ = nullptr;
3216     }
3217     if (IsWaterRippleValid()) {
3218         GenerateWaterRippleFilter();
3219     }
3220     if (backgroundFilter_ == nullptr) {
3221         ROSEN_LOGD("RSProperties::GenerateBackgroundFilter failed");
3222     }
3223 }
3224 
GenerateForegroundFilter()3225 void RSProperties::GenerateForegroundFilter()
3226 {
3227     IfLinearGradientBlurInvalid();
3228     if (linearGradientBlurPara_) {
3229         GenerateLinearGradientBlurFilter();
3230     } else if (IsForegroundMaterialFilterVaild()) {
3231         GenerateForegroundMaterialBlurFilter();
3232     } else if (IsForegroundBlurRadiusXValid() && IsForegroundBlurRadiusYValid()) {
3233         GenerateForegroundBlurFilter();
3234     } else {
3235         filter_ = nullptr;
3236     }
3237     if (filter_ == nullptr) {
3238         ROSEN_LOGD("RSProperties::GenerateForegroundFilter failed");
3239     }
3240 }
3241 
SetUseEffect(bool useEffect)3242 void RSProperties::SetUseEffect(bool useEffect)
3243 {
3244     useEffect_ = useEffect;
3245     if (GetUseEffect()) {
3246         isDrawn_ = true;
3247     }
3248     filterNeedUpdate_ = true;
3249     SetDirty();
3250 }
3251 
GetUseEffect() const3252 bool RSProperties::GetUseEffect() const
3253 {
3254     return useEffect_;
3255 }
3256 
SetUseEffectType(int useEffectType)3257 void RSProperties::SetUseEffectType(int useEffectType)
3258 {
3259     useEffectType_ = std::clamp<int>(useEffectType, 0, static_cast<int>(UseEffectType::MAX));
3260     isDrawn_ = true;
3261     filterNeedUpdate_ = true;
3262     SetDirty();
3263     contentDirty_ = true;
3264 }
3265 
GetUseEffectType() const3266 int RSProperties::GetUseEffectType() const
3267 {
3268     return useEffectType_;
3269 }
3270 
SetNeedDrawBehindWindow(bool needDrawBehindWindow)3271 void RSProperties::SetNeedDrawBehindWindow(bool needDrawBehindWindow)
3272 {
3273     needDrawBehindWindow_ = needDrawBehindWindow;
3274     UpdateFilter();
3275 }
3276 
GetNeedDrawBehindWindow() const3277 bool RSProperties::GetNeedDrawBehindWindow() const
3278 {
3279     return needDrawBehindWindow_;
3280 }
3281 
SetUseShadowBatching(bool useShadowBatching)3282 void RSProperties::SetUseShadowBatching(bool useShadowBatching)
3283 {
3284     if (useShadowBatching) {
3285         isDrawn_ = true;
3286     }
3287     useShadowBatching_ = useShadowBatching;
3288     SetDirty();
3289 }
3290 
SetPixelStretch(const std::optional<Vector4f> & stretchSize)3291 void RSProperties::SetPixelStretch(const std::optional<Vector4f>& stretchSize)
3292 {
3293     pixelStretch_ = stretchSize;
3294     SetDirty();
3295     pixelStretchNeedUpdate_ = true;
3296     contentDirty_ = true;
3297     if (pixelStretch_.has_value() && pixelStretch_->IsZero()) {
3298         pixelStretch_ = std::nullopt;
3299     }
3300 }
3301 
GetPixelStretchDirtyRect() const3302 RectI RSProperties::GetPixelStretchDirtyRect() const
3303 {
3304     auto dirtyRect = GetDirtyRect();
3305 
3306     auto scaledBounds = RectF(dirtyRect.left_ - pixelStretch_->x_, dirtyRect.top_ - pixelStretch_->y_,
3307         dirtyRect.width_ + pixelStretch_->x_ + pixelStretch_->z_,
3308         dirtyRect.height_ + pixelStretch_->y_ + pixelStretch_->w_);
3309 
3310     auto scaledIBounds = RectI(std::floor(scaledBounds.left_), std::floor(scaledBounds.top_),
3311         std::ceil(scaledBounds.width_) + 1, std::ceil(scaledBounds.height_) + 1);
3312     return dirtyRect.JoinRect(scaledIBounds);
3313 }
3314 
SetPixelStretchPercent(const std::optional<Vector4f> & stretchPercent)3315 void RSProperties::SetPixelStretchPercent(const std::optional<Vector4f>& stretchPercent)
3316 {
3317     pixelStretchPercent_ = stretchPercent;
3318     SetDirty();
3319     pixelStretchNeedUpdate_ = true;
3320     contentDirty_ = true;
3321     if (pixelStretchPercent_.has_value() && pixelStretchPercent_->IsZero()) {
3322         pixelStretchPercent_ = std::nullopt;
3323     }
3324 }
3325 
SetPixelStretchTileMode(int stretchTileMode)3326 void RSProperties::SetPixelStretchTileMode(int stretchTileMode)
3327 {
3328     pixelStretchTileMode_ = std::clamp<int>(stretchTileMode, static_cast<int>(Drawing::TileMode::CLAMP),
3329         static_cast<int>(Drawing::TileMode::DECAL));
3330     SetDirty();
3331     pixelStretchNeedUpdate_ = true;
3332     contentDirty_ = true;
3333 }
3334 
GetPixelStretchTileMode() const3335 int RSProperties::GetPixelStretchTileMode() const
3336 {
3337     return pixelStretchTileMode_;
3338 }
3339 
3340 // Image effect properties
SetGrayScale(const std::optional<float> & grayScale)3341 void RSProperties::SetGrayScale(const std::optional<float>& grayScale)
3342 {
3343     grayScale_ = grayScale;
3344     colorFilterNeedUpdate_ = true;
3345     SetDirty();
3346     contentDirty_ = true;
3347 }
3348 
SetLightIntensity(float lightIntensity)3349 void RSProperties::SetLightIntensity(float lightIntensity)
3350 {
3351     if (!lightSourcePtr_) {
3352         lightSourcePtr_ = std::make_shared<RSLightSource>();
3353     }
3354     lightSourcePtr_->SetLightIntensity(lightIntensity);
3355     SetDirty();
3356     contentDirty_ = true;
3357 
3358     if (ROSEN_EQ(lightIntensity, INVALID_INTENSITY)) { // skip when resetFunc call
3359         return;
3360     }
3361     auto preIntensity = lightSourcePtr_->GetPreLightIntensity();
3362     auto renderNode = backref_.lock();
3363     bool preIntensityIsZero = ROSEN_EQ(preIntensity, 0.f);
3364     bool curIntensityIsZero = ROSEN_EQ(lightIntensity, 0.f);
3365     if (preIntensityIsZero && !curIntensityIsZero) { // 0 --> non-zero
3366         RSPointLightManager::Instance()->RegisterLightSource(renderNode);
3367     } else if (!preIntensityIsZero && curIntensityIsZero) { // non-zero --> 0
3368         RSPointLightManager::Instance()->UnRegisterLightSource(renderNode);
3369     }
3370 }
3371 
SetLightColor(Color lightColor)3372 void RSProperties::SetLightColor(Color lightColor)
3373 {
3374     if (!lightSourcePtr_) {
3375         lightSourcePtr_ = std::make_shared<RSLightSource>();
3376     }
3377     lightSourcePtr_->SetLightColor(lightColor);
3378     SetDirty();
3379     contentDirty_ = true;
3380 }
3381 
SetLightPosition(const Vector4f & lightPosition)3382 void RSProperties::SetLightPosition(const Vector4f& lightPosition)
3383 {
3384     if (!lightSourcePtr_) {
3385         lightSourcePtr_ = std::make_shared<RSLightSource>();
3386     }
3387     lightSourcePtr_->SetLightPosition(lightPosition);
3388     SetDirty();
3389     contentDirty_ = true;
3390 }
3391 
SetIlluminatedBorderWidth(float illuminatedBorderWidth)3392 void RSProperties::SetIlluminatedBorderWidth(float illuminatedBorderWidth)
3393 {
3394     if (!illuminatedPtr_) {
3395         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3396     }
3397     illuminatedPtr_->SetIlluminatedBorderWidth(illuminatedBorderWidth);
3398     SetDirty();
3399     contentDirty_ = true;
3400 }
3401 
SetIlluminatedType(int illuminatedType)3402 void RSProperties::SetIlluminatedType(int illuminatedType)
3403 {
3404     if (!illuminatedPtr_) {
3405         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3406     }
3407     auto curIlluminateType = IlluminatedType(illuminatedType);
3408     illuminatedPtr_->SetIlluminatedType(curIlluminateType);
3409     isDrawn_ = true;
3410     SetDirty();
3411     contentDirty_ = true;
3412 
3413     if (curIlluminateType == IlluminatedType::INVALID) { // skip when resetFunc call
3414         return;
3415     }
3416     auto renderNode = backref_.lock();
3417     auto preIlluminatedType = illuminatedPtr_->GetPreIlluminatedType();
3418     bool preTypeIsNone = preIlluminatedType == IlluminatedType::NONE;
3419     bool curTypeIsNone = curIlluminateType == IlluminatedType::NONE;
3420     if (preTypeIsNone && !curTypeIsNone) {
3421         RSPointLightManager::Instance()->RegisterIlluminated(renderNode);
3422     } else if (!preTypeIsNone && curTypeIsNone) {
3423         RSPointLightManager::Instance()->UnRegisterIlluminated(renderNode);
3424     }
3425 }
3426 
SetBloom(float bloomIntensity)3427 void RSProperties::SetBloom(float bloomIntensity)
3428 {
3429     if (!illuminatedPtr_) {
3430         illuminatedPtr_ = std::make_shared<RSIlluminated>();
3431     }
3432     illuminatedPtr_->SetBloomIntensity(bloomIntensity);
3433     isDrawn_ = true;
3434     SetDirty();
3435     contentDirty_ = true;
3436 }
3437 
GetLightIntensity() const3438 float RSProperties::GetLightIntensity() const
3439 {
3440     return lightSourcePtr_ ? lightSourcePtr_->GetLightIntensity() : 0.f;
3441 }
3442 
GetLightColor() const3443 Color RSProperties::GetLightColor() const
3444 {
3445     return lightSourcePtr_ ? lightSourcePtr_->GetLightColor() : RgbPalette::White();
3446 }
3447 
GetLightPosition() const3448 Vector4f RSProperties::GetLightPosition() const
3449 {
3450     return lightSourcePtr_ ? lightSourcePtr_->GetLightPosition() : Vector4f(0.f);
3451 }
3452 
GetIlluminatedType() const3453 int RSProperties::GetIlluminatedType() const
3454 {
3455     return illuminatedPtr_ ? static_cast<int>(illuminatedPtr_->GetIlluminatedType()) : 0;
3456 }
3457 
CalculateAbsLightPosition()3458 void RSProperties::CalculateAbsLightPosition()
3459 {
3460     auto lightSourceAbsRect = boundsGeo_->GetAbsRect();
3461     auto rotation = RSPointLightManager::Instance()->GetScreenRotation();
3462     Vector4f lightAbsPosition = Vector4f();
3463     auto lightPos = lightSourcePtr_->GetLightPosition();
3464     switch (rotation) {
3465         case ScreenRotation::ROTATION_0:
3466             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetLeft() + lightPos.x_);
3467             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetTop() + lightPos.y_);
3468             break;
3469         case ScreenRotation::ROTATION_90:
3470             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetBottom() - lightPos.x_);
3471             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetLeft() + lightPos.y_);
3472             break;
3473         case ScreenRotation::ROTATION_180:
3474             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetRight() - lightPos.x_);
3475             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetBottom() - lightPos.y_);
3476             break;
3477         case ScreenRotation::ROTATION_270:
3478             lightAbsPosition.x_ = static_cast<int>(lightSourceAbsRect.GetTop() + lightPos.x_);
3479             lightAbsPosition.y_ = static_cast<int>(lightSourceAbsRect.GetRight() - lightPos.y_);
3480             break;
3481         default:
3482             break;
3483     }
3484     lightAbsPosition.z_ = lightPos.z_;
3485     lightAbsPosition.w_ = lightPos.w_;
3486     lightSourcePtr_->SetAbsLightPosition(lightAbsPosition);
3487 }
3488 
SetBrightness(const std::optional<float> & brightness)3489 void RSProperties::SetBrightness(const std::optional<float>& brightness)
3490 {
3491     brightness_ = brightness;
3492     colorFilterNeedUpdate_ = true;
3493     SetDirty();
3494     contentDirty_ = true;
3495 }
3496 
GetBrightness() const3497 const std::optional<float>& RSProperties::GetBrightness() const
3498 {
3499     return brightness_;
3500 }
3501 
SetContrast(const std::optional<float> & contrast)3502 void RSProperties::SetContrast(const std::optional<float>& contrast)
3503 {
3504     contrast_ = contrast;
3505     colorFilterNeedUpdate_ = true;
3506     SetDirty();
3507     contentDirty_ = true;
3508 }
3509 
GetContrast() const3510 const std::optional<float>& RSProperties::GetContrast() const
3511 {
3512     return contrast_;
3513 }
3514 
SetSaturate(const std::optional<float> & saturate)3515 void RSProperties::SetSaturate(const std::optional<float>& saturate)
3516 {
3517     saturate_ = saturate;
3518     colorFilterNeedUpdate_ = true;
3519     SetDirty();
3520     contentDirty_ = true;
3521 }
3522 
GetSaturate() const3523 const std::optional<float>& RSProperties::GetSaturate() const
3524 {
3525     return saturate_;
3526 }
3527 
SetSepia(const std::optional<float> & sepia)3528 void RSProperties::SetSepia(const std::optional<float>& sepia)
3529 {
3530     sepia_ = sepia;
3531     colorFilterNeedUpdate_ = true;
3532     SetDirty();
3533     contentDirty_ = true;
3534 }
3535 
GetSepia() const3536 const std::optional<float>& RSProperties::GetSepia() const
3537 {
3538     return sepia_;
3539 }
3540 
SetInvert(const std::optional<float> & invert)3541 void RSProperties::SetInvert(const std::optional<float>& invert)
3542 {
3543     invert_ = invert;
3544     colorFilterNeedUpdate_ = true;
3545     SetDirty();
3546     contentDirty_ = true;
3547 }
3548 
GetInvert() const3549 const std::optional<float>& RSProperties::GetInvert() const
3550 {
3551     return invert_;
3552 }
3553 
3554 
SetAiInvert(const std::optional<Vector4f> & aiInvert)3555 void RSProperties::SetAiInvert(const std::optional<Vector4f>& aiInvert)
3556 {
3557     aiInvert_ = aiInvert;
3558     colorFilterNeedUpdate_ = true;
3559     SetDirty();
3560     contentDirty_ = true;
3561     isDrawn_ = true;
3562 }
3563 
GetAiInvert() const3564 const std::optional<Vector4f>& RSProperties::GetAiInvert() const
3565 {
3566     return aiInvert_;
3567 }
3568 
SetSystemBarEffect(bool systemBarEffect)3569 void RSProperties::SetSystemBarEffect(bool systemBarEffect)
3570 {
3571     systemBarEffect_ = systemBarEffect;
3572     colorFilterNeedUpdate_ = true;
3573     filterNeedUpdate_ = true;
3574     SetDirty();
3575     contentDirty_ = true;
3576     isDrawn_ = true;
3577 }
3578 
GetSystemBarEffect() const3579 bool RSProperties::GetSystemBarEffect() const
3580 {
3581     return systemBarEffect_;
3582 }
3583 
SetHueRotate(const std::optional<float> & hueRotate)3584 void RSProperties::SetHueRotate(const std::optional<float>& hueRotate)
3585 {
3586     hueRotate_ = hueRotate;
3587     colorFilterNeedUpdate_ = true;
3588     SetDirty();
3589     contentDirty_ = true;
3590 }
3591 
GetHueRotate() const3592 const std::optional<float>& RSProperties::GetHueRotate() const
3593 {
3594     return hueRotate_;
3595 }
3596 
SetColorBlend(const std::optional<Color> & colorBlend)3597 void RSProperties::SetColorBlend(const std::optional<Color>& colorBlend)
3598 {
3599     colorBlend_ = colorBlend;
3600     colorFilterNeedUpdate_ = true;
3601     SetDirty();
3602     contentDirty_ = true;
3603 }
3604 
GetColorBlend() const3605 const std::optional<Color>& RSProperties::GetColorBlend() const
3606 {
3607     return colorBlend_;
3608 }
3609 
GreatNotEqual(double left,double right)3610 static bool GreatNotEqual(double left, double right)
3611 {
3612     constexpr double epsilon = 0.001f;
3613     return (left - right) > epsilon;
3614 }
3615 
NearEqual(const double left,const double right)3616 static bool NearEqual(const double left, const double right)
3617 {
3618     constexpr double epsilon = 0.001f;
3619     return (std::abs(left - right) <= epsilon);
3620 }
3621 
GreatOrEqual(double left,double right)3622 static bool GreatOrEqual(double left, double right)
3623 {
3624     constexpr double epsilon = -0.001f;
3625     return (left - right) > epsilon;
3626 }
3627 
GetColorFilter() const3628 const std::shared_ptr<Drawing::ColorFilter>& RSProperties::GetColorFilter() const
3629 {
3630     return colorFilter_;
3631 }
3632 
GenerateColorFilter()3633 void RSProperties::GenerateColorFilter()
3634 {
3635     // No update needed if color filter is valid
3636     if (!colorFilterNeedUpdate_) {
3637         return;
3638     }
3639 
3640     colorFilterNeedUpdate_ = false;
3641     colorFilter_ = nullptr;
3642     if (!grayScale_ && !brightness_ && !contrast_ && !saturate_ && !sepia_ && !invert_ && !hueRotate_ && !colorBlend_) {
3643         return;
3644     }
3645 
3646     std::shared_ptr<Drawing::ColorFilter> filter = nullptr;
3647 
3648     if (grayScale_.has_value() && GreatNotEqual(*grayScale_, 0.f)) {
3649         auto grayScale = grayScale_.value();
3650         float matrix[20] = { 0.0f }; // 20 : matrix size
3651         matrix[0] = matrix[INDEX_5] = matrix[INDEX_10] = 0.2126f * grayScale; // 0.2126 : gray scale coefficient
3652         matrix[1] = matrix[INDEX_6] = matrix[INDEX_11] = 0.7152f * grayScale; // 0.7152 : gray scale coefficient
3653         matrix[INDEX_2] = matrix[INDEX_7] = matrix[INDEX_12] = 0.0722f * grayScale; // 0.0722 : gray scale coefficient
3654         matrix[INDEX_18] = 1.0 * grayScale;
3655         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3656         if (colorFilter_) {
3657             filter->Compose(*colorFilter_);
3658         }
3659         colorFilter_ = filter;
3660     }
3661     if (brightness_.has_value() && !NearEqual(*brightness_, 1.0)) {
3662         auto brightness = brightness_.value();
3663         float matrix[20] = { 0.0f }; // 20 : matrix size
3664         // shift brightness to (-1, 1)
3665         brightness = brightness - 1;
3666         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = matrix[INDEX_18] = 1.0f;
3667         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = brightness;
3668         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3669         if (colorFilter_) {
3670             filter->Compose(*colorFilter_);
3671         }
3672         colorFilter_ = filter;
3673     }
3674     if (contrast_.has_value() && !NearEqual(*contrast_, 1.0)) {
3675         auto contrast = contrast_.value();
3676         uint32_t contrastValue128 = 128;
3677         uint32_t contrastValue255 = 255;
3678         float matrix[20] = { 0.0f }; // 20 : matrix size
3679         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = contrast;
3680         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = contrastValue128 * (1 - contrast) / contrastValue255;
3681         matrix[INDEX_18] = 1.0f;
3682         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3683         if (colorFilter_) {
3684             filter->Compose(*colorFilter_);
3685         }
3686         colorFilter_ = filter;
3687     }
3688     if (saturate_.has_value() && !NearEqual(*saturate_, 1.0) && GreatOrEqual(*saturate_, 0.0)) {
3689         auto saturate = saturate_.value();
3690         float matrix[20] = { 0.0f }; // 20 : matrix size
3691         matrix[0] = 0.3086f * (1 - saturate) + saturate; // 0.3086 : saturate coefficient
3692         matrix[1] = matrix[INDEX_11] = 0.6094f * (1 - saturate); // 0.6094 : saturate coefficient
3693         matrix[INDEX_2] = matrix[INDEX_7] = 0.0820f * (1 - saturate); // 0.0820 : saturate coefficient
3694         matrix[INDEX_5] = matrix[INDEX_10] = 0.3086f * (1 - saturate); // 0.3086 : saturate coefficient
3695         matrix[INDEX_6] = 0.6094f * (1 - saturate) + saturate; // 0.6094 : saturate coefficient
3696         matrix[INDEX_12] = 0.0820f * (1 - saturate) + saturate; // 0.0820 : saturate coefficient
3697         matrix[INDEX_18] = 1.0f;
3698         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3699         if (colorFilter_) {
3700             filter->Compose(*colorFilter_);
3701         }
3702         colorFilter_ = filter;
3703     }
3704     if (sepia_.has_value() && GreatNotEqual(*sepia_, 0.0)) {
3705         auto sepia = sepia_.value();
3706         float matrix[20] = { 0.0f }; // 20 : matrix size
3707         matrix[0] = 0.393f * sepia;
3708         matrix[1] = 0.769f * sepia;
3709         matrix[INDEX_2] = 0.189f * sepia;
3710 
3711         matrix[INDEX_5] = 0.349f * sepia;
3712         matrix[INDEX_6] = 0.686f * sepia;
3713         matrix[INDEX_7] = 0.168f * sepia;
3714 
3715         matrix[INDEX_10] = 0.272f * sepia;
3716         matrix[INDEX_11] = 0.534f * sepia;
3717         matrix[INDEX_12] = 0.131f * sepia;
3718         matrix[INDEX_18] = 1.0f * sepia;
3719         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3720         if (colorFilter_) {
3721             filter->Compose(*colorFilter_);
3722         }
3723         colorFilter_ = filter;
3724     }
3725     if (invert_.has_value() && GreatNotEqual(*invert_, 0.0)) {
3726         auto invert = invert_.value();
3727         float matrix[20] = { 0.0f }; // 20 : matrix size
3728         if (invert > 1.0) {
3729             invert = 1.0;
3730         }
3731         // complete color invert when dstRGB = 1 - srcRGB
3732         // map (0, 1) to (1, -1)
3733         matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = 1.0 - 2.0 * invert; // 2.0: invert
3734         matrix[INDEX_18] = 1.0f;
3735         // invert = 0.5 -> RGB = (0.5, 0.5, 0.5) -> image completely gray
3736         matrix[INDEX_4] = matrix[INDEX_9] = matrix[INDEX_14] = invert;
3737         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3738         if (colorFilter_) {
3739             filter->Compose(*colorFilter_);
3740         }
3741         colorFilter_ = filter;
3742     }
3743     if (hueRotate_.has_value() && GreatNotEqual(*hueRotate_, 0.0)) {
3744         auto hueRotate = hueRotate_.value();
3745         while (GreatOrEqual(hueRotate, 360)) { // 360 : degree
3746             hueRotate -= 360; // 360 : degree
3747         }
3748         float matrix[20] = { 0.0f }; // 20 : matrix size
3749         int32_t type = hueRotate / 120; // 120 : degree
3750         float N = (hueRotate - 120 * type) / 120; // 120 : degree
3751         switch (type) {
3752             case 0:
3753                 // color change = R->G, G->B, B->R
3754                 matrix[INDEX_2] = matrix[INDEX_5] = matrix[INDEX_11] = N;
3755                 matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = 1 - N;
3756                 matrix[INDEX_18] = 1.0f;
3757                 break;
3758             case 1:
3759                 // compare to original: R->B, G->R, B->G
3760                 matrix[1] = matrix[INDEX_7] = matrix[INDEX_10] = N;
3761                 matrix[INDEX_2] = matrix[INDEX_5] = matrix[INDEX_11] = 1 - N;
3762                 matrix[INDEX_18] = 1.0f;
3763                 break;
3764             case 2: // 2: back to normal color
3765                 matrix[0] = matrix[INDEX_6] = matrix[INDEX_12] = N;
3766                 matrix[1] = matrix[INDEX_7] = matrix[INDEX_10] = 1 - N;
3767                 matrix[INDEX_18] = 1.0f;
3768                 break;
3769             default:
3770                 break;
3771         }
3772         filter = Drawing::ColorFilter::CreateFloatColorFilter(matrix, Drawing::Clamp::NO_CLAMP);
3773         if (colorFilter_) {
3774             filter->Compose(*colorFilter_);
3775         }
3776         colorFilter_ = filter;
3777     }
3778     if (colorBlend_.has_value() && *colorBlend_ != RgbPalette::Transparent()) {
3779         auto colorBlend = colorBlend_.value();
3780         filter = Drawing::ColorFilter::CreateBlendModeColorFilter(Drawing::Color::ColorQuadSetARGB(
3781             colorBlend.GetAlpha(), colorBlend.GetRed(), colorBlend.GetGreen(), colorBlend.GetBlue()),
3782             Drawing::BlendMode::PLUS);
3783         if (colorFilter_) {
3784             filter->Compose(*colorFilter_);
3785         }
3786         colorFilter_ = filter;
3787     }
3788     isDrawn_ = true;
3789 }
3790 
Dump() const3791 std::string RSProperties::Dump() const
3792 {
3793     std::string dumpInfo;
3794     char buffer[UINT8_MAX] = { 0 };
3795     if (sprintf_s(buffer, UINT8_MAX, "Bounds[%.1f %.1f %.1f %.1f] Frame[%.1f %.1f %.1f %.1f]",
3796         GetBoundsPositionX(), GetBoundsPositionY(), GetBoundsWidth(), GetBoundsHeight(),
3797         GetFramePositionX(), GetFramePositionY(), GetFrameWidth(), GetFrameHeight()) != -1) {
3798         dumpInfo.append(buffer);
3799     }
3800 
3801     errno_t ret;
3802     if (clipToBounds_) {
3803         // clipToBounds
3804         ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3805         if (ret != EOK) {
3806             return "Failed to memset_s for clipToBounds, ret=" + std::to_string(ret);
3807         }
3808         if (sprintf_s(buffer, UINT8_MAX, ", ClipToBounds[True]") != -1) {
3809             dumpInfo.append(buffer);
3810         }
3811     }
3812     if (clipToFrame_) {
3813         // clipToFrame
3814         ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3815         if (ret != EOK) {
3816             return "Failed to memset_s for clipToFrame, ret=" + std::to_string(ret);
3817         }
3818         if (sprintf_s(buffer, UINT8_MAX, ", ClipToFrame[True]") != -1) {
3819             dumpInfo.append(buffer);
3820         }
3821     }
3822 
3823     // PositionZ
3824     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3825     if (ret != EOK) {
3826         return "Failed to memset_s for PositionZ, ret=" + std::to_string(ret);
3827     }
3828     if (!ROSEN_EQ(GetPositionZ(), 0.f) &&
3829         sprintf_s(buffer, UINT8_MAX, ", PositionZ[%.1f]", GetPositionZ()) != -1) {
3830         dumpInfo.append(buffer);
3831     }
3832 
3833     // Pivot
3834     std::unique_ptr<RSTransform> defaultTrans = std::make_unique<RSTransform>();
3835     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3836     if (ret != EOK) {
3837         return "Failed to memset_s for Pivot, ret=" + std::to_string(ret);
3838     }
3839     Vector2f pivot = GetPivot();
3840     if ((!ROSEN_EQ(pivot[0], defaultTrans->pivotX_) || !ROSEN_EQ(pivot[1], defaultTrans->pivotY_)) &&
3841         sprintf_s(buffer, UINT8_MAX, ", Pivot[%.1f,%.1f]", pivot[0], pivot[1]) != -1) {
3842         dumpInfo.append(buffer);
3843     }
3844 
3845     // CornerRadius
3846     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3847     if (ret != EOK) {
3848         return "Failed to memset_s for CornerRadius, ret=" + std::to_string(ret);
3849     }
3850     if (!GetCornerRadius().IsZero() &&
3851         sprintf_s(buffer, UINT8_MAX, ", CornerRadius[%.1f %.1f %.1f %.1f]",
3852             GetCornerRadius().x_, GetCornerRadius().y_, GetCornerRadius().z_, GetCornerRadius().w_) != -1) {
3853         dumpInfo.append(buffer);
3854     }
3855 
3856     // PixelStretch PixelStretchPercent
3857     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3858     if (ret != EOK) {
3859         return "Failed to memset_s for PixelStretch, ret=" + std::to_string(ret);
3860     }
3861     if (pixelStretch_.has_value() &&
3862         sprintf_s(buffer, UINT8_MAX, ", PixelStretch[left:%.1f top:%.1f right:%.1f bottom:%.1f]",
3863             pixelStretch_->x_, pixelStretch_->y_, pixelStretch_->z_, pixelStretch_->w_) != -1) {
3864         dumpInfo.append(buffer);
3865     }
3866 
3867     // Rotation
3868     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3869     if (ret != EOK) {
3870         return "Failed to memset_s for Rotation, ret=" + std::to_string(ret);
3871     }
3872     if (!ROSEN_EQ(GetRotation(), defaultTrans->rotation_) &&
3873         sprintf_s(buffer, UINT8_MAX, ", Rotation[%.1f]", GetRotation()) != -1) {
3874         dumpInfo.append(buffer);
3875     }
3876     // RotationX
3877     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3878     if (ret != EOK) {
3879         return "Failed to memset_s for RotationX, ret=" + std::to_string(ret);
3880     }
3881     if (!ROSEN_EQ(GetRotationX(), defaultTrans->rotationX_) &&
3882         sprintf_s(buffer, UINT8_MAX, ", RotationX[%.1f]", GetRotationX()) != -1) {
3883         dumpInfo.append(buffer);
3884     }
3885     // RotationY
3886     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3887     if (ret != EOK) {
3888         return "Failed to memset_s for RotationY, ret=" + std::to_string(ret);
3889     }
3890     if (!ROSEN_EQ(GetRotationY(), defaultTrans->rotationY_) &&
3891         sprintf_s(buffer, UINT8_MAX, ", RotationY[%.1f]", GetRotationY()) != -1) {
3892         dumpInfo.append(buffer);
3893     }
3894 
3895     // TranslateX
3896     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3897     if (ret != EOK) {
3898         return "Failed to memset_s for TranslateX, ret=" + std::to_string(ret);
3899     }
3900     if (!ROSEN_EQ(GetTranslateX(), defaultTrans->translateX_) &&
3901         sprintf_s(buffer, UINT8_MAX, ", TranslateX[%.1f]", GetTranslateX()) != -1) {
3902         dumpInfo.append(buffer);
3903     }
3904 
3905     // TranslateY
3906     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3907     if (ret != EOK) {
3908         return "Failed to memset_s for TranslateY, ret=" + std::to_string(ret);
3909     }
3910     if (!ROSEN_EQ(GetTranslateY(), defaultTrans->translateY_) &&
3911         sprintf_s(buffer, UINT8_MAX, ", TranslateY[%.1f]", GetTranslateY()) != -1) {
3912         dumpInfo.append(buffer);
3913     }
3914 
3915     // TranslateZ
3916     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3917     if (ret != EOK) {
3918         return "Failed to memset_s for TranslateZ, ret=" + std::to_string(ret);
3919     }
3920     if (!ROSEN_EQ(GetTranslateZ(), defaultTrans->translateZ_) &&
3921         sprintf_s(buffer, UINT8_MAX, ", TranslateZ[%.1f]", GetTranslateZ()) != -1) {
3922         dumpInfo.append(buffer);
3923     }
3924 
3925     // ScaleX
3926     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3927     if (ret != EOK) {
3928         return "Failed to memset_s for ScaleX, ret=" + std::to_string(ret);
3929     }
3930     if (!ROSEN_EQ(GetScaleX(), defaultTrans->scaleX_) &&
3931         sprintf_s(buffer, UINT8_MAX, ", ScaleX[%.1f]", GetScaleX()) != -1) {
3932         dumpInfo.append(buffer);
3933     }
3934 
3935     // ScaleY
3936     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3937     if (ret != EOK) {
3938         return "Failed to memset_s for ScaleY, ret=" + std::to_string(ret);
3939     }
3940     if (!ROSEN_EQ(GetScaleY(), defaultTrans->scaleY_) &&
3941         sprintf_s(buffer, UINT8_MAX, ", ScaleY[%.1f]", GetScaleY()) != -1) {
3942         dumpInfo.append(buffer);
3943     }
3944 
3945     // Alpha
3946     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3947     if (ret != EOK) {
3948         return "Failed to memset_s for Alpha, ret=" + std::to_string(ret);
3949     }
3950     if (!ROSEN_EQ(GetAlpha(), 1.f) &&
3951         sprintf_s(buffer, UINT8_MAX, ", Alpha[%.3f]", GetAlpha()) != -1) {
3952         dumpInfo.append(buffer);
3953     }
3954 
3955     //NeedFilter
3956     if (NeedFilter()) {
3957         dumpInfo.append(", NeedFilter[true]");
3958     }
3959 
3960     // Spherize
3961     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3962     if (ret != EOK) {
3963         return "Failed to memset_s for Spherize, ret=" + std::to_string(ret);
3964     }
3965     if (!ROSEN_EQ(GetSpherize(), 0.f) &&
3966         sprintf_s(buffer, UINT8_MAX, ", Spherize[%.1f]", GetSpherize()) != -1) {
3967         dumpInfo.append(buffer);
3968     }
3969 
3970     // AttractFraction
3971     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3972     if (ret != EOK) {
3973         return "Failed to memset_s for AttractFraction, ret=" + std::to_string(ret);
3974     }
3975     if (!ROSEN_EQ(GetAttractionFraction(), 0.f) &&
3976         sprintf_s(buffer, UINT8_MAX, ", MiniFraction[%.1f]",  GetAttractionFraction()) != -1) {
3977         dumpInfo.append(buffer);
3978     }
3979 
3980     // Attraction Destination Position
3981     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3982     if (ret != EOK) {
3983         return "Failed to memset_s for MiniDstpoint, ret=" + std::to_string(ret);
3984     }
3985     Vector2f attractionDstpoint = GetAttractionDstPoint();
3986     if ((!ROSEN_EQ(attractionDstpoint[0], 0.f) || !ROSEN_EQ(attractionDstpoint[1], 0.f)) &&
3987         sprintf_s(buffer, UINT8_MAX, ", AttractionFraction DstPointY[%.1f,%.1f]",
3988         attractionDstpoint[0], attractionDstpoint[1]) != -1) {
3989         dumpInfo.append(buffer);
3990     }
3991 
3992     // blendmode
3993     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
3994     if (ret != EOK) {
3995         return "Failed to memset_s for blendmode, ret=" + std::to_string(ret);
3996     }
3997     if (!ROSEN_EQ(GetColorBlendMode(), 0) &&
3998         sprintf_s(buffer, UINT8_MAX, ", skblendmode[%d], blendType[%d]",
3999         GetColorBlendMode() - 1, GetColorBlendApplyType()) != -1) {
4000         dumpInfo.append(buffer);
4001     }
4002 
4003     // LightUpEffect
4004     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4005     if (ret != EOK) {
4006         return "Failed to memset_s for LightUpEffect, ret=" + std::to_string(ret);
4007     }
4008     if (!ROSEN_EQ(GetLightUpEffect(), 1.f) &&
4009         sprintf_s(buffer, UINT8_MAX, ", LightUpEffect[%.1f]", GetLightUpEffect()) != -1) {
4010         dumpInfo.append(buffer);
4011     }
4012 
4013     // ForegroundColor
4014     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4015     if (ret != EOK) {
4016         return "Failed to memset_s for ForegroundColor, ret=" + std::to_string(ret);
4017     }
4018     if (!ROSEN_EQ(GetForegroundColor(), RgbPalette::Transparent()) &&
4019         sprintf_s(buffer, UINT8_MAX, ", ForegroundColor[#%08X]", GetForegroundColor().AsArgbInt()) != -1) {
4020         dumpInfo.append(buffer);
4021     }
4022 
4023     // BackgroundColor
4024     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4025     if (ret != EOK) {
4026         return "Failed to memset_s for BackgroundColor, ret=" + std::to_string(ret);
4027     }
4028     if (!ROSEN_EQ(GetBackgroundColor(), RgbPalette::Transparent()) &&
4029         sprintf_s(buffer, UINT8_MAX, ", BackgroundColor[#%08X]", GetBackgroundColor().AsArgbInt()) != -1) {
4030         dumpInfo.append(buffer);
4031     }
4032 
4033     // BgImage
4034     std::unique_ptr<Decoration> defaultDecoration = std::make_unique<Decoration>();
4035     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4036     if (ret != EOK) {
4037         return "Failed to memset_s for BgImage, ret=" + std::to_string(ret);
4038     }
4039     if ((!ROSEN_EQ(GetBgImagePositionX(), defaultDecoration->bgImageRect_.left_) ||
4040         !ROSEN_EQ(GetBgImagePositionY(), defaultDecoration->bgImageRect_.top_) ||
4041         !ROSEN_EQ(GetBgImageWidth(), defaultDecoration->bgImageRect_.width_) ||
4042         !ROSEN_EQ(GetBgImageHeight(), defaultDecoration->bgImageRect_.height_)) &&
4043         sprintf_s(buffer, UINT8_MAX, ", BgImage[%.1f %.1f %.1f %.1f]", GetBgImagePositionX(),
4044             GetBgImagePositionY(), GetBgImageWidth(), GetBgImageHeight()) != -1) {
4045         dumpInfo.append(buffer);
4046     }
4047 
4048     // Border
4049     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4050     if (ret != EOK) {
4051         return "Failed to memset_s for Border, ret=" + std::to_string(ret);
4052     }
4053     if (border_ && border_->HasBorder() &&
4054         sprintf_s(buffer, UINT8_MAX, ", Border[%s]", border_->ToString().c_str()) != -1) {
4055         dumpInfo.append(buffer);
4056     }
4057 
4058     // Filter
4059     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4060     if (ret != EOK) {
4061         return "Failed to memset_s for Filter, ret=" + std::to_string(ret);
4062     }
4063     auto filter_ = GetFilter();
4064     if (filter_ && filter_->IsValid() &&
4065         sprintf_s(buffer, UINT8_MAX, ", Filter[%s]", filter_->GetDescription().c_str()) != -1) {
4066         dumpInfo.append(buffer);
4067     }
4068 
4069     // BackgroundFilter
4070     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4071     if (ret != EOK) {
4072         return "Failed to memset_s for BackgroundFilter, ret=" + std::to_string(ret);
4073     }
4074     auto backgroundFilter_ = GetBackgroundFilter();
4075     if (backgroundFilter_ && backgroundFilter_->IsValid() &&
4076         sprintf_s(buffer, UINT8_MAX, ", BackgroundFilter[%s]", backgroundFilter_->GetDescription().c_str()) != -1) {
4077         dumpInfo.append(buffer);
4078     }
4079 
4080     // ForegroundFilter
4081     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4082     if (ret != EOK) {
4083         return "Failed to memset_s for ForegroundFilter, ret=" + std::to_string(ret);
4084     }
4085     auto foregroundFilterCache_ = GetForegroundFilterCache();
4086     if (foregroundFilterCache_ && foregroundFilterCache_->IsValid() &&
4087         sprintf_s(buffer, UINT8_MAX, ", ForegroundFilter[%s]", foregroundFilterCache_->GetDescription().c_str()) !=
4088         -1) {
4089         dumpInfo.append(buffer);
4090     }
4091 
4092     // Outline
4093     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4094     if (ret != EOK) {
4095         return "Failed to memset_s for Outline, ret=" + std::to_string(ret);
4096     }
4097     if (outline_ && outline_->HasBorder() &&
4098         sprintf_s(buffer, UINT8_MAX, ", Outline[%s]", outline_->ToString().c_str()) != -1) {
4099         dumpInfo.append(buffer);
4100     }
4101 
4102     // ShadowColor
4103     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4104     if (ret != EOK) {
4105         return "Failed to memset_s for ShadowColor, ret=" + std::to_string(ret);
4106     }
4107     if (!ROSEN_EQ(GetShadowColor(), Color(DEFAULT_SPOT_COLOR)) &&
4108         sprintf_s(buffer, UINT8_MAX, ", ShadowColor[#%08X]", GetShadowColor().AsArgbInt()) != -1) {
4109         dumpInfo.append(buffer);
4110     }
4111 
4112     // ShadowOffsetX
4113     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4114     if (ret != EOK) {
4115         return "Failed to memset_s for ShadowOffsetX, ret=" + std::to_string(ret);
4116     }
4117     if (!ROSEN_EQ(GetShadowOffsetX(), DEFAULT_SHADOW_OFFSET_X) &&
4118         sprintf_s(buffer, UINT8_MAX, ", ShadowOffsetX[%.1f]", GetShadowOffsetX()) != -1) {
4119         dumpInfo.append(buffer);
4120     }
4121 
4122     // ShadowOffsetY
4123     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4124     if (ret != EOK) {
4125         return "Failed to memset_s for ShadowOffsetY, ret=" + std::to_string(ret);
4126     }
4127     if (!ROSEN_EQ(GetShadowOffsetY(), DEFAULT_SHADOW_OFFSET_Y) &&
4128         sprintf_s(buffer, UINT8_MAX, ", ShadowOffsetY[%.1f]", GetShadowOffsetY()) != -1) {
4129         dumpInfo.append(buffer);
4130     }
4131 
4132     // ShadowAlpha
4133     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4134     if (ret != EOK) {
4135         return "Failed to memset_s for ShadowAlpha, ret=" + std::to_string(ret);
4136     }
4137     if (!ROSEN_EQ(GetShadowAlpha(), 0.f) &&
4138         sprintf_s(buffer, UINT8_MAX, ", ShadowAlpha[%.1f]", GetShadowAlpha()) != -1) {
4139         dumpInfo.append(buffer);
4140     }
4141 
4142     // ShadowElevation
4143     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4144     if (ret != EOK) {
4145         return "Failed to memset_s for ShadowElevation, ret=" + std::to_string(ret);
4146     }
4147     if (!ROSEN_EQ(GetShadowElevation(), 0.f) &&
4148         sprintf_s(buffer, UINT8_MAX, ", ShadowElevation[%.1f]", GetShadowElevation()) != -1) {
4149         dumpInfo.append(buffer);
4150     }
4151 
4152     // ShadowRadius
4153     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4154     if (ret != EOK) {
4155         return "Failed to memset_s for ShadowRadius, ret=" + std::to_string(ret);
4156     }
4157     if (!ROSEN_EQ(GetShadowRadius(), 0.f) &&
4158         sprintf_s(buffer, UINT8_MAX, ", ShadowRadius[%.1f]", GetShadowRadius()) != -1) {
4159         dumpInfo.append(buffer);
4160     }
4161 
4162     // ShadowIsFilled
4163     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4164     if (ret != EOK) {
4165         return "Failed to memset_s for ShadowIsFilled, ret=" + std::to_string(ret);
4166     }
4167     if (!ROSEN_EQ(GetShadowIsFilled(), false) &&
4168         sprintf_s(buffer, UINT8_MAX, ", ShadowIsFilled[%d]", GetShadowIsFilled()) != -1) {
4169         dumpInfo.append(buffer);
4170     }
4171 
4172     // FrameGravity
4173     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4174     if (ret != EOK) {
4175         return "Failed to memset_s for FrameGravity, ret=" + std::to_string(ret);
4176     }
4177     if (!ROSEN_EQ(GetFrameGravity(), Gravity::DEFAULT) &&
4178         sprintf_s(buffer, UINT8_MAX, ", FrameGravity[%d]", GetFrameGravity()) != -1) {
4179         dumpInfo.append(buffer);
4180     }
4181 
4182     // IsVisible
4183     if (!GetVisible()) {
4184         dumpInfo.append(", IsVisible[false]");
4185     }
4186 
4187     // UseEffect
4188     if (GetUseEffect()) {
4189         dumpInfo.append(", GetUseEffect[true]");
4190     }
4191 
4192     // Gray Scale
4193     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4194     if (ret != EOK) {
4195         return "Failed to memset_s for GrayScale, ret=" + std::to_string(ret);
4196     }
4197     auto grayScale = GetGrayScale();
4198     if (grayScale.has_value() && !ROSEN_EQ(*grayScale, 0.f) &&
4199         sprintf_s(buffer, UINT8_MAX, ", GrayScale[%.1f]", *grayScale) != -1) {
4200         dumpInfo.append(buffer);
4201     }
4202 
4203     // DynamicLightUpRate
4204     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4205     if (ret != EOK) {
4206         return "Failed to memset_s for DynamicLightUpRate, ret=" + std::to_string(ret);
4207     }
4208     auto dynamicLightUpRate = GetDynamicLightUpRate();
4209     if (dynamicLightUpRate.has_value() && !ROSEN_EQ(*dynamicLightUpRate, 0.f) &&
4210         sprintf_s(buffer, UINT8_MAX, ", DynamicLightUpRate[%.1f]", *dynamicLightUpRate) != -1) {
4211         dumpInfo.append(buffer);
4212     }
4213 
4214     // DynamicLightUpDegree
4215     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4216     if (ret != EOK) {
4217         return "Failed to memset_s for DynamicLightUpDegree, ret=" + std::to_string(ret);
4218     }
4219     auto dynamicLightUpDegree = GetDynamicLightUpDegree();
4220     if (dynamicLightUpDegree.has_value() && !ROSEN_EQ(*dynamicLightUpDegree, 0.f) &&
4221         sprintf_s(buffer, UINT8_MAX, ", DynamicLightUpDegree[%.1f]", *dynamicLightUpDegree) != -1) {
4222         dumpInfo.append(buffer);
4223     }
4224 
4225     // Brightness
4226     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4227     if (ret != EOK) {
4228         return "Failed to memset_s for Brightness, ret=" + std::to_string(ret);
4229     }
4230     auto brightness = GetBrightness();
4231     if (brightness.has_value() && !ROSEN_EQ(*brightness, 1.f) &&
4232         sprintf_s(buffer, UINT8_MAX, ", Brightness[%.1f]", *brightness) != -1) {
4233         dumpInfo.append(buffer);
4234     }
4235 
4236     // Contrast
4237     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4238     if (ret != EOK) {
4239         return "Failed to memset_s for Contrast, ret=" + std::to_string(ret);
4240     }
4241     auto contrast = GetContrast();
4242     if (contrast.has_value() && !ROSEN_EQ(*contrast, 1.f) &&
4243         sprintf_s(buffer, UINT8_MAX, ", Contrast[%.1f]", *contrast) != -1) {
4244         dumpInfo.append(buffer);
4245     }
4246 
4247     // Saturate
4248     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4249     if (ret != EOK) {
4250         return "Failed to memset_s for Saturate, ret=" + std::to_string(ret);
4251     }
4252     auto saturate = GetSaturate();
4253     if (saturate.has_value() && !ROSEN_EQ(*saturate, 1.f) &&
4254         sprintf_s(buffer, UINT8_MAX, ", Saturate[%.1f]", *saturate) != -1) {
4255         dumpInfo.append(buffer);
4256     }
4257 
4258     // Sepia
4259     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4260     if (ret != EOK) {
4261         return "Failed to memset_s for Sepia, ret=" + std::to_string(ret);
4262     }
4263     auto sepia = GetSepia();
4264     if (sepia.has_value() && !ROSEN_EQ(*sepia, 0.f) &&
4265         sprintf_s(buffer, UINT8_MAX, ", Sepia[%.1f]", *sepia) != -1) {
4266         dumpInfo.append(buffer);
4267     }
4268 
4269     // Invert
4270     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4271     if (ret != EOK) {
4272         return "Failed to memset_s for Invert, ret=" + std::to_string(ret);
4273     }
4274     auto invert = GetInvert();
4275     if (invert.has_value() && !ROSEN_EQ(*invert, 0.f) &&
4276         sprintf_s(buffer, UINT8_MAX, ", Invert[%.1f]", *invert) != -1) {
4277         dumpInfo.append(buffer);
4278     }
4279 
4280     // Hue Rotate
4281     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4282     if (ret != EOK) {
4283         return "Failed to memset_s for HueRotate, ret=" + std::to_string(ret);
4284     }
4285     auto hueRotate = GetHueRotate();
4286     if (hueRotate.has_value() && !ROSEN_EQ(*hueRotate, 0.f) &&
4287         sprintf_s(buffer, UINT8_MAX, ", HueRotate[%.1f]", *hueRotate) != -1) {
4288         dumpInfo.append(buffer);
4289     }
4290 
4291     // Color Blend
4292     ret = memset_s(buffer, UINT8_MAX, 0, UINT8_MAX);
4293     if (ret != EOK) {
4294         return "Failed to memset_s for ColorBlend, ret=" + std::to_string(ret);
4295     }
4296     auto colorBlend = GetColorBlend();
4297     if (colorBlend.has_value() && !ROSEN_EQ(*colorBlend, RgbPalette::Transparent()) &&
4298         sprintf_s(buffer, UINT8_MAX, ", ColorBlend[#%08X]", colorBlend->AsArgbInt()) != -1) {
4299         dumpInfo.append(buffer);
4300     }
4301 
4302     return dumpInfo;
4303 }
4304 
4305 // planning: need to delete, cachemanager moved to filter drawable
4306 #if defined(NEW_SKIA) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
CreateFilterCacheManagerIfNeed()4307 void RSProperties::CreateFilterCacheManagerIfNeed()
4308 {
4309     if (!filterCacheEnabled_) {
4310         return;
4311     }
4312     if (auto& filter = GetBackgroundFilter()) {
4313         auto& cacheManager = backgroundFilterCacheManager_;
4314         if (cacheManager == nullptr) {
4315             cacheManager = std::make_unique<RSFilterCacheManager>();
4316         }
4317         cacheManager->UpdateCacheStateWithFilterHash(filter);
4318     } else {
4319         backgroundFilterCacheManager_.reset();
4320     }
4321     if (auto& filter = GetFilter()) {
4322         auto& cacheManager = foregroundFilterCacheManager_;
4323         if (cacheManager == nullptr) {
4324             cacheManager = std::make_unique<RSFilterCacheManager>();
4325         }
4326         cacheManager->UpdateCacheStateWithFilterHash(filter);
4327     } else {
4328         foregroundFilterCacheManager_.reset();
4329     }
4330 }
4331 
GetFilterCacheManager(bool isForeground) const4332 const std::unique_ptr<RSFilterCacheManager>& RSProperties::GetFilterCacheManager(bool isForeground) const
4333 {
4334     return isForeground ? foregroundFilterCacheManager_ : backgroundFilterCacheManager_;
4335 }
4336 
ClearFilterCache()4337 void RSProperties::ClearFilterCache()
4338 {
4339     if (foregroundFilterCacheManager_ != nullptr) {
4340         foregroundFilterCacheManager_->ReleaseCacheOffTree();
4341     }
4342     if (backgroundFilterCacheManager_ != nullptr) {
4343         backgroundFilterCacheManager_->ReleaseCacheOffTree();
4344     }
4345     if (backgroundFilter_ != nullptr) {
4346         auto drawingFilter = std::static_pointer_cast<RSDrawingFilter>(backgroundFilter_);
4347         std::shared_ptr<RSShaderFilter> rsShaderFilter =
4348             drawingFilter->GetShaderFilterWithType(RSShaderFilter::MASK_COLOR);
4349         if (rsShaderFilter != nullptr) {
4350             auto maskColorShaderFilter = std::static_pointer_cast<RSMaskColorShaderFilter>(rsShaderFilter);
4351         }
4352     }
4353     if (filter_ != nullptr) {
4354         auto drawingFilter = std::static_pointer_cast<RSDrawingFilter>(filter_);
4355         std::shared_ptr<RSShaderFilter> rsShaderFilter =
4356             drawingFilter->GetShaderFilterWithType(RSShaderFilter::MASK_COLOR);
4357         if (rsShaderFilter != nullptr) {
4358             auto maskColorShaderFilter = std::static_pointer_cast<RSMaskColorShaderFilter>(rsShaderFilter);
4359         }
4360     }
4361 }
4362 #endif
4363 
OnApplyModifiers()4364 void RSProperties::OnApplyModifiers()
4365 {
4366     if (geoDirty_) {
4367         if (!hasBounds_) {
4368             CheckEmptyBounds();
4369         } else {
4370             CalculateFrameOffset();
4371         }
4372         // frame and bounds are the same, no need to clip twice
4373         if (clipToFrame_ && clipToBounds_ && frameOffsetX_ == 0 && frameOffsetY_ == 0) {
4374             clipToFrame_ = false;
4375         }
4376         // planning: temporary fix to calculate relative matrix in OnApplyModifiers, later RSRenderNode::Update will
4377         // overwrite it.
4378         boundsGeo_->UpdateByMatrixFromSelf();
4379     }
4380     if (colorFilterNeedUpdate_) {
4381         GenerateColorFilter();
4382         if (colorFilter_ != nullptr) {
4383             needFilter_ = true;
4384         } else {
4385             // colorFilter generation failed, need to update needFilter
4386             filterNeedUpdate_ = true;
4387         }
4388     }
4389     if (pixelStretchNeedUpdate_ || geoDirty_) {
4390         CalculatePixelStretch();
4391     }
4392 
4393     if (bgShaderNeedUpdate_) {
4394         UpdateBackgroundShader();
4395     }
4396 
4397     if (greyCoefNeedUpdate_) {
4398         CheckGreyCoef();
4399         greyCoefNeedUpdate_ = false;
4400         filterNeedUpdate_ = true;
4401     }
4402     GenerateRRect();
4403     if (filterNeedUpdate_) {
4404         UpdateFilter();
4405     }
4406 }
4407 
UpdateFilter()4408 void RSProperties::UpdateFilter()
4409 {
4410     filterNeedUpdate_ = false;
4411     GenerateBackgroundFilter();
4412     GenerateForegroundFilter();
4413     if (GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE) {
4414         filterNeedUpdate_ = true;
4415     }
4416     if (backgroundFilter_ != nullptr && !backgroundFilter_->IsValid()) {
4417         backgroundFilter_.reset();
4418     }
4419     if (filter_ != nullptr && !filter_->IsValid()) {
4420         filter_.reset();
4421     }
4422 
4423     if (FOREGROUND_FILTER_ENABLED) {
4424         UpdateForegroundFilter();
4425     }
4426 
4427     needFilter_ = backgroundFilter_ != nullptr || filter_ != nullptr || useEffect_ || IsLightUpEffectValid() ||
4428                   IsDynamicLightUpValid() || greyCoef_.has_value() || linearGradientBlurPara_ != nullptr ||
4429                   IsDynamicDimValid() || GetShadowColorStrategy() != SHADOW_COLOR_STRATEGY::COLOR_STRATEGY_NONE ||
4430                   foregroundFilter_ != nullptr || IsFgBrightnessValid() || IsBgBrightnessValid() ||
4431                   foregroundFilterCache_ != nullptr || IsWaterRippleValid() || needDrawBehindWindow_ ||
4432                   mask_;
4433 }
4434 
UpdateForegroundFilter()4435 void RSProperties::UpdateForegroundFilter()
4436 {
4437     if (motionBlurPara_ && ROSEN_GNE(motionBlurPara_->radius, 0.0)) {
4438         auto motionBlurFilter = std::make_shared<RSMotionBlurFilter>(motionBlurPara_);
4439         if (IS_UNI_RENDER) {
4440             foregroundFilterCache_ = motionBlurFilter;
4441         } else {
4442             foregroundFilter_ = motionBlurFilter;
4443         }
4444     } else if (IsForegroundEffectRadiusValid()) {
4445         auto foregroundEffectFilter = std::make_shared<RSForegroundEffectFilter>(foregroundEffectRadius_);
4446         if (IS_UNI_RENDER) {
4447             foregroundFilterCache_ = foregroundEffectFilter;
4448         } else {
4449             foregroundFilter_ = foregroundEffectFilter;
4450         }
4451     } else if (IsSpherizeValid()) {
4452         CreateSphereEffectFilter();
4453     } else if (IsFlyOutValid()) {
4454         CreateFlyOutShaderFilter();
4455     } else if (IsAttractionValid()) {
4456         CreateAttractionEffectFilter();
4457     } else if (GetShadowMask()) {
4458         CreateColorfulShadowFilter();
4459     } else if (IsDistortionKValid()) {
4460         foregroundFilter_ = std::make_shared<RSDistortionFilter>(*distortionK_);
4461     } else {
4462         foregroundFilter_.reset();
4463         foregroundFilterCache_.reset();
4464     }
4465 }
4466 
UpdateBackgroundShader()4467 void RSProperties::UpdateBackgroundShader()
4468 {
4469     bgShaderNeedUpdate_ = false;
4470     const auto& bgShader = GetBackgroundShader();
4471     if (bgShader) {
4472         bgShader->MakeDrawingShader(GetBoundsRect(), GetBackgroundShaderProgress());
4473     }
4474 }
4475 
CalculatePixelStretch()4476 void RSProperties::CalculatePixelStretch()
4477 {
4478     pixelStretchNeedUpdate_ = false;
4479     // no pixel stretch
4480     if (!pixelStretch_.has_value() && !pixelStretchPercent_.has_value()) {
4481         return;
4482     }
4483     // convert pixel stretch percent to pixel stretch
4484     if (pixelStretchPercent_) {
4485         auto width = GetBoundsWidth();
4486         auto height = GetBoundsHeight();
4487         if (isinf(width) || isinf(height)) {
4488             return;
4489         }
4490         pixelStretch_ = *pixelStretchPercent_ * Vector4f(width, height, width, height);
4491     }
4492     constexpr static float EPS = 1e-5f;
4493     // parameter check: near zero
4494     if (abs(pixelStretch_->x_) < EPS && abs(pixelStretch_->y_) < EPS && abs(pixelStretch_->z_) < EPS &&
4495         abs(pixelStretch_->w_) < EPS) {
4496         pixelStretch_ = std::nullopt;
4497         return;
4498     }
4499     // parameter check: all >= 0 or all <= 0
4500     if ((pixelStretch_->x_ < EPS && pixelStretch_->y_ < EPS && pixelStretch_->z_ < EPS && pixelStretch_->w_ < EPS) ||
4501         (pixelStretch_->x_ > -EPS && pixelStretch_->y_ > -EPS && pixelStretch_->z_ > -EPS &&
4502             pixelStretch_->w_ > -EPS)) {
4503         isDrawn_ = true;
4504         return;
4505     }
4506     pixelStretch_ = std::nullopt;
4507 }
4508 
NeedBlurFuzed()4509 bool RSProperties::NeedBlurFuzed()
4510 {
4511     if (RSSystemProperties::GetMESABlurFuzedEnabled() && greyCoef_.has_value()) {
4512         return true;
4513     }
4514     return false;
4515 }
4516 
CalculateFrameOffset()4517 void RSProperties::CalculateFrameOffset()
4518 {
4519     frameOffsetX_ = frameGeo_.GetX() - boundsGeo_->GetX();
4520     frameOffsetY_ = frameGeo_.GetY() - boundsGeo_->GetY();
4521     if (isinf(frameOffsetX_)) {
4522         frameOffsetX_ = 0.;
4523     }
4524     if (isinf(frameOffsetY_)) {
4525         frameOffsetY_ = 0.;
4526     }
4527     if (frameOffsetX_ != 0. || frameOffsetY_ != 0.) {
4528         isDrawn_ = true;
4529     }
4530 }
4531 
CheckGreyCoef()4532 void RSProperties::CheckGreyCoef()
4533 {
4534     if (!greyCoef_.has_value()) {
4535         return;
4536     }
4537     // 127.0 half of 255.0
4538     if (ROSEN_LNE(greyCoef_->x_, 0.f) || ROSEN_GNE(greyCoef_->x_, 127.f) ||
4539         ROSEN_LNE(greyCoef_->y_, 0.f) || ROSEN_GNE(greyCoef_->y_, 127.f) ||
4540         (ROSEN_EQ(greyCoef_->x_, 0.f) && ROSEN_EQ(greyCoef_->y_, 0.f))) {
4541         greyCoef_ = std::nullopt;
4542     }
4543 }
4544 
4545 // blend with background
SetColorBlendMode(int colorBlendMode)4546 void RSProperties::SetColorBlendMode(int colorBlendMode)
4547 {
4548     colorBlendMode_ = std::clamp<int>(colorBlendMode, 0, static_cast<int>(RSColorBlendMode::MAX));
4549     if (colorBlendMode_ != static_cast<int>(RSColorBlendMode::NONE)) {
4550         isDrawn_ = true;
4551     }
4552     SetDirty();
4553     contentDirty_ = true;
4554 }
4555 
GetColorBlendMode() const4556 int RSProperties::GetColorBlendMode() const
4557 {
4558     return colorBlendMode_;
4559 }
4560 
IsColorBlendModeValid() const4561 bool RSProperties::IsColorBlendModeValid() const
4562 {
4563     return colorBlendMode_ != static_cast<int>(RSColorBlendMode::SRC_OVER) &&
4564            colorBlendMode_ != static_cast<int>(RSColorBlendMode::NONE);
4565 }
4566 
IsColorBlendModeNone() const4567 bool RSProperties::IsColorBlendModeNone() const
4568 {
4569     return colorBlendMode_ == static_cast<int>(RSColorBlendMode::NONE);
4570 }
4571 
SetColorBlendApplyType(int colorBlendApplyType)4572 void RSProperties::SetColorBlendApplyType(int colorBlendApplyType)
4573 {
4574     colorBlendApplyType_ = std::clamp<int>(colorBlendApplyType, 0, static_cast<int>(RSColorBlendApplyType::MAX));
4575     isDrawn_ = true;
4576     SetDirty();
4577     contentDirty_ = true;
4578 }
4579 
GetColorBlendApplyType() const4580 int RSProperties::GetColorBlendApplyType() const
4581 {
4582     return colorBlendApplyType_;
4583 }
4584 
IsColorBlendApplyTypeOffscreen() const4585 bool RSProperties::IsColorBlendApplyTypeOffscreen() const
4586 {
4587     return colorBlendApplyType_ != static_cast<int>(RSColorBlendApplyType::FAST);
4588 }
4589 
GetHaveEffectRegion() const4590 bool RSProperties::GetHaveEffectRegion() const
4591 {
4592     return haveEffectRegion_;
4593 }
4594 
SetHaveEffectRegion(bool haveEffectRegion)4595 void RSProperties::SetHaveEffectRegion(bool haveEffectRegion)
4596 {
4597 #if defined(NEW_SKIA) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
4598     // clear cache if new region is null or outside current region
4599     if (auto& manager = GetFilterCacheManager(false);
4600         manager && manager->IsCacheValid() && haveEffectRegion == false) {
4601         manager->UpdateCacheStateWithFilterRegion();
4602     }
4603 #endif
4604     haveEffectRegion_ = haveEffectRegion;
4605 }
4606 } // namespace Rosen
4607 } // namespace OHOS
4608