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);
77 TestApplication::~TestApplication()
79 Dali::Integration::Log::UninstallLogFunction();
83 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
87 case Dali::Integration::Log::DebugInfo:
88 fprintf(stderr, "INFO: %s", message.c_str());
90 case Dali::Integration::Log::DebugWarning:
91 fprintf(stderr, "WARN: %s", message.c_str());
93 case Dali::Integration::Log::DebugError:
94 fprintf(stderr, "ERROR: %s", message.c_str());
97 fprintf(stderr, "DEFAULT: %s", message.c_str());
102 Dali::Integration::Core& TestApplication::GetCore()
107 TestPlatformAbstraction& TestApplication::GetPlatform()
109 return mPlatformAbstraction;
112 TestRenderController& TestApplication::GetRenderController()
114 return mRenderController;
117 TestGlAbstraction& TestApplication::GetGlAbstraction()
119 return mGlAbstraction;
122 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
124 return mGlSyncAbstraction;
127 TestGestureManager& TestApplication::GetGestureManager()
129 return mGestureManager;
132 void TestApplication::ProcessEvent(const Integration::Event& event)
134 mCore->QueueEvent(event);
135 mCore->ProcessEvents();
138 void TestApplication::SendNotification()
140 mCore->ProcessEvents();
143 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
145 mSurfaceWidth = width;
146 mSurfaceHeight = height;
148 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
151 void TestApplication::DoUpdate( unsigned int intervalMilliseconds )
153 unsigned int seconds(0u), microseconds(0u);
154 mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
155 mLastVSyncTime = ( seconds * 1e3 ) + ( microseconds / 1e3 );
156 unsigned int nextVSyncTime = mLastVSyncTime + 16;
158 // Update Time values
159 mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
161 float elapsedSeconds = intervalMilliseconds / 1e3f;
162 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
165 bool TestApplication::Render( unsigned int intervalMilliseconds )
167 DoUpdate( intervalMilliseconds );
168 mCore->Render( mRenderStatus );
172 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
175 unsigned int TestApplication::GetUpdateStatus()
177 return mStatus.KeepUpdating();
180 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
182 DoUpdate( intervalMilliseconds );
183 return mStatus.KeepUpdating();
186 bool TestApplication::RenderOnly( )
188 // Update Time values
189 mCore->Render( mRenderStatus );
193 return mRenderStatus.NeedsUpdate();
196 void TestApplication::ResetContext()
198 mCore->ContextDestroyed();
199 mCore->ContextCreated();