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 bool enablePartialUpdate )
32 mSurfaceWidth( surfaceWidth ),
33 mSurfaceHeight( surfaceHeight ),
35 mDpi{ horizontalDpi, verticalDpi },
37 mPartialUpdateEnabled(enablePartialUpdate)
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,
62 Integration::RenderToFrameBuffer::FALSE,
63 Integration::DepthBufferAvailable::TRUE,
64 Integration::StencilBufferAvailable::TRUE,
65 mPartialUpdateEnabled ? Integration::PartialUpdateAvailable::TRUE : Integration::PartialUpdateAvailable::FALSE );
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 mScene = Dali::Integration::Scene::New( Size( static_cast<float>( mSurfaceWidth ), static_cast<float>( mSurfaceHeight ) ) );
81 mScene.SetDpi( Vector2( static_cast<float>( mDpi.x ), static_cast<float>( mDpi.y ) ) );
84 void TestApplication::InitializeCore()
86 mCore->SceneCreated();
90 TestApplication::~TestApplication()
92 Dali::Integration::Log::UninstallLogFunction();
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 );
195 mRenderStatus.SetNeedsUpdate( false );
196 mRenderStatus.SetNeedsPostRender( false );
198 mCore->PreRender( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
199 mCore->RenderScene( mRenderStatus, mScene, true /*render the off-screen buffers*/ );
200 mCore->RenderScene( mRenderStatus, mScene, false /*render the surface*/ );
201 mCore->PostRender( false /*do not skip rendering*/ );
205 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
208 bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
210 DoUpdate(intervalMilliseconds, location);
212 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
213 mCore->PreRender(mScene, damagedRects);
215 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
218 bool TestApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
220 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/, clippingRect);
221 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
222 mCore->PostRender(false /*do not skip rendering*/);
226 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
229 uint32_t TestApplication::GetUpdateStatus()
231 return mStatus.KeepUpdating();
234 bool TestApplication::UpdateOnly( uint32_t intervalMilliseconds )
236 DoUpdate( intervalMilliseconds );
237 return mStatus.KeepUpdating();
240 bool TestApplication::GetRenderNeedsUpdate()
242 return mRenderStatus.NeedsUpdate();
245 bool TestApplication::GetRenderNeedsPostRender()
247 return mRenderStatus.NeedsPostRender();
250 bool TestApplication::RenderOnly( )
252 // Update Time values
253 mCore->PreRender( mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/ );
254 mCore->RenderScene( mRenderStatus, mScene, true /*render the off-screen buffers*/ );
255 mCore->RenderScene( mRenderStatus, mScene, false /*render the surface*/ );
256 mCore->PostRender( false /*do not skip rendering*/ );
260 return mRenderStatus.NeedsUpdate();
263 void TestApplication::ResetContext()
265 mCore->ContextDestroyed();
266 mGlAbstraction.Initialize();
267 mCore->ContextCreated();
270 uint32_t TestApplication::Wait( uint32_t durationToWait )
274 for(uint32_t i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
277 Render(RENDER_FRAME_INTERVAL);
278 time += RENDER_FRAME_INTERVAL;