2 * Copyright (c) 2018 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( uint32_t surfaceWidth,
25 uint32_t surfaceHeight,
26 uint32_t horizontalDpi,
28 ResourcePolicy::DataRetention policy)
30 mSurfaceWidth( surfaceWidth ),
31 mSurfaceHeight( surfaceHeight ),
33 mDpi{ horizontalDpi, verticalDpi },
35 mDataRetentionPolicy( policy )
40 void TestApplication::Initialize()
42 // We always need the first update!
43 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
45 mCore = Dali::Integration::Core::New( mRenderController,
51 Integration::RenderToFrameBuffer::FALSE,
52 Integration::DepthBufferAvailable::TRUE,
53 Integration::StencilBufferAvailable::TRUE );
55 mCore->ContextCreated();
56 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
57 mCore->SetDpi( mDpi.x, mDpi.y );
59 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
60 Dali::Integration::Log::InstallLogFunction(logFunction);
62 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
63 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
65 Dali::Integration::Trace::LogContext( true, "Test" );
67 mCore->SceneCreated();
70 TestApplication::~TestApplication()
72 Dali::Integration::Log::UninstallLogFunction();
76 void TestApplication::LogContext( bool start, const char* tag )
80 fprintf(stderr, "INFO: Trace Start: %s", tag);
84 fprintf(stderr, "INFO: Trace End: %s", tag);
88 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
92 case Dali::Integration::Log::DebugInfo:
93 fprintf(stderr, "INFO: %s", message.c_str());
95 case Dali::Integration::Log::DebugWarning:
96 fprintf(stderr, "WARN: %s", message.c_str());
98 case Dali::Integration::Log::DebugError:
99 fprintf(stderr, "ERROR: %s", message.c_str());
102 fprintf(stderr, "DEFAULT: %s", message.c_str());
107 Dali::Integration::Core& TestApplication::GetCore()
112 TestPlatformAbstraction& TestApplication::GetPlatform()
114 return mPlatformAbstraction;
117 TestRenderController& TestApplication::GetRenderController()
119 return mRenderController;
122 TestGlAbstraction& TestApplication::GetGlAbstraction()
124 return mGlAbstraction;
127 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
129 return mGlSyncAbstraction;
132 TestGestureManager& TestApplication::GetGestureManager()
134 return mGestureManager;
137 void TestApplication::ProcessEvent(const Integration::Event& event)
139 mCore->QueueEvent(event);
140 mCore->ProcessEvents();
143 void TestApplication::SendNotification()
145 mCore->ProcessEvents();
148 void TestApplication::SetSurfaceWidth( uint32_t width, uint32_t height )
150 mSurfaceWidth = width;
151 mSurfaceHeight = height;
153 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
156 void TestApplication::SetTopMargin( uint32_t margin )
158 mCore->SetTopMargin( margin );
161 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
163 if( GetUpdateStatus() == 0 &&
164 mRenderStatus.NeedsUpdate() == false &&
165 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
167 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
170 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
171 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
173 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
175 GetRenderController().Initialize();
177 mLastVSyncTime = nextVSyncTime;
180 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
182 DoUpdate( intervalMilliseconds, location );
183 mCore->Render( mRenderStatus, false );
187 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
190 uint32_t TestApplication::GetUpdateStatus()
192 return mStatus.KeepUpdating();
195 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
197 DoUpdate( intervalMilliseconds );
198 return mStatus.KeepUpdating();
201 bool TestApplication::GetRenderNeedsUpdate()
203 return mRenderStatus.NeedsUpdate();
206 bool TestApplication::RenderOnly( )
208 // Update Time values
209 mCore->Render( mRenderStatus, false );
213 return mRenderStatus.NeedsUpdate();
216 void TestApplication::ResetContext()
218 mCore->ContextDestroyed();
219 mGlAbstraction.Initialize();
220 mCore->ContextCreated();
223 uint32_t TestApplication::Wait( uint32_t durationToWait )
227 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
230 Render(RENDER_FRAME_INTERVAL);
231 time += RENDER_FRAME_INTERVAL;