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"
23 bool TestApplication::mLoggingEnabled = true;
25 TestApplication::TestApplication( uint32_t surfaceWidth,
26 uint32_t surfaceHeight,
27 uint32_t horizontalDpi,
29 ResourcePolicy::DataRetention policy)
31 mSurfaceWidth( surfaceWidth ),
32 mSurfaceHeight( surfaceHeight ),
34 mDpi{ horizontalDpi, verticalDpi },
36 mDataRetentionPolicy( policy )
41 void TestApplication::Initialize()
43 // We always need the first update!
44 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
46 mCore = Dali::Integration::Core::New( mRenderController,
52 Integration::RenderToFrameBuffer::FALSE,
53 Integration::DepthBufferAvailable::TRUE,
54 Integration::StencilBufferAvailable::TRUE );
56 mCore->ContextCreated();
57 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
58 mCore->SetDpi( mDpi.x, mDpi.y );
60 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
61 Dali::Integration::Log::InstallLogFunction(logFunction);
63 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
64 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
66 Dali::Integration::Trace::LogContext( true, "Test" );
68 mCore->SceneCreated();
71 TestApplication::~TestApplication()
73 Dali::Integration::Log::UninstallLogFunction();
77 void TestApplication::LogContext( bool start, const char* tag )
81 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
85 fprintf(stderr, "INFO: Trace End: %s\n", tag);
89 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());
111 Dali::Integration::Core& TestApplication::GetCore()
116 TestPlatformAbstraction& TestApplication::GetPlatform()
118 return mPlatformAbstraction;
121 TestRenderController& TestApplication::GetRenderController()
123 return mRenderController;
126 TestGlAbstraction& TestApplication::GetGlAbstraction()
128 return mGlAbstraction;
131 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
133 return mGlSyncAbstraction;
136 TestGestureManager& TestApplication::GetGestureManager()
138 return mGestureManager;
141 void TestApplication::ProcessEvent(const Integration::Event& event)
143 mCore->QueueEvent(event);
144 mCore->ProcessEvents();
147 void TestApplication::SendNotification()
149 mCore->ProcessEvents();
152 void TestApplication::SetSurfaceWidth( uint32_t width, uint32_t height )
154 mSurfaceWidth = width;
155 mSurfaceHeight = height;
157 mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
160 void TestApplication::SetTopMargin( uint32_t margin )
162 mCore->SetTopMargin( margin );
165 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
167 if( GetUpdateStatus() == 0 &&
168 mRenderStatus.NeedsUpdate() == false &&
169 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
171 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
174 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
175 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
177 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
179 GetRenderController().Initialize();
181 mLastVSyncTime = nextVSyncTime;
184 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
186 DoUpdate( intervalMilliseconds, location );
187 mCore->Render( mRenderStatus, false );
191 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
194 uint32_t TestApplication::GetUpdateStatus()
196 return mStatus.KeepUpdating();
199 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
201 DoUpdate( intervalMilliseconds );
202 return mStatus.KeepUpdating();
205 bool TestApplication::GetRenderNeedsUpdate()
207 return mRenderStatus.NeedsUpdate();
210 bool TestApplication::RenderOnly( )
212 // Update Time values
213 mCore->Render( mRenderStatus, false );
217 return mRenderStatus.NeedsUpdate();
220 void TestApplication::ResetContext()
222 mCore->ContextDestroyed();
223 mGlAbstraction.Initialize();
224 mCore->ContextCreated();
227 uint32_t TestApplication::Wait( uint32_t durationToWait )
231 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
234 Render(RENDER_FRAME_INTERVAL);
235 time += RENDER_FRAME_INTERVAL;