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 Geometry* Renderer::GetGeometry() const
65 return mGeometryConnector.Get().Get();
68 void Renderer::SetMaterial( Material& material )
70 mMaterialConnector.Set( material, OnStage() );
71 const SceneGraph::Material* materialSceneObject = material.GetMaterialSceneObject();
72 SetMaterialMessage( GetEventThreadServices(), *mSceneObject, *materialSceneObject );
75 Material* Renderer::GetMaterial() const
77 return mMaterialConnector.Get().Get();
80 void Renderer::SetDepthIndex( int depthIndex )
82 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
85 int Renderer::GetCurrentDepthIndex() const
90 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
91 depthIndex = mSceneObject->mDepthIndex[bufferIndex];
96 SceneGraph::RendererAttachment* Renderer::GetRendererSceneObject()
101 unsigned int Renderer::GetDefaultPropertyCount() const
103 return RENDERER_IMPL.GetDefaultPropertyCount();
106 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
108 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
111 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
113 return RENDERER_IMPL.GetDefaultPropertyName( index );
116 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
118 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
121 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
123 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
126 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
128 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
131 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
133 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
136 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
138 return RENDERER_IMPL.GetDefaultPropertyType( index );
141 void Renderer::SetDefaultProperty( Property::Index index,
142 const Property::Value& propertyValue )
146 case Dali::Renderer::Property::DEPTH_INDEX:
148 SetDepthIndex( propertyValue.Get<int>() );
154 void Renderer::SetSceneGraphProperty( Property::Index index,
155 const PropertyMetadata& entry,
156 const Property::Value& value )
158 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
159 OnPropertySet(index, value);
162 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
164 Property::Value value;
167 case Dali::Renderer::Property::DEPTH_INDEX:
169 value = GetCurrentDepthIndex();
176 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
181 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
186 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
188 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
189 const SceneGraph::PropertyBase* property = NULL;
193 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
195 &Renderer::FindAnimatableProperty,
196 &Renderer::FindCustomProperty,
199 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
203 case Dali::Renderer::Property::DEPTH_INDEX:
205 property = &mSceneObject->mDepthIndex;
215 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
217 const PropertyInputImpl* property = NULL;
221 const SceneGraph::PropertyBase* baseProperty =
222 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
223 &Renderer::FindAnimatableProperty,
224 &Renderer::FindCustomProperty,
226 property = static_cast<const PropertyInputImpl*>( baseProperty );
228 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
232 case Dali::Renderer::Property::DEPTH_INDEX:
234 property = &mSceneObject->mDepthIndex;
244 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
246 return Property::INVALID_COMPONENT_INDEX;
249 bool Renderer::OnStage() const
254 void Renderer::Connect()
256 // @todo: MESH_REWORK : check this
257 mGeometryConnector.OnStageConnect();
258 mMaterialConnector.OnStageConnect();
262 void Renderer::Disconnect()
264 // @todo: MESH_REWORK : check this
265 mGeometryConnector.OnStageDisconnect();
266 mMaterialConnector.OnStageDisconnect();
271 : mSceneObject(NULL),
276 void Renderer::Initialize()
278 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
279 EventThreadServices& eventThreadServices = GetEventThreadServices();
280 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
282 // Transfer object ownership of scene-object to message
283 mSceneObject = SceneGraph::RendererAttachment::New();
285 // Send message to update to connect to scene graph:
286 AttachToSceneGraphMessage( updateManager, mSceneObject );
289 Renderer::~Renderer()
293 } // namespace Internal