From: Paul Wisbey Date: Tue, 20 Jan 2015 11:50:38 +0000 (+0000) Subject: ResourceImage/Image split X-Git-Tag: dali_1.0.31~17^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=9870235a4fd92b473960b27a632bdc428d18f377;p=platform%2Fcore%2Fuifw%2Fdali-core.git ResourceImage/Image split Move all of the features relevant to images loaded via URL into a derived class: - Querying whether the image has loaded (GetLoadingState) - Querying the URL (GetFilename renamed to GetUrl) - Signal when the loading succeeds or fails (LoadingFinishedSignal) - The Reload() feature - The LoadPolicy feature This also enables the derived type to be distinguished from image types such as FrameBufferImage, which are not compatible with certain features (e.g. Atlas) Change-Id: I708d8df6c8ff32067143c022100d6b61b1405ee5 --- diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-Image-Culling.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-Image-Culling.cpp index 8945a75..f506cf2 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-Image-Culling.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-Image-Culling.cpp @@ -54,7 +54,7 @@ Image LoadImage( TestApplication& application, GLuint textureId, int width, int const Vector2 closestImageSize( width, height ); application.GetPlatform().SetClosestImageSize(closestImageSize); - image = Image::New( filename, Image::Immediate, Image::Never ); + image = ResourceImage::New( filename, ResourceImage::IMMEDIATE, Image::NEVER ); free (filename); } DALI_TEST_CHECK(image); diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-ImageFactory.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-ImageFactory.cpp index 37e0980..19d8428 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-ImageFactory.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-ImageFactory.cpp @@ -67,14 +67,14 @@ int UtcDaliImageFactoryUseCachedRequest01(void) tet_infoline( "UtcDaliImageFactoryCachedRequest01 - Request same image more than once" ); - Image image = Image::New( gTestImageFilename ); + Image image = ResourceImage::New( gTestImageFilename ); application.SendNotification(); application.Render(); DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) ); application.GetPlatform().ResetTrace(); - Image image2 = Image::New( gTestImageFilename ); + Image image2 = ResourceImage::New( gTestImageFilename ); application.SendNotification(); application.Render(); @@ -83,7 +83,7 @@ int UtcDaliImageFactoryUseCachedRequest01(void) DALI_TEST_CHECK( !application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) ); application.GetPlatform().ResetTrace(); - Image image3 = Image::New( gTestImageFilename ); + Image image3 = ResourceImage::New( gTestImageFilename ); application.SendNotification(); application.Render(); @@ -99,7 +99,7 @@ int UtcDaliImageFactoryUseCachedRequest02(void) // testing resource deletion when taken off stage tet_infoline( "UtcDaliImageFactoryCachedRequest02 - Discard previously requested resource" ); - Image image = Image::New( gTestImageFilename, Image::Immediate, Image::Unused ); + Image image = ResourceImage::New( gTestImageFilename, ResourceImage::IMMEDIATE, Image::UNUSED ); ImageActor actor = ImageActor::New( image ); application.SendNotification(); @@ -124,7 +124,7 @@ int UtcDaliImageFactoryUseCachedRequest02(void) application.SendNotification(); // Should find stale request in cache, so load image from filesystem - Image image2 = Image::New( gTestImageFilename ); + Image image2 = ResourceImage::New( gTestImageFilename ); application.SendNotification(); application.Render(); @@ -133,7 +133,7 @@ int UtcDaliImageFactoryUseCachedRequest02(void) application.GetPlatform().ResetTrace(); // Resource is reloaded - Image image3 = Image::New( gTestImageFilename ); + Image image3 = ResourceImage::New( gTestImageFilename ); application.SendNotification(); application.Render(); diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp index 57852d3..5feb844 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-ResourceClient.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -117,7 +117,7 @@ static TestTicketLifetimeObserver testTicketLifetimeObserver; Internal::ImagePtr LoadImage(TestApplication& application, char* name) { - Internal::ImagePtr image = Internal::Image::New(name, Dali::ImageAttributes::DEFAULT_ATTRIBUTES ); + Internal::ResourceImagePtr image = Internal::ResourceImage::New( name, Dali::ImageAttributes::DEFAULT_ATTRIBUTES ); application.SendNotification(); // Flush update messages application.Render(); // Process resource request Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); diff --git a/automated-tests/src/dali/utc-Dali-BitmapImage.cpp b/automated-tests/src/dali/utc-Dali-BitmapImage.cpp index a2a9be2..b9af021 100644 --- a/automated-tests/src/dali/utc-Dali-BitmapImage.cpp +++ b/automated-tests/src/dali/utc-Dali-BitmapImage.cpp @@ -51,9 +51,7 @@ int UtcDaliBitmapImageNew01(void) application.Render(16); application.SendNotification(); - ImageAttributes attributes = image.GetAttributes(); - - DALI_TEST_CHECK( attributes.GetWidth() == 16); + DALI_TEST_CHECK( image.GetWidth() == 16); END_TEST; } @@ -70,9 +68,7 @@ int UtcDaliBitmapImageNew02(void) application.Render(16); application.SendNotification(); - Dali::ImageAttributes attributes = image.GetAttributes(); - - DALI_TEST_CHECK( attributes.GetWidth() == 16); + DALI_TEST_CHECK( image.GetWidth() == 16); delete [] buffer; END_TEST; @@ -93,16 +89,13 @@ int UtcDaliBitmapImageNewWithPolicy01(void) BitmapImage image; // initialise handle - image = BitmapImage::New(16, 16, Pixel::A8, Image::OnDemand, Image::Unused); + image = BitmapImage::New(16, 16, Pixel::A8, Image::UNUSED); application.SendNotification(); application.Render(16); application.Render(16); application.SendNotification(); - ImageAttributes attributes = image.GetAttributes(); - DALI_TEST_CHECK( attributes.GetWidth() == 16); - /// @todo: how to test OnDemand? - resource id would be 0 if buffer only allocated on first call to ::GetBuffer() - + DALI_TEST_CHECK( image.GetWidth() == 16); ImageActor actor = ImageActor::New(image); Stage::GetCurrent().Add(actor); @@ -137,16 +130,13 @@ int UtcDaliBitmapImageNewWithPolicy02(void) application.GetGlAbstraction().SetNextTextureIds( ids ); PixelBuffer* buffer = new PixelBuffer[16 * 16]; - BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8, 16, Image::Unused); + BitmapImage image = BitmapImage::New(buffer, 16, 16, Pixel::A8, 16, Image::UNUSED); application.SendNotification(); application.Render(16); application.Render(16); application.SendNotification(); - ImageAttributes attributes = image.GetAttributes(); - DALI_TEST_CHECK( attributes.GetWidth() == 16); - /// @todo: how to test OnDemand? - resource id would be 0 if buffer only allocated on first call to ::GetBuffer() - + DALI_TEST_CHECK( image.GetWidth() == 16); ImageActor actor = ImageActor::New(image); Stage::GetCurrent().Add(actor); @@ -193,7 +183,7 @@ int UtcDaliBitmapImageDownCast2(void) TestApplication application; tet_infoline("Testing Dali::BitmapImage::DownCast()"); - Image image = Image::New("IncorrectImageName"); + Image image = ResourceImage::New("IncorrectImageName"); ImageActor imageActor = ImageActor::New(image); application.SendNotification(); application.Render(16); @@ -223,10 +213,9 @@ int UtcDaliBitmapImageWHITE(void) application.Render(16); application.SendNotification(); - Dali::ImageAttributes attributes = image.GetAttributes(); PixelBuffer* buffer = image.GetBuffer(); - DALI_TEST_CHECK( attributes.GetWidth() == 1 && // 1 pixel wide + DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide buffer != NULL && // valid buffer *buffer == 0xff); // r component is 255 END_TEST; @@ -246,8 +235,7 @@ int UtcDaliBitmapImageGetBuffer(void) application.Render(); application.SendNotification(); - ImageAttributes attributes = image.GetAttributes(); - DALI_TEST_CHECK( attributes.GetWidth() == 1 && // 1 pixel wide + DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide buffer != NULL && // valid buffer *((unsigned int*)buffer) == 0xffffffff); // all component are 255 END_TEST; @@ -265,12 +253,11 @@ int UtcDaliBitmapImageGetBufferSize(void) application.Render(); application.SendNotification(); - Dali::ImageAttributes attributes = image.GetAttributes(); PixelBuffer* buffer = image.GetBuffer(); unsigned int bufferSize = image.GetBufferSize(); - unsigned int pixelSize = Pixel::GetBytesPerPixel(attributes.GetPixelFormat()); + unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat()); - DALI_TEST_CHECK( attributes.GetWidth() == 1 && // 1 pixel wide + DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide buffer != NULL && // valid buffer bufferSize == pixelSize); // r component is 255 END_TEST; @@ -288,8 +275,7 @@ int UtcDaliBitmapImageGetBufferStride(void) application.Render(); application.SendNotification(); - Dali::ImageAttributes attributes = image.GetAttributes(); - unsigned int pixelSize = Pixel::GetBytesPerPixel(attributes.GetPixelFormat()); + unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat()); unsigned int bufferStride = image.GetBufferStride(); DALI_TEST_CHECK( bufferStride == pixelSize ); DALI_TEST_CHECK( !image.IsDataExternal() ); diff --git a/automated-tests/src/dali/utc-Dali-Constrainable.cpp b/automated-tests/src/dali/utc-Dali-Constrainable.cpp index bbe96b2..e62c67d 100644 --- a/automated-tests/src/dali/utc-Dali-Constrainable.cpp +++ b/automated-tests/src/dali/utc-Dali-Constrainable.cpp @@ -51,7 +51,7 @@ int UtcDaliConstrainableDownCastNegative(void) { TestApplication application; - Image image = Image::New( "temp" ); + Image image = ResourceImage::New( "temp" ); Constrainable customHandle1 = Constrainable::DownCast( image ); DALI_TEST_CHECK( ! customHandle1 ); diff --git a/automated-tests/src/dali/utc-Dali-EncodedBufferImage.cpp b/automated-tests/src/dali/utc-Dali-EncodedBufferImage.cpp index 1679189..784d45b 100644 --- a/automated-tests/src/dali/utc-Dali-EncodedBufferImage.cpp +++ b/automated-tests/src/dali/utc-Dali-EncodedBufferImage.cpp @@ -775,7 +775,7 @@ int UtcDaliEncodedBufferImageNew01(void) Dali::ImageAttributes imageAttributes; imageAttributes.SetSize( 720, 1280 ); imageAttributes.SetScalingMode( Dali::ImageAttributes::FitHeight ); - image = EncodedBufferImage::New( sEncodedBufferImageDataPNG, sEncodedBufferImageDataPNGLength, imageAttributes, Image::Never ); + image = EncodedBufferImage::New( sEncodedBufferImageDataPNG, sEncodedBufferImageDataPNGLength, imageAttributes, Image::NEVER ); DALI_TEST_CHECK( image ); @@ -785,7 +785,7 @@ int UtcDaliEncodedBufferImageNew01(void) DALI_TEST_CHECK( !image2 ); // Trigger image decode to initialise the handle - image2 = EncodedBufferImage::New( sEncodedBufferImageDataPNG, sEncodedBufferImageDataPNGLength, imageAttributes, Image::Unused ); + image2 = EncodedBufferImage::New( sEncodedBufferImageDataPNG, sEncodedBufferImageDataPNGLength, imageAttributes, Image::UNUSED ); DALI_TEST_CHECK( image2 ); END_TEST; @@ -810,7 +810,7 @@ int UtcDaliEncodedBufferImageNew02(void) try { // This should throw on the null pointer: - image = EncodedBufferImage::New( 0, sEncodedBufferImageDataPNGLength, imageAttributes, Image::Never ); + image = EncodedBufferImage::New( 0, sEncodedBufferImageDataPNGLength, imageAttributes, Image::NEVER ); tet_result( TET_FAIL ); } catch (Dali::DaliException& e) @@ -839,7 +839,7 @@ int UtcDaliEncodedBufferImageNew03(void) try { // This should throw on the zero size: - image = EncodedBufferImage::New( sEncodedBufferImageDataPNG, /** Trigger the assertion.*/ 0, imageAttributes, Image::Never ); + image = EncodedBufferImage::New( sEncodedBufferImageDataPNG, /** Trigger the assertion.*/ 0, imageAttributes, Image::NEVER ); tet_result( TET_FAIL ); } catch (Dali::DaliException& e) diff --git a/automated-tests/src/dali/utc-Dali-FrameBufferImage.cpp b/automated-tests/src/dali/utc-Dali-FrameBufferImage.cpp index e44171e..f282693 100644 --- a/automated-tests/src/dali/utc-Dali-FrameBufferImage.cpp +++ b/automated-tests/src/dali/utc-Dali-FrameBufferImage.cpp @@ -46,7 +46,6 @@ int UtcDaliFrameBufferImageNew01(void) // invoke default handle constructor FrameBufferImage image; - Dali::ImageAttributes attributes; Vector2 stageSize = Stage::GetCurrent().GetSize(); // initialise handle @@ -59,11 +58,9 @@ int UtcDaliFrameBufferImageNew01(void) application.Render(); application.SendNotification(); - attributes = image.GetAttributes(); - DALI_TEST_CHECK( image ); - DALI_TEST_EQUALS((float)attributes.GetWidth(), stageSize.width, TEST_LOCATION); - DALI_TEST_EQUALS((float)attributes.GetHeight(), stageSize.height, TEST_LOCATION); + DALI_TEST_EQUALS((float)image.GetWidth(), stageSize.width, TEST_LOCATION); + DALI_TEST_EQUALS((float)image.GetHeight(), stageSize.height, TEST_LOCATION); image = FrameBufferImage::New(16, 16); // create framebuffer with dimensions of 16x16 actor.SetImage(image); @@ -73,11 +70,9 @@ int UtcDaliFrameBufferImageNew01(void) application.Render(); application.SendNotification(); - attributes = image.GetAttributes(); - DALI_TEST_CHECK( image ); - DALI_TEST_EQUALS(attributes.GetWidth(), 16u, TEST_LOCATION); - DALI_TEST_EQUALS(attributes.GetHeight(), 16u, TEST_LOCATION); + DALI_TEST_EQUALS(image.GetWidth(), 16u, TEST_LOCATION); + DALI_TEST_EQUALS(image.GetHeight(), 16u, TEST_LOCATION); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-HitTestAlgorithm.cpp b/automated-tests/src/dali/utc-Dali-HitTestAlgorithm.cpp index f6350c7..c37a905 100644 --- a/automated-tests/src/dali/utc-Dali-HitTestAlgorithm.cpp +++ b/automated-tests/src/dali/utc-Dali-HitTestAlgorithm.cpp @@ -170,7 +170,7 @@ int UtcDaliHitTestAlgorithmWithFunctorOnRenderTask(void) RenderTask renderTask[2]; renderTask[0] = taskList.GetTask( 0u ); - FrameBufferImage frameBufferImage = FrameBufferImage::New(stageSize.width, stageSize.height, Pixel::A8, Image::Never); + FrameBufferImage frameBufferImage = FrameBufferImage::New(stageSize.width, stageSize.height, Pixel::A8, Image::NEVER); renderTask[1] = taskList.CreateTask(); renderTask[1].SetSourceActor( actor[1] ); renderTask[1].SetExclusive( true ); diff --git a/automated-tests/src/dali/utc-Dali-Image.cpp b/automated-tests/src/dali/utc-Dali-Image.cpp index 491f618..8170b69 100644 --- a/automated-tests/src/dali/utc-Dali-Image.cpp +++ b/automated-tests/src/dali/utc-Dali-Image.cpp @@ -50,7 +50,7 @@ int UtcDaliImageNew01(void) DALI_TEST_CHECK( !image ); // initialise handle - image = Image::New(gTestImageFilename); + image = ResourceImage::New(gTestImageFilename); DALI_TEST_CHECK( image ); END_TEST; @@ -72,7 +72,7 @@ int UtcDaliImageNew02(void) Dali::ImageAttributes imageAttributes; imageAttributes.SetSize(128, 256); imageAttributes.SetScalingMode(Dali::ImageAttributes::FitHeight); - image = Image::New(gTestImageFilename, imageAttributes); + image = ResourceImage::New(gTestImageFilename, imageAttributes); DALI_TEST_CHECK( image ); END_TEST; @@ -106,7 +106,7 @@ int UtcDaliImageNewWithPolicies01(void) // testing delayed loading tet_infoline("UtcDaliImageNewWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never"); DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Never); + Image image = ResourceImage::New(gTestImageFilename, ResourceImage::ON_DEMAND, Image::NEVER); DALI_TEST_CHECK( image ); @@ -164,7 +164,7 @@ int UtcDaliImageNewWithPolicies02(void) // testing resource deletion when taken off stage tet_infoline("UtcDaliImageNewWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused"); - Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Unused); + Image image = ResourceImage::New(gTestImageFilename, ResourceImage::ON_DEMAND, Image::UNUSED); DALI_TEST_CHECK( image ); @@ -222,7 +222,7 @@ int UtcDaliImageNewWithPolicies03(void) // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused"); - Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Unused); + Image image = ResourceImage::New(gTestImageFilename, ResourceImage::IMMEDIATE, Image::UNUSED); DALI_TEST_CHECK( image ); @@ -288,7 +288,7 @@ int UtcDaliImageNewWithPolicies04(void) // load immediately, don't release texture when off stage tet_infoline("UtcDaliImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never"); - Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Never); + Image image = ResourceImage::New(gTestImageFilename, ResourceImage::IMMEDIATE, Image::NEVER); DALI_TEST_CHECK( image ); @@ -347,360 +347,12 @@ int UtcDaliImageNewWithPolicies04(void) } // 1.8 -int UtcDaliImageNewDistanceField(void) -{ - TestApplication application; - - tet_infoline("UtcDaliImageNewDistanceField - Image::NewDistanceField(const std::string&)"); - - // invoke default handle constructor - Image image; - - DALI_TEST_CHECK( !image ); - - // initialise handle - image = Image::NewDistanceField(gTestImageFilename); - - DALI_TEST_CHECK( image ); - END_TEST; -} - -// 1.9 -int UtcDaliImageNewDistanceFieldWithPolicies01(void) -{ - TestApplication application; - - // testing delayed loading - tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never"); - DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - Image image = Image::NewDistanceField(gTestImageFilename, Image::OnDemand, Image::Never); - - DALI_TEST_CHECK( image ); - - application.SendNotification(); - application.Render(16); - - // request file loading only when actor added to stage - DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - ImageActor actor = ImageActor::New(image); - - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - - DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - // testing ReleasePolicy::Never - // fake loading image - std::vector ids; - ids.push_back( 23 ); - application.GetGlAbstraction().SetNextTextureIds( ids ); - Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD ); - Integration::ResourcePointer resource(bitmap); - bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80); - - if(request) - { - application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource); - } - application.Render(16); - application.SendNotification(); - - DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) ); - - // never discard texture - Stage::GetCurrent().Remove(actor); - application.Render(16); - application.SendNotification(); - application.Render(16); - application.SendNotification(); - DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) ); - END_TEST; -} - -// 1.10 -int UtcDaliImageNewDistanceFieldWithPolicies02(void) -{ - TestApplication application; - - const Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - // testing resource deletion when taken off stage - tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused"); - - Image image = Image::NewDistanceField(gTestImageFilename, Image::OnDemand, Image::Unused); - - DALI_TEST_CHECK( image ); - - application.SendNotification(); - application.Render(16); - - // request file loading only when actor added to stage - DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - ImageActor actor = ImageActor::New(image); - - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - - DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - // testing ReleasePolicy::Unused - // fake loading image - std::vector ids; - ids.push_back( 23 ); - application.GetGlAbstraction().SetNextTextureIds( ids ); - Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD ); - Integration::ResourcePointer resource(bitmap); - bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80); - - if(request) - { - application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource); - } - application.Render(16); - application.SendNotification(); - - DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) ); - - // discard texture when actor comes off stage - Stage::GetCurrent().Remove(actor); - application.Render(16); - application.SendNotification(); - application.Render(16); - application.SendNotification(); - DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) ); - END_TEST; -} - -// 1.11 -int UtcDaliImageNewDistanceFieldWithPolicies03(void) -{ - TestApplication application; - const Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again - tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused"); - - Image image = Image::NewDistanceField(gTestImageFilename, Image::Immediate, Image::Unused); - - DALI_TEST_CHECK( image ); - - application.SendNotification(); - application.Render(16); - - // request file loading immediately - DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - ImageActor actor = ImageActor::New(image); - - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - - // testing ReleasePolicy::Unused - // fake loading image - std::vector ids; - ids.push_back( 23 ); - application.GetGlAbstraction().SetNextTextureIds( ids ); - Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD ); - Integration::ResourcePointer resource(bitmap); - bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80); - - if(request) - { - application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource); - } - application.Render(16); - application.SendNotification(); - - DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) ); - - // discard texture when actor comes off stage - Stage::GetCurrent().Remove(actor); - application.Render(16); - application.SendNotification(); - application.Render(16); - application.SendNotification(); - DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) ); - - // check load request when actor added back to stage - application.GetPlatform().ResetTrace(); - - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - application.SendNotification(); - application.Render(16); - - DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - END_TEST; -} - -// 1.12 -int UtcDaliImageNewDistanceFieldWithPolicies04(void) -{ - TestApplication application; - - // load immediately, don't release texture when off stage - tet_infoline("UtcDaliImageNewDistanceFieldWithPolicies04 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never"); - - Image image = Image::NewDistanceField(gTestImageFilename, Image::Immediate, Image::Never); - - DALI_TEST_CHECK( image ); - - application.SendNotification(); - application.Render(16); - - // request file loading immediately - DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - ImageActor actor = ImageActor::New(image); - - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - - // testing ReleasePolicy::Never - // fake loading image - std::vector ids; - ids.push_back( 23 ); - application.GetGlAbstraction().SetNextTextureIds( ids ); - Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD ); - Integration::ResourcePointer resource(bitmap); - bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80); - - if(request) - { - application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource); - } - application.Render(16); - application.SendNotification(); - - DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) ); - - // texture is not discarded - Stage::GetCurrent().Remove(actor); - application.Render(16); - application.SendNotification(); - application.Render(16); - application.SendNotification(); - DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) ); - - // no load request when actor added back to stage - application.GetPlatform().ResetTrace(); - - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - application.SendNotification(); - application.Render(16); - - DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - END_TEST; -} - -// 1.13 -int UtcDaliImageNewDistanceFieldWithAttributes(void) -{ - TestApplication application; - - tet_infoline("UtcDaliImageNewDistanceFieldWithAttributes - Image::NewDistanceField(const std::string&, const ImageAttributes& attributes)"); - - // invoke default handle constructor - Image image; - Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::NewDistanceField(6.0f, 12); - - DALI_TEST_CHECK( !image ); - - // initialise handle - image = Image::NewDistanceField(gTestImageFilename, imageAttributes); - - DALI_TEST_CHECK( image ); - END_TEST; -} - -// 1.14 -int UtcDaliImageNewDistanceFieldWithAttrandPol(void) -{ - TestApplication application; - - const Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - tet_infoline("UtcDaliImageNewDistanceFieldWithAttrandPol - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused"); - - Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::NewDistanceField(6.0f, 12); - - Image image = Image::NewDistanceField(gTestImageFilename, imageAttributes, Image::OnDemand, Image::Unused); - - DALI_TEST_CHECK( image ); - - application.SendNotification(); - application.Render(16); - - // request file loading only when actor added to stage - DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - ImageActor actor = ImageActor::New(image); - - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - - DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ); - - // testing ReleasePolicy::Unused - // fake loading image - std::vector ids; - ids.push_back( 23 ); - application.GetGlAbstraction().SetNextTextureIds( ids ); - Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD ); - Integration::ResourcePointer resource(bitmap); - bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80); - - if(request) - { - application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource); - } - application.Render(16); - application.SendNotification(); - - DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) ); - - // discard texture when actor comes off stage - Stage::GetCurrent().Remove(actor); - application.Render(16); - application.SendNotification(); - application.Render(16); - application.SendNotification(); - DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) ); - END_TEST; -} - -// 1.15 int UtcDaliImageDownCast(void) { TestApplication application; tet_infoline("Testing Dali::Image::DownCast()"); - Image image = Image::New(gTestImageFilename); + Image image = ResourceImage::New(gTestImageFilename); BaseHandle object(image); @@ -719,7 +371,7 @@ int UtcDaliImageDownCast(void) END_TEST; } -// 1.16 +// 1.9 int UtcDaliImageGetImageSize(void) { TestApplication application; @@ -730,39 +382,39 @@ int UtcDaliImageGetImageSize(void) Vector2 testSize(8.0f, 16.0f); platform.SetClosestImageSize(testSize); - Vector2 size = Image::GetImageSize(gTestImageFilename); + Vector2 size = ResourceImage::GetImageSize(gTestImageFilename); DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize")); DALI_TEST_EQUALS( size, testSize, TEST_LOCATION); END_TEST; } -// 1.17 -int UtcDaliImageGetFilename(void) +// 1.10 +int UtcDaliImageGetUrl(void) { TestApplication application; tet_infoline("UtcDaliImageGetFilename"); // invoke default handle constructor - Image image; + ResourceImage image; DALI_TEST_CHECK( !image ); // initialise handle - image = Image::New(gTestImageFilename); + image = ResourceImage::New(gTestImageFilename); - DALI_TEST_EQUALS( image.GetFilename(), gTestImageFilename, TEST_LOCATION); + DALI_TEST_EQUALS( image.GetUrl(), gTestImageFilename, TEST_LOCATION); END_TEST; } -// 1.18 +// 1.11 int UtcDaliImageGetLoadingState01(void) { TestApplication application; tet_infoline("UtcDaliImageGetLoadingState01"); - Image image = Image::New(gTestImageFilename); + ResourceImage image = ResourceImage::New(gTestImageFilename); DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading); application.SendNotification(); application.Render(16); @@ -785,7 +437,7 @@ int UtcDaliImageGetLoadingState01(void) END_TEST; } -// 1.19 +// 1.12 int UtcDaliImageGetLoadingState02(void) { TestApplication application; @@ -793,12 +445,12 @@ int UtcDaliImageGetLoadingState02(void) tet_infoline("UtcDaliImageGetLoadingState02"); // invoke default handle constructor - Image image; + ResourceImage image; DALI_TEST_CHECK( !image ); // initialise handle - image = Image::New(gTestImageFilename); + image = ResourceImage::New(gTestImageFilename); // Test state == ResourceLoading DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading); @@ -819,40 +471,40 @@ int UtcDaliImageGetLoadingState02(void) END_TEST; } -// 1.20 +// 1.13 int UtcDaliImageGetReleasePolicy(void) { TestApplication application; tet_infoline("UtcDaliImageGetReleasePolicy"); - Image image = Image::New(gTestImageFilename, Image::Immediate, Image::Unused); + Image image = ResourceImage::New(gTestImageFilename, ResourceImage::IMMEDIATE, Image::UNUSED); DALI_TEST_CHECK( image ); - DALI_TEST_CHECK( Image::Unused == image.GetReleasePolicy() ); + DALI_TEST_CHECK( Image::UNUSED == image.GetReleasePolicy() ); END_TEST; } -// 1.21 +// 1.14 int UtcDaliImageGetLoadPolicy(void) { TestApplication application; tet_infoline("UtcDaliImageGetLoadPolicy"); - Image image = Image::New(gTestImageFilename, Image::OnDemand, Image::Never); + ResourceImage image = ResourceImage::New(gTestImageFilename, ResourceImage::ON_DEMAND, Image::NEVER); DALI_TEST_CHECK( image ); - DALI_TEST_CHECK( Image::OnDemand == image.GetLoadPolicy()); + DALI_TEST_CHECK( ResourceImage::ON_DEMAND == image.GetLoadPolicy()); END_TEST; } static bool SignalLoadFlag = false; -static void SignalLoadHandler(Image image) +static void SignalLoadHandler(ResourceImage image) { tet_infoline("Received image load finished signal"); @@ -868,7 +520,7 @@ static void SignalUploadedHandler(Image image) SignalUploadedFlag = true; } -// 1.22 +// 1.15 int UtcDaliImageSignalLoadingFinished(void) { TestApplication application; @@ -877,7 +529,7 @@ int UtcDaliImageSignalLoadingFinished(void) SignalLoadFlag = false; - Image image = Image::New(gTestImageFilename); + ResourceImage image = ResourceImage::New(gTestImageFilename); image.LoadingFinishedSignal().Connect( SignalLoadHandler ); application.SendNotification(); @@ -896,7 +548,7 @@ int UtcDaliImageSignalLoadingFinished(void) END_TEST; } -// 1.23 +// 1.16 int UtcDaliImageSignalUploaded(void) { TestApplication application; @@ -906,7 +558,7 @@ int UtcDaliImageSignalUploaded(void) Vector2 testSize(80.0f, 80.0f); application.GetPlatform().SetClosestImageSize(testSize); - Image image = Image::New(gTestImageFilename); + ResourceImage image = ResourceImage::New(gTestImageFilename); image.LoadingFinishedSignal().Connect( SignalLoadHandler ); // Load image @@ -966,15 +618,14 @@ int UtcDaliImageSignalUploaded(void) END_TEST; } - -// 1.24 +// 1.17 int UtcDaliImageDiscard01(void) { TestApplication application; tet_infoline("UtcDaliImageDiscard01 - no actors"); { - Image image = Image::New(gTestImageFilename); + Image image = ResourceImage::New(gTestImageFilename); // Load image application.SendNotification(); @@ -1006,7 +657,7 @@ int UtcDaliImageDiscard01(void) END_TEST; } -// 1.25 +// 1.18 int UtcDaliImageDiscard02(void) { TestApplication application; @@ -1020,7 +671,7 @@ int UtcDaliImageDiscard02(void) ImageAttributes attrs; const Vector2 requestedSize( 40, 30 ); attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New(gTestImageFilename, attrs); + Image image = ResourceImage::New(gTestImageFilename, attrs); actor = ImageActor::New(image); Stage::GetCurrent().Add(actor); @@ -1065,7 +716,7 @@ int UtcDaliImageDiscard02(void) END_TEST; } -// 1.26 +// 1.19 int UtcDaliImageDiscard03(void) { TestApplication application; @@ -1074,7 +725,7 @@ int UtcDaliImageDiscard03(void) const Vector2 closestImageSize( 1, 1); application.GetPlatform().SetClosestImageSize(closestImageSize); - Image image = Image::New(gTestImageFilename); + Image image = ResourceImage::New(gTestImageFilename); ImageActor actor = ImageActor::New(image); Stage::GetCurrent().Add(actor); @@ -1145,7 +796,7 @@ int UtcDaliImageContextLoss(void) tet_infoline("UtcDaliImageContextLoss - Load image with LoadPolicy::Immediate, ReleasePolicy::Never, bitmap discard. Check that the image is re-requested on context regain\n"); - Image image = Image::New("image.png", Image::Immediate, Image::Never); + Image image = ResourceImage::New("image.png", ResourceImage::IMMEDIATE, Image::NEVER); DALI_TEST_CHECK( image ); diff --git a/automated-tests/src/dali/utc-Dali-ImageActor.cpp b/automated-tests/src/dali/utc-Dali-ImageActor.cpp index 5b7d430..e9331e2 100644 --- a/automated-tests/src/dali/utc-Dali-ImageActor.cpp +++ b/automated-tests/src/dali/utc-Dali-ImageActor.cpp @@ -62,7 +62,7 @@ int UtcDaliImageActorNew01(void) TestApplication application; tet_infoline("Positive test for Dali::ImageActor::New()"); - Image image = Image::New(TestImageFilename); + Image image = ResourceImage::New(TestImageFilename); ImageActor actor = ImageActor::New(image); Stage::GetCurrent().Add(actor); @@ -82,7 +82,7 @@ int UtcDaliImageActorNew02(void) TestApplication application; tet_infoline("Negative test for Dali::ImageActor::New()"); - Image image = Image::New("hopefully-this-image-file-does-not-exist"); + Image image = ResourceImage::New("hopefully-this-image-file-does-not-exist"); ImageActor actor = ImageActor::New(image); DALI_TEST_CHECK(actor); @@ -94,7 +94,7 @@ int UtcDaliImageActorDownCast(void) TestApplication application; tet_infoline("Testing Dali::ImageActor::DownCast()"); - Image image = Image::New("IncorrectImageName"); + Image image = ResourceImage::New("IncorrectImageName"); ImageActor actor1 = ImageActor::New(image); Actor anActor = Actor::New(); anActor.Add(actor1); @@ -130,7 +130,7 @@ int UtcDaliImageActor9Patch(void) TestApplication application; tet_infoline("Positive test for Dali::ImageActor:: 9 patch api"); - Image image = Image::New(TestImageFilename); + Image image = ResourceImage::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); @@ -254,7 +254,7 @@ int UtcDaliImageActorGetCurrentSize02(void) application.GetPlatform().SetClosestImageSize(initialImageSize); - Image image = Image::New("image.jpg"); + Image image = ResourceImage::New("image.jpg"); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -306,7 +306,7 @@ int UtcDaliImageActorGetCurrentSize03(void) ImageAttributes attrs; const Vector2 requestedSize( 40, 30 ); attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Image image = ResourceImage::New("image.jpg", attrs); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -359,7 +359,7 @@ int UtcDaliImageActorGetCurrentSize04(void) const Vector2 requestedSize( 40, 30 ); ImageAttributes attrs; attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Image image = ResourceImage::New("image.jpg", attrs); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -397,7 +397,7 @@ int UtcDaliImageActorGetCurrentSize04(void) const Vector2 request2Size( 100, 100 ); attrs.SetSize( request2Size.width, request2Size.height ); - Image image2 = Image::New("image2.jpg", attrs); + Image image2 = ResourceImage::New("image2.jpg", attrs); actor.SetImage(image2); application.SendNotification(); // Flush update messages @@ -443,7 +443,7 @@ int UtcDaliImageActorGetCurrentSize05(void) ImageAttributes attrs; const Vector2 requestedSize( 40, 30 ); attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Image image = ResourceImage::New("image.jpg", attrs); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -473,7 +473,7 @@ int UtcDaliImageActorGetCurrentSize05(void) const Vector2 requestedSize2( 100, 100 ); attrs.SetSize( requestedSize2.width, requestedSize2.height ); - Image image2 = Image::New("image2.jpg", attrs); + Image image2 = ResourceImage::New("image2.jpg", attrs); actor.SetImage(image2); application.SendNotification(); // Flush update messages @@ -522,7 +522,7 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) ImageAttributes attrs; const Vector2 requestedSize( 40, 30 ); attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Image image = ResourceImage::New("image.jpg", attrs); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -585,7 +585,7 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) ImageAttributes attrs; const Vector2 requestedSize( 40, 30 ); attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Image image = ResourceImage::New("image.jpg", attrs); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -835,7 +835,7 @@ int UtcDaliImageGetStyle(void) { TestApplication application; - Image image = Image::New(TestImageFilename); + Image image = ResourceImage::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); @@ -852,7 +852,7 @@ int UtcDaliImageSetNinePatchBorder(void) { TestApplication application; - Image image = Image::New(TestImageFilename); + Image image = ResourceImage::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); @@ -917,7 +917,7 @@ int UtcDaliImageActorPropertyIndices(void) int UtcDaliImageActorImageProperty(void) { TestApplication application; - Image image = Image::New( "MY_PATH" ); + Image image = ResourceImage::New( "MY_PATH" ); ImageActor imageActor = ImageActor::New( image ); Stage::GetCurrent().Add( imageActor ); @@ -948,7 +948,7 @@ int UtcDaliImageActorNinePatch01(void) Integration::ResourcePointer resourcePtr(bitmap); // reference it platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - Image ninePatchImage = Image::New( "blah.#.png" ); + Image ninePatchImage = ResourceImage::New( "blah.#.png" ); DALI_TEST_CHECK( ninePatchImage ); ImageActor imageActor = ImageActor::New( ninePatchImage ); @@ -994,7 +994,7 @@ int UtcDaliImageActorNinePatch02(void) Integration::ResourcePointer resourcePtr; platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - Image ninePatchImage = Image::New( "blah.#.png" ); + Image ninePatchImage = ResourceImage::New( "blah.#.png" ); DALI_TEST_CHECK( ninePatchImage ); ImageActor imageActor = ImageActor::New( ninePatchImage ); @@ -1041,7 +1041,7 @@ int UtcDaliImageActorNinePatch03(void) Integration::ResourcePointer resourcePtr(bitmap); // reference it platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - Image ninePatchImage = Image::New( "blah.#.png" ); + Image ninePatchImage = ResourceImage::New( "blah.#.png" ); DALI_TEST_CHECK( ninePatchImage ); ImageActor imageActor = ImageActor::New(); @@ -1089,7 +1089,7 @@ int UtcDaliImageActorNinePatch04(void) Integration::ResourcePointer resourcePtr; platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - Image ninePatchImage = Image::New( "blah.#.png" ); + Image ninePatchImage = ResourceImage::New( "blah.#.png" ); DALI_TEST_CHECK( ninePatchImage ); ImageActor imageActor = ImageActor::New(); diff --git a/automated-tests/src/dali/utc-Dali-Material.cpp b/automated-tests/src/dali/utc-Dali-Material.cpp index 1c0d9e2..bca6587 100644 --- a/automated-tests/src/dali/utc-Dali-Material.cpp +++ b/automated-tests/src/dali/utc-Dali-Material.cpp @@ -129,15 +129,15 @@ int UtcDaliMaterialSettersAndGetters(void) material.SetNormalMapFileName("normal-map.png"); DALI_TEST_EQUALS( material.GetNormalMapFileName(), "normal-map.png", TEST_LOCATION); - Image diffuseTexture = Image::New("diffuse-texture.png"); + Image diffuseTexture = ResourceImage::New("diffuse-texture.png"); material.SetDiffuseTexture(diffuseTexture); DALI_TEST_EQUALS( material.GetDiffuseTexture(), diffuseTexture, TEST_LOCATION ); - Image opacityTexture = Image::New("opacity-texture.png"); + Image opacityTexture = ResourceImage::New("opacity-texture.png"); material.SetOpacityTexture(opacityTexture); DALI_TEST_EQUALS( material.GetOpacityTexture(), opacityTexture, TEST_LOCATION); - Image normalMap = Image::New("normal-map.png"); + Image normalMap = ResourceImage::New("normal-map.png"); material.SetNormalMap(normalMap); DALI_TEST_EQUALS( material.GetNormalMap(), normalMap, TEST_LOCATION); @@ -175,7 +175,7 @@ int UtcDaliMaterialStage01(void) { Material material = Material::New("material"); - Image image = Image::New( "image.png", Image::Immediate, Image::Never ); + Image image = ResourceImage::New( "image.png", ResourceImage::IMMEDIATE, Image::NEVER ); DALI_TEST_CHECK(image); application.SendNotification(); application.Render(16); @@ -258,7 +258,7 @@ int UtcDaliMaterialStage02(void) { Material material = Material::New("material"); - Image image = Image::New( "image.png", Image::OnDemand, Image::Unused ); + Image image = ResourceImage::New( "image.png", ResourceImage::ON_DEMAND, Image::UNUSED ); DALI_TEST_CHECK(image); application.SendNotification(); application.Render(16); diff --git a/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp b/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp index bd2560b..21ee17a 100644 --- a/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp +++ b/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp @@ -151,7 +151,7 @@ int UtcDaliNinePatch01(void) Integration::ResourcePointer resourcePtr(bitmap); platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - Image image = Image::New( "blah.#.png" ); + Image image = ResourceImage::New( "blah.#.png" ); DALI_TEST_CHECK( image ); tet_infoline("Assign image to ImageActor"); @@ -220,7 +220,7 @@ int UtcDaliNinePatch02(void) tet_infoline("Getting resource"); Integration::ResourcePointer resourcePtr(bitmap); platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - Image image = Image::New( "blah.#.png" ); + Image image = ResourceImage::New( "blah.#.png" ); DALI_TEST_CHECK( image ); tet_infoline("Assign image to ImageActor"); diff --git a/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp b/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp index d772a3f..e959910 100644 --- a/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp +++ b/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp @@ -312,7 +312,7 @@ int UtcDaliObjectRegistrySignalImageActorCreated(void) ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); static const char* TestImageFilename = "icon_wrt.png"; - Image image = Image::New(TestImageFilename); + Image image = ResourceImage::New(TestImageFilename); bool verified = false; TestImageActorCallback test(verified); diff --git a/automated-tests/src/dali/utc-Dali-RenderTask.cpp b/automated-tests/src/dali/utc-Dali-RenderTask.cpp index 9619b50..dcba4c1 100644 --- a/automated-tests/src/dali/utc-Dali-RenderTask.cpp +++ b/automated-tests/src/dali/utc-Dali-RenderTask.cpp @@ -184,9 +184,9 @@ bool TestScreenToFrameBufferFunction( Vector2& coordinates ) return true; } -ImageActor CreateLoadingImage(TestApplication& application, std::string filename, Image::LoadPolicy loadPolicy, Image::ReleasePolicy releasePolicy) +ImageActor CreateLoadingImage(TestApplication& application, std::string filename, ResourceImage::LoadPolicy loadPolicy, Image::ReleasePolicy releasePolicy) { - Image image = Image::New(filename, loadPolicy, releasePolicy); + Image image = ResourceImage::New(filename, loadPolicy, releasePolicy); DALI_TEST_CHECK( image ); application.SendNotification(); application.Render(16); @@ -216,7 +216,7 @@ void FailImageLoad(TestApplication& application, Integration::ResourceId resourc application.GetPlatform().SetResourceLoadFailed(resourceId, Integration::FailureUnknown); } -void ReloadImage(TestApplication& application, Image image) +void ReloadImage(TestApplication& application, ResourceImage image) { application.GetPlatform().ClearReadyResources(); application.GetPlatform().DiscardRequest(); @@ -1271,7 +1271,7 @@ int UtcDaliRenderTaskContinuous01(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1317,7 +1317,7 @@ int UtcDaliRenderTaskContinuous02(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1361,7 +1361,7 @@ int UtcDaliRenderTaskContinuous03(void) Stage::GetCurrent().Add( rootActor ); CameraActor offscreenCameraActor = CameraActor::New(); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1406,7 +1406,7 @@ int UtcDaliRenderTaskContinuous04(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1446,7 +1446,7 @@ int UtcDaliRenderTaskOnce01(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1503,7 +1503,7 @@ int UtcDaliRenderTaskOnce02(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1562,7 +1562,7 @@ int UtcDaliRenderTaskOnce03(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1619,7 +1619,7 @@ int UtcDaliRenderTaskOnce03(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1693,7 +1693,7 @@ int UtcDaliRenderTaskOnce05(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1761,7 +1761,7 @@ int UtcDaliRenderTaskOnce06(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1838,7 +1838,7 @@ int UtcDaliRenderTaskOnce07(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -1902,7 +1902,7 @@ int UtcDaliRenderTaskOnce08(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Stage::GetCurrent().Add(secondRootActor); @@ -1958,7 +1958,7 @@ int UtcDaliRenderTaskOnceNoSync01(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2008,7 +2008,7 @@ int UtcDaliRenderTaskOnceNoSync02(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2056,7 +2056,7 @@ int UtcDaliRenderTaskOnceNoSync03(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2106,7 +2106,7 @@ int UtcDaliRenderTaskOnceNoSync03(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2168,7 +2168,7 @@ int UtcDaliRenderTaskOnceNoSync05(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2222,7 +2222,7 @@ int UtcDaliRenderTaskOnceNoSync06(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2282,7 +2282,7 @@ int UtcDaliRenderTaskOnceNoSync07(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2334,7 +2334,7 @@ int UtcDaliRenderTaskOnceNoSync08(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Stage::GetCurrent().Add(secondRootActor); @@ -2384,7 +2384,7 @@ int UtcDaliRenderTaskOnceChain01(void) CameraActor offscreenCameraActor = CameraActor::New(); Stage::GetCurrent().Add( offscreenCameraActor ); - ImageActor firstRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused); + ImageActor firstRootActor = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED); Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest(); Integration::ResourceId imageRequestId = imageRequest->GetId(); Integration::ResourceTypeId imageType = imageRequest->GetType()->id; @@ -2459,7 +2459,7 @@ int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void) RenderTaskList taskList = stage.GetRenderTaskList(); RenderTask renderTask = taskList.CreateTask(); - FrameBufferImage frameBufferImage = FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8, Image::Never); + FrameBufferImage frameBufferImage = FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8, Image::NEVER); renderTask.SetSourceActor( offscreenActor ); renderTask.SetExclusive( true ); renderTask.SetInputEnabled( true ); diff --git a/automated-tests/src/dali/utc-Dali-Scripting.cpp b/automated-tests/src/dali/utc-Dali-Scripting.cpp index 64ffcf9..2ed6d3b 100644 --- a/automated-tests/src/dali/utc-Dali-Scripting.cpp +++ b/automated-tests/src/dali/utc-Dali-Scripting.cpp @@ -83,10 +83,17 @@ void TestEnumStrings( } } +/// Helper method to create ResourceImage using property +ResourceImage NewResourceImage( const Property::Value& map ) +{ + ResourceImage image = ResourceImage::DownCast( NewImage( map ) ); + return image; +} + /// Helper method to create ImageAttributes using an Image ImageAttributes NewImageAttributes( const Property::Value& map ) { - Image image = NewImage( map ); + ResourceImage image = ResourceImage::DownCast( NewImage( map ) ); return image.GetAttributes(); } @@ -428,8 +435,6 @@ int UtcDaliScriptingNewImageNegative(void) } -////////////////////////////////////////////////////////////////////////////// - int UtcDaliScriptingNewImage(void) { TestApplication application; @@ -439,8 +444,8 @@ int UtcDaliScriptingNewImage(void) // Filename only { - Image image = NewImage( map ); - DALI_TEST_EQUALS( "TEST_FILE", image.GetFilename(), TEST_LOCATION ); + ResourceImage image = ResourceImage::DownCast( NewImage( map ) ); + DALI_TEST_EQUALS( "TEST_FILE", image.GetUrl(), TEST_LOCATION ); } // load-policy @@ -448,10 +453,10 @@ int UtcDaliScriptingNewImage(void) { const StringEnum< int > values[] = { - { "IMMEDIATE", Image::Immediate }, - { "ON_DEMAND", Image::OnDemand } + { "IMMEDIATE", ResourceImage::IMMEDIATE }, + { "ON_DEMAND", ResourceImage::ON_DEMAND } }; - TestEnumStrings< Image::LoadPolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetLoadPolicy, &NewImage ); + TestEnumStrings< ResourceImage::LoadPolicy, ResourceImage >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &ResourceImage::GetLoadPolicy, &NewResourceImage ); } // release-policy @@ -459,8 +464,8 @@ int UtcDaliScriptingNewImage(void) { const StringEnum< int > values[] = { - { "UNUSED", Image::Unused }, - { "NEVER", Image::Never } + { "UNUSED", Image::UNUSED }, + { "NEVER", Image::NEVER } }; TestEnumStrings< Image::ReleasePolicy, Image >( map, values, ( sizeof( values ) / sizeof ( values[0] ) ), &Image::GetReleasePolicy, &NewImage ); } @@ -550,7 +555,7 @@ int UtcDaliScriptingNewImage(void) map[ "type" ] = "Image"; { Image image = NewImage( map ); - DALI_TEST_CHECK( Image::DownCast( image ) ); + DALI_TEST_CHECK( ResourceImage::DownCast( image ) ); DALI_TEST_CHECK( !FrameBufferImage::DownCast( image ) ); DALI_TEST_CHECK( !BitmapImage::DownCast( image ) ); } @@ -924,7 +929,7 @@ int UtcDaliScriptingCreatePropertyMapImage(void) // Default { - Image image = Image::New( "MY_PATH" ); + Image image = ResourceImage::New( "MY_PATH" ); Property::Map map; CreatePropertyMap( image, map ); @@ -932,7 +937,7 @@ int UtcDaliScriptingCreatePropertyMapImage(void) Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "type" ) ); - DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "Image", TEST_LOCATION ); + DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "ResourceImage", TEST_LOCATION ); DALI_TEST_CHECK( value.HasKey( "filename" ) ); DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION ); DALI_TEST_CHECK( value.HasKey( "load-policy") ); @@ -953,7 +958,7 @@ int UtcDaliScriptingCreatePropertyMapImage(void) attributes.SetPixelFormat( Pixel::A8 ); attributes.SetScalingMode( ImageAttributes::FitWidth ); attributes.SetSize( 300, 400 ); - Image image = Image::New( "MY_PATH", attributes, Image::OnDemand, Image::Unused ); + Image image = ResourceImage::New( "MY_PATH", attributes, ResourceImage::ON_DEMAND, Image::UNUSED ); Property::Map map; CreatePropertyMap( image, map ); @@ -961,7 +966,7 @@ int UtcDaliScriptingCreatePropertyMapImage(void) Property::Value value( map ); DALI_TEST_CHECK( value.HasKey( "type" ) ); - DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "Image", TEST_LOCATION ); + DALI_TEST_EQUALS( value.GetValue( "type" ).Get< std::string >(), "ResourceImage", TEST_LOCATION ); DALI_TEST_CHECK( value.HasKey( "filename" ) ); DALI_TEST_EQUALS( value.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION ); DALI_TEST_CHECK( value.HasKey( "load-policy") ); diff --git a/dali/internal/event/images/atlas-impl.cpp b/dali/internal/event/images/atlas-impl.cpp index 7ad423f..f0a7af1 100644 --- a/dali/internal/event/images/atlas-impl.cpp +++ b/dali/internal/event/images/atlas-impl.cpp @@ -49,6 +49,8 @@ bool Atlas::Upload( const BitmapImage& bitmapImage, { bool uploadSuccess( false ); + AllocateAtlas(); + if( IsWithin(bitmapImage, xOffset, yOffset) ) { ResourceId destId = GetResourceId(); @@ -77,19 +79,13 @@ Atlas::Atlas( std::size_t width, { mWidth = width; mHeight = height; - - if( Dali::Image::Immediate == mLoadPolicy ) - { - AllocateAtlas(); - } } void Atlas::Connect() { ++mConnectionCount; - if( Dali::Image::OnDemand == mLoadPolicy && - mConnectionCount == 1 ) + if( mConnectionCount == 1 ) { AllocateAtlas(); } @@ -101,7 +97,7 @@ void Atlas::Disconnect() { --mConnectionCount; - if ( Dali::Image::Unused == mReleasePolicy && + if ( Dali::Image::UNUSED == mReleasePolicy && mConnectionCount == 0 ) { ReleaseAtlas(); diff --git a/dali/internal/event/images/bitmap-image-impl.cpp b/dali/internal/event/images/bitmap-image-impl.cpp index 298c72f..8299d9f 100644 --- a/dali/internal/event/images/bitmap-image-impl.cpp +++ b/dali/internal/event/images/bitmap-image-impl.cpp @@ -37,9 +37,9 @@ namespace TypeRegistration mType( typeid( Dali::BitmapImage ), typeid( Dali::Image ), NULL ); } // unnamed namespace -BitmapImagePtr BitmapImage::New( unsigned int width, unsigned int height, Pixel::Format pixelformat, LoadPolicy loadPol, ReleasePolicy releasePol ) +BitmapImagePtr BitmapImage::New( unsigned int width, unsigned int height, Pixel::Format pixelformat, ReleasePolicy releasePol ) { - BitmapImagePtr internal = new BitmapImage( width, height, pixelformat, loadPol, releasePol ); + BitmapImagePtr internal = new BitmapImage( width, height, pixelformat, releasePol ); internal->Initialize(); return internal; } @@ -51,8 +51,8 @@ BitmapImagePtr BitmapImage::New( PixelBuffer* pixBuf, unsigned int width, unsign return internal; } -BitmapImage::BitmapImage(unsigned int width, unsigned int height, Pixel::Format pixelformat, LoadPolicy loadPol, ReleasePolicy releasePol) -: Image(loadPol, releasePol), +BitmapImage::BitmapImage(unsigned int width, unsigned int height, Pixel::Format pixelformat, ReleasePolicy releasePol) +: Image(releasePol), mIsDataExternal(false) { ThreadLocalStorage& tls = ThreadLocalStorage::Get(); @@ -67,7 +67,7 @@ BitmapImage::BitmapImage(unsigned int width, unsigned int height, Pixel::Format } BitmapImage::BitmapImage(PixelBuffer* pixBuf, unsigned int width, unsigned int height, Pixel::Format pixelformat, unsigned int stride, ReleasePolicy releasePol) -: Image(ImageLoadPolicyDefault, releasePol), +: Image(releasePol), mIsDataExternal(true) { ThreadLocalStorage& tls = ThreadLocalStorage::Get(); @@ -198,7 +198,7 @@ void BitmapImage::Disconnect() --mConnectionCount; - if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused) + if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::UNUSED) { mBitmapCached = mResourceClient->GetBitmap(mTicket); // release image memory when it's not visible anymore (decrease ref. count of texture) diff --git a/dali/internal/event/images/bitmap-image-impl.h b/dali/internal/event/images/bitmap-image-impl.h index b918635..41cba92 100644 --- a/dali/internal/event/images/bitmap-image-impl.h +++ b/dali/internal/event/images/bitmap-image-impl.h @@ -53,14 +53,12 @@ public: * @param [in] width image width in pixels * @param [in] height image height in pixels * @param [in] pixelformat the pixel format (rgba 32 bit by default) - * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created). * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive). */ static BitmapImagePtr New( unsigned int width, unsigned int height, Pixel::Format pixelformat, - LoadPolicy loadPol=ImageLoadPolicyDefault, - ReleasePolicy releasePol=ImageReleasePolicyDefault); + ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ); /** * Create a new BitmapImage, which uses external data source. @@ -81,7 +79,7 @@ public: unsigned int height, Pixel::Format pixelformat, unsigned int stride, - ReleasePolicy releasePol=ImageReleasePolicyDefault ); + ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ); /** * Create a new BitmapImage. @@ -92,14 +90,12 @@ public: * @param [in] width image width in pixels * @param [in] height image height in pixels * @param [in] pixelformat the pixel format (rgba 32 bit by default) - * @param [in] loadPol optionally delay loading until it used (default: immediate loading) * @param [in] releasePol optionally release memory when image is not visible on screen (default: keep image data until Image object is alive). */ BitmapImage(unsigned int width, unsigned int height, Pixel::Format pixelformat, - LoadPolicy loadPol=ImageLoadPolicyDefault, - ReleasePolicy releasePol=ImageReleasePolicyDefault); + ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT); /** * Create a new BitmapImage, which uses external data source. @@ -120,7 +116,7 @@ public: unsigned int height, Pixel::Format pixelformat, unsigned int stride, - ReleasePolicy releasePol=ImageReleasePolicyDefault); + ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT); protected: /** diff --git a/dali/internal/event/images/encoded-buffer-image-impl.h b/dali/internal/event/images/encoded-buffer-image-impl.h index 0197e46..ed43724 100644 --- a/dali/internal/event/images/encoded-buffer-image-impl.h +++ b/dali/internal/event/images/encoded-buffer-image-impl.h @@ -52,7 +52,7 @@ private: /** * Construct using the supplied load policy. */ - EncodedBufferImage(ReleasePolicy releasePol=ImageReleasePolicyDefault) : Image( Dali::Image::Immediate, releasePol ) {} + EncodedBufferImage( ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ) : Image( releasePol ) {} public: /** @@ -72,7 +72,7 @@ public: static EncodedBufferImagePtr New(const uint8_t * const encodedImage, const std::size_t encodedImageByteCount, const ImageAttributes& attributes, - const ReleasePolicy releasePol=Dali::Image::Never); + const ReleasePolicy releasePol=Dali::Image::NEVER); }; } // namespace Internal diff --git a/dali/internal/event/images/frame-buffer-image-impl.cpp b/dali/internal/event/images/frame-buffer-image-impl.cpp index 8735abb..2a9d279 100644 --- a/dali/internal/event/images/frame-buffer-image-impl.cpp +++ b/dali/internal/event/images/frame-buffer-image-impl.cpp @@ -60,16 +60,15 @@ FrameBufferImagePtr FrameBufferImage::New( NativeImage& nativeImage, ReleasePol } FrameBufferImage::FrameBufferImage(unsigned int width, unsigned int height, Pixel::Format pixelFormat, ReleasePolicy releasePolicy) -: Image(Dali::Image::Immediate, releasePolicy), +: Image(releasePolicy), mPixelFormat(pixelFormat) { mWidth = width; mHeight = height; } - FrameBufferImage::FrameBufferImage( NativeImage& nativeImage ) -: Image(Dali::Image::Immediate), +: Image(), mNativeImage(&nativeImage), mPixelFormat(nativeImage.GetPixelFormat()) { @@ -77,9 +76,8 @@ FrameBufferImage::FrameBufferImage( NativeImage& nativeImage ) mHeight = nativeImage.GetHeight(); } - FrameBufferImage::FrameBufferImage( NativeImage& nativeImage, ReleasePolicy releasePolicy ) -: Image(Dali::Image::Immediate, releasePolicy), +: Image(releasePolicy), mNativeImage(&nativeImage), mPixelFormat(nativeImage.GetPixelFormat()) { @@ -120,7 +118,7 @@ void FrameBufferImage::Disconnect() DALI_ASSERT_DEBUG(mConnectionCount > 0); --mConnectionCount; - if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::Unused) + if (mConnectionCount == 0 && mReleasePolicy == Dali::Image::UNUSED) { // release image memory when it's not visible anymore (decrease ref. count of texture) mTicket->RemoveObserver(*this); diff --git a/dali/internal/event/images/image-factory.cpp b/dali/internal/event/images/image-factory.cpp index 66a1c64..34bdbd2 100644 --- a/dali/internal/event/images/image-factory.cpp +++ b/dali/internal/event/images/image-factory.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -402,7 +403,7 @@ ResourceTicketPtr ImageFactory::IssueLoadRequest( const std::string& filename, c else { // query image size from file if NULL was provided - Vector2 size = Dali::Image::GetImageSize( filename ); + Vector2 size = Dali::ResourceImage::GetImageSize( filename ); attributes.SetSize( size.width, size.height ); } diff --git a/dali/internal/event/images/image-impl.cpp b/dali/internal/event/images/image-impl.cpp index 713dc6d..78cf0d3 100644 --- a/dali/internal/event/images/image-impl.cpp +++ b/dali/internal/event/images/image-impl.cpp @@ -26,8 +26,6 @@ #include #include #include -#include -#include #include using namespace Dali::Integration; @@ -41,63 +39,10 @@ namespace Internal namespace { -BaseHandle CreateImage() -{ - ImagePtr image = Image::New(); - return Dali::Image(image.Get()); -} - -TypeRegistration mType( typeid(Dali::Image), typeid(Dali::BaseHandle), CreateImage ); - -Dali::SignalConnectorType signalConnector1(mType, Dali::Image::SIGNAL_IMAGE_LOADING_FINISHED, &Image::DoConnectSignal); -Dali::SignalConnectorType signalConnector2(mType, Dali::Image::SIGNAL_IMAGE_UPLOADED, &Image::DoConnectSignal); - -} - -Image::Image( LoadPolicy loadPol, ReleasePolicy releasePol ) -: mImageFactory(ThreadLocalStorage::Get().GetImageFactory()), - mWidth(0), - mHeight(0), - mConnectionCount(0), - mLoadPolicy(loadPol), - mReleasePolicy(releasePol) -{ -} - -ImagePtr Image::New() -{ - ImagePtr image = new Image; - image->Initialize(); - return image; -} +TypeRegistration mType( typeid(Dali::Image), typeid(Dali::BaseHandle), NULL ); -ImagePtr Image::New( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol ) -{ - ImagePtr image; - if( IsNinePatchFileName(filename) ) - { - image = NinePatchImage::New( filename, attributes, loadPol, releasePol ); - } - else - { - image = new Image( loadPol, releasePol ); - image->Initialize(); - - // consider the requested size as natural size, 0 means we don't (yet) know it - image->mWidth = attributes.GetWidth(); - image->mHeight = attributes.GetHeight(); - image->mRequest = image->mImageFactory.RegisterRequest( filename, &attributes ); - - if( Dali::Image::Immediate == loadPol ) - { - // Trigger loading of the image on a as soon as it can be done - image->mTicket = image->mImageFactory.Load( *image->mRequest.Get() ); - image->mTicket->AddObserver( *image ); - } - } - DALI_LOG_SET_OBJECT_STRING( image, filename ); +Dali::SignalConnectorType signalConnector2(mType, Dali::Image::SIGNAL_IMAGE_UPLOADED, &Image::DoConnectSignal); - return image; } ImagePtr Image::New( NativeImage& nativeImg ) @@ -118,34 +63,13 @@ ImagePtr Image::New( NativeImage& nativeImg ) return image; } -Image::~Image() -{ - if( mTicket ) - { - mTicket->RemoveObserver( *this ); - if( Stage::IsInstalled() ) - { - mImageFactory.ReleaseTicket( mTicket.Get() ); - } - } - - if( Stage::IsInstalled() ) - { - UnregisterObject(); - } -} - 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) + if(Dali::Image::SIGNAL_IMAGE_UPLOADED == signalName) { image->UploadedSignal().Connect( tracker, functor ); } @@ -165,40 +89,14 @@ ResourceId Image::GetResourceId() const return ret; } -const Dali::ImageAttributes& Image::GetAttributes() const -{ - if( mTicket ) - { - return mImageFactory.GetActualAttributes( mTicket ); - } - else - { - return mImageFactory.GetRequestAttributes( mRequest ); - } -} - -const std::string& Image::GetFilename() const -{ - return mImageFactory.GetRequestPath( mRequest ); -} - -void Image::Reload() -{ - if ( mRequest ) - { - ResourceTicketPtr ticket = mImageFactory.Reload( *mRequest.Get() ); - SetTicket( ticket.Get() ); - } -} - void Image::ResourceLoadingFailed(const ResourceTicket& ticket) { - mLoadingFinished.Emit( Dali::Image( this ) ); + // do nothing } void Image::ResourceLoadingSucceeded(const ResourceTicket& ticket) { - mLoadingFinished.Emit( Dali::Image( this ) ); + // do nothing } void Image::ResourceUploaded(const ResourceTicket& ticket) @@ -218,172 +116,46 @@ void Image::ResourceSavingFailed( const ResourceTicket& ticket ) unsigned int Image::GetWidth() const { - // if width is 0, it means we've not yet loaded the image - if( 0u == mWidth ) - { - Size size; - mImageFactory.GetImageSize( mRequest, mTicket, size ); - mWidth = size.width; - // The app will probably ask for the height immediately, so don't waste the synchronous file IO that ImageFactory may have just done: - DALI_ASSERT_DEBUG( 0 == mHeight || unsigned(size.height) == mHeight ); - if( 0 == mHeight ) - { - mHeight = size.height; - } - } return mWidth; } unsigned int Image::GetHeight() const { - if( 0u == mHeight ) - { - Size size; - mImageFactory.GetImageSize( mRequest, mTicket, size ); - mHeight = size.height; - DALI_ASSERT_DEBUG( 0 == mWidth || unsigned(size.width) == mWidth ); - if( 0 == mWidth ) - { - mWidth = size.width; - } - } return mHeight; } Vector2 Image::GetNaturalSize() const { - Vector2 naturalSize(mWidth, mHeight); - if( 0u == mWidth || 0u == mHeight ) - { - mImageFactory.GetImageSize( mRequest, mTicket, naturalSize ); - mWidth = naturalSize.width; - mHeight = naturalSize.height; - } - return naturalSize; + return Vector2( mWidth, mHeight ); } -void Image::Connect() +Image::Image( ReleasePolicy releasePol ) +: mWidth( 0 ), + mHeight( 0 ), + mConnectionCount( 0 ), + mReleasePolicy( releasePol ) { - ++mConnectionCount; - - if( mConnectionCount == 1 ) - { - // ticket was thrown away when related actors went offstage or image loading on demand - if( !mTicket ) - { - DALI_ASSERT_DEBUG( mRequest.Get() ); - 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::Initialize() -{ - RegisterObject(); -} - -void Image::SetTicket( ResourceTicket* ticket ) +Image::~Image() { - if( ticket == mTicket.Get() ) - { - return; - } - if( mTicket ) { mTicket->RemoveObserver( *this ); - mImageFactory.ReleaseTicket( mTicket.Get() ); + mTicket.Reset(); } - if( ticket ) - { - mTicket.Reset( ticket ); - mTicket->AddObserver( *this ); - } - else + if( Stage::IsInstalled() ) { - mTicket.Reset(); + UnregisterObject(); } } -bool Image::IsNinePatchFileName( const 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 prevent - if( state == DONE ) - { - break; - } - - ++iter; - } - return match; + RegisterObject(); } - } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/images/image-impl.h b/dali/internal/event/images/image-impl.h index e870ccb..d517b8c 100644 --- a/dali/internal/event/images/image-impl.h +++ b/dali/internal/event/images/image-impl.h @@ -25,29 +25,22 @@ #include #include #include -#include -#include -#include #include #include namespace Dali { -class NativeImage; - namespace Internal { -typedef Dali::Image::LoadPolicy LoadPolicy; typedef Dali::Image::ReleasePolicy ReleasePolicy; class Image; class ImageFactory; typedef IntrusivePtr ImagePtr; -const LoadPolicy ImageLoadPolicyDefault = Dali::Image::Immediate; -const ReleasePolicy ImageReleasePolicyDefault = Dali::Image::Never; +const ReleasePolicy IMAGE_RELEASE_POLICY_DEFAULT = Dali::Image::NEVER; /** * Image represents an image resource that can be added to actors etc. @@ -56,39 +49,7 @@ const ReleasePolicy ImageReleasePolicyDefault = Dali::Image::Never; */ class Image : public BaseObject, public ResourceTicketObserver { -protected: - - /** - * A reference counted object may only be deleted by calling Unreference() - */ - virtual ~Image(); - - /** - * Constructor, with default parameters - */ - Image(LoadPolicy loadPol=ImageLoadPolicyDefault, ReleasePolicy releasePol=ImageReleasePolicyDefault); - public: - /** - * Creates a pointer to an uninitialized Image object. - * @return a pointer to a newly created object. - */ - static ImagePtr New(); - - /** - * Creates object and loads image from filesystem - * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE - * @param [in] filename the path of the image on the filesystem - * @param [in] attributes requested parameters for loading (size, scaling etc.) - * if width or height is specified as 0, the natural size will be used. - * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created). - * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive). - * @return a pointer to a newly created object. - */ - static ImagePtr New( const std::string& filename, - const Dali::ImageAttributes& attributes, - LoadPolicy loadPol=ImageLoadPolicyDefault, - ReleasePolicy releasePol=ImageReleasePolicyDefault ); /** * Creates object with already loaded NativeImage @@ -100,26 +61,11 @@ public: static ImagePtr New( NativeImage& nativeImg ); /** - * @copydoc Dali::Image::GetLoadingState() - */ - Dali::LoadingState GetLoadingState() const { return mTicket ? mTicket->GetLoadingState() : ResourceLoading; } - - /** - * @copydoc Dali::Image::GetLoadPolicy() - */ - LoadPolicy GetLoadPolicy () const { return mLoadPolicy; } - - /** * @copydoc Dali::Image::GetReleasePolicy() */ ReleasePolicy GetReleasePolicy () const { return mReleasePolicy; } /** - * @copydoc Dali::Image::LoadingFinishedSignal() - */ - Dali::Image::ImageSignalType& LoadingFinishedSignal() { return mLoadingFinished; } - - /** * @copydoc Dali::Image::UploadedSignal() */ Dali::Image::ImageSignalType& UploadedSignal() { return mUploaded; } @@ -143,16 +89,6 @@ public: ResourceId GetResourceId() const; /** - * Get the attributes of the image. - * Only to be used after the image has finished loading. - * (Ticket's LoadingSucceeded callback was called) - * Reflects the last cached values after a LoadComplete. - * If requested width or height was 0, they are replaced by concrete dimensions. - * @return a copy of the attributes - */ - const Dali::ImageAttributes& GetAttributes() const; - - /** * Get the width of the image. * Only to be used after the image has finished loading. * (Ticket's LoadingSucceeded callback was called) @@ -160,7 +96,7 @@ public: * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual. * @pre image should be loaded */ - unsigned int GetWidth() const; + virtual unsigned int GetWidth() const; /** * Get the height of the image. @@ -170,23 +106,13 @@ public: * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual. * @pre image should be loaded */ - unsigned int GetHeight() const; + virtual unsigned int GetHeight() const; /** * Return the natural size of the image. * This is the size that the loaded image will take */ - Vector2 GetNaturalSize() const; - - /** - * @copydoc Dali::Image::GetFilename() - */ - const std::string& GetFilename() const; - - /** - * @copydoc Dali::Image::Reload() - */ - void Reload(); + virtual Vector2 GetNaturalSize() const; public: // From ResourceTicketObserver @@ -220,58 +146,44 @@ public: /** * Indicates that the image is used. */ - virtual void Connect(); + virtual void Connect() {} /** * Indicates that the image is not used anymore. */ - virtual void Disconnect(); + virtual void Disconnect() {} protected: /** - * Second stage initialization + * A reference counted object may only be deleted by calling Unreference() */ - void Initialize(); - -private: + virtual ~Image(); /** - * Helper method to set new resource ticket. Stops observing current ticket if any, and starts observing - * the new one or just resets the intrusive pointer. - * @param[in] ticket pointer to new resource Ticket or NULL. + * Constructor, with default parameters */ - void SetTicket( ResourceTicket* ticket ); + Image( ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ); /** - * Helper method to determine if the filename indicates that the image has a 9 patch border. - * @param[in] filename The filename to check - * @return true if it is a 9 patch image + * Second stage initialization */ - static bool IsNinePatchFileName( const std::string& filename ); - -protected: //@TODO these should not be protected + void Initialize(); - ImageFactory& mImageFactory; +protected: - ImageFactoryCache::RequestPtr mRequest; ///< contains the initially requested attributes for image. Request is reissued when memory was released. ResourceTicketPtr mTicket; ///< smart pointer to the ticket object that gets completed when load finishes mutable unsigned int mWidth; ///< natural width of the image, needs to be mutable for lazy resolving and as the API for GetWidth is const mutable unsigned int mHeight; ///< natural height of the image, needs to be mutable for lazy resolving and as the API for GetHeight is const - unsigned int mConnectionCount; ///< number of on-stage objects using this image + unsigned int mConnectionCount; ///< number of on-stage objects using this image - LoadPolicy mLoadPolicy:2; ///< 2 bits is enough space - ReleasePolicy mReleasePolicy:2; ///< 2 bits is enough space + ReleasePolicy mReleasePolicy : 2; ///< 2 bits is enough space private: - Dali::Image::ImageSignalType mLoadingFinished; Dali::Image::ImageSignalType mUploaded; - - // Changes scope, should be at end of class - DALI_LOG_OBJECT_STRING_DECLARATION; }; } // namespace Internal diff --git a/dali/internal/event/images/nine-patch-image-impl.cpp b/dali/internal/event/images/nine-patch-image-impl.cpp index b2876a5..18d3ce9 100644 --- a/dali/internal/event/images/nine-patch-image-impl.cpp +++ b/dali/internal/event/images/nine-patch-image-impl.cpp @@ -135,15 +135,15 @@ namespace TypeRegistration mType( typeid( Dali::NinePatchImage ), typeid( Dali::Image ), NULL ); } // unnamed namespace -NinePatchImagePtr NinePatchImage::New( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol ) +NinePatchImagePtr NinePatchImage::New( const std::string& filename, const Dali::ImageAttributes& attributes, ReleasePolicy releasePol ) { - Internal::NinePatchImagePtr internal( new NinePatchImage( filename, attributes, loadPol, releasePol ) ); + Internal::NinePatchImagePtr internal( new NinePatchImage( filename, attributes, releasePol ) ); internal->Initialize(); return internal; } -NinePatchImage::NinePatchImage( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol) -: Image(Dali::Image::Immediate, Dali::Image::Never), +NinePatchImage::NinePatchImage( const std::string& filename, const Dali::ImageAttributes& attributes, ReleasePolicy releasePol) +: ResourceImage( IMAGE_LOAD_POLICY_DEFAULT, releasePol ), mParsedBorder(false) { ThreadLocalStorage& tls = ThreadLocalStorage::Get(); @@ -211,7 +211,7 @@ Internal::BitmapImagePtr NinePatchImage::CreateCroppedBitmapImage() { Pixel::Format pixelFormat = mBitmap->GetPixelFormat(); - cropped = BitmapImage::New( mWidth-2, mHeight-2, pixelFormat, Dali::Image::Immediate, Dali::Image::Never ); + cropped = BitmapImage::New( mWidth-2, mHeight-2, pixelFormat, Dali::Image::NEVER ); Integration::Bitmap::PackedPixelsProfile* srcProfile = mBitmap->GetPackedPixelsProfile(); DALI_ASSERT_DEBUG( srcProfile && "Wrong profile for source bitmap"); diff --git a/dali/internal/event/images/nine-patch-image-impl.h b/dali/internal/event/images/nine-patch-image-impl.h index 11d6c70..3974075 100644 --- a/dali/internal/event/images/nine-patch-image-impl.h +++ b/dali/internal/event/images/nine-patch-image-impl.h @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include +#include #include namespace Dali @@ -44,7 +45,7 @@ class UpdateManager; * It's image data has a border which determines stretch and fill areas * Its pixel buffer data is loaded synchronously from file. */ -class NinePatchImage : public Image +class NinePatchImage : public ResourceImage { public: @@ -54,13 +55,11 @@ public: * Dali has ownership of the buffer. * @param [in] filename File to load synchronously into buffer * @param [in] attributes Image attributes of the file - * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created). * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive). */ static NinePatchImagePtr New( const std::string& filename, const ImageAttributes& attributes, - LoadPolicy loadPol = ImageLoadPolicyDefault, - ReleasePolicy releasePol = ImageReleasePolicyDefault ); + ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ); /** * Create a new NinePatchImage @@ -68,13 +67,11 @@ public: * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE. * @param [in] filename File to load synchronously into buffer * @param [in] attributes Image attributes of the file - * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created). * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive). */ NinePatchImage( const std::string& filename, const ImageAttributes& attributes, - LoadPolicy loadPol = ImageLoadPolicyDefault, - ReleasePolicy releasePol = ImageReleasePolicyDefault ); + ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ); /** * Convert Image object to a 9 patch image object if possible. diff --git a/dali/internal/event/images/resource-image-impl.cpp b/dali/internal/event/images/resource-image-impl.cpp new file mode 100644 index 0000000..b2a937d --- /dev/null +++ b/dali/internal/event/images/resource-image-impl.cpp @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2015 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 + +// INTERNAL INCLUDES +#include +#include +#include +#include +#include +#include +#include + +using namespace Dali::Integration; + +namespace Dali +{ + +namespace Internal +{ + +namespace +{ + +BaseHandle CreateImage() +{ + ImagePtr image = ResourceImage::New(); + return Dali::Image(image.Get()); +} + +TypeRegistration mType( typeid(Dali::ResourceImage), typeid(Dali::Image), CreateImage ); + +Dali::SignalConnectorType signalConnector1(mType, Dali::ResourceImage::SIGNAL_IMAGE_LOADING_FINISHED, &ResourceImage::DoConnectSignal); + +} + +ResourceImage::ResourceImage( LoadPolicy loadPol, ReleasePolicy releasePol ) +: Image( releasePol ), + mImageFactory( ThreadLocalStorage::Get().GetImageFactory() ), + mLoadPolicy(loadPol) +{ +} + +ResourceImagePtr ResourceImage::New() +{ + ResourceImagePtr image = new ResourceImage; + image->Initialize(); + return image; +} + +ResourceImagePtr ResourceImage::New( const std::string& url, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol ) +{ + ResourceImagePtr image; + if( IsNinePatch( url ) ) + { + image = NinePatchImage::New( url, attributes, releasePol ); + } + else + { + image = new ResourceImage( loadPol, releasePol ); + image->Initialize(); + + // consider the requested size as natural size, 0 means we don't (yet) know it + image->mWidth = attributes.GetWidth(); + image->mHeight = attributes.GetHeight(); + image->mRequest = image->mImageFactory.RegisterRequest( url, &attributes ); + + if( Dali::ResourceImage::IMMEDIATE == loadPol ) + { + // Trigger loading of the image on a as soon as it can be done + image->mTicket = image->mImageFactory.Load( *image->mRequest.Get() ); + image->mTicket->AddObserver( *image ); + } + } + DALI_LOG_SET_OBJECT_STRING( image, url ); + + return image; +} + +ResourceImage::~ResourceImage() +{ + if( mTicket ) + { + mTicket->RemoveObserver( *this ); + if( Stage::IsInstalled() ) + { + mImageFactory.ReleaseTicket( mTicket.Get() ); + } + mTicket.Reset(); + } +} + +bool ResourceImage::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" ); + ResourceImage* image = static_cast(object); + + if( Dali::ResourceImage::SIGNAL_IMAGE_LOADING_FINISHED == signalName ) + { + image->LoadingFinishedSignal().Connect( tracker, functor ); + } + else if(Dali::ResourceImage::SIGNAL_IMAGE_UPLOADED == signalName) + { + image->UploadedSignal().Connect( tracker, functor ); + } + else + { + // signalName does not match any signal + connected = false; + } + + return connected; +} + +const Dali::ImageAttributes& ResourceImage::GetAttributes() const +{ + if( mTicket ) + { + return mImageFactory.GetActualAttributes( mTicket ); + } + else + { + return mImageFactory.GetRequestAttributes( mRequest ); + } +} + +const std::string& ResourceImage::GetUrl() const +{ + return mImageFactory.GetRequestPath( mRequest ); +} + +void ResourceImage::Reload() +{ + if ( mRequest ) + { + ResourceTicketPtr ticket = mImageFactory.Reload( *mRequest.Get() ); + SetTicket( ticket.Get() ); + } +} + +unsigned int ResourceImage::GetWidth() const +{ + // if width is 0, it means we've not yet loaded the image + if( 0u == mWidth ) + { + Size size; + mImageFactory.GetImageSize( mRequest, mTicket, size ); + mWidth = size.width; + // The app will probably ask for the height immediately, so don't waste the synchronous file IO that ImageFactory may have just done: + DALI_ASSERT_DEBUG( 0 == mHeight || unsigned(size.height) == mHeight ); + if( 0 == mHeight ) + { + mHeight = size.height; + } + } + return mWidth; +} + +unsigned int ResourceImage::GetHeight() const +{ + if( 0u == mHeight ) + { + Size size; + mImageFactory.GetImageSize( mRequest, mTicket, size ); + mHeight = size.height; + DALI_ASSERT_DEBUG( 0 == mWidth || unsigned(size.width) == mWidth ); + if( 0 == mWidth ) + { + mWidth = size.width; + } + } + return mHeight; +} + +Vector2 ResourceImage::GetNaturalSize() const +{ + Vector2 naturalSize(mWidth, mHeight); + if( 0u == mWidth || 0u == mHeight ) + { + mImageFactory.GetImageSize( mRequest, mTicket, naturalSize ); + mWidth = naturalSize.width; + mHeight = naturalSize.height; + } + return naturalSize; +} + +void ResourceImage::ResourceLoadingFailed(const ResourceTicket& ticket) +{ + mLoadingFinished.Emit( Dali::ResourceImage( this ) ); +} + +void ResourceImage::ResourceLoadingSucceeded(const ResourceTicket& ticket) +{ + mLoadingFinished.Emit( Dali::ResourceImage( this ) ); +} + +void ResourceImage::Connect() +{ + ++mConnectionCount; + + if( mConnectionCount == 1 ) + { + // ticket was thrown away when related actors went offstage or image loading on demand + if( !mTicket ) + { + DALI_ASSERT_DEBUG( mRequest.Get() ); + ResourceTicketPtr newTicket = mImageFactory.Load( *mRequest.Get() ); + SetTicket( newTicket.Get() ); + } + } +} + +void ResourceImage::Disconnect() +{ + if( !mTicket ) + { + return; + } + + DALI_ASSERT_DEBUG( mConnectionCount > 0 ); + --mConnectionCount; + if( mConnectionCount == 0 && mReleasePolicy == Dali::ResourceImage::UNUSED ) + { + // release image memory when it's not visible anymore (decrease ref. count of texture) + SetTicket( NULL ); + } +} + +bool ResourceImage::IsNinePatch( const std::string& url ) +{ + bool match = false; + + std::string::const_reverse_iterator iter = url.rbegin(); + enum { SUFFIX, HASH, HASH_DOT, DONE } state = SUFFIX; + while(iter < url.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 prevent + if( state == DONE ) + { + break; + } + + ++iter; + } + return match; +} + +void ResourceImage::SetTicket( ResourceTicket* ticket ) +{ + if( ticket == mTicket.Get() ) + { + return; + } + + if( mTicket ) + { + mTicket->RemoveObserver( *this ); + mImageFactory.ReleaseTicket( mTicket.Get() ); + } + + if( ticket ) + { + mTicket.Reset( ticket ); + mTicket->AddObserver( *this ); + } + else + { + mTicket.Reset(); + } +} + +} // namespace Internal + +} // namespace Dali diff --git a/dali/internal/event/images/resource-image-impl.h b/dali/internal/event/images/resource-image-impl.h new file mode 100644 index 0000000..87f87f5 --- /dev/null +++ b/dali/internal/event/images/resource-image-impl.h @@ -0,0 +1,219 @@ +#ifndef __DALI_INTERNAL_RESOURCE_IMAGE_H__ +#define __DALI_INTERNAL_RESOURCE_IMAGE_H__ + +/* + * Copyright (c) 2015 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. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include +#include +#include + +namespace Dali +{ + +namespace Internal +{ + +typedef Dali::ResourceImage::LoadPolicy LoadPolicy; + +const LoadPolicy IMAGE_LOAD_POLICY_DEFAULT = Dali::ResourceImage::IMMEDIATE; + +class ResourceImage; +typedef IntrusivePtr ResourceImagePtr; + +/** + * ResourceImage is an image loaded using a URL, it is an image resource that can be added to actors etc. + */ +class ResourceImage : public Image +{ +public: + + /** + * Creates a pointer to an uninitialized Image object. + * @return a pointer to a newly created object. + */ + static ResourceImagePtr New(); + + /** + * Creates object and loads image from filesystem + * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE + * @param [in] url The URL of the image file. + * @param [in] attributes requested parameters for loading (size, scaling etc.) + * if width or height is specified as 0, the natural size will be used. + * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created). + * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive). + * @return a pointer to a newly created object. + */ + static ResourceImagePtr New( const std::string& url, + const Dali::ImageAttributes& attributes, + LoadPolicy loadPol = IMAGE_LOAD_POLICY_DEFAULT, + ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ); + + /** + * @copydoc Dali::ResourceImage::GetLoadingState() + */ + Dali::LoadingState GetLoadingState() const { return mTicket ? mTicket->GetLoadingState() : ResourceLoading; } + + /** + * @copydoc Dali::ResourceImage::GetLoadPolicy() + */ + LoadPolicy GetLoadPolicy () const { return mLoadPolicy; } + + /** + * @copydoc Dali::ResourceImage::LoadingFinishedSignal() + */ + Dali::ResourceImage::ResourceImageSignal& LoadingFinishedSignal() { return mLoadingFinished; } + + /** + * Connects a callback function with the object's signals. + * @param[in] object The object providing the signal. + * @param[in] tracker Used to disconnect the signal. + * @param[in] signalName The signal to connect to. + * @param[in] functor A newly allocated FunctorDelegate. + * @return True if the signal was connected. + * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor. + */ + static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ); + + /** + * Get the attributes of the image. + * Only to be used after the image has finished loading. + * (Ticket's LoadingSucceeded callback was called) + * Reflects the last cached values after a LoadComplete. + * If requested width or height was 0, they are replaced by concrete dimensions. + * @return a copy of the attributes + */ + const Dali::ImageAttributes& GetAttributes() const; + + /** + * @copydoc Dali::ResourceImage::GetUrl() + */ + const std::string& GetUrl() const; + + /** + * @copydoc Dali::ResourceImage::Reload() + */ + void Reload(); + + /** + * @copydoc Dali::Image::GetWidth() + */ + virtual unsigned int GetWidth() const; + + /** + * @copydoc Dali::Image::GetWidth() + */ + virtual unsigned int GetHeight() const; + + /** + * @copydoc Dali::Internal::Image::GetNaturalSize() + */ + virtual Vector2 GetNaturalSize() const; + + /** + * Indicates that the image is used. + */ + virtual void Connect(); + + /** + * Indicates that the image is not used anymore. + */ + virtual void Disconnect(); + +public: // From ResourceTicketObserver + + /** + * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingFailed() + */ + virtual void ResourceLoadingFailed(const ResourceTicket& ticket); + + /** + * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingSucceeded() + */ + virtual void ResourceLoadingSucceeded(const ResourceTicket& ticket); + +protected: + + /** + * A reference counted object may only be deleted by calling Unreference() + */ + virtual ~ResourceImage(); + + /** + * Constructor, with default parameters + */ + ResourceImage( LoadPolicy loadPol = IMAGE_LOAD_POLICY_DEFAULT, ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT ); + +private: + + /** + * Helper method to determine if the filename indicates that the image has a 9 patch border. + * @param [in] url The URL of the image file. + * @return true if it is a 9 patch image + */ + static bool IsNinePatch( const std::string& url ); + + /** + * Helper method to set new resource ticket. Stops observing current ticket if any, and starts observing + * the new one or just resets the intrusive pointer. + * @param[in] ticket pointer to new resource Ticket or NULL. + */ + void SetTicket( ResourceTicket* ticket ); + +private: + + ImageFactory& mImageFactory; + + ImageFactoryCache::RequestPtr mRequest; ///< contains the initially requested attributes for image. Request is reissued when memory was released. + + Dali::ResourceImage::ResourceImageSignal mLoadingFinished; + + LoadPolicy mLoadPolicy : 2; ///< 2 bits is enough space + + // Changes scope, should be at end of class + DALI_LOG_OBJECT_STRING_DECLARATION; +}; + +} // namespace Internal + +/** + * Helper methods for public API. + */ +inline Internal::ResourceImage& GetImplementation(Dali::ResourceImage& image) +{ + DALI_ASSERT_ALWAYS( image && "Image handle is empty" ); + + BaseObject& handle = image.GetBaseObject(); + + return static_cast(handle); +} + +inline const Internal::ResourceImage& GetImplementation(const Dali::ResourceImage& image) +{ + DALI_ASSERT_ALWAYS( image && "Image handle is empty" ); + + const BaseObject& handle = image.GetBaseObject(); + + return static_cast(handle); +} + +} // namespace Dali +#endif // __DALI_INTERNAL_RESOURCE_IMAGE_H__ diff --git a/dali/internal/event/modeling/model-data-impl.cpp b/dali/internal/event/modeling/model-data-impl.cpp index 5f90d7f..48c9ff6 100644 --- a/dali/internal/event/modeling/model-data-impl.cpp +++ b/dali/internal/event/modeling/model-data-impl.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -255,19 +256,19 @@ void ModelData::Unpack( ResourceClient& resourceClient ) const std::string& diffuseFileName = material.GetDiffuseFileName(); if( ! diffuseFileName.empty() ) { - material.SetDiffuseTexture( Dali::Image::New( diffuseFileName ) ); + material.SetDiffuseTexture( Dali::ResourceImage::New( diffuseFileName ) ); } const std::string& opacityFileName = material.GetOpacityTextureFileName(); if( ! opacityFileName.empty() ) { - material.SetOpacityTexture( Dali::Image::New( opacityFileName ) ); + material.SetOpacityTexture( Dali::ResourceImage::New( opacityFileName ) ); } const std::string& normalMapFileName = material.GetNormalMapFileName(); if( ! normalMapFileName.empty() ) { - material.SetNormalMap( Dali::Image::New( normalMapFileName ) ); + material.SetNormalMap( Dali::ResourceImage::New( normalMapFileName ) ); } } diff --git a/dali/internal/file.list b/dali/internal/file.list index fd31a2b..9cd4cfe 100644 --- a/dali/internal/file.list +++ b/dali/internal/file.list @@ -81,6 +81,7 @@ internal_src_files = \ $(internal_src_dir)/event/images/image-factory-cache.cpp \ $(internal_src_dir)/event/images/nine-patch-image-impl.cpp \ $(internal_src_dir)/event/images/emoji-factory.cpp \ + $(internal_src_dir)/event/images/resource-image-impl.cpp \ $(internal_src_dir)/event/modeling/animatable-mesh-impl.cpp \ $(internal_src_dir)/event/modeling/cloth-impl.cpp \ $(internal_src_dir)/event/modeling/entity-impl.cpp \ diff --git a/dali/public-api/file.list b/dali/public-api/file.list index b1365aa..633735d 100644 --- a/dali/public-api/file.list +++ b/dali/public-api/file.list @@ -67,6 +67,7 @@ public_api_src_files = \ $(public_api_src_dir)/images/encoded-buffer-image.cpp \ $(public_api_src_dir)/images/nine-patch-image.cpp \ $(public_api_src_dir)/images/glyph-image.cpp \ + $(public_api_src_dir)/images/resource-image.cpp \ $(public_api_src_dir)/math/angle-axis.cpp \ $(public_api_src_dir)/math/compile-time-math.cpp \ $(public_api_src_dir)/math/degree.cpp \ @@ -219,7 +220,8 @@ public_api_core_images_header_files = \ $(public_api_src_dir)/images/image-attributes.h \ $(public_api_src_dir)/images/native-image.h \ $(public_api_src_dir)/images/nine-patch-image.h \ - $(public_api_src_dir)/images/pixel.h + $(public_api_src_dir)/images/pixel.h \ + $(public_api_src_dir)/images/resource-image.h public_api_core_math_header_files = \ $(public_api_src_dir)/math/angle-axis.h \ diff --git a/dali/public-api/images/bitmap-image.cpp b/dali/public-api/images/bitmap-image.cpp index 862073b..4f8ef6a 100644 --- a/dali/public-api/images/bitmap-image.cpp +++ b/dali/public-api/images/bitmap-image.cpp @@ -57,7 +57,7 @@ BitmapImage& BitmapImage::operator=(const BitmapImage& rhs) const BitmapImage BitmapImage::WHITE() { - Internal::BitmapImage* internal = new Internal::BitmapImage(1,1,Pixel::RGBA8888, Immediate, Never); + Internal::BitmapImage* internal = new Internal::BitmapImage(1,1,Pixel::RGBA8888, Dali::Image::NEVER); PixelBuffer* pBuf = internal->GetBuffer(); pBuf[0] = pBuf[1] = pBuf[2] = pBuf[3] = 0xFF; return BitmapImage(internal); @@ -72,12 +72,12 @@ BitmapImage BitmapImage::New(unsigned int width, unsigned int height, Pixel::For return BitmapImage(internal.Get()); } -BitmapImage BitmapImage::New(unsigned int width, unsigned int height, Pixel::Format pixelformat, LoadPolicy loadPol, ReleasePolicy releasePol) +BitmapImage BitmapImage::New(unsigned int width, unsigned int height, Pixel::Format pixelformat, ReleasePolicy releasePol) { DALI_ASSERT_ALWAYS( 0u != width && "Invalid BitmapImage width requested" ); DALI_ASSERT_ALWAYS( 0u != height && "Invalid BitmapImage height requested" ); - Internal::BitmapImagePtr internal = Internal::BitmapImage::New(width, height, pixelformat, loadPol, releasePol); + Internal::BitmapImagePtr internal = Internal::BitmapImage::New(width, height, pixelformat, releasePol); return BitmapImage(internal.Get()); } diff --git a/dali/public-api/images/bitmap-image.h b/dali/public-api/images/bitmap-image.h index 2f32ec7..59febaf 100644 --- a/dali/public-api/images/bitmap-image.h +++ b/dali/public-api/images/bitmap-image.h @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include #include +#include #include namespace Dali @@ -68,7 +69,7 @@ public: /** * @brief Constructor which creates an uninitialized BitmapImage object. * - * Use Image::New(...) to create an initialised object. + * Use BitmapImage::New(...) to create an initialised object. */ BitmapImage(); @@ -103,14 +104,12 @@ public: * @param [in] width Image width in pixels * @param [in] height Image height in pixels * @param [in] pixelFormat The pixel format - * @param [in] loadPolicy Controls time of loading a resource from the filesystem. * @param [in] releasePolicy Optionally release memory when image is not visible on screen. * @return a handle to a new instance of BitmapImage */ static BitmapImage New(unsigned int width, unsigned int height, Pixel::Format pixelFormat, - LoadPolicy loadPolicy, ReleasePolicy releasePolicy); /** diff --git a/dali/public-api/images/encoded-buffer-image.cpp b/dali/public-api/images/encoded-buffer-image.cpp index 32932b1..632a274 100644 --- a/dali/public-api/images/encoded-buffer-image.cpp +++ b/dali/public-api/images/encoded-buffer-image.cpp @@ -45,7 +45,7 @@ EncodedBufferImage EncodedBufferImage::New(const uint8_t * const encodedImage, c EncodedBufferImage EncodedBufferImage::New(const uint8_t * const encodedImage, const std::size_t encodedImageByteCount) { ImageAttributes attributes; - Internal::EncodedBufferImagePtr internal = Internal::EncodedBufferImage::New(encodedImage, encodedImageByteCount, attributes, Dali::Image::Never); + Internal::EncodedBufferImagePtr internal = Internal::EncodedBufferImage::New(encodedImage, encodedImageByteCount, attributes, Dali::Image::NEVER); EncodedBufferImage image( internal.Get() ); return image; } diff --git a/dali/public-api/images/encoded-buffer-image.h b/dali/public-api/images/encoded-buffer-image.h index 9afe0a9..885f092 100644 --- a/dali/public-api/images/encoded-buffer-image.h +++ b/dali/public-api/images/encoded-buffer-image.h @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -87,7 +88,7 @@ public: * used once all actors using it have gone off-stage. * @return A handle to a newly allocated object. */ - static EncodedBufferImage New(const uint8_t * const encodedImage, std::size_t encodedImageByteCount, const ImageAttributes& attributes, ReleasePolicy releasePol = Image::Never); + static EncodedBufferImage New(const uint8_t * const encodedImage, std::size_t encodedImageByteCount, const ImageAttributes& attributes, ReleasePolicy releasePol = Image::NEVER); /** * @brief Create an initialised image object from an encoded image buffer in memory. diff --git a/dali/public-api/images/frame-buffer-image.cpp b/dali/public-api/images/frame-buffer-image.cpp index 6d2ea36..32f3507 100644 --- a/dali/public-api/images/frame-buffer-image.cpp +++ b/dali/public-api/images/frame-buffer-image.cpp @@ -58,7 +58,7 @@ FrameBufferImage FrameBufferImage::New(unsigned int width, unsigned int height, (0 == width) ? stageSize.width : width, (0 == height) ? stageSize.height : height, pixelformat, - Dali::Image::Never); + Dali::Image::NEVER); return FrameBufferImage(internal.Get()); } diff --git a/dali/public-api/images/frame-buffer-image.h b/dali/public-api/images/frame-buffer-image.h index bcba5c8..b5fca0b 100644 --- a/dali/public-api/images/frame-buffer-image.h +++ b/dali/public-api/images/frame-buffer-image.h @@ -20,7 +20,7 @@ // INTERNAL INCLUDES #include -#include +#include namespace Dali { diff --git a/dali/public-api/images/glyph-image.cpp b/dali/public-api/images/glyph-image.cpp index b319581..1d57a64 100644 --- a/dali/public-api/images/glyph-image.cpp +++ b/dali/public-api/images/glyph-image.cpp @@ -20,6 +20,7 @@ // INTERNAL INCLUDES #include +#include #include #include #include @@ -91,7 +92,7 @@ GlyphImage GlyphImage::New( const Character& character, const TextStyle& style ) ImageAttributes attributes; attributes.SetSize( metrics.GetWidth(), metrics.GetHeight() ); - image = Image::New( DALI_EMOTICON_DIR + Internal::ThreadLocalStorage::Get().GetEmojiFactory().GetEmojiFileNameFromCharacter( character.GetImplementation().GetCharacter() ), attributes ); + image = ResourceImage::New( DALI_EMOTICON_DIR + Internal::ThreadLocalStorage::Get().GetEmojiFactory().GetEmojiFileNameFromCharacter( character.GetImplementation().GetCharacter() ), attributes ); } else { diff --git a/dali/public-api/images/image.cpp b/dali/public-api/images/image.cpp index f929c15..d371c18 100644 --- a/dali/public-api/images/image.cpp +++ b/dali/public-api/images/image.cpp @@ -19,25 +19,14 @@ #include // INTERNAL INCLUDES -#include -#include #include -#include -#include + namespace Dali { -const char* const Image::SIGNAL_IMAGE_LOADING_FINISHED = "image-loading-finished"; const char* const Image::SIGNAL_IMAGE_UPLOADED = "uploaded"; -Vector2 Image::GetImageSize(const std::string fileName) -{ - Vector2 size; - Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize(fileName, ImageAttributes::DEFAULT_ATTRIBUTES, size); - return size; -} - Image::Image() { } @@ -61,63 +50,6 @@ Image& Image::operator=(const Image& rhs) return *this; } -Image Image::New(const std::string& filename) -{ - Internal::ImagePtr internal = Internal::Image::New( filename, - Dali::ImageAttributes::DEFAULT_ATTRIBUTES ); - return Image(internal.Get()); -} - -Image Image::New(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol) -{ - Internal::ImagePtr internal = Internal::Image::New( filename, - Dali::ImageAttributes::DEFAULT_ATTRIBUTES, - loadPol, releasePol ); - return Image(internal.Get()); -} - -Image Image::New(const std::string& filename, const ImageAttributes& attributes) -{ - Internal::ImagePtr internal = Internal::Image::New(filename, attributes); - return Image(internal.Get()); -} - -Image Image::New(const std::string& filename, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol) -{ - Internal::ImagePtr internal = Internal::Image::New(filename, attributes, loadPol, releasePol); - return Image(internal.Get()); -} - -Image Image::NewDistanceField(const std::string& filename) -{ - ImageAttributes attributes = ImageAttributes::NewDistanceField(); - Internal::ImagePtr internal = Internal::Image::New(filename, attributes); - return Image(internal.Get()); -} - -Image Image::NewDistanceField(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol) -{ - ImageAttributes attributes = ImageAttributes::NewDistanceField(); - Internal::ImagePtr internal = Internal::Image::New(filename, attributes, loadPol, releasePol); - return Image(internal.Get()); -} - -Image Image::NewDistanceField(const std::string& filename, const ImageAttributes& attributes) -{ - DALI_ASSERT_DEBUG(attributes.IsDistanceField()); - - Internal::ImagePtr internal = Internal::Image::New(filename, attributes); - return Image(internal.Get()); -} - -Image Image::NewDistanceField(const std::string& filename, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol) -{ - DALI_ASSERT_DEBUG(attributes.IsDistanceField()); - - Internal::ImagePtr internal = Internal::Image::New(filename, attributes, loadPol, releasePol); - return Image(internal.Get()); -} - Image Image::New(NativeImage& nativeImg) { Internal::ImagePtr internal = Internal::Image::New(nativeImg); @@ -129,26 +61,6 @@ Image Image::DownCast( BaseHandle handle ) return Image( dynamic_cast(handle.GetObjectPtr()) ); } -LoadingState Image::GetLoadingState() const -{ - return GetImplementation(*this).GetLoadingState(); -} - -ImageAttributes Image::GetAttributes() const -{ - return GetImplementation(*this).GetAttributes(); -} - -std::string Image::GetFilename() const -{ - return GetImplementation(*this).GetFilename(); -} - -Image::LoadPolicy Image::GetLoadPolicy() const -{ - return GetImplementation(*this).GetLoadPolicy(); -} - Image::ReleasePolicy Image::GetReleasePolicy() const { return GetImplementation(*this).GetReleasePolicy(); @@ -164,16 +76,6 @@ unsigned int Image::GetHeight() const return GetImplementation(*this).GetHeight(); } -void Image::Reload() -{ - GetImplementation(*this).Reload(); -} - -Image::ImageSignalType& Image::LoadingFinishedSignal() -{ - return GetImplementation(*this).LoadingFinishedSignal(); -} - Image::ImageSignalType& Image::UploadedSignal() { return GetImplementation(*this).UploadedSignal(); diff --git a/dali/public-api/images/image.h b/dali/public-api/images/image.h index 3da6e2a..1ff0273 100644 --- a/dali/public-api/images/image.h +++ b/dali/public-api/images/image.h @@ -22,14 +22,11 @@ #include // INTERNAL INCLUDES -#include -#include #include #include namespace Dali { -struct Vector2; namespace Internal DALI_INTERNAL { @@ -37,62 +34,24 @@ class Image; } class NativeImage; -class ImageAttributes; - /** * @brief An Image object represents an image resource that can be added to ImageActors. * - * Image objects can also handle custom requests for image loading and are responsible for - * the underlying resource's lifetime. - * - *

