[dali_2.3.19] Merge branch '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/integration-api/trace.h>
27 #include <dali/public-api/rendering/geometry.h>
28
29 // INTERNAL HEADERS
30 #include <dali-toolkit/internal/texture-manager/texture-async-loading-helper.h>
31 #include <dali-toolkit/internal/texture-manager/texture-cache-manager.h>
32 #include <dali-toolkit/internal/visuals/image-atlas-manager.h>
33 #include <dali-toolkit/internal/visuals/rendering-addon.h>
34
35 namespace
36 {
37 constexpr auto INITIAL_HASH_NUMBER = size_t{0u};
38
39 constexpr auto TEXTURE_INDEX      = 0u; ///< The Index for texture
40 constexpr auto MASK_TEXTURE_INDEX = 1u; ///< The Index for mask texture
41
42 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_IMAGE_PERFORMANCE_MARKER, false);
43 } // namespace
44
45 namespace Dali
46 {
47 namespace Toolkit
48 {
49 namespace Internal
50 {
51 #ifdef DEBUG_ENABLED
52 // Define logfilter Internal namespace level so other files (e.g. texture-cache-manager.cpp) can also use this filter.
53 Debug::Filter* gTextureManagerLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TEXTURE_MANAGER");
54
55 // clang-format off
56 #define GET_LOAD_STATE_STRING(loadState) \
57   loadState == TextureManagerType::LoadState::NOT_STARTED      ? "NOT_STARTED"      : \
58   loadState == TextureManagerType::LoadState::LOADING          ? "LOADING"          : \
59   loadState == TextureManagerType::LoadState::LOAD_FINISHED    ? "LOAD_FINISHED"    : \
60   loadState == TextureManagerType::LoadState::WAITING_FOR_MASK ? "WAITING_FOR_MASK" : \
61   loadState == TextureManagerType::LoadState::MASK_APPLYING    ? "MASK_APPLYING"    : \
62   loadState == TextureManagerType::LoadState::MASK_APPLIED     ? "MASK_APPLIED"     : \
63   loadState == TextureManagerType::LoadState::UPLOADED         ? "UPLOADED"         : \
64   loadState == TextureManagerType::LoadState::CANCELLED        ? "CANCELLED"        : \
65   loadState == TextureManagerType::LoadState::MASK_CANCELLED   ? "MASK_CANCELLED"   : \
66   loadState == TextureManagerType::LoadState::LOAD_FAILED      ? "LOAD_FAILED"      : \
67                                                                  "Unknown"
68 // clang-format on
69 #endif
70
71 namespace
72 {
73 const Vector4 FULL_ATLAS_RECT(0.0f, 0.0f, 1.0f, 1.0f); ///< UV Rectangle that covers the full Texture
74
75 void PreMultiply(Devel::PixelBuffer pixelBuffer, TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
76 {
77   if(Pixel::HasAlpha(pixelBuffer.GetPixelFormat()))
78   {
79     if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
80     {
81       pixelBuffer.MultiplyColorByAlpha();
82     }
83   }
84   else
85   {
86     preMultiplyOnLoad = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
87   }
88 }
89
90 } // Anonymous namespace
91
92 TextureManager::MaskingData::MaskingData()
93 : mAlphaMaskUrl(),
94   mAlphaMaskId(INVALID_TEXTURE_ID),
95   mContentScaleFactor(1.0f),
96   mCropToMask(true),
97   mPreappliedMasking(true),
98   mMaskImageLoadingFailed(false)
99 {
100 }
101
102 TextureManager::TextureManager(bool loadYuvPlanes)
103 : mTextureCacheManager(),
104   mAsyncLoader(std::unique_ptr<TextureAsyncLoadingHelper>(new TextureAsyncLoadingHelper(*this))),
105   mLifecycleObservers(),
106   mLoadQueue(),
107   mLoadingQueueTextureId(INVALID_TEXTURE_ID),
108   mRemoveQueue(),
109   mLoadYuvPlanes(loadYuvPlanes),
110   mRemoveProcessorRegistered(false)
111 {
112   // Initialize the AddOn
113   RenderingAddOn::Get();
114 }
115
116 TextureManager::~TextureManager()
117 {
118   if(mRemoveProcessorRegistered && Adaptor::IsAvailable())
119   {
120     Adaptor::Get().UnregisterProcessor(*this, true);
121     mRemoveProcessorRegistered = false;
122   }
123
124   for(auto iter = mLifecycleObservers.Begin(), endIter = mLifecycleObservers.End(); iter != endIter; ++iter)
125   {
126     (*iter)->TextureManagerDestroyed();
127   }
128 }
129
130 TextureSet TextureManager::LoadAnimatedImageTexture(
131   const VisualUrl&                url,
132   Dali::AnimatedImageLoading      animatedImageLoading,
133   const uint32_t                  frameIndex,
134   TextureManager::TextureId&      textureId,
135   MaskingDataPointer&             maskInfo,
136   const Dali::ImageDimensions&    desiredSize,
137   const Dali::FittingMode::Type   fittingMode,
138   const Dali::SamplingMode::Type  samplingMode,
139   const bool                      synchronousLoading,
140   TextureUploadObserver*          textureObserver,
141   TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
142 {
143   TextureSet textureSet;
144
145   if(synchronousLoading)
146   {
147     Devel::PixelBuffer pixelBuffer;
148     if(animatedImageLoading)
149     {
150       pixelBuffer = animatedImageLoading.LoadFrame(frameIndex, desiredSize, fittingMode, samplingMode);
151     }
152     if(!pixelBuffer)
153     {
154       DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous loading is failed\n");
155     }
156     else
157     {
158       Texture maskTexture;
159       if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
160       {
161         Devel::PixelBuffer maskPixelBuffer = LoadImageFromFile(maskInfo->mAlphaMaskUrl.GetUrl(), desiredSize, fittingMode, samplingMode, true);
162         if(maskPixelBuffer)
163         {
164           if(!maskInfo->mPreappliedMasking)
165           {
166             PixelData maskPixelData = Devel::PixelBuffer::Convert(maskPixelBuffer); // takes ownership of buffer
167             maskTexture             = Texture::New(Dali::TextureType::TEXTURE_2D, maskPixelData.GetPixelFormat(), maskPixelData.GetWidth(), maskPixelData.GetHeight());
168             maskTexture.Upload(maskPixelData);
169           }
170           else
171           {
172             pixelBuffer.ApplyMask(maskPixelBuffer, maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
173           }
174         }
175         else
176         {
177           DALI_LOG_ERROR("TextureManager::LoadAnimatedImageTexture: Synchronous mask image loading is failed\n");
178         }
179       }
180
181       if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
182       {
183         PreMultiply(pixelBuffer, preMultiplyOnLoad);
184       }
185
186       PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); // takes ownership of buffer
187       if(!textureSet)
188       {
189         Texture texture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
190         texture.Upload(pixelData);
191         textureSet = TextureSet::New();
192         textureSet.SetTexture(TEXTURE_INDEX, texture);
193         if(maskTexture)
194         {
195           textureSet.SetTexture(MASK_TEXTURE_INDEX, maskTexture);
196         }
197       }
198     }
199   }
200   else
201   {
202     TextureId alphaMaskId        = INVALID_TEXTURE_ID;
203     float     contentScaleFactor = 1.0f;
204     bool      cropToMask         = false;
205     if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
206     {
207       maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? TextureManager::StorageType::KEEP_PIXEL_BUFFER : TextureManager::StorageType::KEEP_TEXTURE);
208       alphaMaskId            = maskInfo->mAlphaMaskId;
209       if(maskInfo->mPreappliedMasking)
210       {
211         contentScaleFactor = maskInfo->mContentScaleFactor;
212         cropToMask         = maskInfo->mCropToMask;
213       }
214     }
215
216     textureId = RequestLoadInternal(url, alphaMaskId, textureId, contentScaleFactor, desiredSize, fittingMode, samplingMode, cropToMask, TextureManager::StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoad, animatedImageLoading, frameIndex, false);
217
218     TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
219     if(loadState == TextureManager::LoadState::UPLOADED)
220     {
221       // LoadComplete has already been called - keep the same texture set
222       textureSet = GetTextureSet(textureId);
223     }
224   }
225
226   return textureSet;
227 }
228
229 Devel::PixelBuffer TextureManager::LoadPixelBuffer(
230   const VisualUrl&                url,
231   const Dali::ImageDimensions&    desiredSize,
232   const Dali::FittingMode::Type   fittingMode,
233   const Dali::SamplingMode::Type  samplingMode,
234   const bool                      synchronousLoading,
235   TextureUploadObserver*          textureObserver,
236   const bool                      orientationCorrection,
237   TextureManager::MultiplyOnLoad& preMultiplyOnLoad)
238 {
239   Devel::PixelBuffer pixelBuffer;
240   if(synchronousLoading)
241   {
242     if(url.IsValid())
243     {
244       if(url.IsBufferResource())
245       {
246         const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
247         if(encodedImageBuffer)
248         {
249           pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
250         }
251       }
252       else
253       {
254         pixelBuffer = LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
255       }
256       if(pixelBuffer && preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
257       {
258         PreMultiply(pixelBuffer, preMultiplyOnLoad);
259       }
260     }
261   }
262   else
263   {
264     RequestLoadInternal(url, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, false, TextureManager::StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
265   }
266
267   return pixelBuffer;
268 }
269
270 TextureSet TextureManager::LoadTexture(
271   const VisualUrl&                   url,
272   const Dali::ImageDimensions&       desiredSize,
273   const Dali::FittingMode::Type      fittingMode,
274   const Dali::SamplingMode::Type     samplingMode,
275   MaskingDataPointer&                maskInfo,
276   const bool                         synchronousLoading,
277   TextureManager::TextureId&         textureId,
278   Vector4&                           textureRect,
279   Dali::ImageDimensions&             textureRectSize,
280   bool&                              atlasingStatus,
281   bool&                              loadingStatus,
282   TextureUploadObserver*             textureObserver,
283   AtlasUploadObserver*               atlasObserver,
284   ImageAtlasManagerPtr               imageAtlasManager,
285   const bool                         orientationCorrection,
286   const TextureManager::ReloadPolicy reloadPolicy,
287   TextureManager::MultiplyOnLoad&    preMultiplyOnLoad)
288 {
289   TextureSet textureSet;
290
291   loadingStatus = false;
292   textureRect   = FULL_ATLAS_RECT;
293
294   if(VisualUrl::TEXTURE == url.GetProtocolType())
295   {
296     std::string location = url.GetLocation();
297     if(location.size() > 0u)
298     {
299       TextureId id                  = std::stoi(location);
300       auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
301       if(externalTextureInfo.textureSet)
302       {
303         if(preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD)
304         {
305           // Change preMultiplyOnLoad value so make caller determine to preMultiplyAlpha or not.
306           // TODO : Should we seperate input and output value?
307           preMultiplyOnLoad = externalTextureInfo.preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
308         }
309
310         TextureId alphaMaskId = INVALID_TEXTURE_ID;
311         if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
312         {
313           maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, TextureManager::StorageType::KEEP_TEXTURE, synchronousLoading);
314           alphaMaskId            = maskInfo->mAlphaMaskId;
315
316           // Create new textureId. this textureId is not same as location
317           textureId = RequestLoad(url, alphaMaskId, textureId, 1.0f, desiredSize, fittingMode, samplingMode, false, textureObserver, orientationCorrection, reloadPolicy, preMultiplyOnLoad, synchronousLoading);
318
319           TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
320           if(loadState == TextureManager::LoadState::UPLOADED)
321           {
322             textureSet = GetTextureSet(textureId);
323           }
324         }
325         else
326         {
327           // TextureId is same as location
328           textureId = id;
329
330           textureSet = TextureSet::New();
331           textureSet.SetTexture(TEXTURE_INDEX, externalTextureInfo.textureSet.GetTexture(TEXTURE_INDEX));
332         }
333       }
334     }
335   }
336   else
337   {
338     // For Atlas
339     if(synchronousLoading && atlasingStatus)
340     {
341       const bool synchronousAtlasAvaliable = (desiredSize != ImageDimensions() || url.IsLocalResource()) ? imageAtlasManager->CheckAtlasAvailable(url, desiredSize)
342                                                                                                          : false;
343       if(synchronousAtlasAvaliable)
344       {
345         std::vector<Devel::PixelBuffer> pixelBuffers;
346         LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, false, pixelBuffers);
347
348         if(!pixelBuffers.empty() && maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
349         {
350           std::vector<Devel::PixelBuffer> maskPixelBuffers;
351           LoadImageSynchronously(maskInfo->mAlphaMaskUrl, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, true, false, maskPixelBuffers);
352           if(!maskPixelBuffers.empty())
353           {
354             pixelBuffers[0].ApplyMask(maskPixelBuffers[0], maskInfo->mContentScaleFactor, maskInfo->mCropToMask);
355           }
356         }
357
358         PixelData data;
359         if(!pixelBuffers.empty())
360         {
361           PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
362           data = Devel::PixelBuffer::Convert(pixelBuffers[0]); // takes ownership of buffer
363
364           if(data)
365           {
366             textureSet = imageAtlasManager->Add(textureRect, data);
367             if(textureSet)
368             {
369               textureRectSize.SetWidth(data.GetWidth());
370               textureRectSize.SetHeight(data.GetHeight());
371             }
372           }
373           else
374           {
375             DALI_LOG_ERROR("TextureManager::LoadTexture: Synchronous Texture loading with atlasing is failed.\n");
376           }
377         }
378         if(!textureSet)
379         {
380           atlasingStatus = false;
381         }
382       }
383     }
384
385     if(!textureSet)
386     {
387       loadingStatus = true;
388       // Atlas manager can chage desired size when it is set by 0,0.
389       // We should store into textureRectSize only if atlasing successed.
390       // So copy inputed desiredSize, and replace value into textureRectSize only if atlasing success.
391       Dali::ImageDimensions atlasDesiredSize = desiredSize;
392       if(atlasingStatus)
393       {
394         if(url.IsBufferResource())
395         {
396           const EncodedImageBuffer& encodedImageBuffer = GetEncodedImageBuffer(url.GetUrl());
397           if(encodedImageBuffer)
398           {
399             textureSet = imageAtlasManager->Add(textureRect, encodedImageBuffer, desiredSize, fittingMode, true, atlasObserver);
400           }
401         }
402         else
403         {
404           textureSet = imageAtlasManager->Add(textureRect, url, atlasDesiredSize, fittingMode, true, atlasObserver);
405         }
406       }
407       if(!textureSet) // big image, no atlasing or atlasing failed
408       {
409         atlasingStatus = false;
410
411         TextureId alphaMaskId        = INVALID_TEXTURE_ID;
412         float     contentScaleFactor = 1.0f;
413         bool      cropToMask         = false;
414         if(maskInfo && maskInfo->mAlphaMaskUrl.IsValid())
415         {
416           maskInfo->mAlphaMaskId = RequestMaskLoad(maskInfo->mAlphaMaskUrl, maskInfo->mPreappliedMasking ? TextureManager::StorageType::KEEP_PIXEL_BUFFER : TextureManager::StorageType::KEEP_TEXTURE, synchronousLoading);
417           alphaMaskId            = maskInfo->mAlphaMaskId;
418           if(maskInfo && maskInfo->mPreappliedMasking)
419           {
420             contentScaleFactor = maskInfo->mContentScaleFactor;
421             cropToMask         = maskInfo->mCropToMask;
422           }
423         }
424
425         textureId = RequestLoad(
426           url,
427           alphaMaskId,
428           textureId,
429           contentScaleFactor,
430           desiredSize,
431           fittingMode,
432           samplingMode,
433           cropToMask,
434           textureObserver,
435           orientationCorrection,
436           reloadPolicy,
437           preMultiplyOnLoad,
438           synchronousLoading);
439
440         TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
441         if(loadState == TextureManager::LoadState::UPLOADED)
442         {
443           // LoadComplete has already been called - keep the same texture set
444           textureSet = GetTextureSet(textureId);
445         }
446
447         // If we are loading the texture, or waiting for the ready signal handler to complete, inform
448         // caller that they need to wait.
449         loadingStatus = (loadState == TextureManager::LoadState::LOADING ||
450                          loadState == TextureManager::LoadState::WAITING_FOR_MASK ||
451                          loadState == TextureManager::LoadState::MASK_APPLYING ||
452                          loadState == TextureManager::LoadState::MASK_APPLIED ||
453                          loadState == TextureManager::LoadState::NOT_STARTED ||
454                          mLoadingQueueTextureId != INVALID_TEXTURE_ID);
455       }
456       else
457       {
458         textureRectSize = atlasDesiredSize;
459       }
460     }
461   }
462
463   if(synchronousLoading)
464   {
465     loadingStatus = false;
466   }
467
468   return textureSet;
469 }
470
471 TextureManager::TextureId TextureManager::RequestLoad(
472   const VisualUrl&                   url,
473   const ImageDimensions&             desiredSize,
474   const Dali::FittingMode::Type      fittingMode,
475   const Dali::SamplingMode::Type     samplingMode,
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, false, TextureManager::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 bool                         cropToMask,
494   TextureUploadObserver*             observer,
495   const bool                         orientationCorrection,
496   const TextureManager::ReloadPolicy reloadPolicy,
497   TextureManager::MultiplyOnLoad&    preMultiplyOnLoad,
498   const bool                         synchronousLoading)
499 {
500   return RequestLoadInternal(url, maskTextureId, previousTextureId, contentScale, desiredSize, fittingMode, samplingMode, cropToMask, TextureManager::StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
501 }
502
503 TextureManager::TextureId TextureManager::RequestMaskLoad(
504   const VisualUrl&                  maskUrl,
505   const TextureManager::StorageType storageType,
506   const bool                        synchronousLoading)
507 {
508   // Use the normal load procedure to get the alpha mask.
509   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
510   return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::NO_FILTER, false, storageType, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
511 }
512
513 TextureManager::TextureId TextureManager::RequestLoadInternal(
514   const VisualUrl&                   url,
515   const TextureManager::TextureId    maskTextureId,
516   const TextureManager::TextureId    previousTextureId,
517   const float                        contentScale,
518   const Dali::ImageDimensions&       desiredSize,
519   const Dali::FittingMode::Type      fittingMode,
520   const Dali::SamplingMode::Type     samplingMode,
521   const bool                         cropToMask,
522   const TextureManager::StorageType  storageType,
523   TextureUploadObserver*             observer,
524   const bool                         orientationCorrection,
525   const TextureManager::ReloadPolicy reloadPolicy,
526   TextureManager::MultiplyOnLoad&    preMultiplyOnLoad,
527   Dali::AnimatedImageLoading         animatedImageLoading,
528   const uint32_t                     frameIndex,
529   const bool                         synchronousLoading)
530 {
531   TextureHash       textureHash   = INITIAL_HASH_NUMBER;
532   TextureCacheIndex cacheIndex    = INVALID_CACHE_INDEX;
533   bool              loadYuvPlanes = (mLoadYuvPlanes && maskTextureId == INVALID_TEXTURE_ID && storageType == TextureManager::StorageType::UPLOAD_TO_TEXTURE);
534
535   if(storageType != TextureManager::StorageType::RETURN_PIXEL_BUFFER)
536   {
537     textureHash = mTextureCacheManager.GenerateHash(url, desiredSize, fittingMode, samplingMode, maskTextureId, cropToMask, frameIndex);
538
539     // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
540     cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url, desiredSize, fittingMode, samplingMode, storageType, maskTextureId, cropToMask, preMultiplyOnLoad, (animatedImageLoading) ? true : false, frameIndex);
541   }
542
543   TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
544   // Check if the requested Texture exists in the cache.
545   if(cacheIndex != INVALID_CACHE_INDEX)
546   {
547     if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
548     {
549       // Mark this texture being used by another client resource, or Reload forced without request load before.
550       // Forced reload which have current texture before, would replace the current texture.
551       // without the need for incrementing the reference count.
552       ++(mTextureCacheManager[cacheIndex].referenceCount);
553     }
554     textureId = mTextureCacheManager[cacheIndex].textureId;
555
556     // Update preMultiplyOnLoad value. It should be changed according to preMultiplied value of the cached info.
557     preMultiplyOnLoad = mTextureCacheManager[cacheIndex].preMultiplied ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
558     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));
559   }
560
561   if(textureId == INVALID_TEXTURE_ID) // There was no caching, or caching not required
562   {
563     textureId = mTextureCacheManager.GenerateTextureId();
564
565     bool preMultiply = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
566
567     // Cache new texutre, and get cacheIndex.
568     cacheIndex = mTextureCacheManager.AppendCache(TextureInfo(textureId, maskTextureId, url, desiredSize, contentScale, fittingMode, samplingMode, false, cropToMask, textureHash, orientationCorrection, preMultiply, animatedImageLoading, frameIndex, loadYuvPlanes));
569     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);
570   }
571
572   // The below code path is common whether we are using the cache or not.
573   // The textureInfoIndex now refers to either a pre-existing cached TextureInfo,
574   // or a new TextureInfo just created.
575   TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
576   textureInfo.maskTextureId         = maskTextureId;
577   textureInfo.storageType           = storageType;
578   textureInfo.orientationCorrection = orientationCorrection;
579
580   // the case using external texture has already been loaded texture, so change its status to WAITING_FOR_MASK.
581   if(url.GetProtocolType() == VisualUrl::TEXTURE)
582   {
583     if(textureInfo.loadState != TextureManager::LoadState::UPLOADED)
584     {
585       textureInfo.preMultiplied = (preMultiplyOnLoad == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
586       textureInfo.loadState     = TextureManager::LoadState::WAITING_FOR_MASK;
587     }
588   }
589
590   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureInfo loadState:%s\n", GET_LOAD_STATE_STRING(textureInfo.loadState));
591
592   // Force reloading of texture by setting loadState unless already loading or cancelled.
593   if(TextureManager::ReloadPolicy::FORCED == reloadPolicy &&
594      TextureManager::LoadState::LOADING != textureInfo.loadState &&
595      TextureManager::LoadState::WAITING_FOR_MASK != textureInfo.loadState &&
596      TextureManager::LoadState::MASK_APPLYING != textureInfo.loadState &&
597      TextureManager::LoadState::MASK_APPLIED != textureInfo.loadState &&
598      TextureManager::LoadState::CANCELLED != textureInfo.loadState &&
599      TextureManager::LoadState::MASK_CANCELLED != textureInfo.loadState)
600   {
601     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);
602     textureInfo.loadState = TextureManager::LoadState::NOT_STARTED;
603   }
604
605   if(!synchronousLoading)
606   {
607     // Check if we should add the observer.
608     // Only do this if we have not loaded yet and it will not have loaded by the end of this method.
609     switch(textureInfo.loadState)
610     {
611       case TextureManager::LoadState::LOAD_FAILED: // Failed notifies observer which then stops observing.
612       case TextureManager::LoadState::NOT_STARTED:
613       {
614         LoadOrQueueTexture(textureInfo, observer); // If called inside NotifyObservers, queues until afterwards
615         break;
616       }
617       case TextureManager::LoadState::LOADING:
618       case TextureManager::LoadState::WAITING_FOR_MASK:
619       case TextureManager::LoadState::MASK_APPLYING:
620       case TextureManager::LoadState::MASK_APPLIED:
621       {
622         // Do not observe even we reload forced when texture is already loading state.
623         if(TextureManager::ReloadPolicy::CACHED == reloadPolicy || TextureManager::INVALID_TEXTURE_ID == previousTextureId)
624         {
625           ObserveTexture(textureInfo, observer);
626         }
627         break;
628       }
629       case TextureManager::LoadState::UPLOADED:
630       {
631         if(observer)
632         {
633           LoadOrQueueTexture(textureInfo, observer);
634         }
635         break;
636       }
637       case TextureManager::LoadState::CANCELLED:
638       {
639         // A cancelled texture hasn't finished loading yet. Treat as a loading texture
640         // (it's ref count has already been incremented, above)
641         textureInfo.loadState = TextureManager::LoadState::LOADING;
642         ObserveTexture(textureInfo, observer);
643         break;
644       }
645       case TextureManager::LoadState::MASK_CANCELLED:
646       {
647         // A cancelled texture hasn't finished mask applying yet. Treat as a mask applying texture
648         // (it's ref count has already been incremented, above)
649         textureInfo.loadState = TextureManager::LoadState::MASK_APPLYING;
650         ObserveTexture(textureInfo, observer);
651         break;
652       }
653       case TextureManager::LoadState::LOAD_FINISHED:
654       {
655         // Loading has already completed.
656         if(observer && textureInfo.storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER)
657         {
658           LoadOrQueueTexture(textureInfo, observer);
659         }
660         break;
661       }
662     }
663   }
664   else
665   {
666     // If the image is already finished to load, use cached texture.
667     // We don't need to consider Observer because this is synchronous loading.
668     if(!(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
669          textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED))
670     {
671       if(url.GetProtocolType() == VisualUrl::TEXTURE)
672       {
673         // Get external textureSet from cacheManager.
674         std::string location = textureInfo.url.GetLocation();
675         if(!location.empty())
676         {
677           TextureId id                  = std::stoi(location);
678           auto      externalTextureInfo = mTextureCacheManager.GetExternalTextureInfo(id);
679           textureInfo.textures.push_back(externalTextureInfo.textureSet.GetTexture(0));
680           textureInfo.loadState = TextureManager::LoadState::UPLOADED;
681         }
682       }
683       else
684       {
685         std::vector<Devel::PixelBuffer> pixelBuffers;
686         LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection, loadYuvPlanes, pixelBuffers);
687
688         if(pixelBuffers.empty())
689         {
690           // If pixelBuffer loading is failed in synchronously, call RequestRemove() method.
691           RequestRemove(textureId, nullptr);
692           return INVALID_TEXTURE_ID;
693         }
694
695         if(storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER) // For the mask image loading.
696         {
697           textureInfo.pixelBuffer = pixelBuffers[0]; // Store the pixel data
698           textureInfo.loadState   = TextureManager::LoadState::LOAD_FINISHED;
699         }
700         else // For the image loading.
701         {
702           Texture maskTexture;
703           if(maskTextureId != INVALID_TEXTURE_ID)
704           {
705             TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
706             if(maskCacheIndex != INVALID_CACHE_INDEX)
707             {
708               if(mTextureCacheManager[maskCacheIndex].storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER)
709               {
710                 Devel::PixelBuffer maskPixelBuffer = mTextureCacheManager[maskCacheIndex].pixelBuffer;
711                 if(maskPixelBuffer)
712                 {
713                   pixelBuffers[0].ApplyMask(maskPixelBuffer, contentScale, cropToMask);
714                 }
715                 else
716                 {
717                   DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
718                 }
719               }
720             }
721             else
722             {
723               DALI_LOG_ERROR("Mask image is not stored in cache.\n");
724             }
725           }
726           PreMultiply(pixelBuffers[0], preMultiplyOnLoad);
727
728           // Upload texture
729           UploadTextures(pixelBuffers, textureInfo);
730         }
731       }
732     }
733   }
734
735   return textureId;
736 }
737
738 void TextureManager::RequestRemove(const TextureManager::TextureId textureId, TextureUploadObserver* observer)
739 {
740   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::RequestRemove( textureId=%d observer=%p )\n", textureId, observer);
741
742   // Queue to remove.
743   if(textureId != INVALID_TEXTURE_ID)
744   {
745     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
746     if(textureCacheIndex != INVALID_CACHE_INDEX)
747     {
748       if(observer)
749       {
750         // Remove observer from cached texture info
751         TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
752         RemoveTextureObserver(textureInfo, observer);
753       }
754
755       mRemoveQueue.PushBack(textureId);
756
757       if(!mRemoveProcessorRegistered && Adaptor::IsAvailable())
758       {
759         mRemoveProcessorRegistered = true;
760         Adaptor::Get().RegisterProcessor(*this, true);
761       }
762     }
763   }
764 }
765
766 void TextureManager::Remove(const TextureManager::TextureId textureId)
767 {
768   if(textureId != INVALID_TEXTURE_ID)
769   {
770     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
771     if(textureCacheIndex != INVALID_CACHE_INDEX)
772     {
773       TextureManager::TextureId maskTextureId = INVALID_TEXTURE_ID;
774       TextureInfo&              textureInfo(mTextureCacheManager[textureCacheIndex]);
775       // We only need to consider maskTextureId when texture's loadState is not cancelled. Because it is already deleted.
776       if(textureInfo.loadState != TextureManager::LoadState::CANCELLED && textureInfo.loadState != TextureManager::LoadState::MASK_CANCELLED)
777       {
778         if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
779         {
780           maskTextureId = textureInfo.maskTextureId;
781         }
782       }
783
784       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));
785
786       // Remove textureId in CacheManager. Now, textureInfo is invalidate.
787       mTextureCacheManager.RemoveCache(textureInfo);
788
789       // Remove maskTextureId in CacheManager
790       if(maskTextureId != INVALID_TEXTURE_ID)
791       {
792         TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
793         if(maskCacheIndex != INVALID_CACHE_INDEX)
794         {
795           TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
796
797           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));
798
799           mTextureCacheManager.RemoveCache(maskTextureInfo);
800         }
801       }
802     }
803   }
804 }
805
806 void TextureManager::ProcessRemoveQueue()
807 {
808   DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_TEXTURE_MANAGER_PROCESS_REMOVE_QUEUE", [&](std::ostringstream& oss) {
809     oss << "[" << mRemoveQueue.Count() << "]";
810   });
811
812   // Note that RemoveQueue is not be changed during Remove().
813   for(auto&& textureId : mRemoveQueue)
814   {
815     if(textureId != INVALID_TEXTURE_ID)
816     {
817       Remove(textureId);
818     }
819   }
820
821   mRemoveQueue.Clear();
822
823   DALI_TRACE_END(gTraceFilter, "DALI_TEXTURE_MANAGER_PROCESS_REMOVE_QUEUE");
824 }
825
826 void TextureManager::Process(bool postProcessor)
827 {
828   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::General, "TextureManager::Process()\n");
829
830   ProcessRemoveQueue();
831
832   if(Adaptor::IsAvailable())
833   {
834     Adaptor::Get().UnregisterProcessor(*this, true);
835     mRemoveProcessorRegistered = false;
836   }
837 }
838
839 void TextureManager::LoadImageSynchronously(
840   const VisualUrl&                 url,
841   const Dali::ImageDimensions&     desiredSize,
842   const Dali::FittingMode::Type    fittingMode,
843   const Dali::SamplingMode::Type   samplingMode,
844   const bool                       orientationCorrection,
845   const bool                       loadYuvPlanes,
846   std::vector<Devel::PixelBuffer>& pixelBuffers)
847 {
848   Devel::PixelBuffer pixelBuffer;
849   if(url.IsBufferResource())
850   {
851     const EncodedImageBuffer& encodedImageBuffer = mTextureCacheManager.GetEncodedImageBuffer(url);
852     if(encodedImageBuffer)
853     {
854       pixelBuffer = LoadImageFromBuffer(encodedImageBuffer.GetRawBuffer(), desiredSize, fittingMode, samplingMode, orientationCorrection);
855     }
856   }
857   else
858   {
859     if(loadYuvPlanes)
860     {
861       Dali::LoadImagePlanesFromFile(url.GetUrl(), pixelBuffers, desiredSize, fittingMode, samplingMode, orientationCorrection);
862     }
863     else
864     {
865       pixelBuffer = Dali::LoadImageFromFile(url.GetUrl(), desiredSize, fittingMode, samplingMode, orientationCorrection);
866     }
867   }
868
869   if(pixelBuffer)
870   {
871     pixelBuffers.push_back(pixelBuffer);
872   }
873 }
874
875 void TextureManager::AddObserver(TextureManager::LifecycleObserver& observer)
876 {
877   // make sure an observer doesn't observe the same object twice
878   // otherwise it will get multiple calls to ObjectDestroyed()
879   DALI_ASSERT_DEBUG(mLifecycleObservers.End() == std::find(mLifecycleObservers.Begin(), mLifecycleObservers.End(), &observer));
880   mLifecycleObservers.PushBack(&observer);
881 }
882
883 void TextureManager::RemoveObserver(TextureManager::LifecycleObserver& observer)
884 {
885   // Find the observer...
886   auto endIter = mLifecycleObservers.End();
887   for(auto iter = mLifecycleObservers.Begin(); iter != endIter; ++iter)
888   {
889     if((*iter) == &observer)
890     {
891       mLifecycleObservers.Erase(iter);
892       break;
893     }
894   }
895   DALI_ASSERT_DEBUG(endIter != mLifecycleObservers.End());
896 }
897
898 void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
899 {
900   switch(textureInfo.loadState)
901   {
902     case TextureManager::LoadState::NOT_STARTED:
903     case TextureManager::LoadState::LOAD_FAILED:
904     {
905       if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
906       {
907         QueueLoadTexture(textureInfo, observer);
908       }
909       else
910       {
911         LoadTexture(textureInfo, observer);
912       }
913       break;
914     }
915     case TextureManager::LoadState::UPLOADED:
916     {
917       if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
918       {
919         QueueLoadTexture(textureInfo, observer);
920       }
921       else
922       {
923         // The Texture has already loaded. The other observers have already been notified.
924         // We need to send a "late" loaded notification for this observer.
925         if(observer)
926         {
927           EmitLoadComplete(observer, textureInfo, true);
928         }
929       }
930       break;
931     }
932     case TextureManager::LoadState::LOADING:
933     case TextureManager::LoadState::CANCELLED:
934     case TextureManager::LoadState::MASK_CANCELLED:
935     case TextureManager::LoadState::LOAD_FINISHED:
936     case TextureManager::LoadState::WAITING_FOR_MASK:
937     case TextureManager::LoadState::MASK_APPLYING:
938     case TextureManager::LoadState::MASK_APPLIED:
939     {
940       break;
941     }
942   }
943 }
944
945 void TextureManager::QueueLoadTexture(const TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
946 {
947   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Add observer to observer queue (textureId:%d, observer:%p)\n", textureInfo.textureId, observer);
948
949   const auto& textureId = textureInfo.textureId;
950   mLoadQueue.PushBack(QueueElement(textureId, observer));
951
952   if(observer)
953   {
954     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Connect DestructionSignal to observer:%p\n", observer);
955     observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
956   }
957 }
958
959 void TextureManager::LoadTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer)
960 {
961   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::LoadTexture(): url:%s sync:%s\n", textureInfo.url.GetUrl().c_str(), textureInfo.loadSynchronously ? "T" : "F");
962   textureInfo.loadState = TextureManager::LoadState::LOADING;
963   if(!textureInfo.loadSynchronously)
964   {
965     auto premultiplyOnLoad = (textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID) ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
966     if(textureInfo.animatedImageLoading)
967     {
968       mAsyncLoader->LoadAnimatedImage(textureInfo.textureId, textureInfo.animatedImageLoading, textureInfo.frameIndex, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, premultiplyOnLoad);
969     }
970     else
971     {
972       mAsyncLoader->Load(textureInfo.textureId, textureInfo.url, textureInfo.desiredSize, textureInfo.fittingMode, textureInfo.samplingMode, textureInfo.orientationCorrection, premultiplyOnLoad, textureInfo.loadYuvPlanes);
973     }
974   }
975   ObserveTexture(textureInfo, observer);
976 }
977
978 void TextureManager::ProcessLoadQueue()
979 {
980   for(auto&& element : mLoadQueue)
981   {
982     if(element.mTextureId == INVALID_TEXTURE_ID)
983     {
984       continue;
985     }
986
987     TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(element.mTextureId);
988     if(cacheIndex != INVALID_CACHE_INDEX)
989     {
990       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
991
992       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));
993
994       if((textureInfo.loadState == TextureManager::LoadState::UPLOADED) ||
995          (textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED &&
996           textureInfo.storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER))
997       {
998         if(element.mObserver)
999         {
1000           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", element.mObserver);
1001           element.mObserver->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1002
1003           EmitLoadComplete(element.mObserver, textureInfo, true);
1004         }
1005       }
1006       else if(textureInfo.loadState == TextureManager::LoadState::LOADING)
1007       {
1008         // Note : LOADING state texture cannot be queue.
1009         // This case be occured when same texture id are queue in mLoadQueue.
1010         ObserveTexture(textureInfo, element.mObserver);
1011       }
1012       else
1013       {
1014         LoadTexture(textureInfo, element.mObserver);
1015       }
1016     }
1017   }
1018
1019   mLoadQueue.Clear();
1020 }
1021
1022 void TextureManager::ObserveTexture(TextureManager::TextureInfo& textureInfo,
1023                                     TextureUploadObserver*       observer)
1024 {
1025   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::ObserveTexture(): url:%s observer:%p\n", textureInfo.url.GetUrl().c_str(), observer);
1026
1027   if(observer)
1028   {
1029     textureInfo.observerList.PushBack(observer);
1030
1031     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Connect DestructionSignal to observer:%p\n", observer);
1032     observer->DestructionSignal().Connect(this, &TextureManager::ObserverDestroyed);
1033   }
1034 }
1035
1036 void TextureManager::AsyncLoadComplete(const TextureManager::TextureId textureId, std::vector<Devel::PixelBuffer>& pixelBuffers)
1037 {
1038   TextureCacheIndex cacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
1039   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::AsyncLoadComplete( textureId:%d CacheIndex:%d )\n", textureId, cacheIndex.GetIndex());
1040   if(cacheIndex != INVALID_CACHE_INDEX)
1041   {
1042     TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
1043
1044     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));
1045     if(textureInfo.loadState != TextureManager::LoadState::CANCELLED && textureInfo.loadState != TextureManager::LoadState::MASK_CANCELLED)
1046     {
1047       // textureInfo can be invalidated after this call (as the mTextureInfoContainer may be modified)
1048       PostLoad(textureInfo, pixelBuffers);
1049     }
1050     else
1051     {
1052       Remove(textureInfo.textureId);
1053     }
1054   }
1055 }
1056
1057 void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, std::vector<Devel::PixelBuffer>& pixelBuffers)
1058 {
1059   if(!pixelBuffers.empty()) ///< Load success
1060   {
1061     if(pixelBuffers.size() == 1)
1062     {
1063       Devel::PixelBuffer pixelBuffer = pixelBuffers[0];
1064       if(pixelBuffer && (pixelBuffer.GetWidth() != 0) && (pixelBuffer.GetHeight() != 0))
1065       {
1066         textureInfo.preMultiplied = pixelBuffer.IsAlphaPreMultiplied();
1067
1068         if(textureInfo.storageType == TextureManager::StorageType::UPLOAD_TO_TEXTURE)
1069         {
1070           // If there is a mask texture ID associated with this texture, then apply the mask
1071           // if it's already loaded. If it hasn't, and the mask is still loading,
1072           // wait for the mask to finish loading.
1073           // note, If the texture is already uploaded synchronously during loading,
1074           // we don't need to apply mask.
1075           if(textureInfo.loadState != TextureManager::LoadState::UPLOADED &&
1076              textureInfo.maskTextureId != INVALID_TEXTURE_ID)
1077           {
1078             if(textureInfo.loadState == TextureManager::LoadState::MASK_APPLYING)
1079             {
1080               textureInfo.loadState = TextureManager::LoadState::MASK_APPLIED;
1081               UploadTextures(pixelBuffers, textureInfo);
1082               NotifyObservers(textureInfo, true);
1083             }
1084             else
1085             {
1086               LoadState maskLoadState = mTextureCacheManager.GetTextureStateInternal(textureInfo.maskTextureId);
1087               textureInfo.pixelBuffer = pixelBuffer; // Store the pixel buffer temporarily
1088               if(maskLoadState == TextureManager::LoadState::LOADING)
1089               {
1090                 textureInfo.loadState = TextureManager::LoadState::WAITING_FOR_MASK;
1091               }
1092               else if(maskLoadState == TextureManager::LoadState::LOAD_FINISHED || maskLoadState == TextureManager::LoadState::UPLOADED)
1093               {
1094                 TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureInfo.maskTextureId);
1095                 if(maskCacheIndex != INVALID_CACHE_INDEX)
1096                 {
1097                   TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
1098                   if(maskTextureInfo.storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER)
1099                   {
1100                     ApplyMask(textureInfo, textureInfo.maskTextureId);
1101                   }
1102                   else if(maskTextureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
1103                   {
1104                     // Upload image texture. textureInfo.loadState will be UPLOADED.
1105                     UploadTextures(pixelBuffers, textureInfo);
1106
1107                     // notify mask texture set.
1108                     NotifyObservers(textureInfo, true);
1109                   }
1110                 }
1111               }
1112               else // maskLoadState == TextureManager::LoadState::LOAD_FAILED
1113               {
1114                 // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
1115                 DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
1116                 UploadTextures(pixelBuffers, textureInfo);
1117                 NotifyObservers(textureInfo, true);
1118               }
1119             }
1120           }
1121           else
1122           {
1123             UploadTextures(pixelBuffers, textureInfo);
1124             NotifyObservers(textureInfo, true);
1125           }
1126         }
1127         else
1128         {
1129           textureInfo.pixelBuffer = pixelBuffer; // Store the pixel data
1130           textureInfo.loadState   = TextureManager::LoadState::LOAD_FINISHED;
1131
1132           if(textureInfo.storageType == TextureManager::StorageType::RETURN_PIXEL_BUFFER)
1133           {
1134             NotifyObservers(textureInfo, true);
1135           }
1136           else // for the TextureManager::StorageType::KEEP_PIXEL_BUFFER and TextureManager::StorageType::KEEP_TEXTURE
1137           {
1138             // Check if there was another texture waiting for this load to complete
1139             // (e.g. if this was an image mask, and its load is on a different thread)
1140             CheckForWaitingTexture(textureInfo);
1141           }
1142         }
1143       }
1144     }
1145     else
1146     {
1147       // YUV case
1148       textureInfo.preMultiplied = false;
1149
1150       UploadTextures(pixelBuffers, textureInfo);
1151       NotifyObservers(textureInfo, true);
1152     }
1153   }
1154   else ///< Load fail
1155   {
1156     textureInfo.loadState = TextureManager::LoadState::LOAD_FAILED;
1157     if(textureInfo.storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER || textureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
1158     {
1159       // Check if there was another texture waiting for this load to complete
1160       // (e.g. if this was an image mask, and its load is on a different thread)
1161       CheckForWaitingTexture(textureInfo);
1162     }
1163     else
1164     {
1165       NotifyObservers(textureInfo, false);
1166     }
1167   }
1168 }
1169
1170 void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTextureInfo)
1171 {
1172   if(maskTextureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED &&
1173      maskTextureInfo.storageType == TextureManager::StorageType::KEEP_TEXTURE)
1174   {
1175     // Upload mask texture. textureInfo.loadState will be UPLOADED.
1176     std::vector<Devel::PixelBuffer> pixelBuffers;
1177     pixelBuffers.push_back(maskTextureInfo.pixelBuffer);
1178     UploadTextures(pixelBuffers, maskTextureInfo);
1179   }
1180
1181   DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureManager::CheckForWaitingTexture(): maskTextureId=%d, maskTextureUrl=%s\n", maskTextureInfo.textureId, maskTextureInfo.url.GetUrl().c_str());
1182
1183   // Search the cache, checking if any texture has this texture id as a maskTextureId
1184   const size_t size = mTextureCacheManager.size();
1185
1186   // Keep notify observer required textureIds.
1187   // Note : NotifyObservers can change mTextureCacheManager cache struct. We should check id's validation before notify.
1188   std::vector<TextureId> notifyRequiredTextureIds;
1189
1190   // TODO : Refactorize here to not iterate whole cached image.
1191   for(TextureCacheIndex cacheIndex = TextureCacheIndex(TextureManagerType::TEXTURE_CACHE_INDEX_TYPE_LOCAL, 0u); cacheIndex.GetIndex() < size; ++cacheIndex.detailValue.index)
1192   {
1193     if(mTextureCacheManager[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
1194        mTextureCacheManager[cacheIndex].loadState == TextureManager::LoadState::WAITING_FOR_MASK)
1195     {
1196       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
1197
1198       if(maskTextureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED)
1199       {
1200         if(maskTextureInfo.storageType == TextureManager::StorageType::KEEP_PIXEL_BUFFER)
1201         {
1202           ApplyMask(textureInfo, maskTextureInfo.textureId);
1203         }
1204       }
1205       else if(maskTextureInfo.loadState == TextureManager::LoadState::UPLOADED)
1206       {
1207         if(maskTextureInfo.storageType == TextureManager::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 = TextureManager::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 == TextureManager::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  = TextureManager::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 != TextureManager::LoadState::UPLOADED)
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 = TextureManager::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 == TextureManager::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, uint32_t& frontElements, 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 == TextureManager::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, textureInfo.preMultiplied));
1445     }
1446     else
1447     {
1448       observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureSet, 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     TextureCacheIndex textureCacheIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
1460     if(textureCacheIndex != INVALID_CACHE_INDEX)
1461     {
1462       TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
1463       textureSet = GetTextureSet(textureInfo);
1464     }
1465   }
1466   else
1467   {
1468     DALI_LOG_ERROR("GetTextureSet is failed. texture is not uploaded \n");
1469   }
1470   return textureSet;
1471 }
1472
1473 TextureSet TextureManager::GetTextureSet(const TextureManager::TextureInfo& textureInfo)
1474 {
1475   TextureSet textureSet;
1476
1477   // Always create new TextureSet here, so we don't share same TextureSets for multiple visuals.
1478   textureSet = TextureSet::New();
1479
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 == TextureManager::StorageType::UPLOAD_TO_TEXTURE || maskTextureInfo.storageType == TextureManager::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   if(observer)
1513   {
1514     const auto iterEnd = textureInfo.observerList.End();
1515     const auto iter    = std::find(textureInfo.observerList.Begin(), iterEnd, observer);
1516     if(iter != iterEnd)
1517     {
1518       // Disconnect and remove the observer.
1519       DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
1520       observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1521       textureInfo.observerList.Erase(iter);
1522     }
1523     else
1524     {
1525       // Given textureId might exist at load queue.
1526       // Remove observer from the LoadQueue
1527       for(auto&& element : mLoadQueue)
1528       {
1529         if(element.mTextureId == textureInfo.textureId && element.mObserver == observer)
1530         {
1531           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "Remove observer from observer queue (textureId:%d, observer:%p)\n", element.mTextureId, element.mObserver);
1532           DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Verbose, "  Disconnect DestructionSignal to observer:%p\n", observer);
1533           observer->DestructionSignal().Disconnect(this, &TextureManager::ObserverDestroyed);
1534           element.mObserver = nullptr;
1535           break;
1536         }
1537       }
1538     }
1539   }
1540 }
1541
1542 } // namespace Internal
1543
1544 } // namespace Toolkit
1545
1546 } // namespace Dali