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 // We always need the first update!
63 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
65 mCore = Dali::Integration::Core::New(
71 mDataRetentionPolicy);
73 mCore->ContextCreated();
74 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
75 mCore->SetDpi( mDpi.x, mDpi.y );
77 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
78 Dali::Integration::Log::InstallLogFunction(logFunction);
80 mCore->SceneCreated();
83 TestApplication::~TestApplication()
85 Dali::Integration::Log::UninstallLogFunction();
89 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
93 case Dali::Integration::Log::DebugInfo:
94 fprintf(stderr, "INFO: %s", message.c_str());
96 case Dali::Integration::Log::DebugWarning:
97 fprintf(stderr, "WARN: %s", message.c_str());
99 case Dali::Integration::Log::DebugError:
100 fprintf(stderr, "ERROR: %s", message.c_str());
103 fprintf(stderr, "DEFAULT: %s", message.c_str());
108 Dali::Integration::Core& TestApplication::GetCore()
113 TestPlatformAbstraction& TestApplication::GetPlatform()
115 return mPlatformAbstraction;
118 TestRenderController& TestApplication::GetRenderController()
120 return mRenderController;
123 TestGlAbstraction& TestApplication::GetGlAbstraction()
125 return mGlAbstraction;
128 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
130 return mGlSyncAbstraction;
133 TestGestureManager& TestApplication::GetGestureManager()
135 return mGestureManager;
138 void TestApplication::ProcessEvent(const Integration::Event& event)
140 mCore->QueueEvent(event);
141 mCore->ProcessEvents();
144 void TestApplication::SendNotification()
146 mCore->ProcessEvents();
149 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
151 mSurfaceWidth = width;
152 mSurfaceHeight = height;
154 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
157 void TestApplication::DoUpdate( unsigned int intervalMilliseconds, const char* location )
159 if( GetUpdateStatus() == 0 &&
160 mRenderStatus.NeedsUpdate() == false &&
161 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
163 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
166 unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
167 float elapsedSeconds = intervalMilliseconds / 1e3f;
169 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
171 GetRenderController().Initialize();
173 mLastVSyncTime = nextVSyncTime;
176 bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
178 DoUpdate( intervalMilliseconds, location );
179 mCore->Render( mRenderStatus );
183 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
186 unsigned int TestApplication::GetUpdateStatus()
188 return mStatus.KeepUpdating();
191 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
193 DoUpdate( intervalMilliseconds );
194 return mStatus.KeepUpdating();
197 bool TestApplication::GetRenderNeedsUpdate()
199 return mRenderStatus.NeedsUpdate();
202 bool TestApplication::RenderOnly( )
204 // Update Time values
205 mCore->Render( mRenderStatus );
209 return mRenderStatus.NeedsUpdate();
212 void TestApplication::ResetContext()
214 mCore->ContextDestroyed();
215 mGlAbstraction.Initialize();
216 mCore->ContextCreated();