2 * Copyright (c) 2020 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,
31 mSurfaceWidth( surfaceWidth ),
32 mSurfaceHeight( surfaceHeight ),
34 mDpi{ horizontalDpi, verticalDpi },
43 void TestApplication::Initialize()
50 void TestApplication::CreateCore()
52 // We always need the first update!
53 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
55 mCore = Dali::Integration::Core::New( mRenderController,
59 mGlContextHelperAbstraction,
60 Integration::RenderToFrameBuffer::FALSE,
61 Integration::DepthBufferAvailable::TRUE,
62 Integration::StencilBufferAvailable::TRUE );
64 mCore->ContextCreated();
66 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
67 Dali::Integration::Log::InstallLogFunction(logFunction);
69 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
70 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
72 Dali::Integration::Trace::LogContext( true, "Test" );
75 void TestApplication::CreateScene()
77 mScene = Dali::Integration::Scene::New( Size( static_cast<float>( mSurfaceWidth ), static_cast<float>( mSurfaceHeight ) ) );
78 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
81 void TestApplication::InitializeCore()
83 mCore->SceneCreated();
87 TestApplication::~TestApplication()
89 Dali::Integration::Log::UninstallLogFunction();
93 void TestApplication::LogContext( bool start, const char* tag )
97 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
101 fprintf(stderr, "INFO: Trace End: %s\n", tag);
105 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
107 if( mLoggingEnabled )
111 case Dali::Integration::Log::DebugInfo:
112 fprintf(stderr, "INFO: %s", message.c_str());
114 case Dali::Integration::Log::DebugWarning:
115 fprintf(stderr, "WARN: %s", message.c_str());
117 case Dali::Integration::Log::DebugError:
118 fprintf(stderr, "ERROR: %s", message.c_str());
121 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 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
154 return mGlContextHelperAbstraction;
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::DoUpdate( uint32_t intervalMilliseconds, const char* location )
170 if( GetUpdateStatus() == 0 &&
171 mRenderStatus.NeedsUpdate() == false &&
172 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
174 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
177 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
178 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
180 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
182 GetRenderController().Initialize();
184 mLastVSyncTime = nextVSyncTime;
187 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
189 DoUpdate( intervalMilliseconds, location );
191 mCore->PreRender( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
192 mCore->RenderScene( mScene, true /*render the off-screen buffers*/);
193 mCore->RenderScene( mScene, false /*render the surface*/);
194 mCore->PostRender( false /*do not skip rendering*/ );
198 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
201 uint32_t TestApplication::GetUpdateStatus()
203 return mStatus.KeepUpdating();
206 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
208 DoUpdate( intervalMilliseconds );
209 return mStatus.KeepUpdating();
212 bool TestApplication::GetRenderNeedsUpdate()
214 return mRenderStatus.NeedsUpdate();
217 bool TestApplication::RenderOnly( )
219 // Update Time values
220 mCore->PreRender( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
221 mCore->RenderScene( mScene, true /*render the off-screen buffers*/);
222 mCore->RenderScene( mScene, false /*render the surface*/);
223 mCore->PostRender( false /*do not skip rendering*/ );
227 return mRenderStatus.NeedsUpdate();
230 void TestApplication::ResetContext()
232 mCore->ContextDestroyed();
233 mGlAbstraction.Initialize();
234 mCore->ContextCreated();
237 uint32_t TestApplication::Wait( uint32_t durationToWait )
241 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
244 Render(RENDER_FRAME_INTERVAL);
245 time += RENDER_FRAME_INTERVAL;