X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Frenderers%2Fimage%2Fimage-renderer.h;h=26f1d3151cb7da10740080501708f005fabb17ec;hp=efcbf530b54f4aa1908de71042c80feab867fdd0;hb=23ceb4d9eef323cddf0c0f6d13f3a02226926911;hpb=db3fc9592ec6897e668a62afa7ffdff3ad82c023 diff --git a/dali-toolkit/internal/controls/renderers/image/image-renderer.h b/dali-toolkit/internal/controls/renderers/image/image-renderer.h index efcbf53..26f1d31 100644 --- a/dali-toolkit/internal/controls/renderers/image/image-renderer.h +++ b/dali-toolkit/internal/controls/renderers/image/image-renderer.h @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include +#include // EXTERNAL INCLUDES #include @@ -29,6 +30,8 @@ namespace Dali { +class NativeImage; + namespace Toolkit { @@ -43,30 +46,31 @@ typedef IntrusivePtr< ImageRenderer > ImageRendererPtr; * * 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 | + * |--------------------|------------------| + * | url | STRING | + * | fittingMode | STRING | + * | samplingMode | STRING | + * | desiredWidth | INT | + * | desiredHeight | INT | + * | synchronousLoading | BOOLEAN | * - * where image-fitting-mode should be one of the following fitting modes: - * "shrink-to-fit" - * "scale-to-fill" - * "fit-width" - * "fit-height" - * "default" + * where imageFittingMode should be one of the following fitting modes: + * "SHRINK_TO_FIT" + * "SCALE_TO_FIT" + * "FIT_WIDTH" + * "FIT_HEIGHT" + * "DEFAULT" * - * where image-sampling-mode should be one of the following sampling modes: - * "box" - * "nearest" - * "linear" - * "box-then-nearest" - * "box-then-linear" - * "no-filter" - * "dont-care" - * "default" + * where imageSamplingMode should be one of the following sampling modes: + * "BOX" + * "NEAREST" + * "LINEAR" + * "BOX_THEN_NEAREST" + * "BOX_THEN_LINEAR" + * "NO_FILTER" + * "DONT_CARE" + * "DEFAULT" * */ class ImageRenderer: public ControlRenderer, public ConnectionTracker @@ -76,9 +80,10 @@ public: /** * @brief Constructor. * - * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object + * @param[in] factoryCache The RendererFactoryCache object + * @param[in] atlasManager The atlasManager object */ - ImageRenderer( RendererFactoryCache& factoryCache ); + ImageRenderer( RendererFactoryCache& factoryCache, ImageAtlasManager& atlasManager ); /** * @brief A reference counted object may only be deleted by calling Unreference(). @@ -116,7 +121,7 @@ protected: /** * @copydoc ControlRenderer::DoInitialize */ - virtual void DoInitialize( const Property::Map& propertyMap ); + virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); /** * @copydoc ControlRenderer::DoSetOnStage @@ -128,53 +133,100 @@ protected: */ virtual void DoSetOffStage( Actor& actor ); - /** - * @copydoc ControlRenderer::InitializeRenderer - */ - virtual void InitializeRenderer( Renderer& renderer ); - public: /** - * @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 + * Get the standard image rendering shader. + * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object */ - void SetImage( const std::string& imageUrl ); + 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] 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] 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( 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 Gets the image this renderer uses + * @brief Applies the image to the texture set used for this renderer * - * @return The image this renderer uses, which may be null if the image is set from a URL string and the renderer is not set as onstage + * @param[in] image The Image to apply to the texture set used for this renderer */ - Image GetImage() const; + void ApplyImageToSampler( const Image& image ); -private: + /** + * @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 Applies this renderer's image to the sampler to the material used for this renderer + * @brief Initializes the Dali::Renderer from an image handle + * + * @param[in] image The image handle to intialize this ImageRenderer from */ - void ApplyImageToSampler(); + 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; + + /** + * @brief Query whether resources requires to be loaded synchronously. + * @return Returns true if synchronoud resource loading is required, false otherwise. + */ + bool IsSynchronousResourceLoading() const; + + /** + * @brief Do the synchronous resource loading + */ + void DoSynchronousResourceLoading(); + + /** + * Load the image. + * @param[in] url The URL of the image resource to use. + * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously. + */ + Image LoadImage( const std::string& url, bool synchronousLoading ); + + /** + * Load the image and create a texture set to hold the texture, with automatic atlasing applied. + * @param [out] textureRect The texture area of the resource image in the atlas. + * @param[in] url The URL of the image resource to use. + * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously. + */ + TextureSet CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading ); /** * Callback function of image resource loading succeed @@ -182,14 +234,34 @@ private: */ 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 SetNativeFragmentShaderCode( Dali::NativeImage& nativeImage ); + private: Image mImage; + ImageAtlasManager& mAtlasManager; + PixelData mPixels; std::string mImageUrl; Dali::ImageDimensions mDesiredSize; Dali::FittingMode::Type mFittingMode; Dali::SamplingMode::Type mSamplingMode; + std::string mNativeFragmentShaderCode; + bool mNativeImageFlag; }; } // namespace Internal