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/actors/renderer-impl.h> // Dali::Internal::Renderer
22 #include <dali/public-api/actors/renderer.h> // Dali::Renderer
23 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
24 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
25 #include <dali/internal/event/common/property-input-impl.h>
26 #include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
27 #include <dali/internal/update/manager/update-manager.h>
38 * |name |type |writable|animatable|constraint-input|enum for index-checking|
40 DALI_PROPERTY_TABLE_BEGIN
41 DALI_PROPERTY( "depth-index", INTEGER, true, true, true, Dali::Renderer::Property::DEPTH_INDEX )
42 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
44 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
46 } // unnamed namespace
48 RendererPtr Renderer::New()
50 RendererPtr rendererPtr( new Renderer() );
51 rendererPtr->Initialize();
55 void Renderer::SetGeometry( Geometry& geometry )
57 mGeometryConnector.Set( geometry, OnStage() );
58 const SceneGraph::Geometry* geometrySceneObject = geometry.GetGeometrySceneObject();
60 SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
63 void Renderer::SetMaterial( Material& material )
65 mMaterialConnector.Set( material, OnStage() );
66 const SceneGraph::Material* materialSceneObject = material.GetMaterialSceneObject();
67 SetMaterialMessage( GetEventThreadServices(), *mSceneObject, *materialSceneObject );
70 void Renderer::SetDepthIndex( int depthIndex )
72 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
75 int Renderer::GetCurrentDepthIndex() const
80 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
81 depthIndex = mSceneObject->mDepthIndex[bufferIndex];
86 SceneGraph::RendererAttachment* Renderer::GetRendererSceneObject()
91 unsigned int Renderer::GetDefaultPropertyCount() const
93 return RENDERER_IMPL.GetDefaultPropertyCount();
96 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
98 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
101 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
103 return RENDERER_IMPL.GetDefaultPropertyName( index );
106 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
108 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
111 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
113 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
116 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
118 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
121 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
123 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
126 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
128 return RENDERER_IMPL.GetDefaultPropertyType( index );
131 void Renderer::SetDefaultProperty( Property::Index index,
132 const Property::Value& propertyValue )
136 case Dali::Renderer::Property::DEPTH_INDEX:
138 SetDepthIndex( propertyValue.Get<int>() );
144 void Renderer::SetSceneGraphProperty( Property::Index index,
145 const PropertyMetadata& entry,
146 const Property::Value& value )
148 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
149 OnPropertySet(index, value);
152 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
154 Property::Value value;
157 case Dali::Renderer::Property::DEPTH_INDEX:
159 value = GetCurrentDepthIndex();
166 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
171 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
176 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
178 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
179 const SceneGraph::PropertyBase* property = NULL;
183 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
185 &Renderer::FindAnimatableProperty,
186 &Renderer::FindCustomProperty,
189 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
193 case Dali::Renderer::Property::DEPTH_INDEX:
195 property = &mSceneObject->mDepthIndex;
205 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
207 const PropertyInputImpl* property = NULL;
211 const SceneGraph::PropertyBase* baseProperty =
212 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
213 &Renderer::FindAnimatableProperty,
214 &Renderer::FindCustomProperty,
216 property = static_cast<const PropertyInputImpl*>( baseProperty );
218 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
222 case Dali::Renderer::Property::DEPTH_INDEX:
224 property = &mSceneObject->mDepthIndex;
234 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
236 return Property::INVALID_COMPONENT_INDEX;
239 bool Renderer::OnStage() const
244 void Renderer::Connect()
246 // @todo: MESH_REWORK : check this
247 mGeometryConnector.OnStageConnect();
248 mMaterialConnector.OnStageConnect();
252 void Renderer::Disconnect()
254 // @todo: MESH_REWORK : check this
255 mGeometryConnector.OnStageDisconnect();
256 mMaterialConnector.OnStageDisconnect();
261 : mSceneObject(NULL),
266 void Renderer::Initialize()
268 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
269 EventThreadServices& eventThreadServices = GetEventThreadServices();
270 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
272 // Transfer object ownership of scene-object to message
273 mSceneObject = SceneGraph::RendererAttachment::New();
275 // Send message to update to connect to scene graph:
276 AttachToSceneGraphMessage( updateManager, mSceneObject );
279 Renderer::~Renderer()
283 } // namespace Internal