X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-ImageAtlas.cpp;h=b605fc4ec43a0f97ea9e27ac03dcc671e3e18b9e;hp=5fe744fb8f27d208cae075296635df62158a8cd8;hb=5e351965bad7e1de2e94027548b022bac692603c;hpb=193fa3dcbfa6b46bb9d3d1c079f2ca4eb25747a1 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp index 5fe744f..b605fc4 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -21,7 +21,7 @@ #include #include #include -#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -35,19 +35,40 @@ static const char* gImage_50_RGBA = TEST_RESOURCE_DIR "/icon-delete.png"; // resolution: 128*128, pixel format: RGB888 static const char* gImage_128_RGB = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; -// this is image is not exist, for negative test -static const char* gImageNonExist = "non-exist.jpg"; +// Empty image, for testing broken image loading +static const char* gEmptyImage = TEST_RESOURCE_DIR "/empty.bmp"; 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; } @@ -170,26 +191,27 @@ int UtcDaliImageAtlasSetBrokenImage(void) unsigned int size = 200; ImageAtlas atlas = ImageAtlas::New( size, size ); - Vector4 textureRect; - atlas.Upload( textureRect, gImageNonExist ); - DALI_TEST_EQUALS( textureRect, Vector4::ZERO, TEST_LOCATION ); - // Set broken image TestPlatformAbstraction& platform = application.GetPlatform(); platform.SetClosestImageSize(Vector2( 34, 34)); atlas.SetBrokenImage( gImage_34_RGBA ); - // the non-exit image will be replaced with the broken image - platform.SetClosestImageSize(Vector2( 0, 0)); - atlas.Upload( textureRect, gImageNonExist ); + Vector4 textureRect; + + // the empty image will be replaced with the broken image + platform.SetClosestImageSize(Vector2( 20, 20)); + atlas.Upload( textureRect, gEmptyImage ); + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); Rect pixelArea = TextureCoordinateToPixelArea(textureRect, size); - DALI_TEST_EQUALS( pixelArea.width, 34, TEST_LOCATION ); - DALI_TEST_EQUALS( pixelArea.height, 34, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.width, 20, TEST_LOCATION ); + DALI_TEST_EQUALS( pixelArea.height, 20, TEST_LOCATION ); END_TEST; } + + int UtcDaliImageAtlasUploadP(void) { ToolkitTestApplication application; @@ -207,12 +229,7 @@ int UtcDaliImageAtlasUploadP(void) Vector4 textureRect3; atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128) ); - EventThreadCallback* eventTrigger = EventThreadCallback::Get(); - CallbackBase* callback = eventTrigger->GetCallback(); - - 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); @@ -262,8 +279,6 @@ int UtcDaliImageAtlasUploadWithObserver01(void) TestApplication application; ImageAtlas atlas = ImageAtlas::New( 200, 200 ); - EventThreadCallback* eventTrigger = EventThreadCallback::Get(); - CallbackBase* callback = eventTrigger->GetCallback(); gCountOfTestFuncCall = 0; TestUploadObserver uploadObserver; @@ -276,8 +291,7 @@ int UtcDaliImageAtlasUploadWithObserver01(void) atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128), FittingMode::DEFAULT, true, &uploadObserver ); // waiting until all three images are loaded and uploaded to atlas - eventTrigger->WaitingForTrigger( 3 ); - CallbackBase::Execute( *callback ); + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION ); application.SendNotification(); application.Render(RENDER_FRAME_INTERVAL); @@ -292,9 +306,6 @@ int UtcDaliImageAtlasUploadWithObserver02(void) TestApplication application; ImageAtlas atlas = ImageAtlas::New( 200, 200 ); - EventThreadCallback* eventTrigger = EventThreadCallback::Get(); - CallbackBase* callback = eventTrigger->GetCallback(); - gCountOfTestFuncCall = 0; TestUploadObserver* uploadObserver = new TestUploadObserver; @@ -309,8 +320,8 @@ int UtcDaliImageAtlasUploadWithObserver02(void) delete uploadObserver; // waiting until all three images are loaded and uploaded to atlas - eventTrigger->WaitingForTrigger( 3 ); - CallbackBase::Execute( *callback ); + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION ); + application.Render(RENDER_FRAME_INTERVAL); application.SendNotification(); @@ -380,22 +391,38 @@ int UtcDaliImageAtlasImageView(void) callStack.Reset(); callStack.Enable(true); - 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 ); + Property::Map imageMap1; - EventThreadCallback* eventTrigger = EventThreadCallback::Get(); - while( eventTrigger == NULL) // waiting uintil the ImageAtlas is created by ImageAtlasManager - { - usleep(10); - eventTrigger = EventThreadCallback::Get(); - } - CallbackBase* callback = eventTrigger->GetCallback(); + imageMap1[ ImageVisual::Property::URL ] = gImage_34_RGBA; + imageMap1[ ImageVisual::Property::DESIRED_HEIGHT ] = 34; + imageMap1[ ImageVisual::Property::DESIRED_WIDTH ] = 34; + imageMap1[ ImageVisual::Property::ATLASING] = true; + + Property::Map imageMap2; + + imageMap2[ ImageVisual::Property::URL ] = gImage_50_RGBA; + imageMap2[ ImageVisual::Property::DESIRED_HEIGHT ] = 50; + imageMap2[ ImageVisual::Property::DESIRED_WIDTH ] = 50; + imageMap2[ ImageVisual::Property::ATLASING ] = true; + + ImageView imageView1 = ImageView::New(); + imageView1.SetProperty( ImageView::Property::IMAGE, imageMap1 ); + + ImageView imageView2 = ImageView::New(); + imageView2.SetProperty( ImageView::Property::IMAGE, imageMap2 ); + + // 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); @@ -425,11 +452,20 @@ int UtcDaliImageAtlasImageView(void) Stage::GetCurrent().Remove( imageView2 ); application.SendNotification(); application.Render(RENDER_FRAME_INTERVAL); - ImageView imageView3 = ImageView::New( gImage_128_RGB, ImageDimensions(100, 100) ); + + Property::Map imageMap3; + imageMap3[ ImageVisual::Property::URL ] = gImage_128_RGB; + imageMap3[ ImageVisual::Property::DESIRED_HEIGHT ] = 100; + imageMap3[ ImageVisual::Property::DESIRED_WIDTH ] = 100; + imageMap3[ ImageVisual::Property::ATLASING ] = true; + + ImageView imageView3 = ImageView::New(); + imageView3.SetProperty( ImageView::Property::IMAGE, imageMap3 ); + + 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( 1 ), true, TEST_LOCATION ); application.SendNotification(); application.Render(RENDER_FRAME_INTERVAL); @@ -446,3 +482,56 @@ int UtcDaliImageAtlasImageView(void) 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; +}