2 * Copyright (c) 2021 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,
59 Integration::RenderToFrameBuffer::FALSE,
60 Integration::DepthBufferAvailable::TRUE,
61 Integration::StencilBufferAvailable::TRUE,
62 mPartialUpdateEnabled ? Integration::PartialUpdateAvailable::TRUE : Integration::PartialUpdateAvailable::FALSE);
64 mCore->ContextCreated();
66 Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
67 Dali::Integration::Log::InstallLogFunction(logFunction);
69 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
70 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
72 Dali::Integration::Trace::LogContext(true, "Test");
75 void TestApplication::CreateScene()
77 mScene = Dali::Integration::Scene::New(Size(static_cast<float>(mSurfaceWidth), static_cast<float>(mSurfaceHeight)));
78 mScene.SetDpi(Vector2(static_cast<float>(mDpi.x), static_cast<float>(mDpi.y)));
81 void TestApplication::InitializeCore()
83 mCore->SceneCreated();
87 TestApplication::~TestApplication()
89 Dali::Integration::Log::UninstallLogFunction();
93 void TestApplication::LogContext(bool start, const char* tag)
97 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
101 fprintf(stderr, "INFO: Trace End: %s\n", tag);
105 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
111 case Dali::Integration::Log::DebugInfo:
112 fprintf(stderr, "INFO: %s", message.c_str());
114 case Dali::Integration::Log::DebugWarning:
115 fprintf(stderr, "WARN: %s", message.c_str());
117 case Dali::Integration::Log::DebugError:
118 fprintf(stderr, "ERROR: %s", message.c_str());
121 fprintf(stderr, "DEFAULT: %s", message.c_str());
127 Dali::Integration::Core& TestApplication::GetCore()
132 TestPlatformAbstraction& TestApplication::GetPlatform()
134 return mPlatformAbstraction;
137 TestRenderController& TestApplication::GetRenderController()
139 return mRenderController;
142 TestGraphicsController& TestApplication::GetGraphicsController()
144 return mGraphicsController;
147 TestGlAbstraction& TestApplication::GetGlAbstraction()
149 return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
152 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
154 return static_cast<TestGlSyncAbstraction&>(mGraphicsController.GetGlSyncAbstraction());
157 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
159 return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
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);
197 mRenderStatus.SetNeedsUpdate(false);
198 mRenderStatus.SetNeedsPostRender(false);
200 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
201 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
202 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
203 mCore->PostRender(false /*do not skip rendering*/);
207 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
210 bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
212 DoUpdate(intervalMilliseconds, location);
214 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
215 mCore->PreRender(mScene, damagedRects);
217 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
220 bool TestApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
222 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/, clippingRect);
223 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
224 mCore->PostRender(false /*do not skip rendering*/);
228 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
231 uint32_t TestApplication::GetUpdateStatus()
233 return mStatus.KeepUpdating();
236 bool TestApplication::UpdateOnly(uint32_t intervalMilliseconds)
238 DoUpdate(intervalMilliseconds);
239 return mStatus.KeepUpdating();
242 bool TestApplication::GetRenderNeedsUpdate()
244 return mRenderStatus.NeedsUpdate();
247 bool TestApplication::GetRenderNeedsPostRender()
249 return mRenderStatus.NeedsPostRender();
252 bool TestApplication::RenderOnly()
254 // Update Time values
255 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
256 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
257 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
258 mCore->PostRender(false /*do not skip rendering*/);
262 return mRenderStatus.NeedsUpdate();
265 void TestApplication::ResetContext()
267 mCore->ContextDestroyed();
268 mGraphicsController.Initialize();
269 mCore->ContextCreated();
272 uint32_t TestApplication::Wait(uint32_t durationToWait)
276 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
279 Render(RENDER_FRAME_INTERVAL);
280 time += RENDER_FRAME_INTERVAL;