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,
61 mGlContextHelperAbstraction,
63 Integration::RenderToFrameBuffer::FALSE,
64 Integration::DepthBufferAvailable::TRUE,
65 Integration::StencilBufferAvailable::TRUE );
67 mCore->ContextCreated();
69 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
70 Dali::Integration::Log::InstallLogFunction(logFunction);
72 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
73 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
75 Dali::Integration::Trace::LogContext( true, "Test" );
78 void TestApplication::CreateScene()
80 mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) );
81 mScene = Dali::Integration::Scene::New( Vector2( static_cast<float>( mSurfaceWidth ), static_cast<float>( mSurfaceHeight ) ) );
82 mScene.SetSurface( *mRenderSurface );
83 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
85 mCore->SurfaceResized( mRenderSurface );
88 void TestApplication::InitializeCore()
90 mCore->SceneCreated();
94 TestApplication::~TestApplication()
96 Dali::Integration::Log::UninstallLogFunction();
97 delete mRenderSurface;
101 void TestApplication::LogContext( bool start, const char* tag )
105 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
109 fprintf(stderr, "INFO: Trace End: %s\n", tag);
113 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
115 if( mLoggingEnabled )
119 case Dali::Integration::Log::DebugInfo:
120 fprintf(stderr, "INFO: %s", message.c_str());
122 case Dali::Integration::Log::DebugWarning:
123 fprintf(stderr, "WARN: %s", message.c_str());
125 case Dali::Integration::Log::DebugError:
126 fprintf(stderr, "ERROR: %s", message.c_str());
129 fprintf(stderr, "DEFAULT: %s", message.c_str());
135 Dali::Integration::Core& TestApplication::GetCore()
140 TestPlatformAbstraction& TestApplication::GetPlatform()
142 return mPlatformAbstraction;
145 TestRenderController& TestApplication::GetRenderController()
147 return mRenderController;
150 TestGlAbstraction& TestApplication::GetGlAbstraction()
152 return mGlAbstraction;
155 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
157 return mGlSyncAbstraction;
160 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
162 return mGlContextHelperAbstraction;
165 void TestApplication::ProcessEvent(const Integration::Event& event)
167 mCore->QueueEvent(event);
168 mCore->ProcessEvents();
171 void TestApplication::SendNotification()
173 mCore->ProcessEvents();
176 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
178 if( GetUpdateStatus() == 0 &&
179 mRenderStatus.NeedsUpdate() == false &&
180 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
182 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
185 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
186 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
188 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
190 GetRenderController().Initialize();
192 mLastVSyncTime = nextVSyncTime;
195 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
197 DoUpdate( intervalMilliseconds, location );
198 mCore->Render( mRenderStatus, false );
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::RenderOnly( )
223 // Update Time values
224 mCore->Render( mRenderStatus, false );
228 return mRenderStatus.NeedsUpdate();
231 void TestApplication::ResetContext()
233 mCore->ContextDestroyed();
234 mGlAbstraction.Initialize();
235 mCore->ContextCreated();
238 uint32_t TestApplication::Wait( uint32_t durationToWait )
242 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
245 Render(RENDER_FRAME_INTERVAL);
246 time += RENDER_FRAME_INTERVAL;