Rendering API clean-up
[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/internal/event/actors/actor-declarations.h>
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/animation/animation-impl.h>
28 #include <dali/internal/event/effects/shader-effect-impl.h>
29 #include <dali/internal/event/images/nine-patch-image-impl.h>
30 #include <dali/internal/event/rendering/texture-set-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::ImageActor::SetStyle()
104    */
105   void SetStyle( Dali::ImageActor::Style style );
106
107   /**
108    * @copydoc Dali::ImageActor::GetStyle()
109    */
110   Dali::ImageActor::Style GetStyle() const;
111
112   /**
113    * @copydoc Dali::ImageActor::SetNinePatchBorder()
114    */
115   void SetNinePatchBorder( const Vector4& border );
116
117   /**
118    * @copydoc Dali::ImageActor::GetNinePatchBorder()
119    */
120   Vector4 GetNinePatchBorder() const;
121
122   /**
123    * @copydoc Dali::RenderableActor::SetSortModifier()
124    */
125   void SetSortModifier(float modifier);
126
127   /**
128    * @copydoc Dali::RenderableActor::GetSortModifier()
129    */
130   float GetSortModifier() const;
131
132   /**
133    * @copydoc Dali::RenderableActor::SetBlendMode()
134    */
135   void SetBlendMode( BlendingMode::Type mode );
136
137   /**
138    * @copydoc Dali::RenderableActor::GetBlendMode()
139    */
140   BlendingMode::Type GetBlendMode() const;
141
142   /**
143    * @copydoc Dali::RenderableActor::SetBlendFunc()
144    */
145   void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
146
147   /**
148    * @copydoc Dali::RenderableActor::SetBlendFunc()
149    */
150   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
151                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
152
153   /**
154    * @copydoc Dali::RenderableActor::GetBlendFunc()
155    */
156   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
157                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
158
159   /**
160    * @copydoc Dali::RenderableActor::SetBlendEquation()
161    */
162   void SetBlendEquation( BlendingEquation::Type equationRgba );
163
164   /**
165    * @copydoc Dali::RenderableActor::SetBlendEquation()
166    */
167   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
168
169   /**
170    * @copydoc Dali::RenderableActor::GetBlendEquation()
171    */
172   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
173
174   /**
175    * @copydoc Dali::RenderableActor::SetBlendColor()
176    */
177   void SetBlendColor( const Vector4& color );
178
179   /**
180    * @copydoc Dali::RenderableActor::GetBlendColor()
181    */
182   const Vector4& GetBlendColor() const;
183
184   /**
185    * @copydoc Dali::RenderableActor::SetFilterMode()
186    */
187   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
188
189   /**
190    * @copydoc Dali::RenderableActor::GetFilterMode()
191    */
192   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
193
194   /**
195    * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
196    */
197   void EffectImageUpdated();
198
199 public:
200   /**
201    * @copydoc Actor::SetShaderEffect
202    */
203   virtual void SetShaderEffect(ShaderEffect& effect);
204
205   /**
206    * @copydoc Actor::GetShaderEffect
207    */
208   virtual ShaderEffectPtr GetShaderEffect() const;
209
210   /**
211    * @copydoc Actor::RemoveShaderEffect
212    */
213   virtual void RemoveShaderEffect();
214
215 private:
216
217   /**
218    * @copydoc Actor::OnRelayout
219    */
220   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
221
222   /**
223    * @copydoc Actor::OnSizeSet
224    */
225   virtual void OnSizeSet( const Vector3& targetSize );
226
227 public: // Default property extensions from Object
228
229   /**
230    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
231    */
232   virtual unsigned int GetDefaultPropertyCount() const;
233
234   /**
235    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
236    */
237   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
238
239   /**
240    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
241    */
242   virtual const char* GetDefaultPropertyName(Property::Index index) const;
243
244   /**
245    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
246    */
247   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
248
249   /**
250    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
251    */
252   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
253
254   /**
255    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
256    */
257   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
258
259   /**
260    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
261    */
262   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
263
264   /**
265    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
266    */
267   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
268
269   /**
270    * @copydoc Dali::Internal::Object::SetDefaultProperty()
271    */
272   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
273
274   /**
275    * @copydoc Dali::Internal::Object::GetDefaultProperty()
276    */
277   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
278
279 public: // From Actor
280
281   /**
282    * @copydoc Dali::Actor::GetNaturalSize()
283    */
284   virtual Vector3 GetNaturalSize() const;
285
286 protected:
287
288   /**
289    * Protected constructor; see also ImageActor::New()
290    */
291   ImageActor();
292
293   /**
294    * A reference counted object may only be deleted by calling Unreference()
295    */
296   virtual ~ImageActor();
297
298 private:
299
300   /**
301    * Calculate the natural size of this image actor
302    *
303    * @return Return the natural size as a Vector2
304    */
305   Vector2 CalculateNaturalSize() const;
306
307   /**
308    * Update the grid geometry.
309    */
310   void UpdateGeometry();
311
312   /**
313    * Update the texture rect uniform
314    */
315   void UpdateTexureRect();
316
317 private:
318
319   ShaderEffectPtr         mShaderEffect;            ///< Optional referenced shader effect
320   RendererPtr             mRenderer;                ///< The renderer used to render the image
321   PixelArea               mPixelArea;               ///< The pixel area of the image to render
322   Vector4                 mBlendColor;              ///< The blend color for this ImageActor
323   Vector4                 mNinePatchBorder;         ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
324   Vector2                 mActorSize;               ///< The actor size
325   Uint16Pair              mGridSize;                ///< The geometry grid size
326   int                     mRendererIndex;           ///< The index location of mRenderer
327   FilterMode::Type        mMinFilter;               ///< The minification filter currently set
328   FilterMode::Type        mMagFilter;               ///< The magnification filter currently set
329   Dali::ImageActor::Style mStyle;                   ///< The style set by SetStyle. Not used internally, only used to store what is set so it can be returned for backwards compatibility.
330   bool                    mIsPixelAreaSet;          ///< Flag indicating if the pixel area has been set
331 };
332
333 } // namespace Internal
334
335 // Helpers for public-api forwarding methods
336
337 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
338 {
339   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
340
341   BaseObject& handle = image.GetBaseObject();
342
343   return static_cast<Internal::ImageActor&>(handle);
344 }
345
346 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
347 {
348   DALI_ASSERT_ALWAYS(image && "Image handle is empty");
349
350   const BaseObject& handle = image.GetBaseObject();
351
352   return static_cast<const Internal::ImageActor&>(handle);
353 }
354
355 } // namespace Dali
356
357 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__