Allow multiple renderers per Actor and sharing renderers between actors
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / renderer-impl.h
1 #ifndef DALI_INTERNAL_RENDERER_H
2 #define DALI_INTERNAL_RENDERER_H
3
4 /*
5  * Copyright (c) 2015 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/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
25 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
26 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
27 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
28 #include <dali/internal/event/rendering/material-impl.h> // Dali::Internal::Material
29 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
30 #include <dali/internal/update/nodes/node.h>
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace SceneGraph
37 {
38 class Renderer;
39 }
40
41
42 class Renderer;
43 typedef IntrusivePtr<Renderer> RendererPtr;
44
45 /**
46  * Renderer is an object that can be used to show content by combining a Geometry with a material.
47  */
48 class Renderer : public Object
49 {
50 public:
51
52   /**
53    * Create a new Renderer.
54    * @return A smart-pointer to the newly allocated Renderer.
55    */
56   static RendererPtr New();
57
58   /**
59    * @copydoc Dali::Renderer::SetGeometry()
60    */
61   void SetGeometry( Geometry& geometry );
62
63   /**
64    * @copydoc Dali::Renderer::GetGeometry()
65    */
66   Geometry* GetGeometry() const;
67
68   /**
69    * @copydoc Dali::Renderer::SetMaterial()
70    */
71   void SetMaterial( Material& material );
72
73   /**
74    * @copydoc Dali::Renderer::GetMaterial()
75    */
76   Material* GetMaterial() const;
77
78   /**
79    * @copydoc Dali::Renderer::SetDepthIndex()
80    */
81   void SetDepthIndex( int depthIndex );
82
83   /**
84    * @copydoc Dali::Renderer::GetDepthIndex()
85    */
86   int GetDepthIndex() const;
87
88   /**
89    * @brief Get the scene graph object ( the node attachment )
90    *
91    * @return the scene object
92    */
93   SceneGraph::Renderer* GetRendererSceneObject();
94
95 public: // Default property extensions from Object
96
97   /**
98    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
99    */
100   virtual unsigned int GetDefaultPropertyCount() const;
101
102   /**
103    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
104    */
105   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
106
107   /**
108    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
109    */
110   virtual const char* GetDefaultPropertyName(Property::Index index) const;
111
112   /**
113    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
114    */
115   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
116
117   /**
118    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
119    */
120   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
121
122   /**
123    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
124    */
125   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
126
127   /**
128    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
129    */
130   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
131
132   /**
133    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
134    */
135   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
136
137   /**
138    * @copydoc Dali::Internal::Object::SetDefaultProperty()
139    */
140   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
141
142   /**
143    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
144    */
145   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
146
147   /**
148    * @copydoc Dali::Internal::Object::GetDefaultProperty()
149    */
150   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
151
152   /**
153    * @copydoc Dali::Internal::Object::GetPropertyOwner()
154    */
155   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
156
157   /**
158    * @copydoc Dali::Internal::Object::GetSceneObject()
159    */
160   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
161
162   /**
163    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
164    */
165   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
166
167   /**
168    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
169    */
170   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
171
172   /**
173    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
174    */
175   virtual int GetPropertyComponentIndex( Property::Index index ) const;
176
177 public: // Functions from Connectable
178   /**
179    * @copydoc Dali::Internal::Connectable::OnStage()
180    */
181   virtual bool OnStage() const;
182
183   /**
184    * @copydoc Dali::Internal::Connectable::Connect()
185    */
186   virtual void Connect();
187
188   /**
189    * @copydoc Dali::Internal::Connectable::Disconnect()
190    */
191   virtual void Disconnect();
192
193 private: // implementation
194   Renderer();
195
196   void Initialize();
197
198 protected:
199   /**
200    * A reference counted object may only be deleted by calling Unreference()
201    */
202   virtual ~Renderer();
203
204 private: // unimplemented methods
205   Renderer( const Renderer& );
206   Renderer& operator=( const Renderer& );
207
208 private: // data
209   SceneGraph::Renderer* mSceneObject;
210   ObjectConnector<Geometry> mGeometryConnector; ///< Connector that holds the geometry used by this renderer
211   ObjectConnector<Material> mMaterialConnector; ///< Connector that holds the material used by this renderer
212   int mDepthIndex;
213   bool mOnStage;
214 };
215
216 } // namespace Internal
217
218 // Helpers for public-api forwarding methods
219 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
220 {
221   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
222
223   BaseObject& object = handle.GetBaseObject();
224
225   return static_cast<Internal::Renderer&>(object);
226 }
227
228 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
229 {
230   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
231
232   const BaseObject& object = handle.GetBaseObject();
233
234   return static_cast<const Internal::Renderer&>(object);
235 }
236
237 } // namespace Dali
238
239 #endif // DALI_INTERNAL_RENDERER_H