- // 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;