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 "control-renderer-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/control-renderer-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 ControlRenderer::ControlRenderer( RendererFactoryCache& factoryCache )
49 : mImpl( new Impl() ),
50 mFactoryCache( factoryCache )
54 ControlRenderer::~ControlRenderer()
59 void ControlRenderer::Initialize( Actor& actor, const Property::Map& propertyMap )
61 if( mImpl->mCustomShader )
63 mImpl->mCustomShader->SetPropertyMap( propertyMap );
67 Property::Value* customShaderValue = propertyMap.Find( CUSTOM_SHADER );
68 if( customShaderValue )
70 Property::Map customShader;
71 if( customShaderValue->Get( customShader ) )
73 mImpl->mCustomShader = new Impl::CustomShader( propertyMap );
77 DoInitialize( actor, propertyMap );
80 void ControlRenderer::SetSize( const Vector2& size )
85 const Vector2& ControlRenderer::GetSize() const
90 void ControlRenderer::GetNaturalSize( Vector2& naturalSize ) const
92 naturalSize = Vector2::ZERO;
95 void ControlRenderer::SetClipRect( const Rect<int>& clipRect )
99 void ControlRenderer::SetOffset( const Vector2& offset )
101 mImpl->mOffset = offset;
104 void ControlRenderer::SetDepthIndex( float index )
106 mImpl->mDepthIndex = index;
107 if( mImpl->mRenderer )
109 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
113 float ControlRenderer::GetDepthIndex() const
115 return mImpl->mDepthIndex;
118 void ControlRenderer::SetOnStage( Actor& actor )
120 DoSetOnStage( actor );
122 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
123 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
124 actor.AddRenderer( mImpl->mRenderer );
125 mImpl->mFlags |= Impl::IS_ON_STAGE;
128 void ControlRenderer::SetOffStage( Actor& actor )
132 DoSetOffStage( actor );
134 mImpl->mFlags &= ~Impl::IS_ON_STAGE;
138 void ControlRenderer::EnablePreMultipliedAlpha( bool preMultipled )
142 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
146 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
149 if( mImpl->mRenderer )
151 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultipled);
155 bool ControlRenderer::IsPreMultipliedAlphaEnabled() const
157 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
160 void ControlRenderer::DoSetOnStage( Actor& actor )
164 void ControlRenderer::DoSetOffStage( Actor& actor )
166 actor.RemoveRenderer( mImpl->mRenderer );
167 mImpl->mRenderer.Reset();
170 void ControlRenderer::CreatePropertyMap( Property::Map& map ) const
172 DoCreatePropertyMap( map );
174 if( mImpl->mCustomShader )
176 mImpl->mCustomShader->CreatePropertyMap( map );
180 bool ControlRenderer::GetIsOnStage() const
182 return mImpl->mFlags & Impl::IS_ON_STAGE;
185 bool ControlRenderer::GetIsFromCache() const
187 return mImpl->mFlags & Impl::IS_FROM_CACHE;
190 } // namespace Internal
192 } // namespace Toolkit