Merge "Outline effect has been fixed to be not front cropped." into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-application.cpp
1 /*
2  * Copyright (c) 2017 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 "test-application.h"
19
20 namespace Dali
21 {
22
23
24 TestApplication::TestApplication( size_t surfaceWidth,
25                                   size_t surfaceHeight,
26                                   float  horizontalDpi,
27                                   float  verticalDpi,
28                                   ResourcePolicy::DataRetention policy)
29 : mCore( NULL ),
30   mSurfaceWidth( surfaceWidth ),
31   mSurfaceHeight( surfaceHeight ),
32   mFrame( 0u ),
33   mDpi( horizontalDpi, verticalDpi ),
34   mLastVSyncTime(0u),
35   mDataRetentionPolicy( policy )
36 {
37   Initialize();
38 }
39
40 TestApplication::TestApplication( bool   initialize,
41                                   size_t surfaceWidth,
42                                   size_t surfaceHeight,
43                                   float  horizontalDpi,
44                                   float  verticalDpi,
45                                   ResourcePolicy::DataRetention policy)
46 : mCore( NULL ),
47   mSurfaceWidth( surfaceWidth ),
48   mSurfaceHeight( surfaceHeight ),
49   mFrame( 0u ),
50   mDpi( horizontalDpi, verticalDpi ),
51   mLastVSyncTime(0u),
52   mDataRetentionPolicy( policy )
53 {
54   if ( initialize )
55   {
56     Initialize();
57   }
58 }
59
60 void TestApplication::Initialize()
61 {
62   // We always need the first update!
63   mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
64
65   mCore = Dali::Integration::Core::New( mRenderController,
66                                         mPlatformAbstraction,
67                                         mGlAbstraction,
68                                         mGlSyncAbstraction,
69                                         mGestureManager,
70                                         mDataRetentionPolicy,
71                                         Integration::RenderToFrameBuffer::FALSE,
72                                         Integration::DepthBufferAvailable::TRUE,
73                                         Integration::StencilBufferAvailable::TRUE );
74
75   mCore->ContextCreated();
76   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
77   mCore->SetDpi( mDpi.x, mDpi.y );
78
79   Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
80   Dali::Integration::Log::InstallLogFunction(logFunction);
81
82   mCore->SceneCreated();
83 }
84
85 TestApplication::~TestApplication()
86 {
87   Dali::Integration::Log::UninstallLogFunction();
88   delete mCore;
89 }
90
91 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
92 {
93   switch(level)
94   {
95     case Dali::Integration::Log::DebugInfo:
96       fprintf(stderr, "INFO: %s", message.c_str());
97       break;
98     case Dali::Integration::Log::DebugWarning:
99       fprintf(stderr, "WARN: %s", message.c_str());
100       break;
101     case Dali::Integration::Log::DebugError:
102       fprintf(stderr, "ERROR: %s", message.c_str());
103       break;
104     default:
105       fprintf(stderr, "DEFAULT: %s", message.c_str());
106       break;
107   }
108 }
109
110 Dali::Integration::Core& TestApplication::GetCore()
111 {
112   return *mCore;
113 }
114
115 TestPlatformAbstraction& TestApplication::GetPlatform()
116 {
117   return mPlatformAbstraction;
118 }
119
120 TestRenderController& TestApplication::GetRenderController()
121 {
122   return mRenderController;
123 }
124
125 TestGlAbstraction& TestApplication::GetGlAbstraction()
126 {
127   return mGlAbstraction;
128 }
129
130 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
131 {
132   return mGlSyncAbstraction;
133 }
134
135 TestGestureManager& TestApplication::GetGestureManager()
136 {
137   return mGestureManager;
138 }
139
140 void TestApplication::ProcessEvent(const Integration::Event& event)
141 {
142   mCore->QueueEvent(event);
143   mCore->ProcessEvents();
144 }
145
146 void TestApplication::SendNotification()
147 {
148   mCore->ProcessEvents();
149 }
150
151 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
152 {
153   mSurfaceWidth = width;
154   mSurfaceHeight = height;
155
156   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
157 }
158
159 void TestApplication::SetTopMargin( unsigned int margin )
160 {
161   mCore->SetTopMargin( margin );
162 }
163
164 void TestApplication::DoUpdate( unsigned int intervalMilliseconds, const char* location )
165 {
166   if( GetUpdateStatus() == 0 &&
167       mRenderStatus.NeedsUpdate() == false &&
168       ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
169   {
170     fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
171   }
172
173   unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
174   float elapsedSeconds = intervalMilliseconds / 1e3f;
175
176   mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
177
178   GetRenderController().Initialize();
179
180   mLastVSyncTime = nextVSyncTime;
181 }
182
183 bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
184 {
185   DoUpdate( intervalMilliseconds, location );
186   mCore->Render( mRenderStatus );
187
188   mFrame++;
189
190   return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
191 }
192
193 unsigned int TestApplication::GetUpdateStatus()
194 {
195   return mStatus.KeepUpdating();
196 }
197
198 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds  )
199 {
200   DoUpdate( intervalMilliseconds );
201   return mStatus.KeepUpdating();
202 }
203
204 bool TestApplication::GetRenderNeedsUpdate()
205 {
206   return mRenderStatus.NeedsUpdate();
207 }
208
209 bool TestApplication::RenderOnly( )
210 {
211   // Update Time values
212   mCore->Render( mRenderStatus );
213
214   mFrame++;
215
216   return mRenderStatus.NeedsUpdate();
217 }
218
219 void TestApplication::ResetContext()
220 {
221   mCore->ContextDestroyed();
222   mGlAbstraction.Initialize();
223   mCore->ContextCreated();
224 }
225
226 unsigned int TestApplication::Wait( unsigned int durationToWait )
227 {
228   int time = 0;
229
230   for(unsigned int i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
231   {
232     SendNotification();
233     Render(RENDER_FRAME_INTERVAL);
234     time += RENDER_FRAME_INTERVAL;
235   }
236   return time;
237 }
238
239 } // Namespace dali