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"
22 bool TestApplication::mLoggingEnabled = true;
24 TestApplication::TestApplication(uint32_t surfaceWidth,
25 uint32_t surfaceHeight,
26 uint32_t horizontalDpi,
29 bool enablePartialUpdate)
31 mSurfaceWidth(surfaceWidth),
32 mSurfaceHeight(surfaceHeight),
34 mDpi{horizontalDpi, verticalDpi},
36 mPartialUpdateEnabled(enablePartialUpdate)
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,
64 mPartialUpdateEnabled ? Integration::PartialUpdateAvailable::TRUE : Integration::PartialUpdateAvailable::FALSE);
66 mCore->ContextCreated();
68 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
69 Dali::Integration::Log::InstallLogFunction(logFunction);
71 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
72 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
74 Dali::Integration::Trace::LogContext(true, "Test");
77 void TestApplication::CreateScene()
79 mScene = Dali::Integration::Scene::New(Size(static_cast<float>(mSurfaceWidth), static_cast<float>(mSurfaceHeight)));
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();
95 void TestApplication::LogContext(bool start, const char* tag)
99 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
103 fprintf(stderr, "INFO: Trace End: %s\n", tag);
107 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
113 case Dali::Integration::Log::DebugInfo:
114 fprintf(stderr, "INFO: %s", message.c_str());
116 case Dali::Integration::Log::DebugWarning:
117 fprintf(stderr, "WARN: %s", message.c_str());
119 case Dali::Integration::Log::DebugError:
120 fprintf(stderr, "ERROR: %s", message.c_str());
123 fprintf(stderr, "DEFAULT: %s", message.c_str());
129 Dali::Integration::Core& TestApplication::GetCore()
134 TestPlatformAbstraction& TestApplication::GetPlatform()
136 return mPlatformAbstraction;
139 TestRenderController& TestApplication::GetRenderController()
141 return mRenderController;
144 TestGlAbstraction& TestApplication::GetGlAbstraction()
146 return mGlAbstraction;
149 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
151 return mGlSyncAbstraction;
154 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
156 return mGlContextHelperAbstraction;
159 void TestApplication::ProcessEvent(const Integration::Event& event)
161 mCore->QueueEvent(event);
162 mCore->ProcessEvents();
165 void TestApplication::SendNotification()
167 mCore->ProcessEvents();
170 void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location)
172 if(GetUpdateStatus() == 0 &&
173 mRenderStatus.NeedsUpdate() == false &&
174 !GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc))
176 fprintf(stderr, "WARNING - Update not required :%s\n", location == NULL ? "NULL" : location);
179 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
180 float elapsedSeconds = static_cast<float>(intervalMilliseconds) * 0.001f;
182 mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false);
184 GetRenderController().Initialize();
186 mLastVSyncTime = nextVSyncTime;
189 bool TestApplication::Render(uint32_t intervalMilliseconds, const char* location)
191 DoUpdate(intervalMilliseconds, location);
194 mRenderStatus.SetNeedsUpdate(false);
195 mRenderStatus.SetNeedsPostRender(false);
197 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
198 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
199 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
200 mCore->PostRender(false /*do not skip rendering*/);
204 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
207 bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
209 DoUpdate(intervalMilliseconds, location);
211 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
212 mCore->PreRender(mScene, damagedRects);
214 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
217 bool TestApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
219 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/, clippingRect);
220 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
221 mCore->PostRender(false /*do not skip rendering*/);
225 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
228 uint32_t TestApplication::GetUpdateStatus()
230 return mStatus.KeepUpdating();
233 bool TestApplication::UpdateOnly(uint32_t intervalMilliseconds)
235 DoUpdate(intervalMilliseconds);
236 return mStatus.KeepUpdating();
239 bool TestApplication::GetRenderNeedsUpdate()
241 return mRenderStatus.NeedsUpdate();
244 bool TestApplication::GetRenderNeedsPostRender()
246 return mRenderStatus.NeedsPostRender();
249 bool TestApplication::RenderOnly()
251 // Update Time values
252 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
253 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
254 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
255 mCore->PostRender(false /*do not skip rendering*/);
259 return mRenderStatus.NeedsUpdate();
262 void TestApplication::ResetContext()
264 mCore->ContextDestroyed();
265 mGlAbstraction.Initialize();
266 mCore->ContextCreated();
269 uint32_t TestApplication::Wait(uint32_t durationToWait)
273 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
276 Render(RENDER_FRAME_INTERVAL);
277 time += RENDER_FRAME_INTERVAL;