Merge "Reset gPreInitializedApplication to reduce reference count" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/window-system/common/window-impl.h>
20
21 // EXTERNAL HEADERS
22 #include <dali/devel-api/adaptor-framework/orientation.h>
23 #include <dali/integration-api/core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/window-enumerations.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/public-api/rendering/frame-buffer.h>
32 #include <thread>
33
34 // INTERNAL HEADERS
35 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
36 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
37 #include <dali/internal/graphics/gles/egl-graphics.h>
38 #include <dali/internal/window-system/common/event-handler.h>
39 #include <dali/internal/window-system/common/orientation-impl.h>
40 #include <dali/internal/window-system/common/render-surface-factory.h>
41 #include <dali/internal/window-system/common/window-base.h>
42 #include <dali/internal/window-system/common/window-factory.h>
43 #include <dali/internal/window-system/common/window-render-surface.h>
44 #include <dali/internal/window-system/common/window-system.h>
45 #include <dali/internal/window-system/common/window-visibility-observer.h>
46
47 namespace Dali
48 {
49 namespace Internal
50 {
51 namespace Adaptor
52 {
53 namespace
54 {
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
57 #endif
58
59 } // unnamed namespace
60
61 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
62 {
63   Any surface;
64   return Window::New(surface, positionSize, name, className, type, isTransparent);
65 }
66
67 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
68 {
69   Window* window         = new Window();
70   window->mIsTransparent = isTransparent;
71   window->Initialize(surface, positionSize, name, className, type);
72   return window;
73 }
74
75 Window::Window()
76 : mWindowSurface(nullptr),
77   mWindowBase(),
78   mIsTransparent(false),
79   mIsFocusAcceptable(true),
80   mIconified(false),
81   mOpaqueState(false),
82   mWindowRotationAcknowledgement(false),
83   mParentWindow(NULL),
84   mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
85   mRotationAngle(0),
86   mWindowWidth(0),
87   mWindowHeight(0),
88   mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
89   mNativeWindowId(-1),
90   mDeleteRequestSignal(),
91   mFocusChangeSignal(),
92   mResizeSignal(),
93   mVisibilityChangedSignal(),
94   mTransitionEffectEventSignal(),
95   mKeyboardRepeatSettingsChangedSignal()
96 {
97 }
98
99 Window::~Window()
100 {
101   if(mAdaptor)
102   {
103     auto bridge     = Accessibility::Bridge::GetCurrentBridge();
104     auto rootLayer  = mScene.GetRootLayer();
105     auto accessible = Accessibility::Accessible::Get(rootLayer);
106     bridge->RemoveTopLevelWindow(accessible);
107
108     mAdaptor->RemoveWindow(this);
109   }
110
111   if(mEventHandler)
112   {
113     mEventHandler->RemoveObserver(*this);
114   }
115 }
116
117 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
118 {
119   // Create a window render surface
120   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
121   mSurface                  = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
122   mWindowSurface            = static_cast<WindowRenderSurface*>(mSurface.get());
123
124   // Get a window base
125   mWindowBase = mWindowSurface->GetWindowBase();
126
127   // Set Window Type
128   mWindowBase->SetType(type);
129
130   // Initialize for Ime window type
131   if(type == WindowType::IME)
132   {
133     mWindowBase->InitializeIme();
134     mWindowSurface->InitializeImeSurface();
135   }
136
137   // Connect signals
138   mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
139   mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
140   mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
141   mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
142   mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
143   mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
144   mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
145
146   mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
147
148   AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
149
150   SetClass(name, className);
151
152   mOrientation = Orientation::New(this);
153
154   // Get OrientationMode
155   int screenWidth, screenHeight;
156   WindowSystem::GetScreenSize(screenWidth, screenHeight);
157   if(screenWidth > screenHeight)
158   {
159     mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
160   }
161   else
162   {
163     mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
164   }
165   // For Debugging
166   mNativeWindowId = mWindowBase->GetNativeWindowId();
167 }
168
169 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
170 {
171   mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
172   mEventHandler->AddObserver(*this);
173
174   auto bridge     = Accessibility::Bridge::GetCurrentBridge();
175   auto rootLayer  = mScene.GetRootLayer();
176   auto accessible = Accessibility::Accessible::Get(rootLayer, true);
177   bridge->AddTopLevelWindow(accessible);
178
179   // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
180   // The show must be called after the adaptor is initialized.
181   Show();
182 }
183
184 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
185 {
186   mWindowSurface = static_cast<WindowRenderSurface*>(surface);
187 }
188
189 void Window::SetClass(std::string name, std::string className)
190 {
191   mName      = name;
192   mClassName = className;
193   mWindowBase->SetClass(name, className);
194 }
195
196 std::string Window::GetClassName() const
197 {
198   return mClassName;
199 }
200
201 void Window::Raise()
202 {
203   mWindowBase->Raise();
204
205   mSurface->SetFullSwapNextFrame();
206
207   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
208 }
209
210 void Window::Lower()
211 {
212   mWindowBase->Lower();
213
214   mSurface->SetFullSwapNextFrame();
215
216   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
217 }
218
219 void Window::Activate()
220 {
221   mWindowBase->Activate();
222
223   mSurface->SetFullSwapNextFrame();
224
225   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
226 }
227
228 uint32_t Window::GetLayerCount() const
229 {
230   return mScene.GetLayerCount();
231 }
232
233 Dali::Layer Window::GetLayer(uint32_t depth) const
234 {
235   return mScene.GetLayer(depth);
236 }
237
238 Dali::RenderTaskList Window::GetRenderTaskList() const
239 {
240   return mScene.GetRenderTaskList();
241 }
242
243 void Window::AddAvailableOrientation(WindowOrientation orientation)
244 {
245   if(IsOrientationAvailable(orientation) == false)
246   {
247     return;
248   }
249
250   bool found          = false;
251   int  convertedAngle = ConvertToAngle(orientation);
252   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
253   for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
254   {
255     if(mAvailableAngles[i] == convertedAngle)
256     {
257       found = true;
258       break;
259     }
260   }
261
262   if(!found)
263   {
264     mAvailableAngles.push_back(convertedAngle);
265     SetAvailableAnlges(mAvailableAngles);
266   }
267 }
268
269 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
270 {
271   if(IsOrientationAvailable(orientation) == false)
272   {
273     return;
274   }
275
276   int convertedAngle = ConvertToAngle(orientation);
277   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
278   for(std::vector<int>::iterator iter = mAvailableAngles.begin();
279       iter != mAvailableAngles.end();
280       ++iter)
281   {
282     if(*iter == convertedAngle)
283     {
284       mAvailableAngles.erase(iter);
285       break;
286     }
287   }
288
289   SetAvailableAnlges(mAvailableAngles);
290 }
291
292 void Window::SetPreferredOrientation(WindowOrientation orientation)
293 {
294   if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
295   {
296     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
297     return;
298   }
299   mPreferredAngle = ConvertToAngle(orientation);
300   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
301   mWindowBase->SetPreferredAngle(mPreferredAngle);
302 }
303
304 WindowOrientation Window::GetPreferredOrientation()
305 {
306   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
307   WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
308   return preferredOrientation;
309 }
310
311 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
312 {
313   int angle = ConvertToAngle(orientation);
314   mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
315 }
316
317 void Window::SetAvailableAnlges(const std::vector<int>& angles)
318 {
319   if(angles.size() > 4)
320   {
321     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
322     return;
323   }
324
325   mWindowBase->SetAvailableAnlges(angles);
326 }
327
328 int Window::ConvertToAngle(WindowOrientation orientation)
329 {
330   int convertAngle = static_cast<int>(orientation);
331   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
332   {
333     switch(orientation)
334     {
335       case WindowOrientation::LANDSCAPE:
336       {
337         convertAngle = 0;
338         break;
339       }
340       case WindowOrientation::PORTRAIT:
341       {
342         convertAngle = 90;
343         break;
344       }
345       case WindowOrientation::LANDSCAPE_INVERSE:
346       {
347         convertAngle = 180;
348         break;
349       }
350       case WindowOrientation::PORTRAIT_INVERSE:
351       {
352         convertAngle = 270;
353         break;
354       }
355       case WindowOrientation::NO_ORIENTATION_PREFERENCE:
356       {
357         convertAngle = -1;
358         break;
359       }
360     }
361   }
362   return convertAngle;
363 }
364
365 WindowOrientation Window::ConvertToOrientation(int angle) const
366 {
367   WindowOrientation orientation = static_cast<WindowOrientation>(angle);
368   if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
369   {
370     switch(angle)
371     {
372       case 0:
373       {
374         orientation = WindowOrientation::LANDSCAPE;
375         break;
376       }
377       case 90:
378       {
379         orientation = WindowOrientation::PORTRAIT;
380         break;
381       }
382       case 180:
383       {
384         orientation = WindowOrientation::LANDSCAPE_INVERSE;
385         break;
386       }
387       case 270:
388       {
389         orientation = WindowOrientation::PORTRAIT_INVERSE;
390         break;
391       }
392       case -1:
393       {
394         orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
395         break;
396       }
397     }
398   }
399   return orientation;
400 }
401
402 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
403 {
404   if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
405   {
406     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
407     return false;
408   }
409   return true;
410 }
411
412 Dali::Any Window::GetNativeHandle() const
413 {
414   return mWindowSurface->GetNativeWindow();
415 }
416
417 void Window::SetAcceptFocus(bool accept)
418 {
419   mIsFocusAcceptable = accept;
420
421   mWindowBase->SetAcceptFocus(accept);
422 }
423
424 bool Window::IsFocusAcceptable() const
425 {
426   return mIsFocusAcceptable;
427 }
428
429 void Window::Show()
430 {
431   mVisible = true;
432
433   mWindowBase->Show();
434
435   if(!mIconified)
436   {
437     Dali::Window handle(this);
438     mVisibilityChangedSignal.Emit(handle, true);
439
440     WindowVisibilityObserver* observer(mAdaptor);
441     observer->OnWindowShown();
442   }
443
444   mSurface->SetFullSwapNextFrame();
445
446   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
447 }
448
449 void Window::Hide()
450 {
451   mVisible = false;
452
453   mWindowBase->Hide();
454
455   if(!mIconified)
456   {
457     Dali::Window handle(this);
458     mVisibilityChangedSignal.Emit(handle, false);
459
460     WindowVisibilityObserver* observer(mAdaptor);
461     observer->OnWindowHidden();
462   }
463
464   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
465 }
466
467 bool Window::IsVisible() const
468 {
469   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
470   return mVisible && !mIconified;
471 }
472
473 unsigned int Window::GetSupportedAuxiliaryHintCount() const
474 {
475   return mWindowBase->GetSupportedAuxiliaryHintCount();
476 }
477
478 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
479 {
480   return mWindowBase->GetSupportedAuxiliaryHint(index);
481 }
482
483 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
484 {
485   return mWindowBase->AddAuxiliaryHint(hint, value);
486 }
487
488 bool Window::RemoveAuxiliaryHint(unsigned int id)
489 {
490   return mWindowBase->RemoveAuxiliaryHint(id);
491 }
492
493 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
494 {
495   return mWindowBase->SetAuxiliaryHintValue(id, value);
496 }
497
498 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
499 {
500   return mWindowBase->GetAuxiliaryHintValue(id);
501 }
502
503 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
504 {
505   return mWindowBase->GetAuxiliaryHintId(hint);
506 }
507
508 void Window::SetInputRegion(const Rect<int>& inputRegion)
509 {
510   mWindowBase->SetInputRegion(inputRegion);
511
512   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
513 }
514
515 void Window::SetType(WindowType type)
516 {
517   mWindowBase->SetType(type);
518 }
519
520 WindowType Window::GetType() const
521 {
522   return mWindowBase->GetType();
523 }
524
525 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
526 {
527   WindowType type = mWindowBase->GetType();
528   if(type != WindowType::NOTIFICATION)
529   {
530     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
531     return WindowOperationResult::INVALID_OPERATION;
532   }
533
534   return mWindowBase->SetNotificationLevel(level);
535 }
536
537 WindowNotificationLevel Window::GetNotificationLevel() const
538 {
539   WindowType type = mWindowBase->GetType();
540   if(type != WindowType::NOTIFICATION)
541   {
542     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
543     return WindowNotificationLevel::NONE;
544   }
545
546   return mWindowBase->GetNotificationLevel();
547 }
548
549 void Window::SetOpaqueState(bool opaque)
550 {
551   mOpaqueState = opaque;
552
553   mWindowBase->SetOpaqueState(opaque);
554
555   DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
556 }
557
558 bool Window::IsOpaqueState() const
559 {
560   return mOpaqueState;
561 }
562
563 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
564 {
565   return mWindowBase->SetScreenOffMode(screenOffMode);
566 }
567
568 WindowScreenOffMode Window::GetScreenOffMode() const
569 {
570   return mWindowBase->GetScreenOffMode();
571 }
572
573 WindowOperationResult Window::SetBrightness(int brightness)
574 {
575   if(brightness < 0 || brightness > 100)
576   {
577     DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
578     return WindowOperationResult::INVALID_OPERATION;
579   }
580
581   return mWindowBase->SetBrightness(brightness);
582 }
583
584 int Window::GetBrightness() const
585 {
586   return mWindowBase->GetBrightness();
587 }
588
589 void Window::SetSize(Dali::Window::WindowSize size)
590 {
591   PositionSize oldRect = mSurface->GetPositionSize();
592
593   mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
594
595   PositionSize newRect = mSurface->GetPositionSize();
596
597   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
598   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
599   {
600     Uint16Pair newSize(newRect.width, newRect.height);
601
602     SurfaceResized();
603
604     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
605
606     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
607
608     Dali::Window handle(this);
609     mResizeSignal.Emit(handle, newSize);
610
611     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
612   }
613
614   mSurface->SetFullSwapNextFrame();
615
616   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
617 }
618
619 Dali::Window::WindowSize Window::GetSize() const
620 {
621   PositionSize positionSize = mSurface->GetPositionSize();
622
623   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
624 }
625
626 void Window::SetPosition(Dali::Window::WindowPosition position)
627 {
628   PositionSize oldRect = mSurface->GetPositionSize();
629
630   mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
631
632   mSurface->SetFullSwapNextFrame();
633
634   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
635 }
636
637 Dali::Window::WindowPosition Window::GetPosition() const
638 {
639   PositionSize positionSize = mSurface->GetPositionSize();
640
641   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
642 }
643
644 PositionSize Window::GetPositionSize() const
645 {
646   return mSurface->GetPositionSize();
647 }
648
649 void Window::SetPositionSize(PositionSize positionSize)
650 {
651   PositionSize oldRect = mSurface->GetPositionSize();
652
653   mWindowSurface->MoveResize(positionSize);
654
655   PositionSize newRect = mSurface->GetPositionSize();
656
657   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
658   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
659   {
660     Uint16Pair newSize(newRect.width, newRect.height);
661
662     SurfaceResized();
663
664     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
665
666     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
667     Dali::Window handle(this);
668     mResizeSignal.Emit(handle, newSize);
669     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
670   }
671
672   mSurface->SetFullSwapNextFrame();
673
674   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
675 }
676
677 Dali::Layer Window::GetRootLayer() const
678 {
679   return mScene.GetRootLayer();
680 }
681
682 void Window::SetTransparency(bool transparent)
683 {
684   mWindowSurface->SetTransparency(transparent);
685 }
686
687 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
688 {
689   return mWindowBase->GrabKey(key, grabMode);
690 }
691
692 bool Window::UngrabKey(Dali::KEY key)
693 {
694   return mWindowBase->UngrabKey(key);
695 }
696
697 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
698 {
699   return mWindowBase->GrabKeyList(key, grabMode, result);
700 }
701
702 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
703 {
704   return mWindowBase->UngrabKeyList(key, result);
705 }
706
707 void Window::OnIconifyChanged(bool iconified)
708 {
709   if(iconified)
710   {
711     mIconified = true;
712
713     if(mVisible)
714     {
715       Dali::Window handle(this);
716       mVisibilityChangedSignal.Emit(handle, false);
717
718       WindowVisibilityObserver* observer(mAdaptor);
719       observer->OnWindowHidden();
720     }
721
722     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
723   }
724   else
725   {
726     mIconified = false;
727
728     if(mVisible)
729     {
730       Dali::Window handle(this);
731       mVisibilityChangedSignal.Emit(handle, true);
732
733       WindowVisibilityObserver* observer(mAdaptor);
734       observer->OnWindowShown();
735     }
736
737     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
738   }
739
740   mSurface->SetFullSwapNextFrame();
741 }
742
743 void Window::OnFocusChanged(bool focusIn)
744 {
745   Dali::Window handle(this);
746   mFocusChangeSignal.Emit(handle, focusIn);
747
748   mSurface->SetFullSwapNextFrame();
749
750   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
751   {
752     if(focusIn)
753     {
754       bridge->WindowShown();
755     }
756     else
757     {
758       bridge->WindowHidden();
759     }
760   }
761 }
762
763 void Window::OnOutputTransformed()
764 {
765   PositionSize positionSize = mSurface->GetPositionSize();
766
767   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
768   SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
769
770   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
771   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
772 }
773
774 void Window::OnDeleteRequest()
775 {
776   mDeleteRequestSignal.Emit();
777 }
778
779 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
780 {
781   Dali::Window handle(this);
782   mTransitionEffectEventSignal.Emit(handle, state, type);
783 }
784
785 void Window::OnKeyboardRepeatSettingsChanged()
786 {
787   Dali::Window handle(this);
788   mKeyboardRepeatSettingsChangedSignal.Emit();
789 }
790
791 void Window::OnWindowRedrawRequest()
792 {
793   mAdaptor->RenderOnce();
794 }
795
796 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
797 {
798   SetPositionSize(positionSize);
799 }
800
801 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
802 {
803   FeedTouchPoint(point, timeStamp);
804 }
805
806 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
807 {
808   FeedWheelEvent(wheelEvent);
809 }
810
811 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
812 {
813   FeedKeyEvent(keyEvent);
814 }
815
816 void Window::OnRotation(const RotationEvent& rotation)
817 {
818   mRotationAngle = rotation.angle;
819   mWindowWidth   = rotation.width;
820   mWindowHeight  = rotation.height;
821
822   // Notify that the orientation is changed
823   mOrientation->OnOrientationChange(rotation);
824
825   mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
826
827   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
828   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
829
830   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
831
832   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
833   // Emit signal
834   Dali::Window handle(this);
835   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
836
837   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
838 }
839
840 void Window::OnPause()
841 {
842   if(mEventHandler)
843   {
844     mEventHandler->Pause();
845   }
846 }
847
848 void Window::OnResume()
849 {
850   if(mEventHandler)
851   {
852     mEventHandler->Resume();
853   }
854
855   mSurface->SetFullSwapNextFrame();
856 }
857
858 void Window::RecalculateTouchPosition(Integration::Point& point)
859 {
860   Vector2 position = point.GetScreenPosition();
861   Vector2 convertedPosition;
862
863   switch(mRotationAngle)
864   {
865     case 90:
866     {
867       convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
868       convertedPosition.y = position.x;
869       break;
870     }
871     case 180:
872     {
873       convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
874       convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
875       break;
876     }
877     case 270:
878     {
879       convertedPosition.x = position.y;
880       convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
881       break;
882     }
883     default:
884     {
885       convertedPosition = position;
886       break;
887     }
888   }
889
890   point.SetScreenPosition(convertedPosition);
891 }
892
893 Dali::Window Window::Get(Dali::Actor actor)
894 {
895   Internal::Adaptor::Window* windowImpl = nullptr;
896
897   if(Internal::Adaptor::Adaptor::IsAvailable())
898   {
899     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
900     windowImpl                                = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
901     if(windowImpl)
902     {
903       return Dali::Window(windowImpl);
904     }
905   }
906
907   return Dali::Window();
908 }
909
910 void Window::SetParent(Dali::Window& parent)
911 {
912   if(DALI_UNLIKELY(parent))
913   {
914     mParentWindow     = parent;
915     Dali::Window self = Dali::Window(this);
916     // check circular parent window setting
917     if(Dali::DevelWindow::GetParent(parent) == self)
918     {
919       Dali::DevelWindow::Unparent(parent);
920     }
921     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
922   }
923 }
924
925 void Window::SetParent(Dali::Window& parent, bool belowParent)
926 {
927   if(DALI_UNLIKELY(parent))
928   {
929     mParentWindow     = parent;
930     Dali::Window self = Dali::Window(this);
931     // check circular parent window setting
932     if(Dali::DevelWindow::GetParent(parent) == self)
933     {
934       Dali::DevelWindow::Unparent(parent);
935     }
936     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
937   }
938 }
939
940 void Window::Unparent()
941 {
942   mWindowBase->SetParent(nullptr, false);
943   mParentWindow.Reset();
944 }
945
946 Dali::Window Window::GetParent()
947 {
948   return mParentWindow;
949 }
950
951 WindowOrientation Window::GetCurrentOrientation() const
952 {
953   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
954   return ConvertToOrientation(mRotationAngle);
955 }
956
957 int Window::GetPhysicalOrientation() const
958 {
959   return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
960 }
961
962 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
963 {
964   Dali::Vector<float>::SizeType count = orientations.Count();
965   for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
966   {
967     if(IsOrientationAvailable(orientations[index]) == false)
968     {
969       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
970       continue;
971     }
972
973     bool found          = false;
974     int  convertedAngle = ConvertToAngle(orientations[index]);
975
976     for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
977     {
978       if(mAvailableAngles[i] == convertedAngle)
979       {
980         found = true;
981         break;
982       }
983     }
984
985     if(!found)
986     {
987       DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
988       mAvailableAngles.push_back(convertedAngle);
989     }
990   }
991   SetAvailableAnlges(mAvailableAngles);
992 }
993
994 int32_t Window::GetNativeId() const
995 {
996   return mWindowBase->GetNativeWindowId();
997 }
998
999 void Window::RequestMoveToServer()
1000 {
1001   mWindowBase->RequestMoveToServer();
1002 }
1003
1004 void Window::RequestResizeToServer(WindowResizeDirection direction)
1005 {
1006   mWindowBase->RequestResizeToServer(direction);
1007 }
1008
1009 void Window::EnableFloatingMode(bool enable)
1010 {
1011   mWindowBase->EnableFloatingMode(enable);
1012 }
1013
1014 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1015 {
1016   mWindowBase->IncludeInputRegion(inputRegion);
1017 }
1018
1019 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1020 {
1021   mWindowBase->ExcludeInputRegion(inputRegion);
1022 }
1023
1024 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1025 {
1026   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1027   mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1028   mWindowRotationAcknowledgement = needAcknowledgement;
1029 }
1030
1031 void Window::SendRotationCompletedAcknowledgement()
1032 {
1033   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1034   if(mWindowRotationAcknowledgement)
1035   {
1036     SetRotationCompletedAcknowledgement();
1037   }
1038 }
1039
1040 } // namespace Adaptor
1041
1042 } // namespace Internal
1043
1044 } // namespace Dali