-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2020 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 <iostream>
#include <stdlib.h>
#include <dali.h>
#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
using namespace Dali;
using namespace Dali::Toolkit;
{
const int BLUR_LEVELS = 3;
const int RENDER_FRAME_INTERVAL = 16;
-
+static const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
static bool gObjectCreatedCallBackCalled;
static void TestCallback(BaseHandle handle)
{
return time;
}
-Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
+Texture CreateSolidColorTexture( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
{
- BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
-
- // Create the image
- PixelBuffer* pixbuf = imageData.GetBuffer();
unsigned int size = width * height;
+ uint8_t* pixbuf = new uint8_t[size*4];
for( size_t i = 0; i < size; i++ )
- {
- pixbuf[i*4+0] = 0xFF * color.r;
- pixbuf[i*4+1] = 0xFF * color.g;
- pixbuf[i*4+2] = 0xFF * color.b;
- pixbuf[i*4+3] = 0xFF * color.a;
- }
- imageData.Update();
+ {
+ pixbuf[i*4+0] = 0xFF * color.r;
+ pixbuf[i*4+1] = 0xFF * color.g;
+ pixbuf[i*4+2] = 0xFF * color.b;
+ pixbuf[i*4+3] = 0xFF * color.a;
+ }
- application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
- application.SendNotification();
- application.Render(RENDER_FRAME_INTERVAL);
- application.Render(RENDER_FRAME_INTERVAL);
- application.SendNotification();
+ PixelData pixels = PixelData::New( pixbuf, size, width, height, Pixel::RGBA8888, PixelData::ReleaseFunction::DELETE_ARRAY );
- return imageData;
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() );
+ texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() );
+
+ return texture;
}
+
+class SignalHandler : public Dali::ConnectionTracker
+{
+public:
+ SignalHandler() :
+ mCalls( 0 )
+ {
+ }
+
+ void Callback( SuperBlurView handle )
+ {
+ mCalls++;
+ tet_infoline( "Signal called" );
+ }
+
+ unsigned int GetCalls() const
+ {
+ return mCalls;
+ }
+
+private:
+ unsigned int mCalls; ///< Keeps track of how many times the signal has been called.
+};
+
}//namespace
DALI_TEST_CHECK( blurView );
//Additional check to ensure object is created by checking if it's registered
- ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
+ ObjectRegistry registry = application.GetCore().GetObjectRegistry();
DALI_TEST_CHECK( registry );
gObjectCreatedCallBackCalled = false;
END_TEST;
}
-int UtcDaliSuperBlurViewSetImage(void)
+int UtcDaliSuperBlurViewCreate(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline(" UtcDaliSuperBlurViewNew ");
+
+ // Test default constructor.
+ SuperBlurView blurView;
+ DALI_TEST_CHECK( !blurView );
+
+ // Test object creation
+ TypeInfo type = TypeRegistry::Get().GetTypeInfo("SuperBlurView");
+ if( type )
+ {
+ Dali::BaseHandle handle = type.CreateInstance();
+ if( handle )
+ {
+ blurView = Dali::Toolkit::SuperBlurView::DownCast( handle );
+ }
+ }
+
+ DALI_TEST_CHECK( blurView );
+
+ END_TEST;
+}
+
+
+int UtcDaliSuperBlurViewSetTexture(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline(" UtcDaliSuperBlurViewSetTexture ");
+
+ SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
+ blurView.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
+
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 50, 50 );
+ blurView.SetTexture( inputTexture );
+ // start multiple guassian blur call, each guassian blur creates two render tasks
+ DALI_TEST_CHECK( application.GetScene().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
+
+ {
+ // create renderers for the original image and each blurred image
+ application.GetScene().Add( blurView );
+ Wait(application);
+ DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
+
+ Wait(application);
+ application.GetScene().Remove( blurView );
+ }
+
+ END_TEST;
+}
+
+int UtcDaliSuperBlurViewSetTexture2(void)
{
ToolkitTestApplication application;
+ Integration::Scene stage = application.GetScene();
- tet_infoline(" UtcDaliSuperBlurViewSetImage ");
+ tet_infoline(" UtcDaliSuperBlurViewSetTexture2 - test setting a second texture ");
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
- // create image actors for the original image and each blurred image
- DALI_TEST_CHECK( blurView.GetChildCount() == BLUR_LEVELS+1 );
+ blurView.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
- Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
- blurView.SetImage( inputImage );
+ tet_infoline("Call SetTexture and add blurview to stage");
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 50, 50 );
+ blurView.SetTexture( inputTexture );
+
+ // start multiple guassian blur call, each guassian blur creates two render tasks
+ DALI_TEST_CHECK( application.GetScene().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
+ {
+ // create renderers for the original image and each blurred image
+ stage.Add( blurView );
+ Wait(application);
+ DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
+
+ tet_infoline("Wait for a second to allow blur to finish");
+ Wait(application, 1000);
+
+ tet_infoline("Remove from stage");
+ application.GetScene().Remove( blurView );
+ }
+
+ tet_infoline("Test that there are no render tasks remaining");
+ DALI_TEST_EQUALS(blurView.GetRendererCount(), 0, TEST_LOCATION );
+
+ tet_infoline("Call SetTexture a second time and add blurview back to stage");
+ Texture inputTexture2 = CreateSolidColorTexture( application, Color::CYAN, 50, 50 );
+ blurView.SetTexture( inputTexture2 );
// start multiple guassian blur call, each guassian blur creates two render tasks
- DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == BLUR_LEVELS*2 + 1);
+ DALI_TEST_CHECK( application.GetScene().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
+
+ {
+ // create renderers for the original image and each blurred image
+ application.GetScene().Add( blurView );
+ Wait(application);
+ DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
+
+ tet_infoline("Wait for a second to allow blur to finish");
+ Wait(application, 1000);
+
+ tet_infoline("Remove from stage");
+ application.GetScene().Remove( blurView );
+ }
+
+ tet_infoline("Test that there are no render tasks remaining");
+ DALI_TEST_EQUALS(blurView.GetRendererCount(), 0, TEST_LOCATION );
+
END_TEST;
}
+
+int UtcDaliSuperBlurViewSetProperty(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
+
+ SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
+ // create renderers for the original image and each blurred image
+ application.GetScene().Add( blurView );
+ blurView.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
+
+ // Will create ResourceImage
+ blurView.SetProperty(SuperBlurView::Property::IMAGE_URL, TEST_IMAGE_FILE_NAME);
+ Wait(application);
+
+ // start multiple guassian blur call, each guassian blur creates two render tasks
+
+ unsigned int count = application.GetScene().GetRenderTaskList().GetTaskCount();
+ DALI_TEST_CHECK( count == 1+BLUR_LEVELS*2 );
+
+ Wait(application);
+
+ END_TEST;
+}
+
+
+int UtcDaliSuperBlurViewGetProperty(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
+
+ SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
+ blurView.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
+
+ blurView.SetProperty(SuperBlurView::Property::IMAGE_URL, TEST_IMAGE_FILE_NAME);
+ Wait(application);
+
+ // create renderers for the original image and each blurred image
+ application.GetScene().Add( blurView );
+
+ std::string imageUrl = blurView.GetProperty<std::string>( SuperBlurView::Property::IMAGE_URL );
+ DALI_TEST_EQUALS( imageUrl, TEST_IMAGE_FILE_NAME, TEST_LOCATION );
+
+ END_TEST;
+}
+
+
int UtcDaliSuperBlurViewSetGetBlurStrength(void)
{
ToolkitTestApplication application;
END_TEST;
}
-int UtcDaliSuperBlurViewGetBlurredImage(void)
+int UtcDaliSuperBlurViewGetBlurredTexture(void)
{
ToolkitTestApplication application;
- tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
+ tet_infoline( "UtcDaliSuperBlurViewGetBlurredTexture" );
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
- blurView.SetSize( 100.f,100.f );
- Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
- blurView.SetImage( inputImage );
+ blurView.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 100, 100 );
+ blurView.SetTexture( inputTexture );
Wait(application, 200); // Make sure all the gaussian blur finished
- Image image1 = blurView.GetBlurredImage( 1 );
- DALI_TEST_CHECK( image1 );
+ Texture texture1 = blurView.GetBlurredTexture( 1 );
+ DALI_TEST_CHECK( texture1 );
+
+ Texture texture2 = blurView.GetBlurredTexture( 2 );
+ DALI_TEST_EQUALS( texture2.GetWidth(), 25u, TEST_LOCATION );
+ DALI_TEST_EQUALS( texture2.GetHeight(), 25u, TEST_LOCATION );
+
+ Texture texture3 = blurView.GetBlurredTexture( 3 );
+ DALI_TEST_CHECK( texture3 );
+
+ END_TEST;
+}
+
+int UtcDaliSuperBlurViewBlurSignal(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline(" UtcDaliSuperBlurViewSignal ");
+
+ SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
+ blurView.SetProperty( Actor::Property::SIZE, Vector2(100.0f, 100.0f) );
+
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 50, 50 );
+ blurView.SetTexture( inputTexture );
+ // start multiple guassian blur call, each guassian blur creates two render tasks
+ DALI_TEST_CHECK( application.GetScene().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
+
+ SignalHandler signalHandler;
+ blurView.BlurFinishedSignal().Connect(&signalHandler, &SignalHandler::Callback);
- Image image2 = blurView.GetBlurredImage( 2 );
- DALI_TEST_CHECK( image2.GetWidth() == 25 );
- DALI_TEST_CHECK( image2.GetHeight() == 25 );
+ // create renderers for the original image and each blurred image
+ application.GetScene().Add( blurView );
+ Wait(application, 1000);
- Image image3 = blurView.GetBlurredImage( 3 );
- DALI_TEST_CHECK( FrameBufferImage::DownCast( image2 ) );
+ DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
+ //DALI_TEST_EQUALS(signalHandler.GetCalls(), 1, TEST_LOCATION);
END_TEST;
}