Calculate VisualRenderer coefficient only if updated.
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-visual-renderer.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_VISUAL_RENDERER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_VISUAL_RENDERER_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <stdint.h> ///< For size_t
22
23 // INTERNAL INCLUDES
24 #include <dali/internal/update/nodes/node-helper.h> ///< For property wrapper macro
25 #include <dali/internal/update/rendering/scene-graph-visual-renderer-property.h>
26
27 namespace Dali::Internal::SceneGraph::VisualRenderer
28 {
29 struct AnimatableVisualProperties
30 {
31   AnimatableVisualProperties()
32   : mTransformOffset(Vector2::ZERO),
33     mTransformSize(Vector2::ONE),
34     mTransformOrigin(Vector2::ZERO),
35     mTransformAnchorPoint(Vector2::ZERO),
36     mTransformOffsetSizeMode(Vector4::ZERO),
37     mExtraSize(Vector2::ZERO),
38     mMixColor(Vector3::ONE),
39     mPreMultipliedAlpha(0.0f),
40     mExtendedPropertiesDeleteFunction(nullptr)
41   {
42   }
43
44   ~AnimatableVisualProperties()
45   {
46     if(mExtendedProperties && mExtendedPropertiesDeleteFunction)
47     {
48       mExtendedPropertiesDeleteFunction(mExtendedProperties);
49     }
50   }
51
52   /**
53    * @brief Cached coefficient value when we calculate visual transformed update size.
54    * It can reduce complexity of calculate the vertex position.
55    *
56    * Vector2 vertexPosition = (XA * aPosition + XB) * originalSize + (CA * aPosition + CB)
57    */
58   struct VisualTransformedUpdateSizeCoefficientCache : public VisualRendererCoefficientCacheBase
59   {
60     VisualTransformedUpdateSizeCoefficientCache()
61     : VisualRendererCoefficientCacheBase(),
62       coefXA(Vector2::ZERO),
63       coefXB(Vector2::ZERO),
64       coefCA(Vector2::ZERO),
65       coefCB(Vector2::ZERO)
66     {
67     }
68
69     ~VisualTransformedUpdateSizeCoefficientCache() override = default;
70
71     Vector2 coefXA;
72     Vector2 coefXB;
73     Vector2 coefCA;
74     Vector2 coefCB;
75   };
76
77 public: // Default properties
78   // Define a base offset for the following wrappers. The wrapper macros calculate offsets from the previous
79   // element such that each wrapper type generates a compile time offset to the CoefficientCache data.
80   BASE(VisualTransformedUpdateSizeCoefficientCache, mCoefficient); ///< Coefficient value to calculate visual transformed update size by VisualProperties more faster.
81
82   PROPERTY_WRAPPER(mCoefficient, VisualRendererProperty, Vector2, mTransformOffset);
83   PROPERTY_WRAPPER(mTransformOffset, VisualRendererProperty, Vector2, mTransformSize);
84   PROPERTY_WRAPPER(mTransformSize, VisualRendererProperty, Vector2, mTransformOrigin);
85   PROPERTY_WRAPPER(mTransformOrigin, VisualRendererProperty, Vector2, mTransformAnchorPoint);
86   PROPERTY_WRAPPER(mTransformAnchorPoint, VisualRendererProperty, Vector4, mTransformOffsetSizeMode);
87   PROPERTY_WRAPPER(mTransformOffsetSizeMode, VisualRendererProperty, Vector2, mExtraSize);
88
89   // Properties that don't give any effort to coefficient.
90   AnimatableProperty<Vector3> mMixColor;
91   AnimatableProperty<float>   mPreMultipliedAlpha;
92
93 public:                                                      // Extended properties
94   void* mExtendedProperties{nullptr};                        // Enable derived class to extend properties further
95   void (*mExtendedPropertiesDeleteFunction)(void*){nullptr}; // Derived class's custom delete functor
96 };
97
98 struct AnimatableDecoratedVisualProperties
99 {
100   AnimatableDecoratedVisualProperties()
101   : mBorderlineWidth(0.0f),
102     mBorderlineOffset(0.0f),
103     mBlurRadius(0.0f),
104     mBorderlineColor(Color::BLACK),
105     mCornerRadius(Vector4::ZERO),
106     mCornerRadiusPolicy(1.0f)
107   {
108   }
109   ~AnimatableDecoratedVisualProperties()
110   {
111   }
112
113   // Delete function of AnimatableDecoratedVisualProperties* converted as void*
114   static void DeleteFunction(void* data)
115   {
116     delete static_cast<AnimatableDecoratedVisualProperties*>(data);
117   }
118
119   /**
120    * @brief Cached coefficient value when we calculate visual transformed update size.
121    * It can reduce complexity of calculate the vertex position.
122    *
123    * Vector2 vertexPosition += Vector2(D, D) * aPosition
124    */
125   struct DecoratedVisualTransformedUpdateSizeCoefficientCache : public VisualRendererCoefficientCacheBase
126   {
127     DecoratedVisualTransformedUpdateSizeCoefficientCache()
128     : VisualRendererCoefficientCacheBase(),
129       coefD(0.0f)
130     {
131     }
132
133     ~DecoratedVisualTransformedUpdateSizeCoefficientCache() override = default;
134
135     float coefD;
136   };
137
138 public: // Default properties
139   // Define a base offset for the following wrappers. The wrapper macros calculate offsets from the previous
140   // element such that each wrapper type generates a compile time offset to the CoefficientCache data.
141   BASE(DecoratedVisualTransformedUpdateSizeCoefficientCache, mCoefficient); ///< Coefficient value to calculate visual transformed update size by VisualProperties more faster.
142
143   PROPERTY_WRAPPER(mCoefficient, VisualRendererProperty, float, mBorderlineWidth);
144   PROPERTY_WRAPPER(mBorderlineWidth, VisualRendererProperty, float, mBorderlineOffset);
145   PROPERTY_WRAPPER(mBorderlineOffset, VisualRendererProperty, float, mBlurRadius);
146
147   // Properties that don't give any effort to coefficient.
148   AnimatableProperty<Vector4> mBorderlineColor;
149   AnimatableProperty<Vector4> mCornerRadius;
150   AnimatableProperty<float>   mCornerRadiusPolicy;
151 };
152 } // namespace Dali::Internal::SceneGraph::VisualRenderer
153
154 #endif // DALI_INTERNAL_SCENE_GRAPH_VISUAL_RENDERER_H