X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fnpatch-loader.cpp;h=5f8ddff06db9b39d46fce4d8c041aaecd099defd;hb=HEAD;hp=8bc050fdc7d2b0658066a0ad279c9d3d3fc5e3ea;hpb=5fa82acc87ca7de63ce715bb3cb63a12ac36fbcf;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/npatch-loader.cpp b/dali-toolkit/internal/visuals/npatch-loader.cpp deleted file mode 100644 index 8bc050f..0000000 --- a/dali-toolkit/internal/visuals/npatch-loader.cpp +++ /dev/null @@ -1,173 +0,0 @@ - /* - * Copyright (c) 2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// EXTERNAL HEADER -#include -#include -#include - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -NPatchLoader::NPatchLoader() -{ -} - -NPatchLoader::~NPatchLoader() -{ -} - -std::size_t NPatchLoader::Load( const std::string& url, const Rect< int >& border ) -{ - std::size_t hash = CalculateHash( url ); - OwnerContainer< Data* >::SizeType index = UNINITIALIZED_ID; - const OwnerContainer< Data* >::SizeType count = mCache.Count(); - int cachedIndex = -1; - - for( ; index < count; ++index ) - { - if( mCache[ index ]->hash == hash ) - { - // hash match, check url as well in case of hash collision - if( mCache[ index ]->url == url ) - { - // Use cached data - if( mCache[ index ]->border == border ) - { - return index+1u; // valid indices are from 1 onwards - } - else - { - cachedIndex = index; - } - } - } - } - - if( cachedIndex != -1 ) - { - // Same url but border is different - use the existing texture - Data* data = new Data(); - data->hash = hash; - data->url = url; - data->croppedWidth = mCache[ cachedIndex ]->croppedWidth; - data->croppedHeight = mCache[ cachedIndex ]->croppedHeight; - - data->textureSet = mCache[ cachedIndex ]->textureSet; - - NinePatchImage::StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( border.left, ( (data->croppedWidth >= static_cast< unsigned int >( border.right )) ? data->croppedWidth - border.right : 0 ) ) ); - - NinePatchImage::StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( border.top, ( (data->croppedHeight >= static_cast< unsigned int >( border.bottom )) ? data->croppedHeight - border.bottom : 0 ) ) ); - - data->stretchPixelsX = stretchRangesX; - data->stretchPixelsY = stretchRangesY; - data->border = border; - - mCache.PushBack( data ); - - return mCache.Count(); // valid ids start from 1u - } - - // got to the end so no match, decode N patch and append new item to cache - if( border == Rect< int >( 0, 0, 0, 0 ) ) - { - NinePatchImage ninePatch = NinePatchImage::New( url ); - if( ninePatch ) - { - BufferImage croppedImage = ninePatch.CreateCroppedBufferImage(); - if( croppedImage ) - { - Data* data = new Data(); - data->hash = hash; - data->url = url; - data->textureSet = TextureSet::New(); - TextureSetImage( data->textureSet, 0u, croppedImage ); - data->croppedWidth = croppedImage.GetWidth(); - data->croppedHeight = croppedImage.GetHeight(); - data->stretchPixelsX = ninePatch.GetStretchPixelsX(); - data->stretchPixelsY = ninePatch.GetStretchPixelsY(); - data->border = Rect< int >( 0, 0, 0, 0 ); - mCache.PushBack( data ); - - return mCache.Count(); // valid ids start from 1u - } - } - } - else - { - // Load image from file - PixelData pixels = SyncImageLoader::Load( url ); - if( pixels ) - { - Data* data = new Data(); - data->hash = hash; - data->url = url; - data->croppedWidth = pixels.GetWidth(); - data->croppedHeight = pixels.GetHeight(); - - Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() ); - texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() ); - - data->textureSet = TextureSet::New(); - data->textureSet.SetTexture( 0u, texture ); - - NinePatchImage::StretchRanges stretchRangesX; - stretchRangesX.PushBack( Uint16Pair( border.left, ( (data->croppedWidth >= static_cast< unsigned int >( border.right )) ? data->croppedWidth - border.right : 0 ) ) ); - - NinePatchImage::StretchRanges stretchRangesY; - stretchRangesY.PushBack( Uint16Pair( border.top, ( (data->croppedHeight >= static_cast< unsigned int >( border.bottom )) ? data->croppedHeight - border.bottom : 0 ) ) ); - - data->stretchPixelsX = stretchRangesX; - data->stretchPixelsY = stretchRangesY; - data->border = border; - - mCache.PushBack( data ); - - return mCache.Count(); // valid ids start from 1u - } - } - - return 0u; -} - -bool NPatchLoader::GetNPatchData( std::size_t id, const Data*& data ) -{ - if( ( id > UNINITIALIZED_ID )&&( id <= mCache.Count() ) ) - { - data = mCache[ id - 1u ]; // id's start from 1u - return true; - } - data = NULL; - return false; -} - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali