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 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
83 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
85 Dali::Integration::Trace::LogContext( true, "Test" );
87 mCore->SceneCreated();
90 TestApplication::~TestApplication()
92 Dali::Integration::Log::UninstallLogFunction();
96 void TestApplication::LogContext( bool start, const char* tag )
100 fprintf(stderr, "INFO: Trace Start: %s", tag);
104 fprintf(stderr, "INFO: Trace End: %s", tag);
108 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
112 case Dali::Integration::Log::DebugInfo:
113 fprintf(stderr, "INFO: %s", message.c_str());
115 case Dali::Integration::Log::DebugWarning:
116 fprintf(stderr, "WARN: %s", message.c_str());
118 case Dali::Integration::Log::DebugError:
119 fprintf(stderr, "ERROR: %s", message.c_str());
122 fprintf(stderr, "DEFAULT: %s", message.c_str());
127 Dali::Integration::Core& TestApplication::GetCore()
132 TestPlatformAbstraction& TestApplication::GetPlatform()
134 return mPlatformAbstraction;
137 TestRenderController& TestApplication::GetRenderController()
139 return mRenderController;
142 TestGlAbstraction& TestApplication::GetGlAbstraction()
144 return mGlAbstraction;
147 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
149 return mGlSyncAbstraction;
152 TestGestureManager& TestApplication::GetGestureManager()
154 return mGestureManager;
157 void TestApplication::ProcessEvent(const Integration::Event& event)
159 mCore->QueueEvent(event);
160 mCore->ProcessEvents();
163 void TestApplication::SendNotification()
165 mCore->ProcessEvents();
168 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
170 mSurfaceWidth = width;
171 mSurfaceHeight = height;
173 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
176 void TestApplication::SetTopMargin( unsigned int margin )
178 mCore->SetTopMargin( margin );
181 void TestApplication::DoUpdate( unsigned int intervalMilliseconds, const char* location )
183 if( GetUpdateStatus() == 0 &&
184 mRenderStatus.NeedsUpdate() == false &&
185 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
187 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
190 unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
191 float elapsedSeconds = intervalMilliseconds / 1e3f;
193 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
195 GetRenderController().Initialize();
197 mLastVSyncTime = nextVSyncTime;
200 bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
202 DoUpdate( intervalMilliseconds, location );
203 mCore->Render( mRenderStatus, false );
207 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
210 unsigned int TestApplication::GetUpdateStatus()
212 return mStatus.KeepUpdating();
215 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds )
217 DoUpdate( intervalMilliseconds );
218 return mStatus.KeepUpdating();
221 bool TestApplication::GetRenderNeedsUpdate()
223 return mRenderStatus.NeedsUpdate();
226 bool TestApplication::RenderOnly( )
228 // Update Time values
229 mCore->Render( mRenderStatus, false );
233 return mRenderStatus.NeedsUpdate();
236 void TestApplication::ResetContext()
238 mCore->ContextDestroyed();
239 mGlAbstraction.Initialize();
240 mCore->ContextCreated();
243 unsigned int TestApplication::Wait( unsigned int durationToWait )
247 for(unsigned int i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
250 Render(RENDER_FRAME_INTERVAL);
251 time += RENDER_FRAME_INTERVAL;