Temporary Fix to return the Layer as a View when Parent is a Layer.
authorUmar <m.umar@partner.samsung.com>
Tue, 18 Jul 2017 13:28:43 +0000 (14:28 +0100)
committerUmar <m.umar@partner.samsung.com>
Thu, 20 Jul 2017 13:30:48 +0000 (14:30 +0100)
There are three different changes in this patch.
  1: Creating and Returning View if it was a Layer.
  2: Don't register (and unregister) managed object if it is a duplicate copy of existing ref object.
  3: Avoid creating RootLayer managed object multiple times by having global variable in Window class.

Change-Id: I0e0805dd542bbae3f32d7e047bc7792ec37e1d79

src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseHandle.cs
src/Tizen.NUI/src/public/Window.cs

index a36ae38..3674f50 100755 (executable)
@@ -2117,9 +2117,19 @@ namespace Tizen.NUI.BaseComponents
 
         internal View GetParent()
         {
+            View ret;
             IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr);
 
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
+            BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(cPtr);
+
+            if(basehandle is Layer)
+            {
+                ret = new View(cPtr,false);
+            }
+            else
+            {
+                ret = basehandle as View;
+            }
 
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
index d14f943..e0d7ecc 100755 (executable)
@@ -21,22 +21,26 @@ namespace Tizen.NUI
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
         protected bool swigCMemOwn;
+        private bool _registerMe;
 
         internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
         {
-            swigCMemOwn = cMemoryOwn;
+            _registerMe = swigCMemOwn = cMemoryOwn;
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
 
             // using copy constructor to create another native handle so Registry.Unregister works fine.
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
 
-            // Register this instance of BaseHandle in the registry.
-            Registry.Register(this);
+            if (_registerMe)
+            {
+                // Register this instance of BaseHandle in the registry.
+                Registry.Register(this);
+            }
         }
 
         internal BaseHandle(global::System.IntPtr cPtr)
         {
-            swigCMemOwn = true;
+            _registerMe = swigCMemOwn = true;
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
 
             // Register this instance of BaseHandle in the registry.
@@ -101,7 +105,10 @@ namespace Tizen.NUI
             //because the execution order of Finalizes is non-deterministic.
 
             //Unreference this instance from Registry.
-            Registry.Unregister(this);
+            if (_registerMe)
+            {
+                Registry.Unregister(this);
+            }
 
             if (swigCPtr.Handle != global::System.IntPtr.Zero)
             {
index 95cdedf..793e1a5 100755 (executable)
@@ -29,6 +29,7 @@ namespace Tizen.NUI
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
         private global::System.Runtime.InteropServices.HandleRef stageCPtr;
+        private Layer _rootLayer;
 
         internal Window(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Window_SWIGUpcast(cPtr), cMemoryOwn)
         {
@@ -564,9 +565,12 @@ namespace Tizen.NUI
 
         internal Layer GetRootLayer()
         {
-            Layer ret = new Layer(NDalicPINVOKE.Stage_GetRootLayer(stageCPtr), true);
+            if (_rootLayer == null)
+                _rootLayer = new Layer(NDalicPINVOKE.Stage_GetRootLayer(stageCPtr), true);
+
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+            return _rootLayer;
         }
 
         internal void SetBackgroundColor(Vector4 color)