2 * Copyright (c) 2024 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-graphics-application.h"
19 #include <test-graphics-sync-impl.h>
23 bool TestGraphicsApplication::mLoggingEnabled = true;
25 TestGraphicsApplication::TestGraphicsApplication(uint32_t surfaceWidth,
26 uint32_t surfaceHeight,
27 uint32_t horizontalDpi,
30 bool enablePartialUpdate)
32 mSurfaceWidth(surfaceWidth),
33 mSurfaceHeight(surfaceHeight),
35 mDpi{horizontalDpi, verticalDpi},
37 mPartialUpdateEnabled(enablePartialUpdate)
45 void TestGraphicsApplication::Initialize()
52 void TestGraphicsApplication::CreateCore()
54 Dali::Integration::Log::LogFunction logFunction(&TestGraphicsApplication::LogMessage);
55 Dali::Integration::Log::InstallLogFunction(logFunction);
57 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestGraphicsApplication::LogContext);
58 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
60 // We always need the first update!
61 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
63 mGraphics.Initialize();
64 mGraphicsController.InitializeGLES(mGlAbstraction);
65 mGraphicsController.Initialize(mGraphicsSyncImplementation, mGlContextHelperAbstraction, mGraphics);
66 mGraphicsController.ActivateResourceContext();
68 mCore = Dali::Integration::Core::New(mRenderController,
71 Integration::RenderToFrameBuffer::FALSE,
72 Integration::DepthBufferAvailable::TRUE,
73 Integration::StencilBufferAvailable::TRUE,
74 mPartialUpdateEnabled ? Integration::PartialUpdateAvailable::TRUE : Integration::PartialUpdateAvailable::FALSE);
76 mCore->ContextCreated();
78 Dali::Integration::Trace::LogContext(true, "Test");
81 void TestGraphicsApplication::CreateScene()
83 mScene = Dali::Integration::Scene::New(Size(static_cast<float>(mSurfaceWidth), static_cast<float>(mSurfaceHeight)));
84 mScene.SetDpi(Vector2(static_cast<float>(mDpi.x), static_cast<float>(mDpi.y)));
86 Graphics::RenderTargetCreateInfo createInfo{};
87 createInfo.SetSurface({nullptr})
88 .SetExtent({mSurfaceWidth, mSurfaceHeight})
89 .SetPreTransform(0 | Graphics::RenderTargetTransformFlagBits::TRANSFORM_IDENTITY_BIT);
90 //mRenderTarget = mGraphicsController.CreateRenderTarget(createInfo, nullptr);
91 mScene.SetSurfaceRenderTarget(createInfo);
94 void TestGraphicsApplication::InitializeCore()
96 mCore->SceneCreated();
100 TestGraphicsApplication::~TestGraphicsApplication()
102 mGraphicsController.Shutdown();
103 Dali::Integration::Log::UninstallLogFunction();
107 void TestGraphicsApplication::LogContext(bool start, const char* tag, const char* message)
111 fprintf(stderr, "INFO: Trace Start: %s %s\n", tag, message ? message : "");
115 fprintf(stderr, "INFO: Trace End: %s %s\n", tag, message ? message : "");
119 void TestGraphicsApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
125 case Dali::Integration::Log::DEBUG:
126 fprintf(stderr, "DEBUG: %s", message.c_str());
128 case Dali::Integration::Log::INFO:
129 fprintf(stderr, "INFO: %s", message.c_str());
131 case Dali::Integration::Log::WARNING:
132 fprintf(stderr, "WARN: %s", message.c_str());
134 case Dali::Integration::Log::ERROR:
135 fprintf(stderr, "ERROR: %s", message.c_str());
138 fprintf(stderr, "DEFAULT: %s", message.c_str());
144 Dali::Integration::Core& TestGraphicsApplication::GetCore()
149 TestPlatformAbstraction& TestGraphicsApplication::GetPlatform()
151 return mPlatformAbstraction;
154 TestRenderController& TestGraphicsApplication::GetRenderController()
156 return mRenderController;
159 Graphics::Controller& TestGraphicsApplication::GetGraphicsController()
161 return mGraphicsController;
164 TestGlAbstraction& TestGraphicsApplication::GetGlAbstraction()
166 return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
169 TestGlContextHelperAbstraction& TestGraphicsApplication::GetGlContextHelperAbstraction()
171 return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
174 void TestGraphicsApplication::ProcessEvent(const Integration::Event& event)
176 mCore->QueueEvent(event);
177 mCore->ProcessEvents();
180 void TestGraphicsApplication::SendNotification()
182 mCore->ProcessEvents();
185 void TestGraphicsApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location)
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, false);
199 GetRenderController().Initialize();
201 mLastVSyncTime = nextVSyncTime;
204 bool TestGraphicsApplication::Render(uint32_t intervalMilliseconds, const char* location)
206 DoUpdate(intervalMilliseconds, location);
209 mRenderStatus.SetNeedsUpdate(false);
210 mRenderStatus.SetNeedsPostRender(false);
212 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
213 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
214 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
219 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
222 bool TestGraphicsApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
224 DoUpdate(intervalMilliseconds, location);
226 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
227 mCore->PreRender(mScene, damagedRects);
229 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
232 bool TestGraphicsApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
234 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/, clippingRect);
235 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
240 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
243 uint32_t TestGraphicsApplication::GetUpdateStatus()
245 return mStatus.KeepUpdating();
248 bool TestGraphicsApplication::UpdateOnly(uint32_t intervalMilliseconds)
250 DoUpdate(intervalMilliseconds);
251 return mStatus.KeepUpdating();
254 bool TestGraphicsApplication::GetRenderNeedsUpdate()
256 return mRenderStatus.NeedsUpdate();
259 bool TestGraphicsApplication::GetRenderNeedsPostRender()
261 return mRenderStatus.NeedsPostRender();
264 bool TestGraphicsApplication::RenderOnly()
266 // Update Time values
267 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
268 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
269 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
274 return mRenderStatus.NeedsUpdate();
277 void TestGraphicsApplication::ResetContext()
279 mCore->ContextDestroyed();
280 mGraphicsController.InitializeGLES(mGlAbstraction);
281 mGraphicsController.Initialize(mGraphicsSyncImplementation, mGlContextHelperAbstraction, mGraphics);
282 mCore->ContextCreated();
285 uint32_t TestGraphicsApplication::Wait(uint32_t durationToWait)
289 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
292 Render(RENDER_FRAME_INTERVAL);
293 time += RENDER_FRAME_INTERVAL;