Updated all cpp files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch-loader.cpp
index f5d92ab..a7734da 100644 (file)
@@ -1,5 +1,5 @@
- /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+/*
+ * Copyright (c) 2021 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.
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Internal
 {
-
 namespace
 {
-
 constexpr auto INVALID_CACHE_INDEX = int32_t{-1}; ///< Invalid Cache index
-constexpr auto UNINITIALIZED_ID = int32_t{0}; ///< uninitialised id, use to initialize ids
+constexpr auto UNINITIALIZED_ID    = int32_t{0};  ///< uninitialised id, use to initialize ids
 
 } // Anonymous namespace
 
@@ -56,58 +52,58 @@ NPatchData::NPatchDataId NPatchLoader::GenerateUniqueNPatchDataId()
   return mCurrentNPatchDataId++;
 }
 
-std::size_t NPatchLoader::Load( TextureManager& textureManager, TextureUploadObserver* textureObserver, const std::string& url, const Rect< int >& border, bool& preMultiplyOnLoad, bool synchronousLoading )
+std::size_t NPatchLoader::Load(TextureManager& textureManager, TextureUploadObserver* textureObserver, const std::string& url, const Rect<int>& border, bool& preMultiplyOnLoad, bool synchronousLoading)
 {
-  std::size_t hash = CalculateHash( url );
-  OwnerContainer< NPatchData* >::SizeType index = UNINITIALIZED_ID;
-  const OwnerContainer< NPatchData* >::SizeType count = mCache.Count();
+  std::size_t                                 hash  = CalculateHash(url);
+  OwnerContainer<NPatchData*>::SizeType       index = UNINITIALIZED_ID;
+  const OwnerContainer<NPatchData*>::SizeType count = mCache.Count();
 
-  for( ; index < count; ++index )
+  for(; index < count; ++index)
   {
-    if( mCache[ index ]->GetHash() == hash )
+    if(mCache[index]->GetHash() == hash)
     {
       // hash match, check url as well in case of hash collision
-      if(mCache[ index ]->GetUrl() == url)
+      if(mCache[index]->GetUrl() == url)
       {
         // Use cached data
-        if( mCache[ index ]->GetBorder() == border )
+        if(mCache[index]->GetBorder() == border)
         {
-          if( mCache[ index ]->GetLoadingState() == NPatchData::LoadingState::LOADING )
+          if(mCache[index]->GetLoadingState() == NPatchData::LoadingState::LOADING)
           {
-            mCache[ index ]->AddObserver( textureObserver );
+            mCache[index]->AddObserver(textureObserver);
           }
-          return mCache[ index ]->GetId(); // valid indices are from 1 onwards
+          return mCache[index]->GetId(); // valid indices are from 1 onwards
         }
         else
         {
-          if( mCache[ index ]->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE )
+          if(mCache[index]->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
           {
             // Same url but border is different - use the existing texture
             NPatchData* newData = new NPatchData();
             newData->SetId(GenerateUniqueNPatchDataId());
             newData->SetHash(hash);
             newData->SetUrl(url);
-            newData->SetCroppedWidth(mCache[ index ]->GetCroppedWidth());
-            newData->SetCroppedHeight(mCache[ index ]->GetCroppedHeight());
+            newData->SetCroppedWidth(mCache[index]->GetCroppedWidth());
+            newData->SetCroppedHeight(mCache[index]->GetCroppedHeight());
 
-            newData->SetTextures(mCache[ index ]->GetTextures());
+            newData->SetTextures(mCache[index]->GetTextures());
 
             NPatchUtility::StretchRanges stretchRangesX;
-            stretchRangesX.PushBack( Uint16Pair( border.left, ( (newData->GetCroppedWidth() >= static_cast< unsigned int >( border.right )) ? newData->GetCroppedHeight() - border.right : 0 ) ) );
+            stretchRangesX.PushBack(Uint16Pair(border.left, ((newData->GetCroppedWidth() >= static_cast<unsigned int>(border.right)) ? newData->GetCroppedHeight() - border.right : 0)));
 
             NPatchUtility::StretchRanges stretchRangesY;
-            stretchRangesY.PushBack( Uint16Pair( border.top, ( (newData->GetCroppedWidth() >= static_cast< unsigned int >( border.bottom )) ? newData->GetCroppedHeight() - border.bottom : 0 ) ) );
+            stretchRangesY.PushBack(Uint16Pair(border.top, ((newData->GetCroppedWidth() >= static_cast<unsigned int>(border.bottom)) ? newData->GetCroppedHeight() - border.bottom : 0)));
 
             newData->SetStretchPixelsX(stretchRangesX);
             newData->SetStretchPixelsY(stretchRangesY);
             newData->SetBorder(border);
 
-            newData->SetPreMultiplyOnLoad(mCache[ index ]->IsPreMultiplied());
+            newData->SetPreMultiplyOnLoad(mCache[index]->IsPreMultiplied());
 
             newData->SetLoadingState(NPatchData::LoadingState::LOAD_COMPLETE);
-            newData->AddObserver( textureObserver );
+            newData->AddObserver(textureObserver);
 
-            mCache.PushBack( newData );
+            mCache.PushBack(newData);
 
             return newData->GetId(); // valid ids start from 1u
           }
@@ -130,39 +126,36 @@ std::size_t NPatchLoader::Load( TextureManager& textureManager, TextureUploadObs
   auto preMultiplyOnLoading = preMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
                                                 : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
-  Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer( url, Dali::ImageDimensions(), FittingMode::DEFAULT,
-                                                                   SamplingMode::BOX_THEN_LINEAR, synchronousLoading,
-                                                                   data, true, preMultiplyOnLoading );
+  Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(url, Dali::ImageDimensions(), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, synchronousLoading, data, true, preMultiplyOnLoading);
 
-  if( pixelBuffer )
+  if(pixelBuffer)
   {
-    preMultiplyOnLoad = ( preMultiplyOnLoading == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD ) ? true : false;
-    data->SetLoadedNPatchData( pixelBuffer, preMultiplyOnLoad );
+    preMultiplyOnLoad = (preMultiplyOnLoading == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD) ? true : false;
+    data->SetLoadedNPatchData(pixelBuffer, preMultiplyOnLoad);
   }
 
   return data->GetId();
 }
 
-int32_t NPatchLoader::GetCacheIndexFromId( const NPatchData::NPatchDataId id )
+int32_t NPatchLoader::GetCacheIndexFromId(const NPatchData::NPatchDataId id)
 {
   const unsigned int size = mCache.Count();
 
-  for( unsigned int i = 0; i < size; ++i )
+  for(unsigned int i = 0; i < size; ++i)
   {
-    if( mCache[i]->GetId() == id )
+    if(mCache[i]->GetId() == id)
     {
       return i;
     }
   }
 
-  DALI_LOG_ERROR("Wrong NPatchDataId is used\n");
   return INVALID_CACHE_INDEX;
 }
 
-bool NPatchLoader::GetNPatchData( const NPatchData::NPatchDataId id, const NPatchData*& data )
+bool NPatchLoader::GetNPatchData(const NPatchData::NPatchDataId id, const NPatchData*& data)
 {
   int32_t cacheIndex = GetCacheIndexFromId(id);
-  if( cacheIndex != INVALID_CACHE_INDEX )
+  if(cacheIndex != INVALID_CACHE_INDEX)
   {
     data = mCache[cacheIndex];
     return true;
@@ -171,10 +164,10 @@ bool NPatchLoader::GetNPatchData( const NPatchData::NPatchDataId id, const NPatc
   return false;
 }
 
-void NPatchLoader::Remove( std::size_t id, TextureUploadObserver* textureObserver )
+void NPatchLoader::Remove(std::size_t id, TextureUploadObserver* textureObserver)
 {
   int32_t cacheIndex = GetCacheIndexFromId(id);
-  if( cacheIndex == INVALID_CACHE_INDEX )
+  if(cacheIndex == INVALID_CACHE_INDEX)
   {
     return;
   }
@@ -186,7 +179,7 @@ void NPatchLoader::Remove( std::size_t id, TextureUploadObserver* textureObserve
 
   if(data->GetObserverCount() == 0)
   {
-      mCache.Erase( mCache.Begin() + cacheIndex );
+    mCache.Erase(mCache.Begin() + cacheIndex);
   }
 }