Merge "Reduce Render::Renderer size" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / decorated-visual-renderer-impl.h
1 #ifndef DALI_INTERNAL_DECORATED_VISUAL_RENDERER_H
2 #define DALI_INTERNAL_DECORATED_VISUAL_RENDERER_H
3
4 /*
5  * Copyright (c) 2022 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
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/rendering/visual-renderer-impl.h>  // Dali::Internal::VisualRenderer
23 #include <dali/public-api/rendering/decorated-visual-renderer.h> // Dali::DecoratedVisualRenderer
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace SceneGraph
30 {
31 class Renderer;
32 }
33
34 class DecoratedVisualRenderer;
35 using DecoratedVisualRendererPtr = IntrusivePtr<DecoratedVisualRenderer>;
36
37 /**
38  * DecoratedVisualRenderer is a VisualRenderer that has additional default properties for toolkit
39  */
40 class DecoratedVisualRenderer : public VisualRenderer
41 {
42 public:
43   /**
44    * Create a new DecoratedVisualRenderer.
45    * @return A smart-pointer to the newly allocated DecoratedVisualRenderer.
46    */
47   static DecoratedVisualRendererPtr New();
48
49 public: // Default property extensions from Object
50   /**
51    * @copydoc Dali::Internal::Object::SetDefaultProperty()
52    */
53   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
54
55   /**
56    * @copydoc Dali::Internal::Object::GetDefaultProperty()
57    */
58   Property::Value GetDefaultProperty(Property::Index index) const override;
59
60   /**
61    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
62    */
63   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
64
65   /**
66     * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
67     */
68   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
69
70   /**
71    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
72    */
73   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
74
75   /**
76    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
77    */
78   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
79
80 public:
81   /**
82    * @copydoc Dali::DecoratedVisualRenderer::RegisterCornerRadiusUniform()
83    */
84   void RegisterCornerRadiusUniform();
85
86   /**
87    * @copydoc Dali::DecoratedVisualRenderer::RegisterBorderlineUniform()
88    */
89   void RegisterBorderlineUniform();
90
91   /**
92    * @copydoc Dali::DecoratedVisualRenderer::RegisterBlurRadiusUniform()
93    */
94   void RegisterBlurRadiusUniform();
95
96 protected: // implementation
97   /**
98    * @brief Constructor.
99    *
100    * @param sceneObject the scene graph renderer
101    */
102   DecoratedVisualRenderer(const SceneGraph::Renderer* sceneObject);
103
104   /**
105    * @brief Retrieves the current value of a default property from the scene-graph.
106    * @param[in]  index  The index of the property
107    * @param[out] value  Is set with the current scene-graph value of the property
108    * @return True if value set, false otherwise.
109    */
110   bool GetCurrentPropertyValue(Property::Index index, Property::Value& value) const;
111
112   /**
113    * @brief Add the uniforms for DecoratedVisualRendererUseType.
114    * If that flag didn't appended yet, It will add the uniforms map
115    *
116    * @param[in] newFlag one of DecoratedVisualRendererUseType
117    */
118   void AddUniformFlag(uint8_t newAddFlag);
119
120 protected:
121   /**
122    * A reference counted object may only be deleted by calling Unreference()
123    */
124   ~DecoratedVisualRenderer() override;
125
126 private:
127   DecoratedVisualRenderer(const DecoratedVisualRenderer&) = delete;
128   DecoratedVisualRenderer& operator=(const DecoratedVisualRenderer&) = delete;
129
130 public:
131   enum DecoratedVisualRendererUseType
132   {
133     DECORATED_VISUAL_RENDERER_USE_CORNER_RADIUS = 1,
134     DECORATED_VISUAL_RENDERER_USE_BORDERLINE    = 2,
135     DECORATED_VISUAL_RENDERER_USE_BLUR_RADIUS   = 4,
136   };
137
138   struct DecoratedVisualPropertyCache
139   {
140     Vector4 mCornerRadius{Vector4::ZERO};
141     float   mCornerRadiusPolicy{1.0f};
142     float   mBorderlineWidth{0.0f};
143     Vector4 mBorderlineColor{Color::BLACK};
144     float   mBorderlineOffset{0.0f};
145     float   mBlurRadius{0.0f};
146   };
147
148 private:
149   DecoratedVisualPropertyCache mDecoratedPropertyCache;
150
151   uint8_t mAddUniformFlag : 4;
152 };
153
154 } // namespace Internal
155
156 // Helpers for public-api forwarding methods
157 inline Internal::DecoratedVisualRenderer& GetImplementation(Dali::DecoratedVisualRenderer& handle)
158 {
159   DALI_ASSERT_ALWAYS(handle && "DecoratedVisualRenderer handle is empty");
160
161   BaseObject& object = handle.GetBaseObject();
162
163   return static_cast<Internal::DecoratedVisualRenderer&>(object);
164 }
165
166 inline const Internal::DecoratedVisualRenderer& GetImplementation(const Dali::DecoratedVisualRenderer& handle)
167 {
168   DALI_ASSERT_ALWAYS(handle && "DecoratedVisualRenderer handle is empty");
169
170   const BaseObject& object = handle.GetBaseObject();
171
172   return static_cast<const Internal::DecoratedVisualRenderer&>(object);
173 }
174
175 } // namespace Dali
176
177 #endif // DALI_INTERNAL_DECORATED_VISUAL_RENDERER_H