2 * Copyright (c) 2023 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 const Rect<int> TestApplication::DEFAULT_SURFACE_RECT = Rect<int>(0, 0, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
24 bool TestApplication::mLoggingEnabled = true;
26 TestApplication::TestApplication(uint32_t surfaceWidth,
27 uint32_t surfaceHeight,
28 uint32_t horizontalDpi,
31 bool enablePartialUpdate)
33 mSurfaceWidth(surfaceWidth),
34 mSurfaceHeight(surfaceHeight),
36 mDpi{horizontalDpi, verticalDpi},
38 mPartialUpdateEnabled(enablePartialUpdate)
46 void TestApplication::Initialize()
53 void TestApplication::CreateCore()
55 // We always need the first update!
56 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
58 mCore = Dali::Integration::Core::New(mRenderController,
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)));
82 // Create render target for the scene
83 Graphics::RenderTargetCreateInfo rtInfo{};
84 rtInfo.SetExtent({mSurfaceWidth, mSurfaceHeight});
85 rtInfo.SetSurface(&mSurfaceWidth); // Can point to anything, really.
87 mScene.SetSurfaceRenderTarget(rtInfo);
89 mScenes.push_back(mScene);
92 void TestApplication::InitializeCore()
94 mCore->SceneCreated();
98 TestApplication::~TestApplication()
100 Dali::Integration::Log::UninstallLogFunction();
104 void TestApplication::LogContext(bool start, const char* tag, const char* message)
108 fprintf(stderr, "INFO: Trace Start: %s %s\n", tag, message ? message : "");
112 fprintf(stderr, "INFO: Trace End: %s %s\n", tag, message ? message : "");
116 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
122 case Dali::Integration::Log::DEBUG:
123 fprintf(stderr, "DEBUG: %s", message.c_str());
125 case Dali::Integration::Log::INFO:
126 fprintf(stderr, "INFO: %s", message.c_str());
128 case Dali::Integration::Log::WARNING:
129 fprintf(stderr, "WARN: %s", message.c_str());
131 case Dali::Integration::Log::ERROR:
132 fprintf(stderr, "ERROR: %s", message.c_str());
135 fprintf(stderr, "DEFAULT: %s", message.c_str());
141 Dali::Integration::Core& TestApplication::GetCore()
146 TestPlatformAbstraction& TestApplication::GetPlatform()
148 return mPlatformAbstraction;
151 TestRenderController& TestApplication::GetRenderController()
153 return mRenderController;
156 TestGraphicsController& TestApplication::GetGraphicsController()
158 return mGraphicsController;
161 TestGlAbstraction& TestApplication::GetGlAbstraction()
163 return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
166 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
168 return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
171 TestGraphicsSyncImplementation& TestApplication::GetGraphicsSyncImpl()
173 return static_cast<TestGraphicsSyncImplementation&>(mGraphicsController.GetGraphicsSyncImpl());
176 void TestApplication::ProcessEvent(const Integration::Event& event)
178 mCore->QueueEvent(event);
179 mCore->ProcessEvents();
182 void TestApplication::SendNotification()
184 mCore->ProcessEvents();
187 void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location, bool uploadOnly)
189 if(GetUpdateStatus() == 0 &&
190 mRenderStatus.NeedsUpdate() == false &&
191 !GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc))
193 fprintf(stderr, "WARNING - Update not required :%s\n", location == NULL ? "NULL" : location);
196 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
197 float elapsedSeconds = static_cast<float>(intervalMilliseconds) * 0.001f;
199 mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false, uploadOnly);
201 GetRenderController().Initialize();
203 mLastVSyncTime = nextVSyncTime;
206 bool TestApplication::Render(uint32_t intervalMilliseconds, const char* location, bool uploadOnly)
208 DoUpdate(intervalMilliseconds, location, uploadOnly);
211 mRenderStatus.SetNeedsUpdate(false);
212 mRenderStatus.SetNeedsPostRender(false);
214 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
217 for(auto&& scene : mScenes)
219 mCore->RenderScene(mRenderStatus, scene, true /*render the off-screen buffers*/);
220 mCore->RenderScene(mRenderStatus, scene, false /*render the surface*/);
227 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
230 bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
232 DoUpdate(intervalMilliseconds, location);
234 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
235 mCore->PreRender(mScene, damagedRects);
237 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
240 bool TestApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
242 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
243 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
248 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
251 bool TestApplication::RenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location)
253 DoUpdate(intervalMilliseconds, location);
256 mRenderStatus.SetNeedsUpdate(false);
257 mRenderStatus.SetNeedsPostRender(false);
259 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
261 for(auto&& scene : mScenes)
263 std::vector<Rect<int>> damagedRects;
264 Rect<int> clippingRect{};
266 mCore->PreRender(scene, damagedRects);
267 mCore->RenderScene(mRenderStatus, scene, true /*render the off-screen buffers*/);
268 for(auto&& iter : damagedRects)
270 clippingRect.Merge(iter);
272 mCore->RenderScene(mRenderStatus, scene, false /*render the surface*/, clippingRect);
278 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
281 uint32_t TestApplication::GetUpdateStatus()
283 return mStatus.KeepUpdating();
286 bool TestApplication::UpdateOnly(uint32_t intervalMilliseconds)
288 DoUpdate(intervalMilliseconds);
289 return mStatus.KeepUpdating();
292 bool TestApplication::GetRenderNeedsUpdate()
294 return mRenderStatus.NeedsUpdate();
297 bool TestApplication::GetRenderNeedsPostRender()
299 return mRenderStatus.NeedsPostRender();
302 bool TestApplication::RenderOnly()
304 // Update Time values
305 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
306 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
307 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
312 return mRenderStatus.NeedsUpdate();
315 void TestApplication::ResetContext()
317 mCore->ContextDestroyed();
318 mGraphicsController.Initialize();
319 mCore->ContextCreated();
322 uint32_t TestApplication::Wait(uint32_t durationToWait)
326 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
329 Render(RENDER_FRAME_INTERVAL);
330 time += RENDER_FRAME_INTERVAL;
335 void TestApplication::AddScene(Integration::Scene scene)
337 mScenes.push_back(scene);
340 void TestApplication::RemoveScene(Integration::Scene scene)
342 mScenes.erase(std::remove(mScenes.begin(), mScenes.end(), scene), mScenes.end());