Image Loading

- * - * When the Image object is created, resource loading will be attempted unless - * the Image object is created with OnDemand loading policy or a compatible resource is found in cache. - * In case of loading images on demand, resource loading will only be attempted if the associated ImageActor - * is put on Stage. - * Custom loading requests can be made by providing an ImageAttributes object to Image::New(). + * Image objects can be shared between ImageActors. This is practical if you have a visual element on screen + * which is repeatedly used. An example would be a button background image. + * The image resource is discarded when all ImageActors using the Image object are discarded or in case they + * were created with ReleasePolicy::Unused, taken off stage. + * Note: if a resource was shared between Image objects it exists until its last reference is gone. * - * LoadPolicies - * - Immediate: acquire image resource when creating Image object. - * - OnDemand: only load in case the associated ImageActor is put on Stage + * Image objects are responsible for the underlying resource's lifetime. * * ReleasePolicies * - Unused: release resource once ImageActor using it is taken off stage. * - Never: keep resource alive until Image object is thrown away. * * Resolution of conflicting policies - * If the same image is created more than once with conflicting policies, LoadPolicy "Immediate" overrides "OnDemand" - * and ReleasePolicy "Never" overrides "Unused". - * - * Custom load requests - * Size, scaling mode, orientation compensation can be set when requesting an image resource. - * See ImageAttributes for more details. - * - * Compatible resources - * - * Before loading a new image the internal image resource cache is checked by dali. - * If there is an Image already loaded in memory and is deemed "compatible" with the requested Image, - * that resource is reused. - * This happens for example if a loaded image exists with the same filename, and the difference between both - * of the dimensions is less than 50%. - * - * Reloading Images - * - * The same request used on creating the Image is re-issued when reloading Images. - * If the file changed since the last load operation, this might result in a different resource. - * Reload only takes effect if both of these conditions apply: - * - The Image has already finished loading - * - The Image is either on Stage or using Immediate load policy - * - *

