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-graphics-application.h"
22 bool TestGraphicsApplication::mLoggingEnabled = true;
24 TestGraphicsApplication::TestGraphicsApplication(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 TestGraphicsApplication::Initialize()
51 void TestGraphicsApplication::CreateCore()
53 // We always need the first update!
54 mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
56 mGraphicsController.InitializeGLES(mGlAbstraction);
57 mGraphicsController.Initialize(mGlSyncAbstraction, mGlContextHelperAbstraction);
59 mCore = Dali::Integration::Core::New(mRenderController,
62 Integration::RenderToFrameBuffer::FALSE,
63 Integration::DepthBufferAvailable::TRUE,
64 Integration::StencilBufferAvailable::TRUE,
65 mPartialUpdateEnabled ? Integration::PartialUpdateAvailable::TRUE : Integration::PartialUpdateAvailable::FALSE);
67 mCore->ContextCreated();
69 Dali::Integration::Log::LogFunction logFunction(&TestGraphicsApplication::LogMessage);
70 Dali::Integration::Log::InstallLogFunction(logFunction);
72 Dali::Integration::Trace::LogContextFunction logContextFunction(&TestGraphicsApplication::LogContext);
73 Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
75 Dali::Integration::Trace::LogContext(true, "Test");
78 void TestGraphicsApplication::CreateScene()
80 mScene = Dali::Integration::Scene::New(Size(static_cast<float>(mSurfaceWidth), static_cast<float>(mSurfaceHeight)));
81 mScene.SetDpi(Vector2(static_cast<float>(mDpi.x), static_cast<float>(mDpi.y)));
84 void TestGraphicsApplication::InitializeCore()
86 mCore->SceneCreated();
90 TestGraphicsApplication::~TestGraphicsApplication()
92 Dali::Integration::Log::UninstallLogFunction();
96 void TestGraphicsApplication::LogContext(bool start, const char* tag)
100 fprintf(stderr, "INFO: Trace Start: %s\n", tag);
104 fprintf(stderr, "INFO: Trace End: %s\n", tag);
108 void TestGraphicsApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
114 case Dali::Integration::Log::DebugInfo:
115 fprintf(stderr, "INFO: %s", message.c_str());
117 case Dali::Integration::Log::DebugWarning:
118 fprintf(stderr, "WARN: %s", message.c_str());
120 case Dali::Integration::Log::DebugError:
121 fprintf(stderr, "ERROR: %s", message.c_str());
124 fprintf(stderr, "DEFAULT: %s", message.c_str());
130 Dali::Integration::Core& TestGraphicsApplication::GetCore()
135 TestPlatformAbstraction& TestGraphicsApplication::GetPlatform()
137 return mPlatformAbstraction;
140 TestRenderController& TestGraphicsApplication::GetRenderController()
142 return mRenderController;
145 Graphics::Controller& TestGraphicsApplication::GetGraphicsController()
147 return mGraphicsController;
150 TestGlAbstraction& TestGraphicsApplication::GetGlAbstraction()
152 return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
155 TestGlSyncAbstraction& TestGraphicsApplication::GetGlSyncAbstraction()
157 return static_cast<TestGlSyncAbstraction&>(mGraphicsController.GetGlSyncAbstraction());
160 TestGlContextHelperAbstraction& TestGraphicsApplication::GetGlContextHelperAbstraction()
162 return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
165 void TestGraphicsApplication::ProcessEvent(const Integration::Event& event)
167 mCore->QueueEvent(event);
168 mCore->ProcessEvents();
171 void TestGraphicsApplication::SendNotification()
173 mCore->ProcessEvents();
176 void TestGraphicsApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location)
178 if(GetUpdateStatus() == 0 &&
179 mRenderStatus.NeedsUpdate() == false &&
180 !GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc))
182 fprintf(stderr, "WARNING - Update not required :%s\n", location == NULL ? "NULL" : location);
185 uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
186 float elapsedSeconds = static_cast<float>(intervalMilliseconds) * 0.001f;
188 mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false);
190 GetRenderController().Initialize();
192 mLastVSyncTime = nextVSyncTime;
195 bool TestGraphicsApplication::Render(uint32_t intervalMilliseconds, const char* location)
197 DoUpdate(intervalMilliseconds, location);
200 mRenderStatus.SetNeedsUpdate(false);
201 mRenderStatus.SetNeedsPostRender(false);
203 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
204 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
205 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
206 mCore->PostRender(false /*do not skip rendering*/);
210 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
213 bool TestGraphicsApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
215 DoUpdate(intervalMilliseconds, location);
217 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
218 mCore->PreRender(mScene, damagedRects);
220 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
223 bool TestGraphicsApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
225 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/, clippingRect);
226 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
227 mCore->PostRender(false /*do not skip rendering*/);
231 return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
234 uint32_t TestGraphicsApplication::GetUpdateStatus()
236 return mStatus.KeepUpdating();
239 bool TestGraphicsApplication::UpdateOnly(uint32_t intervalMilliseconds)
241 DoUpdate(intervalMilliseconds);
242 return mStatus.KeepUpdating();
245 bool TestGraphicsApplication::GetRenderNeedsUpdate()
247 return mRenderStatus.NeedsUpdate();
250 bool TestGraphicsApplication::GetRenderNeedsPostRender()
252 return mRenderStatus.NeedsPostRender();
255 bool TestGraphicsApplication::RenderOnly()
257 // Update Time values
258 mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
259 mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
260 mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
261 mCore->PostRender(false /*do not skip rendering*/);
265 return mRenderStatus.NeedsUpdate();
268 void TestGraphicsApplication::ResetContext()
270 mCore->ContextDestroyed();
271 mGraphicsController.InitializeGLES(mGlAbstraction);
272 mGraphicsController.Initialize(mGlSyncAbstraction, mGlContextHelperAbstraction);
273 mCore->ContextCreated();
276 uint32_t TestGraphicsApplication::Wait(uint32_t durationToWait)
280 for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
283 Render(RENDER_FRAME_INTERVAL);
284 time += RENDER_FRAME_INTERVAL;