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 #ifndef RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_H 17 #define RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_H 18 19 #ifdef USE_ROSEN_DRAWING 20 #include <bitset> 21 #endif 22 #include <optional> 23 #include <tuple> 24 #include <vector> 25 26 #include "animation/rs_render_particle.h" 27 #include "common/rs_macros.h" 28 #include "common/rs_matrix3.h" 29 #include "common/rs_vector4.h" 30 #include "modifier/rs_modifier_type.h" 31 #include "property/rs_properties_def.h" 32 #include "property/rs_color_picker_cache_task.h" 33 #include "render/rs_aibar_filter.h" 34 #include "render/rs_border.h" 35 #include "render/rs_filter.h" 36 #include "render/rs_gradient_blur_para.h" 37 #include "render/rs_image.h" 38 #include "render/rs_mask.h" 39 #include "render/rs_path.h" 40 #include "render/rs_shader.h" 41 #include "render/rs_shadow.h" 42 43 #include "property/rs_filter_cache_manager.h" 44 45 namespace OHOS { 46 namespace Rosen { 47 class RSRenderNode; 48 class RSObjAbsGeometry; 49 class RSB_EXPORT RSProperties final { 50 public: 51 RSProperties(); 52 RSProperties(const RSProperties&) = delete; 53 RSProperties(const RSProperties&&) = delete; 54 RSProperties& operator=(const RSProperties&) = delete; 55 RSProperties& operator=(const RSProperties&&) = delete; 56 virtual ~RSProperties(); 57 58 // geometry properties 59 void SetBounds(Vector4f bounds); 60 void SetBoundsSize(Vector2f size); 61 void SetBoundsWidth(float width); 62 void SetBoundsHeight(float height); 63 void SetBoundsPosition(Vector2f position); 64 void SetBoundsPositionX(float positionX); 65 void SetBoundsPositionY(float positionY); 66 Vector4f GetBounds() const; 67 Vector2f GetBoundsSize() const; 68 float GetBoundsWidth() const; 69 float GetBoundsHeight() const; 70 Vector2f GetBoundsPosition() const; 71 float GetBoundsPositionX() const; 72 float GetBoundsPositionY() const; 73 74 void SetFrame(Vector4f frame); 75 void SetFrameSize(Vector2f size); 76 void SetFrameWidth(float width); 77 void SetFrameHeight(float height); 78 void SetFramePosition(Vector2f position); 79 void SetFramePositionX(float positionX); 80 void SetFramePositionY(float positionY); 81 Vector4f GetFrame() const; 82 Vector2f GetFrameSize() const; 83 float GetFrameWidth() const; 84 float GetFrameHeight() const; 85 Vector2f GetFramePosition() const; 86 float GetFramePositionX() const; 87 float GetFramePositionY() const; 88 float GetFrameOffsetX() const; 89 float GetFrameOffsetY() const; 90 91 void SetSandBox(const std::optional<Vector2f>& parentPosition); 92 std::optional<Vector2f> GetSandBox() const; 93 void ResetSandBox(); 94 #ifndef USE_ROSEN_DRAWING 95 void UpdateSandBoxMatrix(const std::optional<SkMatrix>& rootMatrix); 96 std::optional<SkMatrix> GetSandBoxMatrix() const; 97 #else 98 void UpdateSandBoxMatrix(const std::optional<Drawing::Matrix>& rootMatrix); 99 std::optional<Drawing::Matrix> GetSandBoxMatrix() const; 100 #endif 101 102 void SetPositionZ(float positionZ); 103 float GetPositionZ() const; 104 105 void SetPivot(Vector2f pivot); 106 void SetPivotX(float pivotX); 107 void SetPivotY(float pivotY); 108 void SetPivotZ(float pivotZ); 109 Vector2f GetPivot() const; 110 float GetPivotX() const; 111 float GetPivotY() const; 112 float GetPivotZ() const; 113 114 void SetCornerRadius(const Vector4f& cornerRadius); 115 const Vector4f& GetCornerRadius() const; 116 117 void SetQuaternion(Quaternion quaternion); 118 void SetRotation(float degree); 119 void SetRotationX(float degree); 120 void SetRotationY(float degree); 121 void SetCameraDistance(float cameraDistance); 122 Quaternion GetQuaternion() const; 123 float GetRotation() const; 124 float GetRotationX() const; 125 float GetRotationY() const; 126 float GetCameraDistance() const; 127 128 void SetTranslate(Vector2f translate); 129 void SetTranslateX(float translate); 130 void SetTranslateY(float translate); 131 void SetTranslateZ(float translate); 132 Vector2f GetTranslate() const; 133 float GetTranslateX() const; 134 float GetTranslateY() const; 135 float GetTranslateZ() const; 136 137 void SetScale(Vector2f scale); 138 void SetScaleX(float sx); 139 void SetScaleY(float sy); 140 Vector2f GetScale() const; 141 float GetScaleX() const; 142 float GetScaleY() const; 143 144 void SetAlpha(float alpha); 145 float GetAlpha() const; 146 void SetAlphaOffscreen(bool alphaOffscreen); 147 bool GetAlphaOffscreen() const; 148 149 void SetSublayerTransform(const std::optional<Matrix3f>& sublayerTransform); 150 const std::optional<Matrix3f>& GetSublayerTransform() const; 151 152 bool GetUseShadowBatching() const; 153 void SetUseShadowBatching(bool useShadowBatching); 154 bool GetNeedSkipShadow() const; 155 void SetNeedSkipShadow(bool needSkipShadow); 156 157 // particle properties 158 void SetParticles(const RSRenderParticleVector& particles); 159 const RSRenderParticleVector& GetParticles() const; 160 161 // foreground properties 162 void SetForegroundColor(Color color); 163 Color GetForegroundColor() const; 164 165 // background properties 166 void SetBackgroundColor(Color color); 167 const Color& GetBackgroundColor() const; 168 void SetBackgroundShader(const std::shared_ptr<RSShader>& shader); 169 std::shared_ptr<RSShader> GetBackgroundShader() const; 170 void SetBgImage(const std::shared_ptr<RSImage>& image); 171 std::shared_ptr<RSImage> GetBgImage() const; 172 void SetBgImageWidth(float width); 173 void SetBgImageHeight(float height); 174 void SetBgImagePositionX(float positionX); 175 void SetBgImagePositionY(float positionY); 176 float GetBgImageWidth() const; 177 float GetBgImageHeight() const; 178 float GetBgImagePositionX() const; 179 float GetBgImagePositionY() const; 180 181 // border properties 182 void SetBorderColor(Vector4<Color> color); 183 void SetBorderWidth(Vector4f width); 184 void SetBorderStyle(Vector4<uint32_t> style); 185 Vector4<Color> GetBorderColor() const; 186 Vector4f GetBorderWidth() const; 187 Vector4<uint32_t> GetBorderStyle() const; 188 const std::shared_ptr<RSBorder>& GetBorder() const; 189 void SetOutlineColor(Vector4<Color> color); 190 void SetOutlineWidth(Vector4f width); 191 void SetOutlineStyle(Vector4<uint32_t> style); 192 void SetOutlineRadius(Vector4f radius); 193 Vector4<Color> GetOutlineColor() const; 194 Vector4f GetOutlineWidth() const; 195 Vector4<uint32_t> GetOutlineStyle() const; 196 Vector4f GetOutlineRadius() const; 197 const std::shared_ptr<RSBorder>& GetOutline() const; 198 199 // filter properties 200 void SetBackgroundFilter(const std::shared_ptr<RSFilter>& backgroundFilter); 201 void SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para); 202 void SetDynamicLightUpRate(const std::optional<float>& rate); 203 void SetDynamicLightUpDegree(const std::optional<float>& lightUpDegree); 204 void SetGreyCoef1(float greyCoef1); 205 void SetGreyCoef2(float greyCoef2); 206 void SetFilter(const std::shared_ptr<RSFilter>& filter); 207 const std::shared_ptr<RSFilter>& GetBackgroundFilter() const; 208 const std::shared_ptr<RSLinearGradientBlurPara>& GetLinearGradientBlurPara() const; 209 void IfLinearGradientBlurInvalid(); 210 const std::shared_ptr<RSFilter>& GetFilter() const; 211 bool NeedFilter() const; 212 float GetGreyCoef1() const; 213 float GetGreyCoef2() const; 214 bool IsGreyAdjustmentValid() const; 215 216 // shadow properties 217 void SetShadowColor(Color color); 218 void SetShadowOffsetX(float offsetX); 219 void SetShadowOffsetY(float offsetY); 220 void SetShadowAlpha(float alpha); 221 void SetShadowElevation(float radius); 222 void SetShadowRadius(float radius); 223 void SetShadowPath(std::shared_ptr<RSPath> shadowPath); 224 void SetShadowMask(bool shadowMask); 225 void SetShadowIsFilled(bool shadowIsFilled); 226 void SetShadowColorStrategy(int shadowColorStrategy); 227 const Color& GetShadowColor() const; 228 float GetShadowOffsetX() const; 229 float GetShadowOffsetY() const; 230 float GetShadowAlpha() const; 231 float GetShadowElevation() const; 232 float GetShadowRadius() const; 233 const std::optional<float>& GetDynamicLightUpRate() const; 234 const std::optional<float>& GetDynamicLightUpDegree() const; 235 std::shared_ptr<RSPath> GetShadowPath() const; 236 bool GetShadowMask() const; 237 bool GetShadowIsFilled() const; 238 int GetShadowColorStrategy() const; 239 const std::optional<RSShadow>& GetShadow() const; 240 bool IsShadowValid() const; 241 242 void SetFrameGravity(Gravity gravity); 243 Gravity GetFrameGravity() const; 244 245 void SetDrawRegion(const std::shared_ptr<RectF>& rect); 246 std::shared_ptr<RectF> GetDrawRegion() const; 247 248 void SetClipRRect(RRect clipRRect); 249 RRect GetClipRRect() const; 250 bool GetClipToRRect() const; 251 void SetClipBounds(const std::shared_ptr<RSPath>& path); 252 const std::shared_ptr<RSPath>& GetClipBounds() const; 253 void SetClipToBounds(bool clipToBounds); 254 bool GetClipToBounds() const; 255 void SetClipToFrame(bool clipToFrame); 256 bool GetClipToFrame() const; 257 258 void SetVisible(bool visible); 259 bool GetVisible() const; 260 std::string Dump() const; 261 262 void SetMask(const std::shared_ptr<RSMask>& mask); 263 std::shared_ptr<RSMask> GetMask() const; 264 265 // Pixel Stretch 266 void SetPixelStretch(const std::optional<Vector4f>& stretchSize); 267 const std::optional<Vector4f>& GetPixelStretch() const; 268 void SetPixelStretchPercent(const std::optional<Vector4f>& stretchPercent); 269 const std::optional<Vector4f>& GetPixelStretchPercent() const; 270 void SetAiInvert(const std::optional<Vector4f>& aiInvert); 271 const std::optional<Vector4f>& GetAiInvert() const; 272 void SetSystemBarEffect(bool systemBarEffect); 273 bool GetSystemBarEffect() const; 274 RectI GetPixelStretchDirtyRect() const; 275 276 const std::shared_ptr<RSObjAbsGeometry>& GetBoundsGeometry() const; 277 const std::shared_ptr<RSObjGeometry>& GetFrameGeometry() const; 278 #ifndef USE_ROSEN_DRAWING 279 bool UpdateGeometry(const RSProperties* parent, bool dirtyFlag, const std::optional<SkPoint>& offset, 280 const std::optional<SkRect>& clipRect); 281 #else 282 bool UpdateGeometry(const RSProperties* parent, bool dirtyFlag, const std::optional<Drawing::Point>& offset, 283 const std::optional<Drawing::Rect>& clipRect); 284 #endif 285 RectF GetBoundsRect() const; 286 287 bool IsGeoDirty() const; 288 bool IsContentDirty() const; 289 290 void SetSpherize(float spherizeDegree); 291 float GetSpherize() const; 292 bool IsSpherizeValid() const; 293 294 void SetLightUpEffect(float lightUpEffectDegree); 295 float GetLightUpEffect() const; 296 bool IsLightUpEffectValid() const; 297 bool IsDynamicLightUpValid() const; 298 299 // Image effect properties 300 void SetGrayScale(const std::optional<float>& grayScale); 301 const std::optional<float>& GetGrayScale() const; 302 void SetBrightness(const std::optional<float>& brightness); 303 const std::optional<float>& GetBrightness() const; 304 void SetContrast(const std::optional<float>& contrast); 305 const std::optional<float>& GetContrast() const; 306 void SetSaturate(const std::optional<float>& saturate); 307 const std::optional<float>& GetSaturate() const; 308 void SetSepia(const std::optional<float>& sepia); 309 const std::optional<float>& GetSepia() const; 310 void SetInvert(const std::optional<float>& invert); 311 const std::optional<float>& GetInvert() const; 312 void SetHueRotate(const std::optional<float>& hueRotate); 313 const std::optional<float>& GetHueRotate() const; 314 void SetColorBlend(const std::optional<Color>& colorBlend); 315 const std::optional<Color>& GetColorBlend() const; 316 317 #ifndef USE_ROSEN_DRAWING 318 const sk_sp<SkColorFilter>& GetColorFilter() const; 319 #else 320 const std::shared_ptr<Drawing::ColorFilter>& GetColorFilter() const; 321 #endif 322 323 void SetLightIntensity(float lightIntensity); 324 void SetLightPosition(const Vector4f& lightPosition); 325 void SetIlluminatedBorderWidth(float illuminatedBorderWidth); 326 void SetIlluminatedType(int illuminatedType); 327 void SetBloom(float bloomIntensity); 328 float GetLightIntensity() const; 329 Vector4f GetLightPosition() const; 330 float GetIlluminatedBorderWidth() const; 331 int GetIlluminatedType() const; 332 float GetBloom() const; 333 void CalculateAbsLightPosition(); 334 const std::shared_ptr<RSLightSource>& GetLightSource() const; 335 const std::shared_ptr<RSIlluminated>& GetIlluminated() const; 336 337 void SetUseEffect(bool useEffect); 338 bool GetUseEffect() const; 339 340 void SetColorBlendMode(int colorBlendMode); 341 int GetColorBlendMode() const; 342 void SetColorBlendApplyType(int colorBlendApplyType); 343 int GetColorBlendApplyType() const; 344 345 #if defined(NEW_SKIA) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)) 346 const std::unique_ptr<RSFilterCacheManager>& GetFilterCacheManager(bool isForeground) const; 347 const std::shared_ptr<RSColorPickerCacheTask>& GetColorPickerCacheTaskShadow() const; 348 void ReleaseColorPickerTaskShadow() const; 349 void ClearFilterCache(); 350 #endif 351 352 const RRect& GetRRect() const; 353 RRect GetInnerRRect() const; 354 RectF GetFrameRect() const; 355 356 bool GetHaveEffectRegion() const; 357 void SetHaveEffectRegion(bool hasEffectRegion); 358 359 void OnApplyModifiers(); 360 361 private: 362 #ifndef USE_ROSEN_DRAWING 363 void ResetProperty(const std::unordered_set<RSModifierType>& dirtyTypes); 364 #else 365 void ResetProperty(const std::bitset<static_cast<int>(RSModifierType::MAX_RS_MODIFIER_TYPE)>& dirtyTypes); 366 #endif 367 void SetDirty(); 368 void ResetDirty(); 369 bool IsDirty() const; 370 371 bool NeedClip() const; 372 373 const RectF& GetBgImageRect() const; 374 void GenerateRRect(); 375 RectI GetDirtyRect() const; 376 // added for update dirty region dfx 377 RectI GetDirtyRect(RectI& drawRegion) const; 378 379 bool visible_ = true; 380 bool clipToBounds_ = false; 381 bool clipToFrame_ = false; 382 bool isDirty_ = false; 383 bool geoDirty_ = false; 384 bool contentDirty_ = false; 385 bool isDrawn_ = false; 386 bool alphaNeedApply_ = false; 387 bool systemBarEffect_ = false; 388 389 bool hasBounds_ = false; 390 bool useEffect_ = false; 391 bool useShadowBatching_ = false; 392 bool needSkipShadow_ = false; 393 394 int colorBlendMode_ = 0; 395 int colorBlendApplyType_ = 0; 396 397 Gravity frameGravity_ = Gravity::DEFAULT; 398 399 std::shared_ptr<RectF> drawRegion_ = nullptr; 400 401 float alpha_ = 1.f; 402 bool alphaOffscreen_ = false; 403 404 std::shared_ptr<RSObjAbsGeometry> boundsGeo_; 405 std::shared_ptr<RSObjGeometry> frameGeo_; 406 407 std::shared_ptr<RSLightSource> lightSourcePtr_ = nullptr; 408 std::shared_ptr<RSIlluminated> illuminatedPtr_ = nullptr; 409 410 std::shared_ptr<RSFilter> backgroundFilter_ = nullptr; 411 std::shared_ptr<RSLinearGradientBlurPara> linearGradientBlurPara_ = nullptr; 412 std::shared_ptr<RSBorder> border_ = nullptr; 413 std::shared_ptr<RSBorder> outline_ = nullptr; 414 std::shared_ptr<RSPath> clipPath_ = nullptr; 415 std::optional<Vector4f> cornerRadius_; 416 std::optional<Decoration> decoration_; 417 std::shared_ptr<RSFilter> filter_ = nullptr; 418 std::shared_ptr<RSMask> mask_ = nullptr; 419 std::optional<RSShadow> shadow_; 420 std::optional<Matrix3f> sublayerTransform_; 421 float spherizeDegree_ = 0.f; 422 bool isSpherizeValid_ = false; 423 float lightUpEffectDegree_ = 1.0f; 424 425 std::weak_ptr<RSRenderNode> backref_; 426 427 std::optional<Vector4f> pixelStretch_; 428 std::optional<Vector4f> pixelStretchPercent_; 429 std::optional<Vector4f> aiInvert_; 430 std::optional<RRect> clipRRect_; 431 432 std::optional<float> grayScale_; 433 std::optional<float> brightness_; 434 std::optional<float> contrast_; 435 std::optional<float> saturate_; 436 std::optional<float> sepia_; 437 std::optional<float> invert_; 438 std::optional<float> hueRotate_; 439 std::optional<float> dynamicLightUpRate_; 440 std::optional<float> dynamicLightUpDegree_; 441 std::optional<Color> colorBlend_; 442 std::optional<RectI> lastRect_; 443 float greyCoef1_ = 0.f; 444 float greyCoef2_ = 0.f; 445 446 // OnApplyModifiers hooks 447 void CheckEmptyBounds(); 448 void GenerateColorFilter(); 449 void CalculatePixelStretch(); 450 void CalculateFrameOffset(); 451 452 // partial update 453 bool colorFilterNeedUpdate_ = false; 454 bool pixelStretchNeedUpdate_ = false; 455 bool filterNeedUpdate_ = false; 456 float frameOffsetX_ = 0.f; 457 float frameOffsetY_ = 0.f; 458 bool needFilter_ = false; 459 RRect rrect_ = RRect{}; 460 461 RSRenderParticleVector particles_; 462 #ifndef USE_ROSEN_DRAWING 463 sk_sp<SkColorFilter> colorFilter_ = nullptr; 464 #else 465 std::shared_ptr<Drawing::ColorFilter> colorFilter_ = nullptr; 466 #endif 467 bool haveEffectRegion_ = false; 468 469 #if defined(NEW_SKIA) && (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)) 470 void CreateFilterCacheManagerIfNeed(); 471 void CreateColorPickerTaskForShadow(); 472 std::unique_ptr<RSFilterCacheManager> backgroundFilterCacheManager_; 473 std::unique_ptr<RSFilterCacheManager> foregroundFilterCacheManager_; 474 static const bool FilterCacheEnabled; 475 #endif 476 477 std::unique_ptr<Sandbox> sandbox_ = nullptr; 478 std::shared_ptr<RSColorPickerCacheTask> colorPickerTaskShadow_ = nullptr; 479 480 friend class RSBackgroundImageDrawable; 481 friend class RSCanvasRenderNode; 482 friend class RSColorfulShadowDrawable; 483 friend class RSEffectDataGenerateDrawable; 484 friend class RSModifierDrawable; 485 friend class RSPropertiesPainter; 486 friend class RSRenderNode; 487 }; 488 } // namespace Rosen 489 } // namespace OHOS 490 491 #endif // RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_H 492