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 "visual-impl.h"
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/internal/controls/renderers/visual-data-impl.h>
31 const char * const CUSTOM_SHADER( "shader" );
32 const char * const CUSTOM_VERTEX_SHADER( "vertexShader" );
33 const char * const CUSTOM_FRAGMENT_SHADER( "fragmentShader" );
34 const char * const CUSTOM_SUBDIVIDE_GRID_X( "subdivideGridX" );
35 const char * const CUSTOM_SUBDIVIDE_GRID_Y( "subdivideGridY" );
36 const char * const CUSTOM_SHADER_HINTS( "hints" ); ///< type INTEGER; (bitfield) values from enum Shader::Hints
48 Visual::Visual( VisualFactoryCache& factoryCache )
49 : mImpl( new Impl() ),
50 mFactoryCache( factoryCache )
59 void Visual::SetCustomShader( const Property::Map& shaderMap )
61 if( mImpl->mCustomShader )
63 mImpl->mCustomShader->SetPropertyMap( shaderMap );
67 mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
71 void Visual::Initialize( Actor& actor, const Property::Map& propertyMap )
73 Property::Value* customShaderValue = propertyMap.Find( CUSTOM_SHADER );
74 if( customShaderValue )
76 Property::Map shaderMap;
77 if( customShaderValue->Get( shaderMap ) )
79 SetCustomShader( shaderMap );
83 DoInitialize( actor, propertyMap );
86 void Visual::SetSize( const Vector2& size )
91 const Vector2& Visual::GetSize() const
96 void Visual::GetNaturalSize( Vector2& naturalSize ) const
98 naturalSize = Vector2::ZERO;
101 void Visual::SetClipRect( const Rect<int>& clipRect )
105 void Visual::SetOffset( const Vector2& offset )
107 mImpl->mOffset = offset;
110 void Visual::SetDepthIndex( float index )
112 mImpl->mDepthIndex = index;
113 if( mImpl->mRenderer )
115 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
119 float Visual::GetDepthIndex() const
121 return mImpl->mDepthIndex;
124 void Visual::SetOnStage( Actor& actor )
126 DoSetOnStage( actor );
128 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
129 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
130 actor.AddRenderer( mImpl->mRenderer );
131 mImpl->mFlags |= Impl::IS_ON_STAGE;
134 void Visual::SetOffStage( Actor& actor )
138 DoSetOffStage( actor );
140 mImpl->mFlags &= ~Impl::IS_ON_STAGE;
144 void Visual::EnablePreMultipliedAlpha( bool preMultipled )
148 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
152 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
155 if( mImpl->mRenderer )
157 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultipled);
161 bool Visual::IsPreMultipliedAlphaEnabled() const
163 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
166 void Visual::DoSetOnStage( Actor& actor )
170 void Visual::DoSetOffStage( Actor& actor )
172 actor.RemoveRenderer( mImpl->mRenderer );
173 mImpl->mRenderer.Reset();
176 void Visual::CreatePropertyMap( Property::Map& map ) const
178 DoCreatePropertyMap( map );
180 if( mImpl->mCustomShader )
182 mImpl->mCustomShader->CreatePropertyMap( map );
186 bool Visual::GetIsOnStage() const
188 return mImpl->mFlags & Impl::IS_ON_STAGE;
191 bool Visual::GetIsFromCache() const
193 return mImpl->mFlags & Impl::IS_FROM_CACHE;
196 } // namespace Internal
198 } // namespace Toolkit