X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=base%2Fdali-toolkit%2Finternal%2Fcontrols%2Frelayout-controller.cpp;h=8dce13a5ad25203f23fd89afec4cf87c730e6767;hp=d3c3ae90067abe3f3ce33c1e8cebcd8f49fca0bd;hb=fba034a17645832eecc1ac8544de26add0745a39;hpb=7ff9fed1e67a2ebc021a3c07b8a368489e2420db diff --git a/base/dali-toolkit/internal/controls/relayout-controller.cpp b/base/dali-toolkit/internal/controls/relayout-controller.cpp index d3c3ae9..8dce13a 100644 --- a/base/dali-toolkit/internal/controls/relayout-controller.cpp +++ b/base/dali-toolkit/internal/controls/relayout-controller.cpp @@ -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 @@ -40,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() { @@ -50,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(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(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) @@ -79,12 +93,6 @@ RelayoutController::RelayoutController(Internal::RelayoutControllerImpl *impl) { } -void RelayoutController::Request() -{ - GetImpl(*this).Request(); -} - - } // namespace Internal } // namespace Toolkit