X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-ImageAtlas.cpp;h=17b44322bc1c1c48e5f736c60eb273b9a85f9392;hb=a3b69d118ee5f918a827b23ea76813a7aefad845;hp=38835530e0364152cf963949ae7ba952b2136abe;hpb=f3c7e52f300fc2f6d07bcbd75ad3b992e19083f5;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp index 3883553..17b4432 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp @@ -20,8 +20,7 @@ #include #include #include -#include -#include +#include #include using namespace Dali; @@ -41,14 +40,35 @@ static const char* gImageNonExist = "non-exist.jpg"; const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS) +PixelData CreatePixelData( unsigned int width, unsigned int height ) +{ + unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGBA8888 ); + + unsigned char* buffer= reinterpret_cast( malloc( bufferSize ) ); + PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE ); + + return pixelData; +} + Rect TextureCoordinateToPixelArea( const Vector4& textureCoordinate, float size ) { Vector4 temp = textureCoordinate * size; Rect pixelArea; pixelArea.x = static_cast( temp.x ); pixelArea.y = static_cast( temp.y ); - pixelArea.width = static_cast( temp.z-temp.x+1.f ); - pixelArea.height = static_cast( temp.w-temp.y+1.f ); + pixelArea.width = static_cast( temp.z-temp.x+1.01f ); + pixelArea.height = static_cast( temp.w-temp.y+1.01f ); + + return pixelArea; +} + +Rect TextureCoordinateToPixelArea( const Vector4& textureCoordinate, float width, float height ) +{ + Rect pixelArea; + pixelArea.x = static_cast( textureCoordinate.x*width ); + pixelArea.y = static_cast( textureCoordinate.y*height); + pixelArea.width = static_cast( (textureCoordinate.z-textureCoordinate.x)*width+1.01f ); + pixelArea.height = static_cast( (textureCoordinate.w-textureCoordinate.y)*height+1.01f ); return pixelArea; } @@ -61,7 +81,23 @@ bool IsOverlap( Rect rect1, Rect rect2 ) && 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) { @@ -120,15 +156,31 @@ int UtcDaliImageAtlasGetAtlas(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; } @@ -153,8 +205,8 @@ int UtcDaliImageAtlasSetBrokenImage(void) atlas.Upload( textureRect, gImageNonExist ); Rect pixelArea = TextureCoordinateToPixelArea(textureRect, size); - DALI_TEST_EQUALS( pixelArea.width, 34.f, TEST_LOCATION ); - DALI_TEST_EQUALS( pixelArea.height, 34.f, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.width, 34, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.height, 34, TEST_LOCATION ); END_TEST; } @@ -165,9 +217,6 @@ int UtcDaliImageAtlasUploadP(void) 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); @@ -179,9 +228,7 @@ int UtcDaliImageAtlasUploadP(void) 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); @@ -191,23 +238,33 @@ int UtcDaliImageAtlasUploadP(void) Rect pixelArea1 = TextureCoordinateToPixelArea(textureRect1, size); DALI_TEST_EQUALS( pixelArea1.width, 34, TEST_LOCATION ); DALI_TEST_EQUALS( pixelArea1.height, 34, TEST_LOCATION ); - std::stringstream out; - out< pixelArea2 = TextureCoordinateToPixelArea(textureRect2, size); DALI_TEST_EQUALS( pixelArea2.width, 50, TEST_LOCATION ); DALI_TEST_EQUALS( pixelArea2.height, 50, TEST_LOCATION ); - out.str(""); - out< pixelArea3 = TextureCoordinateToPixelArea(textureRect3, size); DALI_TEST_EQUALS( pixelArea3.width, 128, TEST_LOCATION ); DALI_TEST_EQUALS( pixelArea3.height, 128, TEST_LOCATION ); - out.str(""); - out< pixelArea = TextureCoordinateToPixelArea(textureRect2, size); - DALI_TEST_EQUALS( pixelArea.x, 0.f, TEST_LOCATION ); - DALI_TEST_EQUALS( pixelArea.y, 0.f, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.x, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.y, 0, TEST_LOCATION ); END_TEST; } @@ -247,28 +392,39 @@ int UtcDaliImageAtlasImageView(void) 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); callStack.Enable(false); - DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 34, 34" ) ); - DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 34, 50, 50" ) ); + TraceCallStack::NamedParams params1; + params1["width"] = "34"; + params1["height"] = "34"; + params1["xoffset"] = "0"; + params1["yoffset"] = "0"; + + TraceCallStack::NamedParams params2; + params2["width"] = "50"; + params2["height"] = "50"; + params2["xoffset"] = "0"; + params2["yoffset"] = "34"; + + DALI_TEST_EQUALS( callStack.FindMethodAndParams("TexSubImage2D", params1 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( callStack.FindMethodAndParams("TexSubImage2D", params2 ), true, TEST_LOCATION ); callStack.Reset(); callStack.Enable(true); @@ -279,16 +435,76 @@ int UtcDaliImageAtlasImageView(void) 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); callStack.Enable(false); - DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 34, 100, 100" ) ); + + TraceCallStack::NamedParams params3; + params3["width"] = "100"; + params3["height"] = "100"; + params3["xoffset"] = "0"; + params3["yoffset"] = "34"; + + DALI_TEST_EQUALS( callStack.FindMethodAndParams("TexSubImage2D", params3 ), true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageAtlasPackToAtlas(void) +{ + ToolkitTestApplication application; + + std::vector pixelDataContainer; + pixelDataContainer.push_back( CreatePixelData( 20, 30 ) ); + pixelDataContainer.push_back( CreatePixelData( 10, 10 ) ); + pixelDataContainer.push_back( CreatePixelData( 45, 30 ) ); + pixelDataContainer.push_back( CreatePixelData( 20, 20 ) ); + + Dali::Vector textureRects; + Texture texture = ImageAtlas::PackToAtlas( pixelDataContainer, textureRects ); + + // -------------- + // | | + // | 45*30 | +// | | +// -------------- +// | 20 | | 20*20 +// | * |____| +// | 30 | | 10*10 +// -------- + + DALI_TEST_EQUALS( texture.GetWidth(), 45, TEST_LOCATION ); + DALI_TEST_EQUALS( texture.GetHeight(), 60, TEST_LOCATION ); + + Rect pixelArea = TextureCoordinateToPixelArea(textureRects[0], texture.GetWidth(), texture.GetHeight()); + DALI_TEST_EQUALS( pixelArea.x, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.y, 30, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.width, 20, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.height, 30, TEST_LOCATION ); + + pixelArea = TextureCoordinateToPixelArea(textureRects[1], texture.GetWidth(), texture.GetHeight()); + DALI_TEST_EQUALS( pixelArea.x, 20, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.y, 50, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.width, 10, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.height, 10, TEST_LOCATION ); + + pixelArea = TextureCoordinateToPixelArea(textureRects[2], texture.GetWidth(), texture.GetHeight()); + DALI_TEST_EQUALS( pixelArea.x, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.y, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.width, 45, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.height, 30, TEST_LOCATION ); + + pixelArea = TextureCoordinateToPixelArea(textureRects[3], texture.GetWidth(), texture.GetHeight()); + DALI_TEST_EQUALS( pixelArea.x, 20, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.y, 30, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.width, 20, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.height, 20, TEST_LOCATION ); END_TEST; }