2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiAnim_DisplayManager.cpp
20 * @brief This file contains implementation of _DisplayManager class
22 * This file contains implementation _DisplayManager class.
26 #include <FBaseSysLog.h>
27 #include "FUiAnim_NativeLayer.h"
28 #include "FUiAnim_RootVisualElement.h"
29 #include "FUiAnim_VisualElementImpl.h"
30 #include "FUiAnim_VisualElementEnvironment.h"
31 #include "FUiAnim_AnimationManager.h"
32 #include "FUiAnim_DisplayManager.h"
34 using namespace Tizen;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Ui::Animations;
43 WakeupEventCallback(void* pData, int type, void* pEvent)
45 _DisplayManager::__wakeUpEventAdded = false;
47 return ECORE_CALLBACK_PASS_ON;
52 namespace Tizen { namespace Ui { namespace Animations
54 int _DisplayManager::__eventType = 0;
55 void* _DisplayManager::__pWakeUpEventHandler = null;
56 bool _DisplayManager::__wakeUpEventAdded = false;
57 _DisplayManager* _DisplayManager::__pInstance = null;
59 _DisplayManager::_DisplayManager(void)
65 _DisplayManager::~_DisplayManager(void)
67 while (__roots.GetCount() > 0)
69 _RootVisualElement* pRoot = static_cast< _RootVisualElement* >(__roots.GetAt(0));
77 _DisplayManager::CreateInstance(void)
79 SysTryReturnResult(NID_UI_ANIM, !__pInstance, E_OBJ_ALREADY_EXIST, "The display manager is already created.");
81 __pInstance = new (std::nothrow) _DisplayManager();
84 return E_OUT_OF_MEMORY;
87 _VisualElementEnvironment::Initialize();
90 __eventType = ecore_event_type_new();
91 __pWakeUpEventHandler = (void*)ecore_event_handler_add(__eventType, WakeupEventCallback, null);
97 _DisplayManager::ReleaseInstance(void)
99 SysTryReturnResult(NID_UI_ANIM, __pInstance, E_INVALID_STATE, "The display manager is not created.");
101 if (__pWakeUpEventHandler)
103 ecore_event_handler_del((Ecore_Event_Handler*)__pWakeUpEventHandler);
113 _DisplayManager::CreateRoot(void)
115 _RootVisualElement* pRoot = new (std::nothrow) _RootVisualElement();
122 pRoot->SetImplicitAnimationEnabled(false);
123 pRoot->SetShowState(true);
125 RegisterRoot(*pRoot);
131 _DisplayManager::DestroyRoot(_RootVisualElement& root)
133 result r = UnregisterRoot(root);
137 SysLogException(NID_UI_ANIM, E_INVALID_ARG, "[E_INVALID_ARG] root is not managed in the DisplayManager" );
146 _DisplayManager::RegisterRoot(_RootVisualElement& root)
148 return __roots.Add(root);
152 _DisplayManager::UnregisterRoot(_RootVisualElement& root)
154 return __roots.Remove(root);
158 _DisplayManager::GetRootCount(void) const
160 return __roots.GetCount();
164 _DisplayManager::GetRoot(int index) const
166 const _RootVisualElement* pRoot = static_cast< const _RootVisualElement* >(__roots.GetAt(index));
167 return const_cast< _RootVisualElement* >(pRoot);
171 _DisplayManager::AddWakeUpEvent(void)
173 if (!__wakeUpEventAdded)
175 ecore_event_add(__eventType, NULL, NULL, NULL);
176 __wakeUpEventAdded = true;
181 _DisplayManager::RenderAll(void)
183 bool needUpdate = false;
184 int count = __roots.GetCount();
187 for (int i = 0; i < count; i++)
189 _RootVisualElement* pRoot = static_cast< _RootVisualElement* >(__roots.GetAt(i));
192 bool updated = Render(*pRoot);
194 needUpdate |= updated;
198 _NativeLayer* pLayer = pRoot->GetNativeLayer();
201 pLayer->SetFlushNeeded();
214 _DisplayManager::Render(_RootVisualElement& root)
216 // VisualElement Rendering
219 // Prevent recursion for rendering !
223 // if the contents of evas object image is changed with geometry change,
224 // damage area is not calculated correctly !!! when event freeze/thaw enabled.
225 // --> artifact occurs
227 //evas_event_freeze(__pEvas);
229 bool updated = false;
231 _RootVisualElement* pPresentationRoot = static_cast< _RootVisualElement* >(const_cast<VisualElement*>(root.AcquirePresentationInstance()));
232 if (pPresentationRoot)
234 _VisualElementImpl* pRootModelImpl = _VisualElementImpl::GetInstance(root);
235 _VisualElementImpl* pRootPresentationImpl = _VisualElementImpl::GetInstance(*pPresentationRoot);
237 if (likely(pRootModelImpl) && likely(pRootPresentationImpl))
239 //-------------------;
241 if (//likely((pRootModelImpl->__childrenNeedsUpdateProps) != 0) ||
242 likely(pRootPresentationImpl->__childrenNeedsUpdateProps != 0) ||
243 likely(pRootPresentationImpl->__pSharedData->NeedNativeReconfigure()) ||
244 unlikely(root.GetNeedsContentUpdate()) ||
245 unlikely(pPresentationRoot->GetNeedsContentUpdate()))
247 root.SetNeedsContentUpdate(false);
248 pRootModelImpl->Draw();
250 pPresentationRoot->SetNeedsContentUpdate(false);
251 pRootPresentationImpl->Draw();
257 root.ReleasePresentationInstance();
260 //evas_event_thaw(__pEvas);
261 //evas_event_thaw_eval(__pEvas); // CHECKME: needed ???
267 _DisplayManager::PostRender(_RootVisualElement& root)
269 // _ElapsedTime foo("PostRender");
272 _RootVisualElement* pPresentationRoot = static_cast< _RootVisualElement* >(const_cast<VisualElement*>(root.AcquirePresentationInstance()));
273 if (likely(pPresentationRoot))
275 _VisualElementImpl* pRootPresentationImpl = _VisualElementImpl::GetInstance(*pPresentationRoot);
278 if (likely((pRootPresentationImpl->__childrenNeedsUpdateProps & ~_VisualElementImpl::HIERARCHY_PROPERTY_CONTENT) != 0) ||
280 if (likely(pRootPresentationImpl->__childrenNeedsUpdateProps) ||
282 likely(pRootPresentationImpl->__pSharedData->NeedNativeReconfigure()) ||
283 unlikely(root.GetNeedsContentUpdate()) ||
284 unlikely(pPresentationRoot->GetNeedsContentUpdate()))
287 // We need wake-up main-loop for VE to be validated(draw) on next loop iteration.
288 // Is there another good method for this???
293 root.ReleasePresentationInstance();
299 _DisplayManager::Flush(void)
301 int count = __roots.GetCount();
304 for (int i = 0; i < count; i++)
306 _RootVisualElement* pRoot = static_cast< _RootVisualElement* >(__roots.GetAt(i));
309 _NativeLayer* pLayer = pRoot->GetNativeLayer();
311 //CHECK ME : when evas marked update flag.
312 // if (pLayer && pLayer->IsFlushNeeded())
315 pLayer->ResetFlushNeeded();
327 }}} // Tizen::Ui::Animations