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( mRenderController,
71 Integration::RenderToFrameBuffer::FALSE,
72 Integration::DepthBufferAvailable::TRUE,
73 Integration::StencilBufferAvailable::TRUE );
75 mCore->ContextCreated();
76 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
77 mCore->SetDpi( mDpi.x, mDpi.y );
79 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
80 Dali::Integration::Log::InstallLogFunction(logFunction);
82 mCore->SceneCreated();
85 TestApplication::~TestApplication()
87 Dali::Integration::Log::UninstallLogFunction();
91 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
95 case Dali::Integration::Log::DebugInfo:
96 fprintf(stderr, "INFO: %s", message.c_str());
98 case Dali::Integration::Log::DebugWarning:
99 fprintf(stderr, "WARN: %s", message.c_str());
101 case Dali::Integration::Log::DebugError:
102 fprintf(stderr, "ERROR: %s", message.c_str());
105 fprintf(stderr, "DEFAULT: %s", message.c_str());
110 Dali::Integration::Core& TestApplication::GetCore()
115 TestPlatformAbstraction& TestApplication::GetPlatform()
117 return mPlatformAbstraction;
120 TestRenderController& TestApplication::GetRenderController()
122 return mRenderController;
125 TestGlAbstraction& TestApplication::GetGlAbstraction()
127 return mGlAbstraction;
130 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
132 return mGlSyncAbstraction;
135 TestGestureManager& TestApplication::GetGestureManager()
137 return mGestureManager;
140 void TestApplication::ProcessEvent(const Integration::Event& event)
142 mCore->QueueEvent(event);
143 mCore->ProcessEvents();
146 void TestApplication::SendNotification()
148 mCore->ProcessEvents();
151 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
153 mSurfaceWidth = width;
154 mSurfaceHeight = height;
156 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
159 void TestApplication::SetTopMargin( unsigned int margin )
161 mCore->SetTopMargin( margin );
164 void TestApplication::DoUpdate( unsigned int intervalMilliseconds, const char* location )
166 if( GetUpdateStatus() == 0 &&
167 mRenderStatus.NeedsUpdate() == false &&
168 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
170 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
173 unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
174 float elapsedSeconds = intervalMilliseconds / 1e3f;
176 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
178 GetRenderController().Initialize();
180 mLastVSyncTime = nextVSyncTime;
183 bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
185 DoUpdate( intervalMilliseconds, location );
186 mCore->Render( mRenderStatus );
190 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
193 unsigned int TestApplication::GetUpdateStatus()
195 return mStatus.KeepUpdating();
198 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
200 DoUpdate( intervalMilliseconds );
201 return mStatus.KeepUpdating();
204 bool TestApplication::GetRenderNeedsUpdate()
206 return mRenderStatus.NeedsUpdate();
209 bool TestApplication::RenderOnly( )
211 // Update Time values
212 mCore->Render( mRenderStatus );
216 return mRenderStatus.NeedsUpdate();
219 void TestApplication::ResetContext()
221 mCore->ContextDestroyed();
222 mGlAbstraction.Initialize();
223 mCore->ContextCreated();
226 unsigned int TestApplication::Wait( unsigned int durationToWait )
230 for(unsigned int i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
233 Render(RENDER_FRAME_INTERVAL);
234 time += RENDER_FRAME_INTERVAL;