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);
90 void TestApplication::InitializeCore()
92 mCore->SceneCreated();
96 TestApplication::~TestApplication()
98 Dali::Integration::Log::UninstallLogFunction();
102 void TestApplication::LogContext(bool start, const char* tag, const char* message)
106 fprintf(stderr, "INFO: Trace Start: %s %s\n", tag, message ? message : "");
110 fprintf(stderr, "INFO: Trace End: %s %s\n", tag, message ? message : "");
114 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
120 case Dali::Integration::Log::DEBUG:
121 fprintf(stderr, "DEBUG: %s", message.c_str());
123 case Dali::Integration::Log::INFO:
124 fprintf(stderr, "INFO: %s", message.c_str());
126 case Dali::Integration::Log::WARNING:
127 fprintf(stderr, "WARN: %s", message.c_str());
129 case Dali::Integration::Log::ERROR:
130 fprintf(stderr, "ERROR: %s", message.c_str());
133 fprintf(stderr, "DEFAULT: %s", message.c_str());
139 Dali::Integration::Core& TestApplication::GetCore()
144 TestPlatformAbstraction& TestApplication::GetPlatform()
146 return mPlatformAbstraction;
149 TestRenderController& TestApplication::GetRenderController()
151 return mRenderController;
154 TestGraphicsController& TestApplication::GetGraphicsController()
156 return mGraphicsController;
159 TestGlAbstraction& TestApplication::GetGlAbstraction()
161 return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
164 TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
166 return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
169 TestGraphicsSyncImplementation& TestApplication::GetGraphicsSyncImpl()
171 return static_cast<TestGraphicsSyncImplementation&>(mGraphicsController.GetGraphicsSyncImpl());
174 void TestApplication::ProcessEvent(const Integration::Event& event)
176 mCore->QueueEvent(event);
177 mCore->ProcessEvents();
180 void TestApplication::SendNotification()
182 mCore->ProcessEvents();
185 void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location, bool uploadOnly)
187 if(GetUpdateStatus() == 0 &&
188 mRenderStatus.NeedsUpdate() == false &&
189 !GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc))
191 fprintf(stderr, "WARNING - Update not required :%s\n", location == NULL ? "NULL" : location);
194 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
195 float elapsedSeconds = static_cast<float>(intervalMilliseconds) * 0.001f;
197 mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false, uploadOnly);
199 GetRenderController().Initialize();
201 mLastVSyncTime = nextVSyncTime;
204 bool TestApplication::Render(uint32_t intervalMilliseconds, const char* location, bool uploadOnly)
206 DoUpdate(intervalMilliseconds, location, uploadOnly);
209 mRenderStatus.SetNeedsUpdate(false);
210 mRenderStatus.SetNeedsPostRender(false);
212 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
215 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
216 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
222 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
225 bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
227 DoUpdate(intervalMilliseconds, location);
229 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
230 mCore->PreRender(mScene, damagedRects);
232 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
235 bool TestApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
237 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
238 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
243 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
246 uint32_t TestApplication::GetUpdateStatus()
248 return mStatus.KeepUpdating();
251 bool TestApplication::UpdateOnly(uint32_t intervalMilliseconds)
253 DoUpdate(intervalMilliseconds);
254 return mStatus.KeepUpdating();
257 bool TestApplication::GetRenderNeedsUpdate()
259 return mRenderStatus.NeedsUpdate();
262 bool TestApplication::GetRenderNeedsPostRender()
264 return mRenderStatus.NeedsPostRender();
267 bool TestApplication::RenderOnly()
269 // Update Time values
270 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
271 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
272 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
277 return mRenderStatus.NeedsUpdate();
280 void TestApplication::ResetContext()
282 mCore->ContextDestroyed();
283 mGraphicsController.Initialize();
284 mCore->ContextCreated();
287 uint32_t TestApplication::Wait(uint32_t durationToWait)
291 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
294 Render(RENDER_FRAME_INTERVAL);
295 time += RENDER_FRAME_INTERVAL;