4d60b1d212166e600c130c0f8e8c3d1897017a72
[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 WindowOperationResult 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 WindowOperationResult::INVALID_OPERATION;
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 WindowOperationResult 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 WindowOperationResult 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 WindowOperationResult::INVALID_OPERATION;
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   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
604 }
605
606 Dali::Window::WindowSize Window::GetSize() const
607 {
608   PositionSize positionSize = mSurface->GetPositionSize();
609
610   return Dali::Window::WindowSize(positionSize.width, positionSize.height);
611 }
612
613 void Window::SetPosition(Dali::Window::WindowPosition position)
614 {
615   PositionSize oldRect = mSurface->GetPositionSize();
616
617   mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
618
619   mSurface->SetFullSwapNextFrame();
620
621   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
622 }
623
624 Dali::Window::WindowPosition Window::GetPosition() const
625 {
626   PositionSize positionSize = mSurface->GetPositionSize();
627
628   return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
629 }
630
631 void Window::SetPositionSize(PositionSize positionSize)
632 {
633   PositionSize oldRect = mSurface->GetPositionSize();
634
635   mWindowSurface->MoveResize(positionSize);
636
637   PositionSize newRect = mSurface->GetPositionSize();
638
639   // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
640   if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
641   {
642     Uint16Pair newSize(newRect.width, newRect.height);
643
644     SurfaceResized();
645
646     mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
647
648     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
649     Dali::Window handle(this);
650     mResizeSignal.Emit(handle, newSize);
651     mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
652   }
653
654   mSurface->SetFullSwapNextFrame();
655
656   Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
657 }
658
659 PositionSize Window::GetPositionSize() const
660 {
661   return mSurface->GetPositionSize();
662 }
663
664 Dali::Layer Window::GetRootLayer() const
665 {
666   return mScene.GetRootLayer();
667 }
668
669 void Window::SetTransparency(bool transparent)
670 {
671   mWindowSurface->SetTransparency(transparent);
672 }
673
674 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
675 {
676   return mWindowBase->GrabKey(key, grabMode);
677 }
678
679 bool Window::UngrabKey(Dali::KEY key)
680 {
681   return mWindowBase->UngrabKey(key);
682 }
683
684 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
685 {
686   return mWindowBase->GrabKeyList(key, grabMode, result);
687 }
688
689 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
690 {
691   return mWindowBase->UngrabKeyList(key, result);
692 }
693
694 void Window::OnIconifyChanged(bool iconified)
695 {
696   if(iconified)
697   {
698     mIconified = true;
699
700     if(mVisible)
701     {
702       WindowVisibilityObserver* observer(mAdaptor);
703       observer->OnWindowHidden();
704
705       Dali::Window handle(this);
706       mVisibilityChangedSignal.Emit(handle, false);
707     }
708
709     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
710   }
711   else
712   {
713     mIconified = false;
714
715     if(mVisible)
716     {
717       WindowVisibilityObserver* observer(mAdaptor);
718       observer->OnWindowShown();
719
720       Dali::Window handle(this);
721       mVisibilityChangedSignal.Emit(handle, true);
722     }
723
724     DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
725   }
726
727   mSurface->SetFullSwapNextFrame();
728 }
729
730 void Window::OnFocusChanged(bool focusIn)
731 {
732   Dali::Window handle(this);
733   mFocusChangeSignal.Emit(handle, focusIn);
734
735   mSurface->SetFullSwapNextFrame();
736
737   if(auto b = Dali::Accessibility::Bridge::GetCurrentBridge())
738   {
739     if(focusIn)
740     {
741       b->ApplicationShown();
742     }
743     else
744     {
745       b->ApplicationHidden();
746     }
747   }
748 }
749
750 void Window::OnOutputTransformed()
751 {
752   PositionSize positionSize = mSurface->GetPositionSize();
753
754   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
755   SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
756
757   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
758   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
759 }
760
761 void Window::OnDeleteRequest()
762 {
763   mDeleteRequestSignal.Emit();
764 }
765
766 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
767 {
768   Dali::Window handle(this);
769   mTransitionEffectEventSignal.Emit(handle, state, type);
770 }
771
772 void Window::OnKeyboardRepeatSettingsChanged()
773 {
774   Dali::Window handle(this);
775   mKeyboardRepeatSettingsChangedSignal.Emit();
776 }
777
778 void Window::OnWindowRedrawRequest()
779 {
780   mAdaptor->RenderOnce();
781 }
782
783 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
784 {
785   SetPositionSize(positionSize);
786 }
787
788 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
789 {
790   FeedTouchPoint(point, timeStamp);
791 }
792
793 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
794 {
795   FeedWheelEvent(wheelEvent);
796 }
797
798 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
799 {
800   FeedKeyEvent(keyEvent);
801 }
802
803 void Window::OnRotation(const RotationEvent& rotation)
804 {
805   mRotationAngle = rotation.angle;
806   mWindowWidth   = rotation.width;
807   mWindowHeight  = rotation.height;
808
809   // Notify that the orientation is changed
810   mOrientation->OnOrientationChange(rotation);
811
812   mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
813
814   int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
815   SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
816
817   mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
818
819   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
820   // Emit signal
821   Dali::Window handle(this);
822   mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
823
824   mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
825 }
826
827 void Window::OnPause()
828 {
829   if(mEventHandler)
830   {
831     mEventHandler->Pause();
832   }
833 }
834
835 void Window::OnResume()
836 {
837   if(mEventHandler)
838   {
839     mEventHandler->Resume();
840   }
841
842   mSurface->SetFullSwapNextFrame();
843 }
844
845 void Window::RecalculateTouchPosition(Integration::Point& point)
846 {
847   Vector2 position = point.GetScreenPosition();
848   Vector2 convertedPosition;
849
850   switch(mRotationAngle)
851   {
852     case 90:
853     {
854       convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
855       convertedPosition.y = position.x;
856       break;
857     }
858     case 180:
859     {
860       convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
861       convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
862       break;
863     }
864     case 270:
865     {
866       convertedPosition.x = position.y;
867       convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
868       break;
869     }
870     default:
871     {
872       convertedPosition = position;
873       break;
874     }
875   }
876
877   point.SetScreenPosition(convertedPosition);
878 }
879
880 Dali::Window Window::Get(Dali::Actor actor)
881 {
882   Internal::Adaptor::Window* windowImpl = nullptr;
883
884   if(Internal::Adaptor::Adaptor::IsAvailable())
885   {
886     Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
887     windowImpl                                = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
888     if(windowImpl)
889     {
890       return Dali::Window(windowImpl);
891     }
892   }
893
894   return Dali::Window();
895 }
896
897 void Window::SetParent(Dali::Window& parent)
898 {
899   if(DALI_UNLIKELY(parent))
900   {
901     mParentWindow     = parent;
902     Dali::Window self = Dali::Window(this);
903     // check circular parent window setting
904     if(Dali::DevelWindow::GetParent(parent) == self)
905     {
906       Dali::DevelWindow::Unparent(parent);
907     }
908     mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase);
909   }
910 }
911
912 void Window::Unparent()
913 {
914   mWindowBase->SetParent(nullptr);
915   mParentWindow.Reset();
916 }
917
918 Dali::Window Window::GetParent()
919 {
920   return mParentWindow;
921 }
922
923 WindowOrientation Window::GetCurrentOrientation() const
924 {
925   DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
926   return ConvertToOrientation(mRotationAngle);
927 }
928
929 int Window::GetPhysicalOrientation() const
930 {
931   return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
932 }
933
934 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
935 {
936   Dali::Vector<float>::SizeType count = orientations.Count();
937   for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
938   {
939     if(IsOrientationAvailable(orientations[index]) == false)
940     {
941       DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
942       continue;
943     }
944
945     bool found          = false;
946     int  convertedAngle = ConvertToAngle(orientations[index]);
947
948     for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
949     {
950       if(mAvailableAngles[i] == convertedAngle)
951       {
952         found = true;
953         break;
954       }
955     }
956
957     if(!found)
958     {
959       DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
960       mAvailableAngles.push_back(convertedAngle);
961     }
962   }
963   SetAvailableAnlges(mAvailableAngles);
964 }
965
966 int32_t Window::GetNativeId() const
967 {
968   return mWindowBase->GetNativeWindowId();
969 }
970
971 } // namespace Adaptor
972
973 } // namespace Internal
974
975 } // namespace Dali