2 * Copyright (c) 2019 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 : mRenderSurface( NULL ),
33 mSurfaceWidth( surfaceWidth ),
34 mSurfaceHeight( surfaceHeight ),
36 mDpi{ horizontalDpi, verticalDpi },
38 mDataRetentionPolicy( policy )
46 void TestApplication::Initialize()
53 void TestApplication::CreateCore()
55 // We always need the first update!
56 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
58 mCore = Dali::Integration::Core::New( mRenderController,
62 mGlContextHelperAbstraction,
64 Integration::RenderToFrameBuffer::FALSE,
65 Integration::DepthBufferAvailable::TRUE,
66 Integration::StencilBufferAvailable::TRUE );
68 mCore->ContextCreated();
70 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
71 Dali::Integration::Log::InstallLogFunction(logFunction);
73 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
74 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
76 Dali::Integration::Trace::LogContext( true, "Test" );
79 void TestApplication::CreateScene()
81 mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) );
82 mScene = Dali::Integration::Scene::New( *mRenderSurface );
83 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
86 void TestApplication::InitializeCore()
88 mCore->SceneCreated();
92 TestApplication::~TestApplication()
94 Dali::Integration::Log::UninstallLogFunction();
95 delete mRenderSurface;
99 void TestApplication::LogContext( bool start, const char* tag )
103 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
107 fprintf(stderr, "INFO: Trace End: %s\n", tag);
111 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
113 if( mLoggingEnabled )
117 case Dali::Integration::Log::DebugInfo:
118 fprintf(stderr, "INFO: %s", message.c_str());
120 case Dali::Integration::Log::DebugWarning:
121 fprintf(stderr, "WARN: %s", message.c_str());
123 case Dali::Integration::Log::DebugError:
124 fprintf(stderr, "ERROR: %s", message.c_str());
127 fprintf(stderr, "DEFAULT: %s", message.c_str());
133 Dali::Integration::Core& TestApplication::GetCore()
138 TestPlatformAbstraction& TestApplication::GetPlatform()
140 return mPlatformAbstraction;
143 TestRenderController& TestApplication::GetRenderController()
145 return mRenderController;
148 TestGlAbstraction& TestApplication::GetGlAbstraction()
150 return mGlAbstraction;
153 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
155 return mGlSyncAbstraction;
158 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
160 return mGlContextHelperAbstraction;
163 void TestApplication::ProcessEvent(const Integration::Event& event)
165 mCore->QueueEvent(event);
166 mCore->ProcessEvents();
169 void TestApplication::SendNotification()
171 mCore->ProcessEvents();
174 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
176 if( GetUpdateStatus() == 0 &&
177 mRenderStatus.NeedsUpdate() == false &&
178 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
180 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
183 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
184 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
186 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
188 GetRenderController().Initialize();
190 mLastVSyncTime = nextVSyncTime;
193 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
195 DoUpdate( intervalMilliseconds, location );
196 mCore->Render( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
200 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
203 uint32_t TestApplication::GetUpdateStatus()
205 return mStatus.KeepUpdating();
208 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
210 DoUpdate( intervalMilliseconds );
211 return mStatus.KeepUpdating();
214 bool TestApplication::GetRenderNeedsUpdate()
216 return mRenderStatus.NeedsUpdate();
219 bool TestApplication::RenderOnly( )
221 // Update Time values
222 mCore->Render( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
226 return mRenderStatus.NeedsUpdate();
229 void TestApplication::ResetContext()
231 mCore->ContextDestroyed();
232 mGlAbstraction.Initialize();
233 mCore->ContextCreated();
236 uint32_t TestApplication::Wait( uint32_t durationToWait )
240 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
243 Render(RENDER_FRAME_INTERVAL);
244 time += RENDER_FRAME_INTERVAL;