2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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;
58 _DisplayManager::RestoreContextCallback _DisplayManager::__pRestoreContextCallback = null;
60 _DisplayManager::_DisplayManager(void)
66 _DisplayManager::~_DisplayManager(void)
68 while (__roots.GetCount() > 0)
70 _RootVisualElement* pRoot = static_cast< _RootVisualElement* >(__roots.GetAt(0));
78 _DisplayManager::CreateInstance(void)
80 SysTryReturnResult(NID_UI_ANIM, !__pInstance, E_OBJ_ALREADY_EXIST, "The display manager is already created.");
82 __pInstance = new (std::nothrow) _DisplayManager();
85 return E_OUT_OF_MEMORY;
88 _VisualElementEnvironment::Initialize();
91 __eventType = ecore_event_type_new();
92 __pWakeUpEventHandler = (void*)ecore_event_handler_add(__eventType, WakeupEventCallback, null);
98 _DisplayManager::ReleaseInstance(void)
100 SysTryReturnResult(NID_UI_ANIM, __pInstance, E_INVALID_STATE, "The display manager is not created.");
102 if (__pWakeUpEventHandler)
104 ecore_event_handler_del((Ecore_Event_Handler*)__pWakeUpEventHandler);
114 _DisplayManager::CreateRoot(void)
116 _RootVisualElement* pRoot = new (std::nothrow) _RootVisualElement();
123 pRoot->SetImplicitAnimationEnabled(false);
124 pRoot->SetShowState(true);
126 RegisterRoot(*pRoot);
132 _DisplayManager::DestroyRoot(_RootVisualElement& root)
134 result r = UnregisterRoot(root);
138 SysLogException(NID_UI_ANIM, E_INVALID_ARG, "[E_INVALID_ARG] root is not managed in the DisplayManager" );
147 _DisplayManager::RegisterRoot(_RootVisualElement& root)
149 return __roots.Add(root);
153 _DisplayManager::UnregisterRoot(_RootVisualElement& root)
155 return __roots.Remove(root);
159 _DisplayManager::GetRootCount(void) const
161 return __roots.GetCount();
165 _DisplayManager::GetRoot(int index) const
167 const _RootVisualElement* pRoot = static_cast< const _RootVisualElement* >(__roots.GetAt(index));
168 return const_cast< _RootVisualElement* >(pRoot);
172 _DisplayManager::AddWakeUpEvent(void)
174 if (!__wakeUpEventAdded)
176 ecore_event_add(__eventType, NULL, NULL, NULL);
177 __wakeUpEventAdded = true;
182 _DisplayManager::RenderAll(void)
184 bool needUpdate = false;
185 int count = __roots.GetCount();
188 for (int i = 0; i < count; i++)
190 _RootVisualElement* pRoot = static_cast< _RootVisualElement* >(__roots.GetAt(i));
193 bool updated = Render(*pRoot);
195 needUpdate |= updated;
199 _NativeLayer* pLayer = pRoot->GetNativeLayer();
202 pLayer->SetFlushNeeded();
215 _DisplayManager::Render(_RootVisualElement& root)
217 // VisualElement Rendering
220 // Prevent recursion for rendering !
224 // if the contents of evas object image is changed with geometry change,
225 // damage area is not calculated correctly !!! when event freeze/thaw enabled.
226 // --> artifact occurs
228 //evas_event_freeze(__pEvas);
230 bool updated = false;
232 _RootVisualElement* pPresentationRoot = static_cast< _RootVisualElement* >(const_cast<VisualElement*>(root.AcquirePresentationInstance()));
233 if (pPresentationRoot)
235 _VisualElementImpl* pRootModelImpl = _VisualElementImpl::GetInstance(root);
236 _VisualElementImpl* pRootPresentationImpl = _VisualElementImpl::GetInstance(*pPresentationRoot);
238 if (likely(pRootModelImpl) && likely(pRootPresentationImpl))
240 //-------------------;
242 if (//likely((pRootModelImpl->__childrenNeedsUpdateProps) != 0) ||
243 likely(pRootPresentationImpl->__childrenNeedsUpdateProps != 0) ||
244 likely(pRootPresentationImpl->__pSharedData->NeedNativeReconfigure()) ||
245 unlikely(root.GetNeedsContentUpdate()) ||
246 unlikely(pPresentationRoot->GetNeedsContentUpdate()))
248 root.SetNeedsContentUpdate(false);
249 pRootModelImpl->Draw();
251 pPresentationRoot->SetNeedsContentUpdate(false);
252 pRootPresentationImpl->Draw();
258 root.ReleasePresentationInstance();
261 //evas_event_thaw(__pEvas);
262 //evas_event_thaw_eval(__pEvas); // CHECKME: needed ???
268 _DisplayManager::PostRender(_RootVisualElement& root)
270 // _ElapsedTime foo("PostRender");
273 _RootVisualElement* pPresentationRoot = static_cast< _RootVisualElement* >(const_cast<VisualElement*>(root.AcquirePresentationInstance()));
274 if (likely(pPresentationRoot))
276 _VisualElementImpl* pRootPresentationImpl = _VisualElementImpl::GetInstance(*pPresentationRoot);
278 if (likely(pRootPresentationImpl->__childrenNeedsUpdateProps) ||
279 likely(pRootPresentationImpl->__pSharedData->NeedNativeReconfigure()) ||
280 unlikely(root.GetNeedsContentUpdate()) ||
281 unlikely(pPresentationRoot->GetNeedsContentUpdate()))
284 // We need wake-up main-loop for VE to be validated(draw) on next loop iteration.
285 // Is there another good method for this???
290 root.ReleasePresentationInstance();
296 _DisplayManager::Flush(void)
298 int count = __roots.GetCount();
301 for (int i = 0; i < count; i++)
303 _RootVisualElement* pRoot = static_cast< _RootVisualElement* >(__roots.GetAt(i));
306 _NativeLayer* pLayer = pRoot->GetNativeLayer();
308 //CHECK ME : when evas marked update flag.
309 // if (pLayer && pLayer->IsFlushNeeded())
312 pLayer->ResetFlushNeeded();
322 _DisplayManager::SetRestoreContextCallback(RestoreContextCallback pRestoreContextCallback)
324 __pRestoreContextCallback = pRestoreContextCallback;
328 _DisplayManager::RestoreContext(void)
330 if (__pRestoreContextCallback)
332 (*__pRestoreContextCallback)();
336 }}} // Tizen::Ui::Animations