2 * Copyright (c) 2022 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);
67 mCore = Dali::Integration::Core::New(mRenderController,
70 Integration::RenderToFrameBuffer::FALSE,
71 Integration::DepthBufferAvailable::TRUE,
72 Integration::StencilBufferAvailable::TRUE,
73 mPartialUpdateEnabled ? Integration::PartialUpdateAvailable::TRUE : Integration::PartialUpdateAvailable::FALSE);
75 mCore->ContextCreated();
77 Dali::Integration::Trace::LogContext(true, "Test");
80 void TestGraphicsApplication::CreateScene()
82 mScene = Dali::Integration::Scene::New(Size(static_cast<float>(mSurfaceWidth), static_cast<float>(mSurfaceHeight)));
83 mScene.SetDpi(Vector2(static_cast<float>(mDpi.x), static_cast<float>(mDpi.y)));
85 Graphics::RenderTargetCreateInfo createInfo{};
86 createInfo.SetSurface({nullptr})
87 .SetExtent({mSurfaceWidth, mSurfaceHeight})
88 .SetPreTransform(0 | Graphics::RenderTargetTransformFlagBits::TRANSFORM_IDENTITY_BIT);
89 //mRenderTarget = mGraphicsController.CreateRenderTarget(createInfo, nullptr);
90 mScene.SetSurfaceRenderTarget(createInfo);
93 void TestGraphicsApplication::InitializeCore()
95 mCore->SceneCreated();
99 TestGraphicsApplication::~TestGraphicsApplication()
101 Dali::Integration::Log::UninstallLogFunction();
105 void TestGraphicsApplication::LogContext(bool start, const char* tag)
109 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
113 fprintf(stderr, "INFO: Trace End: %s\n", tag);
117 void TestGraphicsApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
123 case Dali::Integration::Log::DEBUG:
124 fprintf(stderr, "DEBUG: %s", message.c_str());
126 case Dali::Integration::Log::INFO:
127 fprintf(stderr, "INFO: %s", message.c_str());
129 case Dali::Integration::Log::WARNING:
130 fprintf(stderr, "WARN: %s", message.c_str());
132 case Dali::Integration::Log::ERROR:
133 fprintf(stderr, "ERROR: %s", message.c_str());
136 fprintf(stderr, "DEFAULT: %s", message.c_str());
142 Dali::Integration::Core& TestGraphicsApplication::GetCore()
147 TestPlatformAbstraction& TestGraphicsApplication::GetPlatform()
149 return mPlatformAbstraction;
152 TestRenderController& TestGraphicsApplication::GetRenderController()
154 return mRenderController;
157 Graphics::Controller& TestGraphicsApplication::GetGraphicsController()
159 return mGraphicsController;
162 TestGlAbstraction& TestGraphicsApplication::GetGlAbstraction()
164 return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
167 TestGlContextHelperAbstraction& TestGraphicsApplication::GetGlContextHelperAbstraction()
169 return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
172 void TestGraphicsApplication::ProcessEvent(const Integration::Event& event)
174 mCore->QueueEvent(event);
175 mCore->ProcessEvents();
178 void TestGraphicsApplication::SendNotification()
180 mCore->ProcessEvents();
183 void TestGraphicsApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location)
185 if(GetUpdateStatus() == 0 &&
186 mRenderStatus.NeedsUpdate() == false &&
187 !GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc))
189 fprintf(stderr, "WARNING - Update not required :%s\n", location == NULL ? "NULL" : location);
192 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
193 float elapsedSeconds = static_cast<float>(intervalMilliseconds) * 0.001f;
195 mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false, false);
197 GetRenderController().Initialize();
199 mLastVSyncTime = nextVSyncTime;
202 bool TestGraphicsApplication::Render(uint32_t intervalMilliseconds, const char* location)
204 DoUpdate(intervalMilliseconds, location);
207 mRenderStatus.SetNeedsUpdate(false);
208 mRenderStatus.SetNeedsPostRender(false);
210 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
211 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
212 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
217 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
220 bool TestGraphicsApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
222 DoUpdate(intervalMilliseconds, location);
224 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
225 mCore->PreRender(mScene, damagedRects);
227 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
230 bool TestGraphicsApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
232 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/, clippingRect);
233 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
238 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
241 uint32_t TestGraphicsApplication::GetUpdateStatus()
243 return mStatus.KeepUpdating();
246 bool TestGraphicsApplication::UpdateOnly(uint32_t intervalMilliseconds)
248 DoUpdate(intervalMilliseconds);
249 return mStatus.KeepUpdating();
252 bool TestGraphicsApplication::GetRenderNeedsUpdate()
254 return mRenderStatus.NeedsUpdate();
257 bool TestGraphicsApplication::GetRenderNeedsPostRender()
259 return mRenderStatus.NeedsPostRender();
262 bool TestGraphicsApplication::RenderOnly()
264 // Update Time values
265 mCore->PreRender(mRenderStatus, false /*do not force clear*/);
266 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
267 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
272 return mRenderStatus.NeedsUpdate();
275 void TestGraphicsApplication::ResetContext()
277 mCore->ContextDestroyed();
278 mGraphicsController.InitializeGLES(mGlAbstraction);
279 mGraphicsController.Initialize(mGraphicsSyncImplementation, mGlContextHelperAbstraction, mGraphics);
280 mCore->ContextCreated();
283 uint32_t TestGraphicsApplication::Wait(uint32_t durationToWait)
287 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
290 Render(RENDER_FRAME_INTERVAL);
291 time += RENDER_FRAME_INTERVAL;