2 * Copyright (c) 2017 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::SetTopMargin( unsigned int margin )
159 mCore->SetTopMargin( margin );
162 void TestApplication::DoUpdate( unsigned int intervalMilliseconds, const char* location )
164 if( GetUpdateStatus() == 0 &&
165 mRenderStatus.NeedsUpdate() == false &&
166 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
168 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
171 unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
172 float elapsedSeconds = intervalMilliseconds / 1e3f;
174 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
176 GetRenderController().Initialize();
178 mLastVSyncTime = nextVSyncTime;
181 bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
183 DoUpdate( intervalMilliseconds, location );
184 mCore->Render( mRenderStatus );
188 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
191 unsigned int TestApplication::GetUpdateStatus()
193 return mStatus.KeepUpdating();
196 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
198 DoUpdate( intervalMilliseconds );
199 return mStatus.KeepUpdating();
202 bool TestApplication::GetRenderNeedsUpdate()
204 return mRenderStatus.NeedsUpdate();
207 bool TestApplication::RenderOnly( )
209 // Update Time values
210 mCore->Render( mRenderStatus );
214 return mRenderStatus.NeedsUpdate();
217 void TestApplication::ResetContext()
219 mCore->ContextDestroyed();
220 mGlAbstraction.Initialize();
221 mCore->ContextCreated();
224 unsigned int TestApplication::Wait( unsigned int durationToWait )
228 for(unsigned int i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
231 Render(RENDER_FRAME_INTERVAL);
232 time += RENDER_FRAME_INTERVAL;