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.
21 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
25 #include <dali/devel-api/adaptor-framework/window-devel.h>
26 #include <dali/public-api/signals/render-callback.h>
30 using namespace Dali::Toolkit;
33 // Positive test case for a method
34 int UtcDaliGlViewDirectRenderingNew(void)
36 ToolkitTestApplication application;
37 tet_infoline(" UtcDaliGlViewDirectRenderingNew");
38 GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGBA8888);
39 DALI_TEST_CHECK(view);
41 auto mode1 = view.GetBackendMode();
43 DALI_TEST_EQUALS(mode1, GlView::BackendMode::DIRECT_RENDERING, TEST_LOCATION);
45 GlView view2 = GlView::New(GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING, GlView::ColorFormat::RGBA8888);
46 DALI_TEST_CHECK(view2);
48 auto mode2 = view2.GetBackendMode();
49 DALI_TEST_EQUALS(mode2, GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING, TEST_LOCATION);
54 int UtcDaliGlViewDirectRenderingNewN(void)
56 ToolkitTestApplication application;
57 tet_infoline(" UtcDaliGlViewDirectRenderingNewN");
58 // Invalid backend mode
59 GlView view = GlView::New(GlView::BackendMode(11111), GlView::ColorFormat::RGBA8888);
60 DALI_TEST_CHECK(!view);
65 // Positive test case for a method
66 int UtcDaliGlViewDirectRenderingDownCast(void)
68 ToolkitTestApplication application;
69 tet_infoline(" UtcDaliGlViewDirectRenderingDownCast");
71 GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
72 BaseHandle handle(view);
74 Toolkit::GlView view2 = Toolkit::GlView::DownCast(handle);
75 DALI_TEST_CHECK(view);
76 DALI_TEST_CHECK(view2);
77 DALI_TEST_CHECK(view == view2);
81 int UtcDaliGlViewDirectRenderingCopyAndAssignment(void)
83 ToolkitTestApplication application;
84 tet_infoline("UtcDaliGlViewDirectRenderingCopyAndAssignment");
86 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
87 DALI_TEST_CHECK(view);
90 DALI_TEST_CHECK(view == copy);
93 DALI_TEST_CHECK(!assign);
96 DALI_TEST_CHECK(assign == view);
101 int UtcDaliGlViewDirectRenderingMoveAssignment(void)
103 ToolkitTestApplication application;
104 tet_infoline("UtcDaliGlViewDirectRenderingMoveAssignment");
106 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
107 DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
110 moved = std::move(view);
111 DALI_TEST_CHECK(moved);
112 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
113 DALI_TEST_CHECK(!view);
118 int UtcDaliGlViewDirectRenderingSetGraphicsConfigGles20N(void)
120 ToolkitTestApplication application;
121 tet_infoline("UtcDaliGlViewDirectRenderingSetGraphicsConfigGles20");
125 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
126 DALI_TEST_CHECK(false);
130 DALI_TEST_CHECK(true);
135 int UtcDaliGlViewDirectRenderingSetGraphicsConfigGles30(void)
137 ToolkitTestApplication application;
138 tet_infoline("UtcDaliGlViewDirectRenderingSetGraphicsConfigGles30");
139 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
143 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
144 DALI_TEST_CHECK(true);
148 DALI_TEST_CHECK(false);
153 int UtcDaliGlViewDirectRenderingRenderingMode(void)
155 ToolkitTestApplication application;
156 tet_infoline("UtcDaliGlViewDirectRenderingRenderingMode");
157 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
159 view.SetRenderingMode(GlView::RenderingMode::ON_DEMAND);
161 GlView::RenderingMode mode = view.GetRenderingMode();
163 DALI_TEST_EQUALS(GlView::RenderingMode::ON_DEMAND, mode, TEST_LOCATION);
168 int UtcDaliGlViewDirectRenderingOnSizeSet(void)
170 ToolkitTestApplication application;
171 tet_infoline("UtcDaliGlViewDirectRenderingOnSizeSet");
172 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
174 application.GetScene().Add(view);
176 application.SendNotification();
177 application.Render();
179 Vector3 size(200.0f, 300.0f, 0.0f);
180 view.SetProperty(Actor::Property::SIZE, size);
182 application.SendNotification();
183 application.Render();
185 DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), size, TEST_LOCATION);
190 namespace DirectRenderingCode
193 // Internal callback function
198 int glRenderFrame(void)
200 static unsigned int retFlag = 0;
204 void glTerminate(void)
209 // Internal callback function
210 void glInitMT(Dali::RenderCallbackInput& input)
214 int gDRFramesRendered = 0;
216 int glRenderFrameMT(Dali::RenderCallbackInput& input)
222 void glTerminateMT(Dali::RenderCallbackInput& input)
226 void resizeCB(Vector2 size)
232 int UtcDaliGlViewDirectRenderingRegisterGlCallbacksN(void)
234 ToolkitTestApplication application;
235 tet_infoline("UtcDaliGlViewDirectRenderingRegisterGlCallbacksN");
240 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
241 DALI_TEST_CHECK(false);
245 DALI_TEST_CHECK(true);
250 int UtcDaliGlViewDirectRenderingSetResizeCallbackN(void)
252 ToolkitTestApplication application;
253 tet_infoline("UtcDaliGlViewDirectRenderingSetResizeCallback");
258 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
259 DALI_TEST_CHECK(false);
263 DALI_TEST_CHECK(true);
268 int UtcDaliGlViewDirectRenderingRenderOnce(void)
270 ToolkitTestApplication application;
271 tet_infoline("UtcDaliGlViewDirectRenderingRenderOnce");
272 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
277 DALI_TEST_CHECK(true);
281 DALI_TEST_CHECK(false);
286 int UtcDaliGlViewDirectRenderingWindowVisibilityChanged(void)
288 ToolkitTestApplication application;
289 tet_infoline("UtcDaliGlViewDirectRenderingWindowVisibilityChanged");
290 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
291 application.GetScene().Add(view);
292 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
293 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
294 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
295 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
297 application.SendNotification();
298 application.Render();
300 Window window = DevelWindow::Get(view);
302 application.SendNotification();
303 application.Render();
305 DALI_TEST_CHECK(true);
309 int UtcDaliGlViewDirectRenderingOnScene(void)
311 ToolkitTestApplication application;
313 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
316 application.GetScene().Add(view);
317 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
318 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
319 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
321 application.SendNotification();
322 application.Render();
325 application.GetScene().Remove(view);
327 application.SendNotification();
328 application.Render();
330 DALI_TEST_CHECK(true);
334 int UtcDaliGlViewDirectRenderingControlVisibilityChanged(void)
336 ToolkitTestApplication application;
338 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
339 application.GetScene().Add(view);
341 application.SendNotification();
342 application.Render();
344 view.SetProperty(Actor::Property::VISIBLE, false);
345 application.SendNotification();
346 application.Render();
347 DALI_TEST_CHECK(view.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == false);
349 view.SetProperty(Actor::Property::VISIBLE, true);
350 application.SendNotification();
351 application.Render();
352 DALI_TEST_CHECK(view.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
357 int UtcDaliGlViewDirectRenderingResize(void)
359 ToolkitTestApplication application;
360 tet_infoline("UtcDaliGlViewDirectRenderingResize");
361 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
363 application.GetScene().Add(view);
364 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
365 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
366 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
367 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
368 view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
370 application.SendNotification();
371 application.Render();
373 //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
374 std::this_thread::sleep_for(std::chrono::milliseconds(100));
376 application.SendNotification();
377 application.Render();
379 DALI_TEST_CHECK(true);
383 int UtcDaliGlViewDirectRenderingTerminateCallback(void)
385 ToolkitTestApplication application;
386 tet_infoline("UtcDaliGlViewDirectRenderingTerminateCallback");
387 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
389 application.GetScene().Add(view);
390 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
391 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
392 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
393 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
394 view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
396 application.SendNotification();
397 application.Render();
401 //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
402 std::this_thread::sleep_for(std::chrono::milliseconds(100));
404 application.SendNotification();
405 application.Render();
407 DALI_TEST_CHECK(true);
411 // Positive test case for a method
412 int UtcDaliGlViewDirectRenderingThreadedNew(void)
414 ToolkitTestApplication application;
415 tet_infoline(" UtcDaliGlViewDirectRenderingThreadedNew");
416 GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGBA8888);
417 DALI_TEST_CHECK(view);
419 auto mode1 = view.GetBackendMode();
421 DALI_TEST_EQUALS(mode1, GlView::BackendMode::DIRECT_RENDERING_THREADED, TEST_LOCATION);
426 int UtcDaliGlViewDirectRenderingThreadedOnScene(void)
428 ToolkitTestApplication application;
430 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
433 application.GetScene().Add(view);
434 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
435 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
436 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
437 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
438 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
440 // Set size on the actor (half the window size to show that glClear() and scissor test work together)
441 view.SetProperty(Actor::Property::SIZE, Size(100, 100));
442 view.SetProperty(Actor::Property::POSITION, Vector2(0,0));
444 while( DirectRenderingCode::gDRFramesRendered < 1 )
446 application.SendNotification();
447 application.Render();
449 DALI_TEST_CHECK(true);
453 extern "C" bool gDirectRenderingFailCreateShader;
454 extern "C" bool gDirectRenderingFailCreateProgram;
457 int UtcDaliGlViewDirectRenderingThreadedOnScene1(void)
459 ToolkitTestApplication application;
461 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
463 // This test will fail instantiating shaders
464 gDirectRenderingFailCreateShader = true;
467 application.GetScene().Add(view);
468 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
469 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
470 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
471 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
472 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
474 // Set size on the actor (half the window size to show that glClear() and scissor test work together)
475 view.SetProperty(Actor::Property::SIZE, Size(100, 100));
476 view.SetProperty(Actor::Property::POSITION, Vector2(0,0));
478 while( DirectRenderingCode::gDRFramesRendered < 1 )
480 application.SendNotification();
481 application.Render();
483 DALI_TEST_CHECK(true);
487 int UtcDaliGlViewDirectRenderingThreadedOnScene2(void)
489 ToolkitTestApplication application;
491 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
493 // This test will fail instantiating shaders
494 gDirectRenderingFailCreateProgram = true;
497 application.GetScene().Add(view);
498 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
499 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
500 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
501 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
502 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
504 // Set size on the actor (half the window size to show that glClear() and scissor test work together)
505 view.SetProperty(Actor::Property::SIZE, Size(100, 100));
506 view.SetProperty(Actor::Property::POSITION, Vector2(0,0));
508 while( DirectRenderingCode::gDRFramesRendered < 1 )
510 application.SendNotification();
511 application.Render();
513 DALI_TEST_CHECK(true);