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