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)));
80 // Create render target for the scene
81 Graphics::RenderTargetCreateInfo rtInfo{};
82 rtInfo.SetExtent({mSurfaceWidth, mSurfaceHeight});
83 mRenderTarget = mGraphicsController.CreateRenderTarget(rtInfo, nullptr);
84 mScene.SetSurfaceRenderTarget(mRenderTarget.get());
87 void TestApplication::InitializeCore()
89 mCore->SceneCreated();
93 TestApplication::~TestApplication()
95 Dali::Integration::Log::UninstallLogFunction();
99 void TestApplication::LogContext(bool start, const char* tag)
103 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
107 fprintf(stderr, "INFO: Trace End: %s\n", tag);
111 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
117 case Dali::Integration::Log::DebugInfo:
118 fprintf(stderr, "INFO: %s", message.c_str());
120 case Dali::Integration::Log::DebugWarning:
121 fprintf(stderr, "WARN: %s", message.c_str());
123 case Dali::Integration::Log::DebugError:
124 fprintf(stderr, "ERROR: %s", message.c_str());
127 fprintf(stderr, "DEFAULT: %s", message.c_str());
133 Dali::Integration::Core& TestApplication::GetCore()
138 TestPlatformAbstraction& TestApplication::GetPlatform()
140 return mPlatformAbstraction;
143 TestRenderController& TestApplication::GetRenderController()
145 return mRenderController;
148 TestGraphicsController& TestApplication::GetGraphicsController()
150 return mGraphicsController;
153 TestGlAbstraction& TestApplication::GetGlAbstraction()
155 return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
158 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
160 return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
163 TestGraphicsSyncImplementation& TestApplication::GetGraphicsSyncImpl()
165 return static_cast<TestGraphicsSyncImplementation&>(mGraphicsController.GetGraphicsSyncImpl());
168 void TestApplication::ProcessEvent(const Integration::Event& event)
170 mCore->QueueEvent(event);
171 mCore->ProcessEvents();
174 void TestApplication::SendNotification()
176 mCore->ProcessEvents();
179 void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location)
181 if(GetUpdateStatus() == 0 &&
182 mRenderStatus.NeedsUpdate() == false &&
183 !GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc))
185 fprintf(stderr, "WARNING - Update not required :%s\n", location == NULL ? "NULL" : location);
188 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
189 float elapsedSeconds = static_cast<float>(intervalMilliseconds) * 0.001f;
191 mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false);
193 GetRenderController().Initialize();
195 mLastVSyncTime = nextVSyncTime;
198 bool TestApplication::Render(uint32_t intervalMilliseconds, const char* location)
200 DoUpdate(intervalMilliseconds, location);
203 mRenderStatus.SetNeedsUpdate(false);
204 mRenderStatus.SetNeedsPostRender(false);
206 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
207 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
208 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
209 mCore->PostRender(false /*do not skip rendering*/);
213 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
216 bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
218 DoUpdate(intervalMilliseconds, location);
220 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
221 mCore->PreRender(mScene, damagedRects);
223 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
226 bool TestApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
228 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/, clippingRect);
229 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
230 mCore->PostRender(false /*do not skip rendering*/);
234 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
237 uint32_t TestApplication::GetUpdateStatus()
239 return mStatus.KeepUpdating();
242 bool TestApplication::UpdateOnly(uint32_t intervalMilliseconds)
244 DoUpdate(intervalMilliseconds);
245 return mStatus.KeepUpdating();
248 bool TestApplication::GetRenderNeedsUpdate()
250 return mRenderStatus.NeedsUpdate();
253 bool TestApplication::GetRenderNeedsPostRender()
255 return mRenderStatus.NeedsPostRender();
258 bool TestApplication::RenderOnly()
260 // Update Time values
261 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
262 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
263 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
264 mCore->PostRender(false /*do not skip rendering*/);
268 return mRenderStatus.NeedsUpdate();
271 void TestApplication::ResetContext()
273 mCore->ContextDestroyed();
274 mGraphicsController.Initialize();
275 mCore->ContextCreated();
278 uint32_t TestApplication::Wait(uint32_t durationToWait)
282 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
285 Render(RENDER_FRAME_INTERVAL);
286 time += RENDER_FRAME_INTERVAL;