Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / offscreen / common / offscreen-window-impl.h
1 #ifndef DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_H
2 #define DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_H
3
4 /*
5  * Copyright (c) 2021 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/common/intrusive-ptr.h>
23 #include <dali/public-api/signals/connection-tracker.h>
24 #include <memory>
25
26 // INTERNAL INCLUDES
27 #include <dali/devel-api/adaptor-framework/offscreen-window.h>
28 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
29
30 namespace Dali
31 {
32 class Adaptor;
33 class Layer;
34 class NativeRenderSurface;
35 class TriggerEventInterface;
36
37 namespace Internal
38 {
39 /**
40  * Implementation of the OffscreenWindow class.
41  */
42 class OffscreenWindow : public Dali::Internal::Adaptor::SceneHolder,
43                         public ConnectionTracker
44 {
45 public:
46   using WindowSize           = Dali::OffscreenWindow::WindowSize;
47   using PostRenderSignalType = Dali::OffscreenWindow::PostRenderSignalType;
48
49   /**
50    * @brief Create a new OffscreenWindow
51    *
52    * @param[in] width The initial width of the OffscreenWindow
53    * @param[in] height The initial height of the OffscreenWindow
54    * @param[in] surface The native surface handle of your platform
55    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
56    */
57   static OffscreenWindow* New(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent);
58
59   OffscreenWindow() = default;
60
61 public:
62   /**
63    * Destructor
64    */
65   ~OffscreenWindow();
66
67   /**
68    * @copydoc Dali::OffscreenWindow::GetLayerCount
69    */
70   uint32_t GetLayerCount() const;
71
72   /**
73    * @copydoc Dali::OffscreenWindow::GetLayer
74    */
75   Dali::Layer GetLayer(uint32_t depth) const;
76
77   /**
78    * @copydoc Dali::OffscreenWindow::GetSize
79    */
80   WindowSize GetSize() const;
81
82   /**
83    * @copydoc Dali::OffscreenWindow::GetNativeHandle
84    */
85   Any GetNativeHandle() const override;
86
87   /*
88    * @brief Initialize the OffscreenWindow
89    * @param[in] isDefaultWindow Whether the OffscreenWindow is a default one or not
90    */
91   void Initialize(bool isDefaultWindow);
92
93 public: // Signals
94   /**
95    * @copydoc Dali::OffscreenWindow::PostRenderSignal
96    */
97   PostRenderSignalType& PostRenderSignal();
98
99 private:
100   /**
101    * This function is called after drawing by dali.
102    */
103   void OnPostRender();
104
105   /**
106    * @brief Get the native render surface
107    * @return The render surface
108    */
109   NativeRenderSurface* GetNativeRenderSurface() const;
110
111 private:
112   /**
113    * Private constructor
114    *
115    * @param[in] width The initial width of the OffscreenWindow
116    * @param[in] height The initial height of the OffscreenWindow
117    * @param[in] surface The native surface handle
118    * @param[in] isTranslucent Whether the OffscreenWindow is translucent or not
119    */
120   OffscreenWindow(uint16_t width, uint16_t height, Dali::Any surface, bool isTranslucent);
121
122   // Undefined
123   OffscreenWindow(const OffscreenWindow&);
124   OffscreenWindow& operator=(OffscreenWindow&);
125
126   /*
127    * @brief Initialize the OffscreenWindow (for internal use)
128    */
129   void Initialize();
130
131 private:
132   std::unique_ptr<TriggerEventInterface> mRenderNotification;
133   PostRenderSignalType                   mPostRenderSignal;
134 };
135
136 inline OffscreenWindow& GetImplementation(Dali::OffscreenWindow& offscreenWindow)
137 {
138   DALI_ASSERT_ALWAYS(offscreenWindow && "Dali::OffscreenWindow handle is empty");
139
140   BaseObject& handle = offscreenWindow.GetBaseObject();
141
142   return static_cast<OffscreenWindow&>(handle);
143 }
144
145 inline const OffscreenWindow& GetImplementation(const Dali::OffscreenWindow& offscreenWindow)
146 {
147   DALI_ASSERT_ALWAYS(offscreenWindow && "Dali::OffscreenWindow handle is empty");
148
149   const BaseObject& handle = offscreenWindow.GetBaseObject();
150
151   return static_cast<const OffscreenWindow&>(handle);
152 }
153
154 } // namespace Internal
155
156 } // namespace Dali
157
158 #endif // DALI_INTERNAL_OFFSCREEN_WINDOW_IMPL_H