Added UNSAFE_RENDERING_DIRECT backend mode for GLView. 91/306191/6
authorAdam Bialogonski <adam.b@samsung.com>
Fri, 16 Feb 2024 16:11:14 +0000 (16:11 +0000)
committerAdam Bialogonski <adam.b@samsung.com>
Mon, 19 Feb 2024 16:17:12 +0000 (16:17 +0000)
UNSAFE_RENDERING_DIRECT mode allows injecting the GL calls
directly into window context. This method is considered unsafe
and should be used cautiously as it may alter GL state of the
main DALi pipeline (ie. affect UI rendering).

Change-Id: Idd36a26541f9af56657c1eef72ee7e83e2a45581
Signed-off-by: Adam Bialogonski <adam.b@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-GlViewDirectRendering.cpp
dali-toolkit/internal/controls/gl-view/drawable-view-impl.cpp
dali-toolkit/internal/controls/gl-view/drawable-view-native-renderer.h
dali-toolkit/public-api/controls/gl-view/gl-view.cpp
dali-toolkit/public-api/controls/gl-view/gl-view.h

index e018c49..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.
@@ -384,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;
index 4549ea4..01b84f7 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.
@@ -43,14 +43,16 @@ DrawableView::DrawableView(GlView::BackendMode backendMode)
   mStencil(false),
   mMSAA(0)
 {
-  mRenderCallback = RenderCallback::New(this, &DrawableView::OnRenderCallback);
-
   // Create NativeRenderer
   Dali::Internal::NativeRendererCreateInfo createInfo;
   createInfo.maxOffscreenBuffers = 2u;
   createInfo.threadEnabled       = (backendMode == GlView::BackendMode::DIRECT_RENDERING_THREADED);
+  createInfo.directExecution     = (backendMode == GlView::BackendMode::UNSAFE_DIRECT_RENDERING);
   createInfo.presentationMode    = Dali::Internal::NativeRendererCreateInfo::PresentationMode::FIFO;
-  mNativeRenderer                = std::make_unique<Dali::Internal::DrawableViewNativeRenderer>(createInfo);
+
+  mRenderCallback = RenderCallback::New(this, &DrawableView::OnRenderCallback, createInfo.directExecution ? RenderCallback::ExecutionMode::UNSAFE : RenderCallback::ExecutionMode::ISOLATED);
+
+  mNativeRenderer = std::make_unique<Dali::Internal::DrawableViewNativeRenderer>(createInfo);
 }
 
 DrawableView::~DrawableView() = default;
index 005b9c1..bc13c58 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_PROJECT_DRAWABLE_VIEW_NATIVE_RENDERER_H
 
 /*
-* Copyright (c) 2021 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.
@@ -41,6 +41,8 @@ struct NativeRendererCreateInfo
   };
 
   bool threadEnabled { false };
+  bool directExecution { false };
+
   uint32_t maxOffscreenBuffers { 3u };
   PresentationMode presentationMode {PresentationMode::FIFO};
 };
index 7e41948..5060566 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.
@@ -49,6 +49,7 @@ GlView GlView::New(BackendMode backendMode, ColorFormat colorFormat)
   {
     case BackendMode::DIRECT_RENDERING:
     case BackendMode::DIRECT_RENDERING_THREADED:
+    case BackendMode::UNSAFE_DIRECT_RENDERING:
     {
       return Internal::DrawableView::New(backendMode);
     }
index 3880118..13cc2e9 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef DALI_TOOLKIT_GL_VIEW_H
 #define DALI_TOOLKIT_GL_VIEW_H
 /*
- * Copyright (c) 2023 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.
@@ -54,11 +54,12 @@ public:
   {
     /**
      * DIRECT_RENDERING mode executes GL code within DALi graphics
-     * pipeline. When Renderer is about to be drawn, the callback
+     * pipeline but creates isolated context hence it doesn't alter any
+     * DALi rendering state. When Renderer is about to be drawn, the callback
      * will be executed and the custom code "injected" into the pipeline.
      * This allows rendering directly to the surface rather than offscreen.
      *
-     * * @SINCE_2_1.18
+     * @SINCE_2_3.12
      */
     DIRECT_RENDERING = 0,
 
@@ -82,6 +83,21 @@ public:
     EGL_IMAGE_OFFSCREEN_RENDERING,
 
     /**
+     * UNSAFE_DIRECT_RENDERING mode executes GL code within DALi graphics
+     * pipeline WITHOUT isolating the GL context so should be used with caution!
+     * The custom rendering code is executed within current window context and
+     * may alter the GL state. This mode is considered unsafe and should be used
+     * only when drawing on main GL context is necessary!
+     *
+     * When Renderer is about to be drawn, the callback
+     * will be executed and the custom code "injected" into the pipeline.
+     * This allows rendering directly to the surface rather than offscreen.
+     *
+     * @SINCE_2_3.12
+     */
+    UNSAFE_DIRECT_RENDERING,
+
+    /**
      * The default mode is set to EGL_IMAGE_OFFSCREEN_RENDERING for backwards
      * compatibility.
      *