2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/rendering/renderer-impl.h> // Dali::Internal::Renderer
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>
39 * |name |type |writable|animatable|constraint-input|enum for index-checking|
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_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
55 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
59 return Dali::BaseHandle();
62 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
64 } // unnamed namespace
66 RendererPtr Renderer::New()
68 RendererPtr rendererPtr( new Renderer() );
69 rendererPtr->Initialize();
73 void Renderer::SetGeometry( Geometry& geometry )
75 mGeometryConnector.Set( geometry, OnStage() );
76 const SceneGraph::Geometry* geometrySceneObject = geometry.GetGeometrySceneObject();
78 SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
81 Geometry* Renderer::GetGeometry() const
83 return mGeometryConnector.Get().Get();
86 void Renderer::SetMaterial( Material& material )
88 mMaterialConnector.Set( material, OnStage() );
89 const SceneGraph::Material* materialSceneObject = material.GetMaterialSceneObject();
90 SetMaterialMessage( GetEventThreadServices(), *mSceneObject, *materialSceneObject );
93 Material* Renderer::GetMaterial() const
95 return mMaterialConnector.Get().Get();
98 void Renderer::SetDepthIndex( int depthIndex )
100 if ( mDepthIndex != depthIndex )
102 mDepthIndex = depthIndex;
103 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
107 int Renderer::GetDepthIndex() const
112 void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode cullingMode )
114 if( mFaceCullingMode != cullingMode )
116 mFaceCullingMode = cullingMode;
118 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, mFaceCullingMode );
122 Dali::Renderer::FaceCullingMode Renderer::GetFaceCullingMode()
124 return mFaceCullingMode;
127 void Renderer::SetBlendMode( BlendingMode::Type mode )
129 if( mBlendingMode != mode )
131 mBlendingMode = mode;
133 SetBlendingModeMessage( GetEventThreadServices(), *mSceneObject, mBlendingMode );
137 BlendingMode::Type Renderer::GetBlendMode() const
139 return mBlendingMode;
142 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
144 mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
145 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
148 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
149 BlendingFactor::Type destFactorRgb,
150 BlendingFactor::Type srcFactorAlpha,
151 BlendingFactor::Type destFactorAlpha )
153 mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
154 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
157 void Renderer::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
158 BlendingFactor::Type& destFactorRgb,
159 BlendingFactor::Type& srcFactorAlpha,
160 BlendingFactor::Type& destFactorAlpha ) const
162 srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
163 destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
164 srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
165 destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
168 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgba )
170 mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
171 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
174 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgb,
175 BlendingEquation::Type equationAlpha )
177 mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
178 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
181 void Renderer::GetBlendEquation( BlendingEquation::Type& equationRgb,
182 BlendingEquation::Type& equationAlpha ) const
184 // These are not animatable, the cached values are up-to-date.
185 equationRgb = mBlendingOptions.GetBlendEquationRgb();
186 equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
189 void Renderer::SetBlendColor( const Vector4& color )
193 mBlendColor = new Vector4();
195 if( *mBlendColor != color )
197 *mBlendColor = color;
198 SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
202 Vector4 Renderer::GetBlendColor() const
208 return Color::TRANSPARENT; // GL default
211 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
213 if( mPremultipledAlphaEnabled != preMultipled )
217 SetBlendFunc( BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA, BlendingFactor::ONE, BlendingFactor::ONE );
219 mPremultipledAlphaEnabled = preMultipled;
220 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
224 bool Renderer::IsPreMultipliedAlphaEnabled() const
226 return mPremultipledAlphaEnabled;
229 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
234 unsigned int Renderer::GetDefaultPropertyCount() const
236 return RENDERER_IMPL.GetDefaultPropertyCount();
239 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
241 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
244 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
246 return RENDERER_IMPL.GetDefaultPropertyName( index );
249 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
251 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
254 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
256 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
259 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
261 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
264 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
266 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
269 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
271 return RENDERER_IMPL.GetDefaultPropertyType( index );
274 void Renderer::SetDefaultProperty( Property::Index index,
275 const Property::Value& propertyValue )
279 case Dali::Renderer::Property::DEPTH_INDEX:
281 SetDepthIndex( propertyValue.Get<int>() );
284 case Dali::Renderer::Property::FACE_CULLING_MODE:
287 if( propertyValue.Get( faceCullingMode ) )
289 SetFaceCullingMode( Dali::Renderer::FaceCullingMode( faceCullingMode ) );
293 case Dali::Renderer::Property::BLENDING_MODE:
296 if( propertyValue.Get( blendingMode ) )
298 SetBlendMode( BlendingMode::Type( blendingMode ) );
302 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
304 int blendingEquation;
305 if( propertyValue.Get( blendingEquation ) )
307 BlendingEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
308 mBlendingOptions.SetBlendEquation( static_cast<BlendingEquation::Type>( blendingEquation ), alphaEquation );
309 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
313 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
315 int blendingEquation;
316 if( propertyValue.Get( blendingEquation ) )
318 BlendingEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
319 mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendingEquation::Type>( blendingEquation ) );
320 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
324 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
327 if( propertyValue.Get( blendingFactor ) )
329 BlendingFactor::Type srcFactorRgb;
330 BlendingFactor::Type destFactorRgb;
331 BlendingFactor::Type srcFactorAlpha;
332 BlendingFactor::Type destFactorAlpha;
333 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
334 SetBlendFunc( static_cast<BlendingFactor::Type>( blendingFactor ),
341 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
344 if( propertyValue.Get( blendingFactor ) )
346 BlendingFactor::Type srcFactorRgb;
347 BlendingFactor::Type destFactorRgb;
348 BlendingFactor::Type srcFactorAlpha;
349 BlendingFactor::Type destFactorAlpha;
350 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
351 SetBlendFunc( srcFactorRgb,
352 static_cast<BlendingFactor::Type>( blendingFactor ),
358 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
361 if( propertyValue.Get( blendingFactor ) )
363 BlendingFactor::Type srcFactorRgb;
364 BlendingFactor::Type destFactorRgb;
365 BlendingFactor::Type srcFactorAlpha;
366 BlendingFactor::Type destFactorAlpha;
367 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
368 SetBlendFunc( srcFactorRgb,
370 static_cast<BlendingFactor::Type>( blendingFactor ),
375 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
378 if( propertyValue.Get( blendingFactor ) )
380 BlendingFactor::Type srcFactorRgb;
381 BlendingFactor::Type destFactorRgb;
382 BlendingFactor::Type srcFactorAlpha;
383 BlendingFactor::Type destFactorAlpha;
384 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
385 SetBlendFunc( srcFactorRgb,
388 static_cast<BlendingFactor::Type>( blendingFactor ) );
392 case Dali::Renderer::Property::BLENDING_COLOR:
395 if( propertyValue.Get( blendColor ) )
397 SetBlendColor( blendColor );
401 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
404 if( propertyValue.Get( preMultipled ) )
406 EnablePreMultipliedAlpha( preMultipled );
413 void Renderer::SetSceneGraphProperty( Property::Index index,
414 const PropertyMetadata& entry,
415 const Property::Value& value )
417 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
418 OnPropertySet(index, value);
421 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
423 Property::Value value;
426 case Dali::Renderer::Property::DEPTH_INDEX:
428 value = GetDepthIndex();
431 case Dali::Renderer::Property::FACE_CULLING_MODE:
433 value = mFaceCullingMode;
436 case Dali::Renderer::Property::BLENDING_MODE:
438 value = mBlendingMode;
441 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
443 value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
446 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
448 value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
451 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
453 BlendingFactor::Type srcFactorRgb;
454 BlendingFactor::Type destFactorRgb;
455 BlendingFactor::Type srcFactorAlpha;
456 BlendingFactor::Type destFactorAlpha;
457 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
458 value = static_cast<int>( srcFactorRgb );
461 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
463 BlendingFactor::Type srcFactorRgb;
464 BlendingFactor::Type destFactorRgb;
465 BlendingFactor::Type srcFactorAlpha;
466 BlendingFactor::Type destFactorAlpha;
467 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
468 value = static_cast<int>( destFactorRgb );
471 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
473 BlendingFactor::Type srcFactorRgb;
474 BlendingFactor::Type destFactorRgb;
475 BlendingFactor::Type srcFactorAlpha;
476 BlendingFactor::Type destFactorAlpha;
477 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
478 value = static_cast<int>( srcFactorAlpha );
481 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
483 BlendingFactor::Type srcFactorRgb;
484 BlendingFactor::Type destFactorRgb;
485 BlendingFactor::Type srcFactorAlpha;
486 BlendingFactor::Type destFactorAlpha;
487 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
488 value = static_cast<int>( destFactorAlpha );
491 case Dali::Renderer::Property::BLENDING_COLOR:
495 value = *mBlendColor;
499 value = Color::TRANSPARENT;
503 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
505 value = IsPreMultipliedAlphaEnabled();
512 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
517 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
522 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
524 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
525 const SceneGraph::PropertyBase* property = NULL;
529 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
531 &Renderer::FindAnimatableProperty,
532 &Renderer::FindCustomProperty,
539 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
541 const PropertyInputImpl* property = NULL;
545 const SceneGraph::PropertyBase* baseProperty =
546 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
547 &Renderer::FindAnimatableProperty,
548 &Renderer::FindCustomProperty,
550 property = static_cast<const PropertyInputImpl*>( baseProperty );
556 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
558 return Property::INVALID_COMPONENT_INDEX;
561 bool Renderer::OnStage() const
563 return mOnStageCount > 0;
566 void Renderer::Connect()
568 if( mOnStageCount == 0 )
570 OnStageConnectMessage( GetEventThreadServices(), *mSceneObject );
571 mGeometryConnector.OnStageConnect();
572 mMaterialConnector.OnStageConnect();
577 void Renderer::Disconnect()
580 if( mOnStageCount == 0 )
582 OnStageDisconnectMessage( GetEventThreadServices(), *mSceneObject);
583 mGeometryConnector.OnStageDisconnect();
584 mMaterialConnector.OnStageDisconnect();
589 : mSceneObject(NULL),
593 mFaceCullingMode(Dali::Renderer::NONE),
594 mBlendingMode( Dali::BlendingMode::AUTO ),
596 mPremultipledAlphaEnabled( false )
600 void Renderer::Initialize()
602 EventThreadServices& eventThreadServices = GetEventThreadServices();
603 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
605 mSceneObject = SceneGraph::Renderer::New();
606 AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
608 eventThreadServices.RegisterObject( this );
611 Renderer::~Renderer()
613 if( EventThreadServices::IsCoreRunning() )
615 EventThreadServices& eventThreadServices = GetEventThreadServices();
616 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
617 RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
619 eventThreadServices.UnregisterObject( this );
623 } // namespace Internal