X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fnpatch-loader.cpp;h=a7734da6b4901e6dcdece95d80334372225326cf;hp=f0b154a3b82600b5e8c474465fb742b06d5cfb38;hb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d;hpb=ec1db95268e1cf8e8bd893027d45a19c64b32848 diff --git a/dali-toolkit/internal/visuals/npatch-loader.cpp b/dali-toolkit/internal/visuals/npatch-loader.cpp index f0b154a..a7734da 100644 --- a/dali-toolkit/internal/visuals/npatch-loader.cpp +++ b/dali-toolkit/internal/visuals/npatch-loader.cpp @@ -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. @@ -27,18 +27,14 @@ 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& 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::SizeType index = UNINITIALIZED_ID; + const OwnerContainer::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(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(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,26 +126,24 @@ 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; } @@ -158,10 +152,10 @@ int32_t NPatchLoader::GetCacheIndexFromId( const NPatchData::NPatchDataId id ) 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; @@ -170,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; } @@ -185,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); } }