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/node-attachments/scene-graph-renderer-attachment.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( "depth-index", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
43 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
45 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
49 return Dali::BaseHandle();
52 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
54 } // unnamed namespace
56 RendererPtr Renderer::New()
58 RendererPtr rendererPtr( new Renderer() );
59 rendererPtr->Initialize();
63 void Renderer::SetGeometry( Geometry& geometry )
65 mGeometryConnector.Set( geometry, OnStage() );
66 const SceneGraph::Geometry* geometrySceneObject = geometry.GetGeometrySceneObject();
68 SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
71 Geometry* Renderer::GetGeometry() const
73 return mGeometryConnector.Get().Get();
76 void Renderer::SetMaterial( Material& material )
78 mMaterialConnector.Set( material, OnStage() );
79 const SceneGraph::Material* materialSceneObject = material.GetMaterialSceneObject();
80 SetMaterialMessage( GetEventThreadServices(), *mSceneObject, *materialSceneObject );
83 Material* Renderer::GetMaterial() const
85 return mMaterialConnector.Get().Get();
88 void Renderer::SetDepthIndex( int depthIndex )
90 if ( mDepthIndex != depthIndex )
92 mDepthIndex = depthIndex;
93 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
97 int Renderer::GetDepthIndex() const
102 SceneGraph::RendererAttachment* Renderer::GetRendererSceneObject()
107 unsigned int Renderer::GetDefaultPropertyCount() const
109 return RENDERER_IMPL.GetDefaultPropertyCount();
112 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
114 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
117 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
119 return RENDERER_IMPL.GetDefaultPropertyName( index );
122 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
124 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
127 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
129 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
132 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
134 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
137 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
139 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
142 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
144 return RENDERER_IMPL.GetDefaultPropertyType( index );
147 void Renderer::SetDefaultProperty( Property::Index index,
148 const Property::Value& propertyValue )
152 case Dali::Renderer::Property::DEPTH_INDEX:
154 SetDepthIndex( propertyValue.Get<int>() );
160 void Renderer::SetSceneGraphProperty( Property::Index index,
161 const PropertyMetadata& entry,
162 const Property::Value& value )
164 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
165 OnPropertySet(index, value);
168 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
170 Property::Value value;
173 case Dali::Renderer::Property::DEPTH_INDEX:
175 value = GetDepthIndex();
182 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
187 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
192 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
194 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
195 const SceneGraph::PropertyBase* property = NULL;
199 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
201 &Renderer::FindAnimatableProperty,
202 &Renderer::FindCustomProperty,
209 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
211 const PropertyInputImpl* property = NULL;
215 const SceneGraph::PropertyBase* baseProperty =
216 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
217 &Renderer::FindAnimatableProperty,
218 &Renderer::FindCustomProperty,
220 property = static_cast<const PropertyInputImpl*>( baseProperty );
226 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
228 return Property::INVALID_COMPONENT_INDEX;
231 bool Renderer::OnStage() const
236 void Renderer::Connect()
238 // @todo: MESH_REWORK : check this
239 mGeometryConnector.OnStageConnect();
240 mMaterialConnector.OnStageConnect();
244 void Renderer::Disconnect()
246 // @todo: MESH_REWORK : check this
247 mGeometryConnector.OnStageDisconnect();
248 mMaterialConnector.OnStageDisconnect();
253 : mSceneObject(NULL),
259 void Renderer::Initialize()
261 EventThreadServices& eventThreadServices = GetEventThreadServices();
262 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
264 // Transfer object ownership of scene-object to message
265 mSceneObject = SceneGraph::RendererAttachment::New();
267 // Send message to update to connect to scene graph:
268 AttachToSceneGraphMessage( updateManager, mSceneObject );
270 eventThreadServices.RegisterObject( this );
273 Renderer::~Renderer()
275 if( EventThreadServices::IsCoreRunning() )
277 EventThreadServices& eventThreadServices = GetEventThreadServices();
278 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
279 RemoveObjectMessage( updateManager, mSceneObject );
281 eventThreadServices.UnregisterObject( this );
285 } // namespace Internal