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,
67 Integration::PartialUpdateAvailable::FALSE );
69 mCore->ContextCreated();
71 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
72 Dali::Integration::Log::InstallLogFunction(logFunction);
74 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
75 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
77 Dali::Integration::Trace::LogContext( true, "Test" );
80 void TestApplication::CreateScene()
82 mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) );
83 mScene = Dali::Integration::Scene::New( *mRenderSurface );
84 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
87 void TestApplication::InitializeCore()
89 mCore->SceneCreated();
93 TestApplication::~TestApplication()
95 Dali::Integration::Log::UninstallLogFunction();
96 delete mRenderSurface;
100 void TestApplication::LogContext( bool start, const char* tag )
104 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
108 fprintf(stderr, "INFO: Trace End: %s\n", tag);
112 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
114 if( mLoggingEnabled )
118 case Dali::Integration::Log::DebugInfo:
119 fprintf(stderr, "INFO: %s", message.c_str());
121 case Dali::Integration::Log::DebugWarning:
122 fprintf(stderr, "WARN: %s", message.c_str());
124 case Dali::Integration::Log::DebugError:
125 fprintf(stderr, "ERROR: %s", message.c_str());
128 fprintf(stderr, "DEFAULT: %s", message.c_str());
134 Dali::Integration::Core& TestApplication::GetCore()
139 TestPlatformAbstraction& TestApplication::GetPlatform()
141 return mPlatformAbstraction;
144 TestRenderController& TestApplication::GetRenderController()
146 return mRenderController;
149 TestGlAbstraction& TestApplication::GetGlAbstraction()
151 return mGlAbstraction;
154 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
156 return mGlSyncAbstraction;
159 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
161 return mGlContextHelperAbstraction;
164 void TestApplication::ProcessEvent(const Integration::Event& event)
166 mCore->QueueEvent(event);
167 mCore->ProcessEvents();
170 void TestApplication::SendNotification()
172 mCore->ProcessEvents();
175 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
177 if( GetUpdateStatus() == 0 &&
178 mRenderStatus.NeedsUpdate() == false &&
179 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
181 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
184 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
185 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
187 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
189 GetRenderController().Initialize();
191 mLastVSyncTime = nextVSyncTime;
194 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
196 DoUpdate( intervalMilliseconds, location );
197 mCore->Render( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
201 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
204 uint32_t TestApplication::GetUpdateStatus()
206 return mStatus.KeepUpdating();
209 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
211 DoUpdate( intervalMilliseconds );
212 return mStatus.KeepUpdating();
215 bool TestApplication::GetRenderNeedsUpdate()
217 return mRenderStatus.NeedsUpdate();
220 bool TestApplication::RenderOnly( )
222 // Update Time values
223 mCore->Render( mRenderStatus, false /*do not force clear*/, 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;