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/sampler-impl.h> // Dali::Internal::Sampler
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/devel-api/rendering/sampler.h> // Dali::Internal::Sampler
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/update/rendering/scene-graph-sampler.h> // Dali::Internal::SceneGraph::Sampler
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( "minification-filter", INTEGER, true, false, true, Dali::Sampler::Property::MINIFICATION_FILTER )
42 DALI_PROPERTY( "magnification-filter", INTEGER, true, false, true, Dali::Sampler::Property::MAGNIGICATION_FILTER )
43 DALI_PROPERTY( "u-wrap", INTEGER, true, false, true, Dali::Sampler::Property::U_WRAP )
44 DALI_PROPERTY( "v-wrap", INTEGER, true, false, true, Dali::Sampler::Property::V_WRAP )
45 DALI_PROPERTY( "affects-transparency", BOOLEAN, true, false, true, Dali::Sampler::Property::AFFECTS_TRANSPARENCY )
46 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
48 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> SAMPLER_IMPL = { DEFAULT_PROPERTY_DETAILS };
52 return Dali::BaseHandle();
55 TypeRegistration mType( typeid( Dali::Sampler ), typeid( Dali::Handle ), Create );
57 } // unnamed namespace
59 SamplerPtr Sampler::New( const std::string& textureUnitUniformName )
61 SamplerPtr sampler( new Sampler() );
62 sampler->Initialize( textureUnitUniformName );
66 void Sampler::SetTextureUnitUniformName( const std::string& name )
68 SetTextureUnitUniformNameMessage( GetEventThreadServices(), *mSceneObject, name);
71 void Sampler::SetImage( ImagePtr& image )
73 // Keep a reference to the image object
74 mImageConnector.Set( image, OnStage() );
76 // sceneObject is being used in a separate thread; queue a message to set
79 unsigned int resourceId = image->GetResourceId();
82 SetTextureMessage( GetEventThreadServices(), *mSceneObject, resourceId );
87 ImagePtr Sampler::GetImage() const
89 return mImageConnector.Get();
92 void Sampler::SetFilterMode( Dali::Sampler::FilterMode minFilter, Dali::Sampler::FilterMode magFilter )
94 if( NULL != mSceneObject )
96 SetFilterModeMessage( GetEventThreadServices(), *mSceneObject, minFilter, magFilter );
100 void Sampler::SetWrapMode( Dali::Sampler::WrapMode uWrap, Dali::Sampler::WrapMode vWrap )
102 if( NULL != mSceneObject )
104 SetWrapModeMessage( GetEventThreadServices(), *mSceneObject, uWrap, vWrap );
108 void Sampler::SetAffectsTransparency( bool affectsTransparency )
110 if( NULL != mSceneObject )
112 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mAffectsTransparency, &SceneGraph::DoubleBufferedProperty<bool>::Set, affectsTransparency );
116 const SceneGraph::Sampler* Sampler::GetSamplerSceneObject() const
121 SceneGraph::Sampler* Sampler::GetSamplerSceneObject()
126 unsigned int Sampler::GetDefaultPropertyCount() const
128 return SAMPLER_IMPL.GetDefaultPropertyCount();
131 void Sampler::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
133 SAMPLER_IMPL.GetDefaultPropertyIndices( indices );
136 const char* Sampler::GetDefaultPropertyName(Property::Index index) const
138 return SAMPLER_IMPL.GetDefaultPropertyName( index );
141 Property::Index Sampler::GetDefaultPropertyIndex( const std::string& name ) const
143 return SAMPLER_IMPL.GetDefaultPropertyIndex( name );
146 bool Sampler::IsDefaultPropertyWritable( Property::Index index ) const
148 return SAMPLER_IMPL.IsDefaultPropertyWritable( index );
151 bool Sampler::IsDefaultPropertyAnimatable( Property::Index index ) const
153 return SAMPLER_IMPL.IsDefaultPropertyAnimatable( index );
156 bool Sampler::IsDefaultPropertyAConstraintInput( Property::Index index ) const
158 return SAMPLER_IMPL.IsDefaultPropertyAConstraintInput( index );
161 Property::Type Sampler::GetDefaultPropertyType( Property::Index index ) const
163 return SAMPLER_IMPL.GetDefaultPropertyType( index );
166 void Sampler::SetDefaultProperty( Property::Index index,
167 const Property::Value& propertyValue )
171 case Dali::Sampler::Property::MINIFICATION_FILTER:
173 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mMinFilter, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
176 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
178 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mMagFilter, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
181 case Dali::Sampler::Property::U_WRAP:
183 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mUWrapMode, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
186 case Dali::Sampler::Property::V_WRAP:
188 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mVWrapMode, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
191 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
193 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mAffectsTransparency, &SceneGraph::DoubleBufferedProperty<bool>::Set, propertyValue.Get<bool>() );
199 void Sampler::SetSceneGraphProperty( Property::Index index,
200 const PropertyMetadata& entry,
201 const Property::Value& value )
203 SAMPLER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
204 OnPropertySet(index, value);
207 Property::Value Sampler::GetDefaultProperty( Property::Index index ) const
209 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
210 Property::Value value;
214 case Dali::Sampler::Property::MINIFICATION_FILTER:
216 value = mSceneObject->mMinFilter[bufferIndex];
219 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
221 value = mSceneObject->mMagFilter[bufferIndex];
224 case Dali::Sampler::Property::U_WRAP:
226 value = mSceneObject->mUWrapMode[bufferIndex];
229 case Dali::Sampler::Property::V_WRAP:
231 value = mSceneObject->mVWrapMode[bufferIndex];
234 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
236 value = mSceneObject->mAffectsTransparency[bufferIndex];
243 const SceneGraph::PropertyOwner* Sampler::GetPropertyOwner() const
248 const SceneGraph::PropertyOwner* Sampler::GetSceneObject() const
253 const SceneGraph::PropertyBase* Sampler::GetSceneObjectAnimatableProperty( Property::Index index ) const
255 DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" );
257 const SceneGraph::PropertyBase* property = NULL;
261 property = SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this,
262 &Sampler::FindAnimatableProperty,
263 &Sampler::FindCustomProperty,
266 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
268 // No animatable default props
269 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
276 const PropertyInputImpl* Sampler::GetSceneObjectInputProperty( Property::Index index ) const
278 const PropertyInputImpl* property = NULL;
282 const SceneGraph::PropertyBase* baseProperty =
283 SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this,
284 &Sampler::FindAnimatableProperty,
285 &Sampler::FindCustomProperty,
287 property = static_cast<const PropertyInputImpl*>( baseProperty );
289 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
293 case Dali::Sampler::Property::MINIFICATION_FILTER:
295 property = &mSceneObject->mMinFilter;
298 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
300 property = &mSceneObject->mMagFilter;
303 case Dali::Sampler::Property::U_WRAP:
305 property = &mSceneObject->mUWrapMode;
308 case Dali::Sampler::Property::V_WRAP:
310 property = &mSceneObject->mVWrapMode;
313 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
315 property = &mSceneObject->mAffectsTransparency;
325 int Sampler::GetPropertyComponentIndex( Property::Index index ) const
327 return Property::INVALID_COMPONENT_INDEX;
330 bool Sampler::OnStage() const
335 void Sampler::Connect()
339 mImageConnector.OnStageConnect();
341 // sceneObject is being used in a separate thread; queue a message to set
342 unsigned int resourceId = mImageConnector.Get()->GetResourceId();
343 SetTextureMessage( GetEventThreadServices(), *mSceneObject, resourceId );
346 void Sampler::Disconnect()
350 mImageConnector.OnStageDisconnect();
354 : mSceneObject( NULL ),
359 void Sampler::Initialize( const std::string& textureUnitUniformName )
361 EventThreadServices& eventThreadServices = GetEventThreadServices();
362 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
364 mSceneObject = new SceneGraph::Sampler( textureUnitUniformName );
365 AddMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject );
367 eventThreadServices.RegisterObject( this );
372 if( EventThreadServices::IsCoreRunning() )
374 EventThreadServices& eventThreadServices = GetEventThreadServices();
375 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
376 RemoveMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject );
378 eventThreadServices.UnregisterObject( this );
382 } // namespace Internal