(Builder) Ensure properties are not applied twice
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / relayout-controller.cpp
index 834ab27..8dce13a 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // FILE HEADER
 
@@ -21,7 +22,6 @@
 
 // EXTERNAL INCLUDES
 
-#include <boost/thread/tss.hpp>
 #include <stack>
 #include <sstream>
 #include <dali/integration-api/debug.h>
@@ -41,6 +41,14 @@ namespace Toolkit
 namespace Internal
 {
 
+namespace
+{
+// Flag to avoid doing more than one request per frame
+// getting the singleton handle can be expensive as it requires calling to adaptor, dynamic cast etc
+// and it can get called 100 times per frame easily in startup and new view initialization
+  bool gRelayoutRequestPending = false;
+}
+
 RelayoutController::RelayoutController()
 {
 
@@ -51,28 +59,33 @@ RelayoutController::~RelayoutController()
 
 }
 
-RelayoutController RelayoutController::Get()
+void RelayoutController::Request()
 {
-  RelayoutController controller;
-
-  // Check whether the RelayoutController is already created
-  Dali::Adaptor& adaptor = Dali::Adaptor::Get();
-  Dali::BaseHandle handle = adaptor.GetSingleton(typeid(RelayoutController));
-
-  if(handle)
+  // are we already going to do it this frame
+  if( !gRelayoutRequestPending )
   {
-    // If so, downcast the handle of singleton to RelayoutController
-    controller = RelayoutController(dynamic_cast<Internal::RelayoutControllerImpl*>(handle.GetObjectPtr()));
+    RelayoutController controller;
+
+    // Check whether the RelayoutController is already created
+    Dali::Adaptor& adaptor = Dali::Adaptor::Get();
+    Dali::BaseHandle handle = adaptor.GetSingleton(typeid(RelayoutController));
+
+    if(handle)
+    {
+      // If so, downcast the handle of singleton to RelayoutController
+      controller = RelayoutController(dynamic_cast<Internal::RelayoutControllerImpl*>(handle.GetObjectPtr()));
+    }
+
+    if(!controller)
+    {
+      // If not, create the RelayoutController and register it as a singleton
+      controller = RelayoutController( new Internal::RelayoutControllerImpl(gRelayoutRequestPending) );
+      adaptor.RegisterSingleton( typeid(controller), controller );
+    }
+
+    GetImpl(controller).Request();
+    gRelayoutRequestPending = true;
   }
-
-  if(!controller)
-  {
-    // If not, create the RelayoutController and register it as a singleton
-    controller = RelayoutController(new Internal::RelayoutControllerImpl());
-    adaptor.RegisterSingleton(typeid(controller), controller);
-  }
-
-  return controller;
 }
 
 RelayoutController::RelayoutController(Internal::RelayoutControllerImpl *impl)
@@ -80,12 +93,6 @@ RelayoutController::RelayoutController(Internal::RelayoutControllerImpl *impl)
 {
 }
 
-void RelayoutController::Request()
-{
-  GetImpl(*this).Request();
-}
-
-
 } // namespace Internal
 
 } // namespace Toolkit