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,
51 Integration::RenderToFrameBuffer::FALSE,
52 Integration::DepthBufferAvailable::TRUE,
53 Integration::StencilBufferAvailable::TRUE );
55 mCore->ContextCreated();
57 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
58 Dali::Integration::Log::InstallLogFunction(logFunction);
60 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
61 Dali::Integration::Trace::InstallLogContextFunction( logContextFunction );
63 Dali::Integration::Trace::LogContext( true, "Test" );
65 mRenderSurface = new TestRenderSurface( Dali::PositionSize( 0, 0, mSurfaceWidth, mSurfaceHeight ) );
66 mScene = Dali::Integration::Scene::New( Vector2( static_cast<float>( mSurfaceWidth ), static_cast<float>( mSurfaceHeight ) ) );
67 mScene.SetSurface( *mRenderSurface );
69 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
71 mCore->SurfaceResized( mRenderSurface );
73 mCore->SceneCreated();
77 TestApplication::~TestApplication()
79 Dali::Integration::Log::UninstallLogFunction();
80 delete mRenderSurface;
84 void TestApplication::LogContext( bool start, const char* tag )
88 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
92 fprintf(stderr, "INFO: Trace End: %s\n", tag);
96 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
102 case Dali::Integration::Log::DebugInfo:
103 fprintf(stderr, "INFO: %s", message.c_str());
105 case Dali::Integration::Log::DebugWarning:
106 fprintf(stderr, "WARN: %s", message.c_str());
108 case Dali::Integration::Log::DebugError:
109 fprintf(stderr, "ERROR: %s", message.c_str());
112 fprintf(stderr, "DEFAULT: %s", message.c_str());
118 Dali::Integration::Core& TestApplication::GetCore()
123 TestPlatformAbstraction& TestApplication::GetPlatform()
125 return mPlatformAbstraction;
128 TestRenderController& TestApplication::GetRenderController()
130 return mRenderController;
133 TestGlAbstraction& TestApplication::GetGlAbstraction()
135 return mGlAbstraction;
138 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
140 return mGlSyncAbstraction;
143 void TestApplication::ProcessEvent(const Integration::Event& event)
145 mCore->QueueEvent(event);
146 mCore->ProcessEvents();
149 void TestApplication::SendNotification()
151 mCore->ProcessEvents();
154 void TestApplication::DoUpdate( uint32_t intervalMilliseconds, const char* location )
156 if( GetUpdateStatus() == 0 &&
157 mRenderStatus.NeedsUpdate() == false &&
158 ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
160 fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
163 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
164 float elapsedSeconds = static_cast<float>( intervalMilliseconds ) * 0.001f;
166 mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
168 GetRenderController().Initialize();
170 mLastVSyncTime = nextVSyncTime;
173 bool TestApplication::Render( uint32_t intervalMilliseconds, const char* location )
175 DoUpdate( intervalMilliseconds, location );
176 mCore->Render( mRenderStatus, false );
180 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
183 uint32_t TestApplication::GetUpdateStatus()
185 return mStatus.KeepUpdating();
188 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
190 DoUpdate( intervalMilliseconds );
191 return mStatus.KeepUpdating();
194 bool TestApplication::GetRenderNeedsUpdate()
196 return mRenderStatus.NeedsUpdate();
199 bool TestApplication::RenderOnly( )
201 // Update Time values
202 mCore->Render( mRenderStatus, false );
206 return mRenderStatus.NeedsUpdate();
209 void TestApplication::ResetContext()
211 mCore->ContextDestroyed();
212 mGlAbstraction.Initialize();
213 mCore->ContextCreated();
216 uint32_t TestApplication::Wait( uint32_t durationToWait )
220 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
223 Render(RENDER_FRAME_INTERVAL);
224 time += RENDER_FRAME_INTERVAL;