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 ),
52 mDataRetentionPolicy( policy )
60 void TestApplication::Initialize()
62 mCore = Dali::Integration::Core::New(
68 mDataRetentionPolicy);
70 mCore->ContextCreated();
71 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
72 mCore->SetDpi( mDpi.x, mDpi.y );
74 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
75 Dali::Integration::Log::InstallLogFunction(logFunction);
77 mCore->SceneCreated();
80 TestApplication::~TestApplication()
82 Dali::Integration::Log::UninstallLogFunction();
86 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
90 case Dali::Integration::Log::DebugInfo:
91 fprintf(stderr, "INFO: %s", message.c_str());
93 case Dali::Integration::Log::DebugWarning:
94 fprintf(stderr, "WARN: %s", message.c_str());
96 case Dali::Integration::Log::DebugError:
97 fprintf(stderr, "ERROR: %s", message.c_str());
100 fprintf(stderr, "DEFAULT: %s", message.c_str());
105 Dali::Integration::Core& TestApplication::GetCore()
110 TestPlatformAbstraction& TestApplication::GetPlatform()
112 return mPlatformAbstraction;
115 TestRenderController& TestApplication::GetRenderController()
117 return mRenderController;
120 TestGlAbstraction& TestApplication::GetGlAbstraction()
122 return mGlAbstraction;
125 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
127 return mGlSyncAbstraction;
130 TestGestureManager& TestApplication::GetGestureManager()
132 return mGestureManager;
135 void TestApplication::ProcessEvent(const Integration::Event& event)
137 mCore->QueueEvent(event);
138 mCore->ProcessEvents();
141 void TestApplication::SendNotification()
143 mCore->ProcessEvents();
146 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
148 mSurfaceWidth = width;
149 mSurfaceHeight = height;
151 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
154 void TestApplication::DoUpdate( unsigned int intervalMilliseconds )
156 uint64_t seconds(0u), nanoseconds(0u);
157 mPlatformAbstraction.GetTimeNanoseconds( seconds, nanoseconds );
158 mLastVSyncTime = ( seconds * 1e3 ) + ( nanoseconds / 1e6 );
159 unsigned int nextVSyncTime = mLastVSyncTime + 16;
161 // Update Time values
162 mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
164 float elapsedSeconds = intervalMilliseconds / 1e3f;
165 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
168 bool TestApplication::Render( unsigned int intervalMilliseconds )
170 DoUpdate( intervalMilliseconds );
171 mCore->Render( mRenderStatus );
175 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
178 unsigned int TestApplication::GetUpdateStatus()
180 return mStatus.KeepUpdating();
183 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
185 DoUpdate( intervalMilliseconds );
186 return mStatus.KeepUpdating();
189 bool TestApplication::RenderOnly( )
191 // Update Time values
192 mCore->Render( mRenderStatus );
196 return mRenderStatus.NeedsUpdate();
199 void TestApplication::ResetContext()
201 mCore->ContextDestroyed();
202 mCore->ContextCreated();