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