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 );
65 mCore->ContextCreated();
67 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
68 Dali::Integration::Log::InstallLogFunction(logFunction);
70 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
71 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
73 Dali::Integration::Trace::LogContext( true, "Test" );
76 void TestApplication::CreateScene()
78 mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) );
79 mScene = Dali::Integration::Scene::New( *mRenderSurface );
80 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
83 void TestApplication::InitializeCore()
85 mCore->SceneCreated();
89 TestApplication::~TestApplication()
91 Dali::Integration::Log::UninstallLogFunction();
92 delete mRenderSurface;
96 void TestApplication::LogContext( bool start, const char* tag )
100 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
104 fprintf(stderr, "INFO: Trace End: %s\n", tag);
108 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
110 if( mLoggingEnabled )
114 case Dali::Integration::Log::DebugInfo:
115 fprintf(stderr, "INFO: %s", message.c_str());
117 case Dali::Integration::Log::DebugWarning:
118 fprintf(stderr, "WARN: %s", message.c_str());
120 case Dali::Integration::Log::DebugError:
121 fprintf(stderr, "ERROR: %s", message.c_str());
124 fprintf(stderr, "DEFAULT: %s", message.c_str());
130 Dali::Integration::Core& TestApplication::GetCore()
135 TestPlatformAbstraction& TestApplication::GetPlatform()
137 return mPlatformAbstraction;
140 TestRenderController& TestApplication::GetRenderController()
142 return mRenderController;
145 TestGlAbstraction& TestApplication::GetGlAbstraction()
147 return mGlAbstraction;
150 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
152 return mGlSyncAbstraction;
155 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
157 return mGlContextHelperAbstraction;
160 void TestApplication::ProcessEvent(const Integration::Event& event)
162 mCore->QueueEvent(event);
163 mCore->ProcessEvents();
166 void TestApplication::SendNotification()
168 mCore->ProcessEvents();
171 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
173 if( GetUpdateStatus() == 0 &&
174 mRenderStatus.NeedsUpdate() == false &&
175 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
177 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
180 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
181 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
183 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
185 GetRenderController().Initialize();
187 mLastVSyncTime = nextVSyncTime;
190 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
192 DoUpdate( intervalMilliseconds, location );
193 mCore->Render( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
197 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
200 uint32_t TestApplication::GetUpdateStatus()
202 return mStatus.KeepUpdating();
205 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
207 DoUpdate( intervalMilliseconds );
208 return mStatus.KeepUpdating();
211 bool TestApplication::GetRenderNeedsUpdate()
213 return mRenderStatus.NeedsUpdate();
216 bool TestApplication::RenderOnly( )
218 // Update Time values
219 mCore->Render( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
223 return mRenderStatus.NeedsUpdate();
226 void TestApplication::ResetContext()
228 mCore->ContextDestroyed();
229 mGlAbstraction.Initialize();
230 mCore->ContextCreated();
233 uint32_t TestApplication::Wait( uint32_t durationToWait )
237 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
240 Render(RENDER_FRAME_INTERVAL);
241 time += RENDER_FRAME_INTERVAL;