From b9ec9e194a957bb84ab887c263f50ee1a2ffb627 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Fri, 22 Apr 2016 17:33:27 +0100 Subject: [PATCH] (Automated Tests) Completely remove ImageActor & ShaderEffect test cases Drops line coverage from 83.5% to 81.2% and function coverage from 83.5% to 81.9% which is still above accepted minimum. Change-Id: I2cfc4ea07842dd8367a820c04d1df15d913522e0 --- .../src/dali-devel/utc-Dali-Scripting.cpp | 24 - automated-tests/src/dali/CMakeLists.txt | 2 - .../src/dali/utc-Dali-ImageActor.cpp | 1657 ----------------- .../src/dali/utc-Dali-ObjectRegistry.cpp | 60 - .../src/dali/utc-Dali-ShaderEffect.cpp | 940 ---------- .../src/dali/utc-Dali-TypeRegistry.cpp | 7 - 6 files changed, 2690 deletions(-) delete mode 100644 automated-tests/src/dali/utc-Dali-ImageActor.cpp delete mode 100644 automated-tests/src/dali/utc-Dali-ShaderEffect.cpp diff --git a/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp b/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp index e349e8221..f6e5b0505 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Scripting.cpp @@ -593,29 +593,6 @@ int UtcDaliScriptingNewImage10P(void) END_TEST; } -int UtcDaliScriptingNewShaderEffect(void) -{ - TestApplication application; - - Property::Map programMap; - programMap[ "vertexFilename" ] = "bump.vert"; - programMap[ "fragmentFilename" ] = "bump.frag"; - - Property::Map imageMap; - imageMap[ "filename" ] = "image.png"; - - Property::Map map; - map[ "image" ] = imageMap; - map[ "program" ] = programMap; - map[ "uLightPosition" ] = Vector3( 0.0, 0.0, -1.5); - map[ "uAmbientLight" ] = (int)10; - - ShaderEffect shader = NewShaderEffect( map ); - - DALI_TEST_CHECK( shader ); - END_TEST; -} - int UtcDaliScriptingNewActorNegative(void) { TestApplication application; @@ -663,7 +640,6 @@ int UtcDaliScriptingNewActorProperties(void) map[ "color" ] = Color::MAGENTA; map[ "name" ] = "MyActor"; map[ "colorMode" ] = "USE_PARENT_COLOR"; - map[ "inheritShaderEffect" ] = false; map[ "sensitive" ] = false; map[ "leaveRequired" ] = true; map[ "positionInheritance" ] = "DONT_INHERIT_POSITION"; diff --git a/automated-tests/src/dali/CMakeLists.txt b/automated-tests/src/dali/CMakeLists.txt index 8932108ac..112ef144b 100644 --- a/automated-tests/src/dali/CMakeLists.txt +++ b/automated-tests/src/dali/CMakeLists.txt @@ -28,7 +28,6 @@ SET(TC_SOURCES utc-Dali-Handle.cpp utc-Dali-HoverProcessing.cpp utc-Dali-Image.cpp - utc-Dali-ImageActor.cpp utc-Dali-IntrusivePtr.cpp utc-Dali-KeyEvent.cpp utc-Dali-Layer.cpp @@ -60,7 +59,6 @@ SET(TC_SOURCES utc-Dali-RenderTask.cpp utc-Dali-RenderTaskList.cpp utc-Dali-ResourceImage.cpp - utc-Dali-ShaderEffect.cpp utc-Dali-SignalTemplatesFunctors.cpp utc-Dali-SignalTemplates.cpp utc-Dali-Stage.cpp diff --git a/automated-tests/src/dali/utc-Dali-ImageActor.cpp b/automated-tests/src/dali/utc-Dali-ImageActor.cpp deleted file mode 100644 index c65465c2f..000000000 --- a/automated-tests/src/dali/utc-Dali-ImageActor.cpp +++ /dev/null @@ -1,1657 +0,0 @@ -/* - * Copyright (c) 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include "dali-test-suite-utils/dali-test-suite-utils.h" - -using namespace Dali; - -static const char* TestImageFilename = "icon_wrt.png"; - -void image_actor_test_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void image_actor_test_cleanup(void) -{ - test_return_value = TET_PASS; -} - - -int UtcDaliImageActorConstructorVoid(void) -{ - TestApplication application; - tet_infoline("Testing Dali::ImageActor::ImageActor()"); - - ImageActor actor; - - DALI_TEST_CHECK(!actor); - END_TEST; -} - -int UtcDaliImageActorDestructor(void) -{ - TestApplication application; - - ImageActor* actor = new ImageActor(); - delete actor; - - DALI_TEST_CHECK( true ); - END_TEST; -} - -int UtcDaliImageActorNew01(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::New()"); - - Image image = ResourceImage::New(TestImageFilename); - ImageActor actor = ImageActor::New(image); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - application.Render(); - application.SendNotification(); - - DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc)); - - DALI_TEST_CHECK(actor); - END_TEST; -} - -int UtcDaliImageActorNew02(void) -{ - TestApplication application; - tet_infoline("Negative test for Dali::ImageActor::New()"); - - Image image = ResourceImage::New("hopefullyThisImageFileDoesNotExist"); - ImageActor actor = ImageActor::New(image); - - DALI_TEST_CHECK(actor); - END_TEST; -} - -int UtcDaliImageActorDownCast(void) -{ - TestApplication application; - tet_infoline("Testing Dali::ImageActor::DownCast()"); - - Image image = ResourceImage::New("IncorrectImageName"); - ImageActor actor1 = ImageActor::New(image); - Actor anActor = Actor::New(); - anActor.Add(actor1); - - Actor child = anActor.GetChildAt(0); - ImageActor imageActor = DownCast< ImageActor >(child); - - DALI_TEST_CHECK(imageActor); - END_TEST; -} - -int UtcDaliImageActorDownCast2(void) -{ - TestApplication application; - tet_infoline("Testing Dali::ImageActor::DownCast()"); - - Actor actor1 = Actor::New(); - Actor anActor = Actor::New(); - anActor.Add(actor1); - - Actor child = anActor.GetChildAt(0); - ImageActor imageActor = ImageActor::DownCast(child); - DALI_TEST_CHECK(!imageActor); - - Actor unInitialzedActor; - imageActor = ImageActor::DownCast( unInitialzedActor ); - DALI_TEST_CHECK(!imageActor); - 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 = ResourceImage::New(TestImageFilename); - ImageActor actor = ImageActor::New(image); - - actor.SetStyle(ImageActor::STYLE_NINE_PATCH); - DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION ); - - Vector4 border(0.1,0.2,0.3,0.4); - actor.SetNinePatchBorder(border); - - DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION ); - DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION ); - DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION ); - DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorPixelArea(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea"); - - BufferImage img = BufferImage::New( 10, 10 ); - ImageActor actor = ImageActor::New( img ); - - ImageActor::PixelArea area( 1, 2, 3, 4 ); - actor.SetPixelArea( area ); - - 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_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION ); - DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION ); - DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION ); - DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION ); - 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, 0.0f ); - - 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); - BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height ); - ImageActor actor = ImageActor::New( image ); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION ); - - 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 ); - - size.x = 200.0f; - size.y = 200.0f; - actor.SetSize(size); - application.Render(8); - - // Test when a pixel area is set - ImageActor::PixelArea area(0, 0, 10, 10); - actor.SetPixelArea(area); - application.Render(9); - // natural size is not used as setsize is called - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION ); - - END_TEST; -} - - -int UtcDaliImageActorGetCurrentSize02(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load"); - - Vector2 initialImageSize(100, 50); - - application.GetPlatform().SetClosestImageSize(initialImageSize); - - Image image = ResourceImage::New("image.jpg"); - ImageActor actor = ImageActor::New( image ); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION ); - - // Now complete the image load - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height ); - - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION ); - - 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 ); - - END_TEST; -} - - -int UtcDaliImageActorGetCurrentSize03(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load"); - - const Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - 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); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Now complete the image load - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); - - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - END_TEST; -} - - -int UtcDaliImageActorGetCurrentSize04(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size"); - - const Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - 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); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Now complete the image load - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); - - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - 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 ); - - // Load a different image - - Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below - application.GetPlatform().SetClosestImageSize(image2ClosestSize); - - const Vector2 request2Size( 100, 100 ); - Image image2 = ResourceImage::New("image.jpg", ImageDimensions( request2Size.x, request2Size.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); - actor.SetImage(image2); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - // Ensure the actor size is kept - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION ); - - // Now complete the image load - req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height ); - - Integration::ResourcePointer resourcePtr2(bitmap2); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - // Ensure the actor size is kept - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION ); - - END_TEST; -} - - -int UtcDaliImageActorGetCurrentSize05(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete"); - - Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - 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); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Now complete the image load - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); - - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Load a different image - - Vector2 image2ClosestSize = Vector2(240, 150); - application.GetPlatform().SetClosestImageSize(image2ClosestSize); - - const Vector2 requestedSize2( 100, 100 ); - Image image2 = ResourceImage::New("image.jpg", ImageDimensions( requestedSize2.x, requestedSize2.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT ); - actor.SetImage(image2); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - // Ensure the actor size is kept - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION ); - - // Now complete the image load - req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height ); - - Integration::ResourcePointer resourcePtr2(bitmap2); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - application.SendNotification(); // Process event messages - application.Render(); // Process LoadComplete - - // Ensure the actor size gets the new image's natural size - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorNaturalPixelAreaSize01(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete"); - -//If an image is loaded without setting size, then the actor gets the natural size of the image -//Setting the pixel area will change the actor size to match the pixel area -//Setting the actor size will not change pixel area, and will cause the partial image to stretch -//to the new size. -//Clearing the pixel area will not change actor size, and the actor will show the whole image. - - - Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - 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); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Now complete the image load - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); - - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Set a pixel area on a naturally sized actor - expect the actor to take the - // pixel area as size - actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30)); - application.SendNotification(); // Process event messages - application.Render(); // Process LoadComplete - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION ); - - // Set a size. Expect the partial image to stretch to fill the new size - actor.SetSize(100, 100); - application.SendNotification(); // Process event messages - application.Render(); // Process LoadComplete - application.Render(); // Process LoadComplete - 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.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 ); - END_TEST; -} - -int UtcDaliImageActorNaturalPixelAreaSize02(void) -{ - TestApplication application; - tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete"); - -//If an image is loaded without setting size, then the actor gets the natural size of the image -//Setting the pixel area will change the actor size to match the pixel area -//Setting the actor size will not change pixel area, and will cause the partial image to stretch -//to the new size. -//Clearing the pixel area will not change actor size, and the actor will show the whole image. - - - Vector2 closestImageSize( 80, 45); - application.GetPlatform().SetClosestImageSize(closestImageSize); - - 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); - - application.SendNotification(); // Flush update messages - application.Render(); // Process resource request - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Now complete the image load - Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); - - Integration::ResourcePointer resourcePtr(bitmap); // reference it - application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); - application.Render(); // Process LoadComplete - application.SendNotification(); // Process event messages - application.GetPlatform().DiscardRequest(); // Ensure load request is discarded - application.GetPlatform().ClearReadyResources(); // - - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION ); - - // Set a pixel area on a naturally sized actor - expect the actor to take the - // pixel area as size - actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30)); - application.SendNotification(); // Process event messages - application.Render(); // Process LoadComplete - 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.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 ); - - // Set a size. Expect the partial image to stretch to fill the new size - actor.SetSize(100, 100); - application.SendNotification(); // Process event messages - application.Render(); // Process LoadComplete - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION ); - - // Set a pixel area, don't expect size to change - actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40)); - application.SendNotification(); // Process event messages - application.Render(); // Process LoadComplete - DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION ); - - // Clearing pixel area should change actor size to image size - 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 ); - END_TEST; -} - - - -int UtcDaliImageActorDefaultProperties(void) -{ - TestApplication application; - tet_infoline("Testing Dali::ImageActor DefaultProperties"); - - BufferImage img = BufferImage::New( 10, 10 ); - ImageActor actor = ImageActor::New( img ); - - std::vector indices; - 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() ) ); - - for(std::vector::iterator iter = indices.begin(); iter != indices.end(); ++iter) - { - DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) ); - DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) ); - DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) ); - DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds - } - - // set/get one of them - actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 )); - - ImageActor::PixelArea area( 1, 2, 3, 4 ); - actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect(area))); - - DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA)); - - Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA); - - DALI_TEST_CHECK(v.Get >() == area); - - END_TEST; -} - -int UtcDaliImageActorUseImageAlpha01(void) -{ - TestApplication application; - - tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - - BufferImage image = BufferImage::New( 100, 50 ); - ImageActor actor = ImageActor::New( image ); - actor.SetBlendMode( BlendingMode::ON ); - actor.SetSize(100, 50); - application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND) - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace(); - DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorUseImageAlpha02(void) -{ - TestApplication application; - - tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - - BufferImage image = BufferImage::New( 100, 50 ); - ImageActor actor = ImageActor::New( image ); - actor.SetBlendMode( BlendingMode::OFF ); - actor.SetSize(100, 50); - application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND) - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace(); - DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorUseImageAlpha03(void) -{ - TestApplication application; - - tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - - 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)); - actor.SetSize(100, 50); - application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND) - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace(); - DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorUseImageAlpha04(void) -{ - TestApplication application; - - tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - - FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 ); - RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList(); - RenderTask task = taskList.GetTask( 0u ); - task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected - application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); - application.SendNotification(); - application.Render(0); - - ImageActor actor = ImageActor::New( image ); - application.SendNotification(); - application.Render(0); - - actor.SetBlendMode( BlendingMode::ON ); - actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0)); - actor.SetSize(100, 50); - application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND) - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace(); - DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorUseImageAlpha05(void) -{ - TestApplication application; - - tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()"); - - 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)); - actor.SetSize(100, 50); - application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND) - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace(); - DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorGetStyle(void) -{ - TestApplication application; - - Image image = ResourceImage::New(TestImageFilename); - ImageActor actor = ImageActor::New(image); - - actor.SetStyle(ImageActor::STYLE_NINE_PATCH); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - - DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorSetNinePatchBorder(void) -{ - TestApplication application; - - Image image = ResourceImage::New(TestImageFilename); - ImageActor actor = ImageActor::New(image); - - actor.SetStyle(ImageActor::STYLE_NINE_PATCH); - DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION ); - - actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f)); - - DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION ); - DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION ); - DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION ); - DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION ); - END_TEST; -} - -int UtcDaliImageActorNewNull(void) -{ - TestApplication application; - - ImageActor actor = ImageActor::New(Image()); - - DALI_TEST_CHECK(actor); - END_TEST; -} - -int UtcDaliImageActorNewNullWithArea(void) -{ - TestApplication application; - - ImageActor::PixelArea area( 1, 2, 3, 4 ); - - ImageActor actor = ImageActor::New(Image(), area); - - DALI_TEST_CHECK(actor); - END_TEST; -} - -int UtcDaliImageActorSetImage(void) -{ - TestApplication application; - - ImageActor actor = ImageActor::New(Image()); - - DALI_TEST_CHECK(actor); - - actor.SetImage( Image() ); - - DALI_TEST_CHECK(!actor.GetImage()); - END_TEST; -} - -int UtcDaliImageActorPropertyIndices(void) -{ - TestApplication application; - Actor basicActor = Actor::New(); - ImageActor imageActor = ImageActor::New(); - - Property::IndexContainer indices; - imageActor.GetPropertyIndices( indices ); - 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 = ResourceImage::New( "MY_PATH" ); - ImageActor imageActor = ImageActor::New( image ); - - Stage::GetCurrent().Add( imageActor ); - application.SendNotification(); - application.Render(); - - 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; -} - -int UtcDaliImageActorNinePatch01(void) -{ - TestApplication application; - TestPlatformAbstraction& platform = application.GetPlatform(); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - TraceCallStack& textureTrace = glAbstraction.GetTextureTrace(); - TraceCallStack& drawTrace = glAbstraction.GetDrawTrace(); - - 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, ResourcePolicy::OWNED_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 = ResourceImage::New( "blah.#.png" ); - DALI_TEST_CHECK( ninePatchImage ); - - ImageActor imageActor = ImageActor::New( ninePatchImage ); - DALI_TEST_CHECK( imageActor ); - Stage::GetCurrent().Add( imageActor ); - - drawTrace.Reset(); - textureTrace.Reset(); - drawTrace.Enable(true); - textureTrace.Enable(true); - glAbstraction.ClearBoundTextures(); - std::vector ids; - ids.push_back( 23 ); - glAbstraction.SetNextTextureIds( ids ); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) ); - typedef std::vector TexVec; - const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0); - DALI_TEST_CHECK( textures.size() > 0 ); - if( textures.size() > 0 ) - { - DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION ); - } - - END_TEST; -} - - -int UtcDaliImageActorNinePatch02(void) -{ - TestApplication application; - TestPlatformAbstraction& platform = application.GetPlatform(); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - TraceCallStack& textureTrace = glAbstraction.GetTextureTrace(); - TraceCallStack& drawTrace = glAbstraction.GetDrawTrace(); - - tet_infoline("Test the failed loading of a nine-patch image\n"); - - platform.SetClosestImageSize(Vector2(0, 0)); - Integration::ResourcePointer resourcePtr; - platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - - Image ninePatchImage = ResourceImage::New( "blah.#.png" ); - DALI_TEST_CHECK( ninePatchImage ); - - ImageActor imageActor = ImageActor::New( ninePatchImage ); - DALI_TEST_CHECK( imageActor ); - Stage::GetCurrent().Add( imageActor ); - - drawTrace.Reset(); - textureTrace.Reset(); - drawTrace.Enable(true); - textureTrace.Enable(true); - glAbstraction.ClearBoundTextures(); - std::vector ids; - ids.push_back( 23 ); - glAbstraction.SetNextTextureIds( ids ); - - application.SendNotification(); - application.Render(); - - // Check that nothing was drawn. - DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawElements" ) ); - typedef std::vector TexVec; - const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0); - DALI_TEST_CHECK( textures.size() == 0u ); - - END_TEST; -} - - -int UtcDaliImageActorNinePatch03(void) -{ - TestApplication application; - TestPlatformAbstraction& platform = application.GetPlatform(); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - TraceCallStack& textureTrace = glAbstraction.GetTextureTrace(); - TraceCallStack& drawTrace = glAbstraction.GetDrawTrace(); - - 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, ResourcePolicy::OWNED_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 = ResourceImage::New( "blah.#.png" ); - DALI_TEST_CHECK( ninePatchImage ); - - ImageActor imageActor = ImageActor::New(); - DALI_TEST_CHECK( imageActor ); - Stage::GetCurrent().Add( imageActor ); - - imageActor.SetImage( ninePatchImage ); - - drawTrace.Reset(); - textureTrace.Reset(); - drawTrace.Enable(true); - textureTrace.Enable(true); - glAbstraction.ClearBoundTextures(); - std::vector ids; - ids.push_back( 23 ); - glAbstraction.SetNextTextureIds( ids ); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) ); - typedef std::vector TexVec; - const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0); - DALI_TEST_CHECK( textures.size() > 0 ); - if( textures.size() > 0 ) - { - DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION ); - } - - END_TEST; -} - - -int UtcDaliImageActorNinePatch04(void) -{ - TestApplication application; - TestPlatformAbstraction& platform = application.GetPlatform(); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - TraceCallStack& textureTrace = glAbstraction.GetTextureTrace(); - TraceCallStack& drawTrace = glAbstraction.GetDrawTrace(); - - tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n"); - - platform.SetClosestImageSize(Vector2(0, 0)); - Integration::ResourcePointer resourcePtr; - platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); - - Image ninePatchImage = ResourceImage::New( "blah.#.png" ); - DALI_TEST_CHECK( ninePatchImage ); - - ImageActor imageActor = ImageActor::New(); - DALI_TEST_CHECK( imageActor ); - Stage::GetCurrent().Add( imageActor ); - - imageActor.SetImage( ninePatchImage ); - - drawTrace.Reset(); - textureTrace.Reset(); - drawTrace.Enable(true); - textureTrace.Enable(true); - glAbstraction.ClearBoundTextures(); - std::vector ids; - ids.push_back( 23 ); - glAbstraction.SetNextTextureIds( ids ); - - application.SendNotification(); - application.Render(); - - // Check that nothing was drawn. - DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawElements" ) ); - typedef std::vector TexVec; - const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0); - DALI_TEST_CHECK( textures.size() == 0u ); - - END_TEST; -} - -int UtcDaliImageActorGetNaturalSize(void) -{ - TestApplication application; - - // Standard image - BufferImage img = BufferImage::New( 10, 10 ); - ImageActor actor = ImageActor::New( img ); - - DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) ); - - // Pixel area set - ImageActor::PixelArea area( 1, 2, 3, 4 ); - actor.SetPixelArea( area ); - - DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) ); - - 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; -} diff --git a/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp b/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp index fa110dc07..8e5ebc178 100644 --- a/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp +++ b/automated-tests/src/dali/utc-Dali-ObjectRegistry.cpp @@ -124,30 +124,8 @@ struct TestAnimationCallback bool& mSignalVerified; }; -struct TestShaderEffectCallback -{ - TestShaderEffectCallback(bool& signalReceived) - : mSignalVerified(signalReceived) - { - } - void operator()(BaseHandle object) - { - tet_infoline("Verifying TestShaderEffectCallback()"); - ShaderEffect actor = ShaderEffect::DownCast(object); - if(actor) - { - mSignalVerified = true; - } - } - bool& mSignalVerified; -}; - - } // anonymous namespace - - - int UtcDaliObjectRegistryGet(void) { TestApplication application; @@ -272,41 +250,3 @@ int UtcDaliObjectRegistrySignalAnimationCreated(void) DALI_TEST_CHECK( test.mSignalVerified ); END_TEST; } - -int UtcDaliObjectRegistrySignalShaderEffectCreated(void) -{ - TestApplication application; - ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); - - static const char* VertexSource = - "void main()\n" - "{\n" - " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n" - " vTexCoord = aTexCoord;\n" - "}\n"; - - static const char* FragmentSource = - "void main()\n" - "{\n" - " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n" - "}\n"; - - bool verified = false; - TestShaderEffectCallback test(verified); - - Dali::RefObject* objectPointer = NULL; - TestObjectDestroyedCallback test2(verified, objectPointer); - - registry.ObjectCreatedSignal().Connect(&application, test); - registry.ObjectDestroyedSignal().Connect(&application, test2); - - { - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( test.mSignalVerified ); - - verified = false; - objectPointer = effect.GetObjectPtr(); - } - DALI_TEST_CHECK( test.mSignalVerified ); - END_TEST; -} diff --git a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp deleted file mode 100644 index 937f4aba4..000000000 --- a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp +++ /dev/null @@ -1,940 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include -#include - -using namespace Dali; - -void utc_dali_shader_effect_startup(void) -{ - test_return_value = TET_UNDEF; -} - -void utc_dali_shader_effect_cleanup(void) -{ - test_return_value = TET_PASS; -} - -namespace -{ - -static const char* VertexSource = -"This is a custom vertex shader\n" -"made on purpose to look nothing like a normal vertex shader inside dali\n"; - -static const char* FragmentSource = -"This is a custom fragment shader\n" -"made on purpose to look nothing like a normal fragment shader inside dali\n"; - -const int GETSOURCE_BUFFER_SIZE = 0x10000; - - -struct TestConstraintToVector3 -{ - TestConstraintToVector3(Vector3 target) - : mTarget(target) - { - } - - void operator()( Vector3& current, const PropertyInputContainer& /* inputs */ ) - { - current = mTarget; - } - - Vector3 mTarget; -}; - -struct TestConstraintFromPositionToVector3 -{ - TestConstraintFromPositionToVector3() - { - } - - void operator()( Vector3& current, const PropertyInputContainer& inputs ) - { - current = inputs[0]->GetVector3(); - } -}; - -struct TestConstraintToVector3Double -{ - TestConstraintToVector3Double(Vector3 target) - : mTarget(target) - { - } - - void operator()( Vector3& current, const PropertyInputContainer& /* inputs */ ) - { - current = mTarget * 2.0f; - } - - Vector3 mTarget; -}; - -static const char* TestImageFilename = "icon_wrt.png"; - -Integration::Bitmap* CreateBitmap( unsigned int imageHeight, unsigned int imageWidth, unsigned int initialColor ) -{ - Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN ); - Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, imageWidth,imageHeight,imageWidth,imageHeight ); - unsigned int bytesPerPixel = GetBytesPerPixel( Pixel::RGBA8888 ); - - memset( pixbuffer, initialColor , imageHeight*imageWidth*bytesPerPixel); - - return bitmap; -} - -} // anon namespace - - -int UtcDaliShaderEffectMethodNew01(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK(effect); - END_TEST; -} - -int UtcDaliShaderEffectMethodNew02(void) -{ - TestApplication application; - - ShaderEffect effect; - - try - { - // New must be called to create a ShaderEffect or it wont be valid. - effect.SetUniform( "uUniform", 0 ); - DALI_TEST_CHECK( false ); - } - catch (Dali::DaliException& e) - { - // Tests that a negative test of an assertion succeeds - DALI_TEST_PRINT_ASSERT( e ); - DALI_TEST_CHECK( !effect ); - } - END_TEST; -} - -int UtcDaliShaderEffectMethodNew05(void) -{ - TestApplication application; - - // heap constructor / destructor - DefaultFunctionCoverage shaderEffect; - - END_TEST; -} - -int UtcDaliShaderEffectMethodDownCast(void) -{ - TestApplication application; - tet_infoline("Testing Dali::ShaderEffect::DownCast()"); - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - - BaseHandle object(effect); - - ShaderEffect effect2 = ShaderEffect::DownCast(object); - DALI_TEST_CHECK(effect2); - - ShaderEffect effect3 = DownCast< ShaderEffect >(object); - DALI_TEST_CHECK(effect3); - - BaseHandle unInitializedObject; - ShaderEffect effect4 = ShaderEffect::DownCast(unInitializedObject); - DALI_TEST_CHECK(!effect4); - - ShaderEffect effect5 = DownCast< ShaderEffect >(unInitializedObject); - DALI_TEST_CHECK(!effect5); - END_TEST; -} - -int UtcDaliShaderEffectMethodDelete01(void) -{ - TestApplication application; - - // get the default shaders built, this is not required but makes it - // easier to debug the TET case and isolate the custom shader compilation. - application.SendNotification(); - application.Render(); - - GLuint beforeShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled(); - - // create a new shader effect - // the vertex and fragment shader will be cached in the ShaderFactory - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - - // destroy the shader effect - effect.Reset(); - - // Create the same shader effect again, this should now use the cached version - // held in the shader factory - effect= ShaderEffect::New( VertexSource, FragmentSource ); - - // Compile the shader effect - application.SendNotification(); - application.Render(); - - GLuint lastShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled(); - // no shaders were compiled as they are now compiled on demand and this shader was not used - DALI_TEST_EQUALS( beforeShaderCompiled, lastShaderCompiled, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliShaderEffectMethodSetUniformFloat(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uFloat", 1.0f ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uFloat", 1.0f ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodSetUniformVector2(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec2", Vector2( 2.0f, 3.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec2", Vector2( 2.0f, 3.0f ) ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodSetUniformVector3(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodSetUniformVector4(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodSetUniformMatrix(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uModelView", Matrix::IDENTITY ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uModelView", Matrix::IDENTITY ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodSetUniformMatrix3(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - Matrix3 matIdentity(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); - effect.SetUniform( "uMatrix3", matIdentity ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue("uMatrix3", matIdentity) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodSetUniformViewport(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - effect.SetUniform( "uVec2", Vector2( 0.0f, 0.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION ); - effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION ); - - application.SendNotification(); - application.Render(); - - DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2", Vector2( 0.0f, 0.0f ) ) ); //ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION deprecated - DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2Dir", Vector2( 1.0f, 2.0f ) ) ); //ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION deprecated - - // change coordinate types - effect.SetUniform( "uVec2", Vector2( 0.1f, 0.2f ), ShaderEffect::COORDINATE_TYPE_DEFAULT ); - effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION ); - actor.SetPixelArea( ImageActor::PixelArea( 0, 0, 10, 10 ) ); - - application.SendNotification(); - application.Render(); - - Vector2 outValue; - application.GetGlAbstraction().GetUniformValue( "uVec2", outValue ); - DALI_TEST_EQUALS( outValue, Vector2( 0.1f, 0.2f ), TEST_LOCATION ); - - application.GetGlAbstraction().GetUniformValue( "uVec2Dir", outValue ); - DALI_TEST_EQUALS( outValue, Vector2( 1.0f, 2.0f ), TEST_LOCATION ); //ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION deprecated - - END_TEST; -} - -int UtcDaliShaderEffectMethodSetEffectImage(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - effect.SetEffectImage(image); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - - // Can't test much else with current test suite - really need to have a - // shader compiler. - END_TEST; -} - -int UtcDaliShaderEffectMethodSetEffectImageAndDelete(void) -{ - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - - BufferImage effectImage = CreateBufferImage(); - effect.SetEffectImage(effectImage); - - ImageActor actor = ImageActor::New(); - - actor.SetShaderEffect(effect); - effect.Reset(); - - Stage::GetCurrent().Add(actor); - - // do an update / render cycle - application.SendNotification(); - application.Render(16); - application.SendNotification(); - application.Render(16); - application.SendNotification(); - application.Render(16); - - printf("removing image actor from stage and Reseting handle\n"); - Stage::GetCurrent().Remove(actor); - actor.Reset(); - - tet_printf("### Update & Render \n"); - - application.SendNotification(); - application.Render(16); - - tet_printf("#### Update Only \n"); - - tet_printf("effectImage.Reset \n"); - - // this releases the effect texture resource, - // Update will send a DispatchDiscardTexture message to render - effectImage.Reset(); - application.SendNotification(); - application.UpdateOnly(16); - - tet_printf("#### Update Only \n"); - - // at this point shader is deleted, during clear discard queue - // and it sends a Shader:: DispatchRemoveObserver message to render thread - application.UpdateOnly(16); - - tet_printf("#### Render Only \n"); - // This is where it used to crash, there is a message in the queue to perform DispatchDiscardTexture - // which tries to call observer->TextureDiscarded, where observer == shader that was deleted - // in previous update. - application.RenderOnly(); - - - // process the discard texture message - application.RenderOnly(); - application.SendNotification(); - application.Render(16); - - tet_result(TET_PASS); - - END_TEST; -} - -int UtcDaliShaderEffectMethodApplyConstraint(void) -{ - // Test whether Shader's uniform can be constrained to a stationary constraint. - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - - application.SendNotification(); - application.Render(); - - // Test effects of SetUniform... - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - - Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - constraint.Apply(); - - application.SendNotification(); - application.Render(); - - // Test effects of Constraint. - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodApplyConstraintOffStage(void) -{ - // The same test as UtcDaliShaderEffectMethodApplyConstraint, - // except the Actor is off-stage when the constraint is applied to the shader - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - // Note - Do not add actor to stage here - - Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - - Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - constraint.Apply(); - - // Note - Now we add the actor (after constraint was applied to the shader) - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - - // Test effects of Constraint. - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodApplyConstraintFromActor(void) -{ - // Test whether Shader's uniform can be constrained to Actor's position. - TestApplication application; - - const Vector3 targetPosition = Vector3( 100.0f, 70.0f, 20.0f); - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetPosition(targetPosition); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - - Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintFromPositionToVector3() ); - constraint.AddSource( Source( actor, Actor::Property::POSITION ) ); - constraint.Apply(); - - application.SendNotification(); - application.Render(); - - // Test effects of Constraint. - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", targetPosition ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void) -{ - // Test whether Shader's uniform can be constrained to Actor's position. - // While Actor's position is constrained to another point * 2.0f - TestApplication application; - - const Vector3 targetPosition = Vector3( 25.0f, 36.0f, 49.0f ); - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetPosition(Vector3( 100.0f, 70.0f, 20.0f)); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - - Constraint shaderConstraint = Constraint::New( effect, uVecProperty, TestConstraintFromPositionToVector3() ); - shaderConstraint.AddSource( Source(actor, Actor::Property::POSITION) ); - shaderConstraint.Apply(); - - Constraint actorConstraint = Constraint::New( actor, Actor::Property::POSITION, TestConstraintToVector3Double(targetPosition) ); - actorConstraint.Apply(); - - application.SendNotification(); - application.Render(); - - // Test effects of Constraint. - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", targetPosition * 2.0f ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodRemoveConstraints(void) -{ - // Test if constrains can be removed before they are ever applyed. - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - - application.SendNotification(); - application.Render(); - - // Test effects of SetUniform... - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - - Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - constraint.Apply(); - - // Remove the constraints - effect.RemoveConstraints(); - - application.SendNotification(); - application.Render(); - - // Test effects of Constraint. - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - END_TEST; -} - -int UtcDaliShaderEffectMethodRemoveConstraints2(void) -{ - // Test whether Shader's uniform constrains can be removed after they are applyed. - TestApplication application; - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - - effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ); - - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - Property::Index uVecProperty = effect.GetPropertyIndex("uVec3"); - - application.SendNotification(); - application.Render(); - - // Test effects of SetUniform... - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - - Constraint constraint = Constraint::New( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) ); - constraint.Apply(); - - application.SendNotification(); - application.Render(); - - // Reset the value and remove the constraints - effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ); - effect.RemoveConstraints(); - - application.SendNotification(); - application.Render(); - - // Test effects of Constraint. - DALI_TEST_CHECK( - application.GetGlAbstraction().CheckUniformValue( - "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) ); - END_TEST; -} - -int UtcDaliShaderEffectPropertyIndices(void) -{ - TestApplication application; - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - - Property::IndexContainer indices; - effect.GetPropertyIndices( indices ); - DALI_TEST_CHECK( indices.Size() ); - DALI_TEST_EQUALS( indices.Size(), effect.GetPropertyCount(), TEST_LOCATION ); - END_TEST; -} - -int UtcDaliShaderBinaries(void) -{ - TestApplication application; - // these will not affect the "first round" of dali render as core is already initialized and it has queried the defaults - application.GetGlAbstraction().SetBinaryFormats( 1 ); - application.GetGlAbstraction().SetNumBinaryFormats( 1 ); - application.GetGlAbstraction().SetProgramBinaryLength( 1 ); - - GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled(); - - ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); - DALI_TEST_CHECK( effect ); - - BufferImage image = CreateBufferImage(); - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(16); - // binary was not requested by DALi - DALI_TEST_CHECK( !(application.GetGlAbstraction().GetProgramBinaryCalled()) ); - - GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled(); - - // check that the shader was compiled - DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION ); - - // simulate context loss to get core to re-initialize its GL - application.GetCore().ContextDestroyed(); - application.GetCore().ContextCreated(); - - application.SendNotification(); - application.Render(16); - - // shader is recompiled - GLuint finalShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled(); - // check that the shader was compiled - DALI_TEST_EQUALS( lastShaderCompiledAfter + 2, finalShaderCompiled, TEST_LOCATION ); - - // binary was requested by DALi - DALI_TEST_CHECK( application.GetGlAbstraction().GetProgramBinaryCalled() ); - - END_TEST; -} - -int UtcDaliShaderEffectFromPropertiesP(void) -{ - TestApplication application; - tet_infoline("UtcDaliShaderEffectFromProperties01()"); - - std::string fragmentShaderPrefix = "#define TEST_FS 1\n#extension GL_OES_standard_derivatives : enable"; - std::string vertexShaderPrefix = "#define TEST_VS 1"; - std::string vertexShader(VertexSource); - std::string fragmentShader(FragmentSource); - - // Call render to compile default shaders. - application.SendNotification(); - application.Render(); - - GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled(); - - // create from type registry - - TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" ); - DALI_TEST_CHECK( typeInfo ); - ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() ); - DALI_TEST_CHECK( effect ); - - Property::Value programValue = Property::Value(Property::MAP); - Property::Map* programMap = programValue.GetMap(); - DALI_TEST_CHECK( programMap ); - - programMap->Insert("vertex", vertexShader); - programMap->Insert("fragment", fragmentShader); - - programMap->Insert("vertexPrefix", vertexShaderPrefix); - programMap->Insert("fragmentPrefix", fragmentShaderPrefix); - - effect.SetProperty(effect.GetPropertyIndex("program"), programValue); - - Property::Value imageValue = Property::Value(Property::MAP); - Property::Map* imageMap = imageValue.GetMap(); - DALI_TEST_CHECK( imageMap ); - imageMap->Insert("filename", Property::Value(TestImageFilename)); - effect.SetProperty(effect.GetPropertyIndex("image"), imageValue); - - // do a update & render to get the image request - application.SendNotification(); - application.Render(); - - Integration::ResourceRequest* request = application.GetPlatform().GetRequest(); - // create the image - Integration::Bitmap* bitmap = CreateBitmap( 10, 10, 0xFF ); - Integration::ResourcePointer resourcePtr(bitmap); - TestPlatformAbstraction& platform = application.GetPlatform(); - platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr); - - BufferImage image(CreateBufferImage()); - ImageActor actor = ImageActor::New( image ); - actor.SetSize( 100.0f, 100.0f ); - actor.SetName("TestImageFilenameActor"); - actor.SetShaderEffect(effect); - Stage::GetCurrent().Add(actor); - - application.SendNotification(); - application.Render(); - GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled(); - - // we should have compiled 2 shaders. - DALI_TEST_EQUALS(lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION ); - - std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 ); - DALI_TEST_EQUALS( vertexShaderPrefix, actualVertexShader.substr( 0, vertexShaderPrefix.length() ), TEST_LOCATION ); - DALI_TEST_EQUALS( vertexShader, actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION ); - - std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 ); - DALI_TEST_EQUALS( fragmentShaderPrefix, actualFragmentShader.substr( 0, fragmentShaderPrefix.length() ), TEST_LOCATION ); - DALI_TEST_EQUALS( fragmentShader, actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliShaderEffectFromPropertiesN(void) -{ - try - { - TestApplication application; - tet_infoline("UtcDaliShaderEffectFromProperties02()"); - - // Call render to compile default shaders. - application.SendNotification(); - application.Render(); - - // create from type registry (currently only way to get ShaderEffect with no shader setup in constructor - TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" ); - DALI_TEST_CHECK( typeInfo ); - ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() ); - DALI_TEST_CHECK( effect ); - - Property::Value programValue = Property::Value(Property::MAP); - Property::Map* programMap = programValue.GetMap(); - DALI_TEST_CHECK( programMap ); - - programMap->Insert("vertex", std::string(VertexSource)); - programMap->Insert("fragment", std::string(FragmentSource)); - - // use wrong index on purpose - effect.SetProperty(effect.GetPropertyIndex("program") + 1, programValue ); - - tet_result( TET_FAIL ); - } - catch(Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - } - END_TEST; -} - -int UtcDaliShaderEffectFromProperties2N(void) -{ - try - { - TestApplication application; - tet_infoline("UtcDaliShaderEffectFromProperties03()"); - - // Call render to compile default shaders. - application.SendNotification(); - application.Render(); - - // create from type registry (currently only way to get ShaderEffect with no shader setup in constructor - TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" ); - DALI_TEST_CHECK( typeInfo ); - ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() ); - DALI_TEST_CHECK( effect ); - - // dont set unknown - effect.SetProperty( effect.GetPropertyIndex("geometryHints"), "HINT_2" ); - - tet_result( TET_FAIL ); - } - catch(Dali::DaliException& e) - { - DALI_TEST_PRINT_ASSERT( e ); - } - END_TEST; -} diff --git a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp index c0fc5cd58..53a22d002 100644 --- a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp +++ b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp @@ -613,13 +613,6 @@ int UtcDaliTypeRegistryGetTypeInfoFromTypeNameP(void) an.Play(); application.Render(); - // shader effect - type = registry.GetTypeInfo( "ShaderEffect" ); - DALI_TEST_CHECK( type ); - ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance()); - DALI_TEST_CHECK( ef ); - application.Render(); - END_TEST; } -- 2.34.1