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