Merge "DALi Version 1.1.31" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / renderer-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/rendering/renderer-impl.h> // Dali::Internal::Renderer
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
24 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
25 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
26 #include <dali/internal/event/common/property-input-impl.h>
27 #include <dali/internal/update/rendering/scene-graph-renderer.h>
28 #include <dali/internal/update/manager/update-manager.h>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34
35 namespace
36 {
37
38 /**
39  *            |name                              |type     |writable|animatable|constraint-input|enum for index-checking|
40  */
41 DALI_PROPERTY_TABLE_BEGIN
42 DALI_PROPERTY( "depthIndex",                      INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_INDEX )
43 DALI_PROPERTY( "faceCullingMode",                 INTEGER,   true, false,  false, Dali::Renderer::Property::FACE_CULLING_MODE )
44 DALI_PROPERTY( "blendingMode",                    INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_MODE )
45 DALI_PROPERTY( "blendEquationRgb",                INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
46 DALI_PROPERTY( "blendEquationAlpha",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
47 DALI_PROPERTY( "sourceBlendFactorRgb",            INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB )
48 DALI_PROPERTY( "destinationBlendFactorRgb",       INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB )
49 DALI_PROPERTY( "sourceBlendFactorAlpha",          INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA )
50 DALI_PROPERTY( "destinationBlendFactorAlpha",     INTEGER,   true, false,  false, Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA )
51 DALI_PROPERTY( "blendingColor",                   VECTOR4,   true, false,  false, Dali::Renderer::Property::BLENDING_COLOR )
52 DALI_PROPERTY( "blendPreMultipliedAlpha",         BOOLEAN,   true, false,  false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
53 DALI_PROPERTY( "indexedDrawFirstElement",         INTEGER,   true, false,  false, Dali::Renderer::Property::INDEXED_DRAW_FIRST_ELEMENT )
54 DALI_PROPERTY( "indexedDrawElementsCount",        INTEGER,   true, false,  false, Dali::Renderer::Property::INDEXED_DRAW_ELEMENTS_COUNT )
55 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
56
57 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
58
59 BaseHandle Create()
60 {
61   return Dali::BaseHandle();
62 }
63
64 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
65
66 } // unnamed namespace
67
68 RendererPtr Renderer::New()
69 {
70   RendererPtr rendererPtr( new Renderer() );
71   rendererPtr->Initialize();
72   return rendererPtr;
73 }
74
75 void Renderer::SetGeometry( Geometry& geometry )
76 {
77   mGeometryConnector.Set( geometry, OnStage() );
78   const SceneGraph::Geometry* geometrySceneObject = geometry.GetGeometrySceneObject();
79
80   SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
81 }
82
83 Geometry* Renderer::GetGeometry() const
84 {
85   return mGeometryConnector.Get().Get();
86 }
87
88 void Renderer::SetTextures( TextureSet& textureSet )
89 {
90   mTextureSetConnector.Set( textureSet, OnStage() );
91   const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
92   SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
93 }
94
95 TextureSet* Renderer::GetTextures() const
96 {
97   return mTextureSetConnector.Get().Get();
98 }
99
100 void Renderer::SetShader( Shader& shader )
101 {
102   mShader = &shader;
103   SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
104   SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
105 }
106
107 Shader* Renderer::GetShader() const
108 {
109   return mShader.Get();
110 }
111
112 void Renderer::SetDepthIndex( int depthIndex )
113 {
114   if ( mDepthIndex != depthIndex )
115   {
116     mDepthIndex = depthIndex;
117     SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
118   }
119 }
120
121 int Renderer::GetDepthIndex() const
122 {
123   return mDepthIndex;
124 }
125
126 void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode cullingMode )
127 {
128   if( mFaceCullingMode != cullingMode )
129   {
130     mFaceCullingMode = cullingMode;
131
132     SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, mFaceCullingMode );
133   }
134 }
135
136 Dali::Renderer::FaceCullingMode Renderer::GetFaceCullingMode()
137 {
138   return mFaceCullingMode;
139 }
140
141 void Renderer::SetBlendMode( BlendingMode::Type mode )
142 {
143   if( mBlendingMode != mode )
144   {
145     mBlendingMode = mode;
146
147     SetBlendingModeMessage( GetEventThreadServices(), *mSceneObject, mBlendingMode );
148   }
149 }
150
151 BlendingMode::Type Renderer::GetBlendMode() const
152 {
153   return mBlendingMode;
154 }
155
156 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
157 {
158   mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
159   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
160 }
161
162 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
163                              BlendingFactor::Type destFactorRgb,
164                              BlendingFactor::Type srcFactorAlpha,
165                              BlendingFactor::Type destFactorAlpha )
166 {
167   mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
168   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
169 }
170
171 void Renderer::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
172                              BlendingFactor::Type& destFactorRgb,
173                              BlendingFactor::Type& srcFactorAlpha,
174                              BlendingFactor::Type& destFactorAlpha ) const
175 {
176   srcFactorRgb    = mBlendingOptions.GetBlendSrcFactorRgb();
177   destFactorRgb   = mBlendingOptions.GetBlendDestFactorRgb();
178   srcFactorAlpha  = mBlendingOptions.GetBlendSrcFactorAlpha();
179   destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
180 }
181
182 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgba )
183 {
184   mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
185   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
186 }
187
188 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgb,
189                                  BlendingEquation::Type equationAlpha )
190 {
191   mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
192   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
193 }
194
195 void Renderer::GetBlendEquation( BlendingEquation::Type& equationRgb,
196                                  BlendingEquation::Type& equationAlpha ) const
197 {
198   // These are not animatable, the cached values are up-to-date.
199   equationRgb   = mBlendingOptions.GetBlendEquationRgb();
200   equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
201 }
202
203 void Renderer::SetBlendColor( const Vector4& color )
204 {
205   if( !mBlendColor )
206   {
207     mBlendColor = new Vector4();
208   }
209   if( *mBlendColor != color )
210   {
211     *mBlendColor = color;
212     SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
213   }
214 }
215
216 Vector4 Renderer::GetBlendColor() const
217 {
218   if( mBlendColor )
219   {
220     return *mBlendColor;
221   }
222   return Color::TRANSPARENT; // GL default
223 }
224
225 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
226 {
227   if( firstElement != mIndexedDrawFirstElement )
228   {
229     mIndexedDrawFirstElement = firstElement;
230     SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
231   }
232 }
233
234 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
235 {
236   if( elementsCount != mIndexedDrawElementCount )
237   {
238     mIndexedDrawElementCount = elementsCount;
239     SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
240   }
241 }
242
243
244 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
245 {
246   if(  mPremultipledAlphaEnabled != preMultipled )
247   {
248     if( preMultipled )
249     {
250       SetBlendFunc( BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA, BlendingFactor::ONE, BlendingFactor::ONE );
251     }
252     mPremultipledAlphaEnabled = preMultipled;
253     SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
254   }
255 }
256
257 bool Renderer::IsPreMultipliedAlphaEnabled() const
258 {
259   return mPremultipledAlphaEnabled;
260 }
261
262 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
263 {
264   return mSceneObject;
265 }
266
267 unsigned int Renderer::GetDefaultPropertyCount() const
268 {
269   return RENDERER_IMPL.GetDefaultPropertyCount();
270 }
271
272 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
273 {
274   RENDERER_IMPL.GetDefaultPropertyIndices( indices );
275 }
276
277 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
278 {
279   return RENDERER_IMPL.GetDefaultPropertyName( index );
280 }
281
282 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
283 {
284   return RENDERER_IMPL.GetDefaultPropertyIndex( name );
285 }
286
287 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
288 {
289   return RENDERER_IMPL.IsDefaultPropertyWritable( index );
290 }
291
292 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
293 {
294   return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
295 }
296
297 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
298 {
299   return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
300 }
301
302 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
303 {
304   return RENDERER_IMPL.GetDefaultPropertyType( index );
305 }
306
307 void Renderer::SetDefaultProperty( Property::Index index,
308                                    const Property::Value& propertyValue )
309 {
310   switch( index )
311   {
312     case Dali::Renderer::Property::DEPTH_INDEX:
313     {
314       SetDepthIndex( propertyValue.Get<int>() );
315       break;
316     }
317     case Dali::Renderer::Property::FACE_CULLING_MODE:
318     {
319       int faceCullingMode;
320       if( propertyValue.Get( faceCullingMode ) )
321       {
322         SetFaceCullingMode( Dali::Renderer::FaceCullingMode( faceCullingMode ) );
323       }
324       break;
325     }
326     case Dali::Renderer::Property::BLENDING_MODE:
327     {
328       int blendingMode;
329       if( propertyValue.Get( blendingMode ) )
330       {
331         SetBlendMode( BlendingMode::Type( blendingMode ) );
332       }
333       break;
334     }
335     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
336     {
337       int blendingEquation;
338       if( propertyValue.Get( blendingEquation ) )
339       {
340         BlendingEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
341         mBlendingOptions.SetBlendEquation( static_cast<BlendingEquation::Type>( blendingEquation ), alphaEquation );
342         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
343       }
344       break;
345     }
346     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
347     {
348       int blendingEquation;
349       if( propertyValue.Get( blendingEquation ) )
350       {
351         BlendingEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
352         mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendingEquation::Type>( blendingEquation ) );
353         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
354       }
355       break;
356     }
357     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
358     {
359       int blendingFactor;
360       if( propertyValue.Get( blendingFactor ) )
361       {
362         BlendingFactor::Type srcFactorRgb;
363         BlendingFactor::Type destFactorRgb;
364         BlendingFactor::Type srcFactorAlpha;
365         BlendingFactor::Type destFactorAlpha;
366         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
367         SetBlendFunc( static_cast<BlendingFactor::Type>( blendingFactor ),
368             destFactorRgb,
369             srcFactorAlpha,
370             destFactorAlpha );
371       }
372       break;
373     }
374     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
375     {
376       int blendingFactor;
377       if( propertyValue.Get( blendingFactor ) )
378       {
379         BlendingFactor::Type srcFactorRgb;
380         BlendingFactor::Type destFactorRgb;
381         BlendingFactor::Type srcFactorAlpha;
382         BlendingFactor::Type destFactorAlpha;
383         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
384         SetBlendFunc( srcFactorRgb,
385             static_cast<BlendingFactor::Type>( blendingFactor ),
386             srcFactorAlpha,
387             destFactorAlpha );
388       }
389       break;
390     }
391     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
392     {
393       int blendingFactor;
394       if( propertyValue.Get( blendingFactor ) )
395       {
396         BlendingFactor::Type srcFactorRgb;
397         BlendingFactor::Type destFactorRgb;
398         BlendingFactor::Type srcFactorAlpha;
399         BlendingFactor::Type destFactorAlpha;
400         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
401         SetBlendFunc( srcFactorRgb,
402             destFactorRgb,
403             static_cast<BlendingFactor::Type>( blendingFactor ),
404             destFactorAlpha );
405       }
406       break;
407     }
408     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
409     {
410       int blendingFactor;
411       if( propertyValue.Get( blendingFactor ) )
412       {
413         BlendingFactor::Type srcFactorRgb;
414         BlendingFactor::Type destFactorRgb;
415         BlendingFactor::Type srcFactorAlpha;
416         BlendingFactor::Type destFactorAlpha;
417         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
418         SetBlendFunc( srcFactorRgb,
419             destFactorRgb,
420             srcFactorAlpha,
421             static_cast<BlendingFactor::Type>( blendingFactor ) );
422       }
423       break;
424     }
425     case Dali::Renderer::Property::BLENDING_COLOR:
426     {
427       Vector4 blendColor;
428       if( propertyValue.Get( blendColor ) )
429       {
430         SetBlendColor( blendColor );
431       }
432       break;
433     }
434     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
435     {
436       bool preMultipled;
437       if( propertyValue.Get( preMultipled ) )
438       {
439         EnablePreMultipliedAlpha( preMultipled );
440       }
441       break;
442     }
443     case Dali::Renderer::Property::INDEXED_DRAW_FIRST_ELEMENT:
444     {
445       int firstElement;
446       if( propertyValue.Get( firstElement ) )
447       {
448         SetIndexedDrawFirstElement( firstElement );
449       }
450       break;
451     }
452     case Dali::Renderer::Property::INDEXED_DRAW_ELEMENTS_COUNT:
453     {
454       int elementsCount;
455       if( propertyValue.Get( elementsCount ) )
456       {
457         SetIndexedDrawElementsCount( elementsCount );
458       }
459       break;
460     }
461   }
462 }
463
464 void Renderer::SetSceneGraphProperty( Property::Index index,
465                                       const PropertyMetadata& entry,
466                                       const Property::Value& value )
467 {
468   RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
469   OnPropertySet(index, value);
470 }
471
472 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
473 {
474   Property::Value value;
475   switch( index )
476   {
477     case Dali::Renderer::Property::DEPTH_INDEX:
478     {
479       value = GetDepthIndex();
480       break;
481     }
482     case Dali::Renderer::Property::FACE_CULLING_MODE:
483     {
484       value = mFaceCullingMode;
485       break;
486     }
487     case Dali::Renderer::Property::BLENDING_MODE:
488     {
489       value = mBlendingMode;
490       break;
491     }
492     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
493     {
494       value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
495       break;
496     }
497     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
498     {
499       value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
500       break;
501     }
502     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
503     {
504       BlendingFactor::Type srcFactorRgb;
505       BlendingFactor::Type destFactorRgb;
506       BlendingFactor::Type srcFactorAlpha;
507       BlendingFactor::Type destFactorAlpha;
508       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
509       value = static_cast<int>( srcFactorRgb );
510       break;
511     }
512     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
513     {
514       BlendingFactor::Type srcFactorRgb;
515       BlendingFactor::Type destFactorRgb;
516       BlendingFactor::Type srcFactorAlpha;
517       BlendingFactor::Type destFactorAlpha;
518       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
519       value = static_cast<int>( destFactorRgb );
520       break;
521     }
522     case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
523     {
524       BlendingFactor::Type srcFactorRgb;
525       BlendingFactor::Type destFactorRgb;
526       BlendingFactor::Type srcFactorAlpha;
527       BlendingFactor::Type destFactorAlpha;
528       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
529       value = static_cast<int>( srcFactorAlpha );
530       break;
531     }
532     case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
533     {
534       BlendingFactor::Type srcFactorRgb;
535       BlendingFactor::Type destFactorRgb;
536       BlendingFactor::Type srcFactorAlpha;
537       BlendingFactor::Type destFactorAlpha;
538       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
539       value = static_cast<int>( destFactorAlpha );
540       break;
541     }
542     case Dali::Renderer::Property::BLENDING_COLOR:
543     {
544       if( mBlendColor )
545       {
546         value = *mBlendColor;
547       }
548       else
549       {
550         value = Color::TRANSPARENT;
551       }
552       break;
553     }
554     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
555     {
556       value = IsPreMultipliedAlphaEnabled();
557       break;
558     }
559     case Dali::Renderer::Property::INDEXED_DRAW_FIRST_ELEMENT:
560     {
561       value = static_cast<int>( mIndexedDrawFirstElement );
562       break;
563     }
564     case Dali::Renderer::Property::INDEXED_DRAW_ELEMENTS_COUNT:
565     {
566       value = static_cast<int>( mIndexedDrawElementCount );
567       break;
568     }
569   }
570   return value;
571 }
572
573 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
574 {
575   return mSceneObject;
576 }
577
578 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
579 {
580   return mSceneObject;
581 }
582
583 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
584 {
585   DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
586   const SceneGraph::PropertyBase* property = NULL;
587
588   if( OnStage() )
589   {
590     property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
591       this,
592       &Renderer::FindAnimatableProperty,
593       &Renderer::FindCustomProperty,
594       index );
595   }
596
597   return property;
598 }
599
600 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
601 {
602   const PropertyInputImpl* property = NULL;
603
604   if( OnStage() )
605   {
606     const SceneGraph::PropertyBase* baseProperty =
607       RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
608                                                      &Renderer::FindAnimatableProperty,
609                                                      &Renderer::FindCustomProperty,
610                                                      index );
611     property = static_cast<const PropertyInputImpl*>( baseProperty );
612   }
613
614   return property;
615 }
616
617 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
618 {
619   return Property::INVALID_COMPONENT_INDEX;
620 }
621
622 bool Renderer::OnStage() const
623 {
624   return mOnStageCount > 0;
625 }
626
627 void Renderer::Connect()
628 {
629   if( mOnStageCount == 0 )
630   {
631     OnStageConnectMessage( GetEventThreadServices(), *mSceneObject );
632     mGeometryConnector.OnStageConnect();
633     mTextureSetConnector.OnStageConnect();
634   }
635   ++mOnStageCount;
636 }
637
638 void Renderer::Disconnect()
639 {
640   --mOnStageCount;
641   if( mOnStageCount == 0 )
642   {
643     OnStageDisconnectMessage( GetEventThreadServices(), *mSceneObject);
644     mGeometryConnector.OnStageDisconnect();
645     mTextureSetConnector.OnStageDisconnect();
646   }
647 }
648
649 Renderer::Renderer()
650 : mSceneObject (NULL ),
651   mBlendColor( NULL ),
652   mDepthIndex( 0 ),
653   mOnStageCount( 0 ),
654   mIndexedDrawFirstElement( 0 ),
655   mIndexedDrawElementCount( 0 ),
656   mFaceCullingMode( Dali::Renderer::NONE ),
657   mBlendingMode( Dali::BlendingMode::AUTO ),
658   mBlendingOptions(),
659   mPremultipledAlphaEnabled( false )
660 {
661 }
662
663 void Renderer::Initialize()
664 {
665   EventThreadServices& eventThreadServices = GetEventThreadServices();
666   SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
667
668   mSceneObject = SceneGraph::Renderer::New();
669   AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
670
671   eventThreadServices.RegisterObject( this );
672 }
673
674 Renderer::~Renderer()
675 {
676   if( EventThreadServices::IsCoreRunning() )
677   {
678     EventThreadServices& eventThreadServices = GetEventThreadServices();
679     SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
680     RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
681
682     eventThreadServices.UnregisterObject( this );
683   }
684 }
685
686 } // namespace Internal
687 } // namespace Dali