Merge "Stop using ImageActor in GaussianBlur, Bloom & SuperBlur" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-SuperBlurView.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 void utc_dali_toolkit_super_blur_view_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_super_blur_view_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42
43 namespace
44 {
45 const int BLUR_LEVELS = 3;
46 const int RENDER_FRAME_INTERVAL = 16;
47
48 static bool gObjectCreatedCallBackCalled;
49 static void TestCallback(BaseHandle handle)
50 {
51   gObjectCreatedCallBackCalled = true;
52 }
53
54 /*
55  * Simulate time passed by.
56  *
57  * @note this will always process at least 1 frame (1/60 sec)
58  *
59  * @param application Test application instance
60  * @param duration Time to pass in milliseconds.
61  * @return The actual time passed in milliseconds
62  */
63 int Wait(ToolkitTestApplication& application, int duration = 0)
64 {
65   int time = 0;
66
67   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
68   {
69     application.SendNotification();
70     application.Render(RENDER_FRAME_INTERVAL);
71     time += RENDER_FRAME_INTERVAL;
72   }
73
74   return time;
75 }
76
77 Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
78 {
79   BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
80
81   // Create the image
82   PixelBuffer* pixbuf = imageData.GetBuffer();
83   unsigned int size = width * height;
84
85   for( size_t i = 0; i < size; i++ )
86     {
87       pixbuf[i*4+0] = 0xFF * color.r;
88       pixbuf[i*4+1] = 0xFF * color.g;
89       pixbuf[i*4+2] = 0xFF * color.b;
90       pixbuf[i*4+3] = 0xFF * color.a;
91     }
92   imageData.Update();
93
94   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
95   application.SendNotification();
96   application.Render(RENDER_FRAME_INTERVAL);
97   application.Render(RENDER_FRAME_INTERVAL);
98   application.SendNotification();
99
100   return imageData;
101 }
102 }//namespace
103
104
105 int UtcDaliSuperBlurViewNew(void)
106 {
107   ToolkitTestApplication application;
108
109   tet_infoline(" UtcDaliSuperBlurViewNew ");
110
111   // Test default constructor.
112   SuperBlurView blurView;
113   DALI_TEST_CHECK( !blurView );
114
115   // Test object creation
116   blurView = SuperBlurView::New( BLUR_LEVELS );
117   DALI_TEST_CHECK( blurView );
118
119   //Additional check to ensure object is created by checking if it's registered
120   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
121   DALI_TEST_CHECK( registry );
122
123   gObjectCreatedCallBackCalled = false;
124   registry.ObjectCreatedSignal().Connect( &TestCallback );
125   {
126     SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
127   }
128   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
129
130   // Test copy constructor
131   SuperBlurView blurViewCopy2( blurView );
132   DALI_TEST_CHECK( blurViewCopy2 );
133
134   // Test down cast
135   Actor actorView;
136   actorView = blurView;
137   SuperBlurView downCastView = SuperBlurView::DownCast( actorView );
138   DALI_TEST_CHECK( downCastView );
139   END_TEST;
140 }
141
142 int UtcDaliSuperBlurViewSetImage(void)
143 {
144   ToolkitTestApplication application;
145
146   tet_infoline(" UtcDaliSuperBlurViewSetImage ");
147
148   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
149   blurView.SetSize( 100.f, 100.f );
150
151   Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
152   blurView.SetImage( inputImage );
153   // start multiple guassian blur call, each guassian blur creates two render tasks
154   DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
155
156   // create image actors for the original image and each blurred image
157   Stage::GetCurrent().Add( blurView );
158   Wait(application);
159   DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
160   END_TEST;
161 }
162
163 int UtcDaliSuperBlurViewSetGetBlurStrength(void)
164 {
165   ToolkitTestApplication application;
166
167   tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
168
169   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
170   DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.f, TEST_LOCATION );
171
172   blurView.SetBlurStrength( 0.65f );
173   Wait(application);
174   DALI_TEST_EQUALS(blurView.GetCurrentBlurStrength(), 0.65f, TEST_LOCATION );
175   END_TEST;
176 }
177
178 int UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex(void)
179 {
180   ToolkitTestApplication application;
181
182   tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
183
184   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
185   Property::Index blurPropertyIdx = blurView.GetBlurStrengthPropertyIndex();
186
187   float blurStrength;
188   (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
189   DALI_TEST_EQUALS(blurStrength, 0.f, TEST_LOCATION );
190
191   blurView.SetBlurStrength( 0.65f );
192   Wait(application);
193   (blurView.GetProperty( blurPropertyIdx )).Get(blurStrength);
194   DALI_TEST_EQUALS(blurStrength, 0.65f, TEST_LOCATION );
195   END_TEST;
196 }
197
198 int UtcDaliSuperBlurViewGetBlurredImage(void)
199 {
200   ToolkitTestApplication application;
201
202   tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
203
204   SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
205   blurView.SetSize( 100.f,100.f );
206   Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
207   blurView.SetImage( inputImage );
208
209   Wait(application, 200); // Make sure all the gaussian blur finished
210
211   Image image1 = blurView.GetBlurredImage( 1 );
212   DALI_TEST_CHECK( image1 );
213
214   Image image2 = blurView.GetBlurredImage( 2 );
215   DALI_TEST_EQUALS( image2.GetWidth(), 25u, TEST_LOCATION );
216   DALI_TEST_EQUALS( image2.GetHeight(), 25u, TEST_LOCATION );
217
218   Image image3 = blurView.GetBlurredImage( 3 );
219   DALI_TEST_CHECK( FrameBufferImage::DownCast( image3 ) );
220
221   END_TEST;
222 }