[NUI](Rendering) Get newly added property index + Implement UpdateAreaExtents
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 14 Mar 2025 00:24:13 +0000 (09:24 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 25 Mar 2025 06:44:47 +0000 (15:44 +0900)
Let we bind some missing enums for Renderer.

And also, make new property for extents update area of attached view.

relative dali patches:
- https://review.tizen.org/gerrit/c/platform/core/uifw/dali-core/+/321077
- https://review.tizen.org/gerrit/c/platform/core/uifw/dali-csharp-binder/+/321089

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.Renderer.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/Rendering/Renderer.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/RendererUpdateAreaTest.cs [new file with mode: 0644]

index 3e8fe5a7bf54722bc1d74cccf32b7a10e5ea13c1..d4f22ba6512dfb98162eeab9dba903993077cec1 100755 (executable)
@@ -108,6 +108,33 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_STENCIL_OPERATION_ON_Z_PASS_get")]
             public static extern int StencilOperationOnZPassGet();
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_MIX_COLOR_get")]
+            public static extern int MixColorGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_MIX_COLOR_RED_get")]
+            public static extern int MixColorRedGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_MIX_COLOR_GREEN_get")]
+            public static extern int MixColorGreenGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_MIX_COLOR_BLUE_get")]
+            public static extern int MixColorBlueGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_OPACITY_get")]
+            public static extern int MixColorOpacityGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_RENDERING_BEHAVIOR_get")]
+            public static extern int RenderingBehaviorGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_BLEND_EQUATION_get")]
+            public static extern int BlendEquationGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_INSTANCE_COUNT_get")]
+            public static extern int InstanceCountGet();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_Property_UPDATE_AREA_EXTENTS_get")]
+            public static extern int UpdateAreaExtentsGet();
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Renderer_New")]
             public static extern global::System.IntPtr New(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
index 65a2ff12da6361b28604415ddf04f42976c0433b..3fdca0ae81f1cd0557e3bcf4557316e857b68615 100755 (executable)
@@ -6460,7 +6460,21 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// This will be public opened after ACR done. Before ACR, need to be hidden as inhouse API.
+        /// <summary>
+        /// Gets and Sets hint of partial update area.
+        /// </summary>
+        /// <remarks>
+        /// The property format applied as below logics.
+        /// Vector4(offsetX, offsetY, width, height).
+        /// - offsetX : Offset of the center of partial update area's X axis position from the center of View.
+        /// - offsetY : Offset of the center of partial update area's X axis position from the center of View.
+        /// - width   : Width of partial update area.
+        /// - height  : Height of partial update area.
+        ///
+        /// Special case - If we set Vector4.Zero, it will be used Vector4(0.0f, 0.0f, SizeWidth, SizeHeight) automatically.
+        ///
+        /// This update area give efforts for all Renderer and Visuals.
+        /// </remarks>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public Vector4 UpdateAreaHint
         {
index 53c7de2727b92603e19e5cc5ca6c48a7515da253..c245b2e23945dd165ba2221cf8a718579e6bb13b 100755 (executable)
@@ -724,6 +724,39 @@ namespace Tizen.NUI
             }
         }
 
+        /// <summary>
+        /// Gets and Sets extents of partial update area.
+        /// </summary>
+        /// <remarks>
+        /// Extents the area - the position and the size - used for the attached View's partial update area calculation.
+        /// This value be appended after calculate all update area, like visual offset.
+        /// Change  <see cref="Tizen.NUI.BaseComponents.View.UpdateAreaHint"/> value if you want to change View's partial update area.
+        /// Warning : Only 0u ~ 65535u integer values are allowed for each parameters.
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public UIExtents UpdateArea
+        {
+            get
+            {
+                // TODO : Clean up below logics
+                using Extents temp = new Extents();
+                using var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, Renderer.Property.UpdateAreaExtents);
+                pValue.Get(temp);
+
+                if (temp == null)
+                {
+                    return new UIExtents(0.0f);
+                }
+                UIExtents result = new UIExtents((float)temp.Start, (float)temp.End, (float)temp.Top, (float)temp.Bottom);
+                return result;
+            }
+            set
+            {
+                using var temp = new Tizen.NUI.PropertyValue((Extents)value);
+                Tizen.NUI.Object.SetProperty(SwigCPtr, Renderer.Property.UpdateAreaExtents, temp);
+            }
+        }
+
         /// <summary>
         /// Sets the geometry to be used by this renderer.
         /// </summary>
