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/public-api/adaptor-framework/window.h>
32 #include <dali/public-api/adaptor-framework/key-grab.h>
33 #include <dali/devel-api/adaptor-framework/drag-and-drop-detector.h>
34
35 namespace Dali
36 {
37 class Adaptor;
38 class Actor;
39
40 namespace Internal
41 {
42 namespace Adaptor
43 {
44 class Orientation;
45 class WindowRenderSurface;
46 class WindowBase;
47
48 class Window;
49 typedef IntrusivePtr<Window> WindowPtr;
50 typedef IntrusivePtr<Orientation> OrientationPtr;
51
52 /**
53  * Window provides a surface to render onto with orientation & indicator properties.
54  */
55 class Window : public Dali::BaseObject, public LifeCycleObserver, public ConnectionTracker
56 {
57 public:
58   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
59   typedef Dali::Window::FocusSignalType FocusSignalType;
60   typedef Dali::Window::ResizedSignalType ResizedSignalType;
61   typedef Signal< void () > SignalType;
62
63   /**
64    * Create a new Window. This should only be called once by the Application class
65    * @param[in] positionSize The position and size of the window
66    * @param[in] name The window title
67    * @param[in] className The window class name
68    * @param[in] isTransparent Whether window is transparent
69    * @return A newly allocated Window
70    */
71   static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent = false);
72
73   /**
74    * Pass the adaptor back to the overlay. This allows the window to access Core's overlay.
75    * @param[in] adaptor An initialized adaptor
76    */
77   void SetAdaptor(Dali::Adaptor& adaptor);
78
79   /**
80    * Get the window surface
81    * @return The render surface
82    */
83   WindowRenderSurface* GetSurface();
84
85   /**
86    * @copydoc Dali::Window::ShowIndicator()
87    */
88   void ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode );
89
90   /**
91    * @copydoc Dali::Window::SetIndicatorBgOpacity()
92    */
93   void SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacity );
94
95   /**
96    * @copydoc Dali::Window::RotateIndicator()
97    */
98   void RotateIndicator( Dali::Window::WindowOrientation orientation );
99
100   /**
101    * @copydoc Dali::Window::SetClass()
102    */
103   void SetClass( std::string name, std::string className );
104
105   /**
106    * @copydoc Dali::Window::Raise()
107    */
108   void Raise();
109
110   /**
111    * @copydoc Dali::Window::Lower()
112    */
113   void Lower();
114
115   /**
116    * @copydoc Dali::Window::Activate()
117    */
118   void Activate();
119
120   /**
121    * @copydoc Dali::Window::Add()
122    */
123   void Add( Dali::Actor actor );
124
125   /**
126    * @copydoc Dali::Window::Remove()
127    */
128   void Remove( Dali::Actor remove );
129
130   /**
131    * @copydoc Dali::Window::SetBackgroundColor()
132    */
133   void SetBackgroundColor(Vector4 color);
134
135   /**
136    * @copydoc Dali::Window::GetBackgroundColor()
137    */
138   Vector4 GetBackgroundColor() const;
139
140   /**
141    * @copydoc Dali::Window::GetRootLayer()
142    */
143   Dali::Layer GetRootLayer() const;
144
145   /**
146    * @copydoc Dali::Window::GetLayerCount()
147    */
148   uint32_t GetLayerCount() const;
149
150   /**
151    * @copydoc Dali::Window::GetLayer()
152    */
153   Dali::Layer GetLayer( uint32_t depth ) const;
154
155   /**
156    * @copydoc Dali::Window::AddAvailableOrientation()
157    */
158   void AddAvailableOrientation(Dali::Window::WindowOrientation orientation);
159
160   /**
161    * @copydoc Dali::Window::RemoveAvailableOrientation()
162    */
163   void RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation);
164
165   /**
166    * @copydoc Dali::Window::SetAvailableOrientations()
167    */
168   void SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations);
169
170   /**
171    * @copydoc Dali::Window::GetAvailableOrientations()
172    */
173   const std::vector<Dali::Window::WindowOrientation>& GetAvailableOrientations();
174
175   /**
176    * @copydoc Dali::Window::SetPreferredOrientation()
177    */
178   void SetPreferredOrientation(Dali::Window::WindowOrientation orientation);
179
180   /**
181    * @copydoc Dali::Window::GetPreferredOrientation()
182    */
183   Dali::Window::WindowOrientation GetPreferredOrientation();
184
185   /**
186    * @copydoc Dali::Window::GetDragAndDropDetector() const
187    */
188   Dali::DragAndDropDetector GetDragAndDropDetector() const;
189
190   /**
191    * @copydoc Dali::Window::GetNativeHandle() const
192    */
193   Dali::Any GetNativeHandle() const;
194
195   /**
196    * @copydoc Dali::Window::SetAcceptFocus()
197    */
198   void SetAcceptFocus( bool accept );
199
200   /**
201    * @copydoc Dali::Window::IsFocusAcceptable()
202    */
203   bool IsFocusAcceptable() const;
204
205   /**
206    * @copydoc Dali::Window::Show()
207    */
208   void Show();
209
210   /**
211    * @copydoc Dali::Window::Hide()
212    */
213   void Hide();
214
215   /**
216    * @copydoc Dali::Window::IsVisible() const
217    */
218   bool IsVisible() const;
219
220   /**
221    * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
222    */
223   unsigned int GetSupportedAuxiliaryHintCount() const;
224
225   /**
226    * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
227    */
228   std::string GetSupportedAuxiliaryHint( unsigned int index ) const;
229
230   /**
231    * @copydoc Dali::Window::AddAuxiliaryHint()
232    */
233   unsigned int AddAuxiliaryHint( const std::string& hint, const std::string& value );
234
235   /**
236    * @copydoc Dali::Window::RemoveAuxiliaryHint()
237    */
238   bool RemoveAuxiliaryHint( unsigned int id );
239
240   /**
241    * @copydoc Dali::Window::SetAuxiliaryHintValue()
242    */
243   bool SetAuxiliaryHintValue( unsigned int id, const std::string& value );
244
245   /**
246    * @copydoc Dali::Window::GetAuxiliaryHintValue()
247    */
248   std::string GetAuxiliaryHintValue( unsigned int id ) const;
249
250   /**
251    * @copydoc Dali::Window::GetAuxiliaryHintId()
252    */
253   unsigned int GetAuxiliaryHintId( const std::string& hint ) const;
254
255   /**
256    * @copydoc Dali::Window::SetInputRegion()
257    */
258   void SetInputRegion( const Rect< int >& inputRegion );
259
260   /**
261    * @copydoc Dali::Window::SetType()
262    */
263   void SetType( Dali::Window::Type type );
264
265   /**
266    * @copydoc Dali::Window::GetType() const
267    */
268   Dali::Window::Type GetType() const;
269
270   /**
271    * @copydoc Dali::Window::SetNotificationLevel()
272    */
273   bool SetNotificationLevel( Dali::Window::NotificationLevel::Type level );
274
275   /**
276    * @copydoc Dali::Window::GetNotificationLevel()
277    */
278   Dali::Window::NotificationLevel::Type GetNotificationLevel() const;
279
280   /**
281    * @copydoc Dali::Window::SetOpaqueState()
282    */
283   void SetOpaqueState( bool opaque );
284
285   /**
286    * @copydoc Dali::Window::IsOpaqueState()
287    */
288   bool IsOpaqueState() const;
289
290   /**
291    * @copydoc Dali::Window::SetScreenOffMode()
292    */
293   bool SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode);
294
295   /**
296    * @copydoc Dali::Window::GetScreenOffMode()
297    */
298   Dali::Window::ScreenOffMode::Type GetScreenOffMode() const;
299
300   /**
301    * @copydoc Dali::Window::SetBrightness()
302    */
303   bool SetBrightness( int brightness );
304
305   /**
306    * @copydoc Dali::Window::GetBrightness()
307    */
308   int GetBrightness() const;
309
310   /**
311    * @copydoc Dali::Window::SetSize()
312    */
313   void SetSize( Dali::Window::WindowSize size );
314
315   /**
316    * @copydoc Dali::Window::GetSize()
317    */
318   Dali::Window::WindowSize GetSize() const;
319
320   /**
321    * @copydoc Dali::Window::SetPosition()
322    */
323   void SetPosition( Dali::Window::WindowPosition position );
324
325   /**
326    * @copydoc Dali::Window::GetPosition()
327    */
328   Dali::Window::WindowPosition GetPosition() const;
329
330   /**
331    * @copydoc Dali::DevelWindow::SetPositionSize()
332    */
333   void SetPositionSize( PositionSize positionSize );
334
335   /**
336    * @copydoc Dali::Window::SetTransparency()
337    */
338   void SetTransparency( bool transparent );
339
340   /**
341    * @copydoc Dali::KeyGrab::GrabKey()
342    */
343   bool GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode );
344
345   /**
346    * @copydoc Dali::KeyGrab::UngrabKey()
347    */
348   bool UngrabKey( Dali::KEY key );
349
350   /**
351    * @copydoc Dali::KeyGrab::GrabKeyList()
352    */
353   bool GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result );
354
355   /**
356    * @copydoc Dali::KeyGrab::UngrabKeyList()
357    */
358   bool UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result );
359
360   /**
361    * Called from Orientation after the Change signal has been sent
362    */
363   void RotationDone( int orientation, int width, int height );
364
365   /**
366    * @brief Retrieves the unique ID of the window.
367    * @return The ID
368    */
369   uint32_t GetId() const;
370
371 private:
372
373   /**
374    * Private constructor.
375    * @sa Window::New()
376    */
377   Window();
378
379   /**
380    * Destructor
381    */
382   virtual ~Window();
383
384   /**
385    * Second stage initialization
386    */
387   void Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className);
388
389   /**
390    * Called when the window becomes iconified or deiconified.
391    */
392   void OnIconifyChanged( bool iconified );
393
394   /**
395    * Called when the window focus is changed.
396    */
397   void OnFocusChanged( bool focusIn );
398
399   /**
400    * Called when the output is transformed.
401    */
402   void OnOutputTransformed();
403
404   /**
405    * Called when the window receives a delete request.
406    */
407   void OnDeleteRequest();
408
409 private: // Adaptor::Observer interface
410
411   /**
412    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStart()
413    */
414   virtual void OnStart();
415
416   /**
417    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnPause()
418    */
419   virtual void OnPause();
420
421   /**
422    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnResume()
423    */
424   virtual void OnResume();
425
426   /**
427    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnStop()
428    */
429   virtual void OnStop();
430
431   /**
432    * @copydoc Dali::Internal::Adaptor::Adaptor::Observer::OnDestroy()
433    */
434   virtual void OnDestroy();
435
436 public: // Signals
437
438   /**
439    * The user should connect to this signal to get a timing when indicator was shown / hidden.
440    */
441   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
442
443   /**
444    * @copydoc Dali::Window::FocusChangedSignal()
445    */
446   FocusSignalType& FocusChangedSignal() { return mFocusChangedSignal; }
447
448   /**
449    * @copydoc Dali::Window::ResizedSignal()
450    */
451   ResizedSignalType& ResizedSignal() { return mResizedSignal; }
452
453   /**
454    * This signal is emitted when the window is requesting to be deleted
455    */
456   SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
457
458 private:
459
460   static uint32_t                       mWindowCounter;    ///< A counter to track the window creation
461   uint32_t                              mId;               ///< A unique ID to identify the window starting from 0
462   std::unique_ptr< WindowRenderSurface > mSurface;
463   Dali::Integration::Scene              mScene;
464   WindowBase*                           mWindowBase;
465   bool                                  mStarted:1;
466   bool                                  mIsTransparent:1;
467   bool                                  mIsFocusAcceptable:1;
468   bool                                  mVisible:1;
469   bool                                  mIconified:1;
470   bool                                  mOpaqueState:1;
471   bool                                  mResizeEnabled:1;
472   Adaptor*                              mAdaptor;
473   Dali::DragAndDropDetector             mDragAndDropDetector;
474   Dali::Window::Type                    mType;
475
476   OrientationPtr                               mOrientation;
477   std::vector<Dali::Window::WindowOrientation> mAvailableOrientations;
478   Dali::Window::WindowOrientation              mPreferredOrientation;
479
480   Vector4                               mBackgroundColor;
481
482   // Signals
483   IndicatorSignalType mIndicatorVisibilityChangedSignal;
484   FocusSignalType     mFocusChangedSignal;
485   ResizedSignalType   mResizedSignal;
486   SignalType          mDeleteRequestSignal;
487 };
488
489 } // namespace Adaptor
490 } // namepsace Internal
491
492 // Helpers for public-api forwarding methods
493
494 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
495 {
496   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
497   BaseObject& object = window.GetBaseObject();
498   return static_cast<Internal::Adaptor::Window&>(object);
499 }
500
501 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
502 {
503   DALI_ASSERT_ALWAYS( window && "Window handle is empty" );
504   const BaseObject& object = window.GetBaseObject();
505   return static_cast<const Internal::Adaptor::Window&>(object);
506 }
507
508 } // namespace Dali
509
510 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H