Merge "Fix Svace issue" 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) 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 "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(
66     mRenderController,
67     mPlatformAbstraction,
68     mGlAbstraction,
69     mGlSyncAbstraction,
70     mGestureManager,
71     mDataRetentionPolicy);
72
73   mCore->ContextCreated();
74   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
75   mCore->SetDpi( mDpi.x, mDpi.y );
76
77   Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
78   Dali::Integration::Log::InstallLogFunction(logFunction);
79
80   mCore->SceneCreated();
81 }
82
83 TestApplication::~TestApplication()
84 {
85   Dali::Integration::Log::UninstallLogFunction();
86   delete mCore;
87 }
88
89 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
90 {
91   switch(level)
92   {
93     case Dali::Integration::Log::DebugInfo:
94       fprintf(stderr, "INFO: %s", message.c_str());
95       break;
96     case Dali::Integration::Log::DebugWarning:
97       fprintf(stderr, "WARN: %s", message.c_str());
98       break;
99     case Dali::Integration::Log::DebugError:
100       fprintf(stderr, "ERROR: %s", message.c_str());
101       break;
102     default:
103       fprintf(stderr, "DEFAULT: %s", message.c_str());
104       break;
105   }
106 }
107
108 Dali::Integration::Core& TestApplication::GetCore()
109 {
110   return *mCore;
111 }
112
113 TestPlatformAbstraction& TestApplication::GetPlatform()
114 {
115   return mPlatformAbstraction;
116 }
117
118 TestRenderController& TestApplication::GetRenderController()
119 {
120   return mRenderController;
121 }
122
123 TestGlAbstraction& TestApplication::GetGlAbstraction()
124 {
125   return mGlAbstraction;
126 }
127
128 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
129 {
130   return mGlSyncAbstraction;
131 }
132
133 TestGestureManager& TestApplication::GetGestureManager()
134 {
135   return mGestureManager;
136 }
137
138 void TestApplication::ProcessEvent(const Integration::Event& event)
139 {
140   mCore->QueueEvent(event);
141   mCore->ProcessEvents();
142 }
143
144 void TestApplication::SendNotification()
145 {
146   mCore->ProcessEvents();
147 }
148
149 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
150 {
151   mSurfaceWidth = width;
152   mSurfaceHeight = height;
153
154   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
155 }
156
157 void TestApplication::DoUpdate( unsigned int intervalMilliseconds, const char* location )
158 {
159   if( GetUpdateStatus() == 0 &&
160       mRenderStatus.NeedsUpdate() == false &&
161       ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
162   {
163     fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
164   }
165
166   unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
167   float elapsedSeconds = intervalMilliseconds / 1e3f;
168
169   mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
170
171   GetRenderController().Initialize();
172
173   mLastVSyncTime = nextVSyncTime;
174 }
175
176 bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
177 {
178   DoUpdate( intervalMilliseconds, location );
179   mCore->Render( mRenderStatus );
180
181   mFrame++;
182
183   return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
184 }
185
186 unsigned int TestApplication::GetUpdateStatus()
187 {
188   return mStatus.KeepUpdating();
189 }
190
191 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds  )
192 {
193   DoUpdate( intervalMilliseconds );
194   return mStatus.KeepUpdating();
195 }
196
197 bool TestApplication::GetRenderNeedsUpdate()
198 {
199   return mRenderStatus.NeedsUpdate();
200 }
201
202 bool TestApplication::RenderOnly( )
203 {
204   // Update Time values
205   mCore->Render( mRenderStatus );
206
207   mFrame++;
208
209   return mRenderStatus.NeedsUpdate();
210 }
211
212 void TestApplication::ResetContext()
213 {
214   mCore->ContextDestroyed();
215   mGlAbstraction.Initialize();
216   mCore->ContextCreated();
217 }
218
219
220 } // Namespace dali