Image resource lifetime

- * - * Image objects can be shared between ImageActors. This is practical if you have a visual element on screen - * which is repeatedly used. An example would be a button background image. - * The image resource is discarded when all ImageActors using the Image object are discarded or in case they - * were created with ReleasePolicy::Unused, taken off stage. - * Note: if a resource was shared between Image objects it exists until its last reference is gone. + * If the same image is created more than once with conflicting policies, ReleasePolicy "Never" overrides "Unused". * */ class DALI_IMPORT_API Image : public BaseHandle @@ -103,21 +62,12 @@ public: */ /** - * @brief LoadPolicy controls the way images are loaded into memory. - */ - enum LoadPolicy - { - Immediate, ///< load image once it is created (default) - OnDemand ///< delay loading until the image is being used (a related actor is added to Stage) - }; - - /** * @brief ReleasePolicy controls the way images are deleted from memory. */ enum ReleasePolicy { - Unused, ///< release resource once image is not in use anymore (eg. all actors using it become offstage). Reload when resource is required again. - Never ///< keep image data for the lifetime of the object. (default) + UNUSED, ///< release resource once image is not in use anymore (eg. all actors using it become offstage). Reload when resource is required again. + NEVER ///< keep image data for the lifetime of the object. (default) }; /** @@ -126,27 +76,14 @@ public: typedef Signal< void (Image) > ImageSignalType; // Signal Names - static const char* const SIGNAL_IMAGE_LOADING_FINISHED; ///< Name of LoadingFinished signal static const char* const SIGNAL_IMAGE_UPLOADED; ///< Name of Uploaded signal public: /** - * @brief Get the size of an image from disk. - * - * This function will read the header info from file on disk and is - * synchronous, so it should not be used repeatedly or in tight - * loops. - * - * @param [in] filename of the image file to use. - * @return The width and height in pixels of the image. - */ - static Vector2 GetImageSize(const std::string filename); - - /** - * @brief Constructor which creates an empty Image object. + * @brief Constructor which creates an empty Image handle. * - * Use Image::New(...) to create an initialised object. + * Use Image::New(...) to create an initialised handle. */ Image(); @@ -173,82 +110,6 @@ public: Image& operator=(const Image& rhs); /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @return A handle to a newly allocated object - */ - static Image New(const std::string& filename); - - /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @param [in] loadPol The LoadPolicy to apply when loading the image resource. - * @param [in] releasePol The ReleasePolicy to apply to Image. - * @return A handle to a newly allocated object - */ - static Image New(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol); - - /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @param [in] attributes Requested parameters for loading (size, scaling etc.). - * @return A handle to a newly allocated object - */ - static Image New(const std::string& filename, const ImageAttributes& attributes); - - /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @param [in] attributes Requested parameters for loading (size, scaling etc.). - * @param [in] loadPol The LoadPolicy to apply when loading the image resource. - * @param [in] releasePol The ReleasePolicy to apply to Image. - * @return A handle to a newly allocated object - */ - static Image New(const std::string& filename, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol); - - /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @return A handle to a newly allocated object - */ - static Image NewDistanceField(const std::string& filename); - - /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @param [in] loadPol The LoadPolicy to apply when loading the image resource. - * @param [in] releasePol The ReleasePolicy to apply to Image. - * @return A handle to a newly allocated object - */ - static Image NewDistanceField(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol); - - /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @param [in] attributes The minimum search radius to check for differing pixels - * @return A handle to a newly allocated object - */ - static Image NewDistanceField(const std::string& filename, const ImageAttributes& attributes ); - - /** - * @brief Create an initialised image object. - * - * @param [in] filename The filename of the image file to use. - * @param [in] attributes The minimum search radius to check for differing pixels - * @param [in] loadPol The LoadPolicy to apply when loading the image resource. - * @param [in] releasePol The ReleasePolicy to apply to Image. - * @return A handle to a newly allocated object - */ - static Image NewDistanceField(const std::string& filename, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol); - - /** * @brief Creates object with already loaded NativeImage. * * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE @@ -269,42 +130,11 @@ public: static Image DownCast( BaseHandle handle ); /** - * @brief Query whether the image data has loaded. - * - * The asynchronous loading begins when the Image object is created. - * After the Image object is discarded, the image data will be released from memory. - * @return The loading state, either Loading, Success or Failed. - */ - LoadingState GetLoadingState() const; - - /** - * @brief Returns the filename of the image if the image is created from a file. - * - * @return the image filename or empty string - */ - std::string GetFilename() const; - - /** - * @brief Return load policy. - * - * @return resource load policy - */ - LoadPolicy GetLoadPolicy () const; - - /** * @brief Return resource release policy. * * @return resource release policy */ - ReleasePolicy GetReleasePolicy () const; - - /** - * @brief Reload image from filesystem. - * - * The set ImageAttributes are used when requesting the image again. - * @note if Image is offstage and OnDemand policy is set, reload request is ignored. - */ - void Reload(); + ReleasePolicy GetReleasePolicy() const; /** * @brief Returns the width of the image. @@ -324,28 +154,9 @@ public: */ unsigned int GetHeight() const; - /** - * @brief Get the attributes of an image. - * - * Only to be used after the image has finished loading. - * (Ticket's LoadingSucceeded callback was called) - * The returned value will reflect the true image dimensions once the asynchronous loading has finished. - * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual. - * @pre image should be loaded - * @return a copy of the attributes - */ - ImageAttributes GetAttributes() const; - public: // Signals /** - * @brief Emitted when the image data loads successfully, or when the loading fails. - * - * @return A signal object to Connect() with. - */ - ImageSignalType& LoadingFinishedSignal(); - - /** * @brief This signal is emitted when the image data gets uploaded to GL. * * It Will be sent after an actor using the image is added to diff --git a/dali/public-api/images/nine-patch-image.cpp b/dali/public-api/images/nine-patch-image.cpp index 5d87920..8d13b54 100644 --- a/dali/public-api/images/nine-patch-image.cpp +++ b/dali/public-api/images/nine-patch-image.cpp @@ -32,7 +32,7 @@ NinePatchImage::NinePatchImage() } NinePatchImage::NinePatchImage(Internal::NinePatchImage* internal) -: Image(internal) +: ResourceImage(internal) { } @@ -41,7 +41,7 @@ NinePatchImage::~NinePatchImage() } NinePatchImage::NinePatchImage(const NinePatchImage& handle) -: Image(handle) +: ResourceImage(handle) { } @@ -55,7 +55,7 @@ NinePatchImage NinePatchImage::New( const std::string& filename ) { ImageAttributes defaultAttrs; - Internal::NinePatchImagePtr internal = Internal::NinePatchImage::New( filename, defaultAttrs, Image::Immediate, Image::Never ); + Internal::NinePatchImagePtr internal = Internal::NinePatchImage::New( filename, defaultAttrs, Image::NEVER ); return NinePatchImage(internal.Get()); } diff --git a/dali/public-api/images/nine-patch-image.h b/dali/public-api/images/nine-patch-image.h index d15c6dd..2facc05 100644 --- a/dali/public-api/images/nine-patch-image.h +++ b/dali/public-api/images/nine-patch-image.h @@ -20,7 +20,7 @@ // INTERNAL INCLUDES #include -#include +#include #include #include @@ -47,7 +47,7 @@ class NinePatchImage; * to use the cropped BitmapImage - if you don't retain a handle to this object, it will * be automatically destroyed. */ -class DALI_IMPORT_API NinePatchImage : public Image +class DALI_IMPORT_API NinePatchImage : public ResourceImage { public: /** diff --git a/dali/public-api/images/resource-image.cpp b/dali/public-api/images/resource-image.cpp new file mode 100644 index 0000000..9f4ed32 --- /dev/null +++ b/dali/public-api/images/resource-image.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2015 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 + +// INTERNAL INCLUDES +#include +#include +#include +#include +#include + +namespace Dali +{ + +const char* const ResourceImage::SIGNAL_IMAGE_LOADING_FINISHED = "image-loading-finished"; + +Vector2 ResourceImage::GetImageSize( const std::string& url ) +{ + Vector2 size; + Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( url, ImageAttributes::DEFAULT_ATTRIBUTES, size ); + return size; +} + +ResourceImage::ResourceImage() +{ +} + +ResourceImage::ResourceImage(Internal::ResourceImage* internal) : Image(internal) +{ +} + +ResourceImage::~ResourceImage() +{ +} + +ResourceImage::ResourceImage( const ResourceImage& handle ) +: Image(handle) +{ +} + +ResourceImage& ResourceImage::operator=( const ResourceImage& rhs ) +{ + BaseHandle::operator=(rhs); + return *this; +} + +ResourceImage ResourceImage::New( const std::string& url ) +{ + Internal::ResourceImagePtr internal = Internal::ResourceImage::New( url, + Dali::ImageAttributes::DEFAULT_ATTRIBUTES ); + return ResourceImage(internal.Get()); +} + +ResourceImage ResourceImage::New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol ) +{ + Internal::ResourceImagePtr internal = Internal::ResourceImage::New( url, + Dali::ImageAttributes::DEFAULT_ATTRIBUTES, + loadPol, releasePol ); + return ResourceImage(internal.Get()); +} + +ResourceImage ResourceImage::New( const std::string& url, const ImageAttributes& attributes ) +{ + Internal::ResourceImagePtr internal = Internal::ResourceImage::New( url, attributes ); + return ResourceImage(internal.Get()); +} + +ResourceImage ResourceImage::New( const std::string& url, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol ) +{ + Internal::ResourceImagePtr internal = Internal::ResourceImage::New( url, attributes, loadPol, releasePol ); + return ResourceImage(internal.Get()); +} + +ResourceImage ResourceImage::DownCast( BaseHandle handle ) +{ + return ResourceImage( dynamic_cast(handle.GetObjectPtr()) ); +} + +ResourceImage::LoadPolicy ResourceImage::GetLoadPolicy() const +{ + return GetImplementation(*this).GetLoadPolicy(); +} + +LoadingState ResourceImage::GetLoadingState() const +{ + return GetImplementation(*this).GetLoadingState(); +} + +std::string ResourceImage::GetUrl() const +{ + return GetImplementation(*this).GetUrl(); +} + +void ResourceImage::Reload() +{ + GetImplementation(*this).Reload(); +} + +ImageAttributes ResourceImage::GetAttributes() const +{ + return GetImplementation(*this).GetAttributes(); +} + +ResourceImage::ResourceImageSignal& ResourceImage::LoadingFinishedSignal() +{ + return GetImplementation(*this).LoadingFinishedSignal(); +} + +} // namespace Dali diff --git a/dali/public-api/images/resource-image.h b/dali/public-api/images/resource-image.h new file mode 100644 index 0000000..96808b3 --- /dev/null +++ b/dali/public-api/images/resource-image.h @@ -0,0 +1,251 @@ +#ifndef __DALI_RESOURCE_IMAGE_H__ +#define __DALI_RESOURCE_IMAGE_H__ + +/* + * Copyright (c) 2015 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. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include +#include +#include + +namespace Dali +{ +struct Vector2; +class ImageAttributes; + +namespace Internal DALI_INTERNAL +{ +class ResourceImage; +} + +/** + * @brief ResourceImage is an image loaded using a URL + * + *

ResourceImage Loading

+ * + * When the ResourceImage is created, resource loading will be attempted unless + * the ResourceImage is created with IMMEDIATE loading policy or a compatible resource is found in cache. + * In case of loading images ON_DEMAND, resource loading will only be attempted if the associated ImageActor + * is put on Stage. + * Custom loading requests can be made by providing an ImageAttributes object to ResourceImage::New(). + * + * LoadPolicies + * - IMMEDIATE: acquire image resource when creating ResourceImage. + * - ON_DEMAND: only load in case the associated ImageActor is put on Stage + * + * Resolution of conflicting policies + * If the same image is created more than once with conflicting policies, LoadPolicy "IMMEDIATE" overrides "ON_DEMAND". + * + * Custom load requests + * Size, scaling mode, orientation compensation can be set when requesting an image. + * See ImageAttributes for more details. + * + * Compatible resources + * + * Before loading a new ResourceImage the internal image resource cache is checked by dali. + * If there is an image already loaded in memory and is deemed "compatible" with the requested image, + * that resource is reused. + * This happens for example if a loaded image exists with the same URL, and the difference between both + * of the dimensions is less than 50%. + * + * Reloading images + * + * The same request used on creating the ResourceImage is re-issued when reloading images. + * If the file changed since the last load operation, this might result in a different resource. + * Reload only takes effect if both of these conditions apply: + * - The ResourceImage has already finished loading + * - The ResourceImage is either on Stage or using IMMEDIATE load policy + */ +class DALI_IMPORT_API ResourceImage : public Image +{ +public: + /** + * @brief Resource management options. + */ + + /** + * @brief LoadPolicy controls the way images are loaded into memory. + */ + enum LoadPolicy + { + IMMEDIATE, ///< load image once it is created (default) + ON_DEMAND ///< delay loading until the image is being used (a related actor is added to Stage) + }; + + /** + * @brief Type of signal for LoadingFinished and Uploaded. + */ + typedef Signal< void (ResourceImage) > ResourceImageSignal; + + // Signal Names + static const char* const SIGNAL_IMAGE_LOADING_FINISHED; ///< Name of LoadingFinished signal + +public: + + /** + * @brief Get the size of an image from disk. + * + * This function will read the header info from file on disk and is + * synchronous, so it should not be used repeatedly or in tight + * loops. + * + * @param [in] url The URL of the image file. + * @return The width and height in pixels of the image. + */ + static Vector2 GetImageSize( const std::string& url ); + + /** + * @brief Constructor which creates an empty ResourceImage object. + * + * Use ResourceImage::New(...) to create an initialised object. + */ + ResourceImage(); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~ResourceImage(); + + /** + * @brief This copy constructor is required for (smart) pointer semantics. + * + * @param [in] handle A reference to the copied handle + */ + ResourceImage( const ResourceImage& handle ); + + /** + * @brief This assignment operator is required for (smart) pointer semantics. + * + * @param [in] rhs A reference to the copied handle + * @return A reference to this + */ + ResourceImage& operator=( const ResourceImage& rhs ); + + /** + * @brief Create an initialised ResourceImage object. + * + * @param [in] url The URL of the image file to use. + * @return A handle to a newly allocated object + */ + static ResourceImage New( const std::string& url ); + + /** + * @brief Create an initialised ResourceImage object. + * + * @param [in] url The URL of the image file to use. + * @param [in] loadPol The LoadPolicy to apply when loading the image resource. + * @param [in] releasePol The ReleasePolicy to apply to Image. + * @return A handle to a newly allocated object + */ + static ResourceImage New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol ); + + /** + * @brief Create an initialised ResourceImage object. + * + * @param [in] url The URL of the image file to use. + * @param [in] attributes Requested parameters for loading (size, scaling etc.). + * @return A handle to a newly allocated object + */ + static ResourceImage New( const std::string& url, const ImageAttributes& attributes ); + + /** + * @brief Create an initialised ResourceImage object. + * + * @param [in] url The URL of the image file to use. + * @param [in] attributes Requested parameters for loading (size, scaling etc.). + * @param [in] loadPol The LoadPolicy to apply when loading the image resource. + * @param [in] releasePol The ReleasePolicy to apply to Image. + * @return A handle to a newly allocated object + */ + static ResourceImage New( const std::string& url, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol ); + + /** + * @brief Downcast an Object handle to ResourceImage handle. + * + * If handle points to a ResourceImage object the + * downcast produces valid handle. If not the returned handle is left uninitialized. + * @param[in] handle to An object + * @return handle to a Image object or an uninitialized handle + */ + static ResourceImage DownCast( BaseHandle handle ); + + /** + * @brief Return load policy. + * + * @return resource load policy + */ + LoadPolicy GetLoadPolicy() const; + + /** + * @brief Query whether the image data has loaded. + * + * The asynchronous loading begins when the Image object is created. + * After the Image object is discarded, the image data will be released from memory. + * @return The loading state, either Loading, Success or Failed. + */ + LoadingState GetLoadingState() const; + + /** + * @brief Returns the URL of the image. + * + * @return The URL of the image file. + */ + std::string GetUrl() const; + + /** + * @brief Reload image from filesystem. + * + * The set ImageAttributes are used when requesting the image again. + * @note if Image is offstage and OnDemand policy is set, reload request is ignored. + */ + void Reload(); + + /** + * @brief Get the attributes of an image. + * + * Only to be used after the image has finished loading. + * (Ticket's LoadingSucceeded callback was called) + * The returned value will reflect the true image dimensions once the asynchronous loading has finished. + * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual. + * @pre image should be loaded + * @return a copy of the attributes + */ + ImageAttributes GetAttributes() const; + +public: // Signals + + /** + * @brief Emitted when the image data loads successfully, or when the loading fails. + * + * @return A signal object to Connect() with. + */ + ResourceImageSignal& LoadingFinishedSignal(); + +public: // Not intended for application developers + + explicit DALI_INTERNAL ResourceImage( Internal::ResourceImage* ); +}; + +} // namespace Dali + +#endif // __DALI_RESOURCE_IMAGE_H__ diff --git a/dali/public-api/scripting/scripting.cpp b/dali/public-api/scripting/scripting.cpp index 7d95b42..3903439 100644 --- a/dali/public-api/scripting/scripting.cpp +++ b/dali/public-api/scripting/scripting.cpp @@ -20,10 +20,10 @@ // INTERNAL INCLUDES #include -#include +#include #include #include -#include +#include #include #include #include @@ -97,17 +97,17 @@ const StringEnum< Vector3 > ANCHOR_CONSTANT_TABLE[] = }; const unsigned int ANCHOR_CONSTANT_TABLE_COUNT = sizeof( ANCHOR_CONSTANT_TABLE ) / sizeof( ANCHOR_CONSTANT_TABLE[0] ); -const StringEnum< Image::LoadPolicy > IMAGE_LOAD_POLICY_TABLE[] = +const StringEnum< ResourceImage::LoadPolicy > IMAGE_LOAD_POLICY_TABLE[] = { - { "IMMEDIATE", Image::Immediate }, - { "ON_DEMAND", Image::OnDemand }, + { "IMMEDIATE", ResourceImage::IMMEDIATE }, + { "ON_DEMAND", ResourceImage::ON_DEMAND }, }; const unsigned int IMAGE_LOAD_POLICY_TABLE_COUNT = sizeof( IMAGE_LOAD_POLICY_TABLE ) / sizeof( IMAGE_LOAD_POLICY_TABLE[0] ); const StringEnum< Image::ReleasePolicy > IMAGE_RELEASE_POLICY_TABLE[] = { - { "UNUSED", Image::Unused }, - { "NEVER", Image::Never }, + { "UNUSED", Image::UNUSED }, + { "NEVER", Image::NEVER }, }; const unsigned int IMAGE_RELEASE_POLICY_TABLE_COUNT = sizeof( IMAGE_RELEASE_POLICY_TABLE ) / sizeof( IMAGE_RELEASE_POLICY_TABLE[0] ); @@ -252,8 +252,8 @@ Image NewImage( const Property::Value& map ) Image ret; std::string filename; - Image::LoadPolicy loadPolicy = Dali::Internal::ImageLoadPolicyDefault; - Image::ReleasePolicy releasePolicy = Dali::Internal::ImageReleasePolicyDefault; + ResourceImage::LoadPolicy loadPolicy = Dali::Internal::IMAGE_LOAD_POLICY_DEFAULT; + Image::ReleasePolicy releasePolicy = Dali::Internal::IMAGE_RELEASE_POLICY_DEFAULT; ImageAttributes attributes = ImageAttributes::New(); if( Property::MAP == map.GetType() ) @@ -270,7 +270,7 @@ Image NewImage( const Property::Value& map ) { DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image load-policy property is not a string" ); std::string v(map.GetValue(field).Get()); - loadPolicy = GetEnumeration< Image::LoadPolicy >( v, IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT ); + loadPolicy = GetEnumeration< ResourceImage::LoadPolicy >( v, IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT ); } field = "release-policy"; @@ -342,12 +342,11 @@ Image NewImage( const Property::Value& map ) ret = Image( new Internal::BitmapImage(attributes.GetWidth(), attributes.GetHeight(), attributes.GetPixelFormat(), - loadPolicy, releasePolicy) ); } else if("Image" == s) { - ret = Image::New(filename, attributes, loadPolicy, releasePolicy); + ret = ResourceImage::New(filename, attributes, loadPolicy, releasePolicy); } else { @@ -356,7 +355,7 @@ Image NewImage( const Property::Value& map ) } else { - ret = Image::New(filename, attributes, loadPolicy, releasePolicy); + ret = ResourceImage::New(filename, attributes, loadPolicy, releasePolicy); } } @@ -548,7 +547,7 @@ void CreatePropertyMap( Image image, Property::Map& map ) if ( image ) { - std::string imageType( "Image" ); + std::string imageType( "ResourceImage" ); // Get Type - cannot use TypeRegistry as Image is not a ProxyObject and thus, not registered if ( BitmapImage::DownCast( image ) ) @@ -561,13 +560,18 @@ void CreatePropertyMap( Image image, Property::Map& map ) } map[ "type" ] = imageType; - map[ "filename" ] = image.GetFilename(); - map[ "load-policy" ] = GetEnumerationName< Image::LoadPolicy >( image.GetLoadPolicy(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT ); map[ "release-policy" ] = GetEnumerationName< Image::ReleasePolicy >( image.GetReleasePolicy(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT ); - ImageAttributes attributes( image.GetAttributes() ); - map[ "pixel-format" ] = GetEnumerationName< Pixel::Format >( attributes.GetPixelFormat(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ); - map[ "scaling-mode" ] = GetEnumerationName< ImageAttributes::ScalingMode >( attributes.GetScalingMode(), IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT ); + ResourceImage resourceImage = ResourceImage::DownCast( image ); + if( resourceImage ) + { + map[ "filename" ] = resourceImage.GetUrl(); + map[ "load-policy" ] = GetEnumerationName< ResourceImage::LoadPolicy >( resourceImage.GetLoadPolicy(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT ); + + ImageAttributes attributes( resourceImage.GetAttributes() ); + map[ "pixel-format" ] = GetEnumerationName< Pixel::Format >( attributes.GetPixelFormat(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ); + map[ "scaling-mode" ] = GetEnumerationName< ImageAttributes::ScalingMode >( attributes.GetScalingMode(), IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT ); + } int width( image.GetWidth() ); int height( image.GetHeight() );