Merge "Implement AsyncTaskManager for toolkit UTC" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-manager-impl.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/devel-api/adaptor-framework/image-loading.h>
23 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
24 #include <dali/integration-api/adaptor-framework/adaptor.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/rendering/geometry.h>
27
28 // INTERNAL HEADERS
29 #include <dali-toolkit/internal/texture-manager/texture-async-loading-helper.h>
30 #include <dali-toolkit/internal/texture-manager/texture-cache-manager.h>
31 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
32 #include <dali-toolkit/internal/visuals/rendering-addon.h>
33
34 namespace
35 {
36 constexpr auto INITIAL_HASH_NUMBER = size_t{0u};
37
38 constexpr auto TEXTURE_INDEX      = 0u; ///< The Index for texture
39 constexpr auto MASK_TEXTURE_INDEX = 1u; ///< The Index for mask texture
40 } // namespace
41
42 namespace Dali
43 {
44 namespace Toolkit
45 {
46 namespace Internal
47 {
48 #ifdef DEBUG_ENABLED
49 // Define logfilter Internal namespace level so other files (e.g. texture-cache-manager.cpp) can also use this filter.
50 Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TEXTURE_MANAGER");
51
52 // clang-format off
53 #define GET_LOAD_STATE_STRING(loadState) \
54   loadState == TextureManagerType::LoadState::NOT_STARTED      ? "NOT_STARTED"      : \
55   loadState == TextureManagerType::LoadState::LOADING          ? "LOADING"          : \
56   loadState == TextureManagerType::LoadState::LOAD_FINISHED    ? "LOAD_FINISHED"    : \
57   loadState == TextureManagerType::LoadState::WAITING_FOR_MASK ? "WAITING_FOR_MASK" : \
58   loadState == TextureManagerType::LoadState::MASK_APPLYING    ? "MASK_APPLYING"    : \
59   loadState == TextureManagerType::LoadState::MASK_APPLIED     ? "MASK_APPLIED"     : \
60   loadState == TextureManagerType::LoadState::UPLOADED         ? "UPLOADED"         : \
61   loadState == TextureManagerType::LoadState::CANCELLED        ? "CANCELLED"        : \
62   loadState == TextureManagerType::LoadState::MASK_CANCELLED   ? "MASK_CANCELLED"   : \
63   loadState == TextureManagerType::LoadState::LOAD_FAILED      ? "LOAD_FAILED"      : \
64                                                                  "Unknown"
65 // clang-format on
66 #endif
67
68 namespace
69 {
70 const uint32_t DEFAULT_ATLAS_SIZE(1024u);               ///< This size can fit 8 by 8 images of average size 128 * 128
71 const Vector4  FULL_ATLAS_RECT(0.0f, 0.0f, 1.0f, 1.0f); ///< UV Rectangle that covers the full Texture
72
73 void PreMultiply(Devel::PixelBuffer pixelBuffer, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
74 {
75   if(Pixel::HasAlpha(pixelBuffer.GetPixelFormat()))
76   {
77     if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
78     {
79       pixelBuffer.MultiplyColorByAlpha();
80     }
81   }
82   else
83   {
84     preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
85   }
86 }
87
88 } // Anonymous namespace
89
90 TextureManager::MaskingData::MaskingData()
91 : mAlphaMaskUrl(),
92   mAlphaMaskId(INVALID_TEXTURE_ID),
93   mContentScaleFactor(1.0f),
94   mCropToMask(true),
95   mPreappliedMasking(true),
96   mMaskImageLoadingFailed(false)
97 {
98 }
99
100 TextureManager::TextureManager(bool loadYuvPlanes)
101 : mTextureCacheManager(),
102   mAsyncLoader(std::unique_ptr<TextureAsyncLoadingHelper>(new TextureAsyncLoadingHelper(*this))),
103   mLifecycleObservers(),
104   mLoadQueue(),
105   mLoadingQueueTextureId(INVALID_TEXTURE_ID),
106   mRemoveQueue(),
107   mLoadYuvPlanes(loadYuvPlanes),
108   mRemoveProcessorRegistered(false)
109 {
110   // Initialize the AddOn
111   RenderingAddOn::Get();
112 }
113
114 TextureManager::~TextureManager()
115 {
116   if(mRemoveProcessorRegistered && Adaptor::IsAvailable())
117   {
118     Adaptor::Get().UnregisterProcessor(*this, true);
119     mRemoveProcessorRegistered = false;
120   }
121
122   for(auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
123   {
124     (*iter)->TextureManagerDestroyed();
125   }
126 }
127
128 TextureSet TextureManager::LoadAnimatedImageTexture(
129   const VisualUrl&                url,
130   Dali::AnimatedImageLoading      animatedImageLoading,
131   const uint32_t&                 frameIndex,
132   TextureManager::TextureId&      textureId,
133   MaskingDataPointer&             maskInfo,
134   const Dali::ImageDimensions&    desiredSize,
135   const Dali::FittingMode::Type&  fittingMode,
136   const Dali::SamplingMode::Type& samplingMode,
137   const bool&                     synchronousLoading,
138   TextureUploadObserver*          textureObserver,
139   TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
140 {
141   TextureSet textureSet;
142
143   if(synchronousLoading)
144   {
145     Devel::PixelBuffer pixelBuffer;
146     if(animatedImageLoading)
147     {
148       pixelBuffer = animatedImageLoading.LoadFrame(frameIndex, desiredSize, fittingMode, samplingMode);
149     }
150     if(!pixelBuffer)
151     {
152       DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
153     }
154     else
155     {
156       Texture maskTexture;
157       if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
158       {
159         Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), desiredSize, fittingMode, samplingMode, true);
160         if(maskPixelBuffer)
161         {
162           if(!maskInfo->mPreappliedMasking)
163           {
164             PixelData maskPixelData = Devel::PixelBuffer::Convert(maskPixelBuffer); // takes ownership of buffer
165             maskTexture             = Texture::New(Dali::TextureType::TEXTURE_2D, maskPixelData.GetPixelFormat(), maskPixelData.GetWidth(), maskPixelData.GetHeight());
166             maskTexture.Upload(maskPixelData);
167           }
168           else
169           {
170             pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
171           }
172         }
173         else
174         {
175           DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous mask image loading is failed\n");
176         }
177       }
178
179       if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
180       {
181         PreMultiply(pixelBuffer, preMultiplyOnLoad);
182       }
183
184       PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
185       if(!textureSet)
186       {
187         Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
188         texture.Upload(pixelData);
189         textureSet = TextureSet::New();
190         textureSet.SetTexture(TEXTURE_INDEX, texture);
191         if(maskTexture)
192         {
193           textureSet.SetTexture(MASK_TEXTURE_INDEX, maskTexture);
194         }
195       }
196     }
197   }
198   else
199   {
200     TextureId alphaMaskId        = INVALID_TEXTURE_ID;
201     float     contentScaleFactor = 1.0f;
202     bool      cropToMask         = false;
203     if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
204     {
205       maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE);
206       alphaMaskId            = maskInfo->mAlphaMaskId;
207       if(maskInfo->mPreappliedMasking)
208       {
209         contentScaleFactor = maskInfo->mContentScaleFactor;
210         cropToMask         = maskInfo->mCropToMask;
211       }
212     }
213
214     textureId = RequestLoadInternal(url, alphaMaskId, textureId, contentScaleFactor, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, cropToMask, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoad, animatedImageLoading, frameIndex, false);
215
216     TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
217     if(loadState == TextureManager::LoadState::UPLOADED)
218     {
219       // LoadComplete has already been called - keep the same texture set
220       textureSet = GetTextureSet(textureId);
221     }
222   }
223
224   return textureSet;
225 }
226
227 Devel::PixelBuffer TextureManager::LoadPixelBuffer(
228   const VisualUrl&                url,
229   const Dali::ImageDimensions&    desiredSize,
230   const Dali::FittingMode::Type&  fittingMode,
231   const Dali::SamplingMode::Type& samplingMode,
232   const bool&                     synchronousLoading,
233   TextureUploadObserver*          textureObserver,
234   const bool&                     orientationCorrection,
235   TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
236 {
237   Devel::PixelBuffer pixelBuffer;
238   if(synchronousLoading)
239   {
240     if(url.IsValid())
241     {
242       if(url.IsBufferResource())
243       {
244         const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
245         if(encodedImageBuffer)
246         {
247           pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
248         }
249       }
250       else
251       {
252         pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
253       }
254       if(pixelBuffer && preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
255       {
256         PreMultiply(pixelBuffer, preMultiplyOnLoad);
257       }
258     }
259   }
260   else
261   {
262     RequestLoadInternal(url, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
263   }
264
265   return pixelBuffer;
266 }
267
268 TextureSet TextureManager::LoadTexture(
269   const VisualUrl&                    url,
270   const Dali::ImageDimensions&        desiredSize,
271   const Dali::FittingMode::Type&      fittingMode,
272   const Dali::SamplingMode::Type&     samplingMode,
273   MaskingDataPointer&                 maskInfo,
274   const bool&                         synchronousLoading,
275   TextureManager::TextureId&          textureId,
276   Vector4&                            textureRect,
277   Dali::ImageDimensions&              textureRectSize,
278   bool&                               atlasingStatus,
279   bool&                               loadingStatus,
280   TextureUploadObserver*              textureObserver,
281   AtlasUploadObserver*                atlasObserver,
282   ImageAtlasManagerPtr                imageAtlasManager,
283   const bool&                         orientationCorrection,
284   const TextureManager::ReloadPolicy& reloadPolicy,
285   TextureManager::MultiplyOnLoad&     preMultiplyOnLoad)
286 {
287   TextureSet textureSet;
288
289   loadingStatus = false;
290   textureRect   = FULL_ATLAS_RECT;
291
292   if(VisualUrl::TEXTURE == url.GetProtocolType())
293   {
294     std::string location = url.GetLocation();
295     if(location.size() > 0u)
296     {
297       TextureId id                  = std::stoi(location);
298       auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
299       if(externalTextureInfo.textureSet)
300       {
301         if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
302         {
303           // Change preMultiplyOnLoad value so make caller determine to preMultiplyAlpha or not.
304           // TODO : Should we seperate input and output value?
305           preMultiplyOnLoad = externalTextureInfo.preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
306         }
307
308         TextureId alphaMaskId = INVALID_TEXTURE_ID;
309         if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
310         {
311           maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, StorageType::KEEP_TEXTURE, synchronousLoading);
312           alphaMaskId            = maskInfo->mAlphaMaskId;
313
314           // Create new textureId. this textureId is not same as location
315           textureId = RequestLoad(url, alphaMaskId, textureId, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad, synchronousLoading);
316
317           TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
318           if(loadState == TextureManager::LoadState::UPLOADED)
319           {
320             textureSet = GetTextureSet(textureId);
321           }
322         }
323         else
324         {
325           // TextureId is same as location
326           textureId = id;
327
328           textureSet = TextureSet::New();
329           textureSet.SetTexture(TEXTURE_INDEX, externalTextureInfo.textureSet.GetTexture(TEXTURE_INDEX));
330         }
331       }
332     }
333   }
334   else
335   {
336     // For Atlas
337     if(synchronousLoading && atlasingStatus)
338     {
339       const bool synchronousAtlasAvaliable = (desiredSize != ImageDimensions() || url.IsLocalResource()) ? imageAtlasManager->CheckAtlasAvailable(url, desiredSize)
340                                                                                                          : false;
341       if(synchronousAtlasAvaliable)
342       {
343         std::vector<Devel::PixelBuffer> pixelBuffers;
344         LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, false, pixelBuffers);
345
346         if(!pixelBuffers.empty() && maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
347         {
348           std::vector<Devel::PixelBuffer> maskPixelBuffers;
349           LoadImageSynchronously(maskInfo->mAlphaMaskUrl, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true, false, maskPixelBuffers);
350           if(!maskPixelBuffers.empty())
351           {
352             pixelBuffers[0].ApplyMask(maskPixelBuffers[0], maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
353           }
354         }
355
356         PixelData data;
357         if(!pixelBuffers.empty())
358         {
359           PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
360           data = Devel::PixelBuffer::Convert(pixelBuffers[0]); // takes ownership of buffer
361
362           if(data)
363           {
364             textureSet = imageAtlasManager->Add(textureRect, data);
365             if(textureSet)
366             {
367               textureRectSize.SetWidth(data.GetWidth());
368               textureRectSize.SetHeight(data.GetHeight());
369             }
370           }
371           else
372           {
373             DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous Texture loading with atlasing is failed.\n");
374           }
375         }
376         if(!textureSet)
377         {
378           atlasingStatus = false;
379         }
380       }
381     }
382
383     if(!textureSet)
384     {
385       loadingStatus = true;
386       // Atlas manager can chage desired size when it is set by 0,0.
387       // We should store into textureRectSize only if atlasing successed.
388       // So copy inputed desiredSize, and replace value into textureRectSize only if atlasing success.
389       Dali::ImageDimensions atlasDesiredSize = desiredSize;
390       if(atlasingStatus)
391       {
392         if(url.IsBufferResource())
393         {
394           const EncodedImageBuffer& encodedImageBuffer = GetEncodedImageBuffer(url.GetUrl());
395           if(encodedImageBuffer)
396           {
397             textureSet = imageAtlasManager->Add(textureRect, encodedImageBuffer, desiredSize, fittingMode, true, atlasObserver);
398           }
399         }
400         else
401         {
402           textureSet = imageAtlasManager->Add(textureRect, url, atlasDesiredSize, fittingMode, true, atlasObserver);
403         }
404       }
405       if(!textureSet) // big image, no atlasing or atlasing failed
406       {
407         atlasingStatus = false;
408
409         TextureId alphaMaskId        = INVALID_TEXTURE_ID;
410         float     contentScaleFactor = 1.0f;
411         bool      cropToMask         = false;
412         if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
413         {
414           maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? StorageType::KEEP_PIXEL_BUFFER : StorageType::KEEP_TEXTURE, synchronousLoading);
415           alphaMaskId            = maskInfo->mAlphaMaskId;
416           if(maskInfo && maskInfo->mPreappliedMasking)
417           {
418             contentScaleFactor = maskInfo->mContentScaleFactor;
419             cropToMask         = maskInfo->mCropToMask;
420           }
421         }
422
423         textureId = RequestLoad(
424           url,
425           alphaMaskId,
426           textureId,
427           contentScaleFactor,
428           desiredSize,
429           fittingMode,
430           samplingMode,
431           UseAtlas::NO_ATLAS,
432           cropToMask,
433           textureObserver,
434           orientationCorrection,
435           reloadPolicy,
436           preMultiplyOnLoad,
437           synchronousLoading);
438
439         TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
440         if(loadState == TextureManager::LoadState::UPLOADED)
441         {
442           // LoadComplete has already been called - keep the same texture set
443           textureSet = GetTextureSet(textureId);
444         }
445
446         // If we are loading the texture, or waiting for the ready signal handler to complete, inform
447         // caller that they need to wait.
448         loadingStatus = (loadState == TextureManager::LoadState::LOADING ||
449                          loadState == TextureManager::LoadState::WAITING_FOR_MASK ||
450                          loadState == TextureManager::LoadState::MASK_APPLYING ||
451                          loadState == TextureManager::LoadState::MASK_APPLIED ||
452                          loadState == TextureManager::LoadState::NOT_STARTED ||
453                          mLoadingQueueTextureId != INVALID_TEXTURE_ID);
454       }
455       else
456       {
457         textureRectSize = atlasDesiredSize;
458       }
459     }
460   }
461
462   if(synchronousLoading)
463   {
464     loadingStatus = false;
465   }
466
467   return textureSet;
468 }
469
470 TextureManager::TextureId TextureManager::RequestLoad(
471   const VisualUrl&                    url,
472   const ImageDimensions&              desiredSize,
473   const Dali::FittingMode::Type&      fittingMode,
474   const Dali::SamplingMode::Type&     samplingMode,
475   const UseAtlas&                     useAtlas,
476   TextureUploadObserver*              observer,
477   const bool&                         orientationCorrection,
478   const TextureManager::ReloadPolicy& reloadPolicy,
479   TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
480   const bool&                         synchronousLoading)
481 {
482   return RequestLoadInternal(url, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
483 }
484
485 TextureManager::TextureId TextureManager::RequestLoad(
486   const VisualUrl&                    url,
487   const TextureManager::TextureId&    maskTextureId,
488   const TextureManager::TextureId&    previousTextureId,
489   const float&                        contentScale,
490   const Dali::ImageDimensions&        desiredSize,
491   const Dali::FittingMode::Type&      fittingMode,
492   const Dali::SamplingMode::Type&     samplingMode,
493   const TextureManager::UseAtlas&     useAtlas,
494   const bool&                         cropToMask,
495   TextureUploadObserver*              observer,
496   const bool&                         orientationCorrection,
497   const TextureManager::ReloadPolicy& reloadPolicy,
498   TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
499   const bool&                         synchronousLoading)
500 {
501   return RequestLoadInternal(url, maskTextureId, previousTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
502 }
503
504 TextureManager::TextureId TextureManager::RequestMaskLoad(
505   const VisualUrl& maskUrl,
506   StorageType      storageType,
507   const bool&      synchronousLoading)
508 {
509   // Use the normal load procedure to get the alpha mask.
510   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
511   return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, UseAtlas::NO_ATLAS, false, storageType, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
512 }
513
514 TextureManager::TextureId TextureManager::RequestLoadInternal(
515   const VisualUrl&                    url,
516   const TextureManager::TextureId&    maskTextureId,
517   const TextureManager::TextureId&    previousTextureId,
518   const float&                        contentScale,
519   const Dali::ImageDimensions&        desiredSize,
520   const Dali::FittingMode::Type&      fittingMode,
521   const Dali::SamplingMode::Type&     samplingMode,
522   const TextureManager::UseAtlas&     useAtlas,
523   const bool&                         cropToMask,
524   const TextureManager::StorageType&  storageType,
525   TextureUploadObserver*              observer,
526   const bool&                         orientationCorrection,
527   const TextureManager::ReloadPolicy& reloadPolicy,
528   TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
529   Dali::AnimatedImageLoading          animatedImageLoading,
530   const std::uint32_t&                frameIndex,
531   const bool&                         synchronousLoading)
532 {
533   TextureHash       textureHash   = INITIAL_HASH_NUMBER;
534   TextureCacheIndex cacheIndex    = INVALID_CACHE_INDEX;
535   bool              loadYuvPlanes = (mLoadYuvPlanes && maskTextureId == INVALID_TEXTURE_ID && storageType == StorageType::UPLOAD_TO_TEXTURE);
536
537   if(storageType != StorageType::RETURN_PIXEL_BUFFER)
538   {
539     textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask, frameIndex);
540
541     // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
542     cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, useAtlas, storageType, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
543   }
544
545   TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
546   // Check if the requested Texture exists in the cache.
547   if(cacheIndex != INVALID_CACHE_INDEX)
548   {
549     if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
550     {
551       // Mark this texture being used by another client resource, or Reload forced without request load before.
552       // Forced reload which have current texture before, would replace the current texture.
553       // without the need for incrementing the reference count.
554       ++(mTextureCacheManager[cacheIndex].referenceCount);
555     }
556     textureId = mTextureCacheManager[cacheIndex].textureId;
557
558     // Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
559     preMultiplyOnLoad = mTextureCacheManager[cacheIndex].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
560     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) Using cached texture id@%d, textureId=%d, maskTextureId=%d, prevTextureId=%d, frameindex=%d, premultiplied=%d, refCount=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, previousTextureId, frameIndex, mTextureCacheManager[cacheIndex].preMultiplied ? 1 : 0, static_cast<int>(mTextureCacheManager[cacheIndex].referenceCount));
561   }
562
563   if(textureId == INVALID_TEXTURE_ID) // There was no caching, or caching not required
564   {
565     textureId = mTextureCacheManager.GenerateTextureId();
566
567     bool preMultiply = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
568
569     // Cache new texutre, and get cacheIndex.
570     cacheIndex = mTextureCacheManager.AppendCache(TextureInfo(textureId, maskTextureId, url, desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, useAtlas, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex, loadYuvPlanes));
571     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestLoad( url=%s observer=%p ) New texture, cacheIndex:%d, textureId=%d, maskTextureId=%d, frameindex=%d premultiply=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, frameIndex, preMultiply);
572   }
573
574   // The below code path is common whether we are using the cache or not.
575   // The textureInfoIndex now refers to either a pre-existing cached TextureInfo,
576   // or a new TextureInfo just created.
577   TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
578   textureInfo.maskTextureId         = maskTextureId;
579   textureInfo.storageType           = storageType;
580   textureInfo.orientationCorrection = orientationCorrection;
581
582   // the case using external texture has already been loaded texture, so change its status to WAITING_FOR_MASK.
583   if(url.GetProtocolType() == VisualUrl::TEXTURE)
584   {
585     if(textureInfo.loadState != LoadState::UPLOADED)
586     {
587       textureInfo.preMultiplied = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
588       textureInfo.loadState     = TextureManager::LoadState::WAITING_FOR_MASK;
589     }
590   }
591
592   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n", GET_LOAD_STATE_STRING(textureInfo.loadState));
593
594   // Force reloading of texture by setting loadState unless already loading or cancelled.
595   if(TextureManager::ReloadPolicy::FORCED == reloadPolicy &&
596      TextureManager::LoadState::LOADING != textureInfo.loadState &&
597      TextureManager::LoadState::WAITING_FOR_MASK != textureInfo.loadState &&
598      TextureManager::LoadState::MASK_APPLYING != textureInfo.loadState &&
599      TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
600      TextureManager::LoadState::CANCELLED != textureInfo.loadState &&
601      TextureManager::LoadState::MASK_CANCELLED != textureInfo.loadState)
602   {
603     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::RequestLoad( url=%s observer=%p ) ForcedReload cacheIndex:%d, textureId=%d, maskTextureId=%d, prevTextureId=%d\n", url.GetUrl().c_str(), observer, cacheIndex.GetIndex(), textureId, maskTextureId, previousTextureId);
604     textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
605   }
606
607   if(!synchronousLoading)
608   {
609     // Check if we should add the observer.
610     // Only do this if we have not loaded yet and it will not have loaded by the end of this method.
611     switch(textureInfo.loadState)
612     {
613       case TextureManager::LoadState::LOAD_FAILED: // Failed notifies observer which then stops observing.
614       case TextureManager::LoadState::NOT_STARTED:
615       {
616         LoadOrQueueTexture(textureInfo, observer); // If called inside NotifyObservers, queues until afterwards
617         break;
618       }
619       case TextureManager::LoadState::LOADING:
620       case TextureManager::LoadState::WAITING_FOR_MASK:
621       case TextureManager::LoadState::MASK_APPLYING:
622       case TextureManager::LoadState::MASK_APPLIED:
623       {
624         // Do not observe even we reload forced when texture is already loading state.
625         if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
626         {
627           ObserveTexture(textureInfo, observer);
628         }
629         break;
630       }
631       case TextureManager::LoadState::UPLOADED:
632       {
633         if(observer)
634         {
635           LoadOrQueueTexture(textureInfo, observer);
636         }
637         break;
638       }
639       case TextureManager::LoadState::CANCELLED:
640       {
641         // A cancelled texture hasn't finished loading yet. Treat as a loading texture
642         // (it's ref count has already been incremented, above)
643         textureInfo.loadState = TextureManager::LoadState::LOADING;
644         ObserveTexture(textureInfo, observer);
645         break;
646       }
647       case TextureManager::LoadState::MASK_CANCELLED:
648       {
649         // A cancelled texture hasn't finished mask applying yet. Treat as a mask applying texture
650         // (it's ref count has already been incremented, above)
651         textureInfo.loadState = TextureManager::LoadState::MASK_APPLYING;
652         ObserveTexture(textureInfo, observer);
653         break;
654       }
655       case TextureManager::LoadState::LOAD_FINISHED:
656       {
657         // Loading has already completed.
658         if(observer && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
659         {
660           LoadOrQueueTexture(textureInfo, observer);
661         }
662         break;
663       }
664     }
665   }
666   else
667   {
668     // If the image is already finished to load, use cached texture.
669     // We don't need to consider Observer because this is synchronous loading.
670     if(!(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
671          textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED))
672     {
673       if(url.GetProtocolType() == VisualUrl::TEXTURE)
674       {
675         // Get external textureSet from cacheManager.
676         std::string location = textureInfo.url.GetLocation();
677         if(!location.empty())
678         {
679           TextureId id                  = std::stoi(location);
680           auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
681           textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0));
682           textureInfo.loadState = LoadState::UPLOADED;
683         }
684       }
685       else
686       {
687         std::vector<Devel::PixelBuffer> pixelBuffers;
688         LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, loadYuvPlanes, pixelBuffers);
689
690         if(pixelBuffers.empty())
691         {
692           // If pixelBuffer loading is failed in synchronously, call RequestRemove() method.
693           RequestRemove(textureId, nullptr);
694           return INVALID_TEXTURE_ID;
695         }
696
697         if(storageType == StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
698         {
699           textureInfo.pixelBuffer = pixelBuffers[0]; // Store the pixel data
700           textureInfo.loadState   = LoadState::LOAD_FINISHED;
701         }
702         else // For the image loading.
703         {
704           Texture maskTexture;
705           if(maskTextureId != INVALID_TEXTURE_ID)
706           {
707             TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
708             if(maskCacheIndex != INVALID_CACHE_INDEX)
709             {
710               if(mTextureCacheManager[maskCacheIndex].storageType == StorageType::KEEP_PIXEL_BUFFER)
711               {
712                 Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
713                 if(maskPixelBuffer)
714                 {
715                   pixelBuffers[0].ApplyMask(maskPixelBuffer, contentScale, cropToMask);
716                 }
717                 else
718                 {
719                   DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
720                 }
721               }
722             }
723             else
724             {
725               DALI_LOG_ERROR("Mask image is not stored in cache.\n");
726             }
727           }
728           PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
729
730           // Upload texture
731           UploadTextures(pixelBuffers, textureInfo);
732         }
733       }
734     }
735   }
736
737   return textureId;
738 }
739
740 void TextureManager::RequestRemove(const TextureManager::TextureId& textureId, TextureUploadObserver* observer)
741 {
742   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestRemove( textureId=%d observer=%p )\n", textureId, observer);
743
744   // Queue to remove.
745   if(textureId != INVALID_TEXTURE_ID)
746   {
747     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
748     if(textureCacheIndex != INVALID_CACHE_INDEX)
749     {
750       if(observer)
751       {
752         // Remove observer from cached texture info
753         TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
754         RemoveTextureObserver(textureInfo, observer);
755       }
756
757       mRemoveQueue.PushBack(textureId);
758
759       if(!mRemoveProcessorRegistered && Adaptor::IsAvailable())
760       {
761         mRemoveProcessorRegistered = true;
762         Adaptor::Get().RegisterProcessor(*this, true);
763       }
764     }
765   }
766 }
767
768 void TextureManager::Remove(const TextureManager::TextureId& textureId)
769 {
770   if(textureId != INVALID_TEXTURE_ID)
771   {
772     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
773     if(textureCacheIndex != INVALID_CACHE_INDEX)
774     {
775       TextureManager::TextureId maskTextureId = INVALID_TEXTURE_ID;
776       TextureInfo&              textureInfo(mTextureCacheManager[textureCacheIndex]);
777       // We only need to consider maskTextureId when texture's loadState is not cancelled. Because it is already deleted.
778       if(textureInfo.loadState != LoadState::CANCELLED && textureInfo.loadState != LoadState::MASK_CANCELLED)
779       {
780         if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
781         {
782           maskTextureId = textureInfo.maskTextureId;
783         }
784       }
785
786       DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Remove( textureId=%d ) cacheIndex:%d removal maskTextureId=%d, loadState=%s\n", textureId, textureCacheIndex.GetIndex(), maskTextureId, GET_LOAD_STATE_STRING(textureInfo.loadState));
787
788       // Remove textureId in CacheManager. Now, textureInfo is invalidate.
789       mTextureCacheManager.RemoveCache(textureInfo);
790
791       // Remove maskTextureId in CacheManager
792       if(maskTextureId != INVALID_TEXTURE_ID)
793       {
794         TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
795         if(maskCacheIndex != INVALID_CACHE_INDEX)
796         {
797           TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
798
799           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Remove mask texture( maskTextureId=%d ) cacheIndex:%d, loadState=%s\n", maskTextureId, maskCacheIndex.GetIndex(), GET_LOAD_STATE_STRING(maskTextureInfo.loadState));
800
801           mTextureCacheManager.RemoveCache(maskTextureInfo);
802         }
803       }
804     }
805   }
806 }
807
808 void TextureManager::ProcessRemoveQueue()
809 {
810   // Note that RemoveQueue is not be changed during Remove().
811   for(auto&& textureId : mRemoveQueue)
812   {
813     if(textureId != INVALID_TEXTURE_ID)
814     {
815       Remove(textureId);
816     }
817   }
818   mRemoveQueue.Clear();
819 }
820
821 void TextureManager::Process(bool postProcessor)
822 {
823   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Process()\n");
824
825   ProcessRemoveQueue();
826
827   if(Adaptor::IsAvailable())
828   {
829     Adaptor::Get().UnregisterProcessor(*this, true);
830     mRemoveProcessorRegistered = false;
831   }
832 }
833
834 void TextureManager::LoadImageSynchronously(
835   const VisualUrl&                 url,
836   const Dali::ImageDimensions&     desiredSize,
837   const Dali::FittingMode::Type&   fittingMode,
838   const Dali::SamplingMode::Type&  samplingMode,
839   const bool&                      orientationCorrection,
840   const bool&                      loadYuvPlanes,
841   std::vector<Devel::PixelBuffer>& pixelBuffers)
842 {
843   Devel::PixelBuffer pixelBuffer;
844   if(url.IsBufferResource())
845   {
846     const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
847     if(encodedImageBuffer)
848     {
849       pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
850     }
851   }
852   else
853   {
854     if(loadYuvPlanes)
855     {
856       Dali::LoadImagePlanesFromFile(url.GetUrl(), pixelBuffers, desiredSize, fittingMode, samplingMode, orientationCorrection);
857     }
858     else
859     {
860       pixelBuffer = Dali::LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
861     }
862   }
863
864   if(pixelBuffer)
865   {
866     pixelBuffers.push_back(pixelBuffer);
867   }
868 }
869
870 void TextureManager::AddObserver(TextureManager::LifecycleObserver& observer)
871 {
872   // make sure an observer doesn't observe the same object twice
873   // otherwise it will get multiple calls to ObjectDestroyed()
874   DALI_ASSERT_DEBUG(mLifecycleObservers.End() == std::find(mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
875   mLifecycleObservers.PushBack(&observer);
876 }
877
878 void TextureManager::RemoveObserver(TextureManager::LifecycleObserver& observer)
879 {
880   // Find the observer...
881   auto endIter = mLifecycleObservers.End();
882   for(auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
883   {
884     if((*iter) == &observer)
885     {
886       mLifecycleObservers.Erase(iter);
887       break;
888     }
889   }
890   DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
891 }
892
893 void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
894 {
895   switch(textureInfo.loadState)
896   {
897     case LoadState::NOT_STARTED:
898     case LoadState::LOAD_FAILED:
899     {
900       if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
901       {
902         QueueLoadTexture(textureInfo, observer);
903       }
904       else
905       {
906         LoadTexture(textureInfo, observer);
907       }
908       break;
909     }
910     case LoadState::UPLOADED:
911     {
912       if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
913       {
914         QueueLoadTexture(textureInfo, observer);
915       }
916       else
917       {
918         // The Texture has already loaded. The other observers have already been notified.
919         // We need to send a "late" loaded notification for this observer.
920         if(observer)
921         {
922           EmitLoadComplete(observer, textureInfo, true);
923         }
924       }
925       break;
926     }
927     case LoadState::LOADING:
928     case LoadState::CANCELLED:
929     case LoadState::MASK_CANCELLED:
930     case LoadState::LOAD_FINISHED:
931     case LoadState::WAITING_FOR_MASK:
932     case LoadState::MASK_APPLYING:
933     case LoadState::MASK_APPLIED:
934     {
935       break;
936     }
937   }
938 }
939
940 void TextureManager::QueueLoadTexture(const TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
941 {
942   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Add observer to observer queue (textureId:%d, observer:%p)\n", textureInfo.textureId, observer);
943
944   const auto& textureId = textureInfo.textureId;
945   mLoadQueue.PushBack(QueueElement(textureId, observer));
946
947   if(observer)
948   {
949     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Connect DestructionSignal to observer:%p\n", observer);
950     observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
951   }
952 }
953
954 void TextureManager::LoadTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
955 {
956   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::LoadTexture(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
957   textureInfo.loadState = LoadState::LOADING;
958   if(!textureInfo.loadSynchronously)
959   {
960     auto premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
961     if(textureInfo.animatedImageLoading)
962     {
963       mAsyncLoader->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, premultiplyOnLoad);
964     }
965     else
966     {
967       mAsyncLoader->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad, textureInfo.loadYuvPlanes);
968     }
969   }
970   ObserveTexture(textureInfo, observer);
971 }
972
973 void TextureManager::ProcessLoadQueue()
974 {
975   for(auto&& element : mLoadQueue)
976   {
977     if(element.mTextureId == INVALID_TEXTURE_ID)
978     {
979       continue;
980     }
981
982     TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(element.mTextureId);
983     if(cacheIndex != INVALID_CACHE_INDEX)
984     {
985       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
986
987       DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::ProcessLoadQueue() textureId=%d, observer=%p, cacheIndex=@%d, loadState:%s\n", element.mTextureId, element.mObserver, cacheIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState));
988
989       if((textureInfo.loadState == LoadState::UPLOADED) || (textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER))
990       {
991         if(element.mObserver)
992         {
993           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", element.mObserver);
994           element.mObserver->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
995
996           EmitLoadComplete(element.mObserver, textureInfo, true);
997         }
998       }
999       else if(textureInfo.loadState == LoadState::LOADING)
1000       {
1001         // Note : LOADING state texture cannot be queue.
1002         // This case be occured when same texture id are queue in mLoadQueue.
1003         ObserveTexture(textureInfo, element.mObserver);
1004       }
1005       else
1006       {
1007         LoadTexture(textureInfo, element.mObserver);
1008       }
1009     }
1010   }
1011   mLoadQueue.Clear();
1012 }
1013
1014 void TextureManager::ObserveTexture(TextureManager::TextureInfo& textureInfo,
1015                                     TextureUploadObserver*       observer)
1016 {
1017   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ObserveTexture(): url:%s observer:%p\n", textureInfo.url.GetUrl().c_str(), observer);
1018
1019   if(observer)
1020   {
1021     textureInfo.observerList.PushBack(observer);
1022
1023     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Connect DestructionSignal to observer:%p\n", observer);
1024     observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
1025   }
1026 }
1027
1028 void TextureManager::AsyncLoadComplete(const TextureManager::TextureId& textureId, std::vector<Devel::PixelBuffer>& pixelBuffers)
1029 {
1030   TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
1031   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( textureId:%d CacheIndex:%d )\n", textureId, cacheIndex.GetIndex());
1032   if(cacheIndex != INVALID_CACHE_INDEX)
1033   {
1034     TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
1035
1036     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "  textureId:%d Url:%s CacheIndex:%d LoadState: %s\n", textureInfo.textureId, textureInfo.url.GetUrl().c_str(), cacheIndex.GetIndex(), GET_LOAD_STATE_STRING(textureInfo.loadState));
1037     if(textureInfo.loadState != LoadState::CANCELLED && textureInfo.loadState != LoadState::MASK_CANCELLED)
1038     {
1039       // textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
1040       PostLoad(textureInfo, pixelBuffers);
1041     }
1042     else
1043     {
1044       Remove(textureInfo.textureId);
1045     }
1046   }
1047 }
1048
1049 void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vector<Devel::PixelBuffer>& pixelBuffers)
1050 {
1051   // Was the load successful?
1052   if(!pixelBuffers.empty())
1053   {
1054     if(pixelBuffers.size() == 1)
1055     {
1056       Devel::PixelBuffer pixelBuffer = pixelBuffers[0];
1057       if(pixelBuffer && (pixelBuffer.GetWidth() != 0) && (pixelBuffer.GetHeight() != 0))
1058       {
1059         // No atlas support for now
1060         textureInfo.useAtlas      = UseAtlas::NO_ATLAS;
1061         textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
1062
1063         if(textureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE)
1064         {
1065           // If there is a mask texture ID associated with this texture, then apply the mask
1066           // if it's already loaded. If it hasn't, and the mask is still loading,
1067           // wait for the mask to finish loading.
1068           // note, If the texture is already uploaded synchronously during loading,
1069           // we don't need to apply mask.
1070           if(textureInfo.loadState != LoadState::UPLOADED &&
1071              textureInfo.maskTextureId != INVALID_TEXTURE_ID)
1072           {
1073             if(textureInfo.loadState == LoadState::MASK_APPLYING)
1074             {
1075               textureInfo.loadState = LoadState::MASK_APPLIED;
1076               UploadTextures(pixelBuffers, textureInfo);
1077               NotifyObservers(textureInfo, true);
1078             }
1079             else
1080             {
1081               LoadState maskLoadState = mTextureCacheManager.GetTextureStateInternal(textureInfo.maskTextureId);
1082               textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
1083               if(maskLoadState == LoadState::LOADING)
1084               {
1085                 textureInfo.loadState = LoadState::WAITING_FOR_MASK;
1086               }
1087               else if(maskLoadState == LoadState::LOAD_FINISHED || maskLoadState == LoadState::UPLOADED)
1088               {
1089                 // Send New Task to Thread
1090                 TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
1091                 if(maskCacheIndex != INVALID_CACHE_INDEX)
1092                 {
1093                   TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
1094                   if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
1095                   {
1096                     // Send New Task to Thread
1097                     ApplyMask(textureInfo, textureInfo.maskTextureId);
1098                   }
1099                   else if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
1100                   {
1101                     // Upload image texture. textureInfo.loadState will be UPLOADED.
1102                     UploadTextures(pixelBuffers, textureInfo);
1103
1104                     // notify mask texture set.
1105                     NotifyObservers(textureInfo, true);
1106                   }
1107                 }
1108               }
1109               else // maskLoadState == LoadState::LOAD_FAILED
1110               {
1111                 // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
1112                 DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
1113                 UploadTextures(pixelBuffers, textureInfo);
1114                 NotifyObservers(textureInfo, true);
1115               }
1116             }
1117           }
1118           else
1119           {
1120             UploadTextures(pixelBuffers, textureInfo);
1121             NotifyObservers(textureInfo, true);
1122           }
1123         }
1124         else
1125         {
1126           textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
1127           textureInfo.loadState   = LoadState::LOAD_FINISHED;
1128
1129           if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
1130           {
1131             NotifyObservers(textureInfo, true);
1132           }
1133           else // for the StorageType::KEEP_PIXEL_BUFFER and StorageType::KEEP_TEXTURE
1134           {
1135             // Check if there was another texture waiting for this load to complete
1136             // (e.g. if this was an image mask, and its load is on a different thread)
1137             CheckForWaitingTexture(textureInfo);
1138           }
1139         }
1140       }
1141     }
1142     else
1143     {
1144       // YUV case
1145       // No atlas support for now
1146       textureInfo.useAtlas      = UseAtlas::NO_ATLAS;
1147       textureInfo.preMultiplied = false;
1148
1149       UploadTextures(pixelBuffers, textureInfo);
1150       NotifyObservers(textureInfo, true);
1151     }
1152   }
1153   else
1154   {
1155     textureInfo.loadState = LoadState::LOAD_FAILED;
1156     if(textureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER || textureInfo.storageType == StorageType::KEEP_TEXTURE)
1157     {
1158       // Check if there was another texture waiting for this load to complete
1159       // (e.g. if this was an image mask, and its load is on a different thread)
1160       CheckForWaitingTexture(textureInfo);
1161     }
1162     else
1163     {
1164       NotifyObservers(textureInfo, false);
1165     }
1166   }
1167 }
1168
1169 void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTextureInfo)
1170 {
1171   if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED &&
1172      maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
1173   {
1174     // Upload mask texture. textureInfo.loadState will be UPLOADED.
1175     std::vector<Devel::PixelBuffer> pixelBuffers;
1176     pixelBuffers.push_back(maskTextureInfo.pixelBuffer);
1177     UploadTextures(pixelBuffers, maskTextureInfo);
1178   }
1179
1180   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): maskTextureId=%d, maskTextureUrl=%s\n", maskTextureInfo.textureId, maskTextureInfo.url.GetUrl().c_str());
1181
1182   // Search the cache, checking if any texture has this texture id as a maskTextureId
1183   const std::size_t size = mTextureCacheManager.size();
1184
1185   // Keep notify observer required textureIds.
1186   // Note : NotifyObservers can change mTextureCacheManager cache struct. We should check id's validation before notify.
1187   std::vector<TextureId> notifyRequiredTextureIds;
1188
1189   // TODO : Refactorize here to not iterate whole cached image.
1190   for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
1191   {
1192     if(mTextureCacheManager[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
1193        mTextureCacheManager[cacheIndex].loadState == LoadState::WAITING_FOR_MASK)
1194     {
1195       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
1196
1197       if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED)
1198       {
1199         if(maskTextureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER)
1200         {
1201           // Send New Task to Thread
1202           ApplyMask(textureInfo, maskTextureInfo.textureId);
1203         }
1204       }
1205       else if(maskTextureInfo.loadState == LoadState::UPLOADED)
1206       {
1207         if(maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
1208         {
1209           if(textureInfo.url.GetProtocolType() == VisualUrl::TEXTURE)
1210           {
1211             // Get external textureSet from cacheManager.
1212             std::string location = textureInfo.url.GetLocation();
1213             if(!location.empty())
1214             {
1215               TextureId id                  = std::stoi(location);
1216               auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
1217               textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0));
1218               textureInfo.loadState = LoadState::UPLOADED;
1219             }
1220           }
1221           else
1222           {
1223             // Upload image texture. textureInfo.loadState will be UPLOADED.
1224             std::vector<Devel::PixelBuffer> pixelBuffers;
1225             pixelBuffers.push_back(textureInfo.pixelBuffer);
1226             UploadTextures(pixelBuffers, textureInfo);
1227           }
1228
1229           // Increase reference counts for notify required textureId.
1230           // Now we can assume that we don't remove & re-assign this textureId
1231           // during NotifyObserver signal emit.
1232           maskTextureInfo.referenceCount++;
1233           textureInfo.referenceCount++;
1234
1235           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): Ready to notify textureId=%d\n", textureInfo.textureId);
1236
1237           notifyRequiredTextureIds.push_back(textureInfo.textureId);
1238         }
1239       }
1240       else // maskTextureInfo.loadState == LoadState::LOAD_FAILED
1241       {
1242         // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
1243         DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
1244         std::vector<Devel::PixelBuffer> pixelBuffers;
1245         pixelBuffers.push_back(textureInfo.pixelBuffer);
1246         UploadTextures(pixelBuffers, textureInfo);
1247
1248         // Increase reference counts for notify required textureId.
1249         // Now we can assume that we don't remove & re-assign this textureId
1250         // during NotifyObserver signal emit.
1251         maskTextureInfo.referenceCount++;
1252         textureInfo.referenceCount++;
1253
1254         DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): Ready to notify textureId=%d\n", textureInfo.textureId);
1255
1256         notifyRequiredTextureIds.push_back(textureInfo.textureId);
1257       }
1258     }
1259   }
1260
1261   // Notify textures are masked
1262   for(const auto textureId : notifyRequiredTextureIds)
1263   {
1264     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
1265     if(textureCacheIndex != INVALID_CACHE_INDEX)
1266     {
1267       TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
1268       NotifyObservers(textureInfo, true);
1269     }
1270   }
1271
1272   // Decrease reference count
1273   for(const auto textureId : notifyRequiredTextureIds)
1274   {
1275     RequestRemove(textureId, nullptr);
1276   }
1277 }
1278
1279 void TextureManager::ApplyMask(TextureManager::TextureInfo& textureInfo, const TextureManager::TextureId& maskTextureId)
1280 {
1281   TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
1282   if(maskCacheIndex != INVALID_CACHE_INDEX)
1283   {
1284     Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
1285     Devel::PixelBuffer pixelBuffer     = textureInfo.pixelBuffer;
1286     textureInfo.pixelBuffer.Reset();
1287
1288     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ApplyMask(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
1289
1290     textureInfo.loadState  = LoadState::MASK_APPLYING;
1291     auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
1292     mAsyncLoader->ApplyMask(textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad);
1293   }
1294 }
1295
1296 void TextureManager::UploadTextures(std::vector<Devel::PixelBuffer>& pixelBuffers, TextureManager::TextureInfo& textureInfo)
1297 {
1298   if(!pixelBuffers.empty() && textureInfo.loadState != LoadState::UPLOADED && textureInfo.useAtlas != UseAtlas::USE_ATLAS)
1299   {
1300     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "  TextureManager::UploadTextures() New Texture for textureId:%d\n", textureInfo.textureId);
1301
1302     // Check if this pixelBuffer is premultiplied
1303     textureInfo.preMultiplied = pixelBuffers[0].IsAlphaPreMultiplied();
1304
1305     auto& renderingAddOn = RenderingAddOn::Get();
1306     if(renderingAddOn.IsValid())
1307     {
1308       renderingAddOn.CreateGeometry(textureInfo.textureId, pixelBuffers[0]);
1309     }
1310
1311     // Remove previous textures and insert new textures
1312     textureInfo.textures.clear();
1313
1314     for(auto&& pixelBuffer : pixelBuffers)
1315     {
1316       Texture   texture   = Texture::New(Dali::TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight());
1317       PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
1318       texture.Upload(pixelData);
1319       textureInfo.textures.push_back(texture);
1320     }
1321   }
1322
1323   // Update the load state.
1324   // Note: This is regardless of success as we care about whether a
1325   // load attempt is in progress or not.  If unsuccessful, a broken
1326   // image is still loaded.
1327   textureInfo.loadState = LoadState::UPLOADED;
1328 }
1329
1330 void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, const bool& success)
1331 {
1332   TextureId textureId = textureInfo.textureId;
1333
1334   // If there is an observer: Notify the load is complete, whether successful or not,
1335   // and erase it from the list
1336   TextureInfo* info = &textureInfo;
1337
1338   if(info->animatedImageLoading)
1339   {
1340     // If loading failed, we don't need to get frameCount and frameInterval.
1341     if(success)
1342     {
1343       info->frameCount    = info->animatedImageLoading.GetImageCount();
1344       info->frameInterval = info->animatedImageLoading.GetFrameInterval(info->frameIndex);
1345     }
1346     info->animatedImageLoading.Reset();
1347   }
1348
1349   mLoadingQueueTextureId = textureId;
1350
1351   // Reverse observer list that we can pop_back the observer.
1352   std::reverse(info->observerList.Begin(), info->observerList.End());
1353
1354   while(info->observerList.Count())
1355   {
1356     TextureUploadObserver* observer = *(info->observerList.End() - 1u);
1357
1358     // During LoadComplete() a Control ResourceReady() signal is emitted.
1359     // During that signal the app may add remove /add Textures (e.g. via
1360     // ImageViews).
1361     // It is possible for observers to be removed from the observer list,
1362     // and it is also possible for the mTextureInfoContainer to be modified,
1363     // invalidating the reference to the textureInfo struct.
1364     // Texture load requests for the same URL are deferred until the end of this
1365     // method.
1366     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::NotifyObservers() observer:%p textureId:%d url:%s loadState:%s\n", observer, textureId, info->url.GetUrl().c_str(), GET_LOAD_STATE_STRING(info->loadState));
1367     // It is possible for the observer to be deleted.
1368     // Disconnect and remove the observer first.
1369     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
1370     observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1371
1372     info->observerList.Erase(info->observerList.End() - 1u);
1373
1374     EmitLoadComplete(observer, *info, success);
1375
1376     // Get the textureInfo from the container again as it may have been invalidated.
1377     TextureCacheIndex textureInfoIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
1378     if(textureInfoIndex == INVALID_CACHE_INDEX)
1379     {
1380       break; // texture has been removed - can stop.
1381     }
1382     info = &mTextureCacheManager[textureInfoIndex];
1383   }
1384
1385   mLoadingQueueTextureId = INVALID_TEXTURE_ID;
1386   ProcessLoadQueue();
1387
1388   if(info->storageType == StorageType::RETURN_PIXEL_BUFFER && info->observerList.Count() == 0)
1389   {
1390     RequestRemove(info->textureId, nullptr);
1391   }
1392 }
1393
1394 void TextureManager::ObserverDestroyed(TextureUploadObserver* observer)
1395 {
1396   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "TextureManager::ObserverDestroyed() observer:%p\n", observer);
1397
1398   const std::size_t size = mTextureCacheManager.size();
1399   for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
1400   {
1401     TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
1402     for(TextureInfo::ObserverListType::Iterator j = textureInfo.observerList.Begin();
1403         j != textureInfo.observerList.End();)
1404     {
1405       if(*j == observer)
1406       {
1407         j = textureInfo.observerList.Erase(j);
1408       }
1409       else
1410       {
1411         ++j;
1412       }
1413     }
1414   }
1415
1416   // Remove element from the LoadQueue
1417   for(auto&& element : mLoadQueue)
1418   {
1419     if(element.mObserver == observer)
1420     {
1421       DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Remove observer from observer queue (textureId:%d, observer:%p)\n", element.mTextureId, element.mObserver);
1422       element.mTextureId = INVALID_TEXTURE_ID;
1423       element.mObserver  = nullptr;
1424     }
1425   }
1426 }
1427
1428 Dali::Geometry TextureManager::GetRenderGeometry(const TextureManager::TextureId& textureId, std::uint32_t& frontElements, std::uint32_t& backElements)
1429 {
1430   return RenderingAddOn::Get().IsValid() ? RenderingAddOn::Get().GetGeometry(textureId, frontElements, backElements) : Geometry();
1431 }
1432
1433 void TextureManager::EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success)
1434 {
1435   if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
1436   {
1437     observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, textureInfo.pixelBuffer, textureInfo.url.GetUrl(), textureInfo.preMultiplied));
1438   }
1439   else
1440   {
1441     TextureSet textureSet = GetTextureSet(textureInfo);
1442     if(textureInfo.isAnimatedImageFormat)
1443     {
1444       observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::ANIMATED_IMAGE_TEXTURE, textureInfo.textureId, textureSet, textureInfo.frameCount, textureInfo.frameInterval));
1445     }
1446     else
1447     {
1448       observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
1449     }
1450   }
1451 }
1452
1453 TextureSet TextureManager::GetTextureSet(const TextureManager::TextureId& textureId)
1454 {
1455   TextureSet                textureSet;
1456   TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
1457   if(loadState == TextureManager::LoadState::UPLOADED)
1458   {
1459     // LoadComplete has already been called - keep the same texture set
1460     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
1461     if(textureCacheIndex != INVALID_CACHE_INDEX)
1462     {
1463       TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
1464       textureSet = GetTextureSet(textureInfo);
1465     }
1466   }
1467   else
1468   {
1469     DALI_LOG_ERROR("GetTextureSet is failed. texture is not uploaded \n");
1470   }
1471   return textureSet;
1472 }
1473
1474 TextureSet TextureManager::GetTextureSet(const TextureManager::TextureInfo& textureInfo)
1475 {
1476   TextureSet textureSet;
1477
1478   // LoadComplete has already been called - keep the same texture set
1479   textureSet = TextureSet::New();
1480   if(!textureInfo.textures.empty())
1481   {
1482     if(textureInfo.textures.size() > 1) // For YUV case
1483     {
1484       uint32_t index = 0u;
1485       for(auto&& texture : textureInfo.textures)
1486       {
1487         textureSet.SetTexture(index++, texture);
1488       }
1489     }
1490     else
1491     {
1492       textureSet.SetTexture(TEXTURE_INDEX, textureInfo.textures[0]);
1493       TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
1494       if(maskCacheIndex != INVALID_CACHE_INDEX)
1495       {
1496         TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
1497         if(maskTextureInfo.storageType == StorageType::UPLOAD_TO_TEXTURE || maskTextureInfo.storageType == StorageType::KEEP_TEXTURE)
1498         {
1499           if(!maskTextureInfo.textures.empty())
1500           {
1501             textureSet.SetTexture(MASK_TEXTURE_INDEX, maskTextureInfo.textures[0]);
1502           }
1503         }
1504       }
1505     }
1506   }
1507   return textureSet;
1508 }
1509
1510 void TextureManager::RemoveTextureObserver(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
1511 {
1512   // Remove its observer
1513   if(observer)
1514   {
1515     const auto iterEnd = textureInfo.observerList.End();
1516     const auto iter    = std::find(textureInfo.observerList.Begin(), iterEnd, observer);
1517     if(iter != iterEnd)
1518     {
1519       // Disconnect and remove the observer.
1520       DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
1521       observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1522       textureInfo.observerList.Erase(iter);
1523     }
1524     else
1525     {
1526       // Given textureId might exist at load queue.
1527       // Remove observer from the LoadQueue
1528       for(auto&& element : mLoadQueue)
1529       {
1530         if(element.mTextureId == textureInfo.textureId && element.mObserver == observer)
1531         {
1532           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Remove observer from observer queue (textureId:%d, observer:%p)\n", element.mTextureId, element.mObserver);
1533           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
1534           observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1535           element.mObserver = nullptr;
1536           break;
1537         }
1538       }
1539     }
1540   }
1541 }
1542
1543 } // namespace Internal
1544
1545 } // namespace Toolkit
1546
1547 } // namespace Dali