@@ -860,15 +893,15 @@ namespace Tizen.NUI
 
             /// This will be opened API after ACR done. Before ACR, need to be hidden as inhouse API.
             [EditorBrowsable(EditorBrowsableState.Never)]
-            public static readonly int BACKGROUND = Interop.Renderer.RangesBackgroundGet();
+            public static readonly int Background = Interop.Renderer.RangesBackgroundGet();
 
             /// This will be opened API after ACR done. Before ACR, need to be hidden as inhouse API.
             [EditorBrowsable(EditorBrowsableState.Never)]
-            public static readonly int CONTENT = Interop.Renderer.RangesContentGet();
+            public static readonly int Content = Interop.Renderer.RangesContentGet();
 
             /// This will be opened API after ACR done. Before ACR, need to be hidden as inhouse API.
             [EditorBrowsable(EditorBrowsableState.Never)]
-            public static readonly int DECORATION = Interop.Renderer.RangesDecorationGet();
+            public static readonly int Decoration = Interop.Renderer.RangesDecorationGet();
 
             /// This will be opened API after ACR done. Before ACR, need to be hidden as inhouse API.
             [EditorBrowsable(EditorBrowsableState.Never)]
@@ -876,15 +909,27 @@ namespace Tizen.NUI
 
 
 
-            [Obsolete("Do not use this, that is deprecated in API9 and will be removed in API11. Use ForegroundEffect instead.")]
+            [Obsolete("Do not use this, that is deprecated in API9 and will be removed in API11. Use BackgroundEffect instead.")]
             [EditorBrowsable(EditorBrowsableState.Never)]
             [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "<Pending>")]
-            public static readonly int FOREGROUND_EFFECT = Interop.Renderer.RangesForegroundEffectGet();
+            public static readonly int BACKGROUND_EFFECT = Interop.Renderer.RangesBackgroundEffectGet();
 
-            [Obsolete("Do not use this, that is deprecated in API9 and will be removed in API11. Use BackgroundEffect instead.")]
+            [Obsolete("Do not use this, that is deprecated in API13 and will be removed in API15. Use Background instead.")]
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public static readonly int BACKGROUND = Interop.Renderer.RangesBackgroundGet();
+
+            [Obsolete("Do not use this, that is deprecated in API13 and will be removed in API15. Use Content instead.")]
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public static readonly int CONTENT = Interop.Renderer.RangesContentGet();
+
+            [Obsolete("Do not use this, that is deprecated in API13 and will be removed in API15. Use Decoration instead.")]
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public static readonly int DECORATION = Interop.Renderer.RangesDecorationGet();
+
+            [Obsolete("Do not use this, that is deprecated in API9 and will be removed in API11. Use ForegroundEffect instead.")]
             [EditorBrowsable(EditorBrowsableState.Never)]
             [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "<Pending>")]
-            public static readonly int BACKGROUND_EFFECT = Interop.Renderer.RangesBackgroundEffectGet();
+            public static readonly int FOREGROUND_EFFECT = Interop.Renderer.RangesForegroundEffectGet();
         }
 
         /// <summary>
@@ -916,6 +961,17 @@ namespace Tizen.NUI
             internal static readonly int StencilOperationOnFail = Interop.Renderer.StencilOperationOnFailGet();
             internal static readonly int StencilOperationOnZFail = Interop.Renderer.StencilOperationOnZFailGet();
             internal static readonly int StencilOperationOnZPass = Interop.Renderer.StencilOperationOnZPassGet();
