From f08307024fb4e782cf0f1e7215011398351c7824 Mon Sep 17 00:00:00 2001 From: dongsug-song <35130733+dongsug-song@users.noreply.github.com> Date: Fri, 23 Mar 2018 17:34:10 +0900 Subject: [PATCH] [NUI] Add _parent in Container (#177) * [NUI] Add _parent in Container * [NUI] Change the way of getting native handle and making c# object --- packaging/version.txt | 2 +- src/Tizen.NUI/src/internal/Application.cs | 5 ++ src/Tizen.NUI/src/internal/DaliEnumConstants.cs | 2 +- src/Tizen.NUI/src/internal/FrameBuffer.cs | 8 +-- src/Tizen.NUI/src/internal/ManualPINVOKE.cs | 3 + src/Tizen.NUI/src/internal/NDalicPINVOKE.cs | 2 +- src/Tizen.NUI/src/internal/Registry.cs | 67 ++++++++++++++-------- src/Tizen.NUI/src/internal/VersionCheck.cs | 43 ++++++++------ src/Tizen.NUI/src/internal/ViewWrapperImpl.cs | 8 +-- .../src/public/BaseComponents/TableView.cs | 16 ++---- src/Tizen.NUI/src/public/BaseComponents/View.cs | 51 ++++++---------- src/Tizen.NUI/src/public/Container.cs | 12 +++- src/Tizen.NUI/src/public/FocusManager.cs | 24 ++------ src/Tizen.NUI/src/public/Layer.cs | 14 +++-- src/Tizen.NUI/src/public/UIComponents/Popup.cs | 24 ++------ src/Tizen.NUI/src/public/Window.cs | 3 +- 16 files changed, 137 insertions(+), 147 deletions(-) diff --git a/packaging/version.txt b/packaging/version.txt index 94fc546..e370439 100755 --- a/packaging/version.txt +++ b/packaging/version.txt @@ -7,4 +7,4 @@ NUGET_VERSION=5.0.0-preview1-99999 INTERNAL_NUGET_VERSION=5.0.0.999 # RPM Version Suffix -RPM_VERSION_SUFFIX=nui83 +RPM_VERSION_SUFFIX=nui500 diff --git a/src/Tizen.NUI/src/internal/Application.cs b/src/Tizen.NUI/src/internal/Application.cs index 5684c4e..02e66a0 100755 --- a/src/Tizen.NUI/src/internal/Application.cs +++ b/src/Tizen.NUI/src/internal/Application.cs @@ -515,6 +515,11 @@ namespace Tizen.NUI // Callback for Application InitSignal private void OnApplicationInit(IntPtr data) { + if (Version.DaliVersionMatchWithNUI() == false) + { + Tizen.Log.Fatal("NUI", "Dali and NUI are version mismatched!"); + } + // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread. DisposeQueue.Instance.Initialize(); diff --git a/src/Tizen.NUI/src/internal/DaliEnumConstants.cs b/src/Tizen.NUI/src/internal/DaliEnumConstants.cs index be815da..cf03bc7 100755 --- a/src/Tizen.NUI/src/internal/DaliEnumConstants.cs +++ b/src/Tizen.NUI/src/internal/DaliEnumConstants.cs @@ -201,7 +201,7 @@ namespace Tizen.NUI internal class NUILog { - [Conditional("DEBUG_ON")] + //[Conditional("DEBUG_ON")] public static void Debug(string msg, [CallerLineNumber] int lineNum = 0, [CallerMemberName] string caller = null, diff --git a/src/Tizen.NUI/src/internal/FrameBuffer.cs b/src/Tizen.NUI/src/internal/FrameBuffer.cs index 085bdb1..97c91d9 100755 --- a/src/Tizen.NUI/src/internal/FrameBuffer.cs +++ b/src/Tizen.NUI/src/internal/FrameBuffer.cs @@ -99,12 +99,8 @@ namespace Tizen.NUI public Texture GetColorTexture() { - //to fix memory leak issue, match the handle count with native side. - global::System.IntPtr cPtr = NDalicPINVOKE.FrameBuffer_GetColorTexture(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - Texture ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Texture; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + Texture texture = new Texture(NDalicPINVOKE.FrameBuffer_GetColorTexture(swigCPtr), true); + Texture ret = Registry.GetManagedBaseHandleFromNativePtr(texture) as Texture; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/internal/ManualPINVOKE.cs b/src/Tizen.NUI/src/internal/ManualPINVOKE.cs index 71945bd..f4bc28d 100755 --- a/src/Tizen.NUI/src/internal/ManualPINVOKE.cs +++ b/src/Tizen.NUI/src/internal/ManualPINVOKE.cs @@ -1742,5 +1742,8 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_ImageView_IMAGE_VISUAL_ACTION_STOP_get")] public static extern int ImageView_IMAGE_VISUAL_ACTION_STOP_get(); + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_NUI_InternalAPIVersionCheck")] + public static extern bool InternalAPIVersionCheck(ref int ver1, ref int ver2, ref int ver3); + } } diff --git a/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs b/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs index 319265e..c80ae80 100755 --- a/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs +++ b/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs @@ -11514,5 +11514,5 @@ class NDalicPINVOKE { public static extern uint GetMaxTextureSize(); } -} +} diff --git a/src/Tizen.NUI/src/internal/Registry.cs b/src/Tizen.NUI/src/internal/Registry.cs index fc254b8..8f1f92f 100755 --- a/src/Tizen.NUI/src/internal/Registry.cs +++ b/src/Tizen.NUI/src/internal/Registry.cs @@ -16,7 +16,7 @@ */ using System; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Threading; namespace Tizen.NUI @@ -41,11 +41,11 @@ namespace Tizen.NUI /// Given a C++ object, the dictionary allows us to find which C# object it belongs to. /// By keeping the weak reference only, it will allow the object to be garbage collected. /// - private Dictionary _controlMap; + private ConcurrentDictionary _controlMap; private Registry() { - _controlMap = new Dictionary(); + _controlMap = new ConcurrentDictionary(); } @@ -55,16 +55,15 @@ namespace Tizen.NUI /// The instance of BaseHandle (C# base class). internal static void Register(BaseHandle baseHandle) { - // We store a pointer to the RefObject for the control RefObject refObj = baseHandle.GetObjectPtr(); IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj); - //NUILog.Debug("Storing ref object cptr in control map Hex: {0:X}" + refCptr); + RegistryCurrentThreadCheck(); - if (!Instance._controlMap.ContainsKey(refCptr)) + if(Instance._controlMap.TryAdd(refCptr, new WeakReference(baseHandle, false)) != true) { - Instance._controlMap.Add(refCptr, new WeakReference(baseHandle, false)); + NUILog.Debug("refCptr is already exist! OR something wrong!"); } return; @@ -79,9 +78,12 @@ namespace Tizen.NUI RefObject refObj = baseHandle.GetObjectPtr(); IntPtr refCptr = (IntPtr)RefObject.getCPtr(refObj); - if (Instance._controlMap.ContainsKey(refCptr)) + RegistryCurrentThreadCheck(); + + WeakReference removeTarget; + if(Instance._controlMap.TryRemove(refCptr, out removeTarget) != true) { - Instance._controlMap.Remove(refCptr); + NUILog.Debug("something wrong when removing refCptr!"); } return; @@ -92,42 +94,42 @@ namespace Tizen.NUI RefObject refObj = baseHandle.GetObjectPtr(); IntPtr refObjectPtr = (IntPtr)RefObject.getCPtr(refObj); - if (refObjectPtr != null) - { // we store a dictionary of ref-obects (C++ land) to managed obects (C# land) return GetManagedBaseHandleFromRefObject(refObjectPtr); } - else - { - NUILog.Error("NUI Registry RefObjectPtr is NULL!"); - return null; - } - } internal static BaseHandle GetManagedBaseHandleFromNativePtr(IntPtr cPtr) { IntPtr refObjectPtr = NDalicPINVOKE.GetRefObjectPtr(cPtr); - if (refObjectPtr != null) - { // we store a dictionary of ref-obects (C++ land) to managed obects (C# land) return GetManagedBaseHandleFromRefObject(refObjectPtr); } - else + + internal static BaseHandle GetManagedBaseHandleFromRefObject(IntPtr refObjectPtr) + { + if (refObjectPtr == global::System.IntPtr.Zero) { - NUILog.Error("NUI Registry RefObjectPtr is NULL!"); + NUILog.Debug("Registry refObjectPtr is NULL! This means bind native object is NULL!"); return null; } + else + { + NUILog.Debug($"refObjectPtr=0x{refObjectPtr.ToInt64():X}"); } - internal static BaseHandle GetManagedBaseHandleFromRefObject(IntPtr refObjectPtr) - { + RegistryCurrentThreadCheck(); + // we store a dictionary of ref-obects (C++ land) to managed obects (C# land) WeakReference weakReference; if (Instance._controlMap.TryGetValue(refObjectPtr, out weakReference)) { - if(weakReference == null) { throw new System.InvalidOperationException("Error! NUI Registry weakReference should not be NULL!"); } + if(weakReference == null) + { + throw new System.InvalidOperationException("Error! NUI Registry weakReference should not be NULL!"); + } + BaseHandle ret = weakReference.Target as BaseHandle; return ret; } @@ -150,5 +152,22 @@ namespace Tizen.NUI } } + private static void RegistryCurrentThreadCheck() + { + if(savedApplicationThread == null) + { + Tizen.Log.Fatal("NUI", $"Error! maybe main thread is created by other process "); + return; + } + int currentId = Thread.CurrentThread.ManagedThreadId; + int mainThreadId = savedApplicationThread.ManagedThreadId; + + if(currentId != mainThreadId) + { + Tizen.Log.Fatal("NUI", $"Error! current thread({currentId}) which is NOT main thread({mainThreadId}) utilizes NUI object!"); + } + } + + } } diff --git a/src/Tizen.NUI/src/internal/VersionCheck.cs b/src/Tizen.NUI/src/internal/VersionCheck.cs index 899f087..5c2d3fc 100755 --- a/src/Tizen.NUI/src/internal/VersionCheck.cs +++ b/src/Tizen.NUI/src/internal/VersionCheck.cs @@ -16,20 +16,17 @@ */ using System; +using System.Diagnostics; namespace Tizen.NUI { //This version should be updated and synced for every Dali native release internal static class Version { - public const int daliVer1 = 1; - public const int daliVer2 = 2; - public const int daliVer3 = 83; - public const int nuiVer1 = 1; - public const int nuiVer2 = 2; - public const int nuiVer3 = 83; - public const string nuiRelease = ""; - + //dali_1.3.xx : NUI internal API version 500 + public const int nuiAPIVer = 500; + public const int reservedVer1 = 0; + public const int reservedVer2 = 0; static internal bool DaliVersionMatchWithNUI() { @@ -39,27 +36,39 @@ namespace Tizen.NUI try { - if (NDalicManualPINVOKE.NativeVersionCheck(ref ver1, ref ver2, ref ver3)) + if (NDalicManualPINVOKE.InternalAPIVersionCheck(ref ver1, ref ver2, ref ver3) == true) { - if (ver1 != daliVer1 || ver2 != daliVer2 || ver3 != daliVer3) + if (ver1 != nuiAPIVer) { - NUILog.Error($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali= { ver1 }.{ ver2}.{ ver3}"); - throw new System.InvalidOperationException($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali={ ver1 }.{ ver2}.{ ver3}"); + NUILog.Error($"NUI API version mismatch error! NUI API Version: ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})"); + throw new System.InvalidOperationException($"NUI API version mismatch error! NUI API version should be ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})"); } } else { - NUILog.Error($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali= { ver1 }.{ ver2}.{ ver3}"); - throw new System.InvalidOperationException($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali={ ver1 }.{ ver2}.{ ver3}"); + NUILog.Error($"NUI API version mismatch error! NUI API Version: ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})"); + throw new System.InvalidOperationException($"NUI API version mismatch error! NUI API version should be ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})"); } } catch (Exception) { - NUILog.Error($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali= { ver1 }.{ ver2}.{ ver3}"); - throw new System.InvalidOperationException($"Dali native version mismatch error! nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3} but dali={ ver1 }.{ ver2}.{ ver3}"); + NUILog.Error($"NUI API version mismatch error! NUI API Version: ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})"); + throw new System.InvalidOperationException($"NUI API version mismatch error! NUI API version should be ({nuiAPIVer}) but read version from native: ({ver1}.{ver2}.{ver3})"); } - NUILog.Debug($"version info: nui={ nuiVer1}.{ nuiVer2}.{ nuiVer3}, dali= { ver1 }.{ ver2}.{ ver3}"); + + PrintDaliNativeVersion(); return true; } + + //[Conditional("DEBUG_ON")] + static private void PrintDaliNativeVersion() + { + int ver1 = -1; + int ver2 = -1; + int ver3 = -1; + + NDalicManualPINVOKE.NativeVersionCheck(ref ver1, ref ver2, ref ver3); + NUILog.Debug($"DALi Version: ({ver1}.{ver2}.{ver3}), NUI API Version: ({nuiAPIVer})"); + } } } diff --git a/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs b/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs index 3c009a6..e4071e4 100755 --- a/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs +++ b/src/Tizen.NUI/src/internal/ViewWrapperImpl.cs @@ -252,12 +252,8 @@ namespace Tizen.NUI public VisualBase GetVisual(int index) { - //to fix memory leak issue, match the handle count with native side. - System.IntPtr cPtr = NDalicManualPINVOKE.ViewWrapperImpl_GetVisual(swigCPtr, index); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - VisualBase ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as VisualBase; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + VisualBase visualBase = new VisualBase(NDalicManualPINVOKE.ViewWrapperImpl_GetVisual(swigCPtr, index), true); + VisualBase ret = Registry.GetManagedBaseHandleFromNativePtr(visualBase) as VisualBase; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/BaseComponents/TableView.cs b/src/Tizen.NUI/src/public/BaseComponents/TableView.cs index be2115c..a617586 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TableView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TableView.cs @@ -379,12 +379,8 @@ namespace Tizen.NUI.BaseComponents /// 3 public View GetChildAt(TableView.CellPosition position) { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.TableView_GetChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.TableView_GetChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -398,12 +394,8 @@ namespace Tizen.NUI.BaseComponents /// 3 public View RemoveChildAt(TableView.CellPosition position) { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.TableView_RemoveChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.TableView_RemoveChildAt(swigCPtr, TableView.CellPosition.getCPtr(position)), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 2745def..fb208c5 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -38,6 +38,11 @@ namespace Tizen.NUI.BaseComponents } } + internal View(global::System.IntPtr cPtr, bool cMemoryOwn, bool ignore) : base(NDalicPINVOKE.View_SWIGUpcast(cPtr), cMemoryOwn) + { + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(View obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; @@ -63,6 +68,7 @@ namespace Tizen.NUI.BaseComponents if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); Children.Add(child); + child.SetParent(this); } } @@ -78,6 +84,7 @@ namespace Tizen.NUI.BaseComponents throw NDalicPINVOKE.SWIGPendingException.Retrieve(); Children.Remove(child); + child.SetParent(null); } /// @@ -114,17 +121,7 @@ namespace Tizen.NUI.BaseComponents /// 4 protected override Container GetParent() { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle); - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); - - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - - return basehandle as Container; + return Parent; } internal bool IsTopLevelView() @@ -2559,12 +2556,8 @@ namespace Tizen.NUI.BaseComponents /// 5 public Layer GetLayer() { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Actor_GetLayer(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - Layer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Layer; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + Layer layer = new Layer(NDalicPINVOKE.Actor_GetLayer(swigCPtr), true); + Layer ret = Registry.GetManagedBaseHandleFromNativePtr(layer) as Layer; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2591,12 +2584,8 @@ namespace Tizen.NUI.BaseComponents /// 3 public View FindChildByName(string viewName) { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Actor_FindChildByName(swigCPtr, viewName); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.Actor_FindChildByName(swigCPtr, viewName), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -2605,12 +2594,8 @@ namespace Tizen.NUI.BaseComponents internal View FindChildById(uint id) { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.Actor_FindChildById(swigCPtr, id), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); @@ -3204,12 +3189,8 @@ namespace Tizen.NUI.BaseComponents /// 3 public Renderer GetRendererAt(uint index) { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Actor_GetRendererAt(swigCPtr, index); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as Renderer; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + Renderer renderer = new Renderer(NDalicPINVOKE.Actor_GetRendererAt(swigCPtr, index), true); + Renderer ret = Registry.GetManagedBaseHandleFromNativePtr(renderer) as Renderer; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); diff --git a/src/Tizen.NUI/src/public/Container.cs b/src/Tizen.NUI/src/public/Container.cs index b7d8514..6bb48c6 100755 --- a/src/Tizen.NUI/src/public/Container.cs +++ b/src/Tizen.NUI/src/public/Container.cs @@ -30,6 +30,7 @@ namespace Tizen.NUI { private List _childViews = new List(); + private Container _parent = null; /// /// List of children of Container. @@ -62,6 +63,10 @@ namespace Tizen.NUI base.Dispose(type); } + /// + /// This should be implemented in derived child classes such as View and Layer + /// + /// parent object of mine, which will be Container class protected abstract Container GetParent(); /// @@ -110,10 +115,15 @@ namespace Tizen.NUI { get { - return GetParent(); + return _parent; } } + internal void SetParent(Container parent) + { + _parent = parent; + } + /// /// Gets the number of children for this container. /// Read only diff --git a/src/Tizen.NUI/src/public/FocusManager.cs b/src/Tizen.NUI/src/public/FocusManager.cs index 7cffacb..744f64d 100755 --- a/src/Tizen.NUI/src/public/FocusManager.cs +++ b/src/Tizen.NUI/src/public/FocusManager.cs @@ -449,12 +449,8 @@ namespace Tizen.NUI /// 3 public View GetCurrentFocusView() { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; return ret; } @@ -557,12 +553,8 @@ namespace Tizen.NUI /// 3 public View GetFocusGroup(View view) { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View localView = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(localView) as View; return ret; } @@ -592,12 +584,8 @@ namespace Tizen.NUI internal View GetFocusIndicatorView() { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; return ret; } diff --git a/src/Tizen.NUI/src/public/Layer.cs b/src/Tizen.NUI/src/public/Layer.cs index 4e31810..f2b9730 100755 --- a/src/Tizen.NUI/src/public/Layer.cs +++ b/src/Tizen.NUI/src/public/Layer.cs @@ -61,6 +61,7 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); Children.Add(child); + child.SetParent(this); } } @@ -77,6 +78,7 @@ namespace Tizen.NUI throw NDalicPINVOKE.SWIGPendingException.Retrieve(); Children.Remove(child); + child.SetParent(null); } /// @@ -98,6 +100,10 @@ namespace Tizen.NUI } } + /// + /// protected override method derived from Container abstract parent class + /// + /// always return null, because in NUI, Layer can be added under Window protected override Container GetParent() { return null; @@ -191,12 +197,8 @@ namespace Tizen.NUI /// 3 public View FindChildById(uint id) { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Actor_FindChildById(swigCPtr, id); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.Actor_FindChildById(swigCPtr, id), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); diff --git a/src/Tizen.NUI/src/public/UIComponents/Popup.cs b/src/Tizen.NUI/src/public/UIComponents/Popup.cs index 1a557ee..b8a65ed 100755 --- a/src/Tizen.NUI/src/public/UIComponents/Popup.cs +++ b/src/Tizen.NUI/src/public/UIComponents/Popup.cs @@ -405,12 +405,8 @@ namespace Tizen.NUI.UIComponents internal View GetTitle() { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Popup_GetTitle(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.Popup_GetTitle(swigCPtr), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -429,12 +425,8 @@ namespace Tizen.NUI.UIComponents internal View GetContent() { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Popup_GetContent(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.Popup_GetContent(swigCPtr), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; @@ -453,12 +445,8 @@ namespace Tizen.NUI.UIComponents internal View GetFooter() { - //to fix memory leak issue, match the handle count with native side. - IntPtr cPtr = NDalicPINVOKE.Popup_GetFooter(swigCPtr); - HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; - NDalicPINVOKE.delete_BaseHandle(CPtr); - CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + View view = new View(NDalicPINVOKE.Popup_GetFooter(swigCPtr), true, true); + View ret = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; diff --git a/src/Tizen.NUI/src/public/Window.cs b/src/Tizen.NUI/src/public/Window.cs index cb44337..81d4628 100755 --- a/src/Tizen.NUI/src/public/Window.cs +++ b/src/Tizen.NUI/src/public/Window.cs @@ -1398,7 +1398,8 @@ namespace Tizen.NUI /// /// Whether the window is transparent. /// 5 - public void SetTransparency(bool transparent) { + public void SetTransparency(bool transparent) + { NDalicManualPINVOKE.SetTransparency(swigCPtr, transparent); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } -- 2.7.4