(Visuals) Remove dead code & redundant Get prefix to check if on stage or from the...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image / image-visual.h
index e55491f..56b1ae1 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/visual-impl.h>
-#include <dali-toolkit/internal/visuals/image-atlas-manager.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/devel-api/image-loader/atlas-upload-observer.h>
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/images/image.h>
 #include <dali/public-api/images/image-operations.h>
 #include <dali/public-api/images/resource-image.h>
+#include <dali/devel-api/object/weak-handle.h>
 
 namespace Dali
 {
@@ -42,7 +43,7 @@ class ImageVisual;
 typedef IntrusivePtr< ImageVisual > ImageVisualPtr;
 
 /**
- * The renderer which renders an image to the control's quad
+ * The visual which renders an image to the control's quad
  *
  * The following properties are optional
  *
@@ -73,7 +74,7 @@ typedef IntrusivePtr< ImageVisual > ImageVisualPtr;
  *   "DEFAULT"
  *
  */
-class ImageVisual: public Visual, public ConnectionTracker
+class ImageVisual: public Visual::Base, public ConnectionTracker, public AtlasUploadObserver
 {
 public:
 
@@ -81,55 +82,74 @@ public:
    * @brief Constructor.
    *
    * @param[in] factoryCache The VisualFactoryCache object
-   * @param[in] atlasManager The atlasManager object
    */
-  ImageVisual( VisualFactoryCache& factoryCache, ImageAtlasManager& atlasManager );
+  ImageVisual( VisualFactoryCache& factoryCache );
 
   /**
-   * @brief A reference counted object may only be deleted by calling Unreference().
+   * @brief Constructor with a URL.
+   *
+   * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
+   *
+   * @param[in] factoryCache The VisualFactoryCache object
+   * @param[in] imageUrl The URL of the image resource to use
+   * @param[in] size The width and height to fit the loaded image to.
+   * @param[in] fittingMode The FittingMode of the resource to load
+   * @param[in] samplingMode The SamplingMode of the resource to load
    */
-  ~ImageVisual();
+  ImageVisual( VisualFactoryCache& factoryCache,
+               const std::string& imageUrl,
+               ImageDimensions size=ImageDimensions(),
+               FittingMode::Type fittingMode = FittingMode::DEFAULT,
+               Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
 
-public:  // from Visual
+  /**
+   * @brief Constructor with an Image type.
+   *
+   * @param[in] factoryCache The VisualFactoryCache object
+   * @param[in] image The image to use
+   */
+  ImageVisual( VisualFactoryCache& factoryCache, const Image& image );
 
   /**
-   * @copydoc Visual::SetSize
+   * @brief A reference counted object may only be deleted by calling Unreference().
    */
-  virtual void SetSize( const Vector2& size );
+  ~ImageVisual();
+
+public:  // from Visual
 
   /**
-   * @copydoc Visual::GetNaturalSize
+   * @copydoc Visual::Base::GetNaturalSize
    */
   virtual void GetNaturalSize( Vector2& naturalSize ) const;
 
   /**
-   * @copydoc Visual::SetClipRect
+   * @copydoc Visual::Base::CreatePropertyMap
    */
-  virtual void SetClipRect( const Rect<int>& clipRect );
+  virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
   /**
-   * @copydoc Visual::SetOffset
+   * @copydoc Visual::Base::DoSetProperty
    */
-  virtual void SetOffset( const Vector2& offset );
+  virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
 
   /**
-   * @copydoc Visual::CreatePropertyMap
+   * @copydoc Visual::Base::DoGetProperty
    */
-  virtual void DoCreatePropertyMap( Property::Map& map ) const;
+  virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
 
 protected:
   /**
-   * @copydoc Visual::DoInitialize
+   * @copydoc Visual::Base::DoInitialize
    */
   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
 
   /**
-   * @copydoc Visual::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnStage
    */
   virtual void DoSetOnStage( Actor& actor );
 
   /**
-   * @copydoc Visual::DoSetOffStage
+   * @copydoc Visual::Base::DoSetOffStage
    */
   virtual void DoSetOffStage( Actor& actor );
 
@@ -138,32 +158,18 @@ public:
   /**
    * Get the standard image rendering shader.
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] atlasing Whether texture atlasing is applied.
+   * @param[in] defaultTextureWrapping Whether the default texture wrap mode is applied.
    */
-  static Shader GetImageShader( VisualFactoryCache& factoryCache );
+  static Shader GetImageShader( VisualFactoryCache& factoryCache, bool atlasing, bool defaultTextureWrapping );
 
   /**
-   * @brief Sets the image of this renderer to the resource at imageUrl
-   * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
+   * @copydoc AtlasUploadObserver::UploadCompleted
    *
-   * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
-   * @param[in] imageUrl The URL of the image resource to use
-   * @param[in] size The width and height to fit the loaded image to.
-   * @param[in] fittingMode The FittingMode of the resource to load
-   * @param[in] samplingMode The SamplingMode of the resource to load
-   */
-  void SetImage( Actor& actor,
-                 const std::string& imageUrl,
-                 ImageDimensions size=ImageDimensions(),
-                 FittingMode::Type fittingMode = FittingMode::DEFAULT,
-                 Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
-
-  /**
-   * @brief Sets the image of this renderer to use
-   *
-   * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
-   * @param[in] image The image to use
+   * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready.
+   * This callback is the place to add the renderer as it would be called once the loading is finished.
    */
-  void SetImage( Actor& actor, const Image& image );
+  virtual void UploadCompleted();
 
 private:
 
@@ -200,18 +206,18 @@ private:
    *
    * @return Returns the created Dali::Renderer
    */
-  Renderer CreateNativeImageVisual() const;
+  Renderer CreateNativeImageRenderer() const;
 
   /**
    * @brief Query whether resources requires to be loaded synchronously.
-   * @return Returns true if synchronoud resource loading is required, false otherwise.
+   * @return Returns true if synchronous resource loading is required, false otherwise.
    */
   bool IsSynchronousResourceLoading() const;
 
   /**
-   * @brief Do the synchronous resource loading
+   * @brief Load the resource synchronously
    */
-  void DoSynchronousResourceLoading();
+  void LoadResourceSynchronously();
 
   /**
    * Load the image.
@@ -252,13 +258,16 @@ private:
 
 private:
   Image mImage;
-  ImageAtlasManager& mAtlasManager;
   PixelData mPixels;
+  Vector4 mPixelArea;
+  WeakHandle<Actor> mPlacementActor;
 
   std::string mImageUrl;
   Dali::ImageDimensions mDesiredSize;
   Dali::FittingMode::Type mFittingMode;
   Dali::SamplingMode::Type mSamplingMode;
+  Dali::WrapMode::Type mWrapModeU;
+  Dali::WrapMode::Type mWrapModeV;
 
   std::string mNativeFragmentShaderCode;
   bool mNativeImageFlag;