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( *mRenderSurface );
82 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
85 void TestApplication::InitializeCore()
87 mCore->SceneCreated();
91 TestApplication::~TestApplication()
93 Dali::Integration::Log::UninstallLogFunction();
94 delete mRenderSurface;
98 void TestApplication::LogContext( bool start, const char* tag )
102 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
106 fprintf(stderr, "INFO: Trace End: %s\n", tag);
110 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
112 if( mLoggingEnabled )
116 case Dali::Integration::Log::DebugInfo:
117 fprintf(stderr, "INFO: %s", message.c_str());
119 case Dali::Integration::Log::DebugWarning:
120 fprintf(stderr, "WARN: %s", message.c_str());
122 case Dali::Integration::Log::DebugError:
123 fprintf(stderr, "ERROR: %s", message.c_str());
126 fprintf(stderr, "DEFAULT: %s", message.c_str());
132 Dali::Integration::Core& TestApplication::GetCore()
137 TestPlatformAbstraction& TestApplication::GetPlatform()
139 return mPlatformAbstraction;
142 TestRenderController& TestApplication::GetRenderController()
144 return mRenderController;
147 TestGlAbstraction& TestApplication::GetGlAbstraction()
149 return mGlAbstraction;
152 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
154 return mGlSyncAbstraction;
157 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
159 return mGlContextHelperAbstraction;
162 void TestApplication::ProcessEvent(const Integration::Event& event)
164 mCore->QueueEvent(event);
165 mCore->ProcessEvents();
168 void TestApplication::SendNotification()
170 mCore->ProcessEvents();
173 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
175 if( GetUpdateStatus() == 0 &&
176 mRenderStatus.NeedsUpdate() == false &&
177 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
179 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
182 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
183 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
185 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
187 GetRenderController().Initialize();
189 mLastVSyncTime = nextVSyncTime;
192 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
194 DoUpdate( intervalMilliseconds, location );
195 mCore->Render( mRenderStatus, false );
199 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
202 uint32_t TestApplication::GetUpdateStatus()
204 return mStatus.KeepUpdating();
207 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
209 DoUpdate( intervalMilliseconds );
210 return mStatus.KeepUpdating();
213 bool TestApplication::GetRenderNeedsUpdate()
215 return mRenderStatus.NeedsUpdate();
218 bool TestApplication::RenderOnly( )
220 // Update Time values
221 mCore->Render( mRenderStatus, false );
225 return mRenderStatus.NeedsUpdate();
228 void TestApplication::ResetContext()
230 mCore->ContextDestroyed();
231 mGlAbstraction.Initialize();
232 mCore->ContextCreated();
235 uint32_t TestApplication::Wait( uint32_t durationToWait )
239 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
242 Render(RENDER_FRAME_INTERVAL);
243 time += RENDER_FRAME_INTERVAL;