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>
29 using namespace Dali::Toolkit;
31 // Positive test case for a method
32 int UtcDaliGlViewDirectRenderingNew(void)
34 ToolkitTestApplication application;
35 tet_infoline(" UtcDaliGlViewDirectRenderingNew");
36 GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGBA8888);
37 DALI_TEST_CHECK(view);
39 auto mode1 = view.GetBackendMode();
41 DALI_TEST_EQUALS(mode1, GlView::BackendMode::DIRECT_RENDERING, TEST_LOCATION);
43 GlView view2 = GlView::New(GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING, GlView::ColorFormat::RGBA8888);
44 DALI_TEST_CHECK(view2);
46 auto mode2 = view2.GetBackendMode();
47 DALI_TEST_EQUALS(mode2, GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING, TEST_LOCATION);
52 int UtcDaliGlViewDirectRenderingNewN(void)
54 ToolkitTestApplication application;
55 tet_infoline(" UtcDaliGlViewDirectRenderingNewN");
56 // Invalid backend mode
57 GlView view = GlView::New(GlView::BackendMode(11111), GlView::ColorFormat::RGBA8888);
58 DALI_TEST_CHECK(!view);
63 // Positive test case for a method
64 int UtcDaliGlViewDirectRenderingDownCast(void)
66 ToolkitTestApplication application;
67 tet_infoline(" UtcDaliGlViewDirectRenderingDownCast");
69 GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
70 BaseHandle handle(view);
72 Toolkit::GlView view2 = Toolkit::GlView::DownCast(handle);
73 DALI_TEST_CHECK(view);
74 DALI_TEST_CHECK(view2);
75 DALI_TEST_CHECK(view == view2);
79 int UtcDaliGlViewDirectRenderingCopyAndAssignment(void)
81 ToolkitTestApplication application;
82 tet_infoline("UtcDaliGlViewDirectRenderingCopyAndAssignment");
84 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
85 DALI_TEST_CHECK(view);
88 DALI_TEST_CHECK(view == copy);
91 DALI_TEST_CHECK(!assign);
94 DALI_TEST_CHECK(assign == view);
99 int UtcDaliGlViewDirectRenderingMoveAssignment(void)
101 ToolkitTestApplication application;
102 tet_infoline("UtcDaliGlViewDirectRenderingMoveAssignment");
104 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
105 DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
108 moved = std::move(view);
109 DALI_TEST_CHECK(moved);
110 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
111 DALI_TEST_CHECK(!view);
116 int UtcDaliGlViewDirectRenderingSetGraphicsConfigGles20N(void)
118 ToolkitTestApplication application;
119 tet_infoline("UtcDaliGlViewDirectRenderingSetGraphicsConfigGles20");
123 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
124 DALI_TEST_CHECK(false);
128 DALI_TEST_CHECK(true);
133 int UtcDaliGlViewDirectRenderingSetGraphicsConfigGles30(void)
135 ToolkitTestApplication application;
136 tet_infoline("UtcDaliGlViewDirectRenderingSetGraphicsConfigGles30");
137 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
141 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
142 DALI_TEST_CHECK(true);
146 DALI_TEST_CHECK(false);
151 int UtcDaliGlViewDirectRenderingRenderingMode(void)
153 ToolkitTestApplication application;
154 tet_infoline("UtcDaliGlViewDirectRenderingRenderingMode");
155 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
157 view.SetRenderingMode(GlView::RenderingMode::ON_DEMAND);
159 GlView::RenderingMode mode = view.GetRenderingMode();
161 DALI_TEST_EQUALS(GlView::RenderingMode::ON_DEMAND, mode, TEST_LOCATION);
166 int UtcDaliGlViewDirectRenderingOnSizeSet(void)
168 ToolkitTestApplication application;
169 tet_infoline("UtcDaliGlViewDirectRenderingOnSizeSet");
170 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
172 application.GetScene().Add(view);
174 application.SendNotification();
175 application.Render();
177 Vector3 size(200.0f, 300.0f, 0.0f);
178 view.SetProperty(Actor::Property::SIZE, size);
180 application.SendNotification();
181 application.Render();
183 DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), size, TEST_LOCATION);
188 namespace DirectRenderingCode
190 // Internal callback function
191 void glInit(Dali::RenderCallbackInput& input)
195 int glRenderFrame(Dali::RenderCallbackInput& input)
197 static unsigned int retFlag = 0;
201 int gBoundTextureCount = 0;
203 int glRenderFrameWithTextures(Dali::RenderCallbackInput& input)
205 gBoundTextureCount = input.textureBindings.size();
209 void glTerminate(Dali::RenderCallbackInput& input)
213 // Internal callback function
214 void glInitMT(Dali::RenderCallbackInput& input)
218 int gDRFramesRendered = 0;
220 int glRenderFrameMT(Dali::RenderCallbackInput& input)
226 void glTerminateMT(Dali::RenderCallbackInput& input)
230 void resizeCB(Vector2 size)
234 } // namespace DirectRenderingCode
236 int UtcDaliGlViewDirectRenderingRegisterGlCallbacksN(void)
238 ToolkitTestApplication application;
239 tet_infoline("UtcDaliGlViewDirectRenderingRegisterGlCallbacksN");
244 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
245 DALI_TEST_CHECK(false);
249 DALI_TEST_CHECK(true);
254 int UtcDaliGlViewDirectRenderingSetResizeCallbackN(void)
256 ToolkitTestApplication application;
257 tet_infoline("UtcDaliGlViewDirectRenderingSetResizeCallback");
262 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
263 DALI_TEST_CHECK(false);
267 DALI_TEST_CHECK(true);
272 int UtcDaliGlViewDirectRenderingRenderOnce(void)
274 ToolkitTestApplication application;
275 tet_infoline("UtcDaliGlViewDirectRenderingRenderOnce");
276 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
281 DALI_TEST_CHECK(true);
285 DALI_TEST_CHECK(false);
290 int UtcDaliGlViewDirectRenderingWindowVisibilityChanged(void)
292 ToolkitTestApplication application;
293 tet_infoline("UtcDaliGlViewDirectRenderingWindowVisibilityChanged");
294 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
295 application.GetScene().Add(view);
296 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
297 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
298 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
299 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
301 application.SendNotification();
302 application.Render();
304 Window window = DevelWindow::Get(view);
306 application.SendNotification();
307 application.Render();
309 DALI_TEST_CHECK(true);
313 int UtcDaliGlViewDirectRenderingOnScene(void)
315 ToolkitTestApplication application;
317 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
320 application.GetScene().Add(view);
321 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
322 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
323 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
325 application.SendNotification();
326 application.Render();
329 application.GetScene().Remove(view);
331 application.SendNotification();
332 application.Render();
334 DALI_TEST_CHECK(true);
338 int UtcDaliGlViewDirectRenderingControlVisibilityChanged(void)
340 ToolkitTestApplication application;
342 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
343 application.GetScene().Add(view);
345 application.SendNotification();
346 application.Render();
348 view.SetProperty(Actor::Property::VISIBLE, false);
349 application.SendNotification();
350 application.Render();
351 DALI_TEST_CHECK(view.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == false);
353 view.SetProperty(Actor::Property::VISIBLE, true);
354 application.SendNotification();
355 application.Render();
356 DALI_TEST_CHECK(view.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
361 int UtcDaliGlViewDirectRenderingResize(void)
363 ToolkitTestApplication application;
364 tet_infoline("UtcDaliGlViewDirectRenderingResize");
365 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
367 application.GetScene().Add(view);
368 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
369 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
370 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
371 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
372 view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
374 application.SendNotification();
375 application.Render();
377 //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
378 std::this_thread::sleep_for(std::chrono::milliseconds(100));
380 application.SendNotification();
381 application.Render();
383 DALI_TEST_CHECK(true);
387 int UtcDaliGlViewDirectRenderingTerminateCallback(void)
389 ToolkitTestApplication application;
390 tet_infoline("UtcDaliGlViewDirectRenderingTerminateCallback");
391 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
393 application.GetScene().Add(view);
394 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
395 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
396 view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
397 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
398 view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
400 application.SendNotification();
401 application.Render();
403 //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
404 std::this_thread::sleep_for(std::chrono::milliseconds(100));
406 application.SendNotification();
407 application.Render();
409 DALI_TEST_CHECK(true);
413 int UtcDaliGlViewDirectRenderingTextureBinding(void)
415 ToolkitTestApplication application;
417 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
419 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
420 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
421 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrameWithTextures), Dali::MakeCallback(DirectRenderingCode::glTerminate));
422 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
423 view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
425 // Set size on the actor (half the window size to show that glClear() and scissor test work together)
426 view.SetProperty(Actor::Property::SIZE, Size(100, 100));
427 view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
429 application.GetScene().Add(view);
432 Texture texture1 = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, 512, 512);
433 auto* data1 = reinterpret_cast<uint8_t*>(malloc(512 * 512 * 4));
434 PixelData pixelData1 = PixelData::New(data1, 512 * 512 * 4, 512, 512, Pixel::Format::RGBA8888, PixelData::ReleaseFunction::FREE);
435 texture1.Upload(pixelData1);
438 Texture texture2 = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, 512, 512);
439 auto* data2 = reinterpret_cast<uint8_t*>(malloc(512 * 512 * 4));
440 PixelData pixelData2 = PixelData::New(data2, 512 * 512 * 4, 512, 512, Pixel::Format::RGBA8888, PixelData::ReleaseFunction::FREE);
441 texture2.Upload(pixelData2);
443 std::vector<Texture> texturesToBind;
444 texturesToBind.push_back(texture1);
445 texturesToBind.push_back(texture2);
447 view.BindTextureResources(texturesToBind);
449 DirectRenderingCode::gBoundTextureCount = 0;
451 application.SendNotification();
452 application.Render();
454 DALI_TEST_EQUALS(DirectRenderingCode::gBoundTextureCount, texturesToBind.size(), TEST_LOCATION);
459 // Positive test case for a method
460 int UtcDaliGlViewDirectRenderingThreadedNew(void)
462 ToolkitTestApplication application;
463 tet_infoline(" UtcDaliGlViewDirectRenderingThreadedNew");
464 GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGBA8888);
465 DALI_TEST_CHECK(view);
467 auto mode1 = view.GetBackendMode();
469 DALI_TEST_EQUALS(mode1, GlView::BackendMode::DIRECT_RENDERING_THREADED, TEST_LOCATION);
474 int UtcDaliGlViewDirectRenderingThreadedOnScene(void)
476 ToolkitTestApplication application;
478 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
481 application.GetScene().Add(view);
482 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
483 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
484 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
485 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
486 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
488 // Set size on the actor (half the window size to show that glClear() and scissor test work together)
489 view.SetProperty(Actor::Property::SIZE, Size(100, 100));
490 view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
492 while(DirectRenderingCode::gDRFramesRendered < 1)
494 application.SendNotification();
495 application.Render();
497 DALI_TEST_CHECK(true);
501 extern "C" bool gDirectRenderingFailCreateShader;
502 extern "C" bool gDirectRenderingFailCreateProgram;
504 int UtcDaliGlViewDirectRenderingThreadedOnScene1(void)
506 ToolkitTestApplication application;
508 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
510 // This test will fail instantiating shaders
511 gDirectRenderingFailCreateShader = true;
514 application.GetScene().Add(view);
515 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
516 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
517 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
518 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
519 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
521 // Set size on the actor (half the window size to show that glClear() and scissor test work together)
522 view.SetProperty(Actor::Property::SIZE, Size(100, 100));
523 view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
525 while(DirectRenderingCode::gDRFramesRendered < 1)
527 application.SendNotification();
528 application.Render();
530 DALI_TEST_CHECK(true);
534 int UtcDaliGlViewDirectRenderingThreadedOnScene2(void)
536 ToolkitTestApplication application;
538 GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
540 // This test will fail instantiating shaders
541 gDirectRenderingFailCreateProgram = true;
544 application.GetScene().Add(view);
545 view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
546 view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
547 view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
548 view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
549 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
551 // Set size on the actor (half the window size to show that glClear() and scissor test work together)
552 view.SetProperty(Actor::Property::SIZE, Size(100, 100));
553 view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
555 while(DirectRenderingCode::gDRFramesRendered < 1)
557 application.SendNotification();
558 application.Render();
560 DALI_TEST_CHECK(true);