License conversion from Flora to Apache 2.0
[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 : mCore( NULL ),
29   mSurfaceWidth( surfaceWidth ),
30   mSurfaceHeight( surfaceHeight ),
31   mFrame( 0u ),
32   mDpi( horizontalDpi, verticalDpi )
33 {
34   Initialize();
35 }
36
37 TestApplication::TestApplication( bool   initialize,
38                                   size_t surfaceWidth,
39                                   size_t surfaceHeight,
40                                   float  horizontalDpi,
41                                   float  verticalDpi )
42 : mCore( NULL ),
43   mSurfaceWidth( surfaceWidth ),
44   mSurfaceHeight( surfaceHeight ),
45   mFrame( 0u ),
46   mDpi( horizontalDpi, verticalDpi )
47 {
48   if ( initialize )
49   {
50     Initialize();
51   }
52 }
53
54 void TestApplication::Initialize()
55 {
56   mCore = Dali::Integration::Core::New(
57     mRenderController,
58     mPlatformAbstraction,
59     mGlAbstraction,
60     mGlSyncAbstraction,
61     mGestureManager );
62
63   mCore->ContextCreated();
64   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
65   mCore->SetDpi( mDpi.x, mDpi.y );
66
67   Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
68   Dali::Integration::Log::InstallLogFunction(logFunction);
69 }
70
71 TestApplication::~TestApplication()
72 {
73   Dali::Integration::Log::UninstallLogFunction();
74   delete mCore;
75 }
76
77 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
78 {
79   switch(level)
80   {
81     case Dali::Integration::Log::DebugInfo:
82       fprintf(stderr, "INFO: %s", message.c_str());
83       break;
84     case Dali::Integration::Log::DebugWarning:
85       fprintf(stderr, "WARN: %s", message.c_str());
86       break;
87     case Dali::Integration::Log::DebugError:
88       fprintf(stderr, "ERROR: %s", message.c_str());
89       break;
90     default:
91       fprintf(stderr, "DEFAULT: %s", message.c_str());
92       break;
93   }
94 }
95
96 Dali::Integration::Core& TestApplication::GetCore()
97 {
98   return *mCore;
99 }
100
101 TestPlatformAbstraction& TestApplication::GetPlatform()
102 {
103   return mPlatformAbstraction;
104 }
105
106 TestRenderController& TestApplication::GetRenderController()
107 {
108   return mRenderController;
109 }
110
111 TestGlAbstraction& TestApplication::GetGlAbstraction()
112 {
113   return mGlAbstraction;
114 }
115
116 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
117 {
118   return mGlSyncAbstraction;
119 }
120
121 TestGestureManager& TestApplication::GetGestureManager()
122 {
123   return mGestureManager;
124 }
125
126 void TestApplication::ProcessEvent(const Integration::Event& event)
127 {
128   mCore->QueueEvent(event);
129   mCore->ProcessEvents();
130 }
131
132 void TestApplication::SendNotification()
133 {
134   mCore->ProcessEvents();
135 }
136
137 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
138 {
139   mSurfaceWidth = width;
140   mSurfaceHeight = height;
141
142   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
143 }
144
145 bool TestApplication::Render( unsigned int intervalMilliseconds  )
146 {
147   // Update Time values
148   mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
149   unsigned int seconds(0u), microseconds(0u);
150   mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
151
152   mCore->VSync( mFrame, seconds, microseconds );
153   mCore->Update( mStatus );
154   mCore->Render( mRenderStatus );
155
156   mFrame++;
157
158   return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
159 }
160
161 unsigned int TestApplication::GetUpdateStatus()
162 {
163   return mStatus.KeepUpdating();
164 }
165
166 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds  )
167 {
168   // Update Time values
169   mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
170   unsigned int seconds(0u), microseconds(0u);
171   mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
172
173   mCore->VSync( mFrame, seconds, microseconds );
174   mCore->Update( mStatus );
175
176   return mStatus.KeepUpdating();
177 }
178
179 bool TestApplication::RenderOnly( )
180 {
181   // Update Time values
182   mCore->Render( mRenderStatus );
183
184   mFrame++;
185
186   return mRenderStatus.NeedsUpdate();
187 }
188
189 void TestApplication::ResetContext()
190 {
191   mCore->ContextToBeDestroyed();
192   mCore->ContextCreated();
193 }
194
195
196 } // Namespace dali