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::SetTextures( TextureSet& textureSet )
88 mTextureSetConnector.Set( textureSet, OnStage() );
89 const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
90 SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
93 TextureSet* Renderer::GetTextures() const
95 return mTextureSetConnector.Get().Get();
98 void Renderer::SetShader( Shader& shader )
101 SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
102 SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
105 Shader* Renderer::GetShader() const
107 return mShader.Get();
110 void Renderer::SetDepthIndex( int depthIndex )
112 if ( mDepthIndex != depthIndex )
114 mDepthIndex = depthIndex;
115 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
119 int Renderer::GetDepthIndex() const
124 void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode cullingMode )
126 if( mFaceCullingMode != cullingMode )
128 mFaceCullingMode = cullingMode;
130 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, mFaceCullingMode );
134 Dali::Renderer::FaceCullingMode Renderer::GetFaceCullingMode()
136 return mFaceCullingMode;
139 void Renderer::SetBlendMode( BlendingMode::Type mode )
141 if( mBlendingMode != mode )
143 mBlendingMode = mode;
145 SetBlendingModeMessage( GetEventThreadServices(), *mSceneObject, mBlendingMode );
149 BlendingMode::Type Renderer::GetBlendMode() const
151 return mBlendingMode;
154 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
156 mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
157 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
160 void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
161 BlendingFactor::Type destFactorRgb,
162 BlendingFactor::Type srcFactorAlpha,
163 BlendingFactor::Type destFactorAlpha )
165 mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
166 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
169 void Renderer::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
170 BlendingFactor::Type& destFactorRgb,
171 BlendingFactor::Type& srcFactorAlpha,
172 BlendingFactor::Type& destFactorAlpha ) const
174 srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
175 destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
176 srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
177 destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
180 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgba )
182 mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
183 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
186 void Renderer::SetBlendEquation( BlendingEquation::Type equationRgb,
187 BlendingEquation::Type equationAlpha )
189 mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
190 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
193 void Renderer::GetBlendEquation( BlendingEquation::Type& equationRgb,
194 BlendingEquation::Type& equationAlpha ) const
196 // These are not animatable, the cached values are up-to-date.
197 equationRgb = mBlendingOptions.GetBlendEquationRgb();
198 equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
201 void Renderer::SetBlendColor( const Vector4& color )
205 mBlendColor = new Vector4();
207 if( *mBlendColor != color )
209 *mBlendColor = color;
210 SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
214 Vector4 Renderer::GetBlendColor() const
220 return Color::TRANSPARENT; // GL default
223 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
225 if( mPremultipledAlphaEnabled != preMultipled )
229 SetBlendFunc( BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA, BlendingFactor::ONE, BlendingFactor::ONE );
231 mPremultipledAlphaEnabled = preMultipled;
232 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
236 bool Renderer::IsPreMultipliedAlphaEnabled() const
238 return mPremultipledAlphaEnabled;
241 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
246 unsigned int Renderer::GetDefaultPropertyCount() const
248 return RENDERER_IMPL.GetDefaultPropertyCount();
251 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
253 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
256 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
258 return RENDERER_IMPL.GetDefaultPropertyName( index );
261 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
263 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
266 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
268 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
271 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
273 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
276 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
278 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
281 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
283 return RENDERER_IMPL.GetDefaultPropertyType( index );
286 void Renderer::SetDefaultProperty( Property::Index index,
287 const Property::Value& propertyValue )
291 case Dali::Renderer::Property::DEPTH_INDEX:
293 SetDepthIndex( propertyValue.Get<int>() );
296 case Dali::Renderer::Property::FACE_CULLING_MODE:
299 if( propertyValue.Get( faceCullingMode ) )
301 SetFaceCullingMode( Dali::Renderer::FaceCullingMode( faceCullingMode ) );
305 case Dali::Renderer::Property::BLENDING_MODE:
308 if( propertyValue.Get( blendingMode ) )
310 SetBlendMode( BlendingMode::Type( blendingMode ) );
314 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
316 int blendingEquation;
317 if( propertyValue.Get( blendingEquation ) )
319 BlendingEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
320 mBlendingOptions.SetBlendEquation( static_cast<BlendingEquation::Type>( blendingEquation ), alphaEquation );
321 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
325 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
327 int blendingEquation;
328 if( propertyValue.Get( blendingEquation ) )
330 BlendingEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
331 mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendingEquation::Type>( blendingEquation ) );
332 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
336 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
339 if( propertyValue.Get( blendingFactor ) )
341 BlendingFactor::Type srcFactorRgb;
342 BlendingFactor::Type destFactorRgb;
343 BlendingFactor::Type srcFactorAlpha;
344 BlendingFactor::Type destFactorAlpha;
345 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
346 SetBlendFunc( static_cast<BlendingFactor::Type>( blendingFactor ),
353 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
356 if( propertyValue.Get( blendingFactor ) )
358 BlendingFactor::Type srcFactorRgb;
359 BlendingFactor::Type destFactorRgb;
360 BlendingFactor::Type srcFactorAlpha;
361 BlendingFactor::Type destFactorAlpha;
362 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
363 SetBlendFunc( srcFactorRgb,
364 static_cast<BlendingFactor::Type>( blendingFactor ),
370 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
373 if( propertyValue.Get( blendingFactor ) )
375 BlendingFactor::Type srcFactorRgb;
376 BlendingFactor::Type destFactorRgb;
377 BlendingFactor::Type srcFactorAlpha;
378 BlendingFactor::Type destFactorAlpha;
379 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
380 SetBlendFunc( srcFactorRgb,
382 static_cast<BlendingFactor::Type>( blendingFactor ),
387 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
390 if( propertyValue.Get( blendingFactor ) )
392 BlendingFactor::Type srcFactorRgb;
393 BlendingFactor::Type destFactorRgb;
394 BlendingFactor::Type srcFactorAlpha;
395 BlendingFactor::Type destFactorAlpha;
396 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
397 SetBlendFunc( srcFactorRgb,
400 static_cast<BlendingFactor::Type>( blendingFactor ) );
404 case Dali::Renderer::Property::BLENDING_COLOR:
407 if( propertyValue.Get( blendColor ) )
409 SetBlendColor( blendColor );
413 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
416 if( propertyValue.Get( preMultipled ) )
418 EnablePreMultipliedAlpha( preMultipled );
425 void Renderer::SetSceneGraphProperty( Property::Index index,
426 const PropertyMetadata& entry,
427 const Property::Value& value )
429 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
430 OnPropertySet(index, value);
433 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
435 Property::Value value;
438 case Dali::Renderer::Property::DEPTH_INDEX:
440 value = GetDepthIndex();
443 case Dali::Renderer::Property::FACE_CULLING_MODE:
445 value = mFaceCullingMode;
448 case Dali::Renderer::Property::BLENDING_MODE:
450 value = mBlendingMode;
453 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
455 value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
458 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
460 value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
463 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
465 BlendingFactor::Type srcFactorRgb;
466 BlendingFactor::Type destFactorRgb;
467 BlendingFactor::Type srcFactorAlpha;
468 BlendingFactor::Type destFactorAlpha;
469 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
470 value = static_cast<int>( srcFactorRgb );
473 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
475 BlendingFactor::Type srcFactorRgb;
476 BlendingFactor::Type destFactorRgb;
477 BlendingFactor::Type srcFactorAlpha;
478 BlendingFactor::Type destFactorAlpha;
479 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
480 value = static_cast<int>( destFactorRgb );
483 case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
485 BlendingFactor::Type srcFactorRgb;
486 BlendingFactor::Type destFactorRgb;
487 BlendingFactor::Type srcFactorAlpha;
488 BlendingFactor::Type destFactorAlpha;
489 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
490 value = static_cast<int>( srcFactorAlpha );
493 case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
495 BlendingFactor::Type srcFactorRgb;
496 BlendingFactor::Type destFactorRgb;
497 BlendingFactor::Type srcFactorAlpha;
498 BlendingFactor::Type destFactorAlpha;
499 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
500 value = static_cast<int>( destFactorAlpha );
503 case Dali::Renderer::Property::BLENDING_COLOR:
507 value = *mBlendColor;
511 value = Color::TRANSPARENT;
515 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
517 value = IsPreMultipliedAlphaEnabled();
524 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
529 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
534 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
536 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
537 const SceneGraph::PropertyBase* property = NULL;
541 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
543 &Renderer::FindAnimatableProperty,
544 &Renderer::FindCustomProperty,
551 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
553 const PropertyInputImpl* property = NULL;
557 const SceneGraph::PropertyBase* baseProperty =
558 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
559 &Renderer::FindAnimatableProperty,
560 &Renderer::FindCustomProperty,
562 property = static_cast<const PropertyInputImpl*>( baseProperty );
568 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
570 return Property::INVALID_COMPONENT_INDEX;
573 bool Renderer::OnStage() const
575 return mOnStageCount > 0;
578 void Renderer::Connect()
580 if( mOnStageCount == 0 )
582 OnStageConnectMessage( GetEventThreadServices(), *mSceneObject );
583 mGeometryConnector.OnStageConnect();
584 mTextureSetConnector.OnStageConnect();
589 void Renderer::Disconnect()
592 if( mOnStageCount == 0 )
594 OnStageDisconnectMessage( GetEventThreadServices(), *mSceneObject);
595 mGeometryConnector.OnStageDisconnect();
596 mTextureSetConnector.OnStageDisconnect();
601 : mSceneObject(NULL),
605 mFaceCullingMode(Dali::Renderer::NONE),
606 mBlendingMode( Dali::BlendingMode::AUTO ),
608 mPremultipledAlphaEnabled( false )
612 void Renderer::Initialize()
614 EventThreadServices& eventThreadServices = GetEventThreadServices();
615 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
617 mSceneObject = SceneGraph::Renderer::New();
618 AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
620 eventThreadServices.RegisterObject( this );
623 Renderer::~Renderer()
625 if( EventThreadServices::IsCoreRunning() )
627 EventThreadServices& eventThreadServices = GetEventThreadServices();
628 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
629 RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
631 eventThreadServices.UnregisterObject( this );
635 } // namespace Internal