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
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);
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();
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();
// 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();
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();
application.GetPlatform().ResetTrace();
// Resource is reloaded
- Image image3 = Image::New( gTestImageFilename );
+ Image image3 = ResourceImage::New( gTestImageFilename );
application.SendNotification();
application.Render();
#include <dali/internal/event/resources/resource-ticket.h>
#include <dali/internal/event/resources/image-ticket.h>
#include <dali/internal/event/resources/resource-ticket-observer.h>
-#include <dali/internal/event/images/image-impl.h>
+#include <dali/internal/event/images/resource-image-impl.h>
#include <dali/internal/event/modeling/model-data-impl.h>
#include <dali/integration-api/resource-cache.h>
#include <dali/internal/render/gl-resources/texture-declarations.h>
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();
application.Render(16);
application.SendNotification();
- ImageAttributes attributes = image.GetAttributes();
-
- DALI_TEST_CHECK( attributes.GetWidth() == 16);
+ DALI_TEST_CHECK( image.GetWidth() == 16);
END_TEST;
}
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;
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);
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);
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);
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;
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;
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;
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() );
{
TestApplication application;
- Image image = Image::New( "temp" );
+ Image image = ResourceImage::New( "temp" );
Constrainable customHandle1 = Constrainable::DownCast( image );
DALI_TEST_CHECK( ! customHandle1 );
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 );
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;
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)
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)
// invoke default handle constructor
FrameBufferImage image;
- Dali::ImageAttributes attributes;
Vector2 stageSize = Stage::GetCurrent().GetSize();
// initialise handle
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);
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;
}
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 );
DALI_TEST_CHECK( !image );
// initialise handle
- image = Image::New(gTestImageFilename);
+ image = ResourceImage::New(gTestImageFilename);
DALI_TEST_CHECK( image );
END_TEST;
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;
// 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 );
// 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 );
// 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 );
// 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 );
}
// 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<GLuint> 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<GLuint> 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<GLuint> 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<GLuint> 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<GLuint> 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);
END_TEST;
}
-// 1.16
+// 1.9
int UtcDaliImageGetImageSize(void)
{
TestApplication application;
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);
END_TEST;
}
-// 1.19
+// 1.12
int UtcDaliImageGetLoadingState02(void)
{
TestApplication application;
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);
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");
SignalUploadedFlag = true;
}
-// 1.22
+// 1.15
int UtcDaliImageSignalLoadingFinished(void)
{
TestApplication application;
SignalLoadFlag = false;
- Image image = Image::New(gTestImageFilename);
+ ResourceImage image = ResourceImage::New(gTestImageFilename);
image.LoadingFinishedSignal().Connect( SignalLoadHandler );
application.SendNotification();
END_TEST;
}
-// 1.23
+// 1.16
int UtcDaliImageSignalUploaded(void)
{
TestApplication application;
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
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();
END_TEST;
}
-// 1.25
+// 1.18
int UtcDaliImageDiscard02(void)
{
TestApplication application;
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);
END_TEST;
}
-// 1.26
+// 1.19
int UtcDaliImageDiscard03(void)
{
TestApplication application;
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);
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 );
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);
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);
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);
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);
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);
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);
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);
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
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);
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
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);
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);
{
TestApplication application;
- Image image = Image::New(TestImageFilename);
+ Image image = ResourceImage::New(TestImageFilename);
ImageActor actor = ImageActor::New(image);
actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
{
TestApplication application;
- Image image = Image::New(TestImageFilename);
+ Image image = ResourceImage::New(TestImageFilename);
ImageActor actor = ImageActor::New(image);
actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
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 );
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 );
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 );
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();
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();
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);
{
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);
{
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);
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");
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");
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);
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);
application.GetPlatform().SetResourceLoadFailed(resourceId, Integration::FailureUnknown);
}
-void ReloadImage(TestApplication& application, Image image)
+void ReloadImage(TestApplication& application, ResourceImage image)
{
application.GetPlatform().ClearReadyResources();
application.GetPlatform().DiscardRequest();
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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);
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;
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;
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;
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;
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;
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;
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;
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);
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;
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 );
}
}
+/// 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();
}
}
-//////////////////////////////////////////////////////////////////////////////
-
int UtcDaliScriptingNewImage(void)
{
TestApplication application;
// 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
{
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
{
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 );
}
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 ) );
}
// Default
{
- Image image = Image::New( "MY_PATH" );
+ Image image = ResourceImage::New( "MY_PATH" );
Property::Map map;
CreatePropertyMap( image, map );
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") );
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 );
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") );
{
bool uploadSuccess( false );
+ AllocateAtlas();
+
if( IsWithin(bitmapImage, xOffset, yOffset) )
{
ResourceId destId = GetResourceId();
{
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();
}
{
--mConnectionCount;
- if ( Dali::Image::Unused == mReleasePolicy &&
+ if ( Dali::Image::UNUSED == mReleasePolicy &&
mConnectionCount == 0 )
{
ReleaseAtlas();
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;
}
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();
}
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();
--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)
* @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.
unsigned int height,
Pixel::Format pixelformat,
unsigned int stride,
- ReleasePolicy releasePol=ImageReleasePolicyDefault );
+ ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT );
/**
* Create a new BitmapImage.
* @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.
unsigned int height,
Pixel::Format pixelformat,
unsigned int stride,
- ReleasePolicy releasePol=ImageReleasePolicyDefault);
+ ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT);
protected:
/**
/**
* 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:
/**
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
}
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())
{
mHeight = nativeImage.GetHeight();
}
-
FrameBufferImage::FrameBufferImage( NativeImage& nativeImage, ReleasePolicy releasePolicy )
-: Image(Dali::Image::Immediate, releasePolicy),
+: Image(releasePolicy),
mNativeImage(&nativeImage),
mPixelFormat(nativeImage.GetPixelFormat())
{
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);
#include <dali/integration-api/platform-abstraction.h>
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/common/constants.h>
+#include <dali/public-api/images/resource-image.h>
#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/common/notification-manager.h>
#include <dali/internal/common/event-to-update.h>
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 );
}
#include <dali/internal/event/resources/resource-ticket.h>
#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/resources/resource-client.h>
-#include <dali/internal/event/images/image-factory.h>
-#include <dali/internal/event/images/nine-patch-image-impl.h>
#include <dali/internal/event/common/stage-impl.h>
using namespace Dali::Integration;
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 )
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<Image*>( object ) && "Resource ticket not ImageTicket subclass for image resource.\n" );
Image* image = static_cast<Image*>(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 );
}
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)
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
#include <dali/public-api/images/image.h>
#include <dali/public-api/images/native-image.h>
#include <dali/public-api/object/base-object.h>
-#include <dali/internal/render/gl-resources/texture.h>
-#include <dali/internal/event/images/image-factory-cache.h>
-#include <dali/internal/event/resources/image-ticket.h>
#include <dali/internal/event/resources/resource-client.h>
#include <dali/internal/event/resources/resource-ticket-observer.h>
namespace Dali
{
-class NativeImage;
-
namespace Internal
{
-typedef Dali::Image::LoadPolicy LoadPolicy;
typedef Dali::Image::ReleasePolicy ReleasePolicy;
class Image;
class ImageFactory;
typedef IntrusivePtr<Image> 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.
*/
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
*/
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()
*/
*/
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.
* 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.
* 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
/**
* 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
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();
{
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");
// INTERNAL INCLUDES
#include <dali/public-api/images/nine-patch-image.h>
+#include <dali/internal/event/images/resource-image-impl.h>
#include <dali/internal/event/images/bitmap-image-impl.h>
namespace Dali
* 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:
* 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
* 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.
--- /dev/null
+/*
+ * 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 <dali/internal/event/images/resource-image-impl.h>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/integration-api/debug.h>
+#include <dali/internal/event/common/thread-local-storage.h>
+#include <dali/internal/event/images/image-factory.h>
+#include <dali/internal/event/images/nine-patch-image-impl.h>
+#include <dali/internal/event/common/stage-impl.h>
+
+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<ResourceImage*>( object ) && "Resource ticket not ImageTicket subclass for image resource.\n" );
+ ResourceImage* image = static_cast<ResourceImage*>(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
--- /dev/null
+#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 <string>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/images/resource-image.h>
+#include <dali/internal/event/images/image-impl.h>
+#include <dali/internal/event/images/image-factory-cache.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+typedef Dali::ResourceImage::LoadPolicy LoadPolicy;
+
+const LoadPolicy IMAGE_LOAD_POLICY_DEFAULT = Dali::ResourceImage::IMMEDIATE;
+
+class ResourceImage;
+typedef IntrusivePtr<ResourceImage> 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<Internal::ResourceImage&>(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<const Internal::ResourceImage&>(handle);
+}
+
+} // namespace Dali
+#endif // __DALI_INTERNAL_RESOURCE_IMAGE_H__
#include <dali/integration-api/debug.h>
#include <dali/integration-api/platform-abstraction.h>
#include <dali/internal/event/common/thread-local-storage.h>
+#include <dali/internal/event/images/resource-image-impl.h>
#include <dali/internal/event/modeling/entity-impl.h>
#include <dali/internal/event/modeling/material-impl.h>
#include <dali/internal/event/modeling/mesh-impl.h>
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 ) );
}
}
$(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 \
$(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 \
$(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 \
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);
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());
}
// INTERNAL INCLUDES
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/images/image.h>
+#include <dali/public-api/images/pixel.h>
#include <dali/public-api/math/rect.h>
namespace Dali
/**
* @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();
* @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);
/**
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;
}
// INTERNAL INCLUDES
#include <dali/public-api/images/image.h>
+#include <dali/public-api/images/image-attributes.h>
namespace Dali
{
* 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.
(0 == width) ? stageSize.width : width,
(0 == height) ? stageSize.height : height,
pixelformat,
- Dali::Image::Never);
+ Dali::Image::NEVER);
return FrameBufferImage(internal.Get());
}
// INTERNAL INCLUDES
#include <dali/public-api/images/image.h>
-#include <dali/public-api/math/rect.h>
+#include <dali/public-api/images/pixel.h>
namespace Dali
{
// INTERNAL INCLUDES
#include <dali/public-api/images/bitmap-image.h>
+#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/text/text-style.h>
#include <dali/integration-api/platform-abstraction.h>
#include <dali/internal/event/common/thread-local-storage.h>
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
{
#include <dali/public-api/images/image.h>
// INTERNAL INCLUDES
-#include <dali/public-api/images/image-attributes.h>
-#include <dali/public-api/math/vector2.h>
#include <dali/internal/event/images/image-impl.h>
-#include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/integration-api/platform-abstraction.h>
+
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()
{
}
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);
return Image( dynamic_cast<Dali::Internal::Image*>(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();
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();
#include <string>
// INTERNAL INCLUDES
-#include <dali/public-api/common/loading-state.h>
-#include <dali/public-api/images/pixel.h>
#include <dali/public-api/object/base-handle.h>
#include <dali/public-api/signals/dali-signal.h>
namespace Dali
{
-struct Vector2;
namespace Internal DALI_INTERNAL
{
}
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.
- *
- * <h3>Image Loading</h3>
- *
- * 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.
*
- * <i>LoadPolicies</i>
- * - 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.
*
* <i>ReleasePolicies</i>
* - Unused: release resource once ImageActor using it is taken off stage.
* - Never: keep resource alive until Image object is thrown away.
*
* <i>Resolution of conflicting policies</i>
- * If the same image is created more than once with conflicting policies, LoadPolicy "Immediate" overrides "OnDemand"
- * and ReleasePolicy "Never" overrides "Unused".
- *
- * <i>Custom load requests</i>
- * Size, scaling mode, orientation compensation can be set when requesting an image resource.
- * See ImageAttributes for more details.
- *
- * <i>Compatible resources</i>
- *
- * 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%.
- *
- * <i>Reloading Images</i>
- *
- * 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
- *
- * <h3>Image resource lifetime</h3>
- *
- * 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
* @brief Resource management options.
*/
- /**
- * @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)
};
/**
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();
*/
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.
*
*/
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.
*/
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.
*
}
NinePatchImage::NinePatchImage(Internal::NinePatchImage* internal)
-: Image(internal)
+: ResourceImage(internal)
{
}
}
NinePatchImage::NinePatchImage(const NinePatchImage& handle)
-: Image(handle)
+: ResourceImage(handle)
{
}
{
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());
}
// INTERNAL INCLUDES
#include <dali/public-api/common/vector-wrapper.h>
-#include <dali/public-api/images/image.h>
+#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/images/bitmap-image.h>
#include <dali/public-api/math/rect.h>
* 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:
/**
--- /dev/null
+/*
+ * 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 <dali/public-api/images/resource-image.h>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/images/image-attributes.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/internal/event/images/resource-image-impl.h>
+#include <dali/internal/event/common/thread-local-storage.h>
+#include <dali/integration-api/platform-abstraction.h>
+
+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<Dali::Internal::ResourceImage*>(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
--- /dev/null
+#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 <string>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/common/loading-state.h>
+#include <dali/public-api/images/image.h>
+#include <dali/public-api/signals/dali-signal.h>
+
+namespace Dali
+{
+struct Vector2;
+class ImageAttributes;
+
+namespace Internal DALI_INTERNAL
+{
+class ResourceImage;
+}
+
+/**
+ * @brief ResourceImage is an image loaded using a URL
+ *
+ * <h3>ResourceImage Loading</h3>
+ *
+ * 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().
+ *
+ * <i>LoadPolicies</i>
+ * - IMMEDIATE: acquire image resource when creating ResourceImage.
+ * - ON_DEMAND: only load in case the associated ImageActor is put on Stage
+ *
+ * <i>Resolution of conflicting policies</i>
+ * If the same image is created more than once with conflicting policies, LoadPolicy "IMMEDIATE" overrides "ON_DEMAND".
+ *
+ * <i>Custom load requests</i>
+ * Size, scaling mode, orientation compensation can be set when requesting an image.
+ * See ImageAttributes for more details.
+ *
+ * <i>Compatible resources</i>
+ *
+ * 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%.
+ *
+ * <i>Reloading images</i>
+ *
+ * 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__
// INTERNAL INCLUDES
#include <dali/public-api/actors/actor.h>
-#include <dali/public-api/images/image.h>
+#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/images/image-attributes.h>
#include <dali/public-api/object/type-registry.h>
-#include <dali/internal/event/images/image-impl.h>
+#include <dali/internal/event/images/resource-image-impl.h>
#include <dali/internal/event/images/frame-buffer-image-impl.h>
#include <dali/internal/event/images/bitmap-image-impl.h>
#include <dali/internal/event/effects/shader-effect-impl.h>
};
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] );
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() )
{
DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image load-policy property is not a string" );
std::string v(map.GetValue(field).Get<std::string>());
- 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";
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
{
}
else
{
- ret = Image::New(filename, attributes, loadPolicy, releasePolicy);
+ ret = ResourceImage::New(filename, attributes, loadPolicy, releasePolicy);
}
}
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 ) )
}
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() );