X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Frendering%2Fsampler-impl.cpp;h=d6e8af0dfc763872cfebb66b9534c0e716aab144;hb=14502a507909174b52e486a0ee7516cb26e6ad45;hp=9c6190448506f0ca70627eededac5198b321248c;hpb=b4861e432ab21269f673387dd455e31c6346c4da;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/rendering/sampler-impl.cpp b/dali/internal/event/rendering/sampler-impl.cpp index 9c61904..d6e8af0 100644 --- a/dali/internal/event/rendering/sampler-impl.cpp +++ b/dali/internal/event/rendering/sampler-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,358 +19,65 @@ #include // Dali::Internal::Sampler // INTERNAL INCLUDES -#include -#include // Dali::Internal::Sampler -#include // Dali::Internal::ObjectHelper -#include // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END -#include // Dali::Internal::SceneGraph::Sampler +#include #include +#include namespace Dali { namespace Internal { -namespace -{ - -/** - * |name |type |writable|animatable|constraint-input|enum for index-checking| - */ -DALI_PROPERTY_TABLE_BEGIN -DALI_PROPERTY( "minification-filter", STRING, true, false, true, Dali::Sampler::Property::MINIFICATION_FILTER ) -DALI_PROPERTY( "magnification-filter", STRING, true, false, true, Dali::Sampler::Property::MAGNIGICATION_FILTER ) -DALI_PROPERTY( "u-wrap", STRING, true, false, true, Dali::Sampler::Property::U_WRAP ) -DALI_PROPERTY( "v-wrap", STRING, true, false, true, Dali::Sampler::Property::V_WRAP ) -DALI_PROPERTY( "affects-transparency", BOOLEAN, true, false, true, Dali::Sampler::Property::AFFECTS_TRANSPARENCY ) -DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX ) - -const ObjectImplHelper SAMPLER_IMPL = { DEFAULT_PROPERTY_DETAILS }; - -BaseHandle Create() -{ - return Dali::BaseHandle(); -} - -TypeRegistration mType( typeid( Dali::Sampler ), typeid( Dali::Handle ), Create ); - -} // unnamed namespace - -SamplerPtr Sampler::New( const std::string& textureUnitUniformName ) +SamplerPtr Sampler::New( ) { SamplerPtr sampler( new Sampler() ); - sampler->Initialize( textureUnitUniformName ); + sampler->Initialize(); return sampler; } -void Sampler::SetTextureUnitUniformName( const std::string& name ) -{ - SetTextureUnitUniformNameMessage( GetEventThreadServices(), *mSceneObject, name); -} - -void Sampler::SetImage( ImagePtr& image ) -{ - // Keep a reference to the image object - mImageConnector.Set( image, OnStage() ); - - // sceneObject is being used in a separate thread; queue a message to set - if( mOnStage ) - { - unsigned int resourceId = image->GetResourceId(); - if( resourceId != 0 ) - { - SetTextureMessage( GetEventThreadServices(), *mSceneObject, resourceId ); - } - } -} - -ImagePtr Sampler::GetImage() const -{ - return mImageConnector.Get(); -} - -void Sampler::SetFilterMode( Dali::Sampler::FilterMode minFilter, Dali::Sampler::FilterMode magFilter ) -{ - if( NULL != mSceneObject ) - { - SetFilterModeMessage( GetEventThreadServices(), *mSceneObject, minFilter, magFilter ); - } -} - -void Sampler::SetWrapMode( Dali::Sampler::WrapMode uWrap, Dali::Sampler::WrapMode vWrap ) -{ - if( NULL != mSceneObject ) - { - SetWrapModeMessage( GetEventThreadServices(), *mSceneObject, uWrap, vWrap ); - } -} - -void Sampler::SetAffectsTransparency( bool affectsTransparency ) -{ - if( NULL != mSceneObject ) - { - SceneGraph::DoubleBufferedPropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mAffectsTransparency, &SceneGraph::DoubleBufferedProperty::Set, affectsTransparency ); - } -} - -const SceneGraph::Sampler* Sampler::GetSamplerSceneObject() const -{ - return mSceneObject; -} - -unsigned int Sampler::GetDefaultPropertyCount() const -{ - return SAMPLER_IMPL.GetDefaultPropertyCount(); -} - -void Sampler::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const -{ - SAMPLER_IMPL.GetDefaultPropertyIndices( indices ); -} - -const char* Sampler::GetDefaultPropertyName(Property::Index index) const -{ - return SAMPLER_IMPL.GetDefaultPropertyName( index ); -} - -Property::Index Sampler::GetDefaultPropertyIndex( const std::string& name ) const -{ - return SAMPLER_IMPL.GetDefaultPropertyIndex( name ); -} - -bool Sampler::IsDefaultPropertyWritable( Property::Index index ) const +void Sampler::SetFilterMode( Dali::FilterMode::Type minFilter, Dali::FilterMode::Type magFilter ) { - return SAMPLER_IMPL.IsDefaultPropertyWritable( index ); -} - -bool Sampler::IsDefaultPropertyAnimatable( Property::Index index ) const -{ - return SAMPLER_IMPL.IsDefaultPropertyAnimatable( index ); -} - -bool Sampler::IsDefaultPropertyAConstraintInput( Property::Index index ) const -{ - return SAMPLER_IMPL.IsDefaultPropertyAConstraintInput( index ); -} - -Property::Type Sampler::GetDefaultPropertyType( Property::Index index ) const -{ - return SAMPLER_IMPL.GetDefaultPropertyType( index ); -} - -void Sampler::SetDefaultProperty( Property::Index index, - const Property::Value& propertyValue ) -{ - switch( index ) - { - case Dali::Sampler::Property::MINIFICATION_FILTER: - { - SceneGraph::DoubleBufferedPropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mMinFilter, &SceneGraph::DoubleBufferedProperty::Set, propertyValue.Get() ); - break; - } - case Dali::Sampler::Property::MAGNIGICATION_FILTER: - { - SceneGraph::DoubleBufferedPropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mMagFilter, &SceneGraph::DoubleBufferedProperty::Set, propertyValue.Get() ); - break; - } - case Dali::Sampler::Property::U_WRAP: - { - SceneGraph::DoubleBufferedPropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mUWrapMode, &SceneGraph::DoubleBufferedProperty::Set, propertyValue.Get() ); - break; - } - case Dali::Sampler::Property::V_WRAP: - { - SceneGraph::DoubleBufferedPropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mVWrapMode, &SceneGraph::DoubleBufferedProperty::Set, propertyValue.Get() ); - break; - } - case Dali::Sampler::Property::AFFECTS_TRANSPARENCY: - { - SceneGraph::DoubleBufferedPropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mAffectsTransparency, &SceneGraph::DoubleBufferedProperty::Set, propertyValue.Get() ); - break; - } - } -} - -void Sampler::SetSceneGraphProperty( Property::Index index, - const PropertyMetadata& entry, - const Property::Value& value ) -{ - SAMPLER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value ); - OnPropertySet(index, value); -} - -Property::Value Sampler::GetDefaultProperty( Property::Index index ) const -{ - BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex(); - Property::Value value; - - switch( index ) - { - case Dali::Sampler::Property::MINIFICATION_FILTER: - { - value = mSceneObject->mMinFilter[bufferIndex]; - break; - } - case Dali::Sampler::Property::MAGNIGICATION_FILTER: - { - value = mSceneObject->mMagFilter[bufferIndex]; - break; - } - case Dali::Sampler::Property::U_WRAP: - { - value = mSceneObject->mUWrapMode[bufferIndex]; - break; - } - case Dali::Sampler::Property::V_WRAP: - { - value = mSceneObject->mVWrapMode[bufferIndex]; - break; - } - case Dali::Sampler::Property::AFFECTS_TRANSPARENCY: - { - value = mSceneObject->mAffectsTransparency[bufferIndex]; - break; - } - } - return value; -} - -const SceneGraph::PropertyOwner* Sampler::GetPropertyOwner() const -{ - return mSceneObject; -} - -const SceneGraph::PropertyOwner* Sampler::GetSceneObject() const -{ - return mSceneObject; -} - -const SceneGraph::PropertyBase* Sampler::GetSceneObjectAnimatableProperty( Property::Index index ) const -{ - DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" ); - - const SceneGraph::PropertyBase* property = NULL; - - if( OnStage() ) + if( NULL != mRenderObject ) { - property = SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this, - &Sampler::FindAnimatableProperty, - &Sampler::FindCustomProperty, - index ); - - if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT ) - { - // No animatable default props - DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" ); - } + SetFilterModeMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, static_cast< unsigned int >( minFilter ), static_cast< unsigned int >( magFilter ) ); } - - return property; } -const PropertyInputImpl* Sampler::GetSceneObjectInputProperty( Property::Index index ) const +void Sampler::SetWrapMode( Dali::WrapMode::Type rWrap, Dali::WrapMode::Type sWrap, Dali::WrapMode::Type tWrap ) { - const PropertyInputImpl* property = NULL; - - if( OnStage() ) + if( NULL != mRenderObject ) { - const SceneGraph::PropertyBase* baseProperty = - SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this, - &Sampler::FindAnimatableProperty, - &Sampler::FindCustomProperty, - index ); - property = static_cast( baseProperty ); - - if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT ) - { - switch( index ) - { - case Dali::Sampler::Property::MINIFICATION_FILTER: - { - property = &mSceneObject->mMinFilter; - break; - } - case Dali::Sampler::Property::MAGNIGICATION_FILTER: - { - property = &mSceneObject->mMagFilter; - break; - } - case Dali::Sampler::Property::U_WRAP: - { - property = &mSceneObject->mUWrapMode; - break; - } - case Dali::Sampler::Property::V_WRAP: - { - property = &mSceneObject->mVWrapMode; - break; - } - case Dali::Sampler::Property::AFFECTS_TRANSPARENCY: - { - property = &mSceneObject->mAffectsTransparency; - break; - } - } - } + SetWrapModeMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, static_cast< unsigned int >( rWrap ), static_cast< unsigned int >( sWrap ), static_cast< unsigned int >( tWrap ) ); } - - return property; } -int Sampler::GetPropertyComponentIndex( Property::Index index ) const +Render::Sampler* Sampler::GetSamplerRenderObject() { - return Property::INVALID_COMPONENT_INDEX; + return mRenderObject; } -bool Sampler::OnStage() const -{ - return mOnStage; -} - -void Sampler::Connect() -{ - mOnStage = true; - - mImageConnector.OnStageConnect(); - - // sceneObject is being used in a separate thread; queue a message to set - unsigned int resourceId = mImageConnector.Get()->GetResourceId(); - SetTextureMessage( GetEventThreadServices(), *mSceneObject, resourceId ); -} - -void Sampler::Disconnect() -{ - mOnStage = false; - - mImageConnector.OnStageDisconnect(); -} Sampler::Sampler() -: mSceneObject( NULL ), - mOnStage( false ) +:mEventThreadServices( *Stage::GetCurrent() ), + mRenderObject( NULL ) { } -void Sampler::Initialize( const std::string& textureUnitUniformName ) +void Sampler::Initialize() { - EventThreadServices& eventThreadServices = GetEventThreadServices(); - SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); - - mSceneObject = new SceneGraph::Sampler( textureUnitUniformName ); - AddMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject ); + SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager(); - eventThreadServices.RegisterObject( this ); + mRenderObject = new Render::Sampler(); + OwnerPointer< Render::Sampler > transferOwnership( mRenderObject ); + AddSamplerMessage( updateManager, transferOwnership ); } Sampler::~Sampler() { - if( EventThreadServices::IsCoreRunning() ) + if( EventThreadServices::IsCoreRunning() && mRenderObject ) { - EventThreadServices& eventThreadServices = GetEventThreadServices(); - SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); - RemoveMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject ); - - eventThreadServices.UnregisterObject( this ); + SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager(); + RemoveSamplerMessage( updateManager, *mRenderObject ); } }