Move VisualRenderer properties definition in SceneGraph side.
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / visual-renderer-impl.h
1 #ifndef DALI_INTERNAL_VISUAL_RENDERER_H
2 #define DALI_INTERNAL_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/renderer-impl.h> // Dali::Internal::Renderer
23 #include <dali/public-api/rendering/visual-renderer.h>   // Dali::VisualRenderer
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace SceneGraph
30 {
31 class Renderer;
32 }
33
34 class VisualRenderer;
35 using VisualRendererPtr = IntrusivePtr<VisualRenderer>;
36
37 /**
38  * VisualRenderer is a Renderer that has additional default properties for toolkit
39  */
40 class VisualRenderer : public Renderer
41 {
42 public:
43   /**
44    * Create a new VisualRenderer.
45    * @return A smart-pointer to the newly allocated VisualRenderer.
46    */
47   static VisualRendererPtr New();
48
49   /**
50    * @brief Get the scene graph object
51    *
52    * @return the scene object
53    */
54   const SceneGraph::Renderer& GetVisualRendererSceneObject() const;
55
56 public: // Default property extensions from Object
57   /**
58    * @copydoc Dali::Internal::Object::SetDefaultProperty()
59    */
60   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
61
62   /**
63    * @copydoc Dali::Internal::Object::GetDefaultProperty()
64    */
65   Property::Value GetDefaultProperty(Property::Index index) const override;
66
67   /**
68    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
69    */
70   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
71
72   /**
73     * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
74     */
75   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
76
77   /**
78    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
79    */
80   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
81
82   /**
83    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
84    */
85   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
86
87 protected: // implementation
88   /**
89    * @brief Constructor.
90    *
91    * @param sceneObject the scene graph renderer
92    */
93   VisualRenderer(const SceneGraph::Renderer* sceneObject);
94
95   /**
96    * @brief Retrieves the current value of a default property from the scene-graph.
97    * @param[in]  index  The index of the property
98    * @param[out] value  Is set with the current scene-graph value of the property
99    * @return True if value set, false otherwise.
100    */
101   bool GetCurrentPropertyValue(Property::Index index, Property::Value& value) const;
102
103   /**
104    * @brief Ensure that properties are mapped to uniforms
105    */
106   void AddUniformMappings();
107
108 protected:
109   /**
110    * A reference counted object may only be deleted by calling Unreference()
111    */
112   ~VisualRenderer() override;
113
114 private:
115   VisualRenderer(const VisualRenderer&) = delete;
116   VisualRenderer& operator=(const VisualRenderer&) = delete;
117
118 public:
119   struct VisualPropertyCache
120   {
121     Vector2 mTransformOffset{Vector2::ZERO};
122     Vector2 mTransformSize{Vector2::ONE};
123     Vector2 mTransformOrigin{Vector2::ZERO};
124     Vector2 mTransformAnchorPoint{Vector2::ZERO};
125     Vector4 mTransformOffsetSizeMode{Vector2::ZERO};
126     Vector2 mExtraSize{Vector2::ZERO};
127     Vector3 mMixColor{Vector3::ONE};
128     float   mPreMultipliedAlpha{0.0f};
129   };
130
131 private:
132   VisualPropertyCache mPropertyCache;
133 };
134
135 } // namespace Internal
136
137 // Helpers for public-api forwarding methods
138 inline Internal::VisualRenderer& GetImplementation(Dali::VisualRenderer& handle)
139 {
140   DALI_ASSERT_ALWAYS(handle && "VisualRenderer handle is empty");
141
142   BaseObject& object = handle.GetBaseObject();
143
144   return static_cast<Internal::VisualRenderer&>(object);
145 }
146
147 inline const Internal::VisualRenderer& GetImplementation(const Dali::VisualRenderer& handle)
148 {
149   DALI_ASSERT_ALWAYS(handle && "VisualRenderer handle is empty");
150
151   const BaseObject& object = handle.GetBaseObject();
152
153   return static_cast<const Internal::VisualRenderer&>(object);
154 }
155
156 } // namespace Dali
157
158 #endif // DALI_INTERNAL_VISUAL_RENDERER_H