(DirectRendering) Send rotated clippingBox so we can call glScissor without convert 43/321443/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 21 Mar 2025 08:12:08 +0000 (17:12 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 21 Mar 2025 09:28:34 +0000 (18:28 +0900)
Let we make RenderCallbackInput's clippingBox is screen coordinates.

It will make that we don't consider window surface rotated or not.

Change-Id: I9d7e0c89682a4de12fad6bb57d322b3eaafb5d3c
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-DrawableActor.cpp
dali/internal/render/common/render-algorithms.cpp
dali/public-api/signals/render-callback.h

index 00da72cfe7185fb837a54bd174bceb0097616952..33eb0a338a257b1823117f82ff4ac3aa5d579c52 100644 (file)
@@ -22,16 +22,18 @@ struct DrawableObject
 {
   bool Render(const RenderCallbackInput& inputData)
   {
-    // Store the size of rendered area
-    size = inputData.size;
+    // Store the size and clipping box of rendered area
+    size        = inputData.size;
+    clippingBox = inputData.clippingBox;
 
     return false;
   }
 
   bool RenderWithTextures(const RenderCallbackInput& inputData)
   {
-    // Store the size of rendered area
-    size = inputData.size;
+    // Store the size and clipping box of rendered area
+    size        = inputData.size;
+    clippingBox = inputData.clippingBox;
 
     auto count = inputData.textureBindings.size();
 
@@ -41,7 +43,8 @@ struct DrawableObject
     return false;
   }
 
-  Size size{};
+  Size        size{};
+  ClippingBox clippingBox{};
 };
 
 int UtcDaliRendererSetRenderCallbackP(void)
@@ -131,5 +134,100 @@ int UtcRenderCallbackTextureBindingP(void)
   // Check the size (whether callback has been called)
   DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
 
+  END_TEST;
+}
+
+int UtcDaliDrawableActor2P(void)
+{
+  tet_infoline("Testing Renderer:LSetRenderCallback() and check clipping box");
+  TestApplication application;
+
+  DrawableObject drawable{};
+
+  auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
+
+  Actor actor       = Actor::New();
+  Actor parentActor = Actor::New();
+  application.GetScene().Add(parentActor);
+  parentActor.Add(actor);
+
+  parentActor.SetProperty(Actor::Property::POSITION, Vector2(20, 50));
+  parentActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+  actor.SetProperty(Actor::Property::SIZE, Vector2(100, 200));
+  actor.SetProperty(Actor::Property::POSITION, Vector2(50, 70));
+  actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+  auto renderer = Renderer::New(*callback);
+  actor.AddRenderer(renderer);
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  // Check the size (whether callback has been called)
+  DALI_TEST_EQUALS(drawable.size, Size(100, 200), TEST_LOCATION);
+
+  // Check clippingBox. Note that clippingBox coordinate is in screen coordinates
+  DALI_TEST_EQUALS(drawable.clippingBox, Rect<int32_t>(20 + 50, 800 - (50 + 70 + 200), 100, 200), TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliDrawableActorSceneRotated(void)
+{
+  tet_infoline("Testing Renderer:LSetRenderCallback()");
+  TestApplication application;
+
+  DrawableObject drawable{};
+
+  auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
+
+  Actor actor       = Actor::New();
+  Actor parentActor = Actor::New();
+  application.GetScene().Add(parentActor);
+  parentActor.Add(actor);
+
+  parentActor.SetProperty(Actor::Property::POSITION, Vector2(20, 50));
+  parentActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+  actor.SetProperty(Actor::Property::SIZE, Vector2(100, 200));
+  actor.SetProperty(Actor::Property::POSITION, Vector2(50, 70));
+  actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+  auto renderer = Renderer::New(*callback);
+  actor.AddRenderer(renderer);
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  // Check the size (whether callback has been called)
+  DALI_TEST_EQUALS(drawable.size, Size(100, 200), TEST_LOCATION);
+
+  // Check clippingBox. Note that clippingBox coordinate is in screen coordinates
+  DALI_TEST_EQUALS(drawable.clippingBox, Rect<int32_t>(20 + 50, TestApplication::DEFAULT_SURFACE_HEIGHT - (50 + 70 + 200), 100, 200), TEST_LOCATION);
+
+  // Reset size (to check callback comes)
+  drawable.size = Size();
+
+  application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
+                                        TestApplication::DEFAULT_SURFACE_HEIGHT,
+                                        90,
+                                        0);
+
+  application.SendNotification();
+  application.Render();
+
+  // Check the size (whether callback has been called)
+  DALI_TEST_EQUALS(drawable.size, Size(100, 200), TEST_LOCATION);
+
+  // Check clippingBox. Note that clippingBox coordinate is in screen coordinates
+  DALI_TEST_EQUALS(drawable.clippingBox, Rect<int32_t>(50 + 70, 20 + 50, 200, 100), TEST_LOCATION);
+
   END_TEST;
 }
\ No newline at end of file
index 33204802e44933742ebb1231588ef260c066d088..985cdde2ad2b5deb4b49e179c2f6e10172b95ac4 100644 (file)
@@ -497,9 +497,14 @@ inline void RenderAlgorithms::SetupScissorClipping(
     // callback so it may be clipped
     if(DALI_LIKELY(item.mRenderer) && item.mRenderer->GetRenderCallback())
     {
+      ClippingBox useClippingBox(RenderItem::CalculateViewportSpaceAABB(item.mModelViewMatrix, Vector3::ZERO, item.GetPartialRenderingDataNodeInfomations().size, mViewportRectangle.width, mViewportRectangle.height));
+
+      Graphics::Viewport graphicsViewport   = ViewportFromClippingBox(Uint16Pair{0, 0}, mViewportRectangle, 0);
+      Graphics::Rect2D   graphicsScissorBox = Rect2DFromClippingBox(useClippingBox, orientation, graphicsViewport);
+
       // store clipping box inside the render callback input structure
       auto& input       = item.mRenderer->GetRenderCallbackInput();
-      input.clippingBox = ClippingBox(RenderItem::CalculateViewportSpaceAABB(item.mModelViewMatrix, Vector3::ZERO, item.GetPartialRenderingDataNodeInfomations().size, mViewportRectangle.width, mViewportRectangle.height));
+      input.clippingBox = ClippingBox(graphicsScissorBox.x, graphicsScissorBox.y, graphicsScissorBox.width, graphicsScissorBox.height);
     }
   }
 }
