// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
+#include <dali-toolkit/internal/controls/renderers/image-atlas-manager.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>
namespace Dali
{
+class NativeImage;
+
namespace Toolkit
{
*
* The following properties are optional
*
- * | %Property Name | Type |
- * |---------------------------|------------------|
- * | image-url | STRING |
- * | image-fitting-mode | STRING |
- * | image-sampling-mode | STRING |
- * | image-desired-width | INT |
- * | image-desired-height | INT |
+ * | %Property Name | Type |
+ * |-------------------------|------------------|
+ * | imageUrl | STRING |
+ * | imageFittingMode | STRING |
+ * | imageSamplingMode | STRING |
+ * | imageDesiredWidth | INT |
+ * | imageDesiredHeight | INT |
*
- * where image-fitting-mode should be one of the following fitting modes:
- * "shrink-to-fit"
- * "scale-to-fill"
- * "fit-width"
- * "fit-height"
+ * where imageFittingMode should be one of the following fitting modes:
+ * "shrinkToFit"
+ * "scaleToFill"
+ * "fitWidth"
+ * "fitHeight"
* "default"
*
- * where image-sampling-mode should be one of the following sampling modes:
+ * where imageSamplingMode should be one of the following sampling modes:
* "box"
* "nearest"
* "linear"
- * "box-then-nearest"
- * "box-then-linear"
- * "no-filter"
- * "dont-care"
+ * "boxThenNearest"
+ * "boxThenLinear"
+ * "noFilter"
+ * "dontCare"
* "default"
*
*/
-class ImageRenderer: public ControlRenderer
+class ImageRenderer: public ControlRenderer, public ConnectionTracker
{
public:
/**
* @brief Constructor.
+ *
+ * @param[in] factoryCache The RendererFactoryCache object
+ * @param[in] atlasManager The atlasManager object
*/
- ImageRenderer();
+ ImageRenderer( RendererFactoryCache& factoryCache, ImageAtlasManager& atlasManager );
/**
* @brief A reference counted object may only be deleted by calling Unreference().
public: // from ControlRenderer
/**
- * @copydoc ControlRenderer::Initialize
+ * @copydoc ControlRenderer::SetSize
*/
- virtual void Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap );
+ virtual void SetSize( const Vector2& size );
/**
- * @copydoc ControlRenderer::SetSize
+ * @copydoc ControlRenderer::GetNaturalSize
*/
- virtual void SetSize( const Vector2& size );
+ virtual void GetNaturalSize( Vector2& naturalSize ) const;
/**
* @copydoc ControlRenderer::SetClipRect
*/
virtual void SetOffset( const Vector2& offset );
+ /**
+ * @copydoc ControlRenderer::CreatePropertyMap
+ */
+ virtual void DoCreatePropertyMap( Property::Map& map ) const;
+
protected:
/**
+ * @copydoc ControlRenderer::DoInitialize
+ */
+ virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
+
+ /**
* @copydoc ControlRenderer::DoSetOnStage
*/
virtual void DoSetOnStage( Actor& actor );
public:
/**
- * Request the geometry and shader from the cache, if not available, create and save to the cache for sharing.
- *
+ * Get the standard image rendering shader.
* @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
*/
- void Initialize( RendererFactoryCache& factoryCache );
+ static Shader GetImageShader( RendererFactoryCache& factoryCache );
/**
* @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
*
+ * @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 to to image resource to use
- */
- void SetImage( const std::string& imageUrl );
-
- /**
- * @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
- *
- * @param[in] imageUrl The URL to to image resource to use
- * @param[in] desiredWidth The desired width of the resource to load
- * @param[in] desiredHeight The desired height of the resource to load
+ * @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( const std::string& imageUrl, int desiredWidth, int desiredHeight, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode );
+ 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
*/
- void SetImage( Image image );
+ void SetImage( Actor& actor, const Image& image );
private:
/**
- * @brief Applies this renderer's image to the sampler to the material used for this renderer
+ * @brief Applies the image to the texture set used for this renderer
+ *
+ * @param[in] image The Image to apply to the texture set used for this renderer
+ */
+ void ApplyImageToSampler( const Image& image );
+
+ /**
+ * @brief Initializes the Dali::Renderer from an image url string
+ *
+ * @param[in] imageUrl The image url string to intialize this ImageRenderer from
+ */
+ void InitializeRenderer( const std::string& imageUrl );
+
+ /**
+ * @brief Initializes the Dali::Renderer from an image handle
+ *
+ * @param[in] image The image handle to intialize this ImageRenderer from
+ */
+ void InitializeRenderer( const Image& image );
+
+ /**
+ * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it
+ *
+ * @return Returns the created Dali::Renderer
+ */
+ Renderer CreateRenderer() const;
+
+ /**
+ * @brief Creates the Dali::Renderer for NativeImage with custom sampler type and prefix, initializing it
+ *
+ * @return Returns the created Dali::Renderer
+ */
+ Renderer CreateNativeImageRenderer() const;
+
+ /**
+ * Callback function of image resource loading succeed
+ * @param[in] image The Image content that we attempted to load from mImageUrl
+ */
+ void OnImageLoaded( ResourceImage image );
+
+ /**
+ * Set the value to the uTextureRect uniform
+ * @param[in] textureRect The texture rectangular area.
+ */
+ void SetTextureRectUniform( const Vector4& textureRect );
+
+ /**
+ * Clean the renderer from cache, and remove the image from atlas if it is not used anymore
+ */
+ void CleanCache(const std::string& url);
+
+ /**
+ * Set shader code for nativeimage if it exists
*/
- void ApplyImageToSampler();
+ void SetNativeFragmentShaderCode( Dali::NativeImage& nativeImage );
private:
Image mImage;
+ ImageAtlasManager& mAtlasManager;
std::string mImageUrl;
Dali::ImageDimensions mDesiredSize;
Dali::FittingMode::Type mFittingMode;
Dali::SamplingMode::Type mSamplingMode;
+ std::string mNativeFragmentShaderCode;
+ bool mNativeImageFlag;
};
} // namespace Internal