Move visual renderer updateArea calculation code
[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 public: // Public API
53   /**
54    * @copydoc Dali::Internal::SceneGraph::Renderer::ResetToBaseValues
55    */
56   void ResetToBaseValues(BufferIndex updateBufferIndex);
57
58   /**
59    * @copydoc Dali::Internal::SceneGraph::Renderer::MarkAsDirty
60    */
61   void MarkAsDirty();
62
63   /**
64    * @copydoc RenderDataProvider::GetVisualTransformedUpdateArea()
65    */
66   Vector4 GetVisualTransformedUpdateArea(BufferIndex updateBufferIndex, const Vector4& originalUpdateArea) noexcept;
67
68 public:
69   /**
70    * @brief Cached coefficient value when we calculate visual transformed update size.
71    * It can reduce complexity of calculate the vertex position.
72    *
73    * Vector2 vertexPosition = (XA * aPosition + XB) * originalSize + (CA * aPosition + CB)
74    */
75   struct VisualTransformedUpdateSizeCoefficientCache : public VisualRendererCoefficientCacheBase
76   {
77     VisualTransformedUpdateSizeCoefficientCache()
78     : VisualRendererCoefficientCacheBase(),
79       coefXA(Vector2::ZERO),
80       coefXB(Vector2::ZERO),
81       coefCA(Vector2::ZERO),
82       coefCB(Vector2::ZERO)
83     {
84     }
85
86     ~VisualTransformedUpdateSizeCoefficientCache() override = default;
87
88     Vector2 coefXA;
89     Vector2 coefXB;
90     Vector2 coefCA;
91     Vector2 coefCB;
92   };
93
94 public: // Default properties
95   // Define a base offset for the following wrappers. The wrapper macros calculate offsets from the previous
96   // element such that each wrapper type generates a compile time offset to the CoefficientCache data.
97   BASE(VisualTransformedUpdateSizeCoefficientCache, mCoefficient); ///< Coefficient value to calculate visual transformed update size by VisualProperties more faster.
98
99   PROPERTY_WRAPPER(mCoefficient, VisualRendererProperty, Vector2, mTransformOffset);
100   PROPERTY_WRAPPER(mTransformOffset, VisualRendererProperty, Vector2, mTransformSize);
101   PROPERTY_WRAPPER(mTransformSize, VisualRendererProperty, Vector2, mTransformOrigin);
102   PROPERTY_WRAPPER(mTransformOrigin, VisualRendererProperty, Vector2, mTransformAnchorPoint);
103   PROPERTY_WRAPPER(mTransformAnchorPoint, VisualRendererProperty, Vector4, mTransformOffsetSizeMode);
104   PROPERTY_WRAPPER(mTransformOffsetSizeMode, VisualRendererProperty, Vector2, mExtraSize);
105
106   // Properties that don't give any effort to coefficient.
107   AnimatableProperty<Vector3> mMixColor;
108   AnimatableProperty<float>   mPreMultipliedAlpha;
109
110 public:                                                      // Extended properties
111   void* mExtendedProperties{nullptr};                        // Enable derived class to extend properties further
112   void (*mExtendedPropertiesDeleteFunction)(void*){nullptr}; // Derived class's custom delete functor
113 };
114
115 struct AnimatableDecoratedVisualProperties
116 {
117   AnimatableDecoratedVisualProperties()
118   : mBorderlineWidth(0.0f),
119     mBorderlineOffset(0.0f),
120     mBlurRadius(0.0f),
121     mBorderlineColor(Color::BLACK),
122     mCornerRadius(Vector4::ZERO),
123     mCornerRadiusPolicy(1.0f)
124   {
125   }
126   ~AnimatableDecoratedVisualProperties()
127   {
128   }
129
130 public: // Public API
131   // Delete function of AnimatableDecoratedVisualProperties* converted as void*
132   static void DeleteFunction(void* data)
133   {
134     delete static_cast<AnimatableDecoratedVisualProperties*>(data);
135   }
136
137   /**
138    * @copydoc Dali::Internal::SceneGraph::Renderer::ResetToBaseValues
139    */
140   void ResetToBaseValues(BufferIndex updateBufferIndex);
141
142   /**
143    * @copydoc Dali::Internal::SceneGraph::Renderer::MarkAsDirty
144    */
145   void MarkAsDirty();
146
147 public:
148   /**
149    * @brief Cached coefficient value when we calculate visual transformed update size.
150    * It can reduce complexity of calculate the vertex position.
151    *
152    * Vector2 vertexPosition += Vector2(D, D) * aPosition
153    */
154   struct DecoratedVisualTransformedUpdateSizeCoefficientCache : public VisualRendererCoefficientCacheBase
155   {
156     DecoratedVisualTransformedUpdateSizeCoefficientCache()
157     : VisualRendererCoefficientCacheBase(),
158       coefD(0.0f)
159     {
160     }
161
162     ~DecoratedVisualTransformedUpdateSizeCoefficientCache() override = default;
163
164     float coefD;
165   };
166
167 public: // Default properties
168   // Define a base offset for the following wrappers. The wrapper macros calculate offsets from the previous
169   // element such that each wrapper type generates a compile time offset to the CoefficientCache data.
170   BASE(DecoratedVisualTransformedUpdateSizeCoefficientCache, mCoefficient); ///< Coefficient value to calculate visual transformed update size by VisualProperties more faster.
171
172   PROPERTY_WRAPPER(mCoefficient, VisualRendererProperty, float, mBorderlineWidth);
173   PROPERTY_WRAPPER(mBorderlineWidth, VisualRendererProperty, float, mBorderlineOffset);
174   PROPERTY_WRAPPER(mBorderlineOffset, VisualRendererProperty, float, mBlurRadius);
175
176   // Properties that don't give any effort to coefficient.
177   AnimatableProperty<Vector4> mBorderlineColor;
178   AnimatableProperty<Vector4> mCornerRadius;
179   AnimatableProperty<float>   mCornerRadiusPolicy;
180 };
181 } // namespace Dali::Internal::SceneGraph::VisualRenderer
182
183 #endif // DALI_INTERNAL_SCENE_GRAPH_VISUAL_RENDERER_H