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,
30 : mRenderSurface( NULL ),
32 mSurfaceWidth( surfaceWidth ),
33 mSurfaceHeight( surfaceHeight ),
35 mDpi{ horizontalDpi, verticalDpi },
44 void TestApplication::Initialize()
51 void TestApplication::CreateCore()
53 // We always need the first update!
54 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
56 mCore = Dali::Integration::Core::New( mRenderController,
60 mGlContextHelperAbstraction,
61 Integration::RenderToFrameBuffer::FALSE,
62 Integration::DepthBufferAvailable::TRUE,
63 Integration::StencilBufferAvailable::TRUE,
64 Integration::PartialUpdateAvailable::FALSE );
66 mCore->ContextCreated();
68 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
69 Dali::Integration::Log::InstallLogFunction(logFunction);
71 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
72 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
74 Dali::Integration::Trace::LogContext( true, "Test" );
77 void TestApplication::CreateScene()
79 mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) );
80 mScene = Dali::Integration::Scene::New( *mRenderSurface );
81 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
84 void TestApplication::InitializeCore()
86 mCore->SceneCreated();
90 TestApplication::~TestApplication()
92 Dali::Integration::Log::UninstallLogFunction();
93 delete mRenderSurface;
97 void TestApplication::LogContext( bool start, const char* tag )
101 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
105 fprintf(stderr, "INFO: Trace End: %s\n", tag);
109 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
111 if( mLoggingEnabled )
115 case Dali::Integration::Log::DebugInfo:
116 fprintf(stderr, "INFO: %s", message.c_str());
118 case Dali::Integration::Log::DebugWarning:
119 fprintf(stderr, "WARN: %s", message.c_str());
121 case Dali::Integration::Log::DebugError:
122 fprintf(stderr, "ERROR: %s", message.c_str());
125 fprintf(stderr, "DEFAULT: %s", message.c_str());
131 Dali::Integration::Core& TestApplication::GetCore()
136 TestPlatformAbstraction& TestApplication::GetPlatform()
138 return mPlatformAbstraction;
141 TestRenderController& TestApplication::GetRenderController()
143 return mRenderController;
146 TestGlAbstraction& TestApplication::GetGlAbstraction()
148 return mGlAbstraction;
151 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
153 return mGlSyncAbstraction;
156 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
158 return mGlContextHelperAbstraction;
161 void TestApplication::ProcessEvent(const Integration::Event& event)
163 mCore->QueueEvent(event);
164 mCore->ProcessEvents();
167 void TestApplication::SendNotification()
169 mCore->ProcessEvents();
172 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
174 if( GetUpdateStatus() == 0 &&
175 mRenderStatus.NeedsUpdate() == false &&
176 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
178 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
181 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
182 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
184 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
186 GetRenderController().Initialize();
188 mLastVSyncTime = nextVSyncTime;
191 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
193 DoUpdate( intervalMilliseconds, location );
194 mCore->Render( mRenderStatus, false /*do not force clear*/, 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->Render( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
224 return mRenderStatus.NeedsUpdate();
227 void TestApplication::ResetContext()
229 mCore->ContextDestroyed();
230 mGlAbstraction.Initialize();
231 mCore->ContextCreated();
234 uint32_t TestApplication::Wait( uint32_t durationToWait )
238 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
241 Render(RENDER_FRAME_INTERVAL);
242 time += RENDER_FRAME_INTERVAL;