2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "test-application.h"
24 TestApplication::TestApplication( size_t surfaceWidth,
28 ResourcePolicy::DataRetention policy)
30 mSurfaceWidth( surfaceWidth ),
31 mSurfaceHeight( surfaceHeight ),
33 mDpi( horizontalDpi, verticalDpi ),
35 mDataRetentionPolicy( policy )
40 TestApplication::TestApplication( bool initialize,
45 ResourcePolicy::DataRetention policy)
47 mSurfaceWidth( surfaceWidth ),
48 mSurfaceHeight( surfaceHeight ),
50 mDpi( horizontalDpi, verticalDpi ),
51 mDataRetentionPolicy( policy )
59 void TestApplication::Initialize()
61 mCore = Dali::Integration::Core::New(
67 mDataRetentionPolicy);
69 mCore->ContextCreated();
70 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
71 mCore->SetDpi( mDpi.x, mDpi.y );
73 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
74 Dali::Integration::Log::InstallLogFunction(logFunction);
76 mCore->SceneCreated();
79 TestApplication::~TestApplication()
81 Dali::Integration::Log::UninstallLogFunction();
85 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
89 case Dali::Integration::Log::DebugInfo:
90 fprintf(stderr, "INFO: %s", message.c_str());
92 case Dali::Integration::Log::DebugWarning:
93 fprintf(stderr, "WARN: %s", message.c_str());
95 case Dali::Integration::Log::DebugError:
96 fprintf(stderr, "ERROR: %s", message.c_str());
99 fprintf(stderr, "DEFAULT: %s", message.c_str());
104 Dali::Integration::Core& TestApplication::GetCore()
109 TestPlatformAbstraction& TestApplication::GetPlatform()
111 return mPlatformAbstraction;
114 TestRenderController& TestApplication::GetRenderController()
116 return mRenderController;
119 TestGlAbstraction& TestApplication::GetGlAbstraction()
121 return mGlAbstraction;
124 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
126 return mGlSyncAbstraction;
129 TestGestureManager& TestApplication::GetGestureManager()
131 return mGestureManager;
134 void TestApplication::ProcessEvent(const Integration::Event& event)
136 mCore->QueueEvent(event);
137 mCore->ProcessEvents();
140 void TestApplication::SendNotification()
142 mCore->ProcessEvents();
145 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
147 mSurfaceWidth = width;
148 mSurfaceHeight = height;
150 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
153 void TestApplication::DoUpdate( unsigned int intervalMilliseconds )
155 unsigned int seconds(0u), microseconds(0u);
156 mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
157 mLastVSyncTime = ( seconds * 1e3 ) + ( microseconds / 1e3 );
158 unsigned int nextVSyncTime = mLastVSyncTime + 16;
160 // Update Time values
161 mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
163 float elapsedSeconds = intervalMilliseconds / 1e3f;
164 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
167 bool TestApplication::Render( unsigned int intervalMilliseconds )
169 DoUpdate( intervalMilliseconds );
170 mCore->Render( mRenderStatus );
174 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
177 unsigned int TestApplication::GetUpdateStatus()
179 return mStatus.KeepUpdating();
182 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
184 DoUpdate( intervalMilliseconds );
185 return mStatus.KeepUpdating();
188 bool TestApplication::RenderOnly( )
190 // Update Time values
191 mCore->Render( mRenderStatus );
195 return mRenderStatus.NeedsUpdate();
198 void TestApplication::ResetContext()
200 mCore->ContextDestroyed();
201 mCore->ContextCreated();