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