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 );
192 mRenderStatus.SetNeedsUpdate( false );
193 mRenderStatus.SetNeedsPostRender( false );
195 mCore->PreRender( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
196 mCore->RenderScene( mRenderStatus, mScene, true /*render the off-screen buffers*/);
197 mCore->RenderScene( mRenderStatus, mScene, false /*render the surface*/);
198 mCore->PostRender( false /*do not skip rendering*/ );
202 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
205 uint32_t TestApplication::GetUpdateStatus()
207 return mStatus.KeepUpdating();
210 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
212 DoUpdate( intervalMilliseconds );
213 return mStatus.KeepUpdating();
216 bool TestApplication::GetRenderNeedsUpdate()
218 return mRenderStatus.NeedsUpdate();
221 bool TestApplication::GetRenderNeedsPostRender()
223 return mRenderStatus.NeedsPostRender();
226 bool TestApplication::RenderOnly( )
228 // Update Time values
229 mCore->PreRender( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
230 mCore->RenderScene( mRenderStatus, mScene, true /*render the off-screen buffers*/);
231 mCore->RenderScene( mRenderStatus, mScene, false /*render the surface*/);
232 mCore->PostRender( false /*do not skip rendering*/ );
236 return mRenderStatus.NeedsUpdate();
239 void TestApplication::ResetContext()
241 mCore->ContextDestroyed();
242 mGlAbstraction.Initialize();
243 mCore->ContextCreated();
246 uint32_t TestApplication::Wait( uint32_t durationToWait )
250 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
253 Render(RENDER_FRAME_INTERVAL);
254 time += RENDER_FRAME_INTERVAL;