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=25d83ba54ee6fb4e4636689cb1d7438e6971a6bc;hp=a94585017bc211bcb257895d6bfced4502e664b3;hb=HEAD;hpb=3eb60a0aef6b188727b79bdee2e35c575c432a90 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageAtlas.cpp index a945850..2bd6357 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) 2022 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. @@ -17,11 +17,13 @@ #include #include -#include + #include #include + +#include #include -#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -35,31 +37,67 @@ 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) -Rect TextureCoordinateToPixelArea( const Vector4& textureCoordinate, float size ) +PixelData CreatePixelData(unsigned int width, unsigned int height) { - Vector4 temp = textureCoordinate * size; + 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.x = static_cast(temp.x); + pixelArea.y = static_cast(temp.y); + pixelArea.width = static_cast(temp.z - temp.x + 1.01f); + pixelArea.height = static_cast(temp.w - temp.y + 1.01f); return pixelArea; } -bool IsOverlap( Rect rect1, Rect rect2 ) +Rect TextureCoordinateToPixelArea(const Vector4& textureCoordinate, float width, float height) { - return rect1.x < rect2.x+rect2.width - && rect2.x < rect1.x+rect1.width - && rect1.y < rect2.y+rect2.height - && rect2.y < rect1.y+rect1.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; } +bool IsOverlap(Rect rect1, Rect rect2) +{ + return rect1.x < rect2.x + rect2.width && rect2.x < rect1.x + rect1.width && rect1.y < rect2.y + rect2.height && 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) @@ -79,12 +117,12 @@ int UtcDaliImageAtlasNew(void) // invoke default handle constructor ImageAtlas atlas; - DALI_TEST_CHECK( !atlas ); + DALI_TEST_CHECK(!atlas); // initialise handle - atlas = ImageAtlas::New( 32, 32 ); + atlas = ImageAtlas::New(32, 32); - DALI_TEST_CHECK( atlas ); + DALI_TEST_CHECK(atlas); END_TEST; } @@ -92,10 +130,10 @@ int UtcDaliImageAtlasCopyConstructor(void) { ToolkitTestApplication application; - ImageAtlas atlas = ImageAtlas::New( 32, 32); + ImageAtlas atlas = ImageAtlas::New(32, 32); ImageAtlas atlasCopy(atlas); - DALI_TEST_EQUALS( (bool)atlasCopy, true, TEST_LOCATION ); + DALI_TEST_EQUALS((bool)atlasCopy, true, TEST_LOCATION); END_TEST; } @@ -103,13 +141,13 @@ int UtcDaliImageAtlasAssignmentOperator(void) { ToolkitTestApplication application; - ImageAtlas atlas = ImageAtlas::New( 32, 32 ); + ImageAtlas atlas = ImageAtlas::New(32, 32); ImageAtlas atlas2; - DALI_TEST_EQUALS( (bool)atlas2, false, TEST_LOCATION ); + DALI_TEST_EQUALS((bool)atlas2, false, TEST_LOCATION); atlas2 = atlas; - DALI_TEST_EQUALS( (bool)atlas2, true, TEST_LOCATION ); + DALI_TEST_EQUALS((bool)atlas2, true, TEST_LOCATION); END_TEST; } @@ -118,13 +156,13 @@ int UtcDaliImageAtlasGetAtlas(void) { ToolkitTestApplication application; - ImageAtlas atlas = ImageAtlas::New( 32, 32 ); - Texture image = atlas.GetAtlas(); + ImageAtlas atlas = ImageAtlas::New(32, 32); + 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 ); + DALI_TEST_EQUALS((bool)image, true, TEST_LOCATION); + DALI_TEST_CHECK(image.GetHeight() == 32u); + DALI_TEST_CHECK(image.GetWidth() == 32u); END_TEST; } @@ -133,17 +171,17 @@ int UtcDaliImageAtlasGetOccupancyRate(void) { ToolkitTestApplication application; - ImageAtlas atlas = ImageAtlas::New( 100, 100 ); + ImageAtlas atlas = ImageAtlas::New(100, 100); - DALI_TEST_EQUALS( atlas.GetOccupancyRate(), 0.f, TEST_LOCATION ); + 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 ); + 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 ); + 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; } @@ -151,25 +189,24 @@ int UtcDaliImageAtlasGetOccupancyRate(void) int UtcDaliImageAtlasSetBrokenImage(void) { ToolkitTestApplication application; - unsigned int size = 200; - ImageAtlas atlas = ImageAtlas::New( size, size ); - - Vector4 textureRect; - atlas.Upload( textureRect, gImageNonExist ); - DALI_TEST_EQUALS( textureRect, Vector4::ZERO, TEST_LOCATION ); + unsigned int size = 200; + ImageAtlas atlas = ImageAtlas::New(size, size); // Set broken image TestPlatformAbstraction& platform = application.GetPlatform(); - platform.SetClosestImageSize(Vector2( 34, 34)); - atlas.SetBrokenImage( gImage_34_RGBA ); + platform.SetClosestImageSize(Vector2(34, 34)); + atlas.SetBrokenImage(gImage_34_RGBA); + + Vector4 textureRect; - // the non-exit image will be replaced with the broken image - platform.SetClosestImageSize(Vector2( 0, 0)); - atlas.Upload( textureRect, gImageNonExist ); + // 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; } @@ -177,26 +214,21 @@ int UtcDaliImageAtlasSetBrokenImage(void) int UtcDaliImageAtlasUploadP(void) { ToolkitTestApplication application; - unsigned int size = 200; - ImageAtlas atlas = ImageAtlas::New( size, size ); + unsigned int size = 200; + ImageAtlas atlas = ImageAtlas::New(size, size); TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace(); callStack.Reset(); callStack.Enable(true); Vector4 textureRect1; - atlas.Upload( textureRect1, gImage_34_RGBA, ImageDimensions(34, 34) ); + atlas.Upload(textureRect1, gImage_34_RGBA, ImageDimensions(34, 34)); Vector4 textureRect2; - atlas.Upload( textureRect2, gImage_50_RGBA, ImageDimensions(50, 50) ); + atlas.Upload(textureRect2, gImage_50_RGBA, ImageDimensions(50, 50)); Vector4 textureRect3; - atlas.Upload( textureRect3, gImage_128_RGB, ImageDimensions(128, 128) ); + 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); @@ -204,60 +236,149 @@ int UtcDaliImageAtlasUploadP(void) callStack.Enable(false); Rect pixelArea1 = TextureCoordinateToPixelArea(textureRect1, size); - DALI_TEST_EQUALS( pixelArea1.width, 34, TEST_LOCATION ); - DALI_TEST_EQUALS( pixelArea1.height, 34, TEST_LOCATION ); + DALI_TEST_EQUALS(pixelArea1.width, 34, TEST_LOCATION); + DALI_TEST_EQUALS(pixelArea1.height, 34, TEST_LOCATION); TraceCallStack::NamedParams params; - params["width"] = ToString(pixelArea1.width); - params["height"] = ToString(pixelArea1.height); - params["xoffset"] = ToString(pixelArea1.x); - params["yoffset"] = ToString(pixelArea1.y); - DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", params )); + params["width"] << pixelArea1.width; + params["height"] << pixelArea1.height; + params["xoffset"] << pixelArea1.x; + params["yoffset"] << pixelArea1.y; + DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", params)); Rect pixelArea2 = TextureCoordinateToPixelArea(textureRect2, size); - DALI_TEST_EQUALS( pixelArea2.width, 50, TEST_LOCATION ); - DALI_TEST_EQUALS( pixelArea2.height, 50, TEST_LOCATION ); + DALI_TEST_EQUALS(pixelArea2.width, 50, TEST_LOCATION); + DALI_TEST_EQUALS(pixelArea2.height, 50, TEST_LOCATION); - params["width"] = ToString(pixelArea2.width); - params["height"] = ToString(pixelArea2.height); - params["xoffset"] = ToString(pixelArea2.x); - params["yoffset"] = ToString(pixelArea2.y); - DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", params ) ); + params.mParams.clear(); + params["width"] << pixelArea2.width; + params["height"] << pixelArea2.height; + params["xoffset"] << pixelArea2.x; + params["yoffset"] << pixelArea2.y; + DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", params)); Rect pixelArea3 = TextureCoordinateToPixelArea(textureRect3, size); - DALI_TEST_EQUALS( pixelArea3.width, 128, TEST_LOCATION ); - DALI_TEST_EQUALS( pixelArea3.height, 128, TEST_LOCATION ); + DALI_TEST_EQUALS(pixelArea3.width, 128, TEST_LOCATION); + DALI_TEST_EQUALS(pixelArea3.height, 128, TEST_LOCATION); - params["width"] = ToString(pixelArea3.width); - params["height"] = ToString(pixelArea3.height); - params["xoffset"] = ToString(pixelArea3.x); - params["yoffset"] = ToString(pixelArea3.y); - DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", params ) ); + params.mParams.clear(); + params["width"] << pixelArea3.width; + params["height"] << pixelArea3.height; + params["xoffset"] << pixelArea3.x; + params["yoffset"] << pixelArea3.y; + DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", params)); - DALI_TEST_CHECK( ! IsOverlap(pixelArea1, pixelArea2) ); - DALI_TEST_CHECK( ! IsOverlap(pixelArea1, pixelArea3) ); - DALI_TEST_CHECK( ! IsOverlap(pixelArea2, pixelArea3) ); + DALI_TEST_CHECK(!IsOverlap(pixelArea1, pixelArea2)); + DALI_TEST_CHECK(!IsOverlap(pixelArea1, pixelArea3)); + DALI_TEST_CHECK(!IsOverlap(pixelArea2, pixelArea3)); END_TEST; } -int UtcDaliImageAtlasRemove(void) +int UtcDaliImageAtlasUploadWithObserver01(void) { - TestApplication application; - unsigned int size = 100; - ImageAtlas atlas = ImageAtlas::New( size, size ); + ToolkitTestApplication application; + ImageAtlas atlas = ImageAtlas::New(200, 200); + + gCountOfTestFuncCall = 0; + TestUploadObserver uploadObserver; + Vector4 textureRect1; - atlas.Upload( textureRect1, gImage_34_RGBA, ImageDimensions(34, 34) ); + 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); - atlas.Remove( textureRect1 ); + // 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) +{ + ToolkitTestApplication 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) ); + 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) +{ + ToolkitTestApplication 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) +{ + ToolkitTestApplication application; + unsigned int size = 100; + ImageAtlas atlas = ImageAtlas::New(size, size); + Vector4 textureRect1; + atlas.Upload(textureRect1, gImage_34_RGBA, ImageDimensions(34, 34)); + + atlas.Remove(textureRect1); + + Vector4 textureRect2; + atlas.Upload(textureRect2, gImage_50_RGBA, ImageDimensions(50, 50)); // one pixel gap Rect pixelArea = TextureCoordinateToPixelArea(textureRect2, size); - DALI_TEST_EQUALS( pixelArea.x, 0, TEST_LOCATION ); - DALI_TEST_EQUALS( pixelArea.y, 0, TEST_LOCATION ); + DALI_TEST_EQUALS(pixelArea.x, 0, TEST_LOCATION); + DALI_TEST_EQUALS(pixelArea.y, 0, TEST_LOCATION); END_TEST; } @@ -270,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); - eventTrigger->WaitingForTrigger( 2 );// waiting until both images are loaded + ImageView imageView2 = ImageView::New(); + imageView2.SetProperty(ImageView::Property::IMAGE, imageMap2); - CallbackBase::Execute( *callback ); + // ImageView doesn't do size negotiation properly: it only listens to OnSizeSet: + imageView1.SetProperty(Actor::Property::SIZE, Vector2(100, 100)); + imageView2.SetProperty(Actor::Property::SIZE, Vector2(100, 100)); + imageView1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + imageView2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + + application.GetPlatform().SetClosestImageSize(Vector2(34, 34)); + application.GetScene().Add(imageView1); + application.GetPlatform().SetClosestImageSize(Vector2(50, 50)); + application.GetScene().Add(imageView2); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); application.SendNotification(); application.Render(RENDER_FRAME_INTERVAL); @@ -293,33 +430,42 @@ int UtcDaliImageAtlasImageView(void) callStack.Enable(false); TraceCallStack::NamedParams params1; - params1["width"] = "34"; - params1["height"] = "34"; - params1["xoffset"] = "0"; - params1["yoffset"] = "0"; + 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"; + 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 ); + 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); // remove the imageView2 from stage, the second image will also be removed from atlas // then the space on the atlas will be used by the third image added. - Stage::GetCurrent().Remove( imageView2 ); + application.GetScene().Remove(imageView2); application.SendNotification(); application.Render(RENDER_FRAME_INTERVAL); - ImageView imageView3 = ImageView::New( gImage_128_RGB, ImageDimensions(100, 100) ); - Stage::GetCurrent().Add( imageView3 ); - eventTrigger->WaitingForTrigger( 3 ); // waiting for the third image loaded - CallbackBase::Execute( *callback ); + 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)); + application.GetScene().Add(imageView3); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); application.SendNotification(); application.Render(RENDER_FRAME_INTERVAL); @@ -327,12 +473,65 @@ int UtcDaliImageAtlasImageView(void) callStack.Enable(false); TraceCallStack::NamedParams params3; - params3["width"] = "100"; - params3["height"] = "100"; - params3["xoffset"] = "0"; - params3["yoffset"] = "34"; + 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; - DALI_TEST_EQUALS( callStack.FindMethodAndParams("TexSubImage2D", params3 ), true, TEST_LOCATION ); + 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; }