1 #ifndef DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_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/visuals/visual-impl.h>
23 #include <dali-toolkit/internal/visuals/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< ImageVisual > ImageVisualPtr;
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 |
56 * | synchronousLoading | BOOLEAN |
58 * where imageFittingMode should be one of the following fitting modes:
65 * where imageSamplingMode should be one of the following sampling modes:
76 class ImageVisual: public Visual, public ConnectionTracker
83 * @param[in] factoryCache The VisualFactoryCache object
84 * @param[in] atlasManager The atlasManager object
86 ImageVisual( VisualFactoryCache& factoryCache, ImageAtlasManager& atlasManager );
89 * @brief A reference counted object may only be deleted by calling Unreference().
93 public: // from Visual
96 * @copydoc Visual::SetSize
98 virtual void SetSize( const Vector2& size );
101 * @copydoc Visual::GetNaturalSize
103 virtual void GetNaturalSize( Vector2& naturalSize ) const;
106 * @copydoc Visual::SetClipRect
108 virtual void SetClipRect( const Rect<int>& clipRect );
111 * @copydoc Visual::SetOffset
113 virtual void SetOffset( const Vector2& offset );
116 * @copydoc Visual::CreatePropertyMap
118 virtual void DoCreatePropertyMap( Property::Map& map ) const;
122 * @copydoc Visual::DoInitialize
124 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
127 * @copydoc Visual::DoSetOnStage
129 virtual void DoSetOnStage( Actor& actor );
132 * @copydoc Visual::DoSetOffStage
134 virtual void DoSetOffStage( Actor& actor );
139 * Get the standard image rendering shader.
140 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
142 static Shader GetImageShader( VisualFactoryCache& factoryCache );
145 * @brief Sets the image of this renderer to the resource at imageUrl
146 * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
148 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
149 * @param[in] imageUrl The URL of the image resource to use
150 * @param[in] size The width and height to fit the loaded image to.
151 * @param[in] fittingMode The FittingMode of the resource to load
152 * @param[in] samplingMode The SamplingMode of the resource to load
154 void SetImage( Actor& actor,
155 const std::string& imageUrl,
156 ImageDimensions size=ImageDimensions(),
157 FittingMode::Type fittingMode = FittingMode::DEFAULT,
158 Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
161 * @brief Sets the image of this renderer to use
163 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
164 * @param[in] image The image to use
166 void SetImage( Actor& actor, const Image& image );
171 * @brief Applies the image to the texture set used for this renderer
173 * @param[in] image The Image to apply to the texture set used for this renderer
175 void ApplyImageToSampler( const Image& image );
178 * @brief Initializes the Dali::Renderer from an image url string
180 * @param[in] imageUrl The image url string to intialize this ImageVisual from
182 void InitializeRenderer( const std::string& imageUrl );
185 * @brief Initializes the Dali::Renderer from an image handle
187 * @param[in] image The image handle to intialize this ImageVisual from
189 void InitializeRenderer( const Image& image );
192 * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it
194 * @return Returns the created Dali::Renderer
196 Renderer CreateRenderer() const;
199 * @brief Creates the Dali::Renderer for NativeImage with custom sampler type and prefix, initializing it
201 * @return Returns the created Dali::Renderer
203 Renderer CreateNativeImageVisual() const;
206 * @brief Query whether resources requires to be loaded synchronously.
207 * @return Returns true if synchronoud resource loading is required, false otherwise.
209 bool IsSynchronousResourceLoading() const;
212 * @brief Do the synchronous resource loading
214 void DoSynchronousResourceLoading();
218 * @param[in] url The URL of the image resource to use.
219 * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously.
221 Image LoadImage( const std::string& url, bool synchronousLoading );
224 * Load the image and create a texture set to hold the texture, with automatic atlasing applied.
225 * @param [out] textureRect The texture area of the resource image in the atlas.
226 * @param[in] url The URL of the image resource to use.
227 * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously.
229 TextureSet CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading );
232 * Callback function of image resource loading succeed
233 * @param[in] image The Image content that we attempted to load from mImageUrl
235 void OnImageLoaded( ResourceImage image );
238 * Set the value to the uTextureRect uniform
239 * @param[in] textureRect The texture rectangular area.
241 void SetTextureRectUniform( const Vector4& textureRect );
244 * Clean the renderer from cache, and remove the image from atlas if it is not used anymore
246 void CleanCache(const std::string& url);
249 * Set shader code for nativeimage if it exists
251 void SetNativeFragmentShaderCode( Dali::NativeImage& nativeImage );
255 ImageAtlasManager& mAtlasManager;
258 std::string mImageUrl;
259 Dali::ImageDimensions mDesiredSize;
260 Dali::FittingMode::Type mFittingMode;
261 Dali::SamplingMode::Type mSamplingMode;
263 std::string mNativeFragmentShaderCode;
264 bool mNativeImageFlag;
267 } // namespace Internal
269 } // namespace Toolkit
273 #endif /* DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_H */