2 * Copyright (c) 2016 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/texture-set-impl.h> // Dali::Internal::TextureSet
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/devel-api/rendering/texture-set.h> // Dali::Internal::Render::TextureSet
27 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
28 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
29 #include <dali/internal/update/manager/update-manager.h>
30 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
40 const ObjectImplHelper<0> TEXTURE_SET_IMPL = { NULL };
44 return Dali::BaseHandle();
47 TypeRegistration mType( typeid( Dali::TextureSet ), typeid( Dali::Handle ), Create );
49 } // unnamed namespace
51 TextureSetPtr TextureSet::New()
53 TextureSetPtr textureSet( new TextureSet() );
54 textureSet->Initialize();
58 void TextureSet::SetImage( size_t index, ImagePtr image )
60 size_t textureCount( mTextures.size() );
61 if( index < textureCount )
63 if( mTextures[index].image && mOnStage )
65 mTextures[index].image->Disconnect();
70 mTextures.resize(index + 1);
71 for( size_t i(textureCount); i<=index; ++i )
73 mTextures[i].image = NULL;
74 mTextures[i].sampler = NULL;
77 mTextures[index].image = image;
86 SceneGraph::SetImageMessage( GetEventThreadServices(), *mSceneObject, index, image->GetResourceId() );
90 SceneGraph::SetImageMessage( GetEventThreadServices(), *mSceneObject, index, Integration::InvalidResourceId );
94 Image* TextureSet::GetImage( size_t index ) const
97 if( index < mTextures.size() )
99 result = mTextures[index].image.Get();
103 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
109 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
111 size_t textureCount( mTextures.size() );
112 if( textureCount < index + 1 )
114 mTextures.resize(index + 1);
115 for( size_t i(textureCount); i<=index; ++i )
117 mTextures[i].image = NULL;
118 mTextures[i].sampler = NULL;
122 mTextures[index].sampler = sampler;
124 Render::Sampler* renderSampler(0);
127 renderSampler = sampler->GetSamplerRenderObject();
130 SceneGraph::SetSamplerMessage( GetEventThreadServices(), *mSceneObject, index, renderSampler );
133 Sampler* TextureSet::GetSampler( size_t index ) const
136 if( index < mTextures.size() )
138 result = mTextures[index].sampler.Get();
142 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler");
148 size_t TextureSet::GetTextureCount() const
150 return mTextures.size();
153 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
158 unsigned int TextureSet::GetDefaultPropertyCount() const
160 return TEXTURE_SET_IMPL.GetDefaultPropertyCount();
163 void TextureSet::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
165 TEXTURE_SET_IMPL.GetDefaultPropertyIndices( indices );
168 const char* TextureSet::GetDefaultPropertyName(Property::Index index) const
170 return TEXTURE_SET_IMPL.GetDefaultPropertyName( index );
173 Property::Index TextureSet::GetDefaultPropertyIndex( const std::string& name ) const
175 return TEXTURE_SET_IMPL.GetDefaultPropertyIndex( name );
178 bool TextureSet::IsDefaultPropertyWritable( Property::Index index ) const
180 return TEXTURE_SET_IMPL.IsDefaultPropertyWritable( index );
183 bool TextureSet::IsDefaultPropertyAnimatable( Property::Index index ) const
185 return TEXTURE_SET_IMPL.IsDefaultPropertyAnimatable( index );
188 bool TextureSet::IsDefaultPropertyAConstraintInput( Property::Index index ) const
190 return TEXTURE_SET_IMPL.IsDefaultPropertyAConstraintInput( index );
193 Property::Type TextureSet::GetDefaultPropertyType( Property::Index index ) const
195 return TEXTURE_SET_IMPL.GetDefaultPropertyType( index );
198 void TextureSet::SetDefaultProperty( Property::Index index,
199 const Property::Value& propertyValue )
203 void TextureSet::SetSceneGraphProperty( Property::Index index,
204 const PropertyMetadata& entry,
205 const Property::Value& value )
207 TEXTURE_SET_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
208 OnPropertySet(index, value);
211 Property::Value TextureSet::GetDefaultProperty( Property::Index index ) const
213 Property::Value value;
217 const SceneGraph::PropertyOwner* TextureSet::GetPropertyOwner() const
222 const SceneGraph::PropertyOwner* TextureSet::GetSceneObject() const
227 const SceneGraph::PropertyBase* TextureSet::GetSceneObjectAnimatableProperty( Property::Index index ) const
229 PropertyMetadata* property = index >= PROPERTY_CUSTOM_START_INDEX ? static_cast<PropertyMetadata*>(FindCustomProperty( index )) : static_cast<PropertyMetadata*>(FindAnimatableProperty( index ));
230 DALI_ASSERT_ALWAYS( property && "Property index is invalid" );
231 return property->GetSceneGraphProperty();
234 const PropertyInputImpl* TextureSet::GetSceneObjectInputProperty( Property::Index index ) const
236 return GetSceneObjectAnimatableProperty( index );
239 int TextureSet::GetPropertyComponentIndex( Property::Index index ) const
241 return Property::INVALID_COMPONENT_INDEX;
244 bool TextureSet::OnStage() const
249 void TextureSet::Connect()
253 for( size_t i(0); i<mTextures.size(); ++i )
255 if( mTextures[i].image )
257 mTextures[i].image->Connect();
258 SceneGraph::SetImageMessage( GetEventThreadServices(), *mSceneObject, i, mTextures[i].image->GetResourceId() );
262 SceneGraph::SetImageMessage( GetEventThreadServices(), *mSceneObject, i, Integration::InvalidResourceId );
267 void TextureSet::Disconnect()
269 for( size_t i(0); i<mTextures.size(); ++i )
271 if( mTextures[i].image )
273 mTextures[i].image->Disconnect();
280 TextureSet::TextureSet()
281 : mSceneObject( NULL ),
287 void TextureSet::Initialize()
289 EventThreadServices& eventThreadServices = GetEventThreadServices();
290 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
292 mSceneObject = SceneGraph::TextureSet::New();
293 AddMessage( updateManager, updateManager.GetTexturesOwner(), *mSceneObject );
295 eventThreadServices.RegisterObject( this );
298 TextureSet::~TextureSet()
300 if( EventThreadServices::IsCoreRunning() )
302 EventThreadServices& eventThreadServices = GetEventThreadServices();
303 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
304 RemoveMessage( updateManager, updateManager.GetTexturesOwner(), *mSceneObject );
306 eventThreadServices.UnregisterObject( this );
310 } // namespace Internal