2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "relayout-controller.h"
21 #include "relayout-controller-impl.h"
27 #include <dali/integration-api/debug.h>
31 #include "dali-toolkit/public-api/controls/control.h"
32 #include "dali-toolkit/public-api/controls/control-impl.h"
33 #include "dali-toolkit/public-api/controls/text-view/text-view.h"
46 // Flag to avoid doing more than one request per frame
47 // getting the singleton handle can be expensive as it requires calling to adaptor, dynamic cast etc
48 // and it can get called 100 times per frame easily in startup and new view initialization
49 bool gRelayoutRequestPending = false;
52 RelayoutController::RelayoutController()
57 RelayoutController::~RelayoutController()
62 void RelayoutController::Request()
64 // are we already going to do it this frame
65 if( !gRelayoutRequestPending )
67 RelayoutController controller;
69 // Check whether the RelayoutController is already created
70 SingletonService singletonService( SingletonService::Get() );
71 if ( singletonService )
73 Dali::BaseHandle handle = singletonService.GetSingleton(typeid(RelayoutController));
77 // If so, downcast the handle of singleton to RelayoutController
78 controller = RelayoutController(dynamic_cast<Internal::RelayoutControllerImpl*>(handle.GetObjectPtr()));
83 // If not, create the RelayoutController and register it as a singleton
84 controller = RelayoutController( new Internal::RelayoutControllerImpl(gRelayoutRequestPending) );
85 singletonService.Register( typeid(controller), controller );
88 GetImpl(controller).Request();
89 gRelayoutRequestPending = true;
94 RelayoutController::RelayoutController(Internal::RelayoutControllerImpl *impl)
99 } // namespace Internal
101 } // namespace Toolkit