Revert "[Tizen] Revert "Support multiple window rendering""
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <dali/integration-api/scene.h>
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/adaptor/common/lifecycle-observer.h>
30 #include <dali/internal/adaptor/common/adaptor-impl.h>
31 #include <dali/internal/window-system/common/indicator-interface.h>
32 #include <dali/public-api/adaptor-framework/window.h>
33 #include <dali/public-api/adaptor-framework/key-grab.h>
34 #include <dali/devel-api/adaptor-framework/drag-and-drop-detector.h>
35
36 namespace Dali
37 {
38 class Adaptor;
39 class Actor;
40
41 namespace Internal
42 {
43 namespace Adaptor
44 {
45 class Orientation;
46 class WindowRenderSurface;
47 class WindowBase;
48
49 class Window;
50 typedef IntrusivePtr<Window> WindowPtr;
51 typedef IntrusivePtr<Orientation> OrientationPtr;
52
53 /**
54  * Window provides a surface to render onto with orientation & indicator properties.
55  */
56 class Window : public Dali::BaseObject, public IndicatorInterface::Observer, public LifeCycleObserver, public ConnectionTracker
57 {
58 public:
59   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
60   typedef Dali::Window::FocusSignalType FocusSignalType;
61   typedef Dali::Window::ResizedSignalType ResizedSignalType;
62   typedef Signal< void () > SignalType;
63
64   /**
65    * Create a new Window. This should only be called once by the Application class
66    * @param[in] positionSize The position and size of the window
67    * @param[in] name The window title
68    * @param[in] className The window class name
69    * @param[in] isTransparent Whether window is transparent
70    * @return A newly allocated Window
71    */
72   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
73
74   /**
75    * Pass the adaptor back to the overlay. This allows the window to access Core's overlay.
76    * @param[in] adaptor An initialized adaptor
77    */
78   void SetAdaptor(Dali::Adaptor& adaptor);
79
80   /**
81    * Get the window surface
82    * @return The render surface
83    */
84   WindowRenderSurface* GetSurface();
85
86   /**
87    * @copydoc Dali::Window::ShowIndicator()
88    */
89   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
90
91   /**
92    * @copydoc Dali::Window::SetIndicatorBgOpacity()
93    */
94   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
95
96   /**
97    * Set the indicator visible mode
98    */
99   void SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode );
100
101   /**
102    * @copydoc Dali::Window::RotateIndicator()
103    */
104   void RotateIndicator( Dali::Window::WindowOrientation orientation );
105
106   /**
107    * @copydoc Dali::Window::SetClass()
108    */
109   void SetClass( std::string name, std::string className );
110
111   /**
112    * @copydoc Dali::Window::Raise()
113    */
114   void Raise();
115
116   /**
117    * @copydoc Dali::Window::Lower()
118    */
119   void Lower();
120
121   /**
122    * @copydoc Dali::Window::Activate()
123    */
124   void Activate();
125
126   /**
127    * @copydoc Dali::Window::Add()
128    */
129   void Add( Dali::Actor actor );
130
131   /**
132    * @copydoc Dali::Window::Remove()
133    */
134   void Remove( Dali::Actor remove );
135
136   /**
137    * @copydoc Dali::Window::SetBackgroundColor()
138    */
139   void SetBackgroundColor(Vector4 color);
140
141   /**
142    * @copydoc Dali::Window::GetBackgroundColor()
143    */
144   Vector4 GetBackgroundColor() const;
145
146   /**
147    * @copydoc Dali::Window::GetRootLayer()
148    */
149   Dali::Layer GetRootLayer() const;
150
151   /**
152    * @copydoc Dali::Window::GetLayerCount()
153    */
154   uint32_t GetLayerCount() const;
155
156   /**
157    * @copydoc Dali::Window::GetLayer()
158    */
159   Dali::Layer GetLayer( uint32_t depth ) const;
160
161   /**
162    * @copydoc Dali::Window::AddAvailableOrientation()
163    */
164   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
165
166   /**
167    * @copydoc Dali::Window::RemoveAvailableOrientation()
168    */
169   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
170
171   /**
172    * @copydoc Dali::Window::SetAvailableOrientations()
173    */
174   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
175
176   /**
177    * @copydoc Dali::Window::GetAvailableOrientations()
178    */
179   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
180
181   /**
182    * @copydoc Dali::Window::SetPreferredOrientation()
183    */
184   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
185
186   /**
187    * @copydoc Dali::Window::GetPreferredOrientation()
188    */
189   Dali::Window::WindowOrientation GetPreferredOrientation();
190
191   /**
192    * @copydoc Dali::Window::GetDragAndDropDetector() const
193    */
194   Dali::DragAndDropDetector GetDragAndDropDetector() const;
195
196   /**
197    * @copydoc Dali::Window::GetNativeHandle() const
198    */
199   Dali::Any GetNativeHandle() const;
200
201   /**
202    * @copydoc Dali::Window::SetAcceptFocus()
203    */
204   void SetAcceptFocus( bool accept );
205
206   /**
207    * @copydoc Dali::Window::IsFocusAcceptable()
208    */
209   bool IsFocusAcceptable() const;
210
211   /**
212    * @copydoc Dali::Window::Show()
213    */
214   void Show();
215
216   /**
217    * @copydoc Dali::Window::Hide()
218    */
219   void Hide();
220
221   /**
222    * @copydoc Dali::Window::IsVisible() const
223    */
224   bool IsVisible() const;
225
226   /**
227    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
228    */
229   unsigned int GetSupportedAuxiliaryHintCount() const;
230
231   /**
232    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
233    */
234   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
235
236   /**
237    * @copydoc Dali::Window::AddAuxiliaryHint()
238    */
239   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
240
241   /**
242    * @copydoc Dali::Window::RemoveAuxiliaryHint()
243    */
244   bool RemoveAuxiliaryHint( unsigned int id );
245
246   /**
247    * @copydoc Dali::Window::SetAuxiliaryHintValue()
248    */
249   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
250
251   /**
252    * @copydoc Dali::Window::GetAuxiliaryHintValue()
253    */
254   std::string GetAuxiliaryHintValue( unsigned int id ) const;
255
256   /**
257    * @copydoc Dali::Window::GetAuxiliaryHintId()
258    */
259   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
260
261   /**
262    * @copydoc Dali::Window::SetInputRegion()
263    */
264   void SetInputRegion( const Rect< int >& inputRegion );
265
266   /**
267    * @copydoc Dali::Window::SetType()
268    */
269   void SetType( Dali::Window::Type type );
270
271   /**
272    * @copydoc Dali::Window::GetType() const
273    */
274   Dali::Window::Type GetType() const;
275
276   /**
277    * @copydoc Dali::Window::SetNotificationLevel()
278    */
279   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
280
281   /**
282    * @copydoc Dali::Window::GetNotificationLevel()
283    */
284   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
285
286   /**
287    * @copydoc Dali::Window::SetOpaqueState()
288    */
289   void SetOpaqueState( bool opaque );
290
291   /**
292    * @copydoc Dali::Window::IsOpaqueState()
293    */
294   bool IsOpaqueState() const;
295
296   /**
297    * @copydoc Dali::Window::SetScreenOffMode()
298    */
299   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
300
301   /**
302    * @copydoc Dali::Window::GetScreenOffMode()
303    */
304   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
305
306   /**
307    * @copydoc Dali::Window::SetBrightness()
308    */
309   bool SetBrightness( int brightness );
310
311   /**
312    * @copydoc Dali::Window::GetBrightness()
313    */
314   int GetBrightness() const;
315
316   /**
317    * @copydoc Dali::Window::SetSize()
318    */
319   void SetSize( Dali::Window::WindowSize size );
320
321   /**
322    * @copydoc Dali::Window::GetSize()
323    */
324   Dali::Window::WindowSize GetSize() const;
325
326   /**
327    * @copydoc Dali::Window::SetPosition()
328    */
329   void SetPosition( Dali::Window::WindowPosition position );
330
331   /**
332    * @copydoc Dali::Window::GetPosition()
333    */
334   Dali::Window::WindowPosition GetPosition() const;
335
336   /**
337    * @copydoc Dali::DevelWindow::SetPositionSize()
338    */
339   void SetPositionSize( PositionSize positionSize );
340
341   /**
342    * @copydoc Dali::Window::SetTransparency()
343    */
344   void SetTransparency( bool transparent );
345
346   /**
347    * @copydoc Dali::KeyGrab::GrabKey()
348    */
349   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
350
351   /**
352    * @copydoc Dali::KeyGrab::UngrabKey()
353    */
354   bool UngrabKey( Dali::KEY key );
355
356   /**
357    * @copydoc Dali::KeyGrab::GrabKeyList()
358    */
359   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
360
361   /**
362    * @copydoc Dali::KeyGrab::UngrabKeyList()
363    */
364   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
365
366   /**
367    * Called from Orientation after the Change signal has been sent
368    */
369   void RotationDone( int orientation, int width, int height );
370
371   /**
372    * @brief Retrieves the unique ID of the window.
373    * @return The ID
374    */
375   uint32_t GetId() const;
376
377 private:
378
379   /**
380    * Private constructor.
381    * @sa Window::New()
382    */
383   Window();
384
385   /**
386    * Destructor
387    */
388   virtual ~Window();
389
390   /**
391    * Second stage initialization
392    */
393   void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
394
395   /**
396    * Shows / hides the indicator bar.
397    * Handles close/open if rotation changes whilst hidden
398    */
399   void DoShowIndicator( Dali::Window::WindowOrientation lastOrientation );
400
401   /**
402    * Close current indicator and open a connection onto the new indicator service.
403    * Effect may not be synchronous if waiting for an indicator update on existing connection.
404    */
405   void DoRotateIndicator( Dali::Window::WindowOrientation orientation );
406
407   /**
408    * Change the indicator actor's rotation to match the current orientation
409    */
410   void SetIndicatorActorRotation();
411
412   /**
413    * Set the indicator properties on the window
414    */
415   void SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation );
416
417   /**
418    * Called when the window becomes iconified or deiconified.
419    */
420   void OnIconifyChanged( bool iconified );
421
422   /**
423    * Called when the window focus is changed.
424    */
425   void OnFocusChanged( bool focusIn );
426
427   /**
428    * Called when the output is transformed.
429    */
430   void OnOutputTransformed();
431
432   /**
433    * Called when the window receives a delete request.
434    */
435   void OnDeleteRequest();
436
437   /**
438    * Called when the Ecore indicator event is received.
439    */
440   void OnIndicatorFlicked();
441
442 private: // IndicatorInterface::Observer interface
443
444   /**
445    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorTypeChanged()
446    */
447   virtual void IndicatorTypeChanged( IndicatorInterface::Type type );
448
449   /**
450    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorClosed()
451    */
452   virtual void IndicatorClosed( IndicatorInterface* indicator);
453
454   /**
455    * @copydoc Dali::Internal::Adaptor::IndicatorInterface::Observer::IndicatorVisibilityChanged()
456    */
457   virtual void IndicatorVisibilityChanged( bool isVisible );
458
459 private: // Adaptor::Observer interface
460
461   /**
462    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
463    */
464   virtual void OnStart();
465
466   /**
467    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
468    */
469   virtual void OnPause();
470
471   /**
472    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
473    */
474   virtual void OnResume();
475
476   /**
477    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
478    */
479   virtual void OnStop();
480
481   /**
482    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
483    */
484   virtual void OnDestroy();
485
486 public: // Signals
487
488   /**
489    * The user should connect to this signal to get a timing when indicator was shown / hidden.
490    */
491   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
492
493   /**
494    * @copydoc Dali::Window::FocusChangedSignal()
495    */
496   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
497
498   /**
499    * @copydoc Dali::Window::ResizedSignal()
500    */
501   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
502
503   /**
504    * This signal is emitted when the window is requesting to be deleted
505    */
506   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
507
508 private:
509
510   static uint32_t                       mWindowCounter;    ///< A counter to track the window creation
511   uint32_t                              mId;               ///< A unique ID to identify the window starting from 0
512   std::unique_ptr< WindowRenderSurface > mSurface;
513   Dali::Integration::Scene              mScene;
514   WindowBase*                           mWindowBase;
515   Dali::Window::IndicatorVisibleMode    mIndicatorVisible; ///< public state
516   bool                                  mIndicatorIsShown:1; ///< private state
517   bool                                  mShowRotatedIndicatorOnClose:1;
518   bool                                  mStarted:1;
519   bool                                  mIsTransparent:1;
520   bool                                  mIsFocusAcceptable:1;
521   bool                                  mVisible:1;
522   bool                                  mIconified:1;
523   bool                                  mOpaqueState:1;
524   bool                                  mResizeEnabled:1;
525   std::unique_ptr< IndicatorInterface > mIndicator;
526   Dali::Window::WindowOrientation       mIndicatorOrientation;
527   Dali::Window::WindowOrientation       mNextIndicatorOrientation;
528   Dali::Window::IndicatorBgOpacity      mIndicatorOpacityMode;
529   Adaptor*                              mAdaptor;
530   Dali::DragAndDropDetector             mDragAndDropDetector;
531   Dali::Window::Type                    mType;
532
533   OrientationPtr                               mOrientation;
534   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
535   Dali::Window::WindowOrientation              mPreferredOrientation;
536
537   Vector4                               mBackgroundColor;
538
539   // Signals
540   IndicatorSignalType mIndicatorVisibilityChangedSignal;
541   FocusSignalType     mFocusChangedSignal;
542   ResizedSignalType   mResizedSignal;
543   SignalType          mDeleteRequestSignal;
544 };
545
546 } // namespace Adaptor
547 } // namepsace Internal
548
549 // Helpers for public-api forwarding methods
550
551 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
552 {
553   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
554   BaseObject& object = window.GetBaseObject();
555   return static_cast<Internal::Adaptor::Window&>(object);
556 }
557
558 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
559 {
560   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
561   const BaseObject& object = window.GetBaseObject();
562   return static_cast<const Internal::Adaptor::Window&>(object);
563 }
564
565 } // namespace Dali
566
567 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H