+            internal static readonly int MixColor = Interop.Renderer.MixColorGet();
+            internal static readonly int MixColorRed = Interop.Renderer.MixColorRedGet();
+            internal static readonly int MixColorGreen = Interop.Renderer.MixColorGreenGet();
+            internal static readonly int MixColorBlue = Interop.Renderer.MixColorBlueGet();
+            internal static readonly int MixColorOpacity = Interop.Renderer.MixColorOpacityGet();
+            internal static readonly int RenderingBehavior = Interop.Renderer.RenderingBehaviorGet();
+            internal static readonly int BlendEquation = Interop.Renderer.BlendEquationGet();
+            internal static readonly int VertexRangeFirst = Interop.Renderer.IndexRangeFirstGet();
+            internal static readonly int VertexRangeCount = Interop.Renderer.IndexRangeCountGet();
+            internal static readonly int InstanceCount = Interop.Renderer.InstanceCountGet();
+            internal static readonly int UpdateAreaExtents = Interop.Renderer.UpdateAreaExtentsGet();
         }
     }
 }
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/RendererUpdateAreaTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/RendererUpdateAreaTest.cs
new file mode 100644 (file)
index 0000000..d952b81
--- /dev/null
@@ -0,0 +1,250 @@
+using System;
+using System.Runtime.InteropServices;
+using Tizen.NUI.BaseComponents;
+using System.Collections.Generic;
+
+namespace Tizen.NUI.Samples
+{
+    public class RendererUpdateAreaTest : IExample
+    {
+        static readonly string VERTEX_SHADER =
+        "//@name RendererUpdateAreaTest.vert\n" +
+        "\n" +
+        "//@version 100\n" +
+        "\n" +
+        "precision highp float;\n"+
+        "INPUT highp vec2 aPosition;\n" +
+        "\n" +
+        "UNIFORM_BLOCK VertBlock\n" +
+        "{\n" +
+        "  UNIFORM highp mat4 uMvpMatrix;\n" +
+        "  UNIFORM highp vec3 uSize;\n" +
+        "  UNIFORM highp vec2 uCustomExtraSize;\n" +
+        "};\n" +
+        "void main()\n" +
+        "{\n" +
+        "    vec4 pos = vec4(aPosition, 0.0, 1.0) * vec4(uSize.xy + uCustomExtraSize, 0.0, 1.0);\n" +
+        "    gl_Position = uMvpMatrix * pos;\n" +
+        "}\n";
+
+        static readonly string FRAGMENT_SHADER =
+        "//@name RendererUpdateAreaTest.frag\n" +
+        "\n" +
+        "//@version 100\n" +
+        "\n" +
+        "precision highp float;\n"+
+        "\n" +
+        "UNIFORM_BLOCK FragBlock\n" +
+        "{\n" +
+        "  UNIFORM lowp vec4 uColor;\n" +
+        "};\n" +
+        "\n" +
+        "void main()\n" +
+        "{\n" +
+        "    gl_FragColor = uColor;\n" +
+        "}\n";
+
+
+        struct SimpleQuadVertex
+        {
+            public UIVector2 position;
+        }
+
+        private PropertyBuffer CreateQuadPropertyBuffer()
+        {
+            /* Create Property buffer */
+            PropertyMap vertexFormat = new PropertyMap();
+            vertexFormat.Add("aPosition", (int)PropertyType.Vector2);
+
+            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);
+            
+            SimpleQuadVertex vertex1 = new SimpleQuadVertex();
+            SimpleQuadVertex vertex2 = new SimpleQuadVertex();
+            SimpleQuadVertex vertex3 = new SimpleQuadVertex();
+            SimpleQuadVertex vertex4 = new SimpleQuadVertex();
+            vertex1.position = new UIVector2(-0.5f, -0.5f);
+            vertex2.position = new UIVector2(-0.5f, 0.5f);
+            vertex3.position = new UIVector2(0.5f, -0.5f);
+            vertex4.position = new UIVector2(0.5f, 0.5f);
+
+            SimpleQuadVertex[] texturedQuadVertexData = new SimpleQuadVertex[4] { vertex1, vertex2, vertex3, vertex4 };
+
+            int size = Marshal.SizeOf(vertex1);
+            IntPtr pA = Marshal.AllocHGlobal(checked(size * texturedQuadVertexData.Length));
+
+            try
+            {
+                for (int i = 0; i < texturedQuadVertexData.Length; i++)
+                {
+                    Marshal.StructureToPtr(texturedQuadVertexData[i], pA + i * size, true);
+                }
+
+                vertexBuffer.SetData(pA, (uint)texturedQuadVertexData.Length);
+            }
+            catch(Exception e)
+            {
+                Tizen.Log.Error("NUI", "Exception in PropertyBuffer : " + e.Message);
+            }
+            finally
+            {
+                // Free AllocHGlobal memory after call PropertyBuffer.SetData()
+                Marshal.FreeHGlobal(pA);
+            }
+
+            vertexFormat.Dispose();
+
+            return vertexBuffer;
+        }
+
+        static private readonly float extraSizeWidth = 100.0f;
+        static private readonly float extraSizeHeight = 100.0f;
+
+        private Window win;
+        private View root;
+        private View[] subView = new View[3];
+        private Animation moveXAnimation;
+        private Animation moveYAnimation;
+        private Timer mTimer;
+        private int showingViewIndex = 0;
+
+        public void Activate()
+        {
+            win = NUIApplication.GetDefaultWindow();
+            root = new View()
+            {
+                Name = "root",
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                HeightResizePolicy = ResizePolicyType.FillToParent,
+            };
+            win.Add(root);
+
+            moveXAnimation = new Animation(3000); //3.0s
+            moveYAnimation = new Animation(2600); //2.6s
+
+            AddViews();
+            var infoLabel = new TextLabel()
+            {
+                Text = "1'st : No update area extents\n2'nd : Extents just right and bottom.\n3'rd : Fit extented area.",
+                MultiLine = true,
+            };
+            root.Add(infoLabel);
+
+            moveXAnimation.Looping = true;
+            moveXAnimation.LoopingMode = Animation.LoopingModes.AutoReverse;
+            moveXAnimation.Play();
+            moveYAnimation.Looping = true;
+            moveYAnimation.LoopingMode = Animation.LoopingModes.AutoReverse;
+            moveYAnimation.Play();
+
+            // Visibility change timer
+            subView[showingViewIndex].Show();
+
+            mTimer = new Timer(2000);
+            mTimer.Tick += OnTick;
+            mTimer.Start();
+        }
+
+
+        private bool OnTick(object o, EventArgs e)
+        {
+            subView[showingViewIndex].Hide();
+            showingViewIndex = (showingViewIndex + 1)%3;
+            subView[showingViewIndex].Show();
+            return true;
+        }
+
+        private void AddViews()
+        {
+            for(int i = 0; i < 3; i++)
+            {
+                // View area is red, and additional renderer area is yellow.
+                View view = new View()
+                {
+                    Color = Color.Yellow,
+                    BackgroundColor = Color.Red,
+                    SizeWidth = 8.0f,
+                    SizeHeight = 8.0f,
+                    PositionX = extraSizeWidth * 0.5f,
+                    PositionY = extraSizeHeight * 0.5f,
+                };
+
+                var renderer = GenerateRenderer();
+
+                // Make it draw under the background
+                renderer.DepthIndex = Renderer.Ranges.Background - 1;
+
+                if (i == 1)
+                {
+                    renderer.UpdateArea = new UIExtents(0.0f, extraSizeHeight * 0.5f, 0.0f, extraSizeHeight * 0.5f);
+                }
+                else if (i == 2)
+                {
+                    renderer.UpdateArea = new UIExtents(extraSizeHeight * 0.5f, extraSizeHeight * 0.5f, extraSizeHeight * 0.5f, extraSizeHeight * 0.5f);
+                }
+
+                view.AddRenderer(renderer);
+
+                moveXAnimation.AnimateBy(view, "PositionX", 350.0f);
+                moveYAnimation.AnimateBy(view, "PositionY", 200.0f);
+
+                View playGroundView = new View()
+                {
+                    BorderlineWidth = 2.0f,
+                    BorderlineOffset = 1.0f,
+                    SizeWidth = 8.0f + 350.0f + extraSizeWidth,
+                    SizeHeight = 8.0f + 200.0f + extraSizeHeight,
+                    PositionX = 15.0f,
+                    PositionY = i * 250.0f + 15.0f,
+                };
+
+                playGroundView.Hide();
+
+                playGroundView.Add(view);
+                root.Add(playGroundView);
+                subView[i] = playGroundView;
+            }
+        }
+
+        private Geometry GenerateGeometry()
+        {
+            using PropertyBuffer vertexBuffer = CreateQuadPropertyBuffer();
+            Geometry geometry = new Geometry();
+            geometry.AddVertexBuffer(vertexBuffer);
+            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);
+
+            return geometry;
+        }
+
+        private Shader GenerateShader()
+        {
+            Shader shader = new Shader(VERTEX_SHADER, FRAGMENT_SHADER, "RendererUpdateAreaTest");
+            return shader;
+        }
+
+        private Renderer GenerateRenderer()
+        {
+            Renderer renderer = new Renderer();
+            Geometry geometry = GenerateGeometry();
+            Shader shader = GenerateShader();
+
+            renderer.SetGeometry(geometry);
+            renderer.SetShader(shader);
+
+            renderer.RegisterProperty("uCustomExtraSize", new PropertyValue(new UIVector2(extraSizeWidth, extraSizeHeight)));
+
+            return renderer;
+        }
+
+        public void Deactivate()
+        {
+            mTimer?.Stop();
+            mTimer?.Dispose();
+            moveXAnimation?.Stop();
+            moveXAnimation?.Dispose();
+            moveYAnimation?.Stop();
+            moveYAnimation?.Dispose();
+            root?.Unparent();
+            root?.Dispose();
+        }
+    }
+}