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>
42 typedef IntrusivePtr< ImageRenderer > ImageRendererPtr;
45 * The renderer which renders an image to the control's quad
47 * The following properties are optional
49 * | %Property Name | Type |
50 * |-------------------------|------------------|
52 * | fittingMode | STRING |
53 * | samplingMode | STRING |
54 * | desiredWidth | INT |
55 * | desiredHeight | INT |
57 * where imageFittingMode should be one of the following fitting modes:
64 * where imageSamplingMode should be one of the following sampling modes:
75 class ImageRenderer: public ControlRenderer, public ConnectionTracker
82 * @param[in] factoryCache The RendererFactoryCache object
83 * @param[in] atlasManager The atlasManager object
85 ImageRenderer( RendererFactoryCache& factoryCache, ImageAtlasManager& atlasManager );
88 * @brief A reference counted object may only be deleted by calling Unreference().
92 public: // from ControlRenderer
95 * @copydoc ControlRenderer::SetSize
97 virtual void SetSize( const Vector2& size );
100 * @copydoc ControlRenderer::GetNaturalSize
102 virtual void GetNaturalSize( Vector2& naturalSize ) const;
105 * @copydoc ControlRenderer::SetClipRect
107 virtual void SetClipRect( const Rect<int>& clipRect );
110 * @copydoc ControlRenderer::SetOffset
112 virtual void SetOffset( const Vector2& offset );
115 * @copydoc ControlRenderer::CreatePropertyMap
117 virtual void DoCreatePropertyMap( Property::Map& map ) const;
121 * @copydoc ControlRenderer::DoInitialize
123 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
126 * @copydoc ControlRenderer::DoSetOnStage
128 virtual void DoSetOnStage( Actor& actor );
131 * @copydoc ControlRenderer::DoSetOffStage
133 virtual void DoSetOffStage( Actor& actor );
138 * Get the standard image rendering shader.
139 * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
141 static Shader GetImageShader( RendererFactoryCache& factoryCache );
144 * @brief Sets the image of this renderer to the resource at imageUrl
145 * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
147 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
148 * @param[in] imageUrl The URL to to image resource to use
149 * @param[in] size The width and height to fit the loaded image to.
150 * @param[in] fittingMode The FittingMode of the resource to load
151 * @param[in] samplingMode The SamplingMode of the resource to load
153 void SetImage( Actor& actor,
154 const std::string& imageUrl,
155 ImageDimensions size=ImageDimensions(),
156 FittingMode::Type fittingMode = FittingMode::DEFAULT,
157 Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
160 * @brief Sets the image of this renderer to use
162 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
163 * @param[in] image The image to use
165 void SetImage( Actor& actor, const Image& image );
170 * @brief Applies the image to the texture set used for this renderer
172 * @param[in] image The Image to apply to the texture set used for this renderer
174 void ApplyImageToSampler( const Image& image );
177 * @brief Initializes the Dali::Renderer from an image url string
179 * @param[in] imageUrl The image url string to intialize this ImageRenderer from
181 void InitializeRenderer( const std::string& imageUrl );
184 * @brief Initializes the Dali::Renderer from an image handle
186 * @param[in] image The image handle to intialize this ImageRenderer from
188 void InitializeRenderer( const Image& image );
191 * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it
193 * @return Returns the created Dali::Renderer
195 Renderer CreateRenderer() const;
198 * @brief Creates the Dali::Renderer for NativeImage with custom sampler type and prefix, initializing it
200 * @return Returns the created Dali::Renderer
202 Renderer CreateNativeImageRenderer() const;
205 * Callback function of image resource loading succeed
206 * @param[in] image The Image content that we attempted to load from mImageUrl
208 void OnImageLoaded( ResourceImage image );
211 * Set the value to the uTextureRect uniform
212 * @param[in] textureRect The texture rectangular area.
214 void SetTextureRectUniform( const Vector4& textureRect );
217 * Clean the renderer from cache, and remove the image from atlas if it is not used anymore
219 void CleanCache(const std::string& url);
222 * Set shader code for nativeimage if it exists
224 void SetNativeFragmentShaderCode( Dali::NativeImage& nativeImage );
228 ImageAtlasManager& mAtlasManager;
230 std::string mImageUrl;
231 Dali::ImageDimensions mDesiredSize;
232 Dali::FittingMode::Type mFittingMode;
233 Dali::SamplingMode::Type mSamplingMode;
235 std::string mNativeFragmentShaderCode;
236 bool mNativeImageFlag;
239 } // namespace Internal
241 } // namespace Toolkit
245 #endif /* __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__ */