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