index ec50a15824b3db95938395375757631fd65c27fa..5166cf1aa758edfea22eba6f39a98a9b25ad78a2 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_RENDER_CALLBACK_H
 
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -46,10 +46,10 @@ struct DALI_CORE_API RenderCallbackInput
   Matrix                mvp;
   Matrix                projection;
   Size                  size;
-  Rect<int32_t>         clippingBox;
+  Rect<int32_t>         clippingBox; ///< in screen coordinates
   std::vector<uint32_t> textureBindings;
 
-  std::any eglContext;       ///< Storage for EGL Context
+  std::any eglContext;         ///< Storage for EGL Context
   bool     usingOwnEglContext; ///< Uses own EGL context (owns GL state), custom code should be aware of it
 
   Matrix view; // Added at end to avoid abi break.
@@ -70,7 +70,6 @@ struct DALI_CORE_API RenderCallbackInput
 class DALI_CORE_API RenderCallback
 {
 public:
-
   /**
    * @brief Mode of execution of custom rendering code into the pipeline
    *
@@ -231,16 +230,16 @@ public:
    * @SINCE_2_3.12
    * @return Valid execution mode
    */
-   [[nodiscard]] ExecutionMode GetExecutionMode() const
-   {
-     return mExecutionMode;
-   }
+  [[nodiscard]] ExecutionMode GetExecutionMode() const
+  {
+    return mExecutionMode;
+  }
 
 private:
   std::unique_ptr<CallbackBase> mCallback; //< Callback base object
   RenderCallbackInput           mRenderCallbackInput;
   ExecutionMode                 mExecutionMode{ExecutionMode::DEFAULT};
-  std::vector<Dali::Texture> mTextureResources{};
+  std::vector<Dali::Texture>    mTextureResources{};
 };
 } // namespace Dali