1 #ifndef __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
23 #include <dali-toolkit/internal/controls/renderers/image-atlas-manager.h>
26 #include <dali/public-api/images/image.h>
27 #include <dali/public-api/images/image-operations.h>
28 #include <dali/public-api/images/resource-image.h>
40 typedef IntrusivePtr< ImageRenderer > ImageRendererPtr;
43 * The renderer which renders an image to the control's quad
45 * The following properties are optional
47 * | %Property Name | Type |
48 * |-------------------------|------------------|
49 * | imageUrl | STRING |
50 * | imageFittingMode | STRING |
51 * | imageSamplingMode | STRING |
52 * | imageDesiredWidth | INT |
53 * | imageDesiredHeight | INT |
55 * where imageFittingMode should be one of the following fitting modes:
62 * where imageSamplingMode should be one of the following sampling modes:
73 class ImageRenderer: public ControlRenderer, public ConnectionTracker
80 * @param[in] factoryCache The RendererFactoryCache object
81 * @param[in] atlasManager The atlasManager object
83 ImageRenderer( RendererFactoryCache& factoryCache, ImageAtlasManager& atlasManager );
86 * @brief A reference counted object may only be deleted by calling Unreference().
90 public: // from ControlRenderer
93 * @copydoc ControlRenderer::SetSize
95 virtual void SetSize( const Vector2& size );
98 * @copydoc ControlRenderer::GetNaturalSize
100 virtual void GetNaturalSize( Vector2& naturalSize ) const;
103 * @copydoc ControlRenderer::SetClipRect
105 virtual void SetClipRect( const Rect<int>& clipRect );
108 * @copydoc ControlRenderer::SetOffset
110 virtual void SetOffset( const Vector2& offset );
113 * @copydoc ControlRenderer::CreatePropertyMap
115 virtual void DoCreatePropertyMap( Property::Map& map ) const;
119 * @copydoc ControlRenderer::DoInitialize
121 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
124 * @copydoc ControlRenderer::DoSetOnStage
126 virtual void DoSetOnStage( Actor& actor );
129 * @copydoc ControlRenderer::DoSetOffStage
131 virtual void DoSetOffStage( Actor& actor );
136 * Get the standard image rendering shader.
137 * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
139 static Shader GetImageShader( RendererFactoryCache& factoryCache );
142 * @brief Sets the image of this renderer to the resource at imageUrl
143 * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
145 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
146 * @param[in] imageUrl The URL to to image resource to use
147 * @param[in] size The width and height to fit the loaded image to.
148 * @param[in] fittingMode The FittingMode of the resource to load
149 * @param[in] samplingMode The SamplingMode of the resource to load
151 void SetImage( Actor& actor,
152 const std::string& imageUrl,
153 ImageDimensions size=ImageDimensions(),
154 FittingMode::Type fittingMode = FittingMode::DEFAULT,
155 Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
158 * @brief Sets the image of this renderer to use
160 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
161 * @param[in] image The image to use
163 void SetImage( Actor& actor, const Image& image );
168 * @brief Applies the image to the material used for this renderer
170 * @param[in] image The Image to apply to the material used for this renderer
172 void ApplyImageToSampler( const Image& image );
175 * @brief Initializes the Dali::Renderer from an image url string
177 * @param[in] imageUrl The image url string to intialize this ImageRenderer from
179 void InitializeRenderer( const std::string& imageUrl );
182 * @brief Initializes the Dali::Renderer from an image handle
184 * @param[in] image The image handle to intialize this ImageRenderer from
186 void InitializeRenderer( const Image& image );
189 * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it
191 * @return Returns the created Dali::Renderer
193 Renderer CreateRenderer() const;
196 * Callback function of image resource loading succeed
197 * @param[in] image The Image content that we attempted to load from mImageUrl
199 void OnImageLoaded( ResourceImage image );
202 * Set the value to the uTextureRect uniform
203 * @param[in] textureRect The texture rectangular area.
205 void SetTextureRectUniform( const Vector4& textureRect );
208 * Clean the renderer from cache, and remove the image from atlas if it is not used anymore
210 void CleanCache(const std::string& url);
214 ImageAtlasManager& mAtlasManager;
215 Vector4 mTextureRect;
217 std::string mImageUrl;
218 Dali::ImageDimensions mDesiredSize;
219 Dali::FittingMode::Type mFittingMode;
220 Dali::SamplingMode::Type mSamplingMode;
224 } // namespace Internal
226 } // namespace Toolkit
230 #endif /* __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__ */