X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-ImageActor.cpp;h=ad807926e85df1fbf71daf311f1b7d4476d9b225;hb=1c92aff3ef39de0b3f2699b432deeb3937172f1c;hp=42c4846b1223eb261367477b8c108f71605581a3;hpb=1f2225607eeb5dd96fa7e282abf0d6a470a7693b;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-ImageActor.cpp b/automated-tests/src/dali/utc-Dali-ImageActor.cpp index 42c4846..ad80792 100644 --- a/automated-tests/src/dali/utc-Dali-ImageActor.cpp +++ b/automated-tests/src/dali/utc-Dali-ImageActor.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "dali-test-suite-utils/dali-test-suite-utils.h" using namespace Dali; @@ -62,7 +63,7 @@ int UtcDaliImageActorNew01(void) 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); @@ -82,7 +83,7 @@ int UtcDaliImageActorNew02(void) 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); @@ -94,7 +95,7 @@ int UtcDaliImageActorDownCast(void) 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); @@ -125,12 +126,28 @@ int UtcDaliImageActorDownCast2(void) END_TEST; } +int UtcDaliImageActorCopyConstructor(void) +{ + TestApplication application; + tet_infoline("Testing Dali::ImageActor::ImageActor(const ImageActor& )"); + + Image image = ResourceImage::New("IncorrectImageName"); + ImageActor actor1 = ImageActor::New(image); + + ImageActor actor2(actor1); + DALI_TEST_CHECK(actor2); + DALI_TEST_EQUALS( actor2, actor1, TEST_LOCATION ); + DALI_TEST_EQUALS( actor2.GetImage(), image, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliImageActor9Patch(void) { 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); @@ -149,23 +166,18 @@ int UtcDaliImageActorPixelArea(void) TestApplication application; tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea"); - BitmapImage img = BitmapImage::New( 10, 10 ); + BufferImage img = BufferImage::New( 10, 10 ); ImageActor actor = ImageActor::New( img ); - DALI_TEST_CHECK( actor.IsPixelAreaSet() == false ); - ImageActor::PixelArea area( 1, 2, 3, 4 ); actor.SetPixelArea( area ); - DALI_TEST_CHECK( actor.IsPixelAreaSet() == true ); - DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION ); DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION ); DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION ); DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION ); ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) ); - DALI_TEST_CHECK( actor2.IsPixelAreaSet() == true ); DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION ); DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION ); @@ -174,13 +186,40 @@ int UtcDaliImageActorPixelArea(void) END_TEST; } +// Set a size that is too large on an Image with a shader that requires grid +int UtcDaliImageActorSetSize01(void) +{ + TestApplication application; + + BufferImage img = BufferImage::New( 1,1 ); + ImageActor actor = ImageActor::New( img ); + + ShaderEffect effect = ShaderEffect::New( " ", " ", ShaderEffect::HINT_GRID ); + actor.SetShaderEffect( effect ); + + const float INVALID_SIZE = float(1u<<31); + Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE ); + + DALI_TEST_CHECK(vector != actor.GetCurrentSize()); + + actor.SetSize(vector); + Stage::GetCurrent().Add(actor); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION ); + END_TEST; +} + int UtcDaliImageActorGetCurrentSize01(void) { TestApplication application; tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize"); Vector2 initialImageSize(100, 50); - BitmapImage image = BitmapImage::New( initialImageSize.width, initialImageSize.height ); + BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height ); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -209,11 +248,6 @@ int UtcDaliImageActorGetCurrentSize01(void) // natural size is not used as setsize is called DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION ); - actor.SetToNaturalSize(); - application.SendNotification(); - application.Render(9); - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2( area.width, area.height ), TEST_LOCATION ); - END_TEST; } @@ -227,7 +261,7 @@ int UtcDaliImageActorGetCurrentSize02(void) 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); @@ -240,7 +274,7 @@ int UtcDaliImageActorGetCurrentSize02(void) // Now complete the image load Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height ); Integration::ResourcePointer resourcePtr(bitmap); // reference it @@ -260,10 +294,6 @@ int UtcDaliImageActorGetCurrentSize02(void) application.Render(); DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION ); - actor.SetToNaturalSize(); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION ); END_TEST; } @@ -276,10 +306,8 @@ int UtcDaliImageActorGetCurrentSize03(void) const Vector2 closestImageSize( 80, 45); application.GetPlatform().SetClosestImageSize(closestImageSize); - ImageAttributes attrs; - const Vector2 requestedSize( 40, 30 ); - attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Vector2 requestedSize( 40, 30 ); + Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -292,7 +320,7 @@ int UtcDaliImageActorGetCurrentSize03(void) // Now complete the image load Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); Integration::ResourcePointer resourcePtr(bitmap); // reference it @@ -304,19 +332,6 @@ int UtcDaliImageActorGetCurrentSize03(void) DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - // Test that setting a size on the actor can be 'undone' with SetNaturalSize() - Vector2 size(200.0f, 200.0f); - actor.SetSize(size); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION ); - - actor.SetToNaturalSize(); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); END_TEST; } @@ -329,10 +344,8 @@ int UtcDaliImageActorGetCurrentSize04(void) const Vector2 closestImageSize( 80, 45); application.GetPlatform().SetClosestImageSize(closestImageSize); - const Vector2 requestedSize( 40, 30 ); - ImageAttributes attrs; - attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Vector2 requestedSize( 40, 30 ); + Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -343,7 +356,7 @@ int UtcDaliImageActorGetCurrentSize04(void) // Now complete the image load Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); Integration::ResourcePointer resourcePtr(bitmap); // reference it @@ -369,8 +382,7 @@ int UtcDaliImageActorGetCurrentSize04(void) application.GetPlatform().SetClosestImageSize(image2ClosestSize); const Vector2 request2Size( 100, 100 ); - attrs.SetSize( request2Size.width, request2Size.height ); - Image image2 = Image::New("image2.jpg", attrs); + Image image2 = ResourceImage::New("image.jpg", ImageDimensions( request2Size.x, request2Size.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); actor.SetImage(image2); application.SendNotification(); // Flush update messages @@ -383,7 +395,7 @@ int UtcDaliImageActorGetCurrentSize04(void) // Now complete the image load req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height ); Integration::ResourcePointer resourcePtr2(bitmap2); // reference it @@ -396,11 +408,6 @@ int UtcDaliImageActorGetCurrentSize04(void) // Ensure the actor size is kept DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION ); - actor.SetToNaturalSize(); - application.SendNotification(); - application.Render(); - // Ensure the actor size gets the new image's natural size - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), request2Size, TEST_LOCATION ); END_TEST; } @@ -413,10 +420,8 @@ int UtcDaliImageActorGetCurrentSize05(void) Vector2 closestImageSize( 80, 45); application.GetPlatform().SetClosestImageSize(closestImageSize); - ImageAttributes attrs; - const Vector2 requestedSize( 40, 30 ); - attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Vector2 requestedSize( 40, 30 ); + Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -427,7 +432,7 @@ int UtcDaliImageActorGetCurrentSize05(void) // Now complete the image load Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); Integration::ResourcePointer resourcePtr(bitmap); // reference it @@ -445,8 +450,7 @@ int UtcDaliImageActorGetCurrentSize05(void) application.GetPlatform().SetClosestImageSize(image2ClosestSize); const Vector2 requestedSize2( 100, 100 ); - attrs.SetSize( requestedSize2.width, requestedSize2.height ); - Image image2 = Image::New("image2.jpg", attrs); + Image image2 = ResourceImage::New("image.jpg", ImageDimensions( requestedSize2.x, requestedSize2.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); actor.SetImage(image2); application.SendNotification(); // Flush update messages @@ -459,7 +463,7 @@ int UtcDaliImageActorGetCurrentSize05(void) // Now complete the image load req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height ); Integration::ResourcePointer resourcePtr2(bitmap2); // reference it @@ -492,10 +496,8 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) Vector2 closestImageSize( 80, 45); application.GetPlatform().SetClosestImageSize(closestImageSize); - ImageAttributes attrs; - const Vector2 requestedSize( 40, 30 ); - attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Vector2 requestedSize( 40, 30 ); + Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -506,7 +508,7 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) // Now complete the image load Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); Integration::ResourcePointer resourcePtr(bitmap); // reference it @@ -533,7 +535,7 @@ int UtcDaliImageActorNaturalPixelAreaSize01(void) DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION ); // Clear the pixel area. Expect the whole image to be shown, filling the set size. - actor.ClearPixelArea(); + actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) ); application.SendNotification(); // Process event messages application.Render(); // Process LoadComplete DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION ); @@ -555,10 +557,8 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) Vector2 closestImageSize( 80, 45); application.GetPlatform().SetClosestImageSize(closestImageSize); - ImageAttributes attrs; - const Vector2 requestedSize( 40, 30 ); - attrs.SetSize( requestedSize.width, requestedSize.height ); - Image image = Image::New("image.jpg", attrs); + Vector2 requestedSize( 40, 30 ); + Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); @@ -569,7 +569,7 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) // Now complete the image load Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); Integration::ResourcePointer resourcePtr(bitmap); // reference it @@ -589,7 +589,7 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION ); // Clear the pixel area. Expect the whole image to be shown, changing actor size - actor.ClearPixelArea(); + actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) ); application.SendNotification(); // Process event messages application.Render(); // Process LoadComplete DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); @@ -606,14 +606,9 @@ int UtcDaliImageActorNaturalPixelAreaSize02(void) application.Render(); // Process LoadComplete DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION ); - // Use natural size - expect actor to change to pixel area - actor.SetToNaturalSize(); - application.SendNotification(); // Process event messages - application.Render(); // Process LoadComplete - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION ); - // Clearing pixel area should change actor size to image size - actor.ClearPixelArea(); + actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) ); application.SendNotification(); // Process event messages application.Render(); // Process LoadComplete DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); @@ -627,14 +622,14 @@ int UtcDaliImageActorDefaultProperties(void) TestApplication application; tet_infoline("Testing Dali::ImageActor DefaultProperties"); - BitmapImage img = BitmapImage::New( 10, 10 ); + BufferImage img = BufferImage::New( 10, 10 ); ImageActor actor = ImageActor::New( img ); std::vector indices; - indices.push_back(ImageActor::PIXEL_AREA ); - indices.push_back(ImageActor::STYLE ); - indices.push_back(ImageActor::BORDER ); - indices.push_back(ImageActor::IMAGE ); + indices.push_back(ImageActor::Property::PIXEL_AREA ); + indices.push_back(ImageActor::Property::STYLE ); + indices.push_back(ImageActor::Property::BORDER ); + indices.push_back(ImageActor::Property::IMAGE ); DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) ); @@ -650,11 +645,11 @@ int UtcDaliImageActorDefaultProperties(void) actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 )); ImageActor::PixelArea area( 1, 2, 3, 4 ); - actor.SetProperty(ImageActor::PIXEL_AREA, Property::Value(Rect(area))); + actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect(area))); - DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::PIXEL_AREA)); + DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA)); - Property::Value v = actor.GetProperty(ImageActor::PIXEL_AREA); + Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA); DALI_TEST_CHECK(v.Get >() == area); @@ -667,7 +662,7 @@ int UtcDaliImageActorUseImageAlpha01(void) tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - BitmapImage image = BitmapImage::New( 100, 50 ); + BufferImage image = BufferImage::New( 100, 50 ); ImageActor actor = ImageActor::New( image ); actor.SetBlendMode( BlendingMode::ON ); actor.SetSize(100, 50); @@ -689,7 +684,7 @@ int UtcDaliImageActorUseImageAlpha02(void) tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - BitmapImage image = BitmapImage::New( 100, 50 ); + BufferImage image = BufferImage::New( 100, 50 ); ImageActor actor = ImageActor::New( image ); actor.SetBlendMode( BlendingMode::OFF ); actor.SetSize(100, 50); @@ -711,7 +706,7 @@ int UtcDaliImageActorUseImageAlpha03(void) tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - BitmapImage image = BitmapImage::New( 100, 50 ); + BufferImage image = BufferImage::New( 100, 50 ); ImageActor actor = ImageActor::New( image ); actor.SetBlendMode( BlendingMode::AUTO ); actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5)); @@ -767,7 +762,7 @@ int UtcDaliImageActorUseImageAlpha05(void) tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGB888 ); + BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 ); ImageActor actor = ImageActor::New( image ); actor.SetBlendMode( BlendingMode::AUTO ); actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0)); @@ -784,31 +779,11 @@ int UtcDaliImageActorUseImageAlpha05(void) END_TEST; } -int UtcDaliImageActorClearPixelArea(void) -{ - TestApplication application; - - BitmapImage img = BitmapImage::New( 10, 10 ); - ImageActor actor = ImageActor::New( img ); - - DALI_TEST_CHECK( actor.IsPixelAreaSet() == false ); - - ImageActor::PixelArea area( 1, 2, 3, 4 ); - actor.SetPixelArea( area ); - - DALI_TEST_CHECK( actor.IsPixelAreaSet() == true ); - - actor.ClearPixelArea(); - - DALI_TEST_CHECK( actor.IsPixelAreaSet() == false ); - END_TEST; -} - int UtcDaliImageGetStyle(void) { TestApplication application; - Image image = Image::New(TestImageFilename); + Image image = ResourceImage::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); @@ -825,7 +800,7 @@ int UtcDaliImageSetNinePatchBorder(void) { TestApplication application; - Image image = Image::New(TestImageFilename); + Image image = ResourceImage::New(TestImageFilename); ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); @@ -882,24 +857,26 @@ int UtcDaliImageActorPropertyIndices(void) Property::IndexContainer indices; imageActor.GetPropertyIndices( indices ); - DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() ); - DALI_TEST_EQUALS( indices.size(), imageActor.GetPropertyCount(), TEST_LOCATION ); + DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() ); + DALI_TEST_EQUALS( indices.Size(), imageActor.GetPropertyCount(), TEST_LOCATION ); END_TEST; } 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 ); application.SendNotification(); application.Render(); - Property::Value imageMap = imageActor.GetProperty( ImageActor::IMAGE ); - DALI_TEST_CHECK( imageMap.HasKey( "filename" ) ); - DALI_TEST_EQUALS( imageMap.GetValue( "filename" ).Get< std::string >(), "MY_PATH", TEST_LOCATION ); + Property::Value imageProperty = imageActor.GetProperty( ImageActor::Property::IMAGE ); + Property::Map* imageMap = imageProperty.GetMap(); + DALI_TEST_CHECK( imageMap != NULL ); + DALI_TEST_CHECK( NULL != imageMap->Find( "filename" ) ); + DALI_TEST_EQUALS( (*imageMap)[ "filename" ].Get< std::string >(), "MY_PATH", TEST_LOCATION ); END_TEST; } @@ -914,14 +891,14 @@ int UtcDaliImageActorNinePatch01(void) tet_infoline("Test the successful loading of a nine-patch image\n"); platform.SetClosestImageSize(Vector2(4, 4)); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 ); memset( pixels, 0, 64 ); 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 ); @@ -967,7 +944,7 @@ int UtcDaliImageActorNinePatch02(void) 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 ); @@ -1007,14 +984,14 @@ int UtcDaliImageActorNinePatch03(void) tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n"); platform.SetClosestImageSize(Vector2(4, 4)); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); + Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN ); Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 ); memset( pixels, 0, 64 ); 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(); @@ -1062,7 +1039,7 @@ int UtcDaliImageActorNinePatch04(void) 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(); @@ -1097,7 +1074,7 @@ int UtcDaliImageActorGetNaturalSize(void) TestApplication application; // Standard image - BitmapImage img = BitmapImage::New( 10, 10 ); + BufferImage img = BufferImage::New( 10, 10 ); ImageActor actor = ImageActor::New( img ); DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) ); @@ -1110,3 +1087,567 @@ int UtcDaliImageActorGetNaturalSize(void) END_TEST; } + +int UtcDaliImageActorGetSortModifier(void) +{ + TestApplication application; + + tet_infoline("Testing Dali::ImageActor::GetSortModifier()"); + + ImageActor actor = ImageActor::New(); + Stage::GetCurrent().Add(actor); + + DALI_TEST_EQUALS(actor.GetSortModifier(), 0.0f, TEST_LOCATION); + + Stage::GetCurrent().Remove(actor); + END_TEST; +} + +int UtcDaliImageActorSetGetBlendMode(void) +{ + TestApplication application; + + tet_infoline("Testing Dali::ImageActor::SetBlendMode() / Dali::ImageActor::GetBlendMode()"); + + ImageActor actor = ImageActor::New(); + + actor.SetBlendMode( BlendingMode::OFF ); + DALI_TEST_CHECK( BlendingMode::OFF == actor.GetBlendMode() ); + + actor.SetBlendMode( BlendingMode::AUTO ); + DALI_TEST_CHECK( BlendingMode::AUTO == actor.GetBlendMode() ); + + actor.SetBlendMode( BlendingMode::ON ); + DALI_TEST_CHECK( BlendingMode::ON == actor.GetBlendMode() ); + END_TEST; +} + +int UtcDaliImageActorSetGetBlendFunc(void) +{ + TestApplication application; + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + + tet_infoline("Testing Dali::ImageActor::UtcDaliImageActorSetGetBlendFunc()"); + + BufferImage img = BufferImage::New( 1,1 ); + ImageActor actor = ImageActor::New( img ); + Stage::GetCurrent().Add( actor ); + application.SendNotification(); + application.Render(); + + // Test the defaults as documented int blending.h + { + BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO ); + BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO ); + BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO ); + BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO ); + actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorAlpha, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION ); + } + + // Set to non-default values + actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE, BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE ); + + // Test that Set was successful + { + BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO ); + BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO ); + BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO ); + BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO ); + actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION ); + } + + // Render & check GL commands + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION ); + DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION ); + DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION ); + DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION ); + + // Set using separate alpha settings + actor.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR, + BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA ); + + // Test that Set was successful + { + BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO ); + BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO ); + BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO ); + BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO ); + actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION ); + DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION ); + } + + // Render & check GL commands + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION ); + DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION ); + DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION ); + DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION ); + END_TEST; +} + +int UtcDaliImageActorSetGetAlpha(void) +{ + TestApplication application; + + tet_infoline("Testing Dali::ImageActor::SetGetAlpha()"); + + BufferImage img = BufferImage::New( 1,1 ); + ImageActor actor = ImageActor::New( img ); + Stage::GetCurrent().Add( actor ); + application.SendNotification(); + application.Render(); + + // use the image alpha on actor + actor.SetBlendMode(BlendingMode::ON); + + // Test that Set was successful + DALI_TEST_EQUALS( BlendingMode::ON, actor.GetBlendMode(), TEST_LOCATION ); + + // Now test that it can be set to false + actor.SetBlendMode(BlendingMode::OFF); + DALI_TEST_EQUALS(BlendingMode::OFF, actor.GetBlendMode(), TEST_LOCATION ); + END_TEST; +} + +int UtcDaliImageActorSetGetFilterModes(void) +{ + TestApplication application; + + tet_infoline("Testing Dali::ImageActor::SetFilterMode() / Dali::ImageActor::GetFilterMode()"); + + ImageActor actor = ImageActor::New(); + + FilterMode::Type minifyFilter = FilterMode::NEAREST; + FilterMode::Type magnifyFilter = FilterMode::NEAREST; + + // Default test + actor.GetFilterMode( minifyFilter, magnifyFilter ); + DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter ); + DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter ); + + // Default/Default + actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT ); + actor.GetFilterMode( minifyFilter, magnifyFilter ); + DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter ); + DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter ); + + // Nearest/Nearest + actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST ); + actor.GetFilterMode( minifyFilter, magnifyFilter ); + DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter ); + DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter ); + + // Linear/Linear + actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR ); + actor.GetFilterMode( minifyFilter, magnifyFilter ); + DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter ); + DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter ); + + // Nearest/Linear + actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR ); + actor.GetFilterMode( minifyFilter, magnifyFilter ); + DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter ); + DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter ); + + // Linear/Nearest + actor.SetFilterMode( FilterMode::LINEAR, FilterMode::NEAREST ); + actor.GetFilterMode( minifyFilter, magnifyFilter ); + DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter ); + DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter ); + + END_TEST; +} + +int UtcDaliImageActorSetFilterMode(void) +{ + TestApplication application; + + tet_infoline("Testing Dali::ImageActor::SetFilterMode()"); + + BufferImage img = BufferImage::New( 1,1 ); + ImageActor actor = ImageActor::New( img ); + + actor.SetSize(100.0f, 100.0f); + actor.SetParentOrigin(ParentOrigin::CENTER); + actor.SetAnchorPoint(AnchorPoint::CENTER); + + Stage::GetCurrent().Add(actor); + + /**************************************************************/ + + // Default/Default + TraceCallStack& texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + std::stringstream out; + + // Verify actor gl state + + // There are two calls to TexParameteri when the texture is first created + // Texture mag filter is not called as the first time set it uses the system default + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION); + + /**************************************************************/ + + // Default/Default + texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + + // Should not make any calls when settings are the same + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION); + + /**************************************************************/ + + // Nearest/Nearest + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION); + + /**************************************************************/ + + // Linear/Linear + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION); + + + /**************************************************************/ + + // Nearest/Linear + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + /**************************************************************/ + + // Default/Default + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + /**************************************************************/ + + // None/None + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + actor.SetFilterMode( FilterMode::NONE, FilterMode::NONE ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + /**************************************************************/ + + Stage::GetCurrent().Remove(actor); + + END_TEST; +} + +int UtcDaliImageActorSetShaderEffect(void) +{ + TestApplication application; + BufferImage img = BufferImage::New( 1,1 ); + ImageActor actor = ImageActor::New( img ); + Stage::GetCurrent().Add( actor ); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled(); + + application.GetGlAbstraction().EnableShaderCallTrace( true ); + + const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource"; + const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource"; + ShaderEffect effect = ShaderEffect::New(vertexShader, fragmentShader ); + DALI_TEST_CHECK( effect != actor.GetShaderEffect() ); + + actor.SetShaderEffect( effect ); + DALI_TEST_CHECK( effect == actor.GetShaderEffect() ); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled(); + DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION ); + + std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 ); + DALI_TEST_EQUALS( vertexShader, + actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION ); + std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 ); + DALI_TEST_EQUALS( fragmentShader, + actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliImageActorGetShaderEffect(void) +{ + TestApplication application; + ImageActor actor = ImageActor::New(); + + ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorGetShaderEffect-VertexSource", "UtcDaliImageActorGetShaderEffect-FragmentSource" ); + actor.SetShaderEffect(effect); + + DALI_TEST_CHECK(effect == actor.GetShaderEffect()); + END_TEST; +} + +int UtcDaliImageActorRemoveShaderEffect01(void) +{ + TestApplication application; + ImageActor actor = ImageActor::New(); + + ShaderEffect defaultEffect = actor.GetShaderEffect(); + + ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorRemoveShaderEffect-VertexSource", "UtcDaliImageActorRemoveShaderEffect-FragmentSource" ); + actor.SetShaderEffect(effect); + + DALI_TEST_CHECK(effect == actor.GetShaderEffect()); + + actor.RemoveShaderEffect(); + + DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect()); + END_TEST; +} + +int UtcDaliImageActorRemoveShaderEffect02(void) +{ + TestApplication application; + ImageActor actor = ImageActor::New(); + + ShaderEffect defaultEffect = actor.GetShaderEffect(); + + actor.RemoveShaderEffect(); + + DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect()); + END_TEST; +} + +int UtcDaliSetShaderEffectRecursively(void) +{ + TestApplication application; + /** + * create a tree + * actor1 + * actor2 actor4 + * actor3 imageactor1 + * imageactor2 + */ + BufferImage img = BufferImage::New( 1,1 ); + ImageActor actor1 = ImageActor::New( img ); + Actor actor2 = Actor::New(); + actor1.Add( actor2 ); + Actor actor3 = Actor::New(); + actor2.Add( actor3 ); + ImageActor imageactor1 = ImageActor::New( img ); + actor2.Add( imageactor1 ); + ImageActor imageactor2 = ImageActor::New( img ); + actor3.Add( imageactor2 ); + Actor actor4 = Actor::New(); + actor1.Add( actor4 ); + Stage::GetCurrent().Add( actor1 ); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled(); + + application.GetGlAbstraction().EnableShaderCallTrace( true ); + + const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource"; + const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource"; + // test with empty effect + ShaderEffect effect; + SetShaderEffectRecursively( actor1, effect ); + + effect = ShaderEffect::New(vertexShader, fragmentShader ); + + DALI_TEST_CHECK( effect != actor1.GetShaderEffect() ); + DALI_TEST_CHECK( effect != imageactor1.GetShaderEffect() ); + DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() ); + + SetShaderEffectRecursively( actor1, effect ); + DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() ); + DALI_TEST_CHECK( effect == imageactor2.GetShaderEffect() ); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled(); + DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION ); + + std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 ); + DALI_TEST_EQUALS( vertexShader, + actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION ); + std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 ); + DALI_TEST_EQUALS( fragmentShader, + actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION ); + + // remove from one that does not have shader + RemoveShaderEffectRecursively( actor4 ); + + // remove partially + RemoveShaderEffectRecursively( actor3 ); + DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() ); + DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() ); + + // test with empty actor just to check it does not crash + Actor empty; + SetShaderEffectRecursively( empty, effect ); + RemoveShaderEffectRecursively( empty ); + + // test with actor with no children just to check it does not crash + Actor loner = Actor::New(); + Stage::GetCurrent().Add( loner ); + SetShaderEffectRecursively( loner, effect ); + RemoveShaderEffectRecursively( loner ); + + END_TEST; +} + +int UtcDaliImageActorTestClearCache(void) +{ + // Testing the framebuffer state caching in frame-buffer-state-caching.cpp + TestApplication application; + + tet_infoline("Testing Dali::ImageActor::ClearCache()"); + + BufferImage img = BufferImage::New( 1,1 ); + ImageActor actor = ImageActor::New( img ); + + actor.SetParentOrigin(ParentOrigin::CENTER); + actor.SetAnchorPoint(AnchorPoint::CENTER); + + Stage::GetCurrent().Add(actor); + + /**************************************************************/ + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + // There should be a single call to Clear + DALI_TEST_EQUALS( application.GetGlAbstraction().GetClearCountCalled() , 1u, TEST_LOCATION ); + + // the last set clear mask should be COLOR, DEPTH & STENCIL which occurs at the start of each frame + GLbitfield mask = application.GetGlAbstraction().GetLastClearMask(); + DALI_TEST_CHECK( mask & GL_DEPTH_BUFFER_BIT ); + DALI_TEST_CHECK( mask & GL_STENCIL_BUFFER_BIT ); + DALI_TEST_CHECK( mask & GL_COLOR_BUFFER_BIT ); + + END_TEST; +}