Dali 3D User Interface Engine
utc-Dali-SuperBlurView.cpp
Go to the documentation of this file.
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.
24 
25 #include <dali.h>
28 
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31 
33 {
35 }
36 
38 {
40 }
41 
42 
43 namespace
44 {
45 const int BLUR_LEVELS = 3;
46 const int RENDER_FRAME_INTERVAL = 16;
47 
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 
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 
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
121  DALI_TEST_CHECK( registry );
122 
124  registry.ObjectCreatedSignal().Connect( &TestCallback );
125  {
127  }
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 
143 {
144  ToolkitTestApplication application;
145 
146  tet_infoline(" UtcDaliSuperBlurViewSetImage ");
147 
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);
160  END_TEST;
161 }
162 
164 {
165  ToolkitTestApplication application;
166 
167  tet_infoline(" UtcDaliSuperBlurViewSetGetBlurStrength ");
168 
171 
172  blurView.SetBlurStrength( 0.65f );
173  Wait(application);
175  END_TEST;
176 }
177 
179 {
180  ToolkitTestApplication application;
181 
182  tet_infoline(" UtcDaliSuperBlurViewGetBlurStrengthPropertyIndex ");
183 
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 
199 {
200  ToolkitTestApplication application;
201 
202  tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
203 
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 );
220 
221  END_TEST;
222 }
Dali Docs Home
Read more about Dali