Merge "Add ApplyCustomFragmentPrefix" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-url.cpp
index 97bc9b9..1979f78 100644 (file)
 // EXTERNAL HEADERS
 #include <cstring> // for toupper()
 
+// INTERNAL HEADERS
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
+
 namespace Dali
 {
 namespace Toolkit
@@ -103,12 +107,10 @@ VisualUrl::Type ResolveType(const std::string& url)
     char         GIF[4]    = {'f', 'i', 'g', '.'};
     char         WEBP[5]   = {'p', 'b', 'e', 'w', '.'};
     char         JSON[5]   = {'n', 'o', 's', 'j', '.'};
-    char         RIVE[4]   = {'v', 'i', 'r', '.'};
     unsigned int svgScore  = 0;
     unsigned int gifScore  = 0;
     unsigned int webpScore = 0;
     unsigned int jsonScore = 0;
-    unsigned int riveScore = 0;
     int          index     = count;
     while(--index >= 0)
     {
@@ -146,14 +148,6 @@ VisualUrl::Type ResolveType(const std::string& url)
           return VisualUrl::JSON;
         }
       }
-      if((offsetFromEnd < sizeof(RIVE)) && (currentChar == RIVE[offsetFromEnd]))
-      {
-        // early out if RIVE as can't be used in N patch for now
-        if(++riveScore == sizeof(RIVE))
-        {
-          return VisualUrl::RIVE;
-        }
-      }
       switch(state)
       {
         case SUFFIX:
@@ -219,6 +213,14 @@ VisualUrl::VisualUrl(const std::string& url)
       // TEXTURE location url doesn't need type resolving, REGULAR_IMAGE is fine
       mType = ResolveType(url);
     }
+    else
+    {
+      Toolkit::VisualFactory factory = Toolkit::VisualFactory::Get();
+      if(factory)
+      {
+        GetImplementation(factory).GetTextureManager().UseExternalTexture(*this);
+      }
+    }
   }
 }
 
@@ -227,15 +229,53 @@ VisualUrl::VisualUrl(const VisualUrl& url)
   mType(url.mType),
   mLocation(url.mLocation)
 {
+  if(VisualUrl::TEXTURE == mLocation)
+  {
+    Toolkit::VisualFactory factory = Toolkit::VisualFactory::Get();
+    if(factory)
+    {
+      GetImplementation(factory).GetTextureManager().UseExternalTexture(*this);
+    }
+  }
+}
+
+VisualUrl::~VisualUrl()
+{
+  if(VisualUrl::TEXTURE == mLocation)
+  {
+    Toolkit::VisualFactory factory = Toolkit::VisualFactory::Get();
+    if(factory)
+    {
+      GetImplementation(factory).GetTextureManager().RemoveExternalTexture(mUrl);
+    }
+  }
 }
 
 VisualUrl& VisualUrl::operator=(const VisualUrl& url)
 {
   if(&url != this)
   {
+    if(VisualUrl::TEXTURE == mLocation)
+    {
+      Toolkit::VisualFactory factory = Toolkit::VisualFactory::Get();
+      if(factory)
+      {
+        GetImplementation(factory).GetTextureManager().RemoveExternalTexture(mUrl);
+      }
+    }
+
     mUrl      = url.mUrl;
     mType     = url.mType;
     mLocation = url.mLocation;
+
+    if(VisualUrl::TEXTURE == mLocation)
+    {
+      Toolkit::VisualFactory factory = Toolkit::VisualFactory::Get();
+      if(factory)
+      {
+        GetImplementation(factory).GetTextureManager().UseExternalTexture(*this);
+      }
+    }
   }
   return *this;
 }
@@ -267,12 +307,7 @@ bool VisualUrl::IsLocalResource() const
 
 std::string VisualUrl::GetLocation() const
 {
-  const auto location = mUrl.find("://");
-  if(std::string::npos != location)
-  {
-    return mUrl.substr(location + 3u); // 3 characters forwards from the start of ://
-  }
-  return mUrl;
+  return GetLocation(mUrl);
 }
 
 std::string VisualUrl::CreateTextureUrl(const std::string& location)
@@ -280,6 +315,22 @@ std::string VisualUrl::CreateTextureUrl(const std::string& location)
   return "dali://" + location;
 }
 
+VisualUrl::ProtocolType VisualUrl::GetProtocolType(const std::string& url)
+{
+  return ResolveLocation(url);
+}
+
+std::string VisualUrl::GetLocation(const std::string& url)
+{
+  const auto location = url.find("://");
+  if(std::string::npos != location)
+  {
+    return url.substr(location + 3u); // 3 characters forwards from the start of ://
+  }
+  return url;
+}
+
+
 } // namespace Internal
 
 } // namespace Toolkit