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,
32 mSurfaceWidth( surfaceWidth ),
33 mSurfaceHeight( surfaceHeight ),
35 mDpi{ horizontalDpi, verticalDpi },
37 mDataRetentionPolicy( policy )
45 void TestApplication::Initialize()
52 void TestApplication::CreateCore()
54 // We always need the first update!
55 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
57 mCore = Dali::Integration::Core::New( mRenderController,
62 Integration::RenderToFrameBuffer::FALSE,
63 Integration::DepthBufferAvailable::TRUE,
64 Integration::StencilBufferAvailable::TRUE );
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( Vector2( static_cast<float>( mSurfaceWidth ), static_cast<float>( mSurfaceHeight ) ) );
81 mScene.SetSurface( *mRenderSurface );
82 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
84 mCore->SurfaceResized( mRenderSurface );
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 void TestApplication::ProcessEvent(const Integration::Event& event)
161 mCore->QueueEvent(event);
162 mCore->ProcessEvents();
165 void TestApplication::SendNotification()
167 mCore->ProcessEvents();
170 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
172 if( GetUpdateStatus() == 0 &&
173 mRenderStatus.NeedsUpdate() == false &&
174 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
176 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
179 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
180 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
182 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
184 GetRenderController().Initialize();
186 mLastVSyncTime = nextVSyncTime;
189 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
191 DoUpdate( intervalMilliseconds, location );
192 mCore->Render( mRenderStatus, false );
196 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
199 uint32_t TestApplication::GetUpdateStatus()
201 return mStatus.KeepUpdating();
204 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
206 DoUpdate( intervalMilliseconds );
207 return mStatus.KeepUpdating();
210 bool TestApplication::GetRenderNeedsUpdate()
212 return mRenderStatus.NeedsUpdate();
215 bool TestApplication::RenderOnly( )
217 // Update Time values
218 mCore->Render( mRenderStatus, false );
222 return mRenderStatus.NeedsUpdate();
225 void TestApplication::ResetContext()
227 mCore->ContextDestroyed();
228 mGlAbstraction.Initialize();
229 mCore->ContextCreated();
232 uint32_t TestApplication::Wait( uint32_t durationToWait )
236 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
239 Render(RENDER_FRAME_INTERVAL);
240 time += RENDER_FRAME_INTERVAL;