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-base-impl.h>
23 #include <dali-toolkit/devel-api/image-loader/atlas-upload-observer.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>
29 #include <dali/devel-api/object/weak-handle.h>
34 #include <dali-toolkit/devel-api/image-loader/atlas-upload-observer.h>
35 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
36 #include <dali-toolkit/internal/visuals/visual-url.h>
38 >>>>>>> 8cfc796... Encapsulated visual URL in new VisualUrl class.
51 typedef IntrusivePtr< ImageVisual > ImageVisualPtr;
54 * The visual which renders an image to the control's quad
56 * The following properties are optional
58 * | %Property Name | Type |
59 * |--------------------|------------------|
61 * | fittingMode | STRING |
62 * | samplingMode | STRING |
63 * | desiredWidth | INT |
64 * | desiredHeight | INT |
65 * | synchronousLoading | BOOLEAN |
67 * where imageFittingMode should be one of the following fitting modes:
74 * where imageSamplingMode should be one of the following sampling modes:
85 class ImageVisual: public Visual::Base, public ConnectionTracker, public AtlasUploadObserver
93 * @brief Create a new image visual with a URL.
95 * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
97 * @param[in] factoryCache The VisualFactoryCache object
98 * @param[in] imageUrl The URL of the image resource to use
99 * @param[in] properties A Property::Map containing settings for this visual
100 * @param[in] size The width and height to fit the loaded image to.
101 * @param[in] fittingMode The FittingMode of the resource to load
102 * @param[in] samplingMode The SamplingMode of the resource to load
103 * @return A smart-pointer to the newly allocated visual.
105 static ImageVisualPtr New( VisualFactoryCache& factoryCache,
106 const VisualUrl& imageUrl,
107 const Property::Map& properties,
108 ImageDimensions size = ImageDimensions(),
109 FittingMode::Type fittingMode = FittingMode::DEFAULT,
110 Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
113 * @brief Create a new image visual with a URL.
115 * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
116 >>>>>>> 8cfc796... Encapsulated visual URL in new VisualUrl class.
118 * @param[in] factoryCache The VisualFactoryCache object
121 ImageVisual( VisualFactoryCache& factoryCache );
123 static ImageVisualPtr New( VisualFactoryCache& factoryCache,
124 const VisualUrl& imageUrl,
125 ImageDimensions size = ImageDimensions(),
126 FittingMode::Type fittingMode = FittingMode::DEFAULT,
127 Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
128 >>>>>>> 8cfc796... Encapsulated visual URL in new VisualUrl class.
131 * @brief A reference counted object may only be deleted by calling Unreference().
135 public: // from Visual
138 * @copydoc Visual::GetNaturalSize
140 virtual void GetNaturalSize( Vector2& naturalSize ) const;
143 * @copydoc Visual::CreatePropertyMap
145 virtual void DoCreatePropertyMap( Property::Map& map ) const;
152 * @brief Constructor with a URL.
154 * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
156 * @param[in] factoryCache The VisualFactoryCache object
157 * @param[in] imageUrl The URL of the image resource to use
158 * @param[in] size The width and height to fit the loaded image to.
159 * @param[in] fittingMode The FittingMode of the resource to load
160 * @param[in] samplingMode The SamplingMode of the resource to load
162 ImageVisual( VisualFactoryCache& factoryCache,
163 const VisualUrl& imageUrl,
164 ImageDimensions size,
165 FittingMode::Type fittingMode,
166 Dali::SamplingMode::Type samplingMode );
168 >>>>>>> 8cfc796... Encapsulated visual URL in new VisualUrl class.
170 * @copydoc Visual::Base::DoInitialize
172 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
175 * @copydoc Visual::Base::DoSetOnStage
177 virtual void DoSetOnStage( Actor& actor );
180 * @copydoc Visual::Base::DoSetOffStage
182 virtual void DoSetOffStage( Actor& actor );
187 * Get the standard image rendering shader.
188 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
189 * @param[in] atlasing Whether texture atlasing is applied.
190 * @param[in] defaultTextureWrapping Whether the default texture wrap mode is applied.
192 static Shader GetImageShader( VisualFactoryCache& factoryCache, bool atlasing, bool defaultTextureWrapping );
195 * @brief Sets the image of this visual to the resource at imageUrl
196 * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
198 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
199 * @param[in] imageUrl The URL of the image resource to use
200 * @param[in] size The width and height to fit the loaded image to.
201 * @param[in] fittingMode The FittingMode of the resource to load
202 * @param[in] samplingMode The SamplingMode of the resource to load
204 void SetImage( Actor& actor,
205 const std::string& imageUrl,
206 ImageDimensions size=ImageDimensions(),
207 FittingMode::Type fittingMode = FittingMode::DEFAULT,
208 Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
211 * @brief Sets the image to be rendered by this visual
213 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
214 * @param[in] image The image to use
216 void SetImage( Actor& actor, const Image& image );
219 * @copydoc AtlasUploadObserver::UploadCompleted
221 * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready.
222 * This callback is the place to add the renderer as it would be called once the loading is finished.
224 virtual void UploadCompleted();
229 * @brief Applies the image to the texture set used for this renderer
231 * @param[in] image The Image to apply to the texture set used for this renderer
233 void ApplyImageToSampler( const Image& image );
236 * @brief Initializes the Dali::Renderer from the image url
238 void InitializeRenderer();
241 * @brief Initializes the Dali::Renderer from an image handle
243 * @param[in] image The image handle to intialize this ImageVisual from
245 void InitializeRenderer( const Image& image );
248 * @brief Creates the Dali::Renderer (potentially from the renderer cache), initializing it
250 * @return Returns the created Dali::Renderer
252 Renderer CreateRenderer() const;
255 * @brief Creates the Dali::Renderer for NativeImage with custom sampler type and prefix, initializing it
257 * @return Returns the created Dali::Renderer
259 Renderer CreateNativeImageRenderer() const;
262 * @brief Query whether resources requires to be loaded synchronously.
263 * @return Returns true if synchronoud resource loading is required, false otherwise.
265 bool IsSynchronousResourceLoading() const;
268 * @brief Do the synchronous resource loading
270 void DoSynchronousResourceLoading();
274 * @param[in] url The URL of the image resource to use.
275 * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously.
277 Image LoadImage( const std::string& url, bool synchronousLoading );
280 * Load the image and create a texture set to hold the texture, with automatic atlasing applied.
281 * @param [out] textureRect The texture area of the resource image in the atlas.
282 * @param[in] url The URL of the image resource to use.
283 * @param[in] synchronousLoading If true, the resource is loaded synchronously, otherwise asynchronously.
286 TextureSet CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading );
288 TextureSet CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing );
289 >>>>>>> 8cfc796... Encapsulated visual URL in new VisualUrl class.
292 * Callback function of image resource loading succeed
293 * @param[in] image The Image content that we attempted to load from mImageUrl
295 void OnImageLoaded( ResourceImage image );
298 * Set the value to the uTextureRect uniform
299 * @param[in] textureRect The texture rectangular area.
301 void SetTextureRectUniform( const Vector4& textureRect );
304 * Clean the renderer from cache, and remove the image from atlas if it is not used anymore
306 void CleanCache(const std::string& url);
309 * Set shader code for nativeimage if it exists
311 void SetNativeFragmentShaderCode( Dali::NativeImage& nativeImage );
317 WeakHandle<Actor> mPlacementActor;
321 >>>>>>> 8cfc796... Encapsulated visual URL in new VisualUrl class.
323 std::string mImageUrl;
324 Dali::ImageDimensions mDesiredSize;
325 Dali::FittingMode::Type mFittingMode;
326 Dali::SamplingMode::Type mSamplingMode;
327 Dali::WrapMode::Type mWrapModeU;
328 Dali::WrapMode::Type mWrapModeV;
330 std::string mNativeFragmentShaderCode;
331 bool mNativeImageFlag;
334 } // namespace Internal
336 } // namespace Toolkit
340 #endif /* DALI_TOOLKIT_INTERNAL_IMAGE_VISUAL_H */