Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUI] Make FrameUpdateCallback could use UIVector2 and UIColor #6590

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

hinohie
Copy link
Contributor

@hinohie hinohie commented Jan 20, 2025

Let we allow to use FrameUpdateCallbackInterface could use UIVector2 and UIColor so we can reduce GC call at render thread.

Require dali patch :

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-csharp-binder/+/318520

@TizenAPI-Bot
Copy link
Collaborator

Internal API Changed

Added: 8, Removed: 0, Changed: 0

Added

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakeColor(System.UInt32,Tizen.NUI.UIColor)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakePosition(System.UInt32,Tizen.NUI.UIVector2)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakeScale(System.UInt32,Tizen.NUI.UIVector2)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakeSize(System.UInt32,Tizen.NUI.UIVector2)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetColor(System.UInt32,Tizen.NUI.UIColor&)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetPosition(System.UInt32,Tizen.NUI.UIVector2&)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetScale(System.UInt32,Tizen.NUI.UIVector2&)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetSize(System.UInt32,Tizen.NUI.UIVector2&)

Let we allow to use FrameUpdateCallbackInterface could use UIVector2 and UIColor
so we can reduce GC call at render thread.

Require dali patch :

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-csharp-binder/+/318520

Signed-off-by: Eunki, Hong <[email protected]>
@hinohie hinohie force-pushed the frameupdate_use_uivector2 branch from 870a9d1 to 7cee53f Compare January 20, 2025 04:36
@TizenAPI-Bot
Copy link
Collaborator

Internal API Changed

Added: 8, Removed: 0, Changed: 0

Added

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakeColor(System.UInt32,Tizen.NUI.UIColor)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakePosition(System.UInt32,Tizen.NUI.UIVector2)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakeScale(System.UInt32,Tizen.NUI.UIVector2)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::BakeSize(System.UInt32,Tizen.NUI.UIVector2)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetColor(System.UInt32,Tizen.NUI.UIColor&)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetPosition(System.UInt32,Tizen.NUI.UIVector2&)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetScale(System.UInt32,Tizen.NUI.UIVector2&)

+ /// <since_tizen>none</since_tizen
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ System.Boolean Tizen.NUI.FrameUpdateCallbackInterface::GetSize(System.UInt32,Tizen.NUI.UIVector2&)

{
return false;
}
bool ret = Interop.FrameUpdateCallbackInterface.FrameCallbackInterfaceBakePositionVector2Componentwise(proxyIntPtr, id, position.X, position.Y);
Copy link
Collaborator

@rabbitfor rabbitfor Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, there is a ReusablePool<T> that reuses object for PInvoke.
For example,

internal static void InternalSetPropertyColor(HandleRef actor, int propertyType, UIColor color)
{
if (actor.Handle == System.IntPtr.Zero)
{
throw new System.InvalidOperationException("Error! NUI's native dali object is already disposed. OR the native dali object handle of NUI becomes null!");
}
ReusablePool<Vector4>.GetOne((vector4, actor, propertyType, color) =>
{
vector4.Reset(color);
_ = Interop.Actor.InternalSetPropertyVector4(actor, propertyType, vector4.SwigCPtr);
NDalicPINVOKE.ThrowExceptionIfExists();
}, actor, propertyType, color);
}

This code gets Vector4 object from the pool and use it for PInvoke and return it back to the pool.
By using this, you can avoid to create bindings for every struct cases.

protected bool BakePosition(uint id, UIVector2 position)
{
    if (proxyIntPtr == IntPtr.Zero)
    {
        return false;
    }
    
    return ReusablePool<Vector3>.GetOne((vector3, proxyIntPtr, id, position) =>
    {
        vector3.Reset(position.X, position.Y, 0); // I am not sure there's a Reset for Vector3
        bool ret = Interop.FrameUpdateCallbackInterface.FrameCallbackInterfaceBakePosition(proxyIntPtr, id, position);
        if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
        return ret;
    }, proxyIntPtr, id, position);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I know, ReusablePool is not thread safe. This API will be called at RenderThread, so I think we cannot use this pool here :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my.. It need to be thread safe! since current resuable pool is not thread safe you would not use it.

Copy link
Contributor

@bshsqa bshsqa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.
And if it requires cost to use Vector2 in NUI.
How do you think about to deprecate previous apis.
Because the FrameUpdateCallback is called in every frame so it looks be better to guide for VD to use new API.

@hinohie hinohie merged commit b4ef959 into Samsung:DevelNUI Jan 22, 2025
3 checks passed
@hinohie hinohie deleted the frameupdate_use_uivector2 branch January 22, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants