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);
78 TestApplication::~TestApplication()
80 Dali::Integration::Log::UninstallLogFunction();
84 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
88 case Dali::Integration::Log::DebugInfo:
89 fprintf(stderr, "INFO: %s", message.c_str());
91 case Dali::Integration::Log::DebugWarning:
92 fprintf(stderr, "WARN: %s", message.c_str());
94 case Dali::Integration::Log::DebugError:
95 fprintf(stderr, "ERROR: %s", message.c_str());
98 fprintf(stderr, "DEFAULT: %s", message.c_str());
103 Dali::Integration::Core& TestApplication::GetCore()
108 TestPlatformAbstraction& TestApplication::GetPlatform()
110 return mPlatformAbstraction;
113 TestRenderController& TestApplication::GetRenderController()
115 return mRenderController;
118 TestGlAbstraction& TestApplication::GetGlAbstraction()
120 return mGlAbstraction;
123 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
125 return mGlSyncAbstraction;
128 TestGestureManager& TestApplication::GetGestureManager()
130 return mGestureManager;
133 void TestApplication::ProcessEvent(const Integration::Event& event)
135 mCore->QueueEvent(event);
136 mCore->ProcessEvents();
139 void TestApplication::SendNotification()
141 mCore->ProcessEvents();
144 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
146 mSurfaceWidth = width;
147 mSurfaceHeight = height;
149 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
152 void TestApplication::DoUpdate( unsigned int intervalMilliseconds )
154 unsigned int seconds(0u), microseconds(0u);
155 mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
156 mLastVSyncTime = ( seconds * 1e3 ) + ( microseconds / 1e3 );
157 unsigned int nextVSyncTime = mLastVSyncTime + 16;
159 // Update Time values
160 mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
162 float elapsedSeconds = intervalMilliseconds / 1e3f;
163 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
166 bool TestApplication::Render( unsigned int intervalMilliseconds )
168 DoUpdate( intervalMilliseconds );
169 mCore->Render( mRenderStatus );
173 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
176 unsigned int TestApplication::GetUpdateStatus()
178 return mStatus.KeepUpdating();
181 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
183 DoUpdate( intervalMilliseconds );
184 return mStatus.KeepUpdating();
187 bool TestApplication::RenderOnly( )
189 // Update Time values
190 mCore->Render( mRenderStatus );
194 return mRenderStatus.NeedsUpdate();
197 void TestApplication::ResetContext()
199 mCore->ContextDestroyed();
200 mCore->ContextCreated();