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