X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fimages%2Fimage-impl.cpp;h=49d7f54350cca2c24bba6a78d1006d33339820f0;hb=65bb67c665fe465e388e8510eeb5fadda45cf202;hp=2668f9ae78d74203b146c07c551591aff086a8a2;hpb=8f2c5571c924479b6a07a2c2187dedd9c685baf0;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/images/image-impl.cpp b/dali/internal/event/images/image-impl.cpp index 2668f9a..49d7f54 100644 --- a/dali/internal/event/images/image-impl.cpp +++ b/dali/internal/event/images/image-impl.cpp @@ -1,32 +1,32 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +/* + * Copyright (c) 2018 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 INCLUDES +#include // for strcmp + // INTERNAL INCLUDES #include +#include -#include #include -#include #include -#include -#include -#include #include using namespace Dali::Integration; @@ -37,305 +37,42 @@ namespace Dali namespace Internal { -Image::Image( LoadPolicy loadPol, ReleasePolicy releasePol ) -: mWidth(0), - mHeight(0), - mLoadPolicy(loadPol), - mReleasePolicy(releasePol), - mConnectionCount(0), - mImageFactory(ThreadLocalStorage::Get().GetImageFactory()) -{ -} - -Image* Image::New() -{ - return new Image; -} - -Image* Image::New( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol ) -{ - if( IsNinePatchFileName(filename) ) - { - NinePatchImage* image = new NinePatchImage( filename, attributes, loadPol, releasePol ); - return image; - } - else - { - Image* image = new Image( loadPol, releasePol ); - - if( ! filename.empty() ) - { - Vector2 closestSize; - - Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( filename, attributes, closestSize ); - image->mWidth = closestSize.width; - image->mHeight = closestSize.height; - } - - image->mRequest = image->mImageFactory.RegisterRequest( filename, &attributes ); - - if( Dali::Image::Immediate == loadPol ) - { - // Trigger loading of the image on a seperate resource thread as soon as it - // can be scheduled: - image->mTicket = image->mImageFactory.Load( image->mRequest.Get() ); - image->mTicket->AddObserver( *image ); - } - // else lazily load image data later, only when it is needed to draw something: - - DALI_LOG_SET_OBJECT_STRING( image, filename ); - - return image; - } -} - -Image* Image::New( NativeImage& nativeImg, LoadPolicy loadPol, ReleasePolicy releasePol ) -{ - Image* image = new Image; - ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient(); - - - image->mWidth = nativeImg.GetWidth(); - image->mHeight = nativeImg.GetHeight(); - - const ResourceTicketPtr& ticket = resourceClient.AddNativeImage( nativeImg ); - DALI_ASSERT_DEBUG( dynamic_cast( ticket.Get() ) && "Resource ticket not ImageTicket subclass for image resource.\n" ); - image->mTicket = static_cast(ticket.Get()); - image->mTicket->AddObserver( *image ); - - return image; -} - -Image::~Image() -{ - if( mTicket ) - { - mTicket->RemoveObserver( *this ); - if( Stage::IsInstalled() ) - { - mImageFactory.ReleaseTicket( mTicket.Get() ); - } - } -} - -bool Image::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) -{ - bool connected( true ); - DALI_ASSERT_DEBUG( dynamic_cast( object ) && "Resource ticket not ImageTicket subclass for image resource.\n" ); - Image* image = static_cast(object); - - if( Dali::Image::SIGNAL_IMAGE_LOADING_FINISHED == signalName ) - { - image->LoadingFinishedSignal().Connect( tracker, functor ); - } - else if(Dali::Image::SIGNAL_IMAGE_UPLOADED == signalName) - { - image->UploadedSignal().Connect( tracker, functor ); - } - else - { - // signalName does not match any signal - connected = false; - } - - return connected; -} - -ResourceId Image::GetResourceId() const -{ - ResourceId ret = mTicket ? mTicket->GetId() : 0; - - return ret; -} - -const Dali::ImageAttributes& Image::GetAttributes() const -{ - if( mTicket ) - { - return mImageFactory.GetActualAttributes( mTicket->GetId() ); - } - else - { - return mImageFactory.GetRequestAttributes( mRequest.Get() ); - } -} - -const std::string& Image::GetFilename() const -{ - return mImageFactory.GetRequestPath( mRequest.Get() ); -} - -void Image::Reload() -{ - if ( mRequest ) - { - ResourceTicketPtr ticket = mImageFactory.Reload( mRequest.Get() ); - SetTicket( ticket.Get() ); - } -} - -void Image::ResourceLoadingFailed(const ResourceTicket& ticket) -{ - mLoadingFinishedV2.Emit( Dali::Image( this ) ); -} - -void Image::ResourceLoadingSucceeded(const ResourceTicket& ticket) -{ - // Update size with actual loaded size - const ImageTicket* imageTicket = static_cast(&ticket); - mWidth = imageTicket->GetWidth(); - mHeight = imageTicket->GetHeight(); - mLoadingFinishedV2.Emit( Dali::Image( this ) ); -} - -void Image::ResourceUploaded(const ResourceTicket& ticket) -{ - mUploadedV2.Emit( Dali::Image( this ) ); -} - -void Image::ResourceSavingSucceeded( const ResourceTicket& ticket ) -{ - // do nothing -} - -void Image::ResourceSavingFailed( const ResourceTicket& ticket ) -{ - // do nothing -} - unsigned int Image::GetWidth() const { - // Width has already been calculated - just return that return mWidth; } unsigned int Image::GetHeight() const { - // Height has already been calculated - just return that return mHeight; } Vector2 Image::GetNaturalSize() const { - return Vector2( mWidth, mHeight ); + return Vector2( static_cast( mWidth ), static_cast( mHeight ) ); } -void Image::Connect() +Image::Image() +: mTexture(), + mWidth( 0 ), + mHeight( 0 ), + mConnectionCount( 0 ) { - ++mConnectionCount; - - if( mConnectionCount == 1 ) - { - // ticket was thrown away when related actors went offstage or image loading on demand - if( !mTicket ) - { - ResourceTicketPtr newTicket = mImageFactory.Load( mRequest.Get() ); - SetTicket( newTicket.Get() ); - } - } } -void Image::Disconnect() -{ - if( !mTicket ) - { - return; - } - - DALI_ASSERT_DEBUG( mConnectionCount > 0 ); - --mConnectionCount; - if( mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused ) - { - // release image memory when it's not visible anymore (decrease ref. count of texture) - SetTicket( NULL ); - } -} - -void Image::SetTicket( ResourceTicket* ticket ) +Image::~Image() { - if( ticket == mTicket.Get() ) - { - return; - } - - if( mTicket ) - { - mTicket->RemoveObserver( *this ); - mImageFactory.ReleaseTicket( mTicket.Get() ); - } - - if( ticket ) - { - mTicket.Reset( ticket ); - mTicket->AddObserver( *this ); - } - else + if( Stage::IsInstalled() ) { - mTicket.Reset(); + UnregisterObject(); } } -bool Image::IsNinePatchFileName( std::string filename ) +void Image::Initialize() { - bool match = false; - - std::string::const_reverse_iterator iter = filename.rbegin(); - enum { SUFFIX, HASH, HASH_DOT, DONE } state = SUFFIX; - while(iter < filename.rend()) - { - switch(state) - { - case SUFFIX: - { - if(*iter == '.') - { - state = HASH; - } - else if(!isalnum(*iter)) - { - state = DONE; - } - } - break; - case HASH: - { - if( *iter == '#' || *iter == '9' ) - { - state = HASH_DOT; - } - else - { - state = DONE; - } - } - break; - case HASH_DOT: - { - if(*iter == '.') - { - match = true; - } - state = DONE; // Stop testing characters - } - break; - case DONE: - { - } - break; - } - - // Satisfy prevnet - if( state == DONE ) - { - break; - } - - iter++; - } - return match; + RegisterObject(); } - } // namespace Internal } // namespace Dali