[3.0] Mark Clipping API as being part of the Tizen 3 version
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / image-actor-impl.h
index beac18d..cd2ebe3 100644 (file)
 // INTERNAL INCLUDES
 #include <dali/public-api/object/ref-object.h>
 #include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/math/uint-16-pair.h>
 #include <dali/internal/event/actors/actor-declarations.h>
-#include <dali/internal/event/actors/renderable-actor-impl.h>
-#include <dali/internal/event/actor-attachments/image-attachment-impl.h>
+#include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/animation/animation-impl.h>
+#include <dali/internal/event/effects/shader-effect-impl.h>
 #include <dali/internal/event/images/nine-patch-image-impl.h>
+#include <dali/internal/event/rendering/texture-set-impl.h>
 
 namespace Dali
 {
@@ -36,44 +38,19 @@ namespace Internal
 class Image;
 
 /**
- * An actor which displays an Image object.
- *
- * This handles image fade-in if required, waiting for the image to load.
- *
- * If a new image is set on the actor, then this ensures that the old image
- * is displayed until the new image is ready to render to prevent flashing
- * to the actor color. This will also happen if the image is reloaded.
- *
- * This is achieved by using two connector objects to Image: mImageNext and
- * mImageAttachment's member object. The first one points to the Image object that is going to
- * be displayed next, the second one to the Image that is currently being displayed.
+ * An actor which displays an Image.
  */
-class ImageActor : public RenderableActor, public ConnectionTrackerInterface
+class ImageActor : public Actor
 {
 public:
 
-  typedef Dali::ImageActor::Style Style;
   typedef Dali::ImageActor::PixelArea PixelArea;
 
   /**
-   * @brief Create an initialised image actor.
-   * When the image is loaded the actors size will reset to the image size,
-   * unless a custom size chosen via Actor:SetSize().
-   * @param[in] image A pointer to the image object to display or NULL not to display anything.
-   * @return A smart-pointer to a newly allocated image actor.
-   */
-  static ImageActorPtr New( Image* image );
-
-  /**
-   * @brief Create an initialised image actor.
-   * When the image is loaded the actors size will reset to the image size,
-   * unless a custom size chosen via Actor:SetSize().
-   * @param [in] image A pointer to the image object to display or NULL not to display anything.
-   * @param [in] pixelArea The area of the image to display.
-   * This in pixels, relative to the top-left (0,0) of the image.
+   * @brief Create an image actor instance.
    * @return A smart-pointer to a newly allocated image actor.
    */
-  static ImageActorPtr New( Image* image, const PixelArea& pixelArea );
+  static ImageActorPtr New();
 
   /**
    * @copydoc Dali::Internal::Actor::OnInitialize
@@ -81,253 +58,266 @@ public:
   void OnInitialize() ;
 
   /**
-   * Set the image rendered by the actor's attachment.
-   * When the image is loaded the actors size will be reset to the image size,
-   * unless a custom size is chosen via Actor:SetSize().
-   * The old image will continue to be displayed until the new image has loaded
-   * @param [in] image A pointer to the image to display or NULL not to display anything.
-   */
-  void SetImage( Image* image );
-
-  /**
-   * Retrieve the image rendered by the actor's attachment.
-   * @return The image (uninitialized Image object in case the ImageActor does not display anything).
+   * @see Dali::ImageActor::SetImage()
+   * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
    */
-  Dali::Image GetImage();
+  void SetImage( ImagePtr& image );
 
   /**
-   * @copydoc Dali::ImageActor::SetToNaturalSize()
+   * Retrieve the image rendered by the actor.
+   * @return smart pointer to the image or an empty one if no image is assigned
    */
-  void SetToNaturalSize();
+  ImagePtr GetImage() const;
 
   /**
-   * Set a region of the image to display, in pixels.
-   * @param [in] pixelArea The area of the image to display.
-   * This in pixels, relative to the top-left (0,0) of the image.
+   * @copydoc Dali::ImageActor::SetPixelArea()
    */
   void SetPixelArea( const PixelArea& pixelArea );
 
   /**
-   * Retrieve the region of the image to display, in pixels.
-   * @return The pixel area, or a default-constructed area if none was set.
+   * @copydoc Dali::ImageActor::GetPixelArea()
    */
   const PixelArea& GetPixelArea() const;
 
   /**
-   * Query whether a pixel area has been set.
-   * @return True if a pixel area has been set.
+   * @copydoc Dali::ImageActor::IsPixelAreaSet()
    */
   bool IsPixelAreaSet() const;
 
   /**
-   * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
+   * @copydoc Dali::ImageActor::ClearPixelArea()
    */
   void ClearPixelArea();
 
   /**
-   * Set how the image is rendered; the default is STYLE_QUAD.
-   * @param [in] style The new style.
+   * @copydoc Dali::ImageActor::SetStyle()
    */
-  void SetStyle( Style style );
+  void SetStyle( Dali::ImageActor::Style style );
 
   /**
-   * Query how the image is rendered.
-   * @return The rendering style.
+   * @copydoc Dali::ImageActor::GetStyle()
    */
-  Style GetStyle() const;
+  Dali::ImageActor::Style GetStyle() const;
 
   /**
-   * @copydoc Dali::ImageActor::SetNinePatchBorder
+   * @copydoc Dali::ImageActor::SetNinePatchBorder()
    */
-  void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
+  void SetNinePatchBorder( const Vector4& border );
 
   /**
-   * @copydoc Dali::ImageActor::GetNinePatchBorder
+   * @copydoc Dali::ImageActor::GetNinePatchBorder()
    */
   Vector4 GetNinePatchBorder() const;
 
   /**
-   * Set whether the image should gradually fade in when first rendered.
-   * @param [in] enableFade True if the image should fade in.
+   * @copydoc Dali::RenderableActor::SetSortModifier()
    */
-  void SetFadeIn(bool enableFade);
+  void SetSortModifier(float modifier);
 
   /**
-   * Query whether the image will gradually fade in when first rendered.
-   * @return True if the image will fade in.
+   * @copydoc Dali::RenderableActor::GetSortModifier()
    */
-  bool GetFadeIn() const;
+  float GetSortModifier() const;
 
   /**
-   * Set the duration of the fade-in effect; the default is 1 second.
-   * @param [in] durationSeconds The duration in seconds.
+   * @copydoc Dali::RenderableActor::SetBlendMode()
    */
-  void SetFadeInDuration( float durationSeconds );
+  void SetBlendMode( BlendingMode::Type mode );
 
   /**
-   * Retrieve the duration of the fade-in effect.
-   * @return The duration in seconds.
+   * @copydoc Dali::RenderableActor::GetBlendMode()
    */
-  float GetFadeInDuration() const;
+  BlendingMode::Type GetBlendMode() const;
 
   /**
-   * Retrieve the attachment which renders the image.
-   * @return The attachment.
+   * @copydoc Dali::RenderableActor::SetBlendFunc()
    */
-  ImageAttachment& GetImageAttachment();
+  void SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba );
 
   /**
-   * @copydoc Dali::ImageActor::GetCurrentImageSize
+   * @copydoc Dali::RenderableActor::SetBlendFunc()
    */
-  Vector2 GetCurrentImageSize() const;
-
-public: // Default property extensions from ProxyObject
+  void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
+                     BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
+   * @copydoc Dali::RenderableActor::GetBlendFunc()
    */
-  virtual unsigned int GetDefaultPropertyCount() const;
+  void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
+                     BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
+   * @copydoc Dali::RenderableActor::SetBlendEquation()
    */
-  virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
+  void SetBlendEquation( BlendingEquation::Type equationRgba );
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
+   * @copydoc Dali::RenderableActor::SetBlendEquation()
    */
-  virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
+  void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
+   * @copydoc Dali::RenderableActor::GetBlendEquation()
    */
-  virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
+  void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
+   * @copydoc Dali::RenderableActor::SetBlendColor()
    */
-  virtual bool IsDefaultPropertyWritable(Property::Index index) const;
+  void SetBlendColor( const Vector4& color );
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
+   * @copydoc Dali::RenderableActor::GetBlendColor()
    */
-  virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
+  const Vector4& GetBlendColor() const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
+   * @copydoc Dali::RenderableActor::SetFilterMode()
    */
-  virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
+  void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
+   * @copydoc Dali::RenderableActor::GetFilterMode()
    */
-  virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
+  void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
+   * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
    */
-  virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
+  void EffectImageUpdated();
 
+public:
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
+   * @copydoc Actor::SetShaderEffect
    */
-  virtual Property::Value GetDefaultProperty( Property::Index index ) const;
+  virtual void SetShaderEffect(ShaderEffect& effect);
 
-private: // From RenderableActor
+  /**
+   * @copydoc Actor::GetShaderEffect
+   */
+  virtual ShaderEffectPtr GetShaderEffect() const;
 
   /**
-   * @copydoc RenderableActor::GetRenderableAttachment
+   * @copydoc Actor::RemoveShaderEffect
    */
-  virtual RenderableAttachment& GetRenderableAttachment() const;
+  virtual void RemoveShaderEffect();
 
-private: // From ConnectionTrackerInterface
+private:
 
   /**
-   * @copydoc SignalObserver::SignalConnected
+   * @copydoc Actor::OnRelayout
    */
-  virtual void SignalConnected( SlotObserver*, CallbackBase* );
+  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
 
   /**
-   * @copydoc ConnectionTrackerInterface::SignalDisconnected
+   * @copydoc Actor::OnSizeSet
    */
-  virtual void SignalDisconnected(Dali::SlotObserver*, Dali::CallbackBase* );
+  virtual void OnSizeSet( const Vector3& targetSize );
 
-protected:
+public: // Default property extensions from Object
 
   /**
-   * Protected constructor; see also ImageActor::New()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
    */
-  ImageActor();
+  virtual unsigned int GetDefaultPropertyCount() const;
 
   /**
-   * A reference counted object may only be deleted by calling Unreference()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
    */
-  virtual ~ImageActor();
+  virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
 
-private:
+  /**
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
+   */
+  virtual const char* GetDefaultPropertyName(Property::Index index) const;
 
   /**
-   * Helper to set the actor to the image's natural size
-   * @param image that is used
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
    */
-  void SetNaturalSize( Image& image );
+  virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
 
   /**
-   * From Actor.
-   * This is called after SizeSet() has been called.
+   * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
    */
-  virtual void OnSizeSet( const Vector3& targetSize );
+  virtual bool IsDefaultPropertyWritable(Property::Index index) const;
 
   /**
-   * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
+   * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
    */
-  virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
+  virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
 
   /**
-   * From Actor; used to trigger fade-in animations.
+   * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
    */
-  virtual void OnStageConnectionInternal();
+  virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
 
   /**
-   * From Actor; used to notify Image.
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
    */
-  virtual void OnStageDisconnectionInternal();
+  virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
 
   /**
-   * Helper for when the image loads.
-   * @param[in] image The newly (re)loaded image.
+   * @copydoc Dali::Internal::Object::SetDefaultProperty()
    */
-  void ImageLoaded( Dali::Image image );
+  virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
 
   /**
-   * Helper to start fade-in animations.
+   * @copydoc Dali::Internal::Object::GetDefaultProperty()
    */
-  void FadeIn();
+  virtual Property::Value GetDefaultProperty( Property::Index index ) const;
+
+public: // From Actor
 
   /**
-   * Helper to set image internally
-   * @param currentImage
-   * @param image to set
+   * @copydoc Dali::Actor::GetNaturalSize()
    */
-  void SetImageInternal( Image* currentImage, Image* image );
+  virtual Vector3 GetNaturalSize() const;
+
+protected:
+
+  /**
+   * Protected constructor; see also ImageActor::New()
+   */
+  ImageActor();
+
+  /**
+   * A reference counted object may only be deleted by calling Unreference()
+   */
+  virtual ~ImageActor();
 
 private:
 
-  ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
-  ImageConnector     mImageNext;       ///< Manages the Image this ImageActor will show (used when changing displayed image)
+  /**
+   * Calculate the natural size of this image actor
+   *
+   * @return Return the natural size as a Vector2
+   */
+  Vector2 CalculateNaturalSize() const;
 
-  // For fade-in animations
-  float mFadeInDuration;  ///< Length of animation
+  /**
+   * Update the grid geometry.
+   */
+  void UpdateGeometry();
 
-  // flags, compressed to bitfield (uses only 4 bytes)
-  bool mUsingNaturalSize:1;      ///< True only when the actor is using
-  bool mInternalSetSize:1;       ///< True whilst setting size internally, false at all other times
-  bool mFadeIn:1;                ///< True if fade in animation is enabled
-  bool mFadeInitial:1;           ///< True if fading in for the first time
+  /**
+   * Update the texture rect uniform
+   */
+  void UpdateTexureRect();
 
-  static bool mFirstInstance ;
-  static DefaultPropertyLookup* mDefaultImageActorPropertyLookup; ///< Default properties
+private:
 
+  ShaderEffectPtr         mShaderEffect;            ///< Optional referenced shader effect
+  RendererPtr             mRenderer;                ///< The renderer used to render the image
+  PixelArea               mPixelArea;               ///< The pixel area of the image to render
+  Vector4                 mBlendColor;              ///< The blend color for this ImageActor
+  Vector4                 mNinePatchBorder;         ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
+  Vector2                 mActorSize;               ///< The actor size
+  Uint16Pair              mGridSize;                ///< The geometry grid size
+  int                     mRendererIndex;           ///< The index location of mRenderer
+  FilterMode::Type        mMinFilter;               ///< The minification filter currently set
+  FilterMode::Type        mMagFilter;               ///< The magnification filter currently set
+  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.
+  bool                    mIsPixelAreaSet;          ///< Flag indicating if the pixel area has been set
 };
 
 } // namespace Internal