• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_H
17 #define RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_H
18 
19 #include <bitset>
20 #include <optional>
21 #include <tuple>
22 #include <vector>
23 
24 #include "animation/rs_render_particle.h"
25 #include "animation/rs_particle_noise_field.h"
26 #include "common/rs_macros.h"
27 #include "common/rs_matrix3.h"
28 #include "common/rs_obj_abs_geometry.h"
29 #include "common/rs_vector4.h"
30 #include "effect/runtime_blender_builder.h"
31 #include "property/rs_properties_def.h"
32 #include "render/rs_border.h"
33 #include "render/rs_filter.h"
34 #include "render/rs_gradient_blur_para.h"
35 #include "render/rs_image.h"
36 #include "render/rs_magnifier_para.h"
37 #include "render/rs_mask.h"
38 #include "render/rs_motion_blur_filter.h"
39 #include "render/rs_particles_drawable.h"
40 #include "render/rs_path.h"
41 #include "render/rs_shader.h"
42 #include "render/rs_shadow.h"
43 #include "render/rs_attraction_effect_filter.h"
44 
45 #include "render/rs_filter_cache_manager.h"
46 
47 namespace OHOS {
48 namespace Rosen {
49 class RSRenderNode;
50 class RSObjAbsGeometry;
51 class RSNGRenderFilterBase;
52 namespace DrawableV2 {
53 class RSBackgroundImageDrawable;
54 class RSBackgroundFilterDrawable;
55 class RSShadowDrawable;
56 #ifdef RS_ENABLE_GPU
57 class RSFilterDrawable;
58 #endif
59 }
60 class RSB_EXPORT RSProperties final {
61 public:
62     RSProperties();
63     RSProperties(const RSProperties&) = delete;
64     RSProperties(const RSProperties&&) = delete;
65     RSProperties& operator=(const RSProperties&) = delete;
66     RSProperties& operator=(const RSProperties&&) = delete;
67     virtual ~RSProperties();
68 
69     // geometry properties
70     void SetBounds(Vector4f bounds);
71     void SetBoundsSize(Vector2f size);
72     void SetBoundsWidth(float width);
73     void SetBoundsHeight(float height);
74     void SetBoundsPosition(Vector2f position);
75     void SetBoundsPositionX(float positionX);
76     void SetBoundsPositionY(float positionY);
GetBounds()77     Vector4f GetBounds() const
78     {
79         return { boundsGeo_->GetX(), boundsGeo_->GetY(), boundsGeo_->GetWidth(), boundsGeo_->GetHeight() };
80     }
81     Vector2f GetBoundsSize() const;
GetBoundsWidth()82     float GetBoundsWidth() const
83     {
84         return boundsGeo_->GetWidth();
85     }
GetBoundsHeight()86     float GetBoundsHeight() const
87     {
88         return boundsGeo_->GetHeight();
89     }
90     Vector2f GetBoundsPosition() const;
91     float GetBoundsPositionX() const;
92     float GetBoundsPositionY() const;
93 
94     void SetFrame(Vector4f frame);
95     void SetFrameSize(Vector2f size);
96     void SetFrameWidth(float width);
97     void SetFrameHeight(float height);
98     void SetFramePosition(Vector2f position);
99     void SetFramePositionX(float positionX);
100     void SetFramePositionY(float positionY);
101     Vector4f GetFrame() const;
102     Vector2f GetFrameSize() const;
GetFrameWidth()103     float GetFrameWidth() const
104     {
105         return frameGeo_.GetWidth();
106     }
GetFrameHeight()107     float GetFrameHeight() const
108     {
109         return frameGeo_.GetHeight();
110     }
111     Vector2f GetFramePosition() const;
112     float GetFramePositionX() const;
113     float GetFramePositionY() const;
GetFrameOffsetX()114     float GetFrameOffsetX() const
115     {
116         return frameOffsetX_;
117     }
GetFrameOffsetY()118     float GetFrameOffsetY() const
119     {
120         return frameOffsetY_;
121     }
122 
123     void SetSandBox(const std::optional<Vector2f>& parentPosition);
GetSandBox()124     std::optional<Vector2f> GetSandBox() const
125     {
126         return sandbox_ ? sandbox_->position_ : std::nullopt;
127     }
128     void ResetSandBox();
129     void UpdateSandBoxMatrix(const std::optional<Drawing::Matrix>& rootMatrix);
130     std::optional<Drawing::Matrix> GetSandBoxMatrix() const;
131 
132     void SetPositionZ(float positionZ);
GetPositionZ()133     float GetPositionZ() const
134     {
135         return boundsGeo_->GetZ();
136     }
137     void SetPositionZApplicableCamera3D(bool isApplicable);
138     bool GetPositionZApplicableCamera3D() const;
139 
140     void SetPivot(Vector2f pivot);
141     void SetPivotX(float pivotX);
142     void SetPivotY(float pivotY);
143     void SetPivotZ(float pivotZ);
GetPivot()144     Vector2f GetPivot() const
145     {
146         return { boundsGeo_->GetPivotX(), boundsGeo_->GetPivotY() };
147     }
148     float GetPivotX() const;
149     float GetPivotY() const;
150     float GetPivotZ() const;
151 
152     void SetCornerRadius(const Vector4f& cornerRadius);
153     const Vector4f& GetCornerRadius() const;
154 
155     void SetQuaternion(Quaternion quaternion);
156     void SetRotation(float degree);
157     void SetRotationX(float degree);
158     void SetRotationY(float degree);
159     void SetCameraDistance(float cameraDistance);
GetQuaternion()160     Quaternion GetQuaternion() const
161     {
162         return boundsGeo_->GetQuaternion();
163     }
GetRotation()164     float GetRotation() const
165     {
166         return boundsGeo_->GetRotation();
167     }
GetRotationX()168     float GetRotationX() const
169     {
170         return boundsGeo_->GetRotationX();
171     }
GetRotationY()172     float GetRotationY() const
173     {
174         return boundsGeo_->GetRotationY();
175     }
176     float GetCameraDistance() const;
177 
178     void SetTranslate(Vector2f translate);
179     void SetTranslateX(float translate);
180     void SetTranslateY(float translate);
181     void SetTranslateZ(float translate);
GetTranslate()182     Vector2f GetTranslate() const
183     {
184         return Vector2f(GetTranslateX(), GetTranslateY());
185     }
GetTranslateX()186     float GetTranslateX() const
187     {
188         return boundsGeo_->GetTranslateX();
189     }
GetTranslateY()190     float GetTranslateY() const
191     {
192         return boundsGeo_->GetTranslateY();
193     }
GetTranslateZ()194     float GetTranslateZ() const
195     {
196         return boundsGeo_->GetTranslateZ();
197     }
198 
199     void SetScale(Vector2f scale);
200     void SetScaleX(float sx);
201     void SetScaleY(float sy);
202     void SetScaleZ(float sz);
GetScale()203     Vector2f GetScale() const
204     {
205         return { boundsGeo_->GetScaleX(), boundsGeo_->GetScaleY() };
206     }
GetScaleX()207     float GetScaleX() const
208     {
209         return boundsGeo_->GetScaleX();
210     }
GetScaleY()211     float GetScaleY() const
212     {
213         return boundsGeo_->GetScaleY();
214     }
GetScaleZ()215     float GetScaleZ() const
216     {
217         return boundsGeo_->GetScaleZ();
218     }
219 
220     void SetSkew(const Vector3f& skew);
221     void SetSkewX(float skewX);
222     void SetSkewY(float skewY);
223     void SetSkewZ(float skewZ);
GetSkew()224     Vector3f GetSkew() const
225     {
226         return { boundsGeo_->GetSkewX(), boundsGeo_->GetSkewY(), boundsGeo_->GetSkewZ() };
227     }
228     float GetSkewX() const;
229     float GetSkewY() const;
230     float GetSkewZ() const;
231 
232     void SetPersp(const Vector4f& persp);
233     void SetPerspX(float perspX);
234     void SetPerspY(float perspY);
235     void SetPerspZ(float perspZ);
236     void SetPerspW(float perspW);
GetPersp()237     Vector4f GetPersp() const
238     {
239         return { boundsGeo_->GetPerspX(), boundsGeo_->GetPerspY(), boundsGeo_->GetPerspZ(), boundsGeo_->GetPerspW() };
240     }
241     float GetPerspX() const;
242     float GetPerspY() const;
243     float GetPerspZ() const;
244     float GetPerspW() const;
245 
246     void SetAlpha(float alpha);
GetAlpha()247     float GetAlpha() const
248     {
249         return alpha_;
250     }
251     void SetAlphaOffscreen(bool alphaOffscreen);
252     bool GetAlphaOffscreen() const;
253 
254     void SetLocalMagnificationCap(bool localMagnificationCap);
255 
256     void SetSublayerTransform(const std::optional<Matrix3f>& sublayerTransform);
257     const std::optional<Matrix3f>& GetSublayerTransform() const;
258 
GetUseShadowBatching()259     inline bool GetUseShadowBatching() const
260     {
261         return useShadowBatching_;
262     }
263 
264     void SetUseShadowBatching(bool useShadowBatching);
GetNeedSkipShadow()265     inline bool GetNeedSkipShadow() const
266     {
267         return needSkipShadow_;
268     }
269 
SetNeedSkipShadow(bool needSkipShadow)270     inline void SetNeedSkipShadow(bool needSkipShadow)
271     {
272         needSkipShadow_ = needSkipShadow;
273     }
274 
GetNeedForceSubmit()275     inline bool GetNeedForceSubmit() const
276     {
277         return needForceSubmit_;
278     }
279 
280     void SetHDRBrightnessFactor(float factor);
GetHDRBrightnessFactor()281     float GetHDRBrightnessFactor() const
282     {
283         return hdrBrightnessFactor_;
284     }
285     void SetCanvasNodeHDRBrightnessFactor(float factor);
286     float GetCanvasNodeHDRBrightnessFactor() const;
287 
288     // particle properties
289     void SetParticles(const RSRenderParticleVector& particles);
290     const RSRenderParticleVector& GetParticles() const;
291 
292     // foreground properties
293     void SetForegroundColor(Color color);
294     Color GetForegroundColor() const;
295 
296     // background properties
297     void SetBackgroundColor(Color color);
GetBackgroundColor()298     const Color& GetBackgroundColor() const
299     {
300         return decoration_ ? decoration_->backgroundColor_ : RgbPalette::Transparent();
301     }
302     void SetBackgroundShader(const std::shared_ptr<RSShader>& shader);
303     std::shared_ptr<RSShader> GetBackgroundShader() const;
304     void SetBackgroundShaderProgress(const float& progress);
305     float GetBackgroundShaderProgress() const;
306 
307     void SetComplexShaderParam(const std::vector<float>& param);
308     std::optional<std::vector<float>> GetComplexShaderParam() const;
309 
310     void SetBgImage(const std::shared_ptr<RSImage>& image);
311     std::shared_ptr<RSImage> GetBgImage() const;
312     void SetBgImageInnerRect(const Vector4f& rect);
313     Vector4f GetBgImageInnerRect() const;
314     void SetBgImageDstRect(const Vector4f& rect);
315     const Vector4f GetBgImageDstRect();
316     const RectF& GetBgImageRect() const;
317     void SetBgImageWidth(float width);
318     void SetBgImageHeight(float height);
319     void SetBgImagePositionX(float positionX);
320     void SetBgImagePositionY(float positionY);
321     float GetBgImageWidth() const;
322     float GetBgImageHeight() const;
323     float GetBgImagePositionX() const;
324     float GetBgImagePositionY() const;
325 
326     // border properties
327     void SetBorderColor(Vector4<Color> color);
328     void SetBorderWidth(Vector4f width);
329     void SetBorderStyle(Vector4<uint32_t> style);
330     void SetBorderDashWidth(const Vector4f& dashWidth);
331     void SetBorderDashGap(const Vector4f& dashGap);
332     Vector4<Color> GetBorderColor() const;
333     Vector4f GetBorderWidth() const;
334     Vector4<uint32_t> GetBorderStyle() const;
335     Vector4f GetBorderDashWidth() const;
336     Vector4f GetBorderDashGap() const;
337     const std::shared_ptr<RSBorder>& GetBorder() const;
338     void SetOutlineColor(Vector4<Color> color);
339     void SetOutlineWidth(Vector4f width);
340     void SetOutlineStyle(Vector4<uint32_t> style);
341     void SetOutlineDashWidth(const Vector4f& dashWidth);
342     void SetOutlineDashGap(const Vector4f& dashGap);
343     void SetOutlineRadius(Vector4f radius);
344     Vector4<Color> GetOutlineColor() const;
345     Vector4f GetOutlineWidth() const;
346     Vector4<uint32_t> GetOutlineStyle() const;
347     Vector4f GetOutlineDashWidth() const;
348     Vector4f GetOutlineDashGap() const;
349     Vector4f GetOutlineRadius() const;
GetOutline()350     const std::shared_ptr<RSBorder>& GetOutline() const
351     {
352         return outline_;
353     }
354 
355     void SetForegroundEffectRadius(const float foregroundEffectRadius);
356     float GetForegroundEffectRadius() const;
357     bool IsForegroundEffectRadiusValid() const;
358     void SetForegroundEffectDirty(bool dirty);
359     bool GetForegroundEffectDirty() const;
360     void SetForegroundFilterCache(const std::shared_ptr<RSFilter>& foregroundFilterCache);
GetForegroundFilterCache()361     const std::shared_ptr<RSFilter>& GetForegroundFilterCache() const
362     {
363         return foregroundFilterCache_;
364     }
365 
366     // filter properties
367     void SetLinearGradientBlurPara(const std::shared_ptr<RSLinearGradientBlurPara>& para);
368     void SetEmitterUpdater(const std::vector<std::shared_ptr<EmitterUpdater>>& para);
369     void SetParticleNoiseFields(const std::shared_ptr<ParticleNoiseFields>& para);
370     void SetDynamicLightUpRate(const std::optional<float>& rate);
371     void SetDynamicLightUpDegree(const std::optional<float>& lightUpDegree);
372     void SetDynamicDimDegree(const std::optional<float>& DimDegree);
373 
374     void SetBackgroundNGFilter(const std::shared_ptr<RSNGRenderFilterBase>& renderFilter);
375     std::shared_ptr<RSNGRenderFilterBase> GetBackgroundNGFilter() const;
376 
377     void SetForegroundNGFilter(const std::shared_ptr<RSNGRenderFilterBase>& renderFilter);
378     std::shared_ptr<RSNGRenderFilterBase> GetForegroundNGFilter() const;
379     void SetBackgroundNGShader(const std::shared_ptr<RSNGRenderShaderBase>& renderShader);
380     std::shared_ptr<RSNGRenderShaderBase> GetBackgroundNGShader() const;
381     void SetForegroundShader(const std::shared_ptr<RSNGRenderShaderBase>& renderShader);
382     std::shared_ptr<RSNGRenderShaderBase> GetForegroundShader() const;
383 
384     void SetFgBrightnessRates(const Vector4f& rates);
385     Vector4f GetFgBrightnessRates() const;
386     void SetFgBrightnessSaturation(const float& saturation);
387     float GetFgBrightnessSaturation() const;
388     void SetFgBrightnessPosCoeff(const Vector4f& coeff);
389     Vector4f GetFgBrightnessPosCoeff() const;
390     void SetFgBrightnessNegCoeff(const Vector4f& coeff);
391     Vector4f GetFgBrightnessNegCoeff() const;
392     void SetFgBrightnessFract(const float& fraction);
393     float GetFgBrightnessFract() const;
394     void SetFgBrightnessHdr(const bool enableHdr);
395     bool GetFgBrightnessHdr() const;
396     void SetFgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params);
397     std::optional<RSDynamicBrightnessPara> GetFgBrightnessParams() const;
398     bool GetFgBrightnessEnableEDR() const;
399 
400     void SetShadowBlenderParams(const std::optional<RSShadowBlenderPara>& params);
401     std::optional<RSShadowBlenderPara> GetShadowBlenderParams() const;
402 
403     void SetWaterRippleParams(const std::optional<RSWaterRipplePara>& params);
404     std::optional<RSWaterRipplePara> GetWaterRippleParams() const;
405     void SetWaterRippleProgress(const float& progress);
406     float GetWaterRippleProgress() const;
407 
408     void SetFlyOutParams(const std::optional<RSFlyOutPara>& params);
409     std::optional<RSFlyOutPara> GetFlyOutParams() const;
410     void SetFlyOutDegree(const float& degree);
411     float GetFlyOutDegree() const;
412     void CreateFlyOutShaderFilter();
413 
414     void SetDistortionK(const std::optional<float>& distortionK);
GetDistortionK()415     const std::optional<float>& GetDistortionK() const
416     {
417         return distortionK_;
418     }
419 
420     void SetBgBrightnessRates(const Vector4f& rates);
421     Vector4f GetBgBrightnessRates() const;
422     void SetBgBrightnessSaturation(const float& saturation);
423     float GetBgBrightnessSaturation() const;
424     void SetBgBrightnessPosCoeff(const Vector4f& coeff);
425     Vector4f GetBgBrightnessPosCoeff() const;
426     void SetBgBrightnessNegCoeff(const Vector4f& coeff);
427     Vector4f GetBgBrightnessNegCoeff() const;
428     void SetBgBrightnessFract(const float& fraction);
429     float GetBgBrightnessFract() const;
430     void SetBgBrightnessParams(const std::optional<RSDynamicBrightnessPara>& params);
431     std::optional<RSDynamicBrightnessPara> GetBgBrightnessParams() const;
432 
433     void SetMotionBlurPara(const std::shared_ptr<MotionBlurParam>& para);
434     void SetMagnifierParams(const std::shared_ptr<RSMagnifierParams>& para);
GetBackgroundFilter()435     const std::shared_ptr<RSFilter>& GetBackgroundFilter() const
436     {
437         return backgroundFilter_;
438     }
439     const std::shared_ptr<RSLinearGradientBlurPara>& GetLinearGradientBlurPara() const;
440     const std::vector<std::shared_ptr<EmitterUpdater>>& GetEmitterUpdater() const;
441     const std::shared_ptr<ParticleNoiseFields>& GetParticleNoiseFields() const;
442     void IfLinearGradientBlurInvalid();
GetFilter()443     const std::shared_ptr<RSFilter>& GetFilter() const
444     {
445         return filter_;
446     }
447     const std::shared_ptr<MotionBlurParam>& GetMotionBlurPara() const;
448     const std::shared_ptr<RSMagnifierParams>& GetMagnifierPara() const;
449     bool NeedFilter() const;
450     bool NeedHwcFilter() const;
451     bool NeedSkipSubtreeParallel() const;
452     void SetGreyCoef(const std::optional<Vector2f>& greyCoef);
453     const std::optional<Vector2f>& GetGreyCoef() const;
GetForegroundFilter()454     const std::shared_ptr<RSFilter>& GetForegroundFilter() const
455     {
456         return foregroundFilter_;
457     }
458     void SetForegroundFilter(const std::shared_ptr<RSFilter>& foregroundFilter);
459 
460     void SetBackgroundBlurRadius(float backgroundBlurRadius);
461     float GetBackgroundBlurRadius() const;
462     bool IsBackgroundBlurRadiusValid() const;
463 
464     void SetBackgroundBlurSaturation(float backgroundBlurSaturation);
465     float GetBackgroundBlurSaturation() const;
466     bool IsBackgroundBlurSaturationValid() const;
467 
468     void SetBackgroundBlurBrightness(float backgroundBlurBrightness);
469     float GetBackgroundBlurBrightness() const;
470     bool IsBackgroundBlurBrightnessValid() const;
471 
472     void SetBackgroundBlurMaskColor(Color backgroundMaskColor);
473     const Color& GetBackgroundBlurMaskColor() const;
474     bool IsBackgroundBlurMaskColorValid() const;
475 
476     void SetBackgroundBlurColorMode(int backgroundColorMode);
477     int GetBackgroundBlurColorMode() const;
478 
479     void SetBackgroundBlurRadiusX(float backgroundBlurRadiusX);
480     float GetBackgroundBlurRadiusX() const;
481     bool IsBackgroundBlurRadiusXValid() const;
482 
483     void SetBackgroundBlurRadiusY(float backgroundBlurRadiusY);
484     float GetBackgroundBlurRadiusY() const;
485     bool IsBackgroundBlurRadiusYValid() const;
486 
487     void SetBgBlurDisableSystemAdaptation(bool disableSystemAdaptation);
488     bool GetBgBlurDisableSystemAdaptation() const;
489 
490     void SetAlwaysSnapshot(bool enable);
491     bool GetAlwaysSnapshot() const;
492 
493     void SetForegroundBlurRadius(float ForegroundBlurRadius);
494     float GetForegroundBlurRadius() const;
495     bool IsForegroundBlurRadiusValid() const;
496 
497     void SetForegroundBlurSaturation(float ForegroundBlurSaturation);
498     float GetForegroundBlurSaturation() const;
499     bool IsForegroundBlurSaturationValid() const;
500 
501     void SetForegroundBlurBrightness(float ForegroundBlurBrightness);
502     float GetForegroundBlurBrightness() const;
503     bool IsForegroundBlurBrightnessValid() const;
504 
505     void SetForegroundBlurMaskColor(Color ForegroundMaskColor);
506     const Color& GetForegroundBlurMaskColor() const;
507     bool IsForegroundBlurMaskColorValid() const;
508 
509     void SetForegroundBlurColorMode(int ForegroundColorMode);
510     int GetForegroundBlurColorMode() const;
511 
512     void SetForegroundBlurRadiusX(float foregroundBlurRadiusX);
513     float GetForegroundBlurRadiusX() const;
514     bool IsForegroundBlurRadiusXValid() const;
515 
516     void SetForegroundBlurRadiusY(float foregroundBlurRadiusY);
517     float GetForegroundBlurRadiusY() const;
518     bool IsForegroundBlurRadiusYValid() const;
519 
520     void SetFgBlurDisableSystemAdaptation(bool disableSystemAdaptation);
521     bool GetFgBlurDisableSystemAdaptation() const;
522 
523     bool IsBackgroundMaterialFilterValid() const;
524     bool IsForegroundMaterialFilterVaild() const;
525     bool IsBackgroundLightBlurFilterValid() const;
526     bool IsForegroundLightBlurFilterValid() const;
527 
528     // shadow properties
529     void SetShadowColor(Color color);
530     void SetShadowOffsetX(float offsetX);
531     void SetShadowOffsetY(float offsetY);
532     void SetShadowAlpha(float alpha);
533     void SetShadowElevation(float radius);
534     void SetShadowRadius(float radius);
535     void SetShadowPath(std::shared_ptr<RSPath> shadowPath);
536     void SetShadowMask(int shadowMask);
537     void SetShadowIsFilled(bool shadowIsFilled);
538     void SetShadowColorStrategy(int shadowColorStrategy);
539     const Color& GetShadowColor() const;
540     float GetShadowOffsetX() const;
541     float GetShadowOffsetY() const;
542     float GetShadowAlpha() const;
543     float GetShadowElevation() const;
544     float GetShadowRadius() const;
545     const std::optional<float>& GetDynamicLightUpRate() const;
546     const std::optional<float>& GetDynamicLightUpDegree() const;
547     const std::optional<float>& GetDynamicDimDegree() const;
548     std::shared_ptr<RSPath> GetShadowPath() const;
549     int GetShadowMask() const;
550     bool IsShadowMaskValid() const;
551     bool GetShadowIsFilled() const;
552     int GetShadowColorStrategy() const;
553     const std::optional<RSShadow>& GetShadow() const;
554     bool IsShadowValid() const;
555 
556     void SetFrameGravity(Gravity gravity);
GetFrameGravity()557     Gravity GetFrameGravity() const
558     {
559         return frameGravity_;
560     }
561 
562     void SetDrawRegion(const std::shared_ptr<RectF>& rect);
GetDrawRegion()563     std::shared_ptr<RectF> GetDrawRegion() const
564     {
565         return drawRegion_;
566     }
567 
568     void SetClipRRect(RRect clipRRect);
GetClipRRect()569     RRect GetClipRRect() const
570     {
571         return clipRRect_ ? *clipRRect_ : RRect();
572     }
GetClipToRRect()573     bool GetClipToRRect() const
574     {
575         return clipRRect_.has_value() && !clipRRect_->rect_.IsEmpty();
576     }
577     void SetClipBounds(const std::shared_ptr<RSPath>& path);
GetClipBounds()578     const std::shared_ptr<RSPath>& GetClipBounds() const
579     {
580         return clipPath_;
581     }
582     void SetClipToBounds(bool clipToBounds);
GetClipToBounds()583     bool GetClipToBounds() const
584     {
585         return clipToBounds_;
586     }
587     void SetClipToFrame(bool clipToFrame);
GetClipToFrame()588     bool GetClipToFrame() const
589     {
590         return clipToFrame_;
591     }
592     void SetVisible(bool visible);
GetVisible()593     bool GetVisible() const
594     {
595         return visible_;
596     }
597     std::string Dump() const;
598 
599     void SetMask(const std::shared_ptr<RSMask>& mask);
600     std::shared_ptr<RSMask> GetMask() const;
601 
602     // Pixel Stretch
603     void SetPixelStretch(const std::optional<Vector4f>& stretchSize);
GetPixelStretch()604     inline const std::optional<Vector4f>& GetPixelStretch() const
605     {
606         return pixelStretch_;
607     }
608 
609     void SetPixelStretchPercent(const std::optional<Vector4f>& stretchPercent);
GetPixelStretchPercent()610     inline const std::optional<Vector4f>& GetPixelStretchPercent() const
611     {
612         return pixelStretchPercent_;
613     }
614 
615     void SetPixelStretchTileMode(int stretchTileMode);
616     int GetPixelStretchTileMode() const;
617 
618     void SetAiInvert(const std::optional<Vector4f>& aiInvert);
619     const std::optional<Vector4f>& GetAiInvert() const;
620     void SetSystemBarEffect(bool systemBarEffect);
621     bool GetSystemBarEffect() const;
622     RectI GetPixelStretchDirtyRect() const;
623 
GetBoundsGeometry()624     const std::shared_ptr<RSObjAbsGeometry>& GetBoundsGeometry() const
625     {
626         return boundsGeo_;
627     }
628     const RSObjGeometry& GetFrameGeometry() const;
629     bool UpdateGeometry(const RSProperties* parent, bool dirtyFlag, const std::optional<Drawing::Point>& offset);
630     bool UpdateGeometryByParent(const Drawing::Matrix* parentMatrix, const std::optional<Drawing::Point>& offset);
631     RectF GetLocalBoundsAndFramesRect() const;
632     RectF GetBoundsRect() const;
633 
634     bool IsGeoDirty() const;
635     bool IsCurGeoDirty() const;
636     bool IsContentDirty() const;
637     bool IsSubTreeAllDirty() const;
638 
639     void SetSpherize(float spherizeDegree);
640     float GetSpherize() const;
641     bool IsSpherizeValid() const;
642     void CreateSphereEffectFilter();
643 
644     void SetHDRUIBrightness(float hdrUIBrightness);
645     float GetHDRUIBrightness() const;
646     bool IsHDRUIBrightnessValid() const;
647     void CreateHDRUIBrightnessFilter();
648 
IsAttractionValid()649     bool IsAttractionValid() const
650     {
651         return isAttractionValid_;
652     }
653     void SetAttractionFraction(float fraction);
654     void SetAttractionDstPoint(Vector2f dstPoint);
655     float GetAttractionFraction() const;
656     Vector2f GetAttractionDstPoint() const;
657     void CreateAttractionEffectFilter();
GetAttractionEffectCurrentDirtyRegion()658     RectI GetAttractionEffectCurrentDirtyRegion() const
659     {
660         return attractionEffectCurrentDirtyRegion_;
661     }
662     void SetLightUpEffect(float lightUpEffectDegree);
663     float GetLightUpEffect() const;
664     bool IsLightUpEffectValid() const;
665     bool IsDynamicLightUpValid() const;
666     bool IsDynamicDimValid() const;
IsFgBrightnessValid()667     bool IsFgBrightnessValid() const
668     {
669         return fgBrightnessParams_.has_value() && fgBrightnessParams_->IsValid();
670     }
671 
IsBgBrightnessValid()672     bool IsBgBrightnessValid() const
673     {
674         return bgBrightnessParams_.has_value() && bgBrightnessParams_->IsValid();
675     }
676     bool IsShadowBlenderValid() const;
677     bool IsWaterRippleValid() const;
678     bool IsFlyOutValid() const;
679     bool IsDistortionKValid() const;
680     void SetDistortionDirty(bool distortionEffectDirty);
681     bool GetDistortionDirty() const;
682     std::string GetFgBrightnessDescription() const;
683     std::string GetBgBrightnessDescription() const;
684     std::string GetShadowBlenderDescription() const;
685 
686     // Image effect properties
687     void SetGrayScale(const std::optional<float>& grayScale);
GetGrayScale()688     inline const std::optional<float>& GetGrayScale() const
689     {
690         return grayScale_;
691     }
692 
693     void SetBrightness(const std::optional<float>& brightness);
694     const std::optional<float>& GetBrightness() const;
695     void SetContrast(const std::optional<float>& contrast);
696     const std::optional<float>& GetContrast() const;
697     void SetSaturate(const std::optional<float>& saturate);
698     const std::optional<float>& GetSaturate() const;
699     void SetSepia(const std::optional<float>& sepia);
700     const std::optional<float>& GetSepia() const;
701     void SetInvert(const std::optional<float>& invert);
702     const std::optional<float>& GetInvert() const;
703     void SetHueRotate(const std::optional<float>& hueRotate);
704     const std::optional<float>& GetHueRotate() const;
705     void SetColorBlend(const std::optional<Color>& colorBlend);
706     const std::optional<Color>& GetColorBlend() const;
707 
GetColorFilter()708     const std::shared_ptr<Drawing::ColorFilter>& GetColorFilter() const
709     {
710         return colorFilter_;
711     }
712 
713     void SetLightIntensity(float lightIntensity);
714     void SetLightColor(Color lightColor);
715     void SetLightPosition(const Vector4f& lightPosition);
716     void SetIlluminatedBorderWidth(float illuminatedBorderWidth);
717     void SetIlluminatedType(int illuminatedType);
718     void SetBloom(float bloomIntensity);
719     float GetLightIntensity() const;
720     Color GetLightColor() const;
721     Vector4f GetLightPosition() const;
GetIlluminatedBorderWidth()722     inline float GetIlluminatedBorderWidth() const
723     {
724         return illuminatedPtr_ ? illuminatedPtr_->GetIlluminatedBorderWidth() : 0.f;
725     }
726 
727     int GetIlluminatedType() const;
GetBloom()728     inline float GetBloom() const
729     {
730         return illuminatedPtr_ ? illuminatedPtr_->GetBloomIntensity() : 0.f;
731     }
732 
733     void CalculateAbsLightPosition();
GetLightSource()734     inline const std::shared_ptr<RSLightSource>& GetLightSource() const
735     {
736         return lightSourcePtr_;
737     }
GetIlluminated()738     inline const std::shared_ptr<RSIlluminated>& GetIlluminated() const
739     {
740         return illuminatedPtr_;
741     }
742 
743     void SetUseEffect(bool useEffect);
744     bool GetUseEffect() const;
745     void SetUseEffectType(int useEffectType);
746     int GetUseEffectType() const;
747     void SetNeedDrawBehindWindow(bool needDrawBehindWindow);
GetNeedDrawBehindWindow()748     bool GetNeedDrawBehindWindow() const
749     {
750         return needDrawBehindWindow_;
751     }
752 
753     void SetColorBlendMode(int colorBlendMode);
GetColorBlendMode()754     int GetColorBlendMode() const
755     {
756         return colorBlendMode_;
757     }
IsColorBlendModeValid()758     bool IsColorBlendModeValid() const
759     {
760         return colorBlendMode_ != static_cast<int>(RSColorBlendMode::SRC_OVER) &&
761                colorBlendMode_ != static_cast<int>(RSColorBlendMode::NONE);
762     }
IsColorBlendModeNone()763     bool IsColorBlendModeNone() const
764     {
765         return colorBlendMode_ == static_cast<int>(RSColorBlendMode::NONE);
766     }
767 
768     void SetColorBlendApplyType(int colorBlendApplyType);
GetColorBlendApplyType()769     int GetColorBlendApplyType() const
770     {
771         return colorBlendApplyType_;
772     }
IsColorBlendApplyTypeOffscreen()773     bool IsColorBlendApplyTypeOffscreen() const
774     {
775         return colorBlendApplyType_ != static_cast<int>(RSColorBlendApplyType::FAST);
776     }
777 
778 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
779     const std::unique_ptr<RSFilterCacheManager>& GetFilterCacheManager(bool isForeground) const;
780     void ClearFilterCache();
781 #endif
782 
783     const RRect& GetRRect() const;
784     RRect GetInnerRRect() const;
785     RectF GetFrameRect() const;
786 
787     bool GetHaveEffectRegion() const;
788     void SetHaveEffectRegion(bool hasEffectRegion);
789 
790     void OnApplyModifiers();
791 
792     void ResetBorder(bool isOutline);
793 
794     static void SetFilterCacheEnabledByCCM(bool isCCMFilterCacheEnable);
795     static void SetBlurAdaptiveAdjustEnabledByCCM(bool isCCMBlurAdaptiveAdjustEnabled);
796 
797 private:
DecreasePrecision(float value)798     inline float DecreasePrecision(float value)
799     {
800         // preserve two digital precision when calculating hash, this can reuse filterCache as much as possible.
801         return 0.01 * round(value * 100);
802     }
803     void SetDirty();
804     void ResetDirty();
805     bool IsDirty() const;
806     void AccumulateDirtyStatus();
807     void RecordCurDirtyStatus();
808 
809     // generate filter
810     std::shared_ptr<RSFilter> GenerateLightBlurFilter(float radius);
811     std::shared_ptr<RSFilter> GenerateMaterialLightBlurFilter(
812         std::shared_ptr<Drawing::ColorFilter> colorFilter, uint32_t hash, float radius,
813         int colorMode, const RSColor& color);
814     void GenerateBackgroundFilter();
815     void GenerateForegroundFilter();
816     void GenerateBackgroundMaskFilter();
817     void GenerateBackgroundBlurFilter();
818     void GenerateForegroundBlurFilter();
819     void GenerateBackgroundMaterialBlurFilter();
820     void GenerateForegroundMaterialBlurFilter();
821     void GenerateBackgroundMaterialFuzedBlurFilter();
822     void GenerateCompositingMaterialFuzedBlurFilter();
823     std::shared_ptr<Drawing::ColorFilter> GetMaterialColorFilter(float sat, float brightness);
824     void GenerateAIBarFilter();
825     void GenerateAlwaysSnapshotFilter();
826     void GenerateWaterRippleFilter();
827     void GenerateLinearGradientBlurFilter();
828     void GenerateMagnifierFilter();
829     void ComposeNGRenderFilter(
830         std::shared_ptr<RSFilter>& originFilter, std::shared_ptr<RSNGRenderFilterBase> filter);
831 
832     bool NeedClip() const;
833     bool NeedBlurFuzed();
834     bool NeedLightBlur(bool disableSystemAdaptation);
835 
836     void GenerateRRect();
837     RectI GetDirtyRect() const;
838     // added for update dirty region dfx
839     RectI GetDirtyRect(RectI& drawRegion) const;
840 
841     bool isDirty_ = false;
842     bool geoDirty_ = false;
843     bool contentDirty_ = false;
844     bool subTreeAllDirty_ = false;
845     bool curIsDirty_ = false;
846     bool curGeoDirty_ = false;
847     bool curContentDirty_ = false;
848     bool curSubTreeAllDirty_ = false;
849     bool hasBounds_ = false;
850     bool isSpherizeValid_ = false;
851     bool clipToBounds_ = false;
852     bool clipToFrame_ = false;
853     // partial update
854     bool colorFilterNeedUpdate_ = false;
855     bool pixelStretchNeedUpdate_ = false;
856     bool bgShaderNeedUpdate_ = false;
857     bool filterNeedUpdate_ = false;
858     bool greyCoefNeedUpdate_ = false;
859     bool visible_ = true;
860     bool isDrawn_ = false;
861     bool foregroundEffectDirty_ = false;
862     bool needFilter_ = false;
863     bool needHwcFilter_ = false;
864     bool needForceSubmit_ = false;
865     bool useEffect_ = false;
866     bool needDrawBehindWindow_ = false;
867     bool alphaOffscreen_ = false;
868     std::optional<RRect> clipRRect_;
869     bool alphaNeedApply_ = false;
870     bool systemBarEffect_ = false;
871     bool useShadowBatching_ = false;
872     bool needSkipShadow_ = false;
873     bool distortionEffectDirty_ = false;
874     bool haveEffectRegion_ = false;
875     bool isAttractionValid_ = false;
876     bool bgBlurDisableSystemAdaptation = true;
877     bool fgBlurDisableSystemAdaptation = true;
878     bool alwaysSnapshot_ = false;
879     bool localMagnificationCap_ = false;
880     float hdrBrightnessFactor_ = 1.0f; // for displayNode
881     float canvasNodeHDRBrightnessFactor_ = 1.0f; // for canvasNode
882     float frameOffsetX_ = 0.f;
883     float frameOffsetY_ = 0.f;
884     float alpha_ = 1.f;
885     int useEffectType_ = 0;
886     Gravity frameGravity_ = Gravity::DEFAULT;
887     int colorBlendMode_ = 0;
888     int colorBlendApplyType_ = 0;
889     float waterRippleProgress_ = 0.0f;
890     float flyOutDegree_ = 0.0f;
891     float foregroundEffectRadius_ = 0.f;
892     float attractFraction_ = 0.f;
893     float spherizeDegree_ = 0.f;
894     float hdrUIBrightness_ = 1.0f;
895     float lightUpEffectDegree_ = 1.0f;
896     // filter property
897     float backgroundBlurRadius_ = 0.f;
898     float backgroundBlurSaturation_ = 1.f;
899     float backgroundBlurBrightness_ = 1.f;
900     int backgroundColorMode_ = BLUR_COLOR_MODE::DEFAULT;
901     float backgroundBlurRadiusX_ = 0.f;
902     float backgroundBlurRadiusY_ = 0.f;
903     float foregroundBlurRadius_ = 0.f;
904     float foregroundBlurSaturation_ = 1.f;
905     float foregroundBlurBrightness_ = 1.f;
906     int foregroundColorMode_ = BLUR_COLOR_MODE::DEFAULT;
907     float foregroundBlurRadiusX_ = 0.f;
908     float foregroundBlurRadiusY_ = 0.f;
909     int pixelStretchTileMode_ = 0;
910     std::shared_ptr<RSObjAbsGeometry> boundsGeo_;
911     std::shared_ptr<RSFilter> foregroundFilter_ = nullptr; // view content filter
912     std::shared_ptr<RSFilter> foregroundFilterCache_ = nullptr; // view content filter via cache
913     std::shared_ptr<RSNGRenderFilterBase> bgNGRenderFilter_ = nullptr;
914     std::shared_ptr<RSNGRenderFilterBase> fgNGRenderFilter_ = nullptr;
915     std::shared_ptr<RSNGRenderShaderBase> bgNGRenderShader_ = nullptr;
916     std::shared_ptr<RSNGRenderShaderBase> fgRenderShader_ = nullptr;
917     std::shared_ptr<RSFilter> backgroundFilter_ = nullptr;
918     std::shared_ptr<RSFilter> filter_ = nullptr;
919     std::shared_ptr<RectF> drawRegion_ = nullptr;
920     std::shared_ptr<RSLightSource> lightSourcePtr_ = nullptr;
921     std::shared_ptr<RSIlluminated> illuminatedPtr_ = nullptr;
922     std::shared_ptr<RSLinearGradientBlurPara> linearGradientBlurPara_ = nullptr;
923     std::shared_ptr<MotionBlurParam> motionBlurPara_ = nullptr;
924     std::shared_ptr<RSMagnifierParams> magnifierPara_ = nullptr;
925     std::shared_ptr<ParticleNoiseFields> particleNoiseFields_ = nullptr;
926     std::shared_ptr<RSBorder> border_ = nullptr;
927     std::shared_ptr<RSBorder> outline_ = nullptr;
928     std::shared_ptr<RSPath> clipPath_ = nullptr;
929     std::shared_ptr<RSMask> mask_ = nullptr;
930     std::shared_ptr<Drawing::ColorFilter> colorFilter_ = nullptr;
931     std::weak_ptr<RSRenderNode> backref_;
932     std::unique_ptr<Sandbox> sandbox_ = nullptr;
933     Vector2f attractDstPoint_ = {0.f, 0.f};
934     RectI attractionEffectCurrentDirtyRegion_ = {0, 0, 0, 0};
935     RRect rrect_ = RRect{};
936     RSObjGeometry frameGeo_;
937     std::optional<Vector4f> pixelStretch_;
938     std::optional<Vector4f> pixelStretchPercent_;
939     std::optional<Vector4f> cornerRadius_;
940     std::optional<RSShadow> shadow_;
941 
942     std::shared_ptr<Drawing::RuntimeEffect> shaderEffect_ = nullptr;
943     std::optional<std::vector<float>> complexShaderParam_;
944 
945     std::optional<RSWaterRipplePara> waterRippleParams_ = std::nullopt;
946     std::optional<RSFlyOutPara> flyOutParams_ = std::nullopt;
947     std::optional<float> distortionK_ = std::nullopt;
948     std::optional<RSDynamicBrightnessPara> fgBrightnessParams_;
949     std::optional<RSDynamicBrightnessPara> bgBrightnessParams_;
950     std::optional<RSShadowBlenderPara> shadowBlenderParams_;
951     std::vector<std::shared_ptr<EmitterUpdater>> emitterUpdater_;
952     std::optional<Decoration> decoration_;
953     std::optional<Matrix3f> sublayerTransform_;
954     Color backgroundMaskColor_ = RSColor();
955     Color foregroundMaskColor_ = RSColor();
956 
957     std::optional<Vector4f> aiInvert_;
958     std::optional<float> grayScale_;
959     std::optional<float> brightness_;
960     std::optional<float> contrast_;
961     std::optional<float> saturate_;
962     std::optional<float> sepia_;
963     std::optional<float> invert_;
964     std::optional<float> hueRotate_;
965     std::optional<float> dynamicLightUpRate_;
966     std::optional<float> dynamicLightUpDegree_;
967     std::optional<float> dynamicDimDegree_;
968     std::optional<Color> colorBlend_;
969     std::optional<RectI> lastRect_;
970     std::optional<Vector2f> greyCoef_;
971 
972     // OnApplyModifiers hooks
973     void CheckEmptyBounds();
974     void GenerateColorFilter();
975     void CalculatePixelStretch();
976     void CalculateFrameOffset();
977     void CheckGreyCoef();
978 
979     void UpdateFilter();
980     void UpdateForegroundFilter();
981     void UpdateBackgroundShader();
982 
983     Drawing::Matrix prevAbsMatrix_;
984     RSRenderParticleVector particles_;
985 
986 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
987     void CreateFilterCacheManagerIfNeed();
988     std::unique_ptr<RSFilterCacheManager> backgroundFilterCacheManager_;
989     std::unique_ptr<RSFilterCacheManager> foregroundFilterCacheManager_;
990     static bool filterCacheEnabled_;
991 #endif
992     static bool blurAdaptiveAdjustEnabled_;
993     static const bool IS_UNI_RENDER;
994     static const bool FOREGROUND_FILTER_ENABLED;
995 
996     friend class RSBackgroundImageDrawable;
997     friend class RSCanvasRenderNode;
998     friend class RSColorfulShadowDrawable;
999     friend class RSEffectDataGenerateDrawable;
1000     friend class RSModifierDrawable;
1001     friend class RSPropertiesPainter;
1002     friend class RSRenderNode;
1003     friend class RSEffectRenderNode;
1004     friend class RSPropertyDrawableUtils;
1005 
1006     friend class DrawableV2::RSBackgroundImageDrawable;
1007     friend class DrawableV2::RSBackgroundFilterDrawable;
1008     friend class DrawableV2::RSShadowDrawable;
1009 #ifdef RS_ENABLE_GPU
1010     friend class DrawableV2::RSFilterDrawable;
1011 #endif
1012 #ifdef RS_PROFILER_ENABLED
1013     friend class RSProfiler;
1014 #endif
1015 };
1016 } // namespace Rosen
1017 } // namespace OHOS
1018 
1019 #endif // RENDER_SERVICE_CLIENT_CORE_PROPERTY_RS_PROPERTIES_H
1020