#include <dali/dali.h>
#include <dali-toolkit-test-suite-utils.h>
#include <toolkit-event-thread-callback.h>
-#include <dali/devel-api/images/atlas.h>
-#include <dali-toolkit/devel-api/image-atlas/image-atlas.h>
+#include <dali-toolkit/devel-api/image-loader/image-atlas.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
using namespace Dali;
&& rect2.y < rect1.y+rect1.height;
}
+static unsigned int gCountOfTestFuncCall;
+class TestUploadObserver : public AtlasUploadObserver
+{
+public:
+ TestUploadObserver()
+ {}
+
+ virtual ~TestUploadObserver()
+ {}
+
+ void UploadCompleted()
+ {
+ gCountOfTestFuncCall++;
+ }
+};
+
} // anonymous namespace
void dali_image_atlas_startup(void)
ToolkitTestApplication application;
ImageAtlas atlas = ImageAtlas::New( 32, 32 );
- Image image = atlas.GetAtlas();
+ Texture image = atlas.GetAtlas();
// test the atlas created
DALI_TEST_EQUALS( (bool)image, true, TEST_LOCATION );
DALI_TEST_CHECK( image.GetHeight() == 32u );
DALI_TEST_CHECK( image.GetWidth() == 32u );
- Atlas coreAtlas = Atlas::DownCast( image );
- DALI_TEST_EQUALS( (bool)coreAtlas, true, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliImageAtlasGetOccupancyRate(void)
+{
+ ToolkitTestApplication application;
+
+ ImageAtlas atlas = ImageAtlas::New( 100, 100 );
+
+ DALI_TEST_EQUALS( atlas.GetOccupancyRate(), 0.f, TEST_LOCATION );
+
+ Vector4 textureRect1;
+ atlas.Upload( textureRect1, gImage_34_RGBA, ImageDimensions(34, 34) );
+ DALI_TEST_EQUALS( atlas.GetOccupancyRate(), 34.f*34.f/10000.f, 0.001f, TEST_LOCATION );
+
+ Vector4 textureRect2;
+ atlas.Upload( textureRect2, gImage_50_RGBA, ImageDimensions(50, 50) );
+ DALI_TEST_EQUALS( atlas.GetOccupancyRate(), (34.f*34.f+50.f*50.f)/10000.f, 0.001f, TEST_LOCATION );
END_TEST;
}
unsigned int size = 200;
ImageAtlas atlas = ImageAtlas::New( size, size );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- CallbackBase* callback = eventTrigger->GetCallback();
-
TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
callStack.Reset();
callStack.Enable(true);
Vector4 textureRect3;
atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128) );
- eventTrigger->WaitingForTrigger( 3 );// waiting until all three images are loaded
-
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
END_TEST;
}
+int UtcDaliImageAtlasUploadWithObserver01(void)
+{
+ TestApplication application;
+ ImageAtlas atlas = ImageAtlas::New( 200, 200 );
+
+
+ gCountOfTestFuncCall = 0;
+ TestUploadObserver uploadObserver;
+
+ Vector4 textureRect1;
+ atlas.Upload( textureRect1, gImage_34_RGBA, ImageDimensions(34, 34), FittingMode::DEFAULT, true, &uploadObserver );
+ Vector4 textureRect2;
+ atlas.Upload( textureRect2, gImage_50_RGBA, ImageDimensions(50, 50), FittingMode::DEFAULT, true, NULL );
+ Vector4 textureRect3;
+ atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128), FittingMode::DEFAULT, true, &uploadObserver );
+
+ // waiting until all three images are loaded and uploaded to atlas
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
+ application.SendNotification();
+ application.Render(RENDER_FRAME_INTERVAL);
+
+ // Check that TestFunc is called twice
+ DALI_TEST_EQUALS( gCountOfTestFuncCall, 2, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliImageAtlasUploadWithObserver02(void)
+{
+ TestApplication application;
+ ImageAtlas atlas = ImageAtlas::New( 200, 200 );
+
+ gCountOfTestFuncCall = 0;
+ TestUploadObserver* uploadObserver = new TestUploadObserver;
+
+ Vector4 textureRect1;
+ atlas.Upload( textureRect1, gImage_34_RGBA, ImageDimensions(34, 34), FittingMode::DEFAULT, true, uploadObserver );
+ Vector4 textureRect2;
+ atlas.Upload( textureRect2, gImage_50_RGBA, ImageDimensions(50, 50), FittingMode::DEFAULT, true, uploadObserver );
+ Vector4 textureRect3;
+ atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128), FittingMode::DEFAULT, true, uploadObserver );
+
+ // destroy the object.
+ delete uploadObserver;
+
+ // waiting until all three images are loaded and uploaded to atlas
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
+
+ application.Render(RENDER_FRAME_INTERVAL);
+ application.SendNotification();
+
+ // Check that TestFunc is called twice
+ DALI_TEST_EQUALS( gCountOfTestFuncCall, 0, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliImageAtlasUploadWithObserver03(void)
+{
+ TestApplication application;
+
+ gCountOfTestFuncCall = 0;
+ TestUploadObserver* uploadObserver = new TestUploadObserver;
+
+ {
+ ImageAtlas atlas = ImageAtlas::New( 200, 200 );
+
+ Vector4 textureRect1;
+ atlas.Upload( textureRect1, gImage_34_RGBA, ImageDimensions(34, 34), FittingMode::DEFAULT, true, uploadObserver );
+ Vector4 textureRect2;
+ atlas.Upload( textureRect2, gImage_50_RGBA, ImageDimensions(50, 50), FittingMode::DEFAULT, true, uploadObserver );
+ Vector4 textureRect3;
+ atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128), FittingMode::DEFAULT, true, uploadObserver );
+ }
+
+ //ImageAtlas is out of scope, so it will get destroyed
+
+ application.Render(RENDER_FRAME_INTERVAL);
+ application.SendNotification();
+ application.SendNotification();
+ application.Render(RENDER_FRAME_INTERVAL);
+
+ // Check that TestFunc is called twice
+ DALI_TEST_EQUALS( gCountOfTestFuncCall, 0, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliImageAtlasRemove(void)
{
TestApplication application;
ImageView imageView1 = ImageView::New( gImage_34_RGBA, ImageDimensions(34, 34) );
ImageView imageView2 = ImageView::New( gImage_50_RGBA, ImageDimensions(50, 50) );
- Stage::GetCurrent().Add( imageView1 );
- Stage::GetCurrent().Add( imageView2 );
- EventThreadCallback* eventTrigger = EventThreadCallback::Get();
- while( eventTrigger == NULL) // waiting uintil the ImageAtlas is created by ImageAtlasManager
- {
- usleep(10);
- eventTrigger = EventThreadCallback::Get();
- }
- CallbackBase* callback = eventTrigger->GetCallback();
+ // ImageView doesn't do size negotiation properly: it only listens to OnSizeSet:
+ imageView1.SetSize( 100, 100 );
+ imageView2.SetSize( 100, 100 );
+ imageView1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ imageView2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- eventTrigger->WaitingForTrigger( 2 );// waiting until both images are loaded
+ application.GetPlatform().SetClosestImageSize( Vector2(34, 34) );
+ Stage::GetCurrent().Add( imageView1 );
+ application.GetPlatform().SetClosestImageSize( Vector2(50, 50) );
+ Stage::GetCurrent().Add( imageView2 );
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);
ImageView imageView3 = ImageView::New( gImage_128_RGB, ImageDimensions(100, 100) );
+ application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
Stage::GetCurrent().Add( imageView3 );
- eventTrigger->WaitingForTrigger( 3 ); // waiting for the third image loaded
- CallbackBase::Execute( *callback );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
application.SendNotification();
application.Render(RENDER_FRAME_INTERVAL);