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