Merge branch 'devel/master' into tizen
[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/common/blending-options.h>
26 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
27 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
28 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
29 #include <dali/internal/event/rendering/material-impl.h> // Dali::Internal::Material
30 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
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     * @copydoc Dali::Renderer::SetFaceCullingMode()
90     */
91    void SetFaceCullingMode( Dali::Renderer::FaceCullingMode cullingMode );
92
93    /**
94     * @copydoc Dali::Renderer::GetFaceCullingMode()
95     */
96    Dali::Renderer::FaceCullingMode GetFaceCullingMode();
97
98    /**
99     * @copydoc Dali::Renderer::SetBlendMode()
100     */
101    void SetBlendMode( BlendingMode::Type mode );
102
103    /**
104     * @copydoc Dali::Renderer::GetBlendMode()
105     */
106    BlendingMode::Type GetBlendMode() const;
107
108    /**
109     * @copydoc Dali::Renderer::SetBlendFunc()
110     */
111    void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
112
113    /**
114     * @copydoc Dali::Renderer::SetBlendFunc()
115     */
116    void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
117                       BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
118
119    /**
120     * @copydoc Dali::Renderer::GetBlendFunc()
121     */
122    void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
123                       BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
124
125    /**
126     * @copydoc Dali::Renderer::SetBlendEquation()
127     */
128    void SetBlendEquation( BlendingEquation::Type equationRgba );
129
130    /**
131     * @copydoc Dali::Renderer::SetBlendEquation()
132     */
133    void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
134
135    /**
136     * @copydoc Dali::Renderer::GetBlendEquation()
137     */
138    void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
139
140    /**
141     * @copydoc Dali::Renderer::SetBlendColor()
142     */
143    void SetBlendColor( const Vector4& color );
144
145    /**
146     * @copydoc Dali::Renderer::GetBlendColor()
147     */
148    Vector4 GetBlendColor() const;
149
150    /**
151     * @brief Set whether the Pre-multiplied Alpha Blending is required
152     *
153     * @param[in] preMultipled whether alpha is pre-multiplied.
154     */
155    void EnablePreMultipliedAlpha( bool preMultipled );
156
157    /**
158     * @brief Query whether alpha is pre-multiplied.
159     *
160     * @return True is alpha is pre-multiplied, false otherwise.
161     */
162    bool IsPreMultipliedAlphaEnabled() const;
163
164   /**
165    * @brief Get the scene graph object ( the node attachment )
166    *
167    * @return the scene object
168    */
169   SceneGraph::Renderer* GetRendererSceneObject();
170
171 public: // Default property extensions from Object
172
173   /**
174    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
175    */
176   virtual unsigned int GetDefaultPropertyCount() const;
177
178   /**
179    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
180    */
181   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
182
183   /**
184    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
185    */
186   virtual const char* GetDefaultPropertyName(Property::Index index) const;
187
188   /**
189    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
190    */
191   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
192
193   /**
194    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
195    */
196   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
197
198   /**
199    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
200    */
201   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
202
203   /**
204    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
205    */
206   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
207
208   /**
209    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
210    */
211   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
212
213   /**
214    * @copydoc Dali::Internal::Object::SetDefaultProperty()
215    */
216   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
217
218   /**
219    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
220    */
221   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
222
223   /**
224    * @copydoc Dali::Internal::Object::GetDefaultProperty()
225    */
226   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
227
228   /**
229    * @copydoc Dali::Internal::Object::GetPropertyOwner()
230    */
231   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
232
233   /**
234    * @copydoc Dali::Internal::Object::GetSceneObject()
235    */
236   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
237
238   /**
239    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
240    */
241   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
242
243   /**
244    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
245    */
246   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
247
248   /**
249    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
250    */
251   virtual int GetPropertyComponentIndex( Property::Index index ) const;
252
253 public: // Functions from Connectable
254   /**
255    * @copydoc Dali::Internal::Connectable::OnStage()
256    */
257   virtual bool OnStage() const;
258
259   /**
260    * @copydoc Dali::Internal::Connectable::Connect()
261    */
262   virtual void Connect();
263
264   /**
265    * @copydoc Dali::Internal::Connectable::Disconnect()
266    */
267   virtual void Disconnect();
268
269 private: // implementation
270   Renderer();
271
272   void Initialize();
273
274 protected:
275   /**
276    * A reference counted object may only be deleted by calling Unreference()
277    */
278   virtual ~Renderer();
279
280 private: // unimplemented methods
281   Renderer( const Renderer& );
282   Renderer& operator=( const Renderer& );
283
284 private: // data
285   SceneGraph::Renderer* mSceneObject;
286   Vector4* mBlendColor;                         ///< Local copy of blend color, pointer only as its rarely used
287   ObjectConnector<Geometry> mGeometryConnector; ///< Connector that holds the geometry used by this renderer
288   ObjectConnector<Material> mMaterialConnector; ///< Connector that holds the material used by this renderer
289
290   int mDepthIndex;
291   int mOnStageCount;
292
293   Dali::Renderer::FaceCullingMode mFaceCullingMode; ///< Local copy of face culling mode
294   BlendingMode::Type mBlendingMode;                 ///< Local copy of blending mode
295   BlendingOptions mBlendingOptions;                 ///< Local copy of blending options bitmask
296   bool mPremultipledAlphaEnabled;                   ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
297
298 };
299
300 } // namespace Internal
301
302 // Helpers for public-api forwarding methods
303 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
304 {
305   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
306
307   BaseObject& object = handle.GetBaseObject();
308
309   return static_cast<Internal::Renderer&>(object);
310 }
311
312 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
313 {
314   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
315
316   const BaseObject& object = handle.GetBaseObject();
317
318   return static_cast<const Internal::Renderer&>(object);
319 }
320
321 } // namespace Dali
322
323 #endif // DALI_INTERNAL_RENDERER_H