(ImageActor) resize the geometry in shader
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / image-actor-impl.h
1 #ifndef __DALI_INTERNAL_IMAGE_ACTOR_H__
2 #define __DALI_INTERNAL_IMAGE_ACTOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <dali/devel-api/rendering/cull-face.h>
26 #include <dali/internal/event/actors/actor-declarations.h>
27 #include <dali/internal/event/actors/actor-impl.h>
28 #include <dali/internal/event/animation/animation-impl.h>
29 #include <dali/internal/event/effects/shader-effect-impl.h>
30 #include <dali/internal/event/images/nine-patch-image-impl.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 class Image;
39
40 /**
41  * An actor which displays an Image object.
42  *
43  * This handles image fade-in if required, waiting for the image to load.
44  *
45  * If a new image is set on the actor, then this ensures that the old image
46  * is displayed until the new image is ready to render to prevent flashing
47  * to the actor color. This will also happen if the image is reloaded.
48  *
49  * This is achieved by using two connector objects to Image: mImageNext and
50  * mImageAttachment's member object. The first one points to the Image object that is going to
51  * be displayed next, the second one to the Image that is currently being displayed.
52  */
53 class ImageActor : public Actor
54 {
55 public:
56
57   typedef Dali::ImageActor::PixelArea PixelArea;
58
59   /**
60    * @brief Create an image actor instance.
61    * @return A smart-pointer to a newly allocated image actor.
62    */
63   static ImageActorPtr New();
64
65   /**
66    * @copydoc Dali::Internal::Actor::OnInitialize
67    */
68   void OnInitialize() ;
69
70   /**
71    * @see Dali::ImageActor::SetImage()
72    * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
73    */
74   void SetImage( ImagePtr& image );
75
76   /**
77    * Retrieve the image rendered by the actor's attachment.
78    * @return smart pointer to the image or an empty one if no image is assigned
79    */
80   ImagePtr GetImage() const;
81
82   /**
83    * @copydoc Dali::ImageActor::SetPixelArea()
84    */
85   void SetPixelArea( const PixelArea& pixelArea );
86
87   /**
88    * @copydoc Dali::ImageActor::GetPixelArea()
89    */
90   const PixelArea& GetPixelArea() const;
91
92   /**
93    * @copydoc Dali::ImageActor::IsPixelAreaSet()
94    */
95   bool IsPixelAreaSet() const;
96
97   /**
98    * @copydoc Dali::ImageActor::ClearPixelArea()
99    */
100   void ClearPixelArea();
101
102   /**
103    * @copydoc Dali::RenderableActor::SetSortModifier()
104    */
105   void SetSortModifier(float modifier);
106
107   /**
108    * @copydoc Dali::RenderableActor::GetSortModifier()
109    */
110   float GetSortModifier() const;
111
112   /**
113    * @copydoc Dali::RenderableActor::SetCullFace()
114    */
115   void SetCullFace(CullFaceMode mode);
116
117   /**
118    * @copydoc Dali::RenderableActor::GetCullFace()
119    */
120   CullFaceMode GetCullFace() const;
121
122   /**
123    * @copydoc Dali::RenderableActor::SetBlendMode()
124    */
125   void SetBlendMode( BlendingMode::Type mode );
126
127   /**
128    * @copydoc Dali::RenderableActor::GetBlendMode()
129    */
130   BlendingMode::Type GetBlendMode() const;
131
132   /**
133    * @copydoc Dali::RenderableActor::SetBlendFunc()
134    */
135   void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
136
137   /**
138    * @copydoc Dali::RenderableActor::SetBlendFunc()
139    */
140   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
141                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
142
143   /**
144    * @copydoc Dali::RenderableActor::GetBlendFunc()
145    */
146   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
147                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
148
149   /**
150    * @copydoc Dali::RenderableActor::SetBlendEquation()
151    */
152   void SetBlendEquation( BlendingEquation::Type equationRgba );
153
154   /**
155    * @copydoc Dali::RenderableActor::SetBlendEquation()
156    */
157   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
158
159   /**
160    * @copydoc Dali::RenderableActor::GetBlendEquation()
161    */
162   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
163
164   /**
165    * @copydoc Dali::RenderableActor::SetBlendColor()
166    */
167   void SetBlendColor( const Vector4& color );
168
169   /**
170    * @copydoc Dali::RenderableActor::GetBlendColor()
171    */
172   const Vector4& GetBlendColor() const;
173
174   /**
175    * @copydoc Dali::RenderableActor::SetFilterMode()
176    */
177   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
178
179   /**
180    * @copydoc Dali::RenderableActor::GetFilterMode()
181    */
182   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
183
184   /**
185    * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
186    */
187   void EffectImageUpdated();
188
189 public:
190   /**
191    * @copydoc Actor::SetShaderEffect
192    */
193   virtual void SetShaderEffect(ShaderEffect& effect);
194
195   /**
196    * @copydoc Actor::GetShaderEffect
197    */
198   virtual ShaderEffectPtr GetShaderEffect() const;
199
200   /**
201    * @copydoc Actor::RemoveShaderEffect
202    */
203   virtual void RemoveShaderEffect();
204
205 public: // Default property extensions from Object
206
207   /**
208    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
209    */
210   virtual unsigned int GetDefaultPropertyCount() const;
211
212   /**
213    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
214    */
215   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
216
217   /**
218    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
219    */
220   virtual const char* GetDefaultPropertyName(Property::Index index) const;
221
222   /**
223    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
224    */
225   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
226
227   /**
228    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
229    */
230   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
231
232   /**
233    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
234    */
235   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
236
237   /**
238    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
239    */
240   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
241
242   /**
243    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
244    */
245   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
246
247   /**
248    * @copydoc Dali::Internal::Object::SetDefaultProperty()
249    */
250   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
251
252   /**
253    * @copydoc Dali::Internal::Object::GetDefaultProperty()
254    */
255   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
256
257 public: // From Actor
258
259   /**
260    * @copydoc Dali::Actor::GetNaturalSize()
261    */
262   virtual Vector3 GetNaturalSize() const;
263
264 protected:
265
266   /**
267    * Protected constructor; see also ImageActor::New()
268    */
269   ImageActor();
270
271   /**
272    * A reference counted object may only be deleted by calling Unreference()
273    */
274   virtual ~ImageActor();
275
276 private:
277
278   /**
279    * Calculate the natural size of this image actor
280    *
281    * @return Return the natural size as a Vector2
282    */
283   Vector2 CalculateNaturalSize() const;
284
285   /**
286    * Update the grid geometry.
287    */
288   void UpdateGeometry();
289
290   /**
291    * Update the texture rect uniform
292    */
293   void UpdateTexureRect();
294
295 private:
296
297   ShaderEffectPtr    mShaderEffect;            ///< Optional referenced shader effect
298   RendererPtr        mRenderer;                ///< The renderer used to render the image
299   PixelArea          mPixelArea;               ///< The pixel area of the image to render
300   Vector4            mBlendColor;              ///< The blend color for this ImageActor
301   Uint16Pair         mGridSize;                ///< The geometry grid size
302   int                mRendererIndex;           ///< The index location of mRenderer
303   size_t             mTextureIndex;            ///< The texture index for this ImageActor's texture
304   size_t             mEffectTextureIndex;      ///< The texture index for this ImageActor's effect texture
305   FilterMode::Type   mMinFilter;               ///< The minification filter currently set
306   FilterMode::Type   mMagFilter;               ///< The magnification filter currently set
307   bool               mIsPixelAreaSet;          ///< Flag indicating if the pixel area has been set
308 };
309
310 } // namespace Internal
311
312 // Helpers for public-api forwarding methods
313
314 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
315 {
316   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
317
318   BaseObject& handle = image.GetBaseObject();
319
320   return static_cast<Internal::ImageActor&>(handle);
321 }
322
323 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
324 {
325   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
326
327   const BaseObject& handle = image.GetBaseObject();
328
329   return static_cast<const Internal::ImageActor&>(handle);
330 }
331
332 } // namespace Dali
333
334 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__