Removed unused CullFace features for ImageActor
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / image-actor-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/actors/image-actor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/animation/constraints.h> // for EqualToConstraint
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/devel-api/scripting/scripting.h>
28 #include <dali/internal/event/animation/constraint-impl.h>
29 #include <dali/internal/event/common/property-helper.h>
30 #include <dali/internal/event/effects/shader-effect-impl.h>
31 #include <dali/internal/event/images/image-connector.h>
32 #include <dali/internal/event/images/nine-patch-image-impl.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
40 namespace
41 {
42
43 // Properties
44
45 //              Name           Type   writable animatable constraint-input  enum for index-checking
46 DALI_PROPERTY_TABLE_BEGIN
47 DALI_PROPERTY( "pixelArea",    RECTANGLE, true,    false,   true,    Dali::ImageActor::Property::PIXEL_AREA )
48 DALI_PROPERTY( "style",        STRING,    true,    false,   true,    Dali::ImageActor::Property::STYLE      )
49 DALI_PROPERTY( "border",       VECTOR4,   true,    false,   true,    Dali::ImageActor::Property::BORDER     )
50 DALI_PROPERTY( "image",        MAP,       true,    false,   false,   Dali::ImageActor::Property::IMAGE      )
51 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX )
52
53 BaseHandle Create()
54 {
55   return Dali::ImageActor::New();
56 }
57
58 TypeRegistration mType( typeid( Dali::ImageActor ), typeid( Dali::Actor ), Create );
59
60 struct GridVertex
61 {
62   GridVertex( float positionX, float positionY, const Vector2& size )
63   : mPosition( positionX*size.x, positionY*size.y, 0.f ),
64     mTextureCoord( positionX+0.5f, positionY+0.5f )
65   {
66   }
67
68   Vector3 mPosition;
69   Vector2 mTextureCoord;
70 };
71
72 GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight, const Vector2& size )
73 {
74   // Create vertices
75   std::vector< GridVertex > vertices;
76   vertices.reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
77
78   for( unsigned int y = 0u; y < gridHeight + 1; ++y )
79   {
80     float yPos = (float)y / gridHeight;
81     for( unsigned int x = 0u; x < gridWidth + 1; ++x )
82     {
83       float xPos = (float)x / gridWidth;
84       vertices.push_back( GridVertex( xPos - 0.5f, yPos - 0.5f, size ) );
85     }
86   }
87
88   // Create indices
89   Vector< unsigned int > indices;
90   indices.Reserve( ( gridWidth + 2 ) * gridHeight * 2 - 2);
91
92   for( unsigned int row = 0u; row < gridHeight; ++row )
93   {
94     unsigned int rowStartIndex = row*(gridWidth+1u);
95     unsigned int nextRowStartIndex = rowStartIndex + gridWidth +1u;
96
97     if( row != 0u ) // degenerate index on non-first row
98     {
99       indices.PushBack( rowStartIndex );
100     }
101
102     for( unsigned int column = 0u; column < gridWidth+1u; column++) // main strip
103     {
104       indices.PushBack( rowStartIndex + column);
105       indices.PushBack( nextRowStartIndex + column);
106     }
107
108     if( row != gridHeight-1u ) // degenerate index on non-last row
109     {
110       indices.PushBack( nextRowStartIndex + gridWidth );
111     }
112   }
113
114   Property::Map vertexFormat;
115   vertexFormat[ "aPosition" ] = Property::VECTOR3;
116   vertexFormat[ "aTexCoord" ] = Property::VECTOR2;
117   PropertyBufferPtr vertexPropertyBuffer = PropertyBuffer::New( vertexFormat );
118   if( vertices.size() > 0 )
119   {
120     vertexPropertyBuffer->SetData( &vertices[ 0 ], vertices.size() );
121   }
122
123   Property::Map indexFormat;
124   indexFormat[ "indices" ] = Property::INTEGER;
125   PropertyBufferPtr indexPropertyBuffer = PropertyBuffer::New( indexFormat );
126   if( indices.Size() > 0 )
127   {
128     indexPropertyBuffer->SetData( &indices[ 0 ], indices.Size() );
129   }
130
131   // Create the geometry object
132   GeometryPtr geometry = Geometry::New();
133   geometry->AddVertexBuffer( *vertexPropertyBuffer );
134   geometry->SetIndexBuffer( *indexPropertyBuffer );
135   geometry->SetGeometryType( Dali::Geometry::TRIANGLE_STRIP );
136
137   return geometry;
138 }
139
140 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
141   attribute mediump vec3 aPosition;\n
142   attribute mediump vec2 aTexCoord;\n
143   varying mediump vec2 vTexCoord;\n
144   uniform mediump mat4 uMvpMatrix;\n
145   uniform mediump vec3 uSize;\n
146   uniform mediump vec4 sTextureRect;\n
147   \n
148   void main()\n
149   {\n
150     gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n
151     vTexCoord = aTexCoord;\n
152   }\n
153 );
154
155 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
156   varying mediump vec2 vTexCoord;\n
157   uniform sampler2D sTexture;\n
158   uniform lowp vec4 uColor;\n
159   \n
160   void main()\n
161   {\n
162     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
163   }\n
164 );
165
166 const char * const TEXTURE_RECT_UNIFORM_NAME( "sTextureRect" );
167
168 const size_t INVALID_TEXTURE_ID = (size_t)-1;
169 const int INVALID_RENDERER_ID = -1;
170 const uint16_t MAXIMUM_GRID_SIZE = 2048;
171 }
172
173 ImageActorPtr ImageActor::New()
174 {
175   ImageActorPtr actor( new ImageActor );
176
177   // Second-phase construction of base class
178   actor->Initialize();
179
180   //Create the renderer
181   actor->mRenderer = Renderer::New();
182
183   GeometryPtr quad  = CreateGeometry( 1u, 1u, Vector2::ONE );
184   actor->mRenderer->SetGeometry( *quad );
185
186   ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE );
187   MaterialPtr material = Material::New();
188   material->SetShader( *shader );
189   actor->mRenderer->SetMaterial( *material );
190
191   return actor;
192 }
193
194 void ImageActor::OnInitialize()
195 {
196   // TODO: Remove this, at the moment its needed for size negotiation to work
197   SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
198 }
199
200 void ImageActor::SetImage( ImagePtr& image )
201 {
202   if( !image )
203   {
204     if( mRendererIndex != INVALID_RENDERER_ID )
205     {
206       RemoveRenderer( mRendererIndex );
207       mRendererIndex = INVALID_RENDERER_ID;
208     }
209   }
210   else
211   {
212     SamplerPtr sampler = Sampler::New();
213     sampler->SetFilterMode( mMinFilter, mMagFilter );
214
215     if( mTextureIndex != INVALID_TEXTURE_ID )
216     {
217       mRenderer->GetMaterial()->SetTextureImage( mTextureIndex, image.Get() );
218     }
219     else
220     {
221       mTextureIndex = mRenderer->GetMaterial()->AddTexture( image, "sTexture", sampler );
222     }
223
224     if( mRendererIndex == INVALID_RENDERER_ID )
225     {
226       mRendererIndex = AddRenderer( *mRenderer );
227     }
228
229     if( !mIsPixelAreaSet )
230     {
231       mPixelArea = PixelArea( 0, 0, image->GetWidth(), image->GetHeight() );
232     }
233
234     RelayoutRequest();
235     UpdateTexureRect();
236   }
237 }
238
239 ImagePtr ImageActor::GetImage() const
240 {
241   return mRenderer->GetMaterial()->GetTexture( mTextureIndex );
242 }
243
244 void ImageActor::SetPixelArea( const PixelArea& pixelArea )
245 {
246   mPixelArea = pixelArea;
247   mIsPixelAreaSet = true;
248
249   RelayoutRequest();
250   UpdateTexureRect();
251 }
252
253 const ImageActor::PixelArea& ImageActor::GetPixelArea() const
254 {
255   return mPixelArea;
256 }
257
258 bool ImageActor::IsPixelAreaSet() const
259 {
260   return mIsPixelAreaSet;
261 }
262
263 void ImageActor::ClearPixelArea()
264 {
265   mIsPixelAreaSet = false;
266
267   int imageWidth = 0;
268   int imageHeight = 0;
269   ImagePtr image = GetImage();
270   if( image )
271   {
272     imageWidth = image->GetWidth();
273     imageHeight = image->GetHeight();
274   }
275
276   mPixelArea = PixelArea( 0, 0, imageWidth, imageHeight );
277
278   RelayoutRequest();
279   UpdateTexureRect();
280 }
281
282 void ImageActor::SetStyle( Dali::ImageActor::Style style )
283 {
284   DALI_LOG_WARNING( "SetStyle Deprecated. Only STYLE_QUAD supported." );
285   mStyle = style;
286 }
287
288 Dali::ImageActor::Style ImageActor::GetStyle() const
289 {
290   DALI_LOG_WARNING( "GetStyle Deprecated. Only STYLE_QUAD supported." );
291   return mStyle;
292 }
293
294 void ImageActor::SetNinePatchBorder( const Vector4& border )
295 {
296   DALI_LOG_WARNING( "SetNinePatchBorder Deprecated. Only STYLE_QUAD supported." );
297   mNinePatchBorder = border;
298 }
299
300 Vector4 ImageActor::GetNinePatchBorder() const
301 {
302   DALI_LOG_WARNING( "GetNinePatchBorder Deprecated. Only STYLE_QUAD supported." );
303   return mNinePatchBorder;
304 }
305
306 ImageActor::ImageActor()
307 : Actor( Actor::BASIC ),
308   mActorSize( Vector2::ZERO ),
309   mGridSize( 1u, 1u ),
310   mRendererIndex( INVALID_RENDERER_ID ),
311   mTextureIndex( INVALID_TEXTURE_ID ),
312   mEffectTextureIndex( INVALID_TEXTURE_ID ),
313   mMinFilter( FilterMode::DEFAULT ),
314   mMagFilter( FilterMode::DEFAULT ),
315   mStyle( Dali::ImageActor::STYLE_QUAD ),
316   mIsPixelAreaSet( false )
317 {
318 }
319
320 ImageActor::~ImageActor()
321 {
322 }
323
324 Vector3 ImageActor::GetNaturalSize() const
325 {
326   Vector2 naturalSize( CalculateNaturalSize() );
327   return Vector3( naturalSize.width, naturalSize.height, 0.f );
328 }
329
330 Vector2 ImageActor::CalculateNaturalSize() const
331 {
332   // if no image then natural size is 0
333   Vector2 size( 0.0f, 0.0f );
334
335   ImagePtr image = GetImage();
336   if( image )
337   {
338     if( IsPixelAreaSet() )
339     {
340       PixelArea area(GetPixelArea());
341       size.width = area.width;
342       size.height = area.height;
343     }
344     else
345     {
346       size = image->GetNaturalSize();
347     }
348   }
349
350   return size;
351 }
352
353 void ImageActor::UpdateGeometry()
354 {
355   uint16_t gridWidth = 1u;
356   uint16_t gridHeight = 1u;
357
358   if( mShaderEffect )
359   {
360     Vector2 gridSize = mShaderEffect->GetGridSize( Vector2(mPixelArea.width, mPixelArea.height) );
361
362     //limit the grid size
363     gridWidth = std::min( MAXIMUM_GRID_SIZE, static_cast<uint16_t>(gridSize.width) );
364     gridHeight = std::min( MAXIMUM_GRID_SIZE, static_cast<uint16_t>(gridSize.height) );
365   }
366
367   mGridSize.SetWidth( gridWidth );
368   mGridSize.SetHeight( gridHeight );
369
370   GeometryPtr geometry = CreateGeometry( gridWidth, gridHeight, mActorSize );
371   mRenderer->SetGeometry( *geometry );
372 }
373 void ImageActor::UpdateTexureRect()
374 {
375   Vector4 textureRect( 0.f, 0.f, 1.f, 1.f );
376
377   ImagePtr image = GetImage();
378   if( mIsPixelAreaSet && image )
379   {
380     const float uScale = 1.0f / float(image->GetWidth());
381     const float vScale = 1.0f / float(image->GetHeight());
382     // bottom left
383     textureRect.x = uScale * float(mPixelArea.x);
384     textureRect.y = vScale * float(mPixelArea.y);
385     // top right
386     textureRect.z  = uScale * float(mPixelArea.x + mPixelArea.width);
387     textureRect.w = vScale * float(mPixelArea.y + mPixelArea.height);
388   }
389
390   Material* material = mRenderer->GetMaterial();
391   material->RegisterProperty( TEXTURE_RECT_UNIFORM_NAME, textureRect );
392 }
393
394 unsigned int ImageActor::GetDefaultPropertyCount() const
395 {
396   return Actor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
397 }
398
399 void ImageActor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
400 {
401   Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
402
403   indices.Reserve( indices.Size() + DEFAULT_PROPERTY_COUNT );
404
405   int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
406   for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
407   {
408     indices.PushBack( index );
409   }
410 }
411
412 bool ImageActor::IsDefaultPropertyWritable( Property::Index index ) const
413 {
414   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
415   {
416     return Actor::IsDefaultPropertyWritable(index);
417   }
418
419   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
420   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
421   {
422     return DEFAULT_PROPERTY_DETAILS[ index ].writable;
423   }
424
425   return false;
426 }
427
428 bool ImageActor::IsDefaultPropertyAnimatable( Property::Index index ) const
429 {
430   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
431   {
432     return Actor::IsDefaultPropertyAnimatable( index );
433   }
434
435   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
436   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
437   {
438     return DEFAULT_PROPERTY_DETAILS[ index ].animatable;
439   }
440
441   return false;
442 }
443
444 bool ImageActor::IsDefaultPropertyAConstraintInput( Property::Index index ) const
445 {
446   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
447   {
448     return Actor::IsDefaultPropertyAConstraintInput( index );
449   }
450
451   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
452   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
453   {
454     return DEFAULT_PROPERTY_DETAILS[ index ].constraintInput;
455   }
456
457   return false;
458 }
459
460 Property::Type ImageActor::GetDefaultPropertyType( Property::Index index ) const
461 {
462   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
463   {
464     return Actor::GetDefaultPropertyType( index );
465   }
466
467   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
468   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
469   {
470     return DEFAULT_PROPERTY_DETAILS[index].type;
471   }
472
473   // index out-of-bounds
474   return Property::NONE;
475 }
476
477 const char* ImageActor::GetDefaultPropertyName( Property::Index index ) const
478 {
479   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
480   {
481     return Actor::GetDefaultPropertyName(index);
482   }
483
484   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
485   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
486   {
487     return DEFAULT_PROPERTY_DETAILS[index].name;
488   }
489
490   // index out-of-bounds
491   return NULL;
492 }
493
494 Property::Index ImageActor::GetDefaultPropertyIndex(const std::string& name) const
495 {
496   Property::Index index = Property::INVALID_INDEX;
497
498   // Look for name in default properties
499   for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
500   {
501     const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
502     if( 0 == strcmp( name.c_str(), property->name ) ) // Don't want to convert rhs to string
503     {
504       index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
505       break;
506     }
507   }
508
509   // If not found, check in base class
510   if( Property::INVALID_INDEX == index )
511   {
512     index = Actor::GetDefaultPropertyIndex( name );
513   }
514   return index;
515 }
516
517 void ImageActor::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
518 {
519   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
520   {
521     Actor::SetDefaultProperty( index, propertyValue );
522   }
523   else
524   {
525     switch(index)
526     {
527       case Dali::ImageActor::Property::PIXEL_AREA:
528       {
529         SetPixelArea(propertyValue.Get<Rect<int> >());
530         break;
531       }
532       case Dali::ImageActor::Property::STYLE:
533       {
534         //not supported
535         break;
536       }
537       case Dali::ImageActor::Property::BORDER:
538       {
539         //not supported
540         break;
541       }
542       case Dali::ImageActor::Property::IMAGE:
543       {
544         Dali::Image img = Scripting::NewImage( propertyValue );
545         if(img)
546         {
547           ImagePtr image( &GetImplementation(img) );
548           SetImage( image );
549         }
550         else
551         {
552           DALI_LOG_WARNING("Cannot create image from property value\n");
553         }
554         break;
555       }
556       default:
557       {
558         DALI_LOG_WARNING("Unknown property (%d)\n", index);
559         break;
560       }
561     } // switch(index)
562
563   } // else
564 }
565
566 Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const
567 {
568   Property::Value ret;
569   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
570   {
571     ret = Actor::GetDefaultProperty( index );
572   }
573   else
574   {
575     switch( index )
576     {
577       case Dali::ImageActor::Property::PIXEL_AREA:
578       {
579         Rect<int> r = GetPixelArea();
580         ret = r;
581         break;
582       }
583       case Dali::ImageActor::Property::STYLE:
584       {
585         //not supported
586         break;
587       }
588       case Dali::ImageActor::Property::BORDER:
589       {
590         //not supported
591         break;
592       }
593       case Dali::ImageActor::Property::IMAGE:
594       {
595         Property::Map map;
596         Scripting::CreatePropertyMap( Dali::Image( GetImage().Get() ), map );
597         ret = Property::Value( map );
598         break;
599       }
600       default:
601       {
602         DALI_LOG_WARNING( "Unknown property (%d)\n", index );
603         break;
604       }
605     } // switch(index)
606   }
607
608   return ret;
609 }
610
611 void ImageActor::SetSortModifier(float modifier)
612 {
613   mRenderer->SetDepthIndex( modifier );
614 }
615
616 float ImageActor::GetSortModifier() const
617 {
618   return mRenderer->GetDepthIndex();
619 }
620
621 void ImageActor::SetBlendMode( BlendingMode::Type mode )
622 {
623   mRenderer->SetBlendMode( mode );
624 }
625
626 BlendingMode::Type ImageActor::GetBlendMode() const
627 {
628   return mRenderer->GetBlendMode();
629 }
630
631 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba )
632 {
633   mRenderer->SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
634 }
635
636 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
637                                BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
638 {
639   mRenderer->SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
640 }
641
642 void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
643                                BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
644 {
645   mRenderer->GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
646 }
647
648 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
649 {
650   mRenderer->SetBlendEquation( equationRgba, equationRgba );
651 }
652
653 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
654 {
655   mRenderer->SetBlendEquation( equationRgb, equationAlpha );
656 }
657
658 void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
659 {
660   mRenderer->GetBlendEquation( equationRgb, equationAlpha );
661 }
662
663 void ImageActor::SetBlendColor( const Vector4& color )
664 {
665   mBlendColor = color;
666   mRenderer->SetBlendColor( mBlendColor );
667 }
668
669 const Vector4& ImageActor::GetBlendColor() const
670 {
671   return mBlendColor;
672 }
673
674 void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
675 {
676   mMinFilter = minFilter;
677   mMagFilter = magFilter;
678
679   if( mTextureIndex != INVALID_TEXTURE_ID )
680   {
681     SamplerPtr sampler = Sampler::New();
682     sampler->SetFilterMode( minFilter, magFilter );
683
684     mRenderer->GetMaterial()->SetTextureSampler( mTextureIndex, sampler.Get() );
685   }
686 }
687
688 void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
689 {
690   minFilter = mMinFilter;
691   magFilter = mMagFilter;
692 }
693
694 void ImageActor::SetShaderEffect( ShaderEffect& effect )
695 {
696   if( mShaderEffect )
697   {
698     mShaderEffect->Disconnect( this );
699   }
700
701   mShaderEffect = ShaderEffectPtr( &effect );
702   effect.Connect( this );
703
704   ShaderPtr shader = mShaderEffect->GetShader();
705   mRenderer->GetMaterial()->SetShader( *shader );
706
707   EffectImageUpdated();
708
709   UpdateGeometry();
710 }
711
712 ShaderEffectPtr ImageActor::GetShaderEffect() const
713 {
714   return mShaderEffect;
715 }
716
717 void ImageActor::RemoveShaderEffect()
718 {
719   if( mShaderEffect )
720   {
721     mShaderEffect->Disconnect( this );
722     // change to the standard shader and quad geometry
723     ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE );
724     mRenderer->GetMaterial()->SetShader( *shader );
725     mShaderEffect.Reset();
726
727     UpdateGeometry();
728   }
729 }
730
731 void ImageActor::EffectImageUpdated()
732 {
733   if( mShaderEffect )
734   {
735     Dali::Image effectImage = mShaderEffect->GetEffectImage();
736     if( effectImage )
737     {
738       Image& effectImageImpl = GetImplementation( effectImage );
739
740       if( mEffectTextureIndex == INVALID_TEXTURE_ID )
741       {
742         mEffectTextureIndex = mRenderer->GetMaterial()->AddTexture( &effectImageImpl, "sEffect", NULL );
743       }
744       else
745       {
746         mRenderer->GetMaterial()->SetTextureImage( mEffectTextureIndex, &effectImageImpl );
747       }
748     }
749     else
750     {
751       if( mEffectTextureIndex != INVALID_TEXTURE_ID )
752       {
753         mRenderer->GetMaterial()->RemoveTexture( mEffectTextureIndex );
754       }
755       mEffectTextureIndex = INVALID_TEXTURE_ID;
756     }
757
758   }
759 }
760
761 void ImageActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
762 {
763   if( mActorSize != size )
764   {
765     mActorSize = size;
766     UpdateGeometry();
767   }
768 }
769
770 void ImageActor::OnSizeSet( const Vector3& targetSize )
771 {
772   Vector2 size( targetSize.x, targetSize.y );
773   if( mActorSize != size )
774   {
775     mActorSize = size;
776     UpdateGeometry();
777   }
778 }
779
780 } // namespace Internal
781
782 } // namespace Dali