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 mSurfaceWidth( surfaceWidth ),
32 mSurfaceHeight( surfaceHeight ),
34 mDpi{ horizontalDpi, verticalDpi },
36 mDataRetentionPolicy( policy )
41 void TestApplication::Initialize()
43 // We always need the first update!
44 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
46 mCore = Dali::Integration::Core::New( mRenderController,
52 Integration::RenderToFrameBuffer::FALSE,
53 Integration::DepthBufferAvailable::TRUE,
54 Integration::StencilBufferAvailable::TRUE );
56 mCore->ContextCreated();
58 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
59 Dali::Integration::Log::InstallLogFunction(logFunction);
61 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
62 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
64 Dali::Integration::Trace::LogContext( true, "Test" );
66 mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) );
67 mScene = Dali::Integration::Scene::New( Vector2( static_cast<float>( mSurfaceWidth ), static_cast<float>( mSurfaceHeight ) ) );
68 mScene.SetSurface( *mRenderSurface );
70 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
72 mCore->SurfaceResized( mRenderSurface );
74 mCore->SceneCreated();
78 TestApplication::~TestApplication()
80 Dali::Integration::Log::UninstallLogFunction();
81 delete mRenderSurface;
85 void TestApplication::LogContext( bool start, const char* tag )
89 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
93 fprintf(stderr, "INFO: Trace End: %s\n", tag);
97 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
103 case Dali::Integration::Log::DebugInfo:
104 fprintf(stderr, "INFO: %s", message.c_str());
106 case Dali::Integration::Log::DebugWarning:
107 fprintf(stderr, "WARN: %s", message.c_str());
109 case Dali::Integration::Log::DebugError:
110 fprintf(stderr, "ERROR: %s", message.c_str());
113 fprintf(stderr, "DEFAULT: %s", message.c_str());
119 Dali::Integration::Core& TestApplication::GetCore()
124 TestPlatformAbstraction& TestApplication::GetPlatform()
126 return mPlatformAbstraction;
129 TestRenderController& TestApplication::GetRenderController()
131 return mRenderController;
134 TestGlAbstraction& TestApplication::GetGlAbstraction()
136 return mGlAbstraction;
139 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
141 return mGlSyncAbstraction;
144 TestGestureManager& TestApplication::GetGestureManager()
146 return mGestureManager;
149 void TestApplication::ProcessEvent(const Integration::Event& event)
151 mCore->QueueEvent(event);
152 mCore->ProcessEvents();
155 void TestApplication::SendNotification()
157 mCore->ProcessEvents();
160 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
162 if( GetUpdateStatus() == 0 &&
163 mRenderStatus.NeedsUpdate() == false &&
164 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
166 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
169 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
170 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
172 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
174 GetRenderController().Initialize();
176 mLastVSyncTime = nextVSyncTime;
179 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
181 DoUpdate( intervalMilliseconds, location );
182 mCore->Render( mRenderStatus, false );
186 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
189 uint32_t TestApplication::GetUpdateStatus()
191 return mStatus.KeepUpdating();
194 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
196 DoUpdate( intervalMilliseconds );
197 return mStatus.KeepUpdating();
200 bool TestApplication::GetRenderNeedsUpdate()
202 return mRenderStatus.NeedsUpdate();
205 bool TestApplication::RenderOnly( )
207 // Update Time values
208 mCore->Render( mRenderStatus, false );
212 return mRenderStatus.NeedsUpdate();
215 void TestApplication::ResetContext()
217 mCore->ContextDestroyed();
218 mGlAbstraction.Initialize();
219 mCore->ContextCreated();
222 uint32_t TestApplication::Wait( uint32_t durationToWait )
226 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
229 Render(RENDER_FRAME_INTERVAL);
230 time += RENDER_FRAME_INTERVAL;