[Tizen] Add ImageUrl Class and reference count for external texture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / texture-manager-impl.cpp
index a449997..b225d8d 100644 (file)
@@ -519,6 +519,7 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
 void TextureManager::Remove(const TextureManager::TextureId textureId, TextureUploadObserver* observer)
 {
   int textureInfoIndex = GetCacheIndexFromId(textureId);
+
   if(textureInfoIndex != INVALID_INDEX)
   {
     TextureInfo& textureInfo(mTextureInfoContainer[textureInfoIndex]);
@@ -660,6 +661,7 @@ std::string TextureManager::AddExternalTexture(TextureSet& textureSet)
   info.textureId  = GenerateUniqueTextureId();
   info.textureSet = textureSet;
   mExternalTextures.emplace_back(info);
+
   return VisualUrl::CreateTextureUrl(std::to_string(info.textureId));
 }
 
@@ -668,10 +670,9 @@ TextureSet TextureManager::RemoveExternalTexture(const std::string& url)
   if(url.size() > 0u)
   {
     // get the location from the Url
-    VisualUrl parseUrl(url);
-    if(VisualUrl::TEXTURE == parseUrl.GetProtocolType())
+    if(VisualUrl::TEXTURE == VisualUrl::GetProtocolType(url))
     {
-      std::string location = parseUrl.GetLocation();
+      std::string location = VisualUrl::GetLocation(url);
       if(location.size() > 0u)
       {
         TextureId  id  = std::stoi(location);
@@ -681,7 +682,10 @@ TextureSet TextureManager::RemoveExternalTexture(const std::string& url)
           if(iter->textureId == id)
           {
             auto textureSet = iter->textureSet;
-            mExternalTextures.erase(iter);
+            if(--(iter->referenceCount) <= 0)
+            {
+              mExternalTextures.erase(iter);
+            }
             return textureSet;
           }
         }
@@ -691,6 +695,26 @@ TextureSet TextureManager::RemoveExternalTexture(const std::string& url)
   return TextureSet();
 }
 
+void TextureManager::UseExternalTexture(const VisualUrl& url)
+{
+  if(VisualUrl::TEXTURE == url.GetProtocolType())
+  {
+    std::string location = url.GetLocation();
+    if(location.size() > 0u)
+    {
+      TextureId id = std::stoi(location);
+      for(auto&& elem : mExternalTextures)
+      {
+        if(elem.textureId == id)
+        {
+          elem.referenceCount++;
+          return;
+        }
+      }
+    }
+  }
+}
+
 void TextureManager::AddObserver(TextureManager::LifecycleObserver& observer)
 {
   // make sure an observer doesn't observe the same object twice