X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fvisual-url.cpp;h=c43af6d7485ec4f7a29ed2b3759b9f63846fb62d;hb=a6e73b84ce0442ad28197c3ef2ed1b48fa682508;hp=1979f780dceb119b31226e5e2f90d341fdf88e77;hpb=0f5a244a8e8f8fa680dccafca44ccc9fedb387a8;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/visual-url.cpp b/dali-toolkit/internal/visuals/visual-url.cpp index 1979f78..c43af6d 100644 --- a/dali-toolkit/internal/visuals/visual-url.cpp +++ b/dali-toolkit/internal/visuals/visual-url.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,9 @@ #include // EXTERNAL HEADERS +#include #include // for toupper() -// INTERNAL HEADERS -#include -#include - namespace Dali { namespace Toolkit @@ -38,15 +35,28 @@ VisualUrl::ProtocolType ResolveLocation(const std::string& url) const uint32_t length = url.size(); if((length > 7) && urlCStr[5] == ':' && urlCStr[6] == '/' && urlCStr[7] == '/') { - // https:// - if(('h' == tolower(urlCStr[0])) && - ('t' == tolower(urlCStr[1])) && - ('t' == tolower(urlCStr[2])) && - ('p' == tolower(urlCStr[3])) && - ('s' == tolower(urlCStr[4]))) + // https:// or enbuf:// + const char hOre = tolower(urlCStr[0]); + const char tOrn = tolower(urlCStr[1]); + const char tOrb = tolower(urlCStr[2]); + const char pOru = tolower(urlCStr[3]); + const char sOrf = tolower(urlCStr[4]); + if(('h' == hOre) && + ('t' == tOrn) && + ('t' == tOrb) && + ('p' == pOru) && + ('s' == sOrf)) { return VisualUrl::REMOTE; } + if(('e' == hOre) && + ('n' == tOrn) && + ('b' == tOrb) && + ('u' == pOru) && + ('f' == sOrf)) + { + return VisualUrl::BUFFER; + } } else if((length > 6) && urlCStr[4] == ':' && urlCStr[5] == '/' && urlCStr[6] == '/') { @@ -73,18 +83,20 @@ VisualUrl::ProtocolType ResolveLocation(const std::string& url) else if((length > 5) && urlCStr[3] == ':' && urlCStr[4] == '/' && urlCStr[5] == '/') { // ftp:// or ssh:// - const char fOrS = tolower(urlCStr[0]); - if(('f' == fOrS) || ('s' == fOrS)) + const char fOrs = tolower(urlCStr[0]); + const char tOrs = tolower(urlCStr[1]); + const char pOrh = tolower(urlCStr[2]); + if(('f' == fOrs) && + ('t' == tOrs) && + ('p' == pOrh)) { - const char tOrs = tolower(urlCStr[1]); - if(('t' == tOrs) || ('s' == tOrs)) - { - const char pOrh = tolower(urlCStr[2]); - if(('p' == pOrh) || ('h' == pOrh)) - { - return VisualUrl::REMOTE; - } - } + return VisualUrl::REMOTE; + } + if(('s' == fOrs) && + ('s' == tOrs) && + ('h' == pOrh)) + { + return VisualUrl::REMOTE; } } return VisualUrl::LOCAL; @@ -93,7 +105,8 @@ VisualUrl::ProtocolType ResolveLocation(const std::string& url) VisualUrl::Type ResolveType(const std::string& url) { // if only one char in string, can only be regular image - const std::size_t count = url.size(); + const std::size_t count = url.size(); + VisualUrl::Type returnType = VisualUrl::REGULAR_IMAGE; if(count > 0) { // parsing from the end for better chance of early outs @@ -107,7 +120,9 @@ 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 TVG[4] = {'g', 'v', 't', '.'}; unsigned int svgScore = 0; + unsigned int tvgScore = 0; unsigned int gifScore = 0; unsigned int webpScore = 0; unsigned int jsonScore = 0; @@ -124,20 +139,28 @@ VisualUrl::Type ResolveType(const std::string& url) return VisualUrl::SVG; } } + if((offsetFromEnd < sizeof(TVG)) && (currentChar == TVG[offsetFromEnd])) + { + // early out if TVG as can't be used in N patch for now + if(++tvgScore == sizeof(TVG)) + { + return VisualUrl::TVG; + } + } if((offsetFromEnd < sizeof(GIF)) && (currentChar == GIF[offsetFromEnd])) { - // early out if GIF as can't be used in N patch for now + //find type, but need to be check used in N patch if(++gifScore == sizeof(GIF)) { - return VisualUrl::GIF; + returnType = VisualUrl::GIF; } } if((offsetFromEnd < sizeof(WEBP)) && (currentChar == WEBP[offsetFromEnd])) { - // early out if WEBP as can't be used in N patch for now if(++webpScore == sizeof(WEBP)) { - return VisualUrl::WEBP; + //find type, but need to be check used in N patch + returnType = VisualUrl::WEBP; } } if((offsetFromEnd < sizeof(JSON)) && (currentChar == JSON[offsetFromEnd])) @@ -167,7 +190,7 @@ VisualUrl::Type ResolveType(const std::string& url) else { // early out, not a valid N/9-patch URL - return VisualUrl::REGULAR_IMAGE; + return returnType; } break; } @@ -180,7 +203,7 @@ VisualUrl::Type ResolveType(const std::string& url) else { // early out, not a valid N/9-patch URL - return VisualUrl::REGULAR_IMAGE; + return returnType; } break; } @@ -188,7 +211,7 @@ VisualUrl::Type ResolveType(const std::string& url) } } // if we got here it is a regular image - return VisualUrl::REGULAR_IMAGE; + return returnType; } } // namespace @@ -196,86 +219,48 @@ VisualUrl::Type ResolveType(const std::string& url) VisualUrl::VisualUrl() : mUrl(), mType(VisualUrl::REGULAR_IMAGE), - mLocation(VisualUrl::LOCAL) + mLocation(VisualUrl::LOCAL), + mUrlHash(0ull) { } VisualUrl::VisualUrl(const std::string& url) : mUrl(url), mType(VisualUrl::REGULAR_IMAGE), - mLocation(VisualUrl::LOCAL) + mLocation(VisualUrl::LOCAL), + mUrlHash(0ull) { if(!url.empty()) { mLocation = ResolveLocation(url); - if(VisualUrl::TEXTURE != mLocation) + if(VisualUrl::TEXTURE != mLocation && VisualUrl::BUFFER != mLocation) { - // TEXTURE location url doesn't need type resolving, REGULAR_IMAGE is fine + // TEXTURE and BUFFER 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); - } - } } } VisualUrl::VisualUrl(const VisualUrl& url) : mUrl(url.mUrl), mType(url.mType), - mLocation(url.mLocation) + mLocation(url.mLocation), + mUrlHash(url.mUrlHash) { - 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); - } - } + mUrlHash = url.mUrlHash; } return *this; } @@ -285,6 +270,11 @@ const std::string& VisualUrl::GetUrl() const return mUrl; } +const std::uint64_t& VisualUrl::GetUrlHash() const +{ + return DALI_UNLIKELY(mUrlHash == 0) ? (mUrlHash = Dali::CalculateHash(mUrl)) : mUrlHash; +} + VisualUrl::Type VisualUrl::GetType() const { return mType; @@ -305,6 +295,11 @@ bool VisualUrl::IsLocalResource() const return mLocation == VisualUrl::LOCAL; } +bool VisualUrl::IsBufferResource() const +{ + return mLocation == VisualUrl::BUFFER; +} + std::string VisualUrl::GetLocation() const { return GetLocation(mUrl); @@ -315,6 +310,11 @@ std::string VisualUrl::CreateTextureUrl(const std::string& location) return "dali://" + location; } +std::string VisualUrl::CreateBufferUrl(const std::string& location) +{ + return "enbuf://" + location; +} + VisualUrl::ProtocolType VisualUrl::GetProtocolType(const std::string& url) { return ResolveLocation(url); @@ -330,7 +330,6 @@ std::string VisualUrl::GetLocation(const std::string& url) return url; } - } // namespace Internal } // namespace Toolkit