[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-GlViewDirectRendering.cpp
index 82e3be9..85f1746 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
 #include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/public-api/signals/render-callback.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -186,28 +187,52 @@ int UtcDaliGlViewDirectRenderingOnSizeSet(void)
 
 namespace DirectRenderingCode
 {
-
 // Internal callback function
-void glInit(void)
+void glInit(Dali::RenderCallbackInput& input)
 {
 }
 
-int glRenderFrame(void)
+int glRenderFrame(Dali::RenderCallbackInput& input)
 {
   static unsigned int retFlag = 0;
   return retFlag++;
 }
 
-void glTerminate(void)
+int gBoundTextureCount = 0;
+
+int glRenderFrameWithTextures(Dali::RenderCallbackInput& input)
 {
+  gBoundTextureCount = input.textureBindings.size();
+  return 1;
 }
 
-void resizeCB(Vector2 size)
+void glTerminate(Dali::RenderCallbackInput& input)
 {
 }
 
+// Internal callback function
+void glInitMT(Dali::RenderCallbackInput& input)
+{
+}
+
+int gDRFramesRendered = 0;
+
+int glRenderFrameMT(Dali::RenderCallbackInput& input)
+{
+  gDRFramesRendered++;
+  return 1;
 }
 
+void glTerminateMT(Dali::RenderCallbackInput& input)
+{
+}
+
+void resizeCB(Vector2 size)
+{
+}
+
+} // namespace DirectRenderingCode
+
 int UtcDaliGlViewDirectRenderingRegisterGlCallbacksN(void)
 {
   ToolkitTestApplication application;
@@ -359,6 +384,32 @@ int UtcDaliGlViewDirectRenderingResize(void)
   END_TEST;
 }
 
+int UtcDaliGlViewDirectRenderingDirectResize(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingResize");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::UNSAFE_DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  application.GetScene().Add(view);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
+  view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
+  view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
+
+  application.SendNotification();
+  application.Render();
+
+  //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
+  std::this_thread::sleep_for(std::chrono::milliseconds(100));
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}
+
 int UtcDaliGlViewDirectRenderingTerminateCallback(void)
 {
   ToolkitTestApplication application;
@@ -375,8 +426,6 @@ int UtcDaliGlViewDirectRenderingTerminateCallback(void)
   application.SendNotification();
   application.Render();
 
-
-
   //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
   std::this_thread::sleep_for(std::chrono::milliseconds(100));
 
@@ -385,4 +434,155 @@ int UtcDaliGlViewDirectRenderingTerminateCallback(void)
 
   DALI_TEST_CHECK(true);
   END_TEST;
-}
\ No newline at end of file
+}
+
+int UtcDaliGlViewDirectRenderingTextureBinding(void)
+{
+  ToolkitTestApplication application;
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrameWithTextures), Dali::MakeCallback(DirectRenderingCode::glTerminate));
+  view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
+
+  // Set size on the actor (half the window size to show that glClear() and scissor test work together)
+  view.SetProperty(Actor::Property::SIZE, Size(100, 100));
+  view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
+
+  application.GetScene().Add(view);
+
+  // Prepare texture 1
+  Texture   texture1   = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, 512, 512);
+  auto*     data1      = reinterpret_cast<uint8_t*>(malloc(512 * 512 * 4));
+  PixelData pixelData1 = PixelData::New(data1, 512 * 512 * 4, 512, 512, Pixel::Format::RGBA8888, PixelData::ReleaseFunction::FREE);
+  texture1.Upload(pixelData1);
+
+  // Prepare texture 2
+  Texture   texture2   = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, 512, 512);
+  auto*     data2      = reinterpret_cast<uint8_t*>(malloc(512 * 512 * 4));
+  PixelData pixelData2 = PixelData::New(data2, 512 * 512 * 4, 512, 512, Pixel::Format::RGBA8888, PixelData::ReleaseFunction::FREE);
+  texture2.Upload(pixelData2);
+
+  std::vector<Texture> texturesToBind;
+  texturesToBind.push_back(texture1);
+  texturesToBind.push_back(texture2);
+
+  view.BindTextureResources(texturesToBind);
+
+  DirectRenderingCode::gBoundTextureCount = 0;
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(DirectRenderingCode::gBoundTextureCount, texturesToBind.size(), TEST_LOCATION);
+
+  END_TEST;
+}
+
+// Positive test case for a method
+int UtcDaliGlViewDirectRenderingThreadedNew(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliGlViewDirectRenderingThreadedNew");
+  GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGBA8888);
+  DALI_TEST_CHECK(view);
+
+  auto mode1 = view.GetBackendMode();
+
+  DALI_TEST_EQUALS(mode1, GlView::BackendMode::DIRECT_RENDERING_THREADED, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingThreadedOnScene(void)
+{
+  ToolkitTestApplication application;
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
+
+  //Onscene
+  application.GetScene().Add(view);
+  view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
+  view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+
+  // Set size on the actor (half the window size to show that glClear() and scissor test work together)
+  view.SetProperty(Actor::Property::SIZE, Size(100, 100));
+  view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
+
+  while(DirectRenderingCode::gDRFramesRendered < 1)
+  {
+    application.SendNotification();
+    application.Render();
+  }
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}
+
+extern "C" bool gDirectRenderingFailCreateShader;
+extern "C" bool gDirectRenderingFailCreateProgram;
+
+int UtcDaliGlViewDirectRenderingThreadedOnScene1(void)
+{
+  ToolkitTestApplication application;
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
+
+  // This test will fail instantiating shaders
+  gDirectRenderingFailCreateShader = true;
+
+  //Onscene
+  application.GetScene().Add(view);
+  view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
+  view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+
+  // Set size on the actor (half the window size to show that glClear() and scissor test work together)
+  view.SetProperty(Actor::Property::SIZE, Size(100, 100));
+  view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
+
+  while(DirectRenderingCode::gDRFramesRendered < 1)
+  {
+    application.SendNotification();
+    application.Render();
+  }
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingThreadedOnScene2(void)
+{
+  ToolkitTestApplication application;
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING_THREADED, GlView::ColorFormat::RGB888);
+
+  // This test will fail instantiating shaders
+  gDirectRenderingFailCreateProgram = true;
+
+  //Onscene
+  application.GetScene().Add(view);
+  view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInitMT), Dali::MakeCallback(DirectRenderingCode::glRenderFrameMT), Dali::MakeCallback(DirectRenderingCode::glTerminateMT));
+  view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+
+  // Set size on the actor (half the window size to show that glClear() and scissor test work together)
+  view.SetProperty(Actor::Property::SIZE, Size(100, 100));
+  view.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
+
+  while(DirectRenderingCode::gDRFramesRendered < 1)
+  {
+    application.SendNotification();
+    application.Render();
+